Last active
August 29, 2015 14:00
-
-
Save Zifiv/11235143 to your computer and use it in GitHub Desktop.
Problem for change an item in a custom gui on MinecraftForge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.inventory.container; | |
import com.beaucoralk.mcforge.labnetwork.inventory.InventoryPlan; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.InventoryPlayer; | |
import net.minecraft.inventory.Container; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.inventory.InventoryBasic; | |
import net.minecraft.inventory.Slot; | |
import net.minecraft.item.ItemArmor; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.item.crafting.CraftingManager; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
public class ContainerPlan extends Container { | |
private ItemStack planItem; | |
private final InventoryPlan planInventory; | |
public ContainerPlan(InventoryPlayer par1InventoryPlayer, ItemStack par2PlanItem) { | |
planItem = par2PlanItem; | |
int numberOfMaxLineSlots = (3*(par2PlanItem.getItemDamage() + 1)); | |
int numberOfMaxColumnSlots = (3*(par2PlanItem.getItemDamage() + 1)); | |
if (numberOfMaxLineSlots > 5) { | |
numberOfMaxLineSlots = 5; | |
} | |
planInventory = new InventoryPlan(numberOfMaxLineSlots * numberOfMaxColumnSlots); | |
if (par2PlanItem.hasTagCompound()) { | |
NBTTagCompound nbttagcompound = par2PlanItem.getTagCompound(); | |
NBTTagList planSlots = nbttagcompound.getTagList("planInventory", 10); | |
if (planSlots != null) { | |
for (int i = 0; i < planInventory.getSizeInventory(); i++) { | |
NBTTagCompound tag = planSlots.getCompoundTagAt(i); | |
byte slot = tag.getByte("Slot"); | |
if (slot >= 0 && slot < planInventory.getSizeInventory()) { | |
planInventory.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tag)); | |
} | |
} | |
} | |
} | |
for (int i = 0; i < 9; i++) { | |
addSlotToContainer(new Slot(par1InventoryPlayer, i, 20 + i * 18, 158 + 58)); | |
} | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < 9; j++) { | |
addSlotToContainer(new Slot(par1InventoryPlayer, j + (i + 1) * 9, 20 + j * 18, 158 + i * 18)); | |
} | |
} | |
for (int i = 0; i < numberOfMaxLineSlots; i++) { | |
for (int j = 0; j < numberOfMaxColumnSlots; j++) { | |
addSlotToContainer(new Slot(planInventory, j + i * numberOfMaxColumnSlots, 16 + j * 18 + (int)(((9.0F - numberOfMaxColumnSlots)/2.0F) * 18), 25 + i * 18)); | |
} | |
} | |
} | |
@Override | |
public boolean canInteractWith(EntityPlayer par1EntityPlayer) { | |
return true; | |
} | |
@Override | |
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { | |
ItemStack itemstack = null; | |
Slot slot = (Slot)this.inventorySlots.get(par2); | |
if (slot != null && slot.getHasStack()) { | |
ItemStack itemstack1 = slot.getStack(); | |
itemstack = itemstack1.copy(); | |
if (par2 >= 0 && par2 < 9) { | |
if (!this.mergeItemStack(itemstack1, 9, 35, false)) { | |
return null; | |
} | |
slot.onSlotChange(itemstack1, itemstack); | |
} else if (!this.mergeItemStack(itemstack1, 0, 8, false)) { | |
return null; | |
} | |
if (itemstack1.stackSize == 0) { | |
slot.putStack((ItemStack)null); | |
} else { | |
slot.onSlotChanged(); | |
} | |
if (itemstack1.stackSize == itemstack.stackSize) { | |
return null; | |
} | |
slot.onPickupFromSlot(par1EntityPlayer, itemstack1); | |
} | |
return itemstack; | |
} | |
public ItemStack saveContainerToPlanItem() { | |
NBTTagList itemlist = new NBTTagList(); | |
for (int i = 0; i < planInventory.getSizeInventory(); i++) { | |
ItemStack itemstack = planInventory.getStackInSlot(i); | |
if (itemstack != null) { | |
NBTTagCompound tag = new NBTTagCompound(); | |
tag.setByte("Slot", (byte)(i)); | |
itemstack.writeToNBT(tag); | |
itemlist.appendTag(tag); | |
} | |
} | |
NBTTagCompound nbttagPlanItem = new NBTTagCompound(); | |
nbttagPlanItem.setTag("planInventory", itemlist); | |
planItem.setTagCompound(nbttagPlanItem); | |
return planItem; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.services; | |
import com.beaucoralk.mcforge.labnetwork.client.gui.*; | |
import com.beaucoralk.mcforge.labnetwork.inventory.container.ContainerPlan; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.world.World; | |
import cpw.mods.fml.common.network.IGuiHandler; | |
public class GuiHandlerService implements IGuiHandler { | |
public static int guiLastID = -1; | |
public final static int guiScreenPlan = GuiHandlerService.getNextID(); | |
@Override | |
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | |
if (ID == guiScreenPlan) { | |
ItemStack currentItem = player.inventory.getCurrentItem(); | |
if (currentItem != null) { | |
if (currentItem.getItem() == ItemsService.plan) { | |
return new ContainerPlan(player.inventory, currentItem); | |
} | |
} | |
} | |
return null; | |
} | |
@Override | |
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { | |
if (ID == guiScreenPlan) { | |
ItemStack currentItem = player.inventory.getCurrentItem(); | |
if (currentItem != null) { | |
if (currentItem.getItem() == ItemsService.plan) { | |
return new GuiScreenPlan(player, currentItem, true); | |
} | |
} | |
} | |
return null; | |
} | |
public static int getNextID() { | |
return guiLastID++; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.client.gui; | |
import io.netty.buffer.ByteBuf; | |
import io.netty.buffer.Unpooled; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import org.lwjgl.input.Keyboard; | |
import org.lwjgl.opengl.GL11; | |
import org.lwjgl.opengl.GL12; | |
import com.beaucoralk.mcforge.labnetwork.LabNetworkMod; | |
import com.beaucoralk.mcforge.labnetwork.inventory.InventoryPlan; | |
import com.beaucoralk.mcforge.labnetwork.inventory.container.ContainerPlan; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.client.gui.GuiButton; | |
import net.minecraft.client.gui.GuiScreen; | |
import net.minecraft.client.gui.GuiScreenBook; | |
import net.minecraft.client.gui.inventory.GuiContainer; | |
import net.minecraft.client.renderer.OpenGlHelper; | |
import net.minecraft.client.renderer.RenderHelper; | |
import net.minecraft.client.resources.I18n; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.InventoryPlayer; | |
import net.minecraft.init.Items; | |
import net.minecraft.inventory.Container; | |
import net.minecraft.inventory.ContainerPlayer; | |
import net.minecraft.inventory.InventoryBasic; | |
import net.minecraft.inventory.Slot; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
import net.minecraft.nbt.NBTTagString; | |
import net.minecraft.network.PacketBuffer; | |
import net.minecraft.network.play.client.C17PacketCustomPayload; | |
import net.minecraft.util.EnumChatFormatting; | |
import net.minecraft.util.MathHelper; | |
import net.minecraft.util.ResourceLocation; | |
public class GuiScreenPlan extends GuiContainer { | |
private static final Logger logger = LogManager.getLogger(); | |
private static final ResourceLocation planGuiTextures = new ResourceLocation(LabNetworkMod.MOD_ID + ":textures/gui/gui_plan.png"); | |
private static ResourceLocation planPageGuiTextures; | |
/** The player editing the book */ | |
private final EntityPlayer editingPlayer; | |
private final ItemStack planObj; | |
/** Whether the book is signed or can still be edited */ | |
private final boolean planIsUnsigned; | |
private String planTitle = ""; | |
private GuiButton buttonDone; | |
private GuiButton buttonSignIt; | |
public GuiScreenPlan(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack, boolean par3) { | |
super(new ContainerPlan(par1EntityPlayer.inventory, par2ItemStack)); | |
editingPlayer = par1EntityPlayer; | |
planObj = par2ItemStack; | |
planIsUnsigned = par3; | |
planPageGuiTextures = new ResourceLocation(LabNetworkMod.MOD_ID + ":textures/gui/gui_plan_" + par2ItemStack.getItemDamage() + ".png"); | |
this.xSize = 201; | |
this.ySize = 240; | |
} | |
@Override | |
public void initGui() { | |
super.initGui(); | |
this.buttonList.clear(); | |
if (this.planIsUnsigned) { | |
this.buttonList.add(this.buttonSignIt = new GuiButton(1, ((this.width - xSize) / 2) + 7, ((this.height - ySize) / 2) + 123, 86, 20, "Sign it")); | |
this.buttonList.add(this.buttonDone = new GuiButton(0, ((this.width - xSize) / 2) + 106, ((this.height - ySize) / 2) + 123, 86, 20, "Done")); | |
} | |
} | |
@Override | |
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { | |
drawBackgroundPlanContainer(var1, var2, var3); | |
super.mc.getTextureManager().bindTexture(planGuiTextures); | |
int posX = (this.width - xSize) / 2; | |
int posY = (this.height - ySize) / 2; | |
drawTexturedModalRect(posX, posY, 0, 0, xSize, ySize); | |
} | |
protected void drawBackgroundPlanContainer(float var1, int var2, int var3) { | |
super.mc.getTextureManager().bindTexture(planPageGuiTextures); | |
int numberOfMaxLineSlots = (3*(planObj.getItemDamage() + 1)); | |
int numberOfMaxColumnSlots = (3*(planObj.getItemDamage() + 1)); | |
if (numberOfMaxLineSlots > 5) { | |
numberOfMaxLineSlots = 5; | |
} | |
int posX = ((this.width - xSize) / 2) + 10 + (int)(((9.0F - numberOfMaxColumnSlots)/2.0F) * 18); | |
int posY = ((this.height - ySize) / 2) + 20; | |
int posXMaxTex = numberOfMaxColumnSlots * 18 + 11; | |
int posYMaxTex = numberOfMaxLineSlots * 18 + 9; | |
if (posYMaxTex < 100) { | |
posYMaxTex = 100; | |
} | |
drawTexturedModalRect(posX, posY, 0, 0, posXMaxTex, posYMaxTex); | |
} | |
@Override | |
protected void actionPerformed(GuiButton p_146284_1_) { | |
if (p_146284_1_.enabled) { | |
if (p_146284_1_.id == 0) { | |
this.mc.displayGuiScreen((GuiScreen)null); | |
if (this.planIsUnsigned) { | |
LabNetworkMod.packetPipeline.sendToServer(new PacketSaveItemPlan()); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.inventory; | |
import java.util.ArrayList; | |
import java.util.List; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.IInvBasic; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.inventory.InventoryBasic; | |
import net.minecraft.item.ItemStack; | |
public class InventoryPlan implements IInventory { | |
private ItemStack itemPlan; | |
private int slotsPlanCount; | |
private ItemStack[] planContents; | |
private String inventoryTitle; | |
private int slotsCount; | |
private ItemStack[] inventoryContents; | |
private List field_70480_d; | |
private boolean field_94051_e; | |
public InventoryPlan(int size) { | |
this.inventoryTitle = ""; | |
this.field_94051_e = true; | |
this.slotsCount = size; | |
this.inventoryContents = new ItemStack[size]; | |
} | |
public void func_110134_a(IInvBasic par1IInvBasic) { | |
if (this.field_70480_d == null) { | |
this.field_70480_d = new ArrayList(); | |
} | |
this.field_70480_d.add(par1IInvBasic); | |
} | |
public void func_110132_b(IInvBasic par1IInvBasic) { | |
this.field_70480_d.remove(par1IInvBasic); | |
} | |
/** | |
* Returns the stack in slot i | |
*/ | |
public ItemStack getStackInSlot(int par1) { | |
return this.inventoryContents[par1]; | |
} | |
/** | |
* Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a | |
* new stack. | |
*/ | |
public ItemStack decrStackSize(int par1, int par2) { | |
if (this.inventoryContents[par1] != null) { | |
ItemStack itemstack; | |
if (this.inventoryContents[par1].stackSize <= par2) { | |
itemstack = this.inventoryContents[par1]; | |
this.inventoryContents[par1] = null; | |
this.markDirty(); | |
return itemstack; | |
} else { | |
itemstack = this.inventoryContents[par1].splitStack(par2); | |
if (this.inventoryContents[par1].stackSize == 0) { | |
this.inventoryContents[par1] = null; | |
} | |
this.markDirty(); | |
return itemstack; | |
} | |
} else { | |
return null; | |
} | |
} | |
/** | |
* When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - | |
* like when you close a workbench GUI. | |
*/ | |
public ItemStack getStackInSlotOnClosing(int par1) { | |
if (this.inventoryContents[par1] != null) { | |
ItemStack itemstack = this.inventoryContents[par1]; | |
this.inventoryContents[par1] = null; | |
return itemstack; | |
} else { | |
return null; | |
} | |
} | |
/** | |
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). | |
*/ | |
public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { | |
this.inventoryContents[par1] = par2ItemStack; | |
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) { | |
par2ItemStack.stackSize = this.getInventoryStackLimit(); | |
} | |
this.markDirty(); | |
} | |
/** | |
* Returns the number of slots in the inventory. | |
*/ | |
public int getSizeInventory() { | |
return this.slotsCount; | |
} | |
/** | |
* Returns the name of the inventory | |
*/ | |
public String getInventoryName() { | |
return this.inventoryTitle; | |
} | |
/** | |
* Returns if the inventory is named | |
*/ | |
public boolean hasCustomInventoryName() { | |
return this.field_94051_e; | |
} | |
public void func_110133_a(String par1Str) { | |
this.field_94051_e = true; | |
this.inventoryTitle = par1Str; | |
} | |
/** | |
* Returns the maximum stack size for a inventory slot. | |
*/ | |
public int getInventoryStackLimit() { | |
return 1; | |
} | |
/** | |
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it | |
* hasn't changed and skip it. | |
*/ | |
public void markDirty() { | |
} | |
/** | |
* Do not make give this method the name canInteractWith because it clashes with Container | |
*/ | |
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { | |
return true; | |
} | |
public void openInventory() {} | |
public void closeInventory() {} | |
/** | |
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. | |
*/ | |
public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) { | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.items; | |
import com.beaucoralk.mcforge.labnetwork.LabNetworkMod; | |
import com.beaucoralk.mcforge.labnetwork.services.GuiHandlerService; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.util.StringUtils; | |
import net.minecraft.world.World; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
public class LabItemPlan extends LabItem { | |
public LabItemPlan() { | |
this.setMaxStackSize(1); | |
} | |
@Override | |
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { | |
par3EntityPlayer.openGui(LabNetworkMod.instance, GuiHandlerService.guiScreenPlan, par2World, (int)par3EntityPlayer.posX, (int)par3EntityPlayer.posY, (int)par3EntityPlayer.posZ); | |
return par1ItemStack; | |
} | |
@Override | |
public String getItemStackDisplayName(ItemStack par1ItemStack) { | |
if (par1ItemStack.hasTagCompound()) { | |
NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound(); | |
String s = nbttagcompound.getString("title"); | |
if (!StringUtils.isNullOrEmpty(s)) { | |
return s; | |
} | |
} | |
return super.getItemStackDisplayName(par1ItemStack); | |
} | |
@Override | |
public boolean getShareTag() { | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
@Mod.EventHandler | |
public void preInit(FMLPreInitializationEvent event) { | |
packetPipeline.registerPacket(PacketSaveItemPlan.class); | |
} | |
@Mod.EventHandler | |
public void load(FMLInitializationEvent event) { | |
packetPipeline.initialise(); | |
} | |
@Mod.EventHandler | |
public void postInit(FMLPostInitializationEvent event) { | |
packetPipeline.postInitialise(); | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.services; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.EnumMap; | |
import java.util.LinkedList; | |
import java.util.List; | |
import com.beaucoralk.mcforge.labnetwork.LabNetworkMod; | |
import com.beaucoralk.mcforge.labnetwork.network.AbstractPacket; | |
import io.netty.buffer.ByteBuf; | |
import io.netty.buffer.Unpooled; | |
import io.netty.channel.ChannelHandler; | |
import io.netty.channel.ChannelHandlerContext; | |
import io.netty.handler.codec.MessageToMessageCodec; | |
import net.minecraft.client.Minecraft; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.EntityPlayerMP; | |
import net.minecraft.network.INetHandler; | |
import net.minecraft.network.NetHandlerPlayServer; | |
import cpw.mods.fml.common.FMLCommonHandler; | |
import cpw.mods.fml.common.network.FMLEmbeddedChannel; | |
import cpw.mods.fml.common.network.FMLOutboundHandler; | |
import cpw.mods.fml.common.network.NetworkRegistry; | |
import cpw.mods.fml.common.network.internal.FMLProxyPacket; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
@ChannelHandler.Sharable | |
public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, AbstractPacket> { | |
private EnumMap<Side, FMLEmbeddedChannel> channels; | |
private LinkedList<Class<? extends AbstractPacket>> packets = new LinkedList<Class<? extends AbstractPacket>>(); | |
private boolean isPostInitialised = false; | |
public boolean registerPacket(Class<? extends AbstractPacket> clazz) { | |
if (this.packets.size() > 256) { | |
return false; | |
} | |
if (this.packets.contains(clazz)) { | |
return false; | |
} | |
if (this.isPostInitialised) { | |
return false; | |
} | |
this.packets.add(clazz); | |
return true; | |
} | |
@Override | |
protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception { | |
ByteBuf buffer = Unpooled.buffer(); | |
Class<? extends AbstractPacket> clazz = msg.getClass(); | |
if (!this.packets.contains(msg.getClass())) { | |
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName()); | |
} | |
byte discriminator = (byte) this.packets.indexOf(clazz); | |
buffer.writeByte(discriminator); | |
msg.encodeInto(ctx, buffer); | |
FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get()); | |
out.add(proxyPacket); | |
} | |
@Override | |
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { | |
ByteBuf payload = msg.payload(); | |
byte discriminator = payload.readByte(); | |
Class<? extends AbstractPacket> clazz = this.packets.get(discriminator); | |
if (clazz == null) { | |
throw new NullPointerException("No packet registered for discriminator: " + discriminator); | |
} | |
AbstractPacket pkt = clazz.newInstance(); | |
pkt.decodeInto(ctx, payload.slice()); | |
EntityPlayer player; | |
switch (FMLCommonHandler.instance().getEffectiveSide()) { | |
case CLIENT: | |
player = this.getClientPlayer(); | |
pkt.handleClientSide(player); | |
break; | |
case SERVER: | |
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); | |
player = ((NetHandlerPlayServer) netHandler).playerEntity; | |
pkt.handleServerSide(player); | |
break; | |
default: | |
} | |
out.add(pkt); | |
} | |
public void initialise() { | |
this.channels = NetworkRegistry.INSTANCE.newChannel(LabNetworkMod.MOD_ID, this); | |
} | |
public void postInitialise() { | |
if (this.isPostInitialised) { | |
return; | |
} | |
this.isPostInitialised = true; | |
Collections.sort(this.packets, new Comparator<Class<? extends AbstractPacket>>() { | |
@Override | |
public int compare(Class<? extends AbstractPacket> clazz1, Class<? extends AbstractPacket> clazz2) { | |
int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName()); | |
if (com == 0) { | |
com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName()); | |
} | |
return com; | |
} | |
}); | |
} | |
@SideOnly(Side.CLIENT) | |
private EntityPlayer getClientPlayer() { | |
return Minecraft.getMinecraft().thePlayer; | |
} | |
public void sendToAll(AbstractPacket message) { | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); | |
this.channels.get(Side.SERVER).writeAndFlush(message); | |
} | |
public void sendTo(AbstractPacket message, EntityPlayerMP player) { | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); | |
this.channels.get(Side.SERVER).writeAndFlush(message); | |
} | |
public void sendToAllAround(AbstractPacket message, NetworkRegistry.TargetPoint point) { | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point); | |
this.channels.get(Side.SERVER).writeAndFlush(message); | |
} | |
public void sendToDimension(AbstractPacket message, int dimensionId) { | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION); | |
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId); | |
this.channels.get(Side.SERVER).writeAndFlush(message); | |
} | |
public void sendToServer(AbstractPacket message) { | |
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); | |
this.channels.get(Side.CLIENT).writeAndFlush(message); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.beaucoralk.mcforge.labnetwork.network.packets; | |
import io.netty.buffer.ByteBuf; | |
import io.netty.channel.ChannelHandlerContext; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.item.ItemStack; | |
import com.beaucoralk.mcforge.labnetwork.LabNetworkMod; | |
import com.beaucoralk.mcforge.labnetwork.network.AbstractPacket; | |
import cpw.mods.fml.common.network.ByteBufUtils; | |
public class PacketSaveItemPlan extends AbstractPacket { | |
public PacketSaveItemPlan() { | |
} | |
@Override | |
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { | |
} | |
@Override | |
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { | |
} | |
@Override | |
public void handleClientSide(EntityPlayer player) { | |
} | |
@Override | |
public void handleServerSide(EntityPlayer player) { | |
if (player.openContainer.getClass() == ContainerPlan.class) { | |
player.inventory.setInventorySlotContents(player.inventory.currentItem, ((ContainerPlan)player.openContainer).saveContainerToPlanItem()); | |
player.inventory.inventoryChanged = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment