mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
167 lines
4.9 KiB
Java
167 lines
4.9 KiB
Java
package com.hbm.packet;
|
|
|
|
import com.hbm.items.ModItems;
|
|
import com.hbm.items.machine.ItemAssemblyTemplate;
|
|
import com.hbm.items.machine.ItemCassette;
|
|
import com.hbm.items.machine.ItemChemistryTemplate;
|
|
import com.hbm.items.machine.ItemFluidIdentifier;
|
|
import com.hbm.util.InventoryUtil;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Items;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
public class ItemFolderPacket implements IMessage {
|
|
|
|
int item;
|
|
int meta;
|
|
|
|
public ItemFolderPacket()
|
|
{
|
|
|
|
}
|
|
|
|
public ItemFolderPacket(ItemStack stack)
|
|
{
|
|
this.item = Item.getIdFromItem(stack.getItem());
|
|
this.meta = stack.getItemDamage();
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf buf) {
|
|
item = buf.readInt();
|
|
meta = buf.readInt();
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf buf) {
|
|
buf.writeInt(item);
|
|
buf.writeInt(meta);
|
|
}
|
|
|
|
public static class Handler implements IMessageHandler<ItemFolderPacket, IMessage> {
|
|
|
|
/*
|
|
* While it is still horrible, it is arguably less horrible than it was before.
|
|
*/
|
|
@Override
|
|
public IMessage onMessage(ItemFolderPacket m, MessageContext ctx) {
|
|
|
|
//if(!Minecraft.getMinecraft().theWorld.isRemote)
|
|
EntityPlayer p = ctx.getServerHandler().playerEntity;
|
|
ItemStack stack = new ItemStack(Item.getItemById(m.item), 1, m.meta);
|
|
|
|
if(p.capabilities.isCreativeMode) {
|
|
p.inventory.addItemStackToInventory(stack.copy());
|
|
return null;
|
|
}
|
|
|
|
if(stack.getItem() instanceof ItemFluidIdentifier) {
|
|
tryMakeItem(p, stack, "plateIron", "dye");
|
|
return null;
|
|
}
|
|
if(stack.getItem() instanceof ItemAssemblyTemplate) {
|
|
tryMakeItem(p, stack, Items.paper, "dye");
|
|
return null;
|
|
}
|
|
if(stack.getItem() instanceof ItemChemistryTemplate) {
|
|
tryMakeItem(p, stack, Items.paper, "dye");
|
|
return null;
|
|
}
|
|
if(stack.getItem() instanceof ItemCassette) {
|
|
tryMakeItem(p, stack, ModItems.plate_polymer, "plateSteel");
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_stone_plate ||
|
|
stack.getItem() == ModItems.stamp_stone_wire ||
|
|
stack.getItem() == ModItems.stamp_stone_circuit) {
|
|
tryConvert(p, ModItems.stamp_stone_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_iron_plate ||
|
|
stack.getItem() == ModItems.stamp_iron_wire ||
|
|
stack.getItem() == ModItems.stamp_iron_circuit) {
|
|
tryConvert(p, ModItems.stamp_iron_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_steel_plate ||
|
|
stack.getItem() == ModItems.stamp_steel_wire ||
|
|
stack.getItem() == ModItems.stamp_steel_circuit) {
|
|
tryConvert(p, ModItems.stamp_steel_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_titanium_plate ||
|
|
stack.getItem() == ModItems.stamp_titanium_wire ||
|
|
stack.getItem() == ModItems.stamp_titanium_circuit) {
|
|
tryConvert(p, ModItems.stamp_titanium_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_obsidian_plate ||
|
|
stack.getItem() == ModItems.stamp_obsidian_wire ||
|
|
stack.getItem() == ModItems.stamp_obsidian_circuit) {
|
|
tryConvert(p, ModItems.stamp_obsidian_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
if(stack.getItem() == ModItems.stamp_schrabidium_plate ||
|
|
stack.getItem() == ModItems.stamp_schrabidium_wire ||
|
|
stack.getItem() == ModItems.stamp_schrabidium_circuit) {
|
|
tryConvert(p, ModItems.stamp_schrabidium_flat, stack.getItem());
|
|
return null;
|
|
}
|
|
//}
|
|
|
|
return null;
|
|
}
|
|
|
|
private void tryMakeItem(EntityPlayer player, ItemStack output, Object... ingredients) {
|
|
|
|
//check
|
|
for(Object o : ingredients) {
|
|
|
|
if(o instanceof Item) {
|
|
if(!player.inventory.hasItem((Item)o))
|
|
return;
|
|
}
|
|
|
|
if(o instanceof String) {
|
|
if(!InventoryUtil.hasOreDictMatches(player, (String)o, 1))
|
|
return;
|
|
}
|
|
}
|
|
|
|
//consume
|
|
for(Object o : ingredients) {
|
|
|
|
if(o instanceof Item) {
|
|
player.inventory.consumeInventoryItem((Item)o);
|
|
}
|
|
|
|
if(o instanceof String) {
|
|
InventoryUtil.consumeOreDictMatches(player, (String)o, 1);
|
|
}
|
|
}
|
|
|
|
if(!player.inventory.addItemStackToInventory(output))
|
|
player.dropPlayerItemWithRandomChoice(output, true);
|
|
}
|
|
|
|
private void tryConvert(EntityPlayer player, Item target, Item result) {
|
|
|
|
for(int i = 0; i < player.inventory.mainInventory.length; i++) {
|
|
|
|
ItemStack stack = player.inventory.mainInventory[i];
|
|
|
|
if(stack != null && stack.getItem() == target) {
|
|
player.inventory.mainInventory[i] = new ItemStack(result, stack.stackSize, stack.getItemDamage());
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|