use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.
the class MFRUtil method directionsWithoutConveyors.
public static ForgeDirection[] directionsWithoutConveyors(World world, int x, int y, int z) {
ArrayList<ForgeDirection> nonConveyors = new ArrayList<ForgeDirection>();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
BlockPosition bp = new BlockPosition(x, y, z);
bp.orientation = direction;
bp.moveForwards(1);
TileEntity te = world.getBlockTileEntity(bp.x, bp.y, bp.z);
if (te == null || !(te instanceof TileEntityConveyor)) {
nonConveyors.add(direction);
}
}
return nonConveyors.toArray(new ForgeDirection[nonConveyors.size()]);
}
use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.
the class BlockConveyor method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if (entity instanceof EntityPlayer && MFRConfig.conveyorNeverCapturesPlayers.getBoolean(false)) {
return;
}
// TODO: add conveyer entity blacklist: these two cases will be covered conditionally elsewhere
if (entity.getClass().getName().contains("thaumcraft.common.entities.golems") && MFRConfig.conveyorNeverCapturesTCGolems.getBoolean(false)) {
return;
}
if (!(entity instanceof EntityItem || entity instanceof EntityXPOrb || (entity instanceof EntityLiving && MFRConfig.conveyorCaptureNonItems.getBoolean(true)))) {
return;
}
TileEntity conveyor = world.getBlockTileEntity(x, y, z);
if (!(conveyor instanceof TileEntityConveyor && ((TileEntityConveyor) conveyor).getConveyorActive())) {
return;
}
if (!world.isRemote && entity instanceof EntityItem) {
specialRoute(world, x, y, z, (EntityItem) entity);
}
double xVelocity = 0;
double yVelocity = 0;
double zVelocity = 0;
int md = world.getBlockMetadata(x, y, z);
int horizDirection = md & 0x03;
boolean isUphill = (md & 0x04) != 0;
boolean isDownhill = (md & 0x08) != 0;
if (isUphill) {
yVelocity = 0.25D;
}
if (isUphill || isDownhill) {
entity.onGround = false;
}
if (horizDirection == 0) {
xVelocity = 0.1D;
} else if (horizDirection == 1) {
zVelocity = 0.1D;
} else if (horizDirection == 2) {
xVelocity = -0.1D;
} else if (horizDirection == 3) {
zVelocity = -0.1D;
}
if (horizDirection == 0 || horizDirection == 2) {
if (entity.posZ > z + 0.55D) {
zVelocity = -0.1D;
} else if (entity.posZ < z + 0.45D) {
zVelocity = 0.1D;
}
} else if (horizDirection == 1 || horizDirection == 3) {
if (entity.posX > x + 0.55D) {
xVelocity = -0.1D;
} else if (entity.posX < x + 0.45D) {
xVelocity = 0.1D;
}
}
setEntityVelocity(entity, xVelocity, yVelocity, zVelocity);
if (entity instanceof EntityLiving) {
((EntityLiving) entity).fallDistance = 0;
} else if (entity instanceof EntityItem) {
((EntityItem) entity).delayBeforeCanPickup = 40;
}
}
use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.
the class BlockConveyor method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity, ItemStack stack) {
if (entity == null) {
return;
}
int facing = MathHelper.floor_double((entity.rotationYaw * 4F) / 360F + 0.5D) & 3;
if (facing == 0) {
world.setBlockMetadataWithNotify(x, y, z, 1, 2);
}
if (facing == 1) {
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (facing == 2) {
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (facing == 3) {
world.setBlockMetadataWithNotify(x, y, z, 0, 2);
}
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityConveyor) {
((TileEntityConveyor) te).setDyeColor(stack.getItemDamage() == 16 ? -1 : stack.getItemDamage());
}
}
use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.
the class ClientPacketHandler method onPacketData.
@SuppressWarnings("rawtypes")
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
int packetType = PacketWrapper.readPacketID(data);
if (// server -> client; server propagating machine rotation; args X Y Z rotation isActive
packetType == Packets.TileDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityFactory) {
TileEntityFactory tef = (TileEntityFactory) te;
tef.rotateDirectlyTo((Integer) packetReadout[3]);
tef.setIsActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server propagating conveyor color, activity state
packetType == Packets.ConveyorDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Boolean.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityConveyor) {
TileEntityConveyor tec = (TileEntityConveyor) te;
tec.setDyeColor((Integer) packetReadout[3]);
tec.setConveyorActive((Boolean) packetReadout[4]);
}
} else if (// server -> client; server playing a record
packetType == Packets.AutoJukeboxPlay) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityAutoJukebox) {
Minecraft.getMinecraft().ingameGUI.setRecordPlayingMessage(((ItemRecord) Item.itemsList[(Integer) packetReadout[3]]).recordName);
}
} else if (// server -> client; road block light changed
packetType == Packets.RoadBlockUpdate) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
((EntityPlayer) player).worldObj.setBlock((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2], MineFactoryReloadedCore.factoryRoadBlock.blockID, (Integer) packetReadout[3], 6);
((EntityPlayer) player).worldObj.markBlockForRenderUpdate((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
} else if (// server -> client; cable side colors
packetType == Packets.CableDescription) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Byte.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetCable) {
TileEntityRedNetCable tec = (TileEntityRedNetCable) te;
tec.setSideColor(ForgeDirection.DOWN, (Integer) packetReadout[3]);
tec.setSideColor(ForgeDirection.UP, (Integer) packetReadout[4]);
tec.setSideColor(ForgeDirection.NORTH, (Integer) packetReadout[5]);
tec.setSideColor(ForgeDirection.SOUTH, (Integer) packetReadout[6]);
tec.setSideColor(ForgeDirection.WEST, (Integer) packetReadout[7]);
tec.setSideColor(ForgeDirection.EAST, (Integer) packetReadout[8]);
tec.setMode((Byte) packetReadout[9]);
}
} else if (// server -> client: logic circuit (class and pins)
packetType == Packets.LogicCircuitDefinition) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetLogic) {
((TileEntityRedNetLogic) te).setCircuitFromPacket(data);
}
} else if (packetType == Packets.HistorianValueChanged) {
Class[] decodeAs = { Integer.class, Integer.class, Integer.class, Integer.class };
Object[] packetReadout = PacketWrapper.readPacketData(data, decodeAs);
TileEntity te = ((EntityPlayer) player).worldObj.getBlockTileEntity((Integer) packetReadout[0], (Integer) packetReadout[1], (Integer) packetReadout[2]);
if (te instanceof TileEntityRedNetHistorian) {
((TileEntityRedNetHistorian) te).setClientValue((Integer) packetReadout[3]);
}
}
}
use of powercrystals.minefactoryreloaded.tile.conveyor.TileEntityConveyor in project MineFactoryReloaded by powercrystals.
the class BlockConveyor method breakBlock.
@Override
public void breakBlock(World world, int x, int y, int z, int blockId, int meta) {
TileEntity te = world.getBlockTileEntity(x, y, z);
int dyeColor = 16;
if (te instanceof TileEntityConveyor) {
dyeColor = ((TileEntityConveyor) te).getDyeColor();
if (dyeColor == -1)
dyeColor = 16;
}
dropBlockAsItem_do(world, x, y, z, new ItemStack(blockID, 1, dyeColor));
super.breakBlock(world, x, y, z, blockId, meta);
}
Aggregations