This repository was archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
RFTools and XNet Support #214
Draft
Nerdpie
wants to merge
6
commits into
SquidDev-CC:minecraft-1.12
Choose a base branch
from
Nerdpie:feature/rftools-support
base: minecraft-1.12
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5cb2e87
Start on RFTools & XNet integration
Nerdpie f15889b
Merge remote-tracking branch 'squid/minecraft-1.12' into feature/rfto…
Nerdpie 1bdc9e8
Continued work on integration
Nerdpie 552137e
Some changes based on Squid's input
Nerdpie 8aa1992
Initial naive conversion of OC XNet Driver methods
Nerdpie 554cfe7
Start refactoring XNet methods
Nerdpie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mc_version=1.12.2 | ||
forge_version=14.23.5.2768 | ||
//forge_version=14.23.5.2768 | ||
forge_version=14.23.5.2800 | ||
//FIXME Revert before merging; required by McJtyLib | ||
|
||
mod_version=1.2.0 | ||
cct_version=1.82.3 |
116 changes: 116 additions & 0 deletions
116
src/main/java/org/squiddev/plethora/integration/mcjtylib/IntegrationMcJtyLib.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.squiddev.plethora.integration.mcjtylib; | ||
|
||
import mcjty.lib.McJtyLib; | ||
import mcjty.lib.base.GeneralConfig; | ||
import mcjty.lib.blocks.GenericItemBlock; | ||
import mcjty.lib.tileentity.GenericTileEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraftforge.common.util.Constants; | ||
import org.squiddev.plethora.api.Injects; | ||
import org.squiddev.plethora.api.meta.BasicMetaProvider; | ||
import org.squiddev.plethora.api.meta.IMetaProvider; | ||
import org.squiddev.plethora.api.meta.ItemStackMetaProvider; | ||
import org.squiddev.plethora.utils.EntityPlayerDummy; | ||
import org.squiddev.plethora.utils.WorldDummy; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Injects(McJtyLib.PROVIDES) | ||
public final class IntegrationMcJtyLib { | ||
private IntegrationMcJtyLib() { | ||
} | ||
|
||
/* | ||
* MEMO To test McJtyLib and dependent integrations, Forge must be set to AT LEAST 14.23.5.2800 | ||
*/ | ||
|
||
public static final IMetaProvider<GenericTileEntity> META_GENERIC_TILE = new BasicMetaProvider<GenericTileEntity>() { | ||
|
||
@Nonnull | ||
@Override | ||
public Map<String, ?> getMeta(@Nonnull GenericTileEntity context) { | ||
Map<String, Object> out = new HashMap<>(4); | ||
|
||
if (GeneralConfig.manageOwnership) { | ||
String ownerName = context.getOwnerName(); | ||
UUID ownerID = context.getOwnerUUID(); | ||
if (ownerName != null && !ownerName.isEmpty() && ownerID != null) { | ||
Map<String, Object> ownerMap = new HashMap<>(2); | ||
ownerMap.put("name", ownerName); | ||
ownerMap.put("id", ownerID.toString()); | ||
out.put("owner", ownerMap); | ||
|
||
int securityChannel = context.getSecurityChannel(); | ||
if (securityChannel != -1) out.put("securityChannel", securityChannel); | ||
} | ||
} | ||
|
||
out.put("infusion", context.getInfused()); | ||
out.put("infusionMax", GeneralConfig.maxInfuse); | ||
|
||
return out; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public GenericTileEntity getExample() { | ||
GenericTileEntity tile = new GenericTileEntity(); | ||
tile.setInfused(5); | ||
tile.setOwner(new EntityPlayerDummy(WorldDummy.INSTANCE)); | ||
|
||
return tile; | ||
} | ||
}; | ||
|
||
//Based on the code in `mcjty.lib.blocks.GenericBlock.intAddInformation` | ||
public static final IMetaProvider<ItemStack> META_GENERIC_ITEM_BLOCK = new ItemStackMetaProvider<GenericItemBlock>( | ||
GenericItemBlock.class | ||
) { | ||
@Nonnull | ||
@Override | ||
public Map<String, ?> getMeta(@Nonnull ItemStack stack, @Nonnull GenericItemBlock item) { | ||
NBTTagCompound nbt = stack.getTagCompound(); | ||
if (nbt == null) return Collections.emptyMap(); | ||
|
||
Map<String, Object> out = new HashMap<>(5); | ||
|
||
if (GeneralConfig.manageOwnership && nbt.hasKey("owner", Constants.NBT.TAG_STRING)) { | ||
String ownerName = nbt.getString("owner"); | ||
if (!ownerName.isEmpty() && nbt.hasKey("idM", Constants.NBT.TAG_LONG) && nbt.hasKey("idL", Constants.NBT.TAG_LONG)) { | ||
Map<String, Object> ownerMap = new HashMap<>(2); | ||
ownerMap.put("name", ownerName); | ||
|
||
UUID ownerID = new UUID(nbt.getLong("idM"), nbt.getLong("idL")); | ||
ownerMap.put("id", ownerID.toString()); | ||
|
||
out.put("owner", ownerMap); | ||
|
||
if (nbt.hasKey("secChannel", Constants.NBT.TAG_INT)) { | ||
int securityChannel = nbt.getInteger("secChannel"); | ||
if (securityChannel != -1) out.put("securityChannel", securityChannel); | ||
} | ||
} | ||
} | ||
|
||
if (nbt.hasKey("Energy", Constants.NBT.TAG_LONG)) out.put("energy", nbt.getLong("Energy")); | ||
|
||
//TODO Find a way to only add the 'infused' properties to ItemBlocks that can actually be infused | ||
//Unfortunately, `mcjty.lib.blocks.GenericItemBlock` doesn't expose the base Block, | ||
// so we can't call `isInfusable`; this results in the 'infusion level' showing on ItemBlocks | ||
// that can't be infused... | ||
if (nbt.hasKey("infused", Constants.NBT.TAG_INT)) out.put("infusion", nbt.getInteger("infusion")); | ||
out.put("infusionMax", GeneralConfig.maxInfuse); | ||
|
||
return out; | ||
} | ||
|
||
//TODO Determine if we can implement `getExample` without having to set the Block and Tile | ||
// Preferably without manually constructing the NBT... | ||
}; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/squiddev/plethora/integration/rftools/IntegrationRFTools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.squiddev.plethora.integration.rftools; | ||
|
||
import mcjty.rftools.RFTools; | ||
import org.squiddev.plethora.api.Injects; | ||
|
||
@Injects(RFTools.MODID) | ||
public final class IntegrationRFTools { | ||
private IntegrationRFTools() { | ||
} | ||
|
||
|
||
/* | ||
*RFTools | ||
* | ||
* | ||
* | ||
*Control | ||
* | ||
* | ||
* | ||
*Dimensions | ||
* Use IMC to get the Dimension Manager, a la `rftools.setup.ModSetup` | ||
* | ||
* | ||
* | ||
*/ | ||
|
||
} |
120 changes: 120 additions & 0 deletions
120
src/main/java/org/squiddev/plethora/integration/xnet/IntegrationXNet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.squiddev.plethora.integration.xnet; | ||
|
||
import mcjty.xnet.XNet; | ||
import mcjty.xnet.blocks.cables.ConnectorTileEntity; | ||
import mcjty.xnet.blocks.facade.FacadeItemBlock; | ||
import mcjty.xnet.blocks.facade.IFacadeSupport; | ||
import mcjty.xnet.init.ModBlocks; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.squiddev.plethora.api.Injects; | ||
import org.squiddev.plethora.api.meta.BaseMetaProvider; | ||
import org.squiddev.plethora.api.meta.BasicMetaProvider; | ||
import org.squiddev.plethora.api.meta.IMetaProvider; | ||
import org.squiddev.plethora.api.meta.ItemStackContextMetaProvider; | ||
import org.squiddev.plethora.api.method.IPartialContext; | ||
import org.squiddev.plethora.api.method.wrapper.ArgumentType; | ||
import org.squiddev.plethora.gameplay.modules.glasses.methods.ArgumentPointHelper; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Injects(XNet.MODID) | ||
public final class IntegrationXNet { | ||
private IntegrationXNet() { | ||
} | ||
|
||
/* | ||
*XNet | ||
* Replicate the 'OC XNet Driver' behavior | ||
* TODO Research how to use 'routing'; hard to provide meta for something you don't know yourself... | ||
* TODO Determine how to expose the mimicked block for an IFacadeSupport | ||
* | ||
*/ | ||
|
||
/* | ||
* Redstone Proxy - Not sure if this is of interest, as we have our own RS support | ||
* Connector | ||
* Confirm that the energy capability is properly exposed (or if it should be...) | ||
* Controller | ||
* Router | ||
* Wireless Router | ||
*/ | ||
|
||
//TODO Determine a better location for this ArgumentType | ||
//REFINE This may not be the most efficient, but it does reduce code duplication... | ||
public static final ArgumentType<BlockPos> BLOCK_POS = ArgumentPointHelper.VEC3D.map(BlockPos::new); | ||
|
||
public static final IMetaProvider<IFacadeSupport> META_FACADE = new BaseMetaProvider<IFacadeSupport>() { | ||
@Nonnull | ||
@Override | ||
public Map<String, ?> getMeta(@Nonnull IPartialContext<IFacadeSupport> context) { | ||
IFacadeSupport target = context.getTarget(); | ||
IBlockState mimicState = target.getMimicBlock(); | ||
|
||
//TODO As an alternative to this, the mimicked block is also exposed as part of the | ||
// IExtendedBlockState; see mcjty.xnet.blocks.cables.ConnectorBlock.getExtendedState | ||
// and mcjty.xnet.blocks.facade.FacadeBlock.getExtendedState | ||
|
||
//REFINE This has one minor edge case: new facades default to cobblestone, | ||
// BUT the mimicState isn't set until the facade is broken! | ||
return mimicState == null | ||
? Collections.emptyMap() | ||
: Collections.singletonMap("mimicState", context.makePartialChild(mimicState).getMeta()); | ||
} | ||
}; | ||
|
||
public static final IMetaProvider<ItemStack> META_FACADE_ITEM = new ItemStackContextMetaProvider<FacadeItemBlock>( | ||
FacadeItemBlock.class | ||
) { | ||
@Nonnull | ||
@Override | ||
public Map<String, ?> getMeta(@Nonnull IPartialContext<ItemStack> context, @Nonnull FacadeItemBlock item) { | ||
//REFINE Technically, we should check if the mimicked block is set (versus using the default)... | ||
// See the behavior in mcjty.xnet.blocks.facade.FacadeItemBlock.getMimicBlock | ||
return Collections.singletonMap("mimicState", context.makePartialChild(FacadeItemBlock.getMimicBlock(context.getTarget()))); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ItemStack getExample() { | ||
return new ItemStack(ModBlocks.facadeBlock); | ||
} | ||
}; | ||
|
||
public static final IMetaProvider<ConnectorTileEntity> META_CONNECTOR= new BasicMetaProvider<ConnectorTileEntity>() { | ||
|
||
@Nonnull | ||
@Override | ||
public Map<String, ?> getMeta(@Nonnull ConnectorTileEntity context) { | ||
Map<String, Object> out = new HashMap<>(); | ||
|
||
Map<String, Boolean> enabledMap = new HashMap<>(EnumFacing.VALUES.length); | ||
for (EnumFacing facing : EnumFacing.VALUES) { | ||
enabledMap.put(facing.toString(), context.isEnabled(facing)); | ||
} | ||
out.put("isEnabled", enabledMap); | ||
|
||
out.put("connectorName", context.getConnectorName()); | ||
|
||
return out; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public ConnectorTileEntity getExample() { | ||
ConnectorTileEntity tile = new ConnectorTileEntity(); | ||
|
||
tile.setConnectorName("Simple Example"); | ||
//MEMO The tile's `enabled` mask defaults to 0x3f, or all enabled | ||
tile.setEnabled(EnumFacing.DOWN, false); | ||
tile.setEnabled(EnumFacing.SOUTH, false); | ||
|
||
return tile; | ||
} | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be inclined just to go with meta-provider. I've always had problems with when to expose something as a getter, and when to do it as metadata, but in this case metadata seems fine.