mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-20 03:59:56 +00:00
finished functionality packager
This commit is contained in:
1 parent
3d494de9bc
commit
6c5032f5d6
8 files changed
+237
-28
No files matched your search
@@ -5,6 +5,7 @@ import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
|
||||
import makeo.gadomancy.common.containers.ContainerArcanePackager;
|
||||
import makeo.gadomancy.common.utils.ColorHelper;
|
||||
import makeo.gadomancy.common.utils.SimpleResourceLocation;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -26,11 +27,13 @@ public class ArcanePackagerGui extends GuiContainer {
|
||||
private static final ResourceLocation TEXTURE = new SimpleResourceLocation("gui/gui_packager.png");
|
||||
|
||||
private final TileArcanePackager tile;
|
||||
private final InventoryPlayer playerInv;
|
||||
|
||||
public ArcanePackagerGui(InventoryPlayer playerInv, IInventory inventory) {
|
||||
super(new ContainerArcanePackager(playerInv, inventory));
|
||||
|
||||
this.tile = (TileArcanePackager) inventory;
|
||||
this.playerInv = playerInv;
|
||||
|
||||
this.ySize = 234;
|
||||
this.xSize = 190;
|
||||
@@ -38,10 +41,17 @@ public class ArcanePackagerGui extends GuiContainer {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
if(tile.isInvalid()) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(null);
|
||||
return;
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
this.mc.renderEngine.bindTexture(TEXTURE);
|
||||
|
||||
drawTexturedModalRect(89, 67, 210, 0, tile.progress, 9);
|
||||
if(tile.progress > 0) {
|
||||
drawTexturedModalRect(89, 67, 210, 0, tile.progress, 9);
|
||||
}
|
||||
|
||||
if(tile.useEssentia) {
|
||||
drawTexturedModalRect(91, 97, 249, 10, 8, 8);
|
||||
|
||||
@@ -6,6 +6,7 @@ import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
|
||||
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
|
||||
import makeo.gadomancy.common.utils.ColorHelper;
|
||||
import makeo.gadomancy.common.utils.SimpleResourceLocation;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -37,6 +38,11 @@ public class InfusionClawGui extends GuiContainer {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
if(((TileInfusionClaw)container.clawInv).isInvalid()) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(null);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack cursorStack = container.playerInv.getItemStack();
|
||||
if(((TileInfusionClaw)container.clawInv).isRunning() || (cursorStack != null && cursorStack.stackSize > 0 && !container.clawInv.isItemValidForSlot(0, cursorStack))) {
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package makeo.gadomancy.common.blocks;
|
||||
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileArcanePackager;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulationFocus;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulatorPillar;
|
||||
import makeo.gadomancy.common.blocks.tiles.*;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.ItemUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -142,7 +141,28 @@ public class BlockStoneMachine extends Block {
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
|
||||
if (metadata == 1) {
|
||||
InventoryUtils.dropItems(world, x, y, z);
|
||||
} else if(metadata == 4) {
|
||||
if(!world.isRemote) {
|
||||
TileArcanePackager tile = (TileArcanePackager) world.getTileEntity(x, y, z);
|
||||
|
||||
for(int i = 0; i < tile.getSizeInventory(); i++) {
|
||||
ItemStack stack = tile.getStackInSlot(i);
|
||||
if(stack != null && stack.stackSize > 0) {
|
||||
float f = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
EntityItem entityItem = new EntityItem(world, x + f, y + f1, z + f2, stack.copy());
|
||||
ItemUtils.applyRandomDropOffset(entityItem, world.rand);
|
||||
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
tile.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
super.breakBlock(world, x, y, z, block, metadata);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.common.tiles.TileJarFillable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
@@ -15,17 +22,132 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
* <p/>
|
||||
* Created by makeo @ 14.11.2015 12:22
|
||||
*/
|
||||
public class TileArcanePackager extends SynchronizedTileEntity implements IInventory, ISidedInventory {
|
||||
public class TileArcanePackager extends TileJarFillable implements IInventory, ISidedInventory {
|
||||
private static final Aspect ASPECT = Aspect.CLOTH;
|
||||
|
||||
private ItemStack[] contents = new ItemStack[12];
|
||||
|
||||
//0 - 46
|
||||
public byte progress = 20;
|
||||
public byte progress = -1;
|
||||
public boolean autoStart = false;
|
||||
public boolean useEssentia = false;
|
||||
public boolean disguise = false;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
public TileArcanePackager() {
|
||||
aspectFilter = ASPECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
if(worldObj.isRemote) {
|
||||
if(progress >= 0 && progress < 46) {
|
||||
progress++;
|
||||
}
|
||||
} else {
|
||||
if(progress >= 47) {
|
||||
doPack();
|
||||
progress = -1;
|
||||
markForUpdate();
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if(progress >= 0) {
|
||||
progress++;
|
||||
} else if(count++ % 5 == 0) {
|
||||
if(autoStart && canPack()) {
|
||||
progress = 0;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canPack() {
|
||||
if(getStackInSlot(11) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean check = false;
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(getStackInSlot(i) != null) {
|
||||
check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!check) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(useEssentia) {
|
||||
if(amount < 4) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ItemStack leather = getStackInSlot(9);
|
||||
if(leather == null || leather.stackSize < 1 || leather.getItem() != Items.leather) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack string = getStackInSlot(10);
|
||||
if(string == null || string.stackSize < 1 || string.getItem() != Items.string) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean startPack() {
|
||||
if(canPack()) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void doPack() {
|
||||
if(canPack()) {
|
||||
List<ItemStack> contents = new ArrayList<ItemStack>();
|
||||
for(int i = 0; i < 9; i++) {
|
||||
ItemStack stack = getStackInSlot(i);
|
||||
if(stack != null) {
|
||||
contents.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
int metadata = disguise ? 1 : 0;
|
||||
metadata |= useEssentia ? 2 : 0;
|
||||
ItemStack pack = new ItemStack(RegisteredItems.itemPackage, 1, metadata);
|
||||
|
||||
boolean success = RegisteredItems.itemPackage.setContents(pack, contents);
|
||||
|
||||
if(success) {
|
||||
if(useEssentia) {
|
||||
amount -= 4;
|
||||
} else {
|
||||
decrStackSize(9, 1);
|
||||
decrStackSize(10, 1);
|
||||
}
|
||||
setInventorySlotContents(11, pack);
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
setInventorySlotContents(i, null);
|
||||
}
|
||||
} else {
|
||||
worldObj.newExplosion(null, xCoord, yCoord, zCoord, 4, false, true);
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound compound) {
|
||||
super.readCustomNBT(compound);
|
||||
aspectFilter = ASPECT;
|
||||
|
||||
progress = compound.getByte("progress");
|
||||
|
||||
byte settings = compound.getByte("settings");
|
||||
@@ -36,6 +158,9 @@ public class TileArcanePackager extends SynchronizedTileEntity implements IInven
|
||||
|
||||
@Override
|
||||
public void writeCustomNBT(NBTTagCompound compound) {
|
||||
super.writeCustomNBT(compound);
|
||||
compound.removeTag("AspectFilter");
|
||||
|
||||
compound.setByte("progress", progress);
|
||||
|
||||
byte settings = (byte) (autoStart ? 1 : 0);
|
||||
@@ -96,6 +221,16 @@ public class TileArcanePackager extends SynchronizedTileEntity implements IInven
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumSuction() {
|
||||
return super.getMinimumSuction() * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSuctionAmount(ForgeDirection loc) {
|
||||
return super.getSuctionAmount(loc) * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "blub";
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.ExplosionEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
import thaumcraft.common.items.wands.ItemWandCasting;
|
||||
import thaumcraft.common.tiles.TileJarFillable;
|
||||
@@ -201,4 +202,19 @@ public class EventHandlerWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onLow(ItemTooltipEvent e) {
|
||||
if(e.itemStack.getItem() == RegisteredItems.itemPackage) {
|
||||
if((e.itemStack.getItemDamage() & 1) == 1) {
|
||||
for(int i = 0; i < e.toolTip.size(); i++) {
|
||||
String line = e.toolTip.get(i);
|
||||
if(line.contains(Gadomancy.NAME)) {
|
||||
line = line.replace(Gadomancy.NAME, Thaumcraft.MODNAME);
|
||||
e.toolTip.set(i, line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package makeo.gadomancy.common.items;
|
||||
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -14,6 +16,7 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.common.items.ItemLootBag;
|
||||
import thaumcraft.common.lib.utils.InventoryUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -31,7 +34,7 @@ import java.util.List;
|
||||
public class ItemArcanePackage extends ItemLootBag {
|
||||
public ItemArcanePackage() {
|
||||
setCreativeTab(null);
|
||||
setUnlocalizedName("ItemLootBag");
|
||||
setUnlocalizedName("ItemArcanePackage");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,14 +69,28 @@ public class ItemArcanePackage extends ItemLootBag {
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
if ((stack.getItemDamage() & 1) == 0) {
|
||||
return "item.ItemArcanePackage";
|
||||
if ((stack.getItemDamage() & 1) == 1) {
|
||||
return "item.ItemLootBag." + (stack.getItemDamage() >> 1);
|
||||
}
|
||||
return super.getUnlocalizedName(stack);
|
||||
return super.getUnlocalizedName();
|
||||
}
|
||||
|
||||
public void setContents(ItemStack stack, List<ItemStack> items) {
|
||||
items = new ArrayList<ItemStack>(items);
|
||||
public boolean setContents(ItemStack stack, List<ItemStack> items) {
|
||||
InventoryBasic tempInv = new InventoryBasic("", false, items.size());
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
InventoryUtils.insertStack(tempInv, item.copy(), 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
items = new ArrayList<ItemStack>(tempInv.getSizeInventory());
|
||||
|
||||
for(int i = 0; i < tempInv.getSizeInventory(); i++) {
|
||||
ItemStack item = tempInv.getStackInSlot(i);
|
||||
if(item != null) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(items, new Comparator<ItemStack>() {
|
||||
@Override
|
||||
@@ -84,9 +101,25 @@ public class ItemArcanePackage extends ItemLootBag {
|
||||
|
||||
NBTTagList stackList = new NBTTagList();
|
||||
for (ItemStack item : items) {
|
||||
stackList.appendTag(item.writeToNBT(new NBTTagCompound()));
|
||||
//Prevent depth of more then 2 packages
|
||||
if(item.getItem() == RegisteredItems.itemPackage) {
|
||||
List<ItemStack> packedItems = getContents(item);
|
||||
for(ItemStack packedItem : packedItems) {
|
||||
if(packedItem.getItem() == RegisteredItems.itemPackage) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//If the compound is too long it will not work to prevent lag
|
||||
NBTTagCompound itemTag = item.writeToNBT(new NBTTagCompound());
|
||||
if(itemTag.toString().length() > 8000) {
|
||||
return false;
|
||||
}
|
||||
stackList.appendTag(itemTag);
|
||||
}
|
||||
NBTHelper.getData(stack).setTag("items", stackList);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<ItemStack> getContents(ItemStack stack) {
|
||||
|
||||
@@ -12,19 +12,7 @@ import makeo.gadomancy.common.blocks.BlockNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.BlockRemoteJar;
|
||||
import makeo.gadomancy.common.blocks.BlockStickyJar;
|
||||
import makeo.gadomancy.common.blocks.BlockStoneMachine;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAdditionalEldritchPortal;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylon;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylonTop;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileExtendedNodeJar;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulationFocus;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileManipulatorPillar;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
|
||||
import makeo.gadomancy.common.blocks.tiles.*;
|
||||
import makeo.gadomancy.common.items.ItemBlockAdditionalEldritchPortal;
|
||||
import makeo.gadomancy.common.items.ItemBlockAuraPylon;
|
||||
import makeo.gadomancy.common.items.ItemBlockRemoteJar;
|
||||
@@ -127,6 +115,7 @@ public class RegisteredBlocks {
|
||||
registerTile(TileBlockProtector.class);
|
||||
registerTile(TileAuraPylon.class);
|
||||
registerTile(TileAuraPylonTop.class);
|
||||
registerTile(TileArcanePackager.class);
|
||||
}
|
||||
|
||||
private static void registerTile(Class<? extends TileEntity> tile, String name) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class RegisteredItems {
|
||||
public static Item itemExtendedNodeJar;
|
||||
public static Item itemFamiliar;
|
||||
public static Item itemCreativeNode;
|
||||
public static Item itemPackage;
|
||||
public static ItemArcanePackage itemPackage;
|
||||
|
||||
public static void preInit() {
|
||||
creativeTab = new CreativeTabs(Gadomancy.MODID) {
|
||||
|
||||
Reference in new issue
Block a user