use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.
the class BlockMetalDecoration1 method canConnectFenceTo.
// @Override
// public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos)
// {
// // TileEntity tileEntity = world.getTileEntity(x, y, z);
// IBlockState state = world.getBlockState(pos);
// if(this.getMetaFromState(state)==BlockTypes_MetalDecoration1.STEEL_FENCE.getMeta() || this.getMetaFromState(state)==BlockTypes_MetalDecoration1.ALUMINUM_FENCE.getMeta())
// this.setBlockBounds(canConnectFenceTo(world,pos.add(-1,0,0))?0:.375f,0,canConnectFenceTo(world,pos.add(0,0,-1))?0:.375f, canConnectFenceTo(world,pos.add(1,0,0))?1:.625f,1,canConnectFenceTo(world,pos.add(0,0,1))?1:.625f);
// // else if(tileEntity instanceof TileEntityLantern)
// // {
// // int f = ((TileEntityLantern)tileEntity).facing ;
// // if(f<2)
// // this.setBlockBounds(.25f,f==1?0:.125f,.25f, .75f,f==1?.875f:1f,.75f);
// // else
// // this.setBlockBounds(f==5?0:.25f,0,f==3?0:.25f, f==4?1:.75f,.875f,f==2?1:.75f);
// // }
// // else if(tileEntity instanceof TileEntityConnectorStructural)
// // {
// // float length = .5f;
// // switch(((TileEntityConnectorStructural)tileEntity).facing )
// // {
// // case 0://UP
// // this.setBlockBounds(.25f,0,.25f, .75f,length,.75f);
// // break;
// // case 1://DOWN
// // this.setBlockBounds(.25f,1-length,.25f, .75f,1,.75f);
// // break;
// // case 2://SOUTH
// // this.setBlockBounds(.25f,.25f,0, .75f,.75f,length);
// // break;
// // case 3://NORTH
// // this.setBlockBounds(.25f,.25f,1-length, .75f,.75f,1);
// // break;
// // case 4://EAST
// // this.setBlockBounds(0,.25f,.25f, length,.75f,.75f);
// // break;
// // case 5://WEST
// // this.setBlockBounds(1-length,.25f,.25f, 1,.75f,.75f);
// // break;
// // }
// // }
// // else if(tileEntity instanceof TileEntityWallmount)
// // {
// // TileEntityWallmount arm = (TileEntityWallmount)tileEntity;
// // int f = arm.facing;
// // if(arm.sideAttached>0)
// // this.setBlockBounds(f==4?0:f==5?.375f:.3125f,arm.inverted?.3125f:0,f==2?0:f==3?.375f:.3125f, f==5?1:f==4?.625f:.6875f,arm.inverted?1:.6875f,f==3?1:f==2?.625f:.6875f);
// // else
// // this.setBlockBounds(f==5?0:.3125f,arm.inverted?.375f:0,f==3?0:.3125f, f==4?1:.6875f,arm.inverted?1:.625f,f==2?1:.6875f);
// // }
// else
// this.setBlockBounds(0,0,0,1,1,1);
// }
public boolean canConnectFenceTo(IBlockAccess world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
return block != Blocks.BARRIER && (!((!(block instanceof BlockFence || block.equals(this)) || state.getMaterial() != this.blockMaterial) && !(block instanceof BlockFenceGate)) || ((state.getMaterial().isOpaque() && state.isFullCube()) && state.getMaterial() != Material.GOURD));
}
use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.
the class BlockConnector method onBlockPlaced.
@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
IBlockState ret = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
if (meta == BlockTypes_Connector.TRANSFORMER.getMeta()) {
BlockPos pos2 = pos.offset(facing, -1);
IBlockState placedAgainst = world.getBlockState(pos2);
Block block = placedAgainst.getBlock();
if (block instanceof IPostBlock && ((IPostBlock) block).canConnectTransformer(world, pos2))
ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof IPostBlock && ((IPostBlock) tile).canConnectTransformer(world, pos2))
ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
}
return ret;
}
use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.
the class ItemWireCoil method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (!world.isRemote) {
TileEntity tileEntity = world.getTileEntity(pos);
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);
tileEntity = world.getTileEntity(masterPos);
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() });
NBTTagCompound targetNbt = new NBTTagCompound();
target.writeToNBT(targetNbt);
ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
} else {
WireType type = getWireType(stack);
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
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())
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
else if (linkPos.equals(masterPos))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
else {
TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
else {
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)))
connectionExists = true;
}
if (connectionExists)
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
else {
Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
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) {
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
nodeHere.connectCable(type, target, nodeLink);
nodeLink.connectCable(type, targetLink, nodeHere);
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if (!player.capabilities.isCreativeMode)
stack.stackSize--;
((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.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else
player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
}
}
}
ItemNBTHelper.remove(stack, "linkingPos");
ItemNBTHelper.remove(stack, "targettingInfo");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.
the class Utils method ray.
private static void ray(double dif, Vec3d mov, Vec3d start, double lengthAdd, HashSet<BlockPos> ret, World world, HashSet<BlockPos> checked, Block tmp) {
//Do NOT set this to true unless for debugging. Causes blocks to be placed along the traced ray
boolean place = false;
double standartOff = .0625;
for (int i = 0; i < dif; i++) {
Vec3d pos = addVectors(start, scalarProd(mov, i + lengthAdd + standartOff));
Vec3d posNext = addVectors(start, scalarProd(mov, i + 1 + lengthAdd + standartOff));
Vec3d posPrev = addVectors(start, scalarProd(mov, i + lengthAdd - standartOff));
Vec3d posVeryPrev = addVectors(start, scalarProd(mov, i - 1 + lengthAdd - standartOff));
BlockPos blockPos = new BlockPos((int) Math.floor(pos.xCoord), (int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord));
Block b;
IBlockState state;
if (!checked.contains(blockPos) && i + lengthAdd + standartOff < dif) {
state = world.getBlockState(blockPos);
b = state.getBlock();
if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, pos, posNext) != null)
ret.add(blockPos);
// if (place)
// world.setBlockState(blockPos, tmp);
checked.add(blockPos);
}
blockPos = new BlockPos((int) Math.floor(posPrev.xCoord), (int) Math.floor(posPrev.yCoord), (int) Math.floor(posPrev.zCoord));
if (!checked.contains(blockPos) && i + lengthAdd - standartOff < dif) {
state = world.getBlockState(blockPos);
b = state.getBlock();
if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, posVeryPrev, posPrev) != null)
ret.add(blockPos);
// if (place)
// world.setBlock(blockPos.posX, blockPos.posY, blockPos.posZ, tmp);
checked.add(blockPos);
}
}
}
use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.
the class ItemToolbox method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (!block.isReplaceable(world, pos))
pos = pos.offset(side);
if (stack.stackSize != 0 && player.canPlayerEdit(pos, side, stack) && world.canBlockBePlaced(IEContent.blockMetalDecoration2, pos, false, side, null, stack)) {
IBlockState toolbox = IEContent.blockMetalDecoration2.getStateFromMeta(BlockTypes_MetalDecoration2.TOOLBOX.getMeta());
if (world.setBlockState(pos, toolbox, 3)) {
IEContent.blockMetalDecoration2.onIEBlockPlacedBy(world, pos, toolbox, side, hitX, hitY, hitZ, player, stack);
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
--stack.stackSize;
}
return EnumActionResult.SUCCESS;
} else
return EnumActionResult.FAIL;
}
return super.onItemUse(stack, player, world, pos, hand, side, hitX, hitY, hitZ);
}
Aggregations