use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class TileEntityController method removeConnector.
private void removeConnector(int channel, SidedPos pos) {
WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
SidedConsumer toremove = null;
for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
SidedConsumer key = entry.getKey();
if (key.getSide().getOpposite().equals(pos.getSide())) {
if (key.getConsumerId().equals(consumerId)) {
toremove = key;
break;
}
}
}
if (toremove != null) {
channels[channel].getConnectors().remove(toremove);
networkDirty();
markDirtyQuick();
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ItemChannelSettings method tick.
@Override
public void tick(int channel, IControllerContext context) {
delay--;
if (delay <= 0) {
// Multiply of the different speeds we have
delay = 200 * 6;
}
if (delay % 5 != 0) {
return;
}
int d = delay / 5;
updateCache(channel, context);
World world = context.getControllerWorld();
for (Map.Entry<SidedConsumer, ItemConnectorSettings> entry : itemExtractors.entrySet()) {
ItemConnectorSettings settings = entry.getValue();
if (d % settings.getSpeed() != 0) {
continue;
}
ConsumerId consumerId = entry.getKey().getConsumerId();
BlockPos extractorPos = context.findConsumerPosition(consumerId);
if (extractorPos != null) {
EnumFacing side = entry.getKey().getSide();
BlockPos pos = extractorPos.offset(side);
if (!WorldTools.chunkLoaded(world, pos)) {
continue;
}
if (checkRedstone(world, settings, extractorPos)) {
return;
}
if (!context.matchColor(settings.getColorsMask())) {
return;
}
TileEntity te = world.getTileEntity(pos);
if (XNet.rftools && RFToolsSupport.isStorageScanner(te)) {
RFToolsSupport.tickStorageScanner(context, settings, te, this);
} else {
IItemHandler handler = getItemHandlerAt(te, settings.getFacing());
if (handler != null) {
int idx = getStartExtractIndex(settings, consumerId, handler);
idx = tickItemHandler(context, settings, handler, idx);
if (handler.getSlots() > 0) {
rememberExtractIndex(consumerId, (idx + 1) % handler.getSlots());
}
}
}
}
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ItemChannelSettings method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound tag) {
channelMode = ChannelMode.values()[tag.getByte("mode")];
delay = tag.getInteger("delay");
roundRobinOffset = tag.getInteger("offset");
int[] cons = tag.getIntArray("extidx");
for (int idx = 0; idx < cons.length; idx += 2) {
extractIndeces.put(new ConsumerId(cons[idx]), cons[idx + 1]);
}
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ConnectorBlock method getDrops.
@Override
public List<ItemStack> getDrops(IBlockAccess blockAccess, BlockPos pos, IBlockState state, int fortune) {
List<ItemStack> drops = super.getDrops(blockAccess, pos, state, fortune);
if (blockAccess instanceof World) {
World world = (World) blockAccess;
for (ItemStack drop : drops) {
if (!drop.hasTagCompound()) {
drop.setTagCompound(new NBTTagCompound());
}
WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
ConsumerId consumer = worldBlob.getConsumerAt(pos);
if (consumer != null) {
drop.getTagCompound().setInteger("consumerId", consumer.getId());
}
}
}
return drops;
}
use of mcjty.xnet.api.keys.ConsumerId in project XNet by McJty.
the class ConnectorUpgradeItem method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == NetCableSetup.connectorBlock) {
if (!world.isRemote) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof ConnectorTileEntity) {
NBTTagCompound tag = new NBTTagCompound();
te.writeToNBT(tag);
CableColor color = world.getBlockState(pos).getValue(GenericCableBlock.COLOR);
XNetBlobData blobData = XNetBlobData.getBlobData(world);
WorldBlob worldBlob = blobData.getWorldBlob(world);
ConsumerId consumer = worldBlob.getConsumerAt(pos);
((ConnectorBlock) block).unlinkBlock(world, pos);
world.setBlockState(pos, NetCableSetup.advancedConnectorBlock.getDefaultState().withProperty(GenericCableBlock.COLOR, color));
IBlockState blockState = world.getBlockState(pos);
((ConnectorBlock) blockState.getBlock()).createCableSegment(world, pos, consumer);
te = TileEntity.create(world, tag);
if (te != null) {
world.getChunkFromBlockCoords(pos).addTileEntity(te);
te.markDirty();
world.notifyBlockUpdate(pos, blockState, blockState, 3);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
player.openContainer.detectAndSendChanges();
player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Connector was upgraded"), false);
} else {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Something went wrong during upgrade!"), false);
return EnumActionResult.FAIL;
}
}
}
return EnumActionResult.SUCCESS;
} else if (block == NetCableSetup.advancedConnectorBlock) {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "This connector is already advanced!"), false);
}
return EnumActionResult.SUCCESS;
} else {
if (!world.isRemote) {
player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Use this item on a connector to upgrade it!"), false);
}
return EnumActionResult.SUCCESS;
}
}
Aggregations