General refactoring, IC2 connectors no longer use BlockIEBase!

This commit is contained in:
malte0811 2017-03-21 18:12:09 +01:00
parent 12e18534fe
commit b36e5c2623
11 changed files with 356 additions and 214 deletions

View file

@ -1,5 +1,5 @@
def mainVersion = "1.3" def mainVersion = "1.3"
def buildNumber = "7" def buildNumber = "8"
/* /*
* This file is part of Industrial Wires. * This file is part of Industrial Wires.

View file

@ -1,3 +1,5 @@
#####Version 1.3-8
- the converters and the motor don't have missing textures any more when using Chisel
#####Version 1.3-7 #####Version 1.3-7
- added Jacob's Ladders/High voltage travelling arcs - added Jacob's Ladders/High voltage travelling arcs
- they don't have a particular purpose aside from looking nice - they don't have a particular purpose aside from looking nice

View file

@ -0,0 +1,184 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
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);
setCreativeTab(IndustrialWires.creativeTab);
}
@Override
protected BlockStateContainer createBlockState() {
if (properties==null) {
properties = getProperties();
}
BlockStateContainer cont = super.createBlockState();
IProperty[] props = cont.getProperties().toArray(new IProperty[0]);
int oldLength = props.length;
props = Arrays.copyOf(props, oldLength + properties.length);
System.arraycopy(properties, 0, props, oldLength, properties.length);
return new BlockStateContainer(this, props);
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
state = super.getActualState(state, worldIn, pos);
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof IHasDummyBlocksIW) {
state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocksIW) tile).isDummy());
}
if (tile instanceof IEBlockInterfaces.IDirectionalTile) {
state = state.withProperty(IEProperties.FACING_ALL, ((IEBlockInterfaces.IDirectionalTile) tile).getFacing());
}
return state;
}
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) {
return in.withProperty(prop, val);
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).breakDummies();
}
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof IEBlockInterfaces.IDirectionalTile) {
((IEBlockInterfaces.IDirectionalTile)te).setFacing(state.getValue(IEProperties.FACING_ALL));
}
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).placeDummies(state);
}
}
@Nullable
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
return getBoundingBox(blockState, worldIn, pos);
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
AxisAlignedBB axisalignedbb = getBoundingBox(state, worldIn, pos).offset(pos);
if (entityBox.intersectsWith(axisalignedbb)) {
collidingBoxes.add(axisalignedbb);
}
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
TileEntity te = source.getTileEntity(pos);
if (te instanceof IBlockBoundsIW) {
AxisAlignedBB ret = ((IBlockBoundsIW) te).getBoundingBox();
if (ret!=null) {
return ret;
}
}
return super.getBoundingBox(state, source, pos);
}
//mostly copied from IE
@Override
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) {
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) {
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();
}
if (f!=original) {
directionalTe.setFacing(f);
te.markDirty();
world.notifyBlockUpdate(pos,state,state,3);
world.addBlockEvent(pos, this, 255, 0);
}
return true;
}
} else if (te instanceof IEBlockInterfaces.IPlayerInteraction) {
((IEBlockInterfaces.IPlayerInteraction) te).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
}
return false;
}
@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) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;
}
return def;
}
protected abstract IProperty[] getProperties();
}

View file

@ -50,56 +50,29 @@ import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class BlockJacobsLadder extends Block implements IMetaEnum, IPlacementCheck { public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacementCheck {
static PropertyEnum<LadderSize> size_property = PropertyEnum.create("size", LadderSize.class); private static PropertyEnum<LadderSize> size_property = PropertyEnum.create("size", LadderSize.class);
public BlockJacobsLadder() { public BlockJacobsLadder() {
super(Material.IRON); super(Material.IRON, "jacobs_ladder");
setHardness(3.0F);
setResistance(15.0F);
String name = "jacobs_ladder";
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name));
setUnlocalizedName(IndustrialWires.MODID+"."+name);
setCreativeTab(IndustrialWires.creativeTab);
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).breakDummies();
}
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
@Override
protected BlockStateContainer createBlockState() {
BlockStateContainer cont = super.createBlockState();
IProperty[] props = cont.getProperties().toArray(new IProperty[0]);
props = Arrays.copyOf(props, props.length + 3);
props[props.length - 3] = size_property;
props[props.length - 2] = IEProperties.MULTIBLOCKSLAVE;
props[props.length - 1] = IEProperties.FACING_HORIZONTAL;
return new BlockStateContainer(this, props);
} }
@Override @Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
state = super.getActualState(state, worldIn, pos);
TileEntity tile = worldIn.getTileEntity(pos); TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof IHasDummyBlocksIW) {
state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocksIW) tile).isDummy());
}
if (tile instanceof TileEntityJacobsLadder) { if (tile instanceof TileEntityJacobsLadder) {
state = applyProperty(state, size_property, ((TileEntityJacobsLadder) tile).size); state = applyProperty(state, size_property, ((TileEntityJacobsLadder) tile).size);
state = applyProperty(state, IEProperties.FACING_HORIZONTAL, ((TileEntityJacobsLadder) tile).facing); state = applyProperty(state, IEProperties.FACING_HORIZONTAL, ((TileEntityJacobsLadder) tile).facing);
} }
return super.getActualState(state, worldIn, pos); return state;
} }
private <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, V val) { @Override
return in.withProperty(prop, val); protected IProperty[] getProperties() {
return new IProperty[]{
size_property, IEProperties.MULTIBLOCKSLAVE, IEProperties.FACING_HORIZONTAL
};
} }
@Override @Override
@ -176,51 +149,6 @@ public class BlockJacobsLadder extends Block implements IMetaEnum, IPlacementChe
if (te instanceof TileEntityJacobsLadder) { if (te instanceof TileEntityJacobsLadder) {
((TileEntityJacobsLadder) te).facing = state.getValue(IEProperties.FACING_HORIZONTAL); ((TileEntityJacobsLadder) te).facing = state.getValue(IEProperties.FACING_HORIZONTAL);
} }
if (te instanceof IHasDummyBlocksIW) {
((IHasDummyBlocksIW) te).placeDummies(state);
}
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
TileEntity te = source.getTileEntity(pos);
if (!(te instanceof TileEntityJacobsLadder)) {
return FULL_BLOCK_AABB;
}
TileEntityJacobsLadder tile = (TileEntityJacobsLadder) te;
if (!tile.isDummy()) {
//transformer
return FULL_BLOCK_AABB;
} else {
Vec3d min;
Vec3d max;
LadderSize size = tile.size;
double distX = (1 - size.topDistance) / 2;
double distZ = .5 - .0625 * (size.ordinal() + 1);
double h = Math.min(1, 1 + size.height - tile.dummy);
if (tile.facing.getAxis() == EnumFacing.Axis.Z) {
min = new Vec3d(distX, 0, distZ);
max = new Vec3d(1 - distX, h, 1 - distZ);
} else {
min = new Vec3d(distZ, 0, distX);
max = new Vec3d(1 - distZ, h, 1 - distX);
}
return new AxisAlignedBB(min.xCoord, min.yCoord, min.zCoord, max.xCoord, max.yCoord, max.zCoord);
}
}
@Nullable
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) {
return getBoundingBox(blockState, worldIn, pos);
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
AxisAlignedBB axisalignedbb = getBoundingBox(state, worldIn, pos).offset(pos);
if (entityBox.intersectsWith(axisalignedbb)) {
collidingBoxes.add(axisalignedbb);
}
} }
@Override @Override
@ -262,15 +190,4 @@ public class BlockJacobsLadder extends Block implements IMetaEnum, IPlacementChe
TileEntity te = world.getTileEntity(pos); TileEntity te = world.getTileEntity(pos);
return te instanceof TileEntityJacobsLadder && ((TileEntityJacobsLadder) te).rotate(world, pos, axis); return te instanceof TileEntityJacobsLadder && ((TileEntityJacobsLadder) te).rotate(world, pos, axis);
} }
@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) {
IBlockState s = worldIn.getBlockState(pos);
worldIn.notifyBlockUpdate(pos, s, s, 3);
return true;
}
return def;
}
} }

View file

@ -0,0 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks;
import net.minecraft.util.math.AxisAlignedBB;
public interface IBlockBoundsIW {
AxisAlignedBB getBoundingBox();
}

View file

@ -29,6 +29,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.network.MessageTileSyncIW; import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.util.Beziers; import malte0811.industrialWires.util.Beziers;
import malte0811.industrialWires.util.DualEnergyStorage; import malte0811.industrialWires.util.DualEnergyStorage;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -49,7 +50,7 @@ import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickable, IHasDummyBlocksIW, ISyncReceiver, IEnergySink { public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickable, IHasDummyBlocksIW, ISyncReceiver, IEnergySink, IBlockBoundsIW {
public EnumFacing facing = EnumFacing.NORTH; public EnumFacing facing = EnumFacing.NORTH;
private DualEnergyStorage energy; private DualEnergyStorage energy;
public LadderSize size; public LadderSize size;
@ -447,6 +448,29 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
return new AxisAlignedBB(pos, pos.add(1, 2, 1)); return new AxisAlignedBB(pos, pos.add(1, 2, 1));
} }
@Override
public AxisAlignedBB getBoundingBox() {
if (!isDummy()) {
//transformer
return Block.FULL_BLOCK_AABB;
} else {
Vec3d min;
Vec3d max;
double distX = (1 - size.topDistance) / 2;
double distZ = .5 - .0625 * (size.ordinal() + 1);
double h = Math.min(1, 1 + size.height - dummy);
if (facing.getAxis() == EnumFacing.Axis.Z) {
min = new Vec3d(distX, 0, distZ);
max = new Vec3d(1 - distX, h, 1 - distZ);
} else {
min = new Vec3d(distZ, 0, distX);
max = new Vec3d(1 - distZ, h, 1 - distX);
}
return new AxisAlignedBB(min.xCoord, min.yCoord, min.zCoord, max.xCoord, max.yCoord, max.zCoord);
}
}
public enum LadderSize implements IStringSerializable { public enum LadderSize implements IStringSerializable {
/* /*
all on a block (HV transformer) all on a block (HV transformer)

View file

@ -21,11 +21,13 @@ import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile; import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import blusunrize.immersiveengineering.common.util.Utils; import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum; import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.blocks.ItemBlockIW; import malte0811.industrialWires.blocks.ItemBlockIW;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -46,17 +48,10 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.List; import java.util.List;
public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileEntityProvider { public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
PropertyEnum<MechanicalBlockType> type; private static PropertyEnum<MechanicalBlockType> type = PropertyEnum.create("type", MechanicalBlockType.class);
public BlockMechanicalConverter() { public BlockMechanicalConverter() {
super(Material.IRON); super(Material.IRON, "mechanical_converter");
setHardness(3.0F);
setResistance(15.0F);
String name = "mechanical_converter";
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
GameRegistry.register(new ItemBlockIW(this), new ResourceLocation(IndustrialWires.MODID, name));
setUnlocalizedName(name);
setCreativeTab(IndustrialWires.creativeTab);
} }
@Override @Override
@ -67,20 +62,8 @@ public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileE
} }
@Override @Override
protected BlockStateContainer createBlockState() { protected IProperty[] getProperties() {
type = PropertyEnum.create("type", MechanicalBlockType.class); return new IProperty[]{type, IEProperties.FACING_ALL};
BlockStateContainer container = new BlockStateContainer(this, type, IEProperties.FACING_ALL);
return container;
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
IBlockState ret = super.getActualState(state, world, pos);
TileEntity te = world.getTileEntity(pos);
if (te instanceof IDirectionalTile) {
ret = ret.withProperty(IEProperties.FACING_ALL, ((IDirectionalTile) te).getFacing());
}
return ret;
} }
@Override @Override
@ -94,9 +77,9 @@ public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileE
} }
@Override @Override
public TileEntity createNewTileEntity(World worldIn, int meta) { public TileEntity createTileEntity(World world, IBlockState state) {
switch (MechanicalBlockType.values[meta]) { switch (state.getValue(type)) {
case IE_MOTOR: case IE_MOTOR:
return new TileEntityIEMotor(); return new TileEntityIEMotor();
case IE_TO_IC2: case IE_TO_IC2:
return new TileEntityMechIEtoIC(); return new TileEntityMechIEtoIC();
@ -117,15 +100,6 @@ public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileE
return base.withProperty(IEProperties.FACING_ALL, facing.getOpposite()); return base.withProperty(IEProperties.FACING_ALL, facing.getOpposite());
} }
@Override @Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof IDirectionalTile) {
((IDirectionalTile)te).setFacing(state.getValue(IEProperties.FACING_ALL));
}
}
@Override
public int damageDropped(IBlockState state) { public int damageDropped(IBlockState state) {
return state.getValue(type).ordinal(); return state.getValue(type).ordinal();
} }
@ -134,36 +108,6 @@ public class BlockMechanicalConverter extends Block implements IMetaEnum, ITileE
EntityPlayer player) { EntityPlayer player) {
return new ItemStack(this, 1, damageDropped(state)); return new ItemStack(this, 1, damageDropped(state));
} }
//mostly copied from IE
@Override
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 IDirectionalTile && Utils.isHammer(heldItem) && !world.isRemote) {
IDirectionalTile directionalTe = (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) {
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();
}
if (f!=original) {
directionalTe.setFacing(f);
te.markDirty();
world.notifyBlockUpdate(pos,state,state,3);
world.addBlockEvent(pos, this, 255, 0);
}
return true;
}
}
return false;
}
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) { public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {

View file

@ -1,6 +1,6 @@
/******************************************************************************* /*
* This file is part of Industrial Wires. * This file is part of Industrial Wires.
* Copyright (C) 2016 malte0811 * Copyright (C) 2016-2017 malte0811
* *
* Industrial Wires is free software: you can redistribute it and/or modify * Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -14,16 +14,19 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>. * along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/ */
package malte0811.industrialWires.blocks.wire; package malte0811.industrialWires.blocks.wire;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import blusunrize.immersiveengineering.api.IEProperties; import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable; import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable;
import blusunrize.immersiveengineering.common.blocks.BlockIETileProvider; import blusunrize.immersiveengineering.common.blocks.BlockIETileProvider;
import blusunrize.immersiveengineering.common.blocks.ItemBlockIEBase; import blusunrize.immersiveengineering.common.blocks.ItemBlockIEBase;
import blusunrize.immersiveengineering.common.util.IELogger;
import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum; import malte0811.industrialWires.blocks.IMetaEnum;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -31,6 +34,9 @@ import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -41,10 +47,10 @@ import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.common.property.IUnlistedProperty;
public class BlockIC2Connector extends BlockIETileProvider<BlockTypes_IC2_Connector> implements IMetaEnum { public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
private static PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
public BlockIC2Connector() { public BlockIC2Connector() {
super("ic2Connector", Material.IRON, PropertyEnum.create("type", BlockTypes_IC2_Connector.class), ItemBlockIEBase.class, IEProperties.FACING_ALL); super(Material.IRON, "ic2Connector");
setHardness(3.0F); setHardness(3.0F);
setResistance(15.0F); setResistance(15.0F);
lightOpacity = 0; lightOpacity = 0;
@ -61,6 +67,14 @@ public class BlockIC2Connector extends BlockIETileProvider<BlockTypes_IC2_Connec
} }
} }
} }
@Override
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
for (int i = 0;i<type.getAllowedValues().size();i++) {
list.add(new ItemStack(itemIn, 1, i));
}
}
@Override @Override
protected BlockStateContainer createBlockState() { protected BlockStateContainer createBlockState() {
BlockStateContainer base = super.createBlockState(); BlockStateContainer base = super.createBlockState();
@ -69,6 +83,27 @@ public class BlockIC2Connector extends BlockIETileProvider<BlockTypes_IC2_Connec
unlisted[unlisted.length-1] = IEProperties.CONNECTIONS; unlisted[unlisted.length-1] = IEProperties.CONNECTIONS;
return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted); return new ExtendedBlockState(this, base.getProperties().toArray(new IProperty[0]), unlisted);
} }
@Override
protected IProperty[] getProperties() {
return new IProperty[]{type, IEProperties.FACING_ALL};
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
state = super.getActualState(state, worldIn, pos);
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof TileEntityIC2ConnectorTin) {
state.withProperty(IEProperties.FACING_ALL, ((TileEntityIC2ConnectorTin) te).getFacing());
}
return state;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_IC2_Connector.values()[meta]);
}
@Override @Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
state = super.getExtendedState(state, world, pos); state = super.getExtendedState(state, world, pos);
@ -85,34 +120,37 @@ public class BlockIC2Connector extends BlockIETileProvider<BlockTypes_IC2_Connec
public boolean isSideSolid(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { public boolean isSideSolid(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
return false; return false;
} }
@Override @Override
public TileEntity createNewTileEntity(World worldIn, int meta) { public boolean hasTileEntity(IBlockState state) {
if (meta==0) return true;
return new TileEntityIC2ConnectorTin(false);
else if (meta==1)
return new TileEntityIC2ConnectorTin(true);
else if (meta==2)
return new TileEntityIC2ConnectorCopper(false);
else if (meta==3)
return new TileEntityIC2ConnectorCopper(true);
else if (meta==4)
return new TileEntityIC2ConnectorGold(false);
else if (meta==5)
return new TileEntityIC2ConnectorGold(true);
else if (meta==6)
return new TileEntityIC2ConnectorHV(false);
else if (meta==7)
return new TileEntityIC2ConnectorHV(true);
else if (meta==8)
return new TileEntityIC2ConnectorGlass(false);
else if (meta==9)
return new TileEntityIC2ConnectorGlass(true);
return null;
} }
@Override @Override
public String createRegistryName() { public TileEntity createTileEntity(World world, IBlockState state) {
return IndustrialWires.MODID+":"+name; switch (state.getValue(type)) {
case TIN_CONN:
return new TileEntityIC2ConnectorTin(false);
case TIN_RELAY:
return new TileEntityIC2ConnectorTin(true);
case COPPER_CONN:
return new TileEntityIC2ConnectorCopper(false);
case COPPER_RELAY:
return new TileEntityIC2ConnectorCopper(true);
case GOLD_CONN:
return new TileEntityIC2ConnectorGold(false);
case GOLD_RELAY:
return new TileEntityIC2ConnectorGold(true);
case HV_CONN:
return new TileEntityIC2ConnectorHV(false);
case HV_RELAY:
return new TileEntityIC2ConnectorHV(true);
case GLASS_CONN:
return new TileEntityIC2ConnectorGlass(false);
case GLASS_RELAY:
return new TileEntityIC2ConnectorGlass(true);
}
return null;
} }
@Override @Override
public boolean canRenderInLayer(BlockRenderLayer layer) { public boolean canRenderInLayer(BlockRenderLayer layer) {
@ -140,6 +178,11 @@ public class BlockIC2Connector extends BlockIETileProvider<BlockTypes_IC2_Connec
} }
@Override @Override
public Object[] getValues() { public Object[] getValues() {
return enumValues; return BlockTypes_IC2_Connector.values();
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(type).ordinal();
} }
} }

View file

@ -22,6 +22,8 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import net.minecraft.util.math.AxisAlignedBB;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -50,17 +52,17 @@ import net.minecraft.util.ITickable;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable implements IEnergySource, IEnergySink, IDirectionalTile, ITickable, IIC2Connector, IBlockBounds { public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable implements IEnergySource, IEnergySink, IDirectionalTile, ITickable, IIC2Connector, IBlockBoundsIW {
EnumFacing f = EnumFacing.NORTH; EnumFacing f = EnumFacing.NORTH;
boolean relay; boolean relay;
boolean first = true; private boolean first = true;
//IC2 net to IE net buffer //IC2 net to IE net buffer
double inBuffer = 0; private double inBuffer = 0;
double maxToNet = 0; private double maxToNet = 0;
//IE net to IC2 net buffer //IE net to IC2 net buffer
double outBuffer = 0; private double outBuffer = 0;
double maxToMachine = 0; private double maxToMachine = 0;
double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate()/8; protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate()/8;
int tier = 1; int tier = 1;
public TileEntityIC2ConnectorTin(boolean rel) { public TileEntityIC2ConnectorTin(boolean rel) {
relay = rel; relay = rel;
@ -299,27 +301,28 @@ public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable im
public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) { public boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity) {
return false; return false;
} }
@Override @Override
public float[] getBlockBounds() { 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 wMin = .3125f;
float wMax = .6875f; float wMax = .6875f;
switch(f.getOpposite() ) switch(f.getOpposite() )
{ {
case UP: case UP:
return new float[]{wMin,0,wMin, wMax,length,wMax}; return new AxisAlignedBB(wMin,0,wMin, wMax,length,wMax);
case DOWN: case DOWN:
return new float[]{wMin,1-length,wMin, wMax,1,wMax}; return new AxisAlignedBB(wMin,1-length,wMin, wMax,1,wMax);
case SOUTH: case SOUTH:
return new float[]{wMin,wMin,0, wMax,wMax,length}; return new AxisAlignedBB(wMin,wMin,0, wMax,wMax,length);
case NORTH: case NORTH:
return new float[]{wMin,wMin,1-length, wMax,wMax,1}; return new AxisAlignedBB(wMin,wMin,1-length, wMax,wMax,1);
case EAST: case EAST:
return new float[]{0,wMin,wMin, length,wMax,wMax}; return new AxisAlignedBB(0,wMin,wMin, length,wMax,wMax);
case WEST: case WEST:
return new float[]{1-length,wMin,wMin, 1,wMax,wMax}; return new AxisAlignedBB(1-length,wMin,wMin, 1,wMax,wMax);
} }
return new float[]{0,0,0,1,1,1}; return new AxisAlignedBB(0,0,0,1,1,1);
} }
/* /*
* regarding equals+hashCode * regarding equals+hashCode

View file

@ -9,9 +9,9 @@ tile.industrialwires.ic2Connector.hv_relay.name=IC2 HV Wire Relay
tile.industrialwires.ic2Connector.glass_conn.name=Glass Fiber Wire Connector tile.industrialwires.ic2Connector.glass_conn.name=Glass Fiber Wire Connector
tile.industrialwires.ic2Connector.glass_relay.name=Glass Fiber Wire Relay tile.industrialwires.ic2Connector.glass_relay.name=Glass Fiber Wire Relay
tile.mechanical_converter.ie_motor.name=Rotational Motor tile.industrialwires.mechanical_converter.ie_motor.name=Rotational Motor
tile.mechanical_converter.ie_to_ic2.name=Converter: Rotational To Kinetic tile.industrialwires.mechanical_converter.ie_to_ic2.name=Converter: Rotational To Kinetic
tile.mechanical_converter.ic2_to_ie.name=Converter: Kinetic To Rotational tile.industrialwires.mechanical_converter.ic2_to_ie.name=Converter: Kinetic To Rotational
tile.industrialwires.jacobs_ladder.small.name=Small Jacob's ladder tile.industrialwires.jacobs_ladder.small.name=Small Jacob's ladder
tile.industrialwires.jacobs_ladder.normal.name=Jacob's ladder tile.industrialwires.jacobs_ladder.normal.name=Jacob's ladder

View file

@ -9,9 +9,9 @@ tile.industrialwires.ic2Connector.hv_relay.name=工业2高压继电器
tile.industrialwires.ic2Connector.glass_conn.name=玻璃纤维接线器 tile.industrialwires.ic2Connector.glass_conn.name=玻璃纤维接线器
tile.industrialwires.ic2Connector.glass_relay.name=玻璃纤维继电器 tile.industrialwires.ic2Connector.glass_relay.name=玻璃纤维继电器
tile.mechanical_converter.ie_motor.name=旋转能马达 tile.industrialwires.mechanical_converter.ie_motor.name=旋转能马达
tile.mechanical_converter.ie_to_ic2.name=转换器IE旋转能-IC动能 tile.industrialwires.mechanical_converter.ie_to_ic2.name=转换器IE旋转能-IC动能
tile.mechanical_converter.ic2_to_ie.name=转换器IC动能-IE旋转能 tile.industrialwires.mechanical_converter.ic2_to_ie.name=转换器IC动能-IE旋转能
item.industrialwires.ic2wireCoil.tin.name=锡质线圈 item.industrialwires.ic2wireCoil.tin.name=锡质线圈