Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

RFTools and XNet Support #214

Draft
wants to merge 6 commits into
base: minecraft-1.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ dependencies {
integrationMod "cofh:CoFHWorld:1.12.2-1.3.0.6:universal"
compileOnly ("com.enderio:EnderIO:1.12.2-5.0.43") { transitive = false }
compileOnly "com.enderio.core:EnderCore:1.12.2-0.5.57" // EnderCore appears to crash in a development environment.
integrationMod("com.github.mcjty:mcjtylib:1.12-3.5.0") { transitive = false }
integrationMod("com.github.mcjty:rftools:1.12-7.70") { transitive = false }
integrationMod("com.github.mcjty:xnet:1.12-1.8.0") { transitive = false }
//FIXME Revert these to `integrationMod` before merging
deobfCompile("com.github.mcjty:mcjtylib:1.12-3.5.0") { transitive = false }
deobfCompile("com.github.mcjty:rftools:1.12-7.70") { transitive = false }
deobfCompile("mcjty.rftoolsctrl:rftoolsctrl:1.12-2.0.1") { transitive = false }
deobfCompile("com.github.mcjty:xnet:1.12-1.8.0") { transitive = false }
integrationMod "com.mod-buildcraft:buildcraft-all:7.99.22"
integrationMod "hellfirepvp.astralsorcery:astralsorcery:1.12.2-1.10.18-v129"
integrationMod "MCMultiPart2:MCMultiPart:2.5.4"
integrationMod "MCMultiPart2:MCMultiPart:2.5.3"
integrationMod "net.darkhax.tesla:Tesla-1.12.2:1.0.63"
integrationMod "net.industrial-craft:industrialcraft-2:2.8.146-ex112"
integrationMod "net.sengir.forestry:forestry_1.12.2:5.8.2.387:api"
Expand All @@ -116,6 +118,9 @@ dependencies {
integrationMod "roost:roost:1.12:1.3.0"
integrationMod "chickens:chickens:6.0.4"
integrationMod "hatchery:hatchery:1.12.2:2.2.1"
//FIXME Switch to `integrationMod` before merging
//TODO See if this is available via the k-4u.nl Maven repo
deobfCompile("rftools-dimensions:rftoolsdim:1.12:5.70") { transitive = false }

compileOnly('org.squiddev:ConfigGen:1.2.5') { exclude group: 'net.minecraftforge' }

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
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
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);
Copy link
Member

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.


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...
};

}
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`
*
*
*
*/

}
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;
}
};
}
Loading