use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project SilentGems by SilentChaos512.
the class MessageToggleChaosGem method handleMessage.
@Override
public IMessage handleMessage(MessageContext context) {
if (context.side != Side.SERVER)
return null;
EntityPlayer player = context.getServerHandler().player;
Predicate<ItemStack> predicate = s -> s.getItem() instanceof ItemChaosGem;
ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
for (ItemStack stack : stacks) {
if (stack.getItem() instanceof ItemChaosGem) {
ItemChaosGem item = (ItemChaosGem) stack.getItem();
item.setEnabled(stack, !item.isEnabled(stack));
if (item.isEnabled(stack))
item.applyEffects(stack, player);
else
item.removeEffects(stack, player);
if (!all)
return null;
}
}
return null;
}
use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project BuildCraft by BuildCraft.
the class TileFiller method readPayload.
@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
super.readPayload(id, buffer, side, ctx);
if (side == Side.CLIENT) {
if (id == NET_RENDER_DATA) {
builder.readFromByteBuf(buffer);
readPayload(NET_BOX, buffer, side, ctx);
} else if (id == NET_GUI_DATA || id == NET_GUI_TICK) {
readPayload(NET_CAN_EXCAVATE, buffer, side, ctx);
readPayload(NET_INVERT, buffer, side, ctx);
readPayload(NET_PATTERN, buffer, side, ctx);
builder.readFromByteBuf(buffer);
finished = buffer.readBoolean();
lockedTicks = buffer.readBoolean() ? (byte) 1 : (byte) 0;
mode = buffer.readEnumValue(Mode.class);
} else if (id == NET_BOX) {
box.readData(buffer);
markerBox = buffer.readBoolean();
if (buffer.readBoolean()) {
UUID volumeBoxId = buffer.readUniqueId();
VolumeBox volumeBox = world.isRemote ? ClientVolumeBoxes.INSTANCE.volumeBoxes.stream().filter(localVolumeBox -> localVolumeBox.id.equals(volumeBoxId)).findFirst().orElseThrow(NullPointerException::new) : WorldSavedDataVolumeBoxes.get(world).getVolumeBoxFromId(volumeBoxId);
addon = (AddonFillerPlanner) volumeBox.addons.get(buffer.readEnumValue(EnumAddonSlot.class));
}
} else if (id == NET_CAN_EXCAVATE) {
canExcavate = buffer.readBoolean();
} else if (id == NET_INVERT) {
inverted = buffer.readBoolean();
} else if (id == NET_PATTERN) {
patternStatement.readFromBuffer(buffer);
}
}
if (side == Side.SERVER) {
if (id == NET_CAN_EXCAVATE) {
canExcavate = buffer.readBoolean();
sendNetworkGuiUpdate(NET_CAN_EXCAVATE);
}
}
}
use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project RebornCore by TechReborn.
the class PacketSlotSync method processData.
@Override
public void processData(PacketSlotSync message, MessageContext context) {
if (!RebornCore.proxy.getClientWorld().isBlockLoaded(pos, false)) {
return;
}
TileLegacyMachineBase machineBase = (TileLegacyMachineBase) RebornCore.proxy.getClientWorld().getTileEntity(pos);
if (machineBase == null || machineBase.slotConfiguration == null || slotConfig == null || slotConfig.getSlotDetails() == null) {
RebornCore.logHelper.error("Failed to sync slot data to " + pos);
}
Minecraft.getMinecraft().addScheduledTask(() -> slotConfig.getSlotDetails().forEach(slotConfigHolder -> machineBase.slotConfiguration.updateSlotDetails(slotConfigHolder)));
}
use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project AgriCraft by AgriCraft.
the class MessageTileEntitySeedStorage method processMessage.
@Override
protected void processMessage(MessageContext ctx) {
TileEntity te = FMLClientHandler.instance().getClient().world.getTileEntity(this.pos);
if (te instanceof TileEntitySeedStorage) {
TileEntitySeedStorage storage = (TileEntitySeedStorage) te;
ItemStack stack = storage.getLockedSeed().map(s -> s.toStack()).orElse(null);
if (stack != null) {
stack.setCount(this.amount);
NBTTagCompound tag = new NBTTagCompound();
stats.writeToNBT(tag);
stack.setTagCompound(tag);
storage.setSlotContents(this.slotId, stack);
}
}
}
use of net.minecraftforge.fml.common.network.simpleimpl.MessageContext in project SilentGems by SilentChaos512.
the class MessageKeyReturnHome method handleMessage.
@Override
public IMessage handleMessage(MessageContext ctx) {
if (ctx.side != Side.SERVER)
return null;
Predicate<ItemStack> predicate = s -> s.getItem() == ModItems.returnHomeCharm;
EntityPlayer player = ctx.getServerHandler().player;
ItemStackList stacks = BaublesCompat.getBaubles(player, predicate);
stacks.addAll(PlayerHelper.getNonEmptyStacks(player, predicate));
if (stacks.isEmpty())
return null;
ModItems.returnHomeCharm.tryTeleportPlayer(stacks.get(0), player);
return null;
}
Aggregations