Glowing components like the indicator light actuall glow in the dark now

Some bugfixes
Complete code reformatting

(Cherry-picked)

# Conflicts:
#	src/main/java/malte0811/industrialWires/IndustrialWires.java
#	src/main/java/malte0811/industrialWires/blocks/BlockIWBase.java
#	src/main/java/malte0811/industrialWires/blocks/EnergyAdapter.java
#	src/main/java/malte0811/industrialWires/blocks/ItemBlockIW.java
#	src/main/java/malte0811/industrialWires/blocks/TileEntityJacobsLadder.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/BlockPanel.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanel.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityPanelCreator.java
#	src/main/java/malte0811/industrialWires/blocks/controlpanel/TileEntityRSPanelConn.java
#	src/main/java/malte0811/industrialWires/blocks/converter/BlockMechanicalConverter.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityIEMotor.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityMechICtoIE.java
#	src/main/java/malte0811/industrialWires/blocks/converter/TileEntityMechIEtoIC.java
#	src/main/java/malte0811/industrialWires/blocks/wire/BlockIC2Connector.java
#	src/main/java/malte0811/industrialWires/blocks/wire/TileEntityIC2ConnectorTin.java
#	src/main/java/malte0811/industrialWires/client/ClientEventHandler.java
#	src/main/java/malte0811/industrialWires/client/gui/GuiPanelComponent.java
#	src/main/java/malte0811/industrialWires/client/gui/GuiPanelCreator.java
#	src/main/java/malte0811/industrialWires/client/gui/elements/GuiIntChooser.java
#	src/main/java/malte0811/industrialWires/containers/ContainerPanelCreator.java
#	src/main/java/malte0811/industrialWires/containers/ContainerRSPanelConn.java
#	src/main/java/malte0811/industrialWires/controlpanel/CoveredToggleSwitch.java
#	src/main/java/malte0811/industrialWires/controlpanel/LightedButton.java
#	src/main/java/malte0811/industrialWires/controlpanel/PanelComponent.java
#	src/main/java/malte0811/industrialWires/controlpanel/PanelUtils.java
#	src/main/java/malte0811/industrialWires/controlpanel/Slider.java
#	src/main/java/malte0811/industrialWires/crafting/RecipeCoilLength.java
#	src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java
#	src/main/java/malte0811/industrialWires/items/ItemPanelComponent.java
#	src/main/java/malte0811/industrialWires/network/MessageGUIInteract.java
#	src/main/java/malte0811/industrialWires/network/MessagePanelInteract.java
#	src/main/java/malte0811/industrialWires/util/MiscUtils.java
This commit is contained in:
malte0811 2017-05-11 16:39:20 +02:00
parent 0f0232469e
commit 0c52514b15
66 changed files with 1191 additions and 719 deletions

View file

@ -20,7 +20,7 @@ package malte0811.industrialWires;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
@Config(modid=IndustrialWires.MODID)
@Config(modid = IndustrialWires.MODID)
public class IWConfig {
@Comment({"The maximum length of a single connection.", "Order: Tin, Copper, Gold, HV, Glass Fiber"})
public static int[] maxLengthPerConn = {16, 16, 16, 32, 32};
@ -29,14 +29,15 @@ public class IWConfig {
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
public static boolean enableConversion = true;
public static MechConversion mc = new MechConversion();
public static MechConversion mech;
public static class MechConversion {
@Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"})
public static double euPerIf = .25;
@Comment({"The amount of IC2 kinetic energy that an ideal converter produces from 1 EU"})
public static double kinPerEu = 4;
@Comment({"The maximum amount of IF that can be converted to rotational energy", "by one motor in one tick (default: 100)"})
public static int maxIfToMech = 100;
@Comment({"The efficiency of the IF motor. The default value of 0.9 means that 10% of the energy are lost in the conversion."})
@ -46,16 +47,18 @@ public class IWConfig {
public static double maxRotToKin = 50;
@Comment({"The efficiency of the conversion from IE rotational energy to IC2 kinetic energy"})
public static double rotToKinEfficiency = .7;
@Comment({"The maximum amount of IC2 kinetic energy that can be converted into IE rotational energy", "by one converter in one tick"})
public static int maxKinToRot = 2400;
@Comment({"The efficiency of the conversion from IC2 kinetic energy to IE rotational energy"})
public static double kinToRotEfficiency = .8;
}
public static HVStuff hv = new HVStuff();
public static HVStuff hv;
public static class HVStuff {
@Comment({"The amount of Eu a Jacobs Ladder uses per tick, sorted by size of the ladder"})
public static double[] jacobsUsageEU = {10, 20, 50};
@Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"})
public static double[] jacobsUsageEU = {20, 50, 100};
@Comment({"The damage dealt by a small Jacobs Ladder. Normal Ladders deal twice this damage, huge ones 3 times as much"})
public static float jacobsBaseDmg = 5;
}

View file

@ -87,7 +87,7 @@ public class IndustrialWires {
return new ItemStack(coil, 1, 2);
}
};
@SidedProxy(clientSide="malte0811.industrialWires.client.ClientProxy", serverSide="malte0811.industrialWires.CommonProxy")
@SidedProxy(clientSide = "malte0811.industrialWires.client.ClientProxy", serverSide = "malte0811.industrialWires.CommonProxy")
public static CommonProxy proxy;
@EventHandler
@ -100,7 +100,6 @@ public class IndustrialWires {
coil = new ItemIC2Coil();
panelComponent = new ItemPanelComponent();
panel = new BlockPanel();
//TODO change to MODID+ when changing to a new MC version
GameRegistry.registerTileEntity(TileEntityIC2ConnectorTin.class, "ic2ConnectorTin");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorCopper.class, "ic2ConnectorCopper");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGold.class, "ic2ConnectorGold");
@ -115,7 +114,7 @@ public class IndustrialWires {
GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID+":mechIcToIe");
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID+":mechIeToIc");
}
if (IC2Wiretype.IC2_TYPES==null) {
if (IC2Wiretype.IC2_TYPES == null) {
throw new IllegalStateException("No IC2 wires registered");
}
proxy.preInit();
@ -129,7 +128,7 @@ public class IndustrialWires {
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 2), " c ", "rcr", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 4), " g ", "rgr", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 6), " i ", "rir", "rir", 'i', "ingotIron", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 8), " c ", "rcr", "rcr",'c', glassCable, 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 8), " c ", "rcr", "rcr", 'c', glassCable, 'r', "itemRubber"));
//RELAYS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 1), " t ", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 3), " c ", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
@ -138,12 +137,12 @@ public class IndustrialWires {
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 2, 9), " c ", "grg", "grg", 'r', "itemRubber", 'c', glassCable, 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
//WIRES
RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, Category.SHAPELESS, "after:forge:shapelessore");
for (int i = 0;i<IC2Wiretype.IC2_TYPES.length;i++) {
for (int i = 0; i < IC2Wiretype.IC2_TYPES.length; i++) {
GameRegistry.addRecipe(new RecipeCoilLength(i));
}
AssemblerHandler.registerRecipeAdapter(RecipeCoilLength.class, new CoilLengthAdapter());
// MECH CONVERTERS
if (mechConv!=null) {
if (mechConv != null) {
ItemStack shaftIron = IC2Items.getItem("crafting", "iron_shaft");
ItemStack shaftSteel = IC2Items.getItem("crafting", "steel_shaft");
ItemStack ironMechComponent = new ItemStack(IEContent.itemMaterial, 1, 8);
@ -204,10 +203,12 @@ public class IndustrialWires {
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
}
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
public void postInit(FMLPostInitializationEvent e) {
proxy.postInit();
}
private class CoilLengthAdapter implements IRecipeAdapter<RecipeCoilLength> {
@Override
public RecipeQuery[] getQueriedInputs(RecipeCoilLength recipe, ItemStack[] in) {
@ -227,6 +228,7 @@ public class IndustrialWires {
}
return ret.toArray(new RecipeQuery[ret.size()]);
}
@Override
public RecipeQuery[] getQueriedInputs(RecipeCoilLength arg0) {
return new RecipeQuery[0];

View file

@ -52,19 +52,20 @@ import java.util.Set;
public abstract class BlockIWBase extends Block {
private IProperty[] properties;
public BlockIWBase(Material mat, String name) {
super(mat);
setHardness(3.0F);
setResistance(15.0F);
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name));
setUnlocalizedName(IndustrialWires.MODID+"."+name);
setUnlocalizedName(IndustrialWires.MODID + "." + name);
setCreativeTab(IndustrialWires.creativeTab);
}
@Override
protected BlockStateContainer createBlockState() {
if (properties==null) {
if (properties == null) {
properties = getProperties();
}
BlockStateContainer cont = super.createBlockState();
@ -82,8 +83,8 @@ public abstract class BlockIWBase extends Block {
if (tile instanceof IHasDummyBlocksIW) {
state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocksIW) tile).isDummy());
}
if (tile instanceof IEBlockInterfaces.IDirectionalTile&&((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation()>=0) {
if (((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation()==2) {
if (tile instanceof IEBlockInterfaces.IDirectionalTile && ((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation() >= 0) {
if (((IEBlockInterfaces.IDirectionalTile) tile).getFacingLimitation() == 2) {
state = state.withProperty(IEProperties.FACING_HORIZONTAL, ((IEBlockInterfaces.IDirectionalTile) tile).getFacing());
} else {
state = state.withProperty(IEProperties.FACING_ALL, ((IEBlockInterfaces.IDirectionalTile) tile).getFacing());
@ -105,7 +106,7 @@ public abstract class BlockIWBase extends Block {
return state;
}
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) {
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) {
return in.withProperty(prop, val);
}
@ -115,9 +116,9 @@ public abstract class BlockIWBase extends Block {
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).breakDummies();
}
if(te instanceof IImmersiveConnectable) {
if(!worldIn.isRemote||!Minecraft.getMinecraft().isSingleplayer())
ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(te), worldIn, !worldIn.isRemote&&worldIn.getGameRules().getBoolean("doTileDrops"));
if (te instanceof IImmersiveConnectable) {
if (!worldIn.isRemote || !Minecraft.getMinecraft().isSingleplayer())
ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(te), worldIn, !worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops"));
}
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
@ -142,7 +143,7 @@ public abstract class BlockIWBase extends Block {
TileEntity te = source.getTileEntity(pos);
if (te instanceof IBlockBoundsIW) {
AxisAlignedBB ret = ((IBlockBoundsIW) te).getBoundingBox();
if (ret!=null) {
if (ret != null) {
return ret;
}
}
@ -154,24 +155,24 @@ public abstract class BlockIWBase extends Block {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof IEBlockInterfaces.IDirectionalTile && Utils.isHammer(heldItem) && !world.isRemote) {
if (te instanceof IEBlockInterfaces.IDirectionalTile && Utils.isHammer(heldItem) && !world.isRemote) {
IEBlockInterfaces.IDirectionalTile directionalTe = (IEBlockInterfaces.IDirectionalTile) te;
if (directionalTe.canHammerRotate(side, hitX, hitY, hitZ, player)) {
EnumFacing f = directionalTe.getFacing();
final EnumFacing original = f;
int limit = directionalTe.getFacingLimitation();
if(limit==0) {
if (limit == 0) {
f = EnumFacing.VALUES[(f.ordinal() + 1) % EnumFacing.VALUES.length];
} else if(limit==1) {
f = player.isSneaking()?f.rotateAround(side.getAxis()).getOpposite():f.rotateAround(side.getAxis());
} else if(limit == 2 || limit == 5) {
f = player.isSneaking()?f.rotateYCCW():f.rotateY();
} else if (limit == 1) {
f = player.isSneaking() ? f.rotateAround(side.getAxis()).getOpposite() : f.rotateAround(side.getAxis());
} else if (limit == 2 || limit == 5) {
f = player.isSneaking() ? f.rotateYCCW() : f.rotateY();
}
if (f!=original) {
if (f != original) {
directionalTe.setFacing(f);
te.markDirty();
world.notifyBlockUpdate(pos,state,state,3);
world.notifyBlockUpdate(pos, state, state, 3);
world.addBlockEvent(pos, this, 255, 0);
}
return true;
@ -187,7 +188,7 @@ public abstract class BlockIWBase extends Block {
@Override
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
boolean def = super.eventReceived(state, worldIn, pos, id, param);
if ((id&255)==255) {
if ((id & 255) == 255) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;
@ -216,5 +217,6 @@ public abstract class BlockIWBase extends Block {
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
protected abstract IProperty[] getProperties();
}

View file

@ -159,7 +159,7 @@ public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacem
@Override
public boolean canPlaceBlockAt(World w, BlockPos pos, ItemStack stack) {
int dummyCount = LadderSize.values()[stack.getMetadata()].dummyCount;
for (int i = 1;i<=dummyCount;i++) {
for (int i = 1; i <= dummyCount; i++) {
if (!w.isAirBlock(pos.up(i))) {
return false;
}

View file

@ -25,16 +25,15 @@ import net.minecraftforge.energy.IEnergyStorage;
public class EnergyAdapter implements IEnergyStorage {
/**
* 3 different copies of the same thing, the TE this adapter is mirroring.
* 2 different copies of the same thing, the TE this adapter is mirroring.
* rec and prov are null if the TE does not implement them
*/
IFluxConnection tile;
IFluxReceiver rec;
IFluxProvider prov;
EnumFacing dir;
private IFluxReceiver rec;
private IFluxProvider prov;
private EnumFacing dir;
public EnergyAdapter(IFluxConnection te, EnumFacing f) {
tile = te;
dir = f;
if (te instanceof IFluxReceiver) {
rec = (IFluxReceiver) te;
@ -43,10 +42,10 @@ public class EnergyAdapter implements IEnergyStorage {
prov = (IFluxProvider) te;
}
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
if (rec==null) {
if (rec == null) {
return 0;
} else {
return rec.receiveEnergy(dir, maxReceive, simulate);
@ -55,7 +54,7 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
if (prov==null) {
if (prov == null) {
return 0;
} else {
return prov.extractEnergy(dir, maxExtract, simulate);
@ -64,9 +63,9 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int getEnergyStored() {
if (prov!=null) {
if (prov != null) {
return prov.getEnergyStored(dir);
} else if (rec!=null) {
} else if (rec != null) {
return rec.getEnergyStored(dir);
} else {
return 0;
@ -75,9 +74,9 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public int getMaxEnergyStored() {
if (prov!=null) {
if (prov != null) {
return prov.getMaxEnergyStored(dir);
} else if (rec!=null) {
} else if (rec != null) {
return rec.getMaxEnergyStored(dir);
} else {
return 0;
@ -86,11 +85,11 @@ public class EnergyAdapter implements IEnergyStorage {
@Override
public boolean canExtract() {
return prov!=null;
return prov != null;
}
@Override
public boolean canReceive() {
return rec!=null;
return rec != null;
}
}

View file

@ -22,6 +22,8 @@ import net.minecraft.block.state.IBlockState;
public interface IHasDummyBlocksIW {
void placeDummies(IBlockState state);
void breakDummies();
boolean isDummy();
}

View file

@ -28,12 +28,15 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class ItemBlockIW extends ItemBlock {
private final Object[] values;
public ItemBlockIW(Block b) {
super(b);
if (b instanceof IMetaEnum) {
values = ((IMetaEnum)b).getValues();
values = ((IMetaEnum) b).getValues();
} else {
values = null;
}
@ -42,19 +45,20 @@ public class ItemBlockIW extends ItemBlock {
@Override
public String getUnlocalizedName(ItemStack stack) {
int meta = stack.getMetadata();
if (values!=null) {
if (values != null) {
return block.getUnlocalizedName() + "." + values[meta].toString().toLowerCase();
} else {
return block.getUnlocalizedName();
}
}
@Override
public int getMetadata(int damage) {
return damage;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) {
public boolean placeBlockAt(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, World world, @Nonnull BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull IBlockState newState) {
if (block instanceof IPlacementCheck&&!((IPlacementCheck) block).canPlaceBlockAt(world, pos, stack)) {
return false;
}

View file

@ -32,6 +32,7 @@ public abstract class TileEntityIWBase extends TileEntity {
writeNBT(nbt, true);
return nbt;
}
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(pos, getBlockMetadata(), getUpdateTag());
@ -41,18 +42,21 @@ public abstract class TileEntityIWBase extends TileEntity {
writeNBT(compound, false);
return super.writeToNBT(compound);
}
@Override
public void readFromNBT(NBTTagCompound compound) {
readNBT(compound, false);
super.readFromNBT(compound);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
readNBT(pkt.getNbtCompound(), true);
}
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
public abstract void readNBT(NBTTagCompound in, boolean updatePacket);
}

View file

@ -159,7 +159,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
} else if (timeTillActive == 0 && t < 1) {
t += tStep;
if (salt > 0) {
salt -= 1D/(20*20);//20 seconds per item of salt
salt -= 1D / (20 * 20);//20 seconds per item of salt
} else if (salt < 0) {
salt = 0;
}
@ -370,7 +370,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
if (!worldObj.isRemote) {
EnumFacing targetDir = facing.rotateAround(EnumFacing.Axis.Y);
for (int i = -dummy;i<size.dummyCount-dummy+1;i++) {
for (int i = -dummy; i < size.dummyCount - dummy + 1; i++) {
BlockPos currPos = pos.up(i);
TileEntity te = world.getTileEntity(currPos);
if (te instanceof TileEntityJacobsLadder) {
@ -378,7 +378,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
teJacobs.facing = targetDir;
teJacobs.markDirty();
IBlockState state = world.getBlockState(currPos).getActualState(world, currPos);
world.notifyBlockUpdate(currPos,state,state,3);
world.notifyBlockUpdate(currPos, state, state, 3);
world.addBlockEvent(currPos, state.getBlock(), 255, 0);
world.notifyBlockOfStateChange(currPos, state.getBlock());
}

View file

@ -43,10 +43,12 @@ import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nonnull;
import java.util.List;
public class BlockPanel extends BlockIWBase implements IMetaEnum {
public static final PropertyEnum<BlockTypes_Panel> type = PropertyEnum.create("type", BlockTypes_Panel.class);
public BlockPanel() {
super(Material.IRON, "control_panel");
lightOpacity = 0;
@ -56,17 +58,17 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
switch (state.getValue(type)) {
case TOP:
return layer==BlockRenderLayer.CUTOUT;
return layer == BlockRenderLayer.CUTOUT;
case RS_WIRE:
return layer==BlockRenderLayer.TRANSLUCENT||layer==BlockRenderLayer.SOLID;
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
default:
return super.canRenderInLayer(state, layer);
}
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
switch(state.getValue(type)) {
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
switch (state.getValue(type)) {
case TOP:
return new TileEntityPanel();
case RS_WIRE:
@ -143,18 +145,22 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
list.add(new ItemStack(itemIn, 1, 2));
list.add(new ItemStack(itemIn, 1, 3));
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
@ -168,7 +174,7 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!super.onBlockActivated(world, pos, state, player, hand, heldItem, side, hitX, hitY, hitZ)&&hand==EnumHand.MAIN_HAND) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityRSPanelConn){
if (te instanceof TileEntityRSPanelConn) {
if (!world.isRemote) {
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
}
@ -182,12 +188,13 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
return false;
}
return state.getValue(type)==BlockTypes_Panel.TOP;
return state.getValue(type) == BlockTypes_Panel.TOP;
}
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
if (state.getValue(type)==BlockTypes_Panel.TOP) {
@Nonnull
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
if (state.getValue(type) == BlockTypes_Panel.TOP) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityPanel) {
return ((TileEntityPanel) te).getTileDrop(player, state);

View file

@ -22,7 +22,7 @@ import net.minecraft.util.IStringSerializable;
import java.util.Locale;
public enum BlockTypes_Panel implements IStringSerializable {
public enum BlockTypes_Panel implements IStringSerializable {
TOP,
RS_WIRE,
DUMMY,

View file

@ -27,6 +27,7 @@ import java.util.ArrayList;
public class PropertyComponents implements IUnlistedProperty<PropertyComponents.PanelRenderProperties> {
public static PropertyComponents INSTANCE = new PropertyComponents();
@Override
public String getName() {
return "components";
@ -34,7 +35,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
@Override
public boolean isValid(PanelRenderProperties value) {
return value!=null;
return value != null;
}
@Override
@ -51,26 +52,31 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
public EnumFacing facing = EnumFacing.NORTH;
public float height = .5F;
public EnumFacing top = EnumFacing.UP;
public PanelRenderProperties() {
super();
}
public PanelRenderProperties(int length) {
super(length);
}
@Override
public String toString() {
StringBuilder ret = new StringBuilder("[");
for (int i = 0;i<size();i++) {
for (int i = 0; i < size(); i++) {
ret.append(get(i));
if (i<size()-1) {
if (i < size() - 1) {
ret.append(", ");
}
}
return ret+"]";
return ret + "]";
}
public Matrix4 getPanelTopTransform() {
return getPanelBaseTransform().translate(0, height, 0);
}
public Matrix4 getPanelBaseTransform() {
Matrix4 ret = new Matrix4();
ret.translate(.5, .5, .5);
@ -84,7 +90,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
case SOUTH:
case WEST:
case EAST:
ret.rotate(Math.PI/2, 1, 0, 0);
ret.rotate(Math.PI / 2, 1, 0, 0);
ret.rotate(top.getHorizontalAngle() * Math.PI / 180, 0, 0, 1);
break;
}
@ -94,18 +100,18 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
public float getMaxHeight() {
float ret = 0;
for (PanelComponent pc:this) {
for (PanelComponent pc : this) {
float hHere = pc.getHeight();
if (hHere>ret) {
if (hHere > ret) {
ret = hHere;
}
}
return ret+height;
return ret + height;
}
public PanelRenderProperties copyOf() {
PanelRenderProperties ret = new PanelRenderProperties(size());
for (PanelComponent pc:this) {
for (PanelComponent pc : this) {
ret.add(pc.copyOf());
}
ret.facing = facing;

View file

@ -27,7 +27,6 @@ import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.controlpanel.*;
import malte0811.industrialWires.network.MessagePanelInteract;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
@ -92,7 +91,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
if (!worldObj.isRemote) {
if (firstTick) {
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
for (BlockPos bp : parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityRSPanelConn&&!rsPorts.contains(te)) {
@ -135,7 +134,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
}
public void readFromItemNBT(@Nullable NBTTagCompound nbt) {
if (nbt!=null) {
if (nbt != null) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
components.height = nbt.getFloat("height");
@ -233,7 +232,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
Vec3d playerPos = Minecraft.getMinecraft().thePlayer.getPositionVector().addVector(-pos.getX(), player.getEyeHeight() - pos.getY(), -pos.getZ());
for (PanelComponent pc : components) {
AxisAlignedBB box = pc.getBlockRelativeAABB();
if (box.maxY>box.minY) {
if (box.maxY > box.minY) {
box = apply(mat, box.expandXyz(.002));
Vec3d hitVec = hitAbs ? hit.addVector(-pos.getX(), -pos.getY(), -pos.getZ()) : hit;
hitVec = hitVec.scale(2).subtract(playerPos);
@ -297,7 +296,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (PanelComponent pc:components) {
for (PanelComponent pc : components) {
pc.invalidate(this);
}
for (TileEntityRSPanelConn rs : rsPorts) {
@ -308,7 +307,7 @@ public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTil
@Override
public void invalidate() {
super.invalidate();
for (PanelComponent pc:components) {
for (PanelComponent pc : components) {
pc.invalidate(this);
}
for (TileEntityRSPanelConn rs : rsPorts) {

View file

@ -18,10 +18,8 @@
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.common.util.IELogger;
import blusunrize.immersiveengineering.common.util.Utils;
import blusunrize.immersiveengineering.common.util.inventory.IIEInventory;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
@ -41,23 +39,23 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInventory, INetGUI, IBlockBoundsIW {
public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI, IBlockBoundsIW {
public List<PanelComponent> components = new ArrayList<>();
public float height = 0.5F;
public ItemStack[] inv = new ItemStack[1];
public ItemStack inv = null;
@Override
public void readNBT(NBTTagCompound nbt, boolean updatePacket) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
height = nbt.getFloat("height");
inv = Utils.readInventory(nbt.getTagList("inventory", 10), inv.length);
inv = Utils.readInventory(nbt.getTagList("inventory", 10), 1)[0];
}
@Override
public void writeNBT(NBTTagCompound nbt, boolean updatePacket) {
writeToItemNBT(nbt, false);
nbt.setTag("inventory", Utils.writeInventory(inv));
nbt.setTag("inventory", Utils.writeInventory(new ItemStack[]{inv}));
}
public void writeToItemNBT(NBTTagCompound nbt, boolean toItem) {
@ -71,29 +69,6 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
nbt.setFloat("height", height);
}
@Override
public ItemStack[] getInventory() {
return inv;
}
@Override
public boolean isStackValid(int slot, ItemStack stack) {
if (slot == 0) {
return ApiUtils.compareToOreName(stack, "plateIron");
}
return true;
}
@Override
public int getSlotLimit(int slot) {
return slot == 0 ? 1 : 64;
}
@Override
public void doGraphicalUpdates(int slot) {
}
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
int type = nbt.getInteger("type");
@ -128,12 +103,12 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
}
break;
case CREATE_PANEL:
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv[0])) {
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv)) {
NBTTagCompound panelNBT = new NBTTagCompound();
writeToItemNBT(panelNBT, true);
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
panel.setTagCompound(panelNBT);
inv[0] = panel;
inv = panel;
components.clear();
}
break;
@ -152,12 +127,12 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
}
break;
case DISASSEMBLE:
if (components.size() == 0 && inv[0] != null && inv[0].getItem() == PanelUtils.PANEL_ITEM) {
if (components.size() == 0 && inv != null && inv.getItem() == PanelUtils.PANEL_ITEM) {
TileEntityPanel te = new TileEntityPanel();
te.readFromItemNBT(inv[0].getTagCompound());
te.readFromItemNBT(inv.getTagCompound());
components = new ArrayList<>(te.getComponents());
height = te.getComponents().height;
inv[0] = null;
inv = null;
}
break;
}
@ -166,7 +141,8 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
worldObj.notifyBlockUpdate(pos, state, state, 3);
}
private static final AxisAlignedBB aabb = new AxisAlignedBB(0, 0,0, 1, 14/16D, 1);
private static final AxisAlignedBB aabb = new AxisAlignedBB(0, 0, 0, 1, 14 / 16D, 1);
@Override
public AxisAlignedBB getBoundingBox() {
return aabb;

View file

@ -29,7 +29,7 @@ import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.util.MiscUtils;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -59,11 +59,13 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
private RedstoneWireNetwork network = new RedstoneWireNetwork().add(this);
private boolean hasConn = false;
private int id;
{
for (int i = 0;i<16;i++) {
for (int i = 0; i < 16; i++) {
oldInput[i] = -1;
}
}
private boolean loaded = false;
@Override
@ -73,7 +75,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
loaded = true;
// completely reload the network
network.removeFromNetwork(null);
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
for (BlockPos bp:parts) {
TileEntity te = worldObj.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
@ -87,6 +89,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
}
}
@Override
public void writeCustomNBT(NBTTagCompound out, boolean updatePacket) {
super.writeCustomNBT(out, updatePacket);
@ -106,8 +109,8 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
aabb = null;
}
private BiConsumer<Integer, Byte> rsOut = (channel, value)->{
if (value!=out[channel]) {
private BiConsumer<Integer, Byte> rsOut = (channel, value) -> {
if (value != out[channel]) {
dirty = true;
out[channel] = value;
}
@ -115,9 +118,9 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void registerPanel(TileEntityPanel panel) {
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc:p) {
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener!=null) {
if (listener != null) {
changeListeners.add(listener);
}
pc.registerRSOutput(id, rsOut);
@ -128,9 +131,9 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void unregisterPanel(TileEntityPanel panel, boolean remove) {
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc:p) {
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener!=null) {
if (listener != null) {
changeListeners.remove(listener);
}
pc.unregisterRSOutput(id, rsOut);
@ -156,7 +159,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
public void onChange() {
if (!Arrays.equals(oldInput, network.channelValues)) {
oldInput = Arrays.copyOf(network.channelValues, 16);
for (Consumer<byte[]> c:changeListeners) {
for (Consumer<byte[]> c : changeListeners) {
c.accept(oldInput);
}
}
@ -164,7 +167,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void updateInput(byte[] currIn) {
for (int i = 0;i<16;i++) {
for (int i = 0; i < 16; i++) {
currIn[i] = (byte) Math.max(currIn[i], out[i]);
}
}
@ -176,13 +179,13 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public boolean canConnectCable(WireType wire, TargetingInfo targetingInfo) {
return wire==WireType.REDSTONE&&!hasConn;
return wire == WireType.REDSTONE && !hasConn;
}
@Override
public void connectCable(WireType wireType, TargetingInfo targetingInfo, IImmersiveConnectable other) {
hasConn = true;
if (other instanceof IRedstoneConnector&&((IRedstoneConnector) other).getNetwork()!=network) {
if (other instanceof IRedstoneConnector && ((IRedstoneConnector) other).getNetwork() != network) {
network.mergeNetwork(((IRedstoneConnector) other).getNetwork());
}
}
@ -224,7 +227,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (TileEntityPanel panel:connectedPanels) {
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false);
}
}
@ -232,7 +235,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void invalidate() {
super.invalidate();
for (TileEntityPanel panel:connectedPanels) {
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false);
}
}
@ -240,7 +243,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
if (nbt.hasKey("rsId")) {
List<BlockPos> parts = MiscUtils.discoverPanelParts(worldObj, pos);
List<BlockPos> parts = PanelUtils.discoverPanelParts(worldObj, pos);
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
for (BlockPos bp:parts) {
TileEntity te = worldObj.getTileEntity(bp);
@ -251,7 +254,7 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
id = nbt.getInteger("rsId");
out = new byte[16];
for (TileEntityPanel panel:tes) {
for (TileEntityPanel panel : tes) {
registerPanel(panel);
}
network.updateValues();
@ -301,28 +304,29 @@ public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implem
}
private AxisAlignedBB aabb;
@Override
public AxisAlignedBB getBoundingBox() {
if (aabb==null) {
if (aabb == null) {
double h = 9 / 16D;
switch (facing) {
case DOWN:
aabb = new AxisAlignedBB(0, 0, 0, 1, h, 1);
break;
case UP:
aabb = new AxisAlignedBB(0, 1-h, 0, 1, 1, 1);
aabb = new AxisAlignedBB(0, 1 - h, 0, 1, 1, 1);
break;
case NORTH:
aabb = new AxisAlignedBB(0, 0, 0, 1, 1, h);
break;
case SOUTH:
aabb = new AxisAlignedBB(0, 0, 1-h, 1, 1, 1);
aabb = new AxisAlignedBB(0, 0, 1 - h, 1, 1, 1);
break;
case WEST:
aabb = new AxisAlignedBB(0, 0, 0, h, 1, 1);
break;
case EAST:
aabb = new AxisAlignedBB(1-h, 0, 0, 1, 1, 1);
aabb = new AxisAlignedBB(1 - h, 0, 0, 1, 1, 1);
break;
}
}

View file

@ -35,17 +35,19 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.List;
public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
private static PropertyEnum<MechanicalBlockType> type = PropertyEnum.create("type", MechanicalBlockType.class);
public BlockMechanicalConverter() {
super(Material.IRON, "mechanical_converter");
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0;i<3;i++) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0; i < 3; i++) {
list.add(new ItemStack(itemIn, 1, i));
}
}
@ -87,6 +89,7 @@ public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
public int getMetaFromState(IBlockState state) {
return state.getValue(type).ordinal();
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, ItemStack stack) {
@ -102,11 +105,12 @@ public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
EntityPlayer player) {
return new ItemStack(this, 1, damageDropped(state));
}
@Override
@SuppressWarnings("deprecation")
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
boolean def = super.eventReceived(state, worldIn, pos, id, param);
if ((id&255)==255) {
if ((id & 255) == 255) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;

View file

@ -34,13 +34,16 @@ import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import javax.annotation.Nonnull;
public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IFluxReceiver, IDirectionalTile {
public final double bufferMax = 2*MechConversion.maxIfToMech*ConversionUtil.rotPerIf();
public final double bufferMax = 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf();
private double rotBuffer = 0;
private FluxStorage energy = new FluxStorage(20*MechConversion.maxIfToMech, 2*MechConversion.maxIfToMech);
private FluxStorage energy = new FluxStorage(20 * MechConversion.maxIfToMech, 2 * MechConversion.maxIfToMech);
private EnumFacing dir = EnumFacing.DOWN;
private BlockPos receiver;
@Override
public void update() {
if (!worldObj.isRemote) {
@ -49,14 +52,14 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
}
int max = MechConversion.maxIfToMech;
boolean dirty = false;
if (rotBuffer<bufferMax&&energy.extractEnergy(max, true)>0) {
if (rotBuffer < bufferMax && energy.extractEnergy(max, true) > 0) {
int extracted = energy.extractEnergy(max, false);
rotBuffer += extracted*ConversionUtil.rotPerIf()*MechConversion.ifMotorEfficiency;
rotBuffer += extracted * ConversionUtil.rotPerIf() * MechConversion.ifMotorEfficiency;
dirty = true;
}
TileEntity te = worldObj.getTileEntity(receiver);
if (te instanceof IRotationAcceptor) {
((IRotationAcceptor)te).inputRotation(rotBuffer, dir);
((IRotationAcceptor) te).inputRotation(rotBuffer, dir);
rotBuffer = 0;
dirty = true;
}
@ -65,6 +68,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
}
}
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
@ -72,6 +76,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
receiver = null;
rotBuffer = in.getDouble(BUFFER_TAG);
}
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIR_TAG, (byte) dir.getIndex());
@ -84,8 +89,9 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
// Flux energy
@Override
public boolean canConnectEnergy(EnumFacing from) {
return from==dir.getOpposite()||from==null;
return from == dir.getOpposite() || from == null;
}
@Override
public int receiveEnergy(EnumFacing from, int energyIn, boolean simulate) {
if (canConnectEnergy(from)) {
@ -96,10 +102,12 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
return 0;
}
}
@Override
public int getEnergyStored(EnumFacing from) {
return energy.getEnergyStored();
}
@Override
public int getMaxEnergyStored(EnumFacing from) {
return energy.getMaxEnergyStored();
@ -110,35 +118,42 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
receiver = null;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if (capability==CapabilityEnergy.ENERGY&&canConnectEnergy(facing)) {
public boolean hasCapability(@Nonnull Capability<?> capability, @Nonnull EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
return true;
}
return super.hasCapability(capability, facing);
}
@Nonnull
@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability==CapabilityEnergy.ENERGY&&canConnectEnergy(facing)) {
public <T> T getCapability(@Nonnull Capability<T> capability, @Nonnull EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
return (T) new EnergyAdapter(this, facing);
}
return super.getCapability(capability, facing);

View file

@ -33,32 +33,33 @@ import net.minecraft.util.math.BlockPos;
public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirectionalTile, ITickable {
EnumFacing dir = EnumFacing.DOWN;
int kinBuffer = 0;
private final int kinBufMax = 2*MechConversion.maxKinToRot;
private final double maxInsert = ConversionUtil.rotPerKin()*MechConversion.maxKinToRot;
private final int kinBufMax = 2 * MechConversion.maxKinToRot;
private final double maxInsert = ConversionUtil.rotPerKin() * MechConversion.maxKinToRot;
BlockPos to;
BlockPos from;
@Override
public void update() {
if (!worldObj.isRemote) {
if (to==null) {
to = pos.offset(dir);
}
if (from==null) {
if (from == null) {
from = pos.offset(dir, -1);
}
TileEntity teFrom = worldObj.getTileEntity(from);
if (teFrom instanceof IKineticSource) {
int sourceMax = ((IKineticSource) teFrom).maxrequestkineticenergyTick(dir);
int draw = Math.min(kinBufMax-kinBuffer, sourceMax);
if (draw>0) {
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw)*MechConversion.kinToRotEfficiency;
int draw = Math.min(kinBufMax - kinBuffer, sourceMax);
if (draw > 0) {
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw) * MechConversion.kinToRotEfficiency;
}
}
TileEntity teTo = worldObj.getTileEntity(to);
if (kinBuffer>0&&teTo instanceof IRotationAcceptor) {
double out = Math.min(maxInsert, ConversionUtil.rotPerKin()*kinBuffer);
((IRotationAcceptor) teTo).inputRotation(out, dir);
kinBuffer -= out*ConversionUtil.kinPerRot();
kinBuffer -= out * ConversionUtil.kinPerRot();
}
}
}
@ -76,11 +77,13 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
to = null;
from = null;
}
// Directional
@Override
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
@ -88,18 +91,22 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
from = null;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
@Override
public boolean canRotate(EnumFacing axis) {
return true;

View file

@ -27,12 +27,14 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import javax.annotation.Nonnull;
public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirectionalTile, IRotationAcceptor, IKineticSource {
EnumFacing dir = EnumFacing.DOWN;
double rotBuffer = 0;
private final double rotBufMax = 2*MechConversion.maxRotToKin;
private final int maxOutput = (int)(ConversionUtil.kinPerRot()*MechConversion.maxRotToKin);
private final double rotBufMax = 2 * MechConversion.maxRotToKin;
private final int maxOutput = (int) (ConversionUtil.kinPerRot() * MechConversion.maxRotToKin);
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIR_TAG, (byte) dir.getIndex());
@ -44,32 +46,38 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
rotBuffer = in.getDouble(BUFFER_TAG);
}
// Directional
@Override
public EnumFacing getFacing() {
return dir;
}
@Override
public void setFacing(EnumFacing facing) {
dir = facing;
markDirty();
}
@Override
public int getFacingLimitation() {
return 1;
}
@Override
public boolean mirrorFacingOnPlacement(EntityLivingBase placer) {
return false;
}
@Override
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return true;
}
//IC2 kinetic
@Override
public int maxrequestkineticenergyTick(EnumFacing f) {
if (f==dir) {
if (f == dir) {
return maxOutput;
} else {
return 0;
@ -78,24 +86,25 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
@Override
public int requestkineticenergy(EnumFacing f, int requested) {
if (f==dir) {
int stored = (int) (ConversionUtil.kinPerRot()*rotBuffer);
if (f == dir) {
int stored = (int) (ConversionUtil.kinPerRot() * rotBuffer);
int out = Math.min(maxOutput, stored);
out = Math.min(requested, out);
rotBuffer -= out*ConversionUtil.rotPerKin();
return (int)(out*MechConversion.rotToKinEfficiency);
rotBuffer -= out * ConversionUtil.rotPerKin();
return (int) (out * MechConversion.rotToKinEfficiency);
} else {
return 0;
}
}
//IE rotation
@Override
public void inputRotation(double rotation, EnumFacing side) {
if (side==dir) {
rotBuffer = Math.min(rotBufMax, rotBuffer+rotation);
public void inputRotation(double rotation, @Nonnull EnumFacing side) {
if (side == dir) {
rotBuffer = Math.min(rotBufMax, rotBuffer + rotation);
}
}
@Override
public boolean canRotate(EnumFacing axis) {
return true;

View file

@ -21,13 +21,16 @@ import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -39,11 +42,13 @@ import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.List;
public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
private static PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
public BlockIC2Connector() {
super(Material.IRON, "ic2Connector");
setHardness(3.0F);
@ -54,9 +59,9 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileEntityIC2ConnectorTin) {
if (te instanceof TileEntityIC2ConnectorTin) {
TileEntityIC2ConnectorTin connector = (TileEntityIC2ConnectorTin) te;
if(world.isAirBlock(pos.offset(connector.f))) {
if (world.isAirBlock(pos.offset(connector.f))) {
this.dropBlockAsItem(connector.getWorld(), pos, world.getBlockState(pos), 0);
connector.getWorld().setBlockToAir(pos);
}
@ -64,7 +69,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0;i<type.getAllowedValues().size();i++) {
list.add(new ItemStack(itemIn, 1, i));
}
@ -74,8 +79,8 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
protected BlockStateContainer createBlockState() {
BlockStateContainer base = super.createBlockState();
IUnlistedProperty<?>[] unlisted = (base instanceof ExtendedBlockState) ? ((ExtendedBlockState) base).getUnlistedProperties().toArray(new IUnlistedProperty[0]) : new IUnlistedProperty[0];
unlisted = Arrays.copyOf(unlisted, unlisted.length+1);
unlisted[unlisted.length-1] = IEProperties.CONNECTIONS;
unlisted = Arrays.copyOf(unlisted, unlisted.length + 1);
unlisted[unlisted.length - 1] = IEProperties.CONNECTIONS;
return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
}
@ -135,22 +140,37 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
return null;
}
@Override
public boolean canRenderInLayer(BlockRenderLayer layer) {
return layer==BlockRenderLayer.TRANSLUCENT||layer==BlockRenderLayer.SOLID;
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack!=null && stack.getMetadata() % 2 == 0) {
int type = stack.getMetadata() / 2;
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", type + 1));
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.IC2_TYPES[type].getTransferRate() / 8));
}
}
@Override
public boolean canRenderInLayer(IBlockState state, @Nonnull BlockRenderLayer layer) {
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
}
@Override
public boolean isFullBlock(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;

View file

@ -30,6 +30,7 @@ public enum BlockTypes_IC2_Connector implements IBlockEnum {
HV_RELAY,
GLASS_CONN,
GLASS_RELAY;
@Override
public String getName() {
return toString().toLowerCase();

View file

@ -26,15 +26,17 @@ public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorCopper() {}
public TileEntityIC2ConnectorCopper() {
}
{
tier = 2;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[1];
return t == IC2Wiretype.IC2_TYPES[1];
}
}

View file

@ -25,14 +25,16 @@ public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorHV {
super(rel);
}
public TileEntityIC2ConnectorGlass() {}
public TileEntityIC2ConnectorGlass() {
}
{
tier = 5;
maxStored = IC2Wiretype.IC2_TYPES[4].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[4].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[4];
return t == IC2Wiretype.IC2_TYPES[4];
}
}

View file

@ -30,26 +30,29 @@ public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorGold() {}
public TileEntityIC2ConnectorGold() {
}
{
tier = 3;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[2];
return t == IC2Wiretype.IC2_TYPES[2];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5+side.getFrontOffsetX()*.125, .5+side.getFrontOffsetY()*.125, .5+side.getFrontOffsetZ()*.125);
return new Vec3d(.5 + side.getFrontOffsetX() * .125, .5 + side.getFrontOffsetY() * .125, .5 + side.getFrontOffsetZ() * .125);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter()/2;
return new Vec3d(.5+side.getFrontOffsetX()*(.0625-conRadius), .5+side.getFrontOffsetY()*(.0625-conRadius), .5+side.getFrontOffsetZ()*(.0625-conRadius));
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 + side.getFrontOffsetX() * (.0625 - conRadius), .5 + side.getFrontOffsetY() * (.0625 - conRadius), .5 + side.getFrontOffsetZ() * (.0625 - conRadius));
}
}

View file

@ -30,34 +30,37 @@ public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
super(rel);
}
public TileEntityIC2ConnectorHV() {}
public TileEntityIC2ConnectorHV() {
}
{
tier = 4;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate()/8;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[3];
return t == IC2Wiretype.IC2_TYPES[3];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
if (relay) {
return new Vec3d(.5+side.getFrontOffsetX()*.4375, .5+side.getFrontOffsetY()*.4375, .5+side.getFrontOffsetZ()*.4375);
return new Vec3d(.5 + side.getFrontOffsetX() * .4375, .5 + side.getFrontOffsetY() * .4375, .5 + side.getFrontOffsetZ() * .4375);
} else {
return new Vec3d(.5+side.getFrontOffsetX()*.3125, .5+side.getFrontOffsetY()*.3125, .5+side.getFrontOffsetZ()*.3125);
return new Vec3d(.5 + side.getFrontOffsetX() * .3125, .5 + side.getFrontOffsetY() * .3125, .5 + side.getFrontOffsetZ() * .3125);
}
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter()/2;
double conRadius = con.cableType.getRenderDiameter() / 2;
if (relay) {
return new Vec3d(.5+side.getFrontOffsetX()*(.375-conRadius), .5+side.getFrontOffsetY()*(.375-conRadius), .5+side.getFrontOffsetZ()*(.375-conRadius));
return new Vec3d(.5 + side.getFrontOffsetX() * (.375 - conRadius), .5 + side.getFrontOffsetY() * (.375 - conRadius), .5 + side.getFrontOffsetZ() * (.375 - conRadius));
} else {
return new Vec3d(.5+side.getFrontOffsetX()*(.25-conRadius), .5+side.getFrontOffsetY()*(.25-conRadius), .5+side.getFrontOffsetZ()*(.25-conRadius));
return new Vec3d(.5 + side.getFrontOffsetX() * (.25 - conRadius), .5 + side.getFrontOffsetY() * (.25 - conRadius), .5 + side.getFrontOffsetZ() * (.25 - conRadius));
}
}
}

View file

@ -60,12 +60,16 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
//IE net to IC2 net buffer
private double outBuffer = 0;
private double maxToMachine = 0;
protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate()/8;
protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate() / 8;
int tier = 1;
public TileEntityIC2ConnectorTin(boolean rel) {
relay = rel;
}
public TileEntityIC2ConnectorTin() {}
public TileEntityIC2ConnectorTin() {
}
@Override
public void update() {
if (first) {
@ -76,32 +80,33 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
if (!worldObj.isRemote&&inBuffer>.1)
transferPower();
}
public void transferPower() {
Set<AbstractConnection> conns = new HashSet<>(ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, worldObj));
Map<AbstractConnection, Pair<IIC2Connector, Double>> maxOutputs = new HashMap<>();
double outputMax = Math.min(inBuffer, maxToNet);
double sum = 0;
for (AbstractConnection c:conns) {
for (AbstractConnection c : conns) {
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, worldObj);
if (iic instanceof IIC2Connector) {
double tmp = outputMax-((IIC2Connector)iic).insertEnergy(outputMax, true);
if (tmp>.00000001) {
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector)iic, tmp));
sum+=tmp;
double tmp = inBuffer - ((IIC2Connector) iic).insertEnergy(outputMax, true);
if (tmp > .00000001) {
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector) iic, tmp));
sum += tmp;
}
}
}
if (sum<.0001) {
if (sum < .0001) {
return;
}
final double oldInBuf = outputMax;
HashMap<Connection, Integer> transferedPerConn = ImmersiveNetHandler.INSTANCE.getTransferedRates(worldObj.provider.getDimension());
for (AbstractConnection c:maxOutputs.keySet()) {
Pair<IIC2Connector, Double> p = maxOutputs.get(c);
double out = oldInBuf*p.getRight()/sum;
double out = oldInBuf * p.getRight() / sum;
double loss = getAverageLossRate(c);
double inserted = out-p.getLeft().insertEnergy(out-loss, false);
inBuffer-=inserted;
double inserted = out - p.getLeft().insertEnergy(out - loss, false);
inBuffer -= inserted;
float intermediaryLoss = 0;
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
double energyAtConn = inserted+loss;
@ -119,30 +124,33 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
}
}
public double getAverageLossRate(AbstractConnection conn) {
double f = 0;
for(Connection c : conn.subConnections) {
f += c.length*c.cableType.getLossRatio();
for (Connection c : conn.subConnections) {
f += c.length * c.cableType.getLossRatio();
}
return f;
}
//Input through the net
@Override
public double insertEnergy(double eu, boolean simulate) {
final double insert = Math.min(maxStored-outBuffer, eu);
if (insert>0) {
if (outBuffer<maxToMachine) {
final double insert = Math.min(maxStored - outBuffer, eu);
if (insert > 0) {
if (outBuffer < maxToMachine) {
maxToMachine = outBuffer;
}
if (eu>maxToMachine) {
if (eu > maxToMachine) {
maxToMachine = eu;
}
}
if (!simulate) {
outBuffer+=insert;
outBuffer += insert;
}
return eu-insert;
return eu - insert;
}
@Override
public void invalidate() {
if (!worldObj.isRemote&&!first)
@ -150,6 +158,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
first = true;
super.invalidate();
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
@ -161,28 +170,33 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5+side.getFrontOffsetX()*.0625, .5+side.getFrontOffsetY()*.0625, .5+side.getFrontOffsetZ()*.0625);
return new Vec3d(.5 + side.getFrontOffsetX() * .0625, .5 + side.getFrontOffsetY() * .0625, .5 + side.getFrontOffsetZ() * .0625);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter()/2;
return new Vec3d(.5-conRadius*side.getFrontOffsetX(), .5-conRadius*side.getFrontOffsetY(), .5-conRadius*side.getFrontOffsetZ());
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 - conRadius * side.getFrontOffsetX(), .5 - conRadius * side.getFrontOffsetY(), .5 - conRadius * side.getFrontOffsetZ());
}
@Override
public boolean canConnect() {
return true;
}
@Override
public boolean isEnergyOutput() {
return !relay;
}
@Override
public boolean canConnectCable(WireType cableType, TargetingInfo target) {
return (limitType==null||(this.isRelay() && limitType==cableType))&&canConnect(cableType);
return (limitType == null || (this.isRelay() && limitType == cableType)) && canConnect(cableType);
}
public boolean canConnect(WireType t) {
return t==IC2Wiretype.IC2_TYPES[0];
return t == IC2Wiretype.IC2_TYPES[0];
}
@Override
@ -192,18 +206,18 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing side) {
return !relay&&side==f;
return !relay && side == f;
}
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing side) {
return !relay&&side==f;
return !relay && side == f;
}
@Override
public double getDemandedEnergy() {
double ret = maxStored-inBuffer;
if (ret<.1)
double ret = maxStored + .5 - inBuffer;
if (ret < .1)
ret = 0;
return ret;
}
@ -215,12 +229,12 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
if (inBuffer<maxStored) {
if (inBuffer<maxToNet) {
if (inBuffer < maxStored) {
if (inBuffer < maxToNet) {
maxToNet = inBuffer;
}
inBuffer += amount;
if (amount>maxToNet) {
if (amount > maxToNet) {
maxToNet = amount;
}
markDirty();
@ -302,26 +316,26 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
@Override
public AxisAlignedBB getBoundingBox() {
float length = this instanceof TileEntityIC2ConnectorHV?(relay?.875f:.75f): this instanceof TileEntityIC2ConnectorGold?.5625f: .5f;
float length = this instanceof TileEntityIC2ConnectorHV ? (relay ? .875f : .75f) : this instanceof TileEntityIC2ConnectorGold ? .5625f : .5f;
float wMin = .3125f;
float wMax = .6875f;
switch(f.getOpposite() )
{
switch (f.getOpposite()) {
case UP:
return new AxisAlignedBB(wMin,0,wMin, wMax,length,wMax);
return new AxisAlignedBB(wMin, 0, wMin, wMax, length, wMax);
case DOWN:
return new AxisAlignedBB(wMin,1-length,wMin, wMax,1,wMax);
return new AxisAlignedBB(wMin, 1 - length, wMin, wMax, 1, wMax);
case SOUTH:
return new AxisAlignedBB(wMin,wMin,0, wMax,wMax,length);
return new AxisAlignedBB(wMin, wMin, 0, wMax, wMax, length);
case NORTH:
return new AxisAlignedBB(wMin,wMin,1-length, wMax,wMax,1);
return new AxisAlignedBB(wMin, wMin, 1 - length, wMax, wMax, 1);
case EAST:
return new AxisAlignedBB(0,wMin,wMin, length,wMax,wMax);
return new AxisAlignedBB(0, wMin, wMin, length, wMax, wMax);
case WEST:
return new AxisAlignedBB(1-length,wMin,wMin, 1,wMax,wMax);
return new AxisAlignedBB(1 - length, wMin, wMin, 1, wMax, wMax);
}
return new AxisAlignedBB(0,0,0,1,1,1);
return new AxisAlignedBB(0, 0, 0, 1, 1, 1);
}
/*
* regarding equals+hashCode
* TE's are considered equal if they have the same pos+dimension id
@ -334,15 +348,16 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
ret = 31*ret+pos.hashCode();
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj==this) {
if (obj == this) {
return true;
}
if (!(obj instanceof TileEntityIC2ConnectorTin)) {
return false;
}
if (obj.getClass()!=getClass()) {
if (obj.getClass() != getClass()) {
return false;
}
TileEntityIC2ConnectorTin te = (TileEntityIC2ConnectorTin) obj;
@ -354,6 +369,7 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
}
return true;
}
@Override
public boolean canRotate(EnumFacing axis) {
return false;

View file

@ -51,27 +51,27 @@ public class ClientEventHandler {
for(EnumHand hand : EnumHand.values()) {
if(player.getHeldItem(hand)!=null) {
ItemStack equipped = player.getHeldItem(hand);
if(OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
if (OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
IC2Wiretype type = IC2Wiretype.IC2_TYPES[equipped.getItemDamage()];
int color = type.getColour(null);
String s = I18n.format(IndustrialWires.MODID+".desc.wireLength", ItemIC2Coil.getLength(equipped));
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth()/2 - ClientUtils.font().getStringWidth(s)/2, e.getResolution().getScaledHeight()-GuiIngameForge.left_height-40, color, true);
if(ItemNBTHelper.hasKey(equipped, "linkingPos")) {
String s = I18n.format(IndustrialWires.MODID + ".desc.wireLength", ItemIC2Coil.getLength(equipped));
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 40, color, true);
if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
if(link!=null&&link.length>3) {
s = I18n.format(Lib.DESC_INFO+"attachedTo", link[1],link[2],link[3]);
if (link != null && link.length > 3) {
s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
RayTraceResult focussedBlock = ClientUtils.mc().objectMouseOver;
double distSquared;
if (focussedBlock!=null&&focussedBlock.getBlockPos()!=null) {
distSquared = focussedBlock.getBlockPos().distanceSq(link[1],link[2],link[3]);
if (focussedBlock != null && focussedBlock.typeOfHit == RayTraceResult.Type.BLOCK) {
distSquared = focussedBlock.getBlockPos().distanceSq(link[1], link[2], link[3]);
} else {
distSquared = player.getDistanceSq(link[1],link[2],link[3]);
distSquared = player.getDistanceSq(link[1], link[2], link[3]);
}
int length = Math.min(ItemIC2Coil.getLength(equipped), type.getMaxLength());
if (length*length<distSquared) {
if (length * length < distSquared) {
color = 0xdd3333;
}
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth()/2 - ClientUtils.font().getStringWidth(s)/2, e.getResolution().getScaledHeight()-GuiIngameForge.left_height-20, color, true);
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, color, true);
}
}
}
@ -94,8 +94,9 @@ public class ClientEventHandler {
}
}
}
@SubscribeEvent
public void bakeModel(ModelBakeEvent event) {
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID+":control_panel", "inventory,type=top"), new PanelModel());
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=top"), new PanelModel());
}
}

View file

@ -182,7 +182,7 @@ public class ClientProxy extends CommonProxy {
}
ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> {
if (pass==1) {
if (pass == 1) {
PanelComponent pc = ItemPanelComponent.componentFromStack(stack);
if (pc != null) {
return 0xff000000 | pc.getColor();
@ -245,6 +245,7 @@ public class ClientProxy extends CommonProxy {
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
@Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
if (playingSounds.containsKey(te.getPos())) {
@ -265,14 +266,14 @@ public class ClientProxy extends CommonProxy {
default:
return;
}
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float)soundPos.xCoord, (float)soundPos.yCoord, (float) soundPos.zCoord);
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float) soundPos.xCoord, (float) soundPos.yCoord, (float) soundPos.zCoord);
ClientUtils.mc().getSoundHandler().playSound(sound);
playingSounds.put(te.getPos(), sound);
}
@Override
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID==0) {
if (ID == 0) {
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
if (te instanceof TileEntityRSPanelConn) {
return new GuiRSPanelConn((TileEntityRSPanelConn) te);
@ -280,7 +281,7 @@ public class ClientProxy extends CommonProxy {
if (te instanceof TileEntityPanelCreator) {
return new GuiPanelCreator(player.inventory, (TileEntityPanelCreator) te);
}
} else if (ID==1) {
} else if (ID == 1) {
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
ItemStack held = player.getHeldItem(h);
if (held != null && held.getItem() == IndustrialWires.panelComponent) {

View file

@ -32,16 +32,24 @@ public class RawQuad {
public final float[] colorA;
public final Vector3f normal;
public final float[] uvs;
public int light;
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
Vector3f normal, float[] uvs) {
this(v0, v1, v2, v3, facing, tex, colorA, normal, uvs, -1);
}
public RawQuad(Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3,
EnumFacing facing, TextureAtlasSprite tex, float[] colorA,
Vector3f normal, float[] uvs, int light) {
vertices[0] = v0;
vertices[1] = v1;
vertices[2] = v2;
vertices[3] = v3;
this.facing = facing;
this.tex = tex;
if (colorA.length==3) {
if (colorA.length == 3) {
this.colorA = Arrays.copyOf(colorA, 4);
this.colorA[3] = 1;
} else {
@ -49,7 +57,9 @@ public class RawQuad {
}
this.normal = normal;
this.uvs = uvs;
this.light = light;
}
public RawQuad apply(Matrix4 mat) {
Matrix4 matNormal = mat.copy().transpose();
matNormal.invert();

View file

@ -53,9 +53,9 @@ public class GuiPanelComponent extends GuiContainer {
confComp = (IConfigurableComponent) component;
IConfigurableComponent.BoolConfig[] bools = confComp.getBooleanOptions();
boolButtons.clear();
int componentLeft = this.guiLeft+5;
int componentTop = this.guiTop+5;
for (int i = 0;i<bools.length;i++) {
int componentLeft = this.guiLeft + 5;
int componentTop = this.guiTop + 5;
for (int i = 0; i < bools.length; i++) {
IConfigurableComponent.BoolConfig bc = bools[i];
boolButtons.add(new GuiButtonCheckbox(0, componentLeft + bc.x, componentTop + bc.y, confComp.fomatConfigName(IConfigurableComponent.ConfigType.BOOL, i), bc.value));
}
@ -78,22 +78,23 @@ public class GuiPanelComponent extends GuiContainer {
intChoosers.clear();
IConfigurableComponent.IntConfig[] is = confComp.getIntegerOptions();
for (IConfigurableComponent.IntConfig ic : is) {
intChoosers.add(new GuiIntChooser(componentLeft+ic.x, componentTop+ic.y, ic.allowNegative, ic.value, ic.digits));
intChoosers.add(new GuiIntChooser(componentLeft + ic.x, componentTop + ic.y, ic.allowNegative, ic.value, ic.digits));
}
floatSliders.clear();
IConfigurableComponent.FloatConfig[] fs = confComp.getFloatOptions();
for (int i = 0;i<fs.length;i++) {
for (int i = 0; i < fs.length; i++) {
IConfigurableComponent.FloatConfig fc = fs[i];
floatSliders.add(new GuiSliderIE(0, componentLeft+fc.x, componentTop+fc.y, fc.width,
floatSliders.add(new GuiSliderIE(0, componentLeft + fc.x, componentTop + fc.y, fc.width,
confComp.fomatConfigName(IConfigurableComponent.ConfigType.FLOAT, i), fc.value));
}
}
}
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/panel_component.png");
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1,1,1,1);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 150, 150);
}
@ -108,7 +109,7 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
boolean superCall = true;
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
if (field.isFocused() && keyCode == 28) {
sync(i, field.getText());
@ -125,7 +126,7 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
for (int i = 0;i<rsChannelChoosers.size();i++) {
for (int i = 0; i < rsChannelChoosers.size(); i++) {
GuiChannelPicker picker = rsChannelChoosers.get(i);
int old = picker.getSelected();
boolean stopNow = picker.click(mouseX, mouseY);
@ -136,35 +137,35 @@ public class GuiPanelComponent extends GuiContainer {
return;
}
}
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
boolean focus = field.isFocused();
field.mouseClicked(mouseX, mouseY, mouseButton);
if (focus&&!field.isFocused()) {
if (focus && !field.isFocused()) {
sync(i, field.getText());
}
}
for (int i = 0;i<boolButtons.size();i++) {
for (int i = 0; i < boolButtons.size(); i++) {
GuiButtonCheckbox box = boolButtons.get(i);
boolean on = box.state;
box.mousePressed(mc, mouseX, mouseY);
if (on!=box.state) {
if (on != box.state) {
sync(i, box.state);
}
}
for (int i = 0;i<intChoosers.size();i++) {
for (int i = 0; i < intChoosers.size(); i++) {
GuiIntChooser chooser = intChoosers.get(i);
int oldV = chooser.getValue();
chooser.click(mouseX, mouseY);
if (oldV!=chooser.getValue()) {
if (oldV != chooser.getValue()) {
sync(i, chooser.getValue());
}
}
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE slider = floatSliders.get(i);
double oldV = slider.getValue();
slider.mousePressed(mc, mouseX, mouseY);
if (oldV!=slider.getValue()) {
if (oldV != slider.getValue()) {
sync(i, (float) slider.getValue());
}
}
@ -173,11 +174,11 @@ public class GuiPanelComponent extends GuiContainer {
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE slider = floatSliders.get(i);
double oldV = slider.getValue();
slider.mouseReleased(mouseX, mouseY);
if (oldV!=slider.getValue()) {
if (oldV != slider.getValue()) {
sync(i, (float) slider.getValue());
}
}
@ -204,21 +205,21 @@ public class GuiPanelComponent extends GuiContainer {
choose.drawButton(mc, mouseX, mouseY);
}
//TOOLTIPS
for (int i = 0;i<rsChannelChoosers.size();i++) {
for (int i = 0; i < rsChannelChoosers.size(); i++) {
GuiChannelPicker pick = rsChannelChoosers.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.RS_CHANNEL, i);
if (tooltip!=null&&pick.isHovered(mouseX, mouseY)) {
if (tooltip != null && pick.isHovered(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<boolButtons.size();i++) {
for (int i = 0; i < boolButtons.size(); i++) {
GuiButtonCheckbox box = boolButtons.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.BOOL, i);
if (tooltip!=null&&box.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
GuiTextField field = stringTexts.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.STRING, i);
if (tooltip!=null&&mouseX>=field.xPosition&&mouseX<field.xPosition+field.width&&
@ -226,14 +227,14 @@ public class GuiPanelComponent extends GuiContainer {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<intChoosers.size();i++) {
for (int i = 0; i < intChoosers.size(); i++) {
GuiIntChooser choose = intChoosers.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.INT, i);
if (tooltip!=null&&choose.isMouseOver(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
}
}
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE choose = floatSliders.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.FLOAT, i);
if (tooltip!=null&&choose.isMouseOver()) {
@ -249,6 +250,7 @@ public class GuiPanelComponent extends GuiContainer {
update.setString(MessageComponentSync.VALUE, value);
syncSingle(update);
}
private void sync(int id, boolean value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
@ -256,6 +258,7 @@ public class GuiPanelComponent extends GuiContainer {
update.setBoolean(MessageComponentSync.VALUE, value);
syncSingle(update);
}
private void sync(int id, byte value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
@ -263,6 +266,7 @@ public class GuiPanelComponent extends GuiContainer {
update.setByte(MessageComponentSync.VALUE, value);
syncSingle(update);
}
private void sync(int id, int value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
@ -270,6 +274,7 @@ public class GuiPanelComponent extends GuiContainer {
update.setInteger(MessageComponentSync.VALUE, value);
syncSingle(update);
}
private void sync(int id, float value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
@ -277,37 +282,38 @@ public class GuiPanelComponent extends GuiContainer {
update.setFloat(MessageComponentSync.VALUE, value);
syncSingle(update);
}
private void syncAll() {
NBTTagList list = new NBTTagList();
for (int i = 0;i<stringTexts.size();i++) {
for (int i = 0; i < stringTexts.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setString(MessageComponentSync.VALUE, stringTexts.get(i).getText());
list.appendTag(update);
}
for (int i = 0;i<boolButtons.size();i++) {
for (int i = 0; i < boolButtons.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setBoolean(MessageComponentSync.VALUE, boolButtons.get(i).state);
list.appendTag(update);
}
for (int i = 0;i<rsChannelChoosers.size();i++) {
for (int i = 0; i < rsChannelChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setByte(MessageComponentSync.VALUE, rsChannelChoosers.get(i).getSelected());
list.appendTag(update);
}
for (int i = 0;i<intChoosers.size();i++) {
for (int i = 0; i < intChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(MessageComponentSync.ID, i);
update.setInteger(MessageComponentSync.VALUE, intChoosers.get(i).getValue());
list.appendTag(update);
}
for (int i = 0;i<floatSliders.size();i++) {
for (int i = 0; i < floatSliders.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(MessageComponentSync.ID, i);
@ -316,11 +322,13 @@ public class GuiPanelComponent extends GuiContainer {
}
sync(list);
}
private void syncSingle(NBTTagCompound nbt) {
NBTTagList list = new NBTTagList();
list.appendTag(nbt);
sync(list);
}
private void sync(NBTTagList list) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("data", list);

View file

@ -55,22 +55,22 @@ public class GuiPanelCreator extends GuiContainer {
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1,1,1,1);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
this.drawTexturedModalRect(guiLeft,guiTop, 0, 0, xSize, ySize);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
int x0 = getX0();
int y0 = getY0();
int xRel = mouseX - x0;
int yRel = mouseY - y0;
if (snapToGrid) {
xRel = (int) Math.floor(xRel*16/panelSize)*panelSize/16;
yRel = (int) Math.floor(yRel*16/panelSize)*panelSize/16;
xRel = (int) Math.floor(xRel * 16 / panelSize) * panelSize / 16;
yRel = (int) Math.floor(yRel * 16 / panelSize) * panelSize / 16;
}
for (PanelComponent pc : container.tile.components) {
drawPanelComponent(pc, -1, -1);
}
PanelComponent curr = getFloatingPC();
if (curr!=null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
if (curr != null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
drawPanelComponent(curr, xRel, yRel);
}
}
@ -83,15 +83,15 @@ public class GuiPanelCreator extends GuiContainer {
tooltip = I18n.format(IndustrialWires.MODID+".desc.create_panel");
ClientUtils.drawHoveringText(ImmutableList.of("Create a new panel"), mouseX, mouseY, mc.fontRendererObj);
} else if (buttonList.get(1).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.remove_all");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.remove_all");
} else if (buttonList.get(2).isMouseOver()) {
if (snapToGrid) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.disable_snap");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disable_snap");
} else {
tooltip = I18n.format(IndustrialWires.MODID+".desc.enable_snap");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.enable_snap");
}
} else if (buttonList.get(3).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID+".desc.disassemble");
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disassemble");
}
if (tooltip!=null) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
@ -105,10 +105,10 @@ public class GuiPanelCreator extends GuiContainer {
}
if (!pc.isValidPos(container.tile.components)) {
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
int left = (int) (getX0()+aabb.minX*panelSize)-1;
int top = (int) (getY0()+aabb.minZ*panelSize)-1;
int right = (int) (getX0()+aabb.maxX*panelSize)+1;
int bottom = (int) (getY0()+aabb.maxZ*panelSize)+1;
int left = (int) (getX0() + aabb.minX * panelSize) - 1;
int top = (int) (getY0() + aabb.minZ * panelSize) - 1;
int right = (int) (getX0() + aabb.maxX * panelSize) + 1;
int bottom = (int) (getY0() + aabb.maxZ * panelSize) + 1;
Gui.drawRect(left, top, right, bottom, 0xffff0000);
}
pc.renderInGUI(this);
@ -119,11 +119,11 @@ public class GuiPanelCreator extends GuiContainer {
public void initGui() {
super.initGui();
buttonList.clear();
int buttonTop = guiTop+62;
buttonList.add(new GuiButton(0, guiLeft+2, buttonTop, 20, 20, "C"));
buttonList.add(new GuiButton(1, guiLeft+2, buttonTop+22, 20, 20, "R"));
buttonList.add(new GuiButton(2, guiLeft+2, buttonTop+44, 20, 20, "S"));
buttonList.add(new GuiButton(3, guiLeft+2, buttonTop-54, 20, 20, "D"));
int buttonTop = guiTop + 62;
buttonList.add(new GuiButton(0, guiLeft + 2, buttonTop, 20, 20, "C"));
buttonList.add(new GuiButton(1, guiLeft + 2, buttonTop + 22, 20, 20, "R"));
buttonList.add(new GuiButton(2, guiLeft + 2, buttonTop + 44, 20, 20, "S"));
buttonList.add(new GuiButton(3, guiLeft + 2, buttonTop - 54, 20, 20, "D"));
}
@Override
@ -159,7 +159,7 @@ public class GuiPanelCreator extends GuiContainer {
for (int i = 0;i<components.size();i++) {
PanelComponent pc = components.get(i);
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
if (aabb.minX<=xRelFloat&&aabb.maxX>xRelFloat&&aabb.minZ<=yRelFloat&&aabb.maxZ>yRelFloat) {
if (aabb.minX <= xRelFloat && aabb.maxX > xRelFloat && aabb.minZ <= yRelFloat && aabb.maxZ > yRelFloat) {
PanelComponent removed = components.get(i);
ItemStack remItem = ItemPanelComponent.stackFromComponent(removed);
mc.thePlayer.inventory.setItemStack(remItem);
@ -175,11 +175,11 @@ public class GuiPanelCreator extends GuiContainer {
}
public int getX0() {
return 30+guiLeft;
return 30 + guiLeft;
}
public int getY0() {
return 6+guiTop;
return 6 + guiTop;
}
@Override
@ -206,6 +206,7 @@ public class GuiPanelCreator extends GuiContainer {
}
private ItemStack lastFloating;
private PanelComponent lastFloatingPC;
private PanelComponent getFloatingPC() {
ItemStack floating = mc.thePlayer.inventory.getItemStack();
if (floating==null||floating.getItem()!=IndustrialWires.panelComponent) {

View file

@ -35,18 +35,20 @@ import java.io.IOException;
public class GuiRSPanelConn extends GuiContainer {
private TileEntityRSPanelConn te;
private GuiIntChooser chooser;
public GuiRSPanelConn(TileEntityRSPanelConn tile) {
super(new ContainerRSPanelConn(tile));
te = tile;
}
@Override
public void initGui() {
super.initGui();
chooser = new GuiIntChooser((width-32)/2, (height-4)/2, false, te.getRsId(), 2);
chooser = new GuiIntChooser((width - 32) / 2, (height - 4) / 2, false, te.getRsId(), 2);
xSize = 64;
ySize = 64;
guiLeft = (width-xSize)/2;
guiTop = (height-ySize)/2;
guiLeft = (width - xSize) / 2;
guiTop = (height - ySize) / 2;
}
@Override
@ -65,9 +67,10 @@ public class GuiRSPanelConn extends GuiContainer {
}
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/rs_wire_controller.png");
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1,1,1,1);
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 64, 64);
}
@ -84,7 +87,7 @@ public class GuiRSPanelConn extends GuiContainer {
}
private void onChange() {
if (chooser.getValue()!=te.getRsId()) {
if (chooser.getValue() != te.getRsId()) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("rsId", chooser.getValue());
IndustrialWires.packetHandler.sendToServer(new MessageGUIInteract(te, nbt));

View file

@ -10,6 +10,7 @@ import javax.annotation.Nonnull;
public class GuiChannelPicker extends GuiButton {
protected byte selected;
protected byte currHovered;
public GuiChannelPicker(int id, int x, int y, int size, byte selectedChannel) {
super(id, x, y, size, size, "");
selected = selectedChannel;
@ -21,33 +22,33 @@ public class GuiChannelPicker extends GuiButton {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
mouseX-=xPosition;
mouseY-=yPosition;
mouseX -= xPosition;
mouseY -= yPosition;
currHovered = -1;
for (byte i = 0;i<16;i++) {
int xMin = width/4*(i%4);
int yMin = height/4*(i/4);
int xMax = xMin+width/4;
int yMax = yMin+height/4;
for (byte i = 0; i < 16; i++) {
int xMin = width / 4 * (i % 4);
int yMin = height / 4 * (i / 4);
int xMax = xMin + width / 4;
int yMax = yMin + height / 4;
EnumDyeColor color = EnumDyeColor.byMetadata(i);
int colorVal = color.getMapColor().colorValue|0xff000000;
if (mouseX>=xMin&&mouseX<xMax&&mouseY>=yMin&&mouseY<yMax) {
int colorVal = color.getMapColor().colorValue | 0xff000000;
if (mouseX >= xMin && mouseX < xMax && mouseY >= yMin && mouseY < yMax) {
currHovered = i;
}
if (selected==i) {
drawRect(xMin+xPosition, yMin+yPosition, xMax+xPosition, yMax+yPosition, 0xff000000|~colorVal);
if (selected == i) {
drawRect(xMin + xPosition, yMin + yPosition, xMax + xPosition, yMax + yPosition, 0xff000000 | ~colorVal);
}
if (currHovered==i) {
drawRect(xMin+xPosition, yMin+yPosition, xMax+xPosition, yMax+yPosition, colorVal);
if (currHovered == i) {
drawRect(xMin + xPosition, yMin + yPosition, xMax + xPosition, yMax + yPosition, colorVal);
} else {
final int offset = width/20;
drawRect(xMin+offset+xPosition, yMin+offset+yPosition, xMax-offset+xPosition, yMax-offset+yPosition, colorVal);
final int offset = width / 20;
drawRect(xMin + offset + xPosition, yMin + offset + yPosition, xMax - offset + xPosition, yMax - offset + yPosition, colorVal);
}
}
}
public boolean click(int x, int y) {
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
select();
return true;
}
@ -55,14 +56,16 @@ public class GuiChannelPicker extends GuiButton {
}
protected void select() {
if (currHovered>=0) {
if (currHovered >= 0) {
selected = currHovered;
}
}
public byte getSelected() {
return selected;
}
public boolean isHovered(int x, int y) {
return xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y;
return xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y;
}
}

View file

@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
public class GuiChannelPickerSmall extends GuiChannelPicker {
private boolean open = false;
private int offSize, onSize;
public GuiChannelPickerSmall(int id, int x, int y, int offSize, int onSize, byte selectedChannel) {
super(id, x, y, offSize, selectedChannel);
selected = selectedChannel;
@ -45,14 +46,14 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
} else {
EnumDyeColor color = EnumDyeColor.byMetadata(selected);
int colorVal = color.getMapColor().colorValue | 0xff000000;
drawRect(xPosition, yPosition, xPosition+width, yPosition+height, colorVal);
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, colorVal);
}
}
@Override
public boolean click(int x, int y) {
if (!open) {
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
open = true;
width = onSize;
height = onSize;
@ -61,7 +62,7 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
return false;
} else {
boolean ret = false;
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
if (xPosition <= x && xPosition + width >= x && yPosition <= y && yPosition + height >= y) {
select();
ret = true;
}

View file

@ -11,6 +11,7 @@ public class GuiIntChooser extends Gui {
private int max;
private String format;
private Minecraft mc = Minecraft.getMinecraft();
public GuiIntChooser(int x, int y, boolean neg, int initialValue, int digits) {
allowNegative = neg;
value = initialValue;
@ -20,11 +21,12 @@ public class GuiIntChooser extends Gui {
xPlus = x+mc.fontRendererObj.getCharWidth('0')*(digits+(allowNegative?1:0))+mc.fontRendererObj.getCharWidth('-')+2;
format = "%"+digits+"s";
}
public void drawChooser() {
int color = 0xE0E0E0;
String val = String.format(format, Integer.toString(value)).replace(' ', '0');
if (value>=0&&allowNegative) {
val = "+"+val;
if (value >= 0 && allowNegative) {
val = "+" + val;
}
mc.fontRendererObj.drawStringWithShadow(val, xPos+mc.fontRendererObj.getCharWidth('-')+1, yPos, color);
mc.fontRendererObj.drawStringWithShadow("-", xPos, yPos, color);

View file

@ -49,13 +49,14 @@ public class PanelModel implements IBakedModel {
.maximumSize(100)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();
static {
IEApi.renderCacheClearers.add(modelCache::invalidateAll);
IEApi.renderCacheClearers.add(PanelItemOverride.ITEM_MODEL_CACHE::invalidateAll);
}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side!=null) {
if (side != null) {
return ImmutableList.of();
}
if (state instanceof IExtendedBlockState) {
@ -169,6 +170,7 @@ public class PanelModel implements IBakedModel {
.maximumSize(100)
.expireAfterAccess(60, TimeUnit.SECONDS)
.build();
public PanelItemOverride() {
super(ImmutableList.of());
}
@ -178,7 +180,7 @@ public class PanelModel implements IBakedModel {
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) {
if (stack != null && stack.getItem() == PanelUtils.PANEL_ITEM && stack.getMetadata() == BlockTypes_Panel.TOP.ordinal()) {
try {
return ITEM_MODEL_CACHE.get(stack, ()-> {
return ITEM_MODEL_CACHE.get(stack, () -> {
TileEntityPanel te = new TileEntityPanel();
te.readFromItemNBT(stack.getTagCompound());
return new AssembledBakedModel(te.getComponents());

View file

@ -49,7 +49,7 @@ public class PanelModelLoader implements ICustomModelLoader {
@Override
public boolean accepts(ResourceLocation modelLocation) {
return modelLocation.getResourcePath().contains(RESOURCE_BASE+RESOURCE_LOCATION);
return modelLocation.getResourcePath().contains(RESOURCE_BASE + RESOURCE_LOCATION);
}
@Override
@ -57,7 +57,7 @@ public class PanelModelLoader implements ICustomModelLoader {
String resourcePath = modelLocation.getResourcePath();
int pos = resourcePath.indexOf(RESOURCE_LOCATION);
if (pos >= 0) {
return new PanelModelBase();
return new PanelModelBase();
}
return ModelLoaderRegistry.getMissingModel();
}
@ -82,7 +82,7 @@ public class PanelModelLoader implements ICustomModelLoader {
}
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
try {
return new PanelModel();
} catch (Exception e) {

View file

@ -40,7 +40,7 @@ public class RawModelFontRenderer extends FontRenderer {
public RawModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, float scale) {
super(settings, font, manager, isUnicode);
this.scale = scale/(9*16);
this.scale = scale / (9 * 16);
onResourceManagerReload(null);
}
@ -50,22 +50,23 @@ public class RawModelFontRenderer extends FontRenderer {
float y = (pos / 16);
float w = charWidth[pos] - 1.01f;
float h = FONT_HEIGHT - 1.01f;
float wt = w / 128f*16;
float ht = h / 128f*16;
float wt = w / 128f * 16;
float ht = h / 128f * 16;
float h0 = .01F;
Vector3f v0 = new Vector3f(posX, h0, posY);
v0.scale(scale);
Vector3f v1 = new Vector3f(posX, h0, posY+h);
Vector3f v1 = new Vector3f(posX, h0, posY + h);
v1.scale(scale);
Vector3f v2 = new Vector3f(posX+w, h0, posY+h);
Vector3f v2 = new Vector3f(posX + w, h0, posY + h);
v2.scale(scale);
Vector3f v3 = new Vector3f(posX+w, h0, posY);
Vector3f v3 = new Vector3f(posX + w, h0, posY);
v3.scale(scale);
builder.add(new RawQuad(v0, v1, v2, v3,
EnumFacing.UP, sprite, new float[]{1, 0, 0, 1}, new Vector3f(0, 1, 0),
new float[]{x, y, x+wt, y+ht}));
EnumFacing.UP, sprite, colorA, new Vector3f(0, 1, 0),
new float[]{x, y, x + wt, y + ht}));
return charWidth[pos];
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
super.onResourceManagerReload(resourceManager);

View file

@ -0,0 +1,78 @@
package malte0811.industrialWires.client.panelmodel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumType;
import net.minecraft.client.renderer.vertex.VertexFormatElement.EnumUsage;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.LightUtil;
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
import net.minecraftforge.client.model.pipeline.VertexLighterFlat;
import java.lang.reflect.Field;
//Yes, this is copied from the IE version. But I wrote that one, so...
public class SmartLightingQuadIW extends BakedQuad {
private static Field parent;
static {
try {
parent = QuadGatheringTransformer.class.getDeclaredField("parent");
parent.setAccessible(true);
} catch (Exception x) {
x.printStackTrace();
}
}
private int brightness;
public SmartLightingQuadIW(int[] vertexDataIn, int tintIndexIn, EnumFacing faceIn, TextureAtlasSprite spriteIn, VertexFormat format, int brightness) {
super(vertexDataIn, tintIndexIn, faceIn, spriteIn, false, format);
this.brightness = brightness;
}
public SmartLightingQuadIW(BakedQuad ret, int light) {
super(ret.getVertexData(), ret.getTintIndex(), ret.getFace(), ret.getSprite(), false, ret.getFormat());
this.brightness = light;
}
@Override
public void pipe(IVertexConsumer consumer) {
if (consumer instanceof VertexLighterFlat) {
try {
consumer = (IVertexConsumer) parent.get(consumer);
} catch (Throwable e) {
e.printStackTrace();
}
}
consumer.setQuadOrientation(this.getFace());
if (this.hasTintIndex()) {
consumer.setQuadTint(this.getTintIndex());
}
float[] data = new float[4];
VertexFormat format = consumer.getVertexFormat();
int count = format.getElementCount();
int[] eMap = LightUtil.mapFormats(format, DefaultVertexFormats.ITEM);
int itemCount = DefaultVertexFormats.ITEM.getElementCount();
eMap[eMap.length - 1] = 2;
for (int v = 0; v < 4; v++) {
for (int e = 0; e < count; e++) {
if (eMap[e] != itemCount) {
if (format.getElement(e).getUsage() == EnumUsage.UV && format.getElement(e).getType() == EnumType.SHORT)//lightmap is UV with 2 shorts
{
data[0] = ((float) ((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
data[1] = ((float) ((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
} else {
LightUtil.unpack(this.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
}
consumer.put(e, data);
} else {
consumer.put(e, 0);
}
}
}
}
}

View file

@ -25,23 +25,21 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.ModelLoader;
import org.lwjgl.opengl.GL11;
public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntityJacobsLadder> {
@Override
public void renderTileEntityAt(TileEntityJacobsLadder tile, double x, double y, double z, float partialTicks, int destroyStage) {
super.renderTileEntityAt(tile, x, y, z, partialTicks, destroyStage);
if (!tile.isDummy()&&tile.timeTillActive==0&&tile.controls[0] != null) {
if (!tile.isDummy() && tile.timeTillActive == 0 && tile.controls[0] != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + tile.size.heightOffset, z + .5);
GlStateManager.rotate(tile.facing.getHorizontalAngle(), 0, 1, 0);
GlStateManager.translate( - tile.size.bottomDistance / 2, 0, 0);
GlStateManager.translate(-tile.size.bottomDistance / 2, 0, 0);
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
@ -89,47 +87,50 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
Vec3d radZ = new Vec3d(0, 0, diameter / 2);
Tessellator tes = Tessellator.getInstance();
VertexBuffer vertBuffer = tes.getBuffer();
float[][] colors = new float[steps+1][];
float[][] colors = new float[steps + 1][];
vertBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
Vec3d last = Beziers.getPoint(0, controls);
colors[0] = getColor(0, salt, size);
for (int i = 1;i<=steps;i++) {
double d = i/(double)steps;
for (int i = 1; i <= steps; i++) {
double d = i / (double) steps;
colors[i] = getColor(d, salt, size);
Vec3d pos = Beziers.getPoint(d, controls);
drawQuad(last, pos, radY, colors[i-1], colors[i], vertBuffer);
drawQuad(last, pos, radZ, colors[i-1], colors[i], vertBuffer);
drawQuad(last, pos, radY, colors[i - 1], colors[i], vertBuffer);
drawQuad(last, pos, radZ, colors[i - 1], colors[i], vertBuffer);
last = pos;
}
tes.draw();
}
private final float[] saltColor = {1, 190/255F, 50/255F};
private final float[] saltColor = {1, 190 / 255F, 50 / 255F};
private final float[] airColor = {1, .85F, 1};
private float[] getColor(double t, double salt, LadderSize size) {
salt = Math.min(salt, 1);
int factor = 20;
double smallMin = Math.exp(-.5);
double normalMin = Math.exp(-.25*factor);
double hugeMin = Math.exp(-.75*factor);
double normalMin = Math.exp(-.25 * factor);
double hugeMin = Math.exp(-.75 * factor);
double saltyness = 0;
double t2 = t-.5;
double t2 = t - .5;
switch (size) {
case SMALL:
saltyness = salt*(1-.9*(Math.exp(-Math.abs(t2))-smallMin));
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(t2)) - smallMin));
break;
case NORMAL:
saltyness = salt*(1-.9*(Math.exp(-factor*t2*t2)-normalMin));
saltyness = salt * (1 - .9 * (Math.exp(-factor * t2 * t2) - normalMin));
break;
case HUGE:
saltyness = salt*(1-.9*(Math.exp(-Math.abs(factor*t2*t2*t2))-hugeMin));
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(factor * t2 * t2 * t2)) - hugeMin));
break;
}
return interpolate(saltyness, saltColor, 1-saltyness, airColor);
return interpolate(saltyness, saltColor, 1 - saltyness, airColor);
}
private float[] interpolate(double a, float[] cA, double b, float[] cB) {
float[] ret = new float[cA.length];
for (int i = 0;i<ret.length;i++) {
ret[i] = (float) (a*cA[i]+b*cB[i]);
for (int i = 0; i < ret.length; i++) {
ret[i] = (float) (a * cA[i] + b * cB[i]);
}
return ret;
}
@ -145,6 +146,7 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
color(color0, vertexBuffer.pos(v0.xCoord - rad.xCoord, v0.yCoord - rad.yCoord, v0.zCoord - rad.zCoord)).endVertex();
color(color1, vertexBuffer.pos(v1.xCoord - rad.xCoord, v1.yCoord - rad.yCoord, v1.zCoord - rad.zCoord)).endVertex();
}
private VertexBuffer color(float[] color, VertexBuffer vb) {
vb.color(color[0], color[1], color[2], 1);
return vb;

View file

@ -26,9 +26,11 @@ import net.minecraft.util.EnumHand;
public class ContainerPanelComponent extends Container {
public EnumHand hand;
public ContainerPanelComponent(EnumHand h) {
hand = h;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
ItemStack held = playerIn.getHeldItem(hand);

View file

@ -18,22 +18,32 @@
package malte0811.industrialWires.containers;
import blusunrize.immersiveengineering.common.gui.ContainerIEBase;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import javax.annotation.Nullable;
import javax.annotation.Nonnull;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class ContainerPanelCreator extends Container {
public TileEntityPanelCreator tile;
private IInventory inv;
//TODO remove dependency on core IE
public class ContainerPanelCreator extends ContainerIEBase<TileEntityPanelCreator> {
public ContainerPanelCreator(InventoryPlayer inventoryPlayer, TileEntityPanelCreator tile) {
super(inventoryPlayer, tile);
int slotH = 150;
int slotX = 14;
slotCount = 1;
this.tile = tile;
inv = new SingleSlotInventory((i) -> tile.inv = i, () -> tile.inv, tile::markDirty, this::canInteractWith, "panel_creator");
addSlotToContainer(new Slot(inv, 0, 7, 37) {
@Override
public int getSlotStackLimit() {
@ -41,15 +51,168 @@ public class ContainerPanelCreator extends ContainerIEBase<TileEntityPanelCreato
}
@Override
public boolean isItemValid(@Nullable ItemStack stack) {
return stack != null && (ItemStack.areItemStacksEqual(stack, PanelUtils.getPanelBase()) || stack.getItem() == PanelUtils.PANEL_ITEM);
public boolean isItemValid(ItemStack stack) {
return ItemStack.areItemStacksEqual(ApiUtils.copyStackWithAmount(stack, 1), PanelUtils.getPanelBase()) || stack.getItem() == PanelUtils.PANEL_ITEM;
}
});
for (int i = 0; i < 3; i++)
for (int j = 0; j < 9; j++)
addSlotToContainer(new Slot(inventoryPlayer, j+i*9+9, slotX+j*18, slotH+i*18));
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, slotX + j * 18, slotH + i * 18));
for (int i = 0; i < 9; i++)
addSlotToContainer(new Slot(inventoryPlayer, i, slotX+i*18, slotH+58));
addSlotToContainer(new Slot(inventoryPlayer, i, slotX + i * 18, slotH + 58));
}
}
@Override
public boolean canInteractWith(@Nonnull EntityPlayer player) {
return player.getDistanceSq(tile.getPos()) < 100;
}
@Nonnull
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
Slot clicked = getSlot(index);
if (index == 0 && clicked.getStack()!=null) {
boolean change = mergeItemStack(clicked.getStack(), 1, 37, false);
if (change) {
clicked.onSlotChanged();
}
} else {
ItemStack inSlot = clicked.getStack();
Slot slot0 = getSlot(0);
ItemStack stack0 = slot0.getStack();
if (inSlot!=null && slot0.isItemValid(inSlot) && stack0!=null && stack0.stackSize < slot0.getSlotStackLimit()) {
slot0.putStack(inSlot.splitStack(slot0.getSlotStackLimit()));
clicked.onSlotChanged();
}
}
return null;
}
public static class SingleSlotInventory implements IInventory {
Consumer<ItemStack> set;
Supplier<ItemStack> get;
Runnable markDirty;
Predicate<EntityPlayer> isUsable;
String name;
public SingleSlotInventory(Consumer<ItemStack> set, Supplier<ItemStack> get, Runnable markDirty, Predicate<EntityPlayer> isUsable,
String name) {
this.set = set;
this.get = get;
this.markDirty = markDirty;
this.isUsable = isUsable;
this.name = name;
}
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int index) {
return index == 0 ? get.get() : null;
}
@Override
public ItemStack decrStackSize(int index, int count) {
if (index != 0) {
return null;
}
ItemStack stack = get.get();
if (stack==null) {
return null;
}
ItemStack ret = stack.splitStack(count);
if (stack.stackSize <= 0) {
set.accept(null);
}
return ret;
}
@Override
public ItemStack removeStackFromSlot(int index) {
if (index == 0) {
ItemStack ret = get.get();
set.accept(null);
return ret;
}
return null;
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
if (index == 0) {
set.accept(stack);
}
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public void markDirty() {
markDirty.run();
}
@Override
public boolean isUseableByPlayer(@Nonnull EntityPlayer player) {
return isUsable.test(player);
}
@Override
public void openInventory(@Nonnull EntityPlayer player) {
}
@Override
public void closeInventory(@Nonnull EntityPlayer player) {
}
@Override
public boolean isItemValidForSlot(int index, @Nonnull ItemStack stack) {
return true;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
@Override
public void clear() {
set.accept(null);
}
@Nonnull
@Override
public String getName() {
return name;
}
@Override
public boolean hasCustomName() {
return false;
}
@Nonnull
@Override
public ITextComponent getDisplayName() {
return new TextComponentString(name);
}
}
}

View file

@ -22,13 +22,17 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import javax.annotation.Nonnull;
public class ContainerRSPanelConn extends Container {
final TileEntityRSPanelConn te;
private final TileEntityRSPanelConn te;
public ContainerRSPanelConn(TileEntityRSPanelConn tile) {
te = tile;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return playerIn.getDistanceSq(te.getPos())<64;
public boolean canInteractWith(@Nonnull EntityPlayer playerIn) {
return playerIn.getDistanceSq(te.getPos()) < 64;
}
}

View file

@ -50,18 +50,18 @@ public class CoveredToggleSwitch extends ToggleSwitch {
Matrix4 rot = null;
if (state.open) {
rot = new Matrix4();
rot.rotate(-Math.PI*.4, 1, 0, 0);
rot.rotate(-Math.PI * .4, 1, 0, 0);
}
PanelUtils.addColoredBox(color, color, null, new Vector3f(0, 0, 0), new Vector3f(sizeX, getHeight(), sizeY), ret,
false, rot, true);
ret.remove(ret.size()-2);//remove front face
ret.remove(ret.size()-1);//remove front face
ret.remove(ret.size() - 2);//remove front face
ret.remove(ret.size() - 1);//remove front face
return ret;
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (player.isSneaking()&&state==SwitchState.OPEN) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (player.isSneaking() && state == SwitchState.OPEN) {
state = SwitchState.CLOSED;
} else {
state = state.next();
@ -69,12 +69,11 @@ public class CoveredToggleSwitch extends ToggleSwitch {
setOut(state.active, tile);
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
super.renderInGUIDefault(gui, 0xff000000|this.color);
super.renderInGUIDefault(gui, 0xff000000 | this.color);
super.renderInGUI(gui);
}
@ -105,6 +104,7 @@ public class CoveredToggleSwitch extends ToggleSwitch {
ret.state = state;
ret.rsOutputChannel = rsOutputChannel;
ret.rsOutputId = rsOutputId;
ret.active = active;
ret.setX(getX());
ret.setY(getY());
ret.setPanelHeight(panelHeight);
@ -118,30 +118,30 @@ public class CoveredToggleSwitch extends ToggleSwitch {
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
super.applyConfigOption(type, id, value);
if (type==ConfigType.FLOAT) {
if (type == ConfigType.FLOAT) {
color = PanelUtils.setColor(color, id, value);
}
}
@Override
public String fomatConfigName(ConfigType type, int id) {
if (type==ConfigType.FLOAT) {
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
if (type == ConfigType.FLOAT) {
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
}
return super.fomatConfigName(type, id);
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
if (type==ConfigType.FLOAT) {
if (type == ConfigType.FLOAT) {
return null;
}
return super.fomatConfigDescription(type, id);
@ -160,7 +160,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
CoveredToggleSwitch that = (CoveredToggleSwitch) o;
if (active != that.active) return false;
if (rsOutputId != that.rsOutputId) return false;
if (rsOutputChannel != that.rsOutputChannel) return false;
if (color != that.color) return false;
@ -184,12 +183,14 @@ public class CoveredToggleSwitch extends ToggleSwitch {
ACTIVE(true, true);
public boolean active;
public boolean open;
SwitchState(boolean active, boolean open) {
this.open = open;
this.active = active;
}
SwitchState next() {
return values()[(ordinal()+1)%values().length];
return values()[(ordinal() + 1) % values().length];
}
}
}

View file

@ -85,9 +85,11 @@ public interface IConfigurableComponent {
class RSChannelConfig extends UniversalConfig<Byte> {
public boolean small;
public RSChannelConfig(String name, int x, int y, Byte value) {
this(name, x, y, value, false);
}
public RSChannelConfig(String name, int x, int y, Byte value, boolean small) {
super(name, x, y, value);
this.small = small;
@ -113,6 +115,7 @@ public interface IConfigurableComponent {
this.width = width;
}
}
enum ConfigType {
BOOL,
STRING,

View file

@ -44,9 +44,11 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private byte rsInputChannel;
private int colorA = 0xff00;
private byte rsInput;
public IndicatorLight() {
super("indicator_light");
}
public IndicatorLight(int rsId, byte rsChannel, int color) {
this();
colorA = color;
@ -74,15 +76,19 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private static final float size = .0625F;
private static final float antiZOffset = .001F;
@Override
public List<RawQuad> getQuads() {
float[] color = new float[4];
color[3] = 1;
for (int i = 0;i<3;i++) {
color[i] = ((this.colorA>>(8*(2-i)))&255)/255F*(rsInput+15F)/30F;
for (int i = 0; i < 3; i++) {
color[i] = ((this.colorA >> (8 * (2 - i))) & 255) / 255F * (rsInput + 15F) / 30F;
}
List<RawQuad> ret = new ArrayList<>(1);
PanelUtils.addColoredQuad(ret, new Vector3f(), new Vector3f(0, antiZOffset, size), new Vector3f(size, antiZOffset, size), new Vector3f(size, antiZOffset, 0), EnumFacing.UP, color);
if (rsInput>0) {
ret.get(ret.size()-1).light = 0xff0ff;
}
return ret;
}
@ -100,33 +106,35 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+size, 0, y+size);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + size, 0, y + size);
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
return false;
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
public void update(TileEntityPanel tile) {
}
private TileEntityPanel panel;
private Consumer<byte[]> handler = (input)->{
if (input[rsInputChannel]!=rsInput) {
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput) {
rsInput = input[rsInputChannel];
panel.markDirty();
panel.triggerRenderUpdate();
}
};
@Nullable
@Override
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
if (id==rsInputId) {
if (id == rsInputId) {
this.panel = panel;
return handler;
}
@ -167,10 +175,10 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
rsInputChannel = ((NBTTagByte)value).getByte();
rsInputChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsInputId = ((NBTTagInt)value).getInt();
rsInputId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
colorA = PanelUtils.setColor(colorA, id, value);
@ -183,7 +191,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
case RS_CHANNEL:
case INT:
default:
@ -198,9 +206,9 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
case FLOAT:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return null;
}
@ -208,14 +216,14 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[] {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[] {
return new IntConfig[]{
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
};
}
@ -227,8 +235,8 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}

View file

@ -49,6 +49,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
this.text = text;
this.color = color;
}
public Label() {
super("label");
}
@ -68,7 +69,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Override
public List<RawQuad> getQuads() {
RawModelFontRenderer render = fontRenderer();
render.drawString(text, 0, 0, 0xff000000|color);
render.drawString(text, 0, 0, 0xff000000 | color);
return render.build();
}
@ -95,8 +96,8 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
return false;
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
@ -115,17 +116,17 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
private RawModelFontRenderer fontRenderer() {
if (renderer==null) {
if (renderer == null) {
renderer = new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, font, Minecraft.getMinecraft().getTextureManager(),
false, 1);
false, 1);
}
return renderer;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
int left = (int) (gui.getX0()+getX()*gui.panelSize);
int top = (int) (gui.getY0()+getY()*gui.panelSize);
int left = (int) (gui.getX0() + getX() * gui.panelSize);
int top = (int) (gui.getY0() + getY() * gui.panelSize);
GlStateManager.pushMatrix();
float scale = gui.mc.fontRendererObj.FONT_HEIGHT*gui.panelSize/(16F*9F*9F);
GlStateManager.translate(left, top, 0);
@ -138,7 +139,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case STRING:
text = ((NBTTagString)value).getString();
text = ((NBTTagString) value).getString();
break;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
@ -151,7 +152,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
default:
return null;
}
@ -162,7 +163,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case STRING:
return I18n.format(IndustrialWires.MODID+".desc.label_text");
return I18n.format(IndustrialWires.MODID + ".desc.label_text");
default:
return null;
}

View file

@ -47,9 +47,11 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
public int rsOutputChannel;
private int ticksTillOff;
private Set<BiConsumer<Integer, Byte>> rsOut = new HashSet<>();
public LightedButton() {
super("lighted_button");
}
public LightedButton(int color, boolean active, boolean latching, int rsOutputId, int rsOutputChannel) {
this();
this.color = color;
@ -80,12 +82,18 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
private final static float size = .0625F;
@Override
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(active, this.color);
List<RawQuad> ret = new ArrayList<>(5);
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size/2, size), ret, false);
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size / 2, size), ret, false);
if (active) {
ret.get(0).light = 0xff0ff;
}
return ret;
}
@ -102,16 +110,16 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+size, getHeight(), y+size);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + size, getHeight(), y + size);
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching&&active) {
return false;
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching && active) {
return;
}
setOut(!active, tile);
if (!latching) {
@ -119,15 +127,14 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
public void update(TileEntityPanel tile) {
if (!latching&&ticksTillOff>0) {
if (!latching && ticksTillOff > 0) {
ticksTillOff--;
tile.markDirty();
if (ticksTillOff==0) {
if (ticksTillOff == 0) {
setOut(false, tile);
}
}
@ -135,27 +142,27 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
if (id == rsOutputId) {
rsOut.add(out);
out.accept(rsOutputChannel, (byte) (active?15:0));
out.accept(rsOutputChannel, (byte) (active ? 15 : 0));
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
if (id == rsOutputId) {
rsOut.remove(out);
}
}
@Override
public float getHeight() {
return size/2;
return size / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0xff000000|color);
renderInGUIDefault(gui, 0xff000000 | color);
}
@Override
@ -167,8 +174,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
active = on;
tile.markDirty();
tile.triggerRenderUpdate();
for (BiConsumer<Integer, Byte> rs:rsOut) {
rs.accept(rsOutputChannel, (byte)(active?15:0));
for (BiConsumer<Integer, Byte> rs : rsOut) {
rs.accept(rsOutputChannel, (byte) (active ? 15 : 0));
}
}
@ -197,61 +204,61 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
if (id==0) {
latching = ((NBTTagByte)value).getByte()!=0;
}
break;
case RS_CHANNEL:
if (id==0) {
rsOutputChannel = ((NBTTagByte)value).getByte();
}
break;
case INT:
if (id==0) {
rsOutputId = ((NBTTagInt)value).getInt();
}
break;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
break;
case BOOL:
if (id == 0) {
latching = ((NBTTagByte) value).getByte() != 0;
}
break;
case RS_CHANNEL:
if (id == 0) {
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
case FLOAT:
color = PanelUtils.setColor(color, id, value);
break;
}
}
@Override
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID+".desc.latching");
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
default:
return "INVALID";
case BOOL:
return I18n.format(IndustrialWires.MODID + ".desc.latching");
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
default:
return "INVALID";
}
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID+".desc.latching_info");
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
case BOOL:
return I18n.format(IndustrialWires.MODID + ".desc.latching_info");
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte)rsOutputChannel)};
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
@ -271,8 +278,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset+20, color[1], 60),
new FloatConfig("blue", x, yOffset+40, color[2], 60)
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}

View file

@ -47,9 +47,11 @@ public abstract class PanelComponent {
private final String type;
protected final static float[] GRAY = {.8F, .8F, .8F};
protected final static int GRAY_INT = 0xFFD0D0D0;
protected PanelComponent(String type) {
this.type = type;
}
public static final Map<String, Supplier<PanelComponent>> baseCreaters = new HashMap<>();
public final static String COLOR = "color";
public final static String RS_CHANNEL = "rsChannel";
@ -58,6 +60,7 @@ public abstract class PanelComponent {
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
static {
baseCreaters.put("lighted_button", LightedButton::new);
baseCreaters.put("label", Label::new);
@ -67,10 +70,14 @@ public abstract class PanelComponent {
baseCreaters.put("toggle_switch", ToggleSwitch::new);
baseCreaters.put("toggle_switch_covered", CoveredToggleSwitch::new);
}
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
protected abstract void readCustomNBT(NBTTagCompound nbt);
// DON'T OFFSET BY x, y IN THIS METHOD!
public abstract List<RawQuad> getQuads();
@Nonnull
public abstract PanelComponent copyOf();
@ -78,7 +85,7 @@ public abstract class PanelComponent {
@Nonnull
public abstract AxisAlignedBB getBlockRelativeAABB();
public abstract boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player);
public abstract void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player);
public abstract void update(TileEntityPanel tile);
@ -89,11 +96,14 @@ public abstract class PanelComponent {
return null;
}
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {}
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
}
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {}
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
}
public void invalidate(TileEntityPanel te) {}
public void invalidate(TileEntityPanel te) {
}
public float getX() {
return x;
@ -126,6 +136,7 @@ public abstract class PanelComponent {
nbt.setFloat("panelHeight", panelHeight);
nbt.setString("type", type);
}
public static PanelComponent read(NBTTagCompound nbt) {
String type = nbt.getString("type");
if (baseCreaters.containsKey(type)) {
@ -136,10 +147,11 @@ public abstract class PanelComponent {
ret.setPanelHeight(nbt.getFloat("panelHeight"));
return ret;
} else {
IELogger.info("(IndustrialWires) Unknown panel component: "+type);//TODO own logger?
IELogger.info("(IndustrialWires) Unknown panel component: " + type);//TODO own logger?
return null;
}
}
public void renderBox(TileEntityPanel te) {
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
@ -160,28 +172,28 @@ public abstract class PanelComponent {
public void renderInGUIDefault(GuiPanelCreator gui, int color) {
color |= 0xff000000;
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0()+aabb.minX*gui.panelSize);
int top = (int) (gui.getY0()+aabb.minZ*gui.panelSize);
int right = (int) (gui.getX0()+aabb.maxX*gui.panelSize);
int bottom = (int) (gui.getY0()+aabb.maxZ*gui.panelSize);
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) (gui.getY0() + aabb.minZ * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) (gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, color);
}
public boolean isValidPos(List<PanelComponent> components) {
AxisAlignedBB aabb = getBlockRelativeAABB().offset(0, panelHeight, 0);
if (aabb.minX<0||aabb.maxX>1) {
if (aabb.minX < 0 || aabb.maxX > 1) {
return false;
}
if (aabb.minY<0||aabb.maxY>1) {
if (aabb.minY < 0 || aabb.maxY > 1) {
return false;
}
if (aabb.minZ<0||aabb.maxZ>1) {
if (aabb.minZ < 0 || aabb.maxZ > 1) {
return false;
}
aabb = getBlockRelativeAABB();
for (PanelComponent pc:components) {
if (pc==this) {
for (PanelComponent pc : components) {
if (pc == this) {
continue;
}
AxisAlignedBB otherBB = pc.getBlockRelativeAABB();

View file

@ -22,8 +22,12 @@ import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.PropertyComponents.PanelRenderProperties;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -39,7 +43,9 @@ import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
@ -51,8 +57,10 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import static malte0811.industrialWires.controlpanel.PanelComponent.*;
import static malte0811.industrialWires.util.MiscUtils.discoverLocal;
public final class PanelUtils {
public static TextureAtlasSprite PANEL_TEXTURE;
@ -130,7 +138,11 @@ public final class PanelUtils {
raw.colorA);
putVertexData(format, builder, transform.apply(vertices[3]), faceNormal, uvs[flip ? 0 : 2], uvs[flip ? 3 : 1], raw.tex,
raw.colorA);
return builder.build();
BakedQuad ret = builder.build();
if (raw.light>0) {
ret = new SmartLightingQuadIW(ret, raw.light);
}
return ret;
}
//mostly copied from IE's ClientUtils, it has protected access there...
@ -185,7 +197,7 @@ public final class PanelUtils {
@SideOnly(Side.CLIENT)
public static void addBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, float[] uvs, TextureAtlasSprite tex,
@Nullable Matrix4 mat, boolean inside) {
@Nullable Matrix4 mat, boolean inside) {
addQuad(out, new Vector3f(min.x, min.y + size.y, min.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
EnumFacing.UP, colorTop, tex, uvs, mat, inside);
@ -223,7 +235,7 @@ public final class PanelUtils {
Vec3i dirV = dir.getDirectionVec();
RawQuad quad = new RawQuad(v0, v1, v2, v3, dir, tex,
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs);
if (mat!=null) {
if (mat != null) {
quad = quad.apply(mat);
}
out.add(quad);
@ -311,6 +323,7 @@ public final class PanelUtils {
public static boolean intersectXZ(AxisAlignedBB aabb1, AxisAlignedBB aabb2) {
return aabb1.minX < aabb2.maxX && aabb1.maxX > aabb2.minX && aabb1.minZ < aabb2.maxZ && aabb1.maxZ > aabb2.minZ;
}
public static void readListFromNBT(NBTTagList list, @Nonnull List<PanelComponent> base) {
base.clear();
for (int i = 0; i < list.tagCount(); i++) {
@ -322,9 +335,27 @@ public final class PanelUtils {
}
public static ItemStack getPanelBase() {
if (panelBase==null) {
if (panelBase == null) {
panelBase = IC2Items.getItem("resource", "machine");
}
return panelBase;
}
public static List<BlockPos> discoverPanelParts(World w, BlockPos here) {
BiPredicate<BlockPos, Integer> isValid = (pos, count) -> {
if (here.distanceSq(pos) > 25 || count > 100 || !w.isBlockLoaded(pos)) {
return false;
}
IBlockState state = w.getBlockState(pos);
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type) != BlockTypes_Panel.CREATOR;
};
List<BlockPos> all = discoverLocal(w, here, isValid);
List<BlockPos> ret = new ArrayList<>();
for (BlockPos pos : all) {
if (w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
ret.add(pos);
}
}
return ret;
}
}

View file

@ -47,6 +47,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
private byte rsChannel;
private int rsId;
private Set<BiConsumer<Integer, Byte>> outputs = new HashSet<>();
public Slider(float length, int color, boolean horizontal, int rsId, byte rsChannel) {
this();
this.color = color;
@ -55,9 +56,11 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
this.rsChannel = rsChannel;
this.rsId = rsId;
}
public Slider() {
super("slider");
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(COLOR, color);
@ -84,23 +87,26 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
final float yOff = .001F;
float xSize = horizontal?length:WIDTH;
float ySize = horizontal?WIDTH:length;
float xSize = horizontal ? length : WIDTH;
float ySize = horizontal ? WIDTH : length;
PanelUtils.addColoredQuad(ret, new Vector3f(0, yOff, 0), new Vector3f(0, yOff, ySize), new Vector3f(xSize, yOff, ySize), new Vector3f(xSize, yOff, 0),
EnumFacing.UP, GRAY);
float[] color = new float[4];
color[3] = 1;
for (int i = 0;i<3;i++) {
color[i] = ((this.color>>(8*(2-i)))&255)/255F*(.5F+out/30F);
for (int i = 0; i < 3; i++) {
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 30F);
}
float val;
if (horizontal) {
val = (out/15F)*(length-.0625F);
val = (out / 15F) * (length - .0625F);
} else {
val = (1-out/15F)*(length-.0625F);
val = (1 - out / 15F) * (length - .0625F);
}
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal?val:0, 0, horizontal?0:val),
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal ? val : 0, 0, horizontal ? 0 : val),
new Vector3f(.0625F, getHeight(), .0625F), ret, false);
if (out>0) {
ret.get(1).light = 0xff0ff;
}
return ret;
}
@ -118,39 +124,37 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+(horizontal?length:WIDTH), getHeight(), y+(horizontal?WIDTH:length));
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + (horizontal ? length : WIDTH), getHeight(), y + (horizontal ? WIDTH : length));
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double pos = horizontal?hitRelative.xCoord:(length-hitRelative.zCoord);
byte newLevel = (byte)(Math.min(pos*16/length, 15));
if (newLevel!=out) {
for (BiConsumer<Integer, Byte> output:outputs) {
output.accept((int)rsChannel, newLevel);
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double pos = horizontal ? hitRelative.xCoord : (length - hitRelative.zCoord);
byte newLevel = (byte) (Math.min(pos * 16 / length, 15));
if (newLevel != out) {
for (BiConsumer<Integer, Byte> output : outputs) {
output.accept((int) rsChannel, newLevel);
}
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
return false;
}
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsId) {
if (id == rsId) {
outputs.add(out);
out.accept((int)rsChannel, this.out);
out.accept((int) rsChannel, this.out);
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsId) {
if (id == rsId) {
outputs.remove(out);
}
}
@ -162,25 +166,25 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public float getHeight() {
return .0625F/2;
return .0625F / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
double middleX = (getX()+(horizontal?length:.0625)/2);
double middleY = (getY()+(horizontal?.0625:length)/2);
int left = gui.getX0()+(int) ((middleX-.0625/2)*gui.panelSize);
int right = gui.getX0()+(int) ((middleX+.0625/2)*gui.panelSize);
int top = gui.getY0()+(int) ((middleY-.0625/2)*gui.panelSize);
int bottom = gui.getY0()+(int) ((middleY+.0625/2)*gui.panelSize);
Gui.drawRect(left, top, right, bottom, 0xff000000|color);
double middleX = (getX() + (horizontal ? length : .0625) / 2);
double middleY = (getY() + (horizontal ? .0625 : length) / 2);
int left = gui.getX0() + (int) ((middleX - .0625 / 2) * gui.panelSize);
int right = gui.getX0() + (int) ((middleX + .0625 / 2) * gui.panelSize);
int top = gui.getY0() + (int) ((middleY - .0625 / 2) * gui.panelSize);
int bottom = gui.getY0() + (int) ((middleY + .0625 / 2) * gui.panelSize);
Gui.drawRect(left, top, right, bottom, 0xff000000 | color);
}
@Override
public void invalidate(TileEntityPanel te) {
for (BiConsumer<Integer, Byte> out:outputs) {
out.accept((int)rsChannel, (byte) 0);
for (BiConsumer<Integer, Byte> out : outputs) {
out.accept((int) rsChannel, (byte) 0);
}
}
@ -216,19 +220,19 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
horizontal = ((NBTTagByte)value).getByte()!=0;
horizontal = ((NBTTagByte) value).getByte() != 0;
break;
case RS_CHANNEL:
rsChannel = ((NBTTagByte)value).getByte();
rsChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsId = ((NBTTagInt)value).getInt();
rsId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
if (id<3) {
if (id < 3) {
color = PanelUtils.setColor(color, id, value);
} else {
length = scaleToRangePercent(((NBTTagFloat)value).getFloat(), .125F, 1);
length = scaleToRangePercent(((NBTTagFloat) value).getFloat(), .125F, 1);
}
break;
}
@ -242,12 +246,12 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
return I18n.format(IndustrialWires.MODID+".tooltip.horizontal");
return I18n.format(IndustrialWires.MODID + ".tooltip.horizontal");
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":id==2?"blue":"length")));
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : id == 2 ? "blue" : "length")));
default:
return "INVALID";
}
@ -259,9 +263,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
case BOOL:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
@ -271,21 +275,21 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[] {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[] {
return new IntConfig[]{
new IntConfig("rsId", 0, 50, rsId, 2, false)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[] {
return new BoolConfig[]{
new BoolConfig("horizontal", 0, 70, horizontal)
};
}
@ -296,10 +300,10 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
int x = 70;
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset+20, color[0], 60),
new FloatConfig("green", x, yOffset+40, color[1], 60),
new FloatConfig("blue", x, yOffset+60, color[2], 60),
new FloatConfig("length", x, yOffset, (length-.125F)/(1-.125F), 60)
new FloatConfig("red", x, yOffset + 20, color[0], 60),
new FloatConfig("green", x, yOffset + 40, color[1], 60),
new FloatConfig("blue", x, yOffset + 60, color[2], 60),
new FloatConfig("length", x, yOffset, (length - .125F) / (1 - .125F), 60)
};
}

View file

@ -47,12 +47,15 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
public int rsOutputId;
public byte rsOutputChannel;
private Set<BiConsumer<Integer, Byte>> rsOut = new HashSet<>();
public ToggleSwitch() {
super("toggle_switch");
}
public ToggleSwitch(String name) {
super(name);
}
public ToggleSwitch(boolean active, int rsOutputId, byte rsOutputChannel) {
this();
this.active = active;
@ -75,22 +78,24 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
rsOutputChannel = nbt.getByte(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
protected float sizeX = .0625F;
protected float sizeY = 1.5F*sizeX;
protected float rodRadius = sizeX*.25F;
protected float rodLength = 3/32F;
protected float sizeY = 1.5F * sizeX;
protected float rodRadius = sizeX * .25F;
protected float rodLength = 3 / 32F;
protected float yOffset = .0001F;
@Override
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY-sizeX)/2),
new Vector3f(0, yOffset, (sizeY-sizeX)/2),
new Vector3f(0, yOffset, (sizeY+sizeX)/2),
new Vector3f(sizeX, yOffset, (sizeY+sizeX)/2), EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY + sizeX) / 2),
new Vector3f(sizeX, yOffset, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
Matrix4 rot = new Matrix4();
rot.translate((sizeX)/2, -.01F, sizeY/2);
rot.rotate(Math.PI*1/16*(active?-1:1), 1, 0, 0);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(-rodRadius, 0, -rodRadius), new Vector3f(2*rodRadius, rodLength, 2*rodRadius), ret,
rot.translate((sizeX) / 2, -.01F, sizeY / 2);
rot.rotate(Math.PI * 1 / 16 * (active ? -1 : 1), 1, 0, 0);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(-rodRadius, 0, -rodRadius), new Vector3f(2 * rodRadius, rodLength, 2 * rodRadius), ret,
false, rot);
return ret;
}
@ -108,18 +113,17 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb==null) {
aabb = new AxisAlignedBB(x, 0, y, x+sizeX, getHeight(), y +sizeY);
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + sizeX, getHeight(), y + sizeY);
}
return aabb;
}
@Override
public boolean interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
setOut(!active, tile);
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
@Override
@ -129,39 +133,39 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Override
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
if (id == rsOutputId) {
rsOut.add(out);
out.accept((int) rsOutputChannel, (byte) (active?15:0));
out.accept((int) rsOutputChannel, (byte) (active ? 15 : 0));
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
if (id==rsOutputId) {
if (id == rsOutputId) {
rsOut.remove(out);
}
}
@Override
public float getHeight() {
return .0625F*3/2;
return .0625F * 3 / 2;
}
@Override
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
double zOffset = (aabb.maxZ-aabb.minZ-sizeX)/2;
int left = (int) (gui.getX0()+aabb.minX*gui.panelSize);
int top = (int) Math.ceil(gui.getY0()+(aabb.minZ+zOffset)*gui.panelSize);
int right = (int) (gui.getX0()+aabb.maxX*gui.panelSize);
int bottom = (int) Math.floor(gui.getY0()+(aabb.maxZ-zOffset)*gui.panelSize);
double zOffset = (aabb.maxZ - aabb.minZ - sizeX) / 2;
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) Math.ceil(gui.getY0() + (aabb.minZ + zOffset) * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) Math.floor(gui.getY0() + (aabb.maxZ - zOffset) * gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT);
double xOffset = (aabb.maxX-aabb.minX-rodRadius)/2;
left = (int) (gui.getX0()+(aabb.minX+xOffset)*gui.panelSize);
top = (int) Math.floor(gui.getY0()+(aabb.minZ+aabb.maxZ)/2*gui.panelSize);
right = (int) (gui.getX0()+(aabb.maxX-xOffset)*gui.panelSize);
bottom = (int) Math.ceil(gui.getY0()+aabb.maxZ*gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT+0x101010);
double xOffset = (aabb.maxX - aabb.minX - rodRadius) / 2;
left = (int) (gui.getX0() + (aabb.minX + xOffset) * gui.panelSize);
top = (int) Math.floor(gui.getY0() + (aabb.minZ + aabb.maxZ) / 2 * gui.panelSize);
right = (int) (gui.getX0() + (aabb.maxX - xOffset) * gui.panelSize);
bottom = (int) Math.ceil(gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, GRAY_INT + 0x101010);
}
@ -174,8 +178,8 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
active = on;
tile.markDirty();
tile.triggerRenderUpdate();
for (BiConsumer<Integer, Byte> rs:rsOut) {
rs.accept((int)rsOutputChannel, (byte)(active?15:0));
for (BiConsumer<Integer, Byte> rs : rsOut) {
rs.accept((int) rsOutputChannel, (byte) (active ? 15 : 0));
}
}
@ -204,49 +208,49 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
if (id==0) {
rsOutputChannel = ((NBTTagByte)value).getByte();
}
break;
case INT:
if (id==0) {
rsOutputId = ((NBTTagInt)value).getInt();
}
break;
case RS_CHANNEL:
if (id == 0) {
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
}
}
@Override
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID+".desc."+(id==0?"red":(id==1?"green":"blue")));
default:
return "INVALID";
case RS_CHANNEL:
case INT:
return null;
case FLOAT:
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
default:
return "INVALID";
}
}
@Override
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID+".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID+".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
return "INVALID?";
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte)rsOutputChannel)};
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override

View file

@ -131,7 +131,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double xRel = hitRelative.xCoord - SIZE / 2;
double yRel = -(hitRelative.zCoord - SIZE / 2);
double angle = 1.5 * Math.PI - Math.atan2(yRel, xRel);
@ -143,7 +143,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
angle -= .5 * Math.PI / 17;
angle /= 2 * Math.PI;
if (angle < 0 || angle >= 16 / 17D) {
return true;
return;
}
byte newLevel = (byte) (angle * 17);
if (newLevel > out) {
@ -159,9 +159,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
return true;
}
return false;
}
@Override

View file

@ -28,7 +28,8 @@ import net.minecraftforge.oredict.OreDictionary;
public class RecipeCoilLength implements IRecipe {
public final ItemStack coil;
public final ItemStack cable;
final int maxLength;
private final int maxLength;
public RecipeCoilLength(int meta) {
coil = new ItemStack(IndustrialWires.coil, 1, meta);
cable = ItemIC2Coil.getUninsulatedCable(coil);
@ -38,7 +39,7 @@ public class RecipeCoilLength implements IRecipe {
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
int l = getLength(inv);
return l>0;
return l > 0;
}
@Override
@ -76,12 +77,13 @@ public class RecipeCoilLength implements IRecipe {
}
return ret;
}
private int getLength(InventoryCrafting inv) {
int cableLength = 0;
for (int i = 0;i<inv.getSizeInventory();i++) {
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack curr = inv.getStackInSlot(i);
if (OreDictionary.itemMatches(curr, coil, false)) {
cableLength+=ItemIC2Coil.getLength(curr);
cableLength += ItemIC2Coil.getLength(curr);
} else if (OreDictionary.itemMatches(curr, cable, false)) {
cableLength++;
} else if (curr!=null) {

View file

@ -17,10 +17,6 @@
*/
package malte0811.industrialWires.items;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.TargetingInfo;
@ -53,7 +49,12 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
public class ItemIC2Coil extends Item implements IWireCoil{
import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ItemIC2Coil extends Item implements IWireCoil {
public final static String[] subNames = {"tin", "copper", "gold", "hv", "glass"};
public final static String lengthKey = "wireLength";
@ -62,11 +63,12 @@ public class ItemIC2Coil extends Item implements IWireCoil{
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
ImmersiveEngineering.registerByFullName(this, IndustrialWires.MODID+":"+"ic2WireCoil");
ImmersiveEngineering.registerByFullName(this, IndustrialWires.MODID + ":" + "ic2WireCoil");
}
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0;i<subNames.length;i++) {
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
for (int i = 0; i < subNames.length; i++) {
ItemStack tmp = new ItemStack(this, 1, i);
setLength(tmp, getMaxWireLength(tmp));
subItems.add(tmp);
@ -74,23 +76,29 @@ public class ItemIC2Coil extends Item implements IWireCoil{
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return this.getUnlocalizedName()+"."+subNames[stack.getMetadata()];
return this.getUnlocalizedName() + "." + subNames[stack.getMetadata()];
}
@Override
public WireType getWireType(ItemStack stack) {
return IC2Wiretype.IC2_TYPES[stack.getMetadata()];
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean adv) {
list.add(I18n.format(IndustrialWires.MODID+".desc.wireLength", getLength(stack)));
list.add(I18n.format(IndustrialWires.MODID+".desc.recipe"));
if(stack.getTagCompound()!=null && stack.getTagCompound().hasKey("linkingPos")) {
list.add(I18n.format(IndustrialWires.MODID + ".desc.wireLength", getLength(stack)));
int transferRate = IC2Wiretype.IC2_TYPES[stack.getMetadata()].getTransferRate();
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate", transferRate));
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate", transferRate / 8));
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) {
int[] link = stack.getTagCompound().getIntArray("linkingPos");
if(link!=null&&link.length>3) {
list.add(I18n.format(Lib.DESC_INFO+"attachedToDim", link[1],link[2],link[3],link[0]));
if (link.length > 3) {
list.add(I18n.format(Lib.DESC_INFO + "attachedToDim", link[1], link[2], link[3], link[0]));
}
}
list.add(I18n.format(IndustrialWires.MODID + ".desc.recipe"));
}
//mostly copied from IE
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
@ -100,27 +108,26 @@ public class ItemIC2Coil extends Item implements IWireCoil{
return EnumActionResult.FAIL;
}
TileEntity tileEntity = world.getTileEntity(pos);
if(tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable)tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX,hitY,hitZ);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
WireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable)tileEntity).getConnectionMaster(wire, target);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
tileEntity = world.getTileEntity(masterPos);
if( !(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable)tileEntity).canConnect()) {
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect()) {
return EnumActionResult.PASS;
}
if( !((IImmersiveConnectable)tileEntity).canConnectCable(wire, target)) {
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN+"wrongCable"));
return EnumActionResult.FAIL;
}
if(!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(),masterPos.getX(),masterPos.getY(),masterPos.getZ()});
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ()});
target.writeToNBT(stack.getTagCompound());
} else {
WireType type = getWireType(stack);
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1],array[2],array[3]);
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
int distanceSq = (int) Math.ceil( linkPos.distanceSq(masterPos) );
if(array[0]!=world.provider.getDimension()) {
@ -132,13 +139,13 @@ public class ItemIC2Coil extends Item implements IWireCoil{
} else if(!(tileEntityLinkingPos instanceof IImmersiveConnectable)||!((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(type, TargetingInfo.readFromNBT(stack.getTagCompound()))) {
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN+"invalidPoint"));
} else {
IImmersiveConnectable nodeHere = (IImmersiveConnectable)tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable)tileEntityLinkingPos;
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
boolean connectionExists = false;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
if(outputs!=null) {
for(Connection con : outputs) {
if(con.end.equals(Utils.toCC(nodeLink))) {
if (outputs != null) {
for (Connection con : outputs) {
if (con.end.equals(Utils.toCC(nodeLink))) {
connectionExists = true;
}
}
@ -151,11 +158,11 @@ public class ItemIC2Coil extends Item implements IWireCoil{
Set<BlockPos> ignore = new HashSet<>();
ignore.addAll(nodeHere.getIgnored(nodeLink));
ignore.addAll(nodeLink.getIgnored(nodeHere));
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore)==null;
if(canSee) {
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
if (canSee) {
int lengthOnStack = getLength(stack);
int length = (int)Math.sqrt(distanceSq);
if (length<=lengthOnStack) {
int length = (int) Math.sqrt(distanceSq);
if (length <= lengthOnStack) {
TargetingInfo targetLink = TargetingInfo.readFromNBT(stack.getTagCompound());
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), length, type);
@ -164,21 +171,21 @@ public class ItemIC2Coil extends Item implements IWireCoil{
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if(!player.capabilities.isCreativeMode) {
if (length<lengthOnStack) {
setLength(stack, lengthOnStack-length);
if (!player.capabilities.isCreativeMode) {
if (length < lengthOnStack) {
setLength(stack, lengthOnStack - length);
} else {
player.setHeldItem(hand, null);
}
}
((TileEntity)nodeHere).markDirty();
((TileEntity) nodeHere).markDirty();
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
IBlockState state = world.getBlockState(masterPos);
world.notifyBlockUpdate(masterPos, state,state, 3);
((TileEntity)nodeLink).markDirty();
world.notifyBlockUpdate(masterPos, state, state, 3);
((TileEntity) nodeLink).markDirty();
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state,state, 3);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else {
player.addChatMessage(new TextComponentTranslation(IndustrialWires.MODID+".chat.tooLong"));
}
@ -198,18 +205,22 @@ public class ItemIC2Coil extends Item implements IWireCoil{
}
return EnumActionResult.PASS;
}
public static void setLength(ItemStack i, int blocks) {
i.setTagInfo(lengthKey, new NBTTagInt(blocks));
}
public static int getLength(ItemStack i) {
if (i.getTagCompound()==null) {
if (i.getTagCompound() == null) {
setLength(i, 4);
}
return i.getTagCompound().getInteger(lengthKey);
}
public static int getMaxWireLength(ItemStack i) {
return IWConfig.maxLengthOnCoil[i.getItemDamage()];
}
public static ItemStack getUninsulatedCable(ItemStack i) {
switch (i.getMetadata()) {
case 0:

View file

@ -103,7 +103,7 @@ public class ItemPanelComponent extends Item {
outer.setTag("data", inner);
int meta = getMetaFromPC(inner.getString("type"));
removeIrrelevantTags(inner);
if (meta>=0) {
if (meta >= 0) {
ItemStack ret = new ItemStack(IndustrialWires.panelComponent, 1, meta);
ret.setTagCompound(outer);
return ret;
@ -119,7 +119,7 @@ public class ItemPanelComponent extends Item {
}
private static int getMetaFromPC(String pc) {
for (int i = 0;i<types.length;i++) {
for (int i = 0; i < types.length; i++) {
if (pc.equals(types[i])) {
return i;
}

View file

@ -46,7 +46,8 @@ public class MessageComponentSync implements IMessage {
this.data = data;
}
public MessageComponentSync() {}
public MessageComponentSync() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -66,6 +67,7 @@ public class MessageComponentSync implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessageComponentSync msg, EntityPlayerMP player) {
ItemStack held = player.getHeldItem(msg.hand);
if (held!=null&&held.getItem()== IndustrialWires.panelComponent) {

View file

@ -38,7 +38,8 @@ public class MessageGUIInteract implements IMessage {
this.data = data;
}
public MessageGUIInteract() {}
public MessageGUIInteract() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -60,6 +61,7 @@ public class MessageGUIInteract implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessageGUIInteract msg, EntityPlayerMP player) {
if (player.getDistanceSqToCenter(msg.pos)<100) {//closer than 10 blocks
TileEntity te = player.worldObj.getTileEntity(msg.pos);

View file

@ -41,7 +41,8 @@ public class MessagePanelInteract implements IMessage {
hitRelative = hit;
}
public MessagePanelInteract() {}
public MessagePanelInteract() {
}
@Override
public void fromBytes(ByteBuf buf) {
@ -67,6 +68,7 @@ public class MessagePanelInteract implements IMessage {
ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(()->handle(message, ctx.getServerHandler().playerEntity));
return null;
}
private void handle(MessagePanelInteract msg, EntityPlayerMP player) {
if (player.getDistanceSqToCenter(msg.pos)<100) {//closer than 10 blocks
TileEntity te = player.worldObj.getTileEntity(msg.pos);

View file

@ -41,7 +41,8 @@ public class MessageTileSyncIW implements IMessage {
this.nbt = nbt;
}
public MessageTileSyncIW() {}
public MessageTileSyncIW() {
}
@Override
public void fromBytes(ByteBuf buf) {

View file

@ -21,27 +21,31 @@ package malte0811.industrialWires.util;
import net.minecraft.util.math.Vec3d;
public final class Beziers {
private Beziers() {}
private Beziers() {
}
public static Vec3d getPoint(double t, Vec3d[] controls) {
if (t==0) {
if (t == 0) {
return controls[0];
} else if (t==1) {
return controls[controls.length-1];
} else if (t == 1) {
return controls[controls.length - 1];
}
Vec3d ret = new Vec3d(0, 0, 0);
int n = controls.length-1;
for (int i = 0;i<=n;i++) {
double coeff = binomialCoeff(n, i)*Math.pow(t, i)*Math.pow(1-t, n-i);
ret = ret.addVector(coeff*controls[i].xCoord, coeff*controls[i].yCoord, coeff*controls[i].zCoord);
int n = controls.length - 1;
for (int i = 0; i <= n; i++) {
double coeff = binomialCoeff(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
ret = ret.addVector(coeff * controls[i].xCoord, coeff * controls[i].yCoord, coeff * controls[i].zCoord);
}
return ret;
}
public static int binomialCoeff(int n, int k) {
return factorial(n-k+1, n)/factorial(2, k);
return factorial(n - k + 1, n) / factorial(2, k);
}
public static int factorial(int start, int end) {
int ret = 1;
for (int i = start;i<=end;i++) {
for (int i = start; i <= end; i++) {
ret *= i;
}
return ret;

View file

@ -21,29 +21,38 @@ import blusunrize.immersiveengineering.common.Config;
import malte0811.industrialWires.IWConfig.MechConversion;
public class ConversionUtil {
private ConversionUtil() {}
public static double rotPerIf() {
return 1/Config.IEConfig.Machines.dynamo_output;
private ConversionUtil() {
}
public static double rotPerIf() {
return 1 / Config.IEConfig.Machines.dynamo_output;
}
public static double ifPerRot() {
return Config.IEConfig.Machines.dynamo_output;
}
public static double euPerIfIdeal() {
return MechConversion.euPerIf;
}
public static double ifPerEuIdeal() {
return 1/MechConversion.euPerIf;
return 1 / MechConversion.euPerIf;
}
public static double euPerKin() {
return 1/euPerKin();
return 1 / euPerKin();
}
public static double kinPerEu() {
return MechConversion.kinPerEu;
}
public static double kinPerRot() {
return kinPerEu()*euPerIfIdeal()*ifPerRot();
return kinPerEu() * euPerIfIdeal() * ifPerRot();
}
public static double rotPerKin() {
return 1/kinPerRot();
return 1 / kinPerRot();
}
}

View file

@ -29,6 +29,7 @@ public class DualEnergyStorage {
public DualEnergyStorage(double maxEU, double maxInEU, double maxOutEU) {
this(0, maxEU, maxInEU, maxOutEU);
}
public DualEnergyStorage(double storedEU, double maxEU, double maxInEU, double maxOutEU) {
this.maxEU = maxEU;
this.maxInEU = maxInEU;
@ -103,15 +104,16 @@ public class DualEnergyStorage {
}
public void writeToNbt(NBTTagCompound nbtOuter, String key) {
NBTTagCompound nbt = key==null?nbtOuter:new NBTTagCompound();
NBTTagCompound nbt = key == null ? nbtOuter : new NBTTagCompound();
nbt.setDouble("stored", storedEU);
nbt.setDouble("maxStored", maxEU);
nbt.setDouble("maxIn", maxInEU);
nbt.setDouble("maxOut", maxOutEU);
if (key!=null) {
if (key != null) {
nbtOuter.setTag(key, nbt);
}
}
public static DualEnergyStorage readFromNBT(NBTTagCompound nbt) {
return new DualEnergyStorage(nbt.getDouble("stored"), nbt.getDouble("maxStored"), nbt.getDouble("maxIn"), nbt.getDouble("maxOut"));
}

View file

@ -22,10 +22,6 @@ import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@ -37,16 +33,15 @@ import java.util.Set;
import java.util.function.BiPredicate;
public final class MiscUtils {
private MiscUtils() {}
public static Set<ImmersiveNetHandler.Connection> genConnBlockstate(Set<ImmersiveNetHandler.Connection> conns, World world)
{
private MiscUtils() {
}
public static Set<ImmersiveNetHandler.Connection> genConnBlockstate(Set<ImmersiveNetHandler.Connection> conns, World world) {
if (conns == null)
return ImmutableSet.of();
Set<ImmersiveNetHandler.Connection> ret = new HashSet<ImmersiveNetHandler.Connection>()
{
Set<ImmersiveNetHandler.Connection> ret = new HashSet<ImmersiveNetHandler.Connection>() {
@Override
public boolean equals(Object o)
{
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof HashSet))
@ -60,10 +55,9 @@ public final class MiscUtils {
return true;
}
};
for (ImmersiveNetHandler.Connection c : conns)
{
for (ImmersiveNetHandler.Connection c : conns) {
IImmersiveConnectable end = ApiUtils.toIIC(c.end, world, false);
if (end==null)
if (end == null)
continue;
// generate subvertices
c.getSubVertices(world);
@ -72,23 +66,7 @@ public final class MiscUtils {
return ret;
}
public static List<BlockPos> discoverPanelParts(World w, BlockPos here) {
BiPredicate<BlockPos, Integer> isValid = (pos, count)->{
if (here.distanceSq(pos)>25||count>100||!w.isBlockLoaded(pos)) {
return false;
}
IBlockState state = w.getBlockState(pos);
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type) != BlockTypes_Panel.CREATOR;
};
List<BlockPos> all = discoverLocal(w, here, isValid);
List<BlockPos> ret = new ArrayList<>();
for (BlockPos pos:all) {
if (w.getBlockState(pos).getValue(BlockPanel.type)!= BlockTypes_Panel.DUMMY) {
ret.add(pos);
}
}
return ret;
}
public static List<BlockPos> discoverLocal(World w, BlockPos here, BiPredicate<BlockPos, Integer> isValid) {
List<BlockPos> ret = new ArrayList<>();
List<BlockPos> open = new ArrayList<>();
@ -97,9 +75,9 @@ public final class MiscUtils {
BlockPos curr = open.get(0);
ret.add(curr);
open.remove(0);
for (EnumFacing f:EnumFacing.VALUES) {
for (EnumFacing f : EnumFacing.VALUES) {
BlockPos next = curr.offset(f);
if (!open.contains(next)&&!ret.contains(next)&&isValid.test(next, ret.size())) {
if (!open.contains(next) && !ret.contains(next) && isValid.test(next, ret.size())) {
open.add(next);
}
}

View file

@ -28,18 +28,20 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class IC2Wiretype extends WireType{
public class IC2Wiretype extends WireType {
final int type;
final int[] ic2Rates = {32*8, 128*8, 512*8, 2048*8, 8192*8};
final int[] ic2Rates = {32 * 8, 128 * 8, 512 * 8, 2048 * 8, 8192 * 8};
final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1};
final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass"};
final double[] lossPerBlock = {.2, .2, .4, .8, .025};
final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75*.03125};
final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75 * .03125};
public static final IC2Wiretype[] IC2_TYPES = {new IC2Wiretype(0), new IC2Wiretype(1), new IC2Wiretype(2), new IC2Wiretype(3), new IC2Wiretype(4)};
public IC2Wiretype(int ordinal) {
super();
this.type = ordinal;
}
/**
* In this case, this does not return the loss RATIO but the loss PER BLOCK
*/
@ -47,45 +49,55 @@ public class IC2Wiretype extends WireType{
public double getLossRatio() {
return lossPerBlock[type];
}
@Override
public int getTransferRate() {
return ic2Rates[type];
}
@Override
public int getColour(Connection connection) {
return ic2Colors[type];
}
@Override
public double getSlack() {
return type==2?1.03:1.005;
return type == 2 ? 1.03 : 1.005;
}
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getIcon(Connection connection) {
return iconDefaultWire;
}
@Override
public int getMaxLength() {
return IWConfig.maxLengthPerConn[type];
}
@Override
public ItemStack getWireCoil(ImmersiveNetHandler.Connection con) {
ItemStack ret = getWireCoil();
ItemIC2Coil.setLength(ret, con.length);
return ret;
}
@Override
public ItemStack getWireCoil() {
return new ItemStack(IndustrialWires.coil,1,type);
return new ItemStack(IndustrialWires.coil, 1, type);
}
@Override
public String getUniqueName() {
return ic2Names[type];
}
@Override
public double getRenderDiameter() {
return ic2RenderDiameter[type];
}
@Override
public boolean isEnergyWire() {
return true;

View file

@ -22,11 +22,11 @@ tile.industrialwires.control_panel.rs_wire.name=Redstone Wire Controller
tile.industrialwires.control_panel.dummy.name=Panel Connector
tile.industrialwires.control_panel.creator.name=Control Panel Creator
item.industrialwires.ic2wireCoil.tin.name=Tin Wire Coil
item.industrialwires.ic2wireCoil.copper.name=Copper Wire Coil
item.industrialwires.ic2wireCoil.gold.name=Gold Wire Coil
item.industrialwires.ic2wireCoil.hv.name=IC2 HV Wire Coil
item.industrialwires.ic2wireCoil.glass.name=Glass Fiber Wire Coil
item.industrialwires.ic2_wire_coil.tin.name=Tin Wire Coil
item.industrialwires.ic2_wire_coil.copper.name=Copper Wire Coil
item.industrialwires.ic2_wire_coil.gold.name=Gold Wire Coil
item.industrialwires.ic2_wire_coil.hv.name=IC2 HV Wire Coil
item.industrialwires.ic2_wire_coil.glass.name=Glass Fiber Wire Coil
item.industrialwires.panel_component.lighted_button.name=Lighted Button
item.industrialwires.panel_component.label.name=Label
@ -53,6 +53,7 @@ industrialwires.desc.red=Red
industrialwires.desc.green=Green
industrialwires.desc.blue=Blue
industrialwires.desc.length=Length
industrialwires.tooltip.rsChannel_info=The color of the channel to output the signal to
industrialwires.tooltip.horizontal=Horizontal
industrialwires.tooltip.vertical=Vertical
@ -61,6 +62,11 @@ industrialwires.tooltip.text=Text: %1s
industrialwires.tooltip.latching=Stays on indefinitely
industrialwires.tooltip.instantaneous=Turns off after half a second
industrialwires.tooltip.length=Length: %1s
industrialwires.tooltip.power_tier=Power Tier: %s
industrialwires.tooltip.eu_per_tick=%s EU/t
industrialwires.tooltip.transfer_rate=Burns at %s EU/t
industrialwires.tooltip.input_rate=%s EU/t per connector
industrialwires.chat.tooLong=This coil does not contain enough wire for this connection
industrialwires.chat.stackSize=Linking is only possible with a stack of size 1