Fixed the Biome Radar model, added the Flower Basket
This commit is contained in:
parent
1223f8e753
commit
0208fe6fc0
19 changed files with 683 additions and 4 deletions
|
@ -106,6 +106,7 @@ public class BOPItems
|
|||
public static Item biome_finder;
|
||||
public static Item biome_essence;
|
||||
public static Item enderporter;
|
||||
public static Item flower_basket;
|
||||
public static Item jar_empty;
|
||||
public static Item jar_filled;
|
||||
public static Item honey_bucket;
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package biomesoplenty.client.gui.inventory;
|
||||
|
||||
import static biomesoplenty.common.inventory.InventoryFlowerBasket.INVENTORY_ROWS;
|
||||
|
||||
import biomesoplenty.common.inventory.ContainerFlowerBasket;
|
||||
import biomesoplenty.common.inventory.InventoryFlowerBasket;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiFlowerBasket extends GuiContainer
|
||||
{
|
||||
//Reuse the chest texture to save us some trouble
|
||||
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("textures/gui/container/generic_54.png");
|
||||
|
||||
private final InventoryPlayer playerInventory;
|
||||
private InventoryFlowerBasket inventory;
|
||||
|
||||
public GuiFlowerBasket(EntityPlayer player, InventoryFlowerBasket inventoryFlowerBasket)
|
||||
{
|
||||
super(new ContainerFlowerBasket(player, inventoryFlowerBasket));
|
||||
|
||||
this.playerInventory = player.inventory;
|
||||
this.inventory = inventoryFlowerBasket;
|
||||
this.ySize = 114 + INVENTORY_ROWS * 18;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
||||
{
|
||||
String inventoryName = this.inventory.getDisplayName().getUnformattedText();
|
||||
this.fontRendererObj.drawString(inventoryName, 8, 6, 4210752);
|
||||
this.fontRendererObj.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
|
||||
{
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
|
||||
|
||||
int drawStartX = (this.width - this.xSize) / 2;
|
||||
int drawStartY = (this.height - this.ySize) / 2;
|
||||
|
||||
//Draw the top half of the bag inventory. Starts from the top left of the texture, offset by 17 pixels from the
|
||||
//top to account for the inventory title. Each row of slots is 18 pixels tall.
|
||||
this.drawTexturedModalRect(drawStartX, drawStartY, 0, 0, this.xSize, INVENTORY_ROWS * 18 + 17);
|
||||
|
||||
//Draw the player's hotbar and inventory (96 pixels tall). Begin drawing beneath the top half of the inventory, based
|
||||
//on the number of rows drawn. The bottom half of the inventory begins 126 pixels from the top of the image.
|
||||
this.drawTexturedModalRect(drawStartX, drawStartY + INVENTORY_ROWS * 18 + 17, 0, 126, this.xSize, 96);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import biomesoplenty.client.model.ModelBiomeFinder;
|
||||
import biomesoplenty.client.model.ModelFlowerBasket;
|
||||
import biomesoplenty.client.texture.TextureAnimationFrame;
|
||||
import biomesoplenty.client.util.TextureUtils;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
|
@ -27,8 +28,11 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|||
|
||||
public class ModelBakeHandler
|
||||
{
|
||||
public static final ModelResourceLocation BIOME_FINDER_LOC = new ModelResourceLocation("biomesoplenty:item/biome_finder", "inventory");
|
||||
public static final ModelResourceLocation BIOME_FINDER_REG_LOC = new ModelResourceLocation("biomesoplenty:biome_finder", "inventory");
|
||||
public static final ModelResourceLocation BIOME_FINDER_LOC = new ModelResourceLocation("biomesoplenty:biome_finder", "inventory");
|
||||
|
||||
public static final ModelResourceLocation FLOWER_BASKET_LOC = new ModelResourceLocation("biomesoplenty:flower_basket", "inventory");
|
||||
public static final ModelResourceLocation FLOWER_BASKET_EMPTY_LOC = new ModelResourceLocation("biomesoplenty:flower_basket_empty", "inventory");
|
||||
public static final ModelResourceLocation FLOWER_BASKET_FULL_LOC = new ModelResourceLocation("biomesoplenty:flower_basket_full", "inventory");
|
||||
|
||||
public static List<String> fluidsToTextureStitch = new ArrayList<String>();
|
||||
|
||||
|
@ -58,6 +62,7 @@ public class ModelBakeHandler
|
|||
//Get the existing model defined by the json file
|
||||
IModel biomeFinderModel = modelLoader.getModel(BIOME_FINDER_LOC);
|
||||
//Replace the existing model with our new flexible one
|
||||
modelRegistry.putObject(BIOME_FINDER_REG_LOC, new ModelBiomeFinder(biomeFinderModel, biomeFinderFrames));
|
||||
modelRegistry.putObject(BIOME_FINDER_LOC, new ModelBiomeFinder(biomeFinderModel, biomeFinderFrames));
|
||||
modelRegistry.putObject(FLOWER_BASKET_LOC, new ModelFlowerBasket(modelRegistry.getObject(FLOWER_BASKET_EMPTY_LOC), modelRegistry.getObject(FLOWER_BASKET_FULL_LOC)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2016, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.client.model;
|
||||
|
||||
import biomesoplenty.common.inventory.InventoryFlowerBasket;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.model.IFlexibleBakedModel;
|
||||
import net.minecraftforge.client.model.ISmartItemModel;
|
||||
|
||||
public class ModelFlowerBasket extends IFlexibleBakedModel.Wrapper implements ISmartItemModel
|
||||
{
|
||||
private IBakedModel emptyBakedModel;
|
||||
private IBakedModel filledBakedModel;
|
||||
|
||||
public ModelFlowerBasket(IBakedModel emptyModel, IBakedModel filledModel)
|
||||
{
|
||||
super(null, DefaultVertexFormats.ITEM);
|
||||
|
||||
this.emptyBakedModel = emptyModel;
|
||||
this.filledBakedModel = filledModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handleItemState(ItemStack stack)
|
||||
{
|
||||
InventoryFlowerBasket inventory = new InventoryFlowerBasket(stack, null);
|
||||
boolean filled = false;
|
||||
|
||||
for (int index = 0; index < inventory.getSizeInventory(); ++index)
|
||||
{
|
||||
if (inventory.getStackInSlot(index) != null)
|
||||
{
|
||||
filled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return filled ? this.filledBakedModel : this.emptyBakedModel;
|
||||
}
|
||||
}
|
37
src/main/java/biomesoplenty/common/handler/GuiHandler.java
Normal file
37
src/main/java/biomesoplenty/common/handler/GuiHandler.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package biomesoplenty.common.handler;
|
||||
|
||||
import biomesoplenty.client.gui.inventory.GuiFlowerBasket;
|
||||
import biomesoplenty.common.inventory.ContainerFlowerBasket;
|
||||
import biomesoplenty.common.inventory.InventoryFlowerBasket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
|
||||
public class GuiHandler implements IGuiHandler
|
||||
{
|
||||
public static final int FLOWER_BASKET_ID = 0;
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
if (id == FLOWER_BASKET_ID)
|
||||
{
|
||||
//We assume if the flower basket gui is open, then the player must be holding a flower basket
|
||||
return new ContainerFlowerBasket(player, new InventoryFlowerBasket(player));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
if (id == FLOWER_BASKET_ID)
|
||||
{
|
||||
return new GuiFlowerBasket(player, new InventoryFlowerBasket(player));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package biomesoplenty.common.handler;
|
||||
|
||||
import biomesoplenty.common.inventory.ContainerFlowerBasket;
|
||||
import biomesoplenty.common.inventory.InventoryFlowerBasket;
|
||||
import biomesoplenty.common.item.ItemFlowerBasket;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class ItemEventHandler
|
||||
{
|
||||
/**
|
||||
* Closes the gui if the open flower basket is tossed
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onItemToss(ItemTossEvent event)
|
||||
{
|
||||
EntityPlayer player = event.player;
|
||||
ItemStack stack = event.entityItem.getEntityItem();
|
||||
|
||||
if (player.openContainer instanceof ContainerFlowerBasket)
|
||||
{
|
||||
//Only close the gui if this stack was the one that was open
|
||||
if (ItemFlowerBasket.isBasketOpen(stack))
|
||||
{
|
||||
//Remove the itemstack from the inventory now to prevent a loop
|
||||
player.inventory.setItemStack(null);
|
||||
player.closeScreen();
|
||||
}
|
||||
}
|
||||
|
||||
//Ensure the tossed stack is properly closed
|
||||
ItemFlowerBasket.closeIfBasket(stack);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemPickup(EntityItemPickupEvent event)
|
||||
{
|
||||
EntityPlayer player = event.entityPlayer;
|
||||
EntityItem entityItem = event.item;
|
||||
|
||||
ItemStack stack = event.item.getEntityItem();
|
||||
ItemStack basketStack = ItemFlowerBasket.findBasketStack(player);
|
||||
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
//Check if the player has a basket in their inventory, and if the stack is suitable for adding
|
||||
//to the basket
|
||||
if (basketStack != null && ItemFlowerBasket.isStackSuitableForBasket(stack))
|
||||
{
|
||||
InventoryFlowerBasket inventory = new InventoryFlowerBasket(basketStack, player);
|
||||
|
||||
//Add the stack to the basket's inventory
|
||||
inventory.func_174894_a(stack);
|
||||
//Set stack size to 0 to cause it to be removed
|
||||
stack.stackSize = 0;
|
||||
//Prevent the stack from being added to the player's inventory
|
||||
event.setResult(Result.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -174,6 +174,9 @@ public class ModCrafting
|
|||
GameRegistry.addShapedRecipe(new ItemStack(BOPItems.biome_finder), new Object[] {" E ", "ERE", " E ", 'E', new ItemStack(Items.emerald), 'R', new ItemStack(Items.redstone)});
|
||||
GameRegistry.addRecipe(new BiomeEssenceRecipe());
|
||||
|
||||
/*** Flower Basket ***/
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BOPItems.flower_basket), new Object [] {" S ", "S S", "SSS", 'S', "stickWood" }));
|
||||
|
||||
/*** Misc Others ***/
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ public class ModHandlers
|
|||
MinecraftForge.EVENT_BUS.register(new BucketEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new PotionParalysisEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new PotionPossessionEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new ItemEventHandler());
|
||||
FMLCommonHandler.instance().bus().register(new AchievementEventHandler());
|
||||
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.init.Blocks;
|
|||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.Item.ToolMaterial;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
@ -36,6 +37,12 @@ import biomesoplenty.core.BiomesOPlenty;
|
|||
public class ModItems
|
||||
{
|
||||
public static void init()
|
||||
{
|
||||
registerItems();
|
||||
setupModels();
|
||||
}
|
||||
|
||||
public static void registerItems()
|
||||
{
|
||||
// food
|
||||
ambrosia = registerItem(new ItemAmbrosia(), "ambrosia");
|
||||
|
@ -167,6 +174,7 @@ public class ModItems
|
|||
biome_finder = registerItem(new ItemBiomeFinder(), "biome_finder");
|
||||
biome_essence = registerItem(new ItemBiomeEssence(), "biome_essence");
|
||||
enderporter = registerItem(new ItemEnderporter(), "enderporter");
|
||||
flower_basket = registerItem(new ItemFlowerBasket(), "flower_basket");
|
||||
jar_empty = registerItem(new ItemJarEmpty(), "jar_empty");
|
||||
jar_filled = registerItem(new ItemJarFilled(), "jar_filled");
|
||||
|
||||
|
@ -178,6 +186,14 @@ public class ModItems
|
|||
|
||||
}
|
||||
|
||||
private static void setupModels()
|
||||
{
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
|
||||
{
|
||||
ModelBakery.registerItemVariants(flower_basket, new ResourceLocation(BiomesOPlenty.MOD_ID, "flower_basket_empty"), new ResourceLocation(BiomesOPlenty.MOD_ID, "flower_basket_full"));
|
||||
}
|
||||
}
|
||||
|
||||
public static Item registerItem(Item item, String name)
|
||||
{
|
||||
return registerItem(item, name, CreativeTabBOP.instance);
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2016, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.inventory;
|
||||
|
||||
import static biomesoplenty.common.inventory.InventoryFlowerBasket.INVENTORY_ROWS;
|
||||
import static biomesoplenty.common.inventory.InventoryFlowerBasket.INVENTORY_COLUMNS;
|
||||
|
||||
import biomesoplenty.common.item.ItemFlowerBasket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerFlowerBasket extends Container
|
||||
{
|
||||
private static final int PLAYER_ROWS = 3;
|
||||
private static final int PLAYER_COLUMNS = 9;
|
||||
|
||||
public ContainerFlowerBasket(EntityPlayer player, InventoryFlowerBasket inventoryFlowerBasket)
|
||||
{
|
||||
//Slots are inset on the x axis by 8 pixels as a result of the inventory border.
|
||||
//Each slot is 18 pixels wide. The total slot height may vary as extra rows are
|
||||
//added, however there is always a constant based on the texture layout.
|
||||
|
||||
int totalInvSlotHeight = INVENTORY_ROWS * 18;
|
||||
|
||||
for (int row = 0; row < INVENTORY_ROWS; ++row)
|
||||
{
|
||||
for (int col = 0; col < INVENTORY_COLUMNS; ++col)
|
||||
{
|
||||
this.addSlotToContainer(new BasketSlot(inventoryFlowerBasket, col + row * 9, 8 + col * 18, 18 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
//Adds slots for the player's inventory
|
||||
for (int row = 0; row < PLAYER_ROWS; ++row)
|
||||
{
|
||||
for (int col = 0; col < PLAYER_COLUMNS; ++col)
|
||||
{
|
||||
//Start at index 9, after the hotbar
|
||||
this.addSlotToContainer(new Slot(player.inventory, col + row * 9 + 9, 8 + col * 18, 31 + row * 18 + totalInvSlotHeight));
|
||||
}
|
||||
}
|
||||
|
||||
//Adds slots for the player's hotbar
|
||||
for (int col = 0; col < PLAYER_COLUMNS; ++col)
|
||||
{
|
||||
//Hotbar uses the indexes 0-8 for its slots.
|
||||
this.addSlotToContainer(new Slot(player.inventory, col, 8 + col * 18, 89 + totalInvSlotHeight));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player)
|
||||
{
|
||||
super.onContainerClosed(player);
|
||||
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
//Ensure all baskets are closed once the inventory is
|
||||
ItemFlowerBasket.clearOpenBaskets(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int index)
|
||||
{
|
||||
ItemStack oldStack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
|
||||
//Ensure there is a slot at this index and it has an item in it
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack mergedStack = slot.getStack();
|
||||
oldStack = mergedStack.copy();
|
||||
|
||||
if (index < INVENTORY_ROWS * 9)
|
||||
{
|
||||
if (!this.mergeItemStack(mergedStack, INVENTORY_ROWS * 9, this.inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(mergedStack, 0, INVENTORY_ROWS * 9, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (mergedStack.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return oldStack;
|
||||
}
|
||||
|
||||
public static class BasketSlot extends Slot
|
||||
{
|
||||
public BasketSlot(IInventory inventoryIn, int index, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, index, xPosition, yPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return ItemFlowerBasket.isStackSuitableForBasket(stack);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2016, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.inventory;
|
||||
|
||||
import biomesoplenty.common.item.ItemFlowerBasket;
|
||||
import biomesoplenty.common.util.NBTUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
public class InventoryFlowerBasket extends InventoryBasic
|
||||
{
|
||||
public static final int INVENTORY_ROWS = 2;
|
||||
public static final int INVENTORY_COLUMNS = 9;
|
||||
|
||||
private EntityPlayer player;
|
||||
|
||||
private ItemStack ownerStack;
|
||||
|
||||
public InventoryFlowerBasket(ItemStack ownerStack, EntityPlayer player)
|
||||
{
|
||||
super("container.flower_basket", false, INVENTORY_ROWS * INVENTORY_COLUMNS);
|
||||
|
||||
this.player = player;
|
||||
|
||||
//Load only on the server
|
||||
ItemStack basketStack = ownerStack;
|
||||
|
||||
if (basketStack == null) basketStack = player.getHeldItem();
|
||||
else this.ownerStack = basketStack;
|
||||
|
||||
NBTTagCompound invData = NBTUtil.getOrCreateStackNBT(basketStack);
|
||||
this.readFromNBT(invData);
|
||||
}
|
||||
|
||||
public InventoryFlowerBasket(EntityPlayer player)
|
||||
{
|
||||
this(null, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
//Resolve the basket stack (it may have moved since it was opened)
|
||||
ItemStack basketStack = getBasketStack();
|
||||
|
||||
//There's no point continuing if there's nothing to save to
|
||||
if (basketStack != null)
|
||||
{
|
||||
NBTTagCompound currentData = new NBTTagCompound();
|
||||
//Overwrite relevant data in the compound with updated data
|
||||
this.writeToNBT(currentData);
|
||||
//Replace the stack's compound
|
||||
basketStack.setTagCompound(currentData);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound)
|
||||
{
|
||||
//Obtain a list of the existing items
|
||||
NBTTagList itemsList = compound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
|
||||
//Remove any existing items
|
||||
this.clear();
|
||||
|
||||
for (int index = 0; index < itemsList.tagCount(); ++index)
|
||||
{
|
||||
NBTTagCompound itemTag = itemsList.getCompoundTagAt(index);
|
||||
int slotIndex = itemTag.getByte("Slot");
|
||||
|
||||
//Ensure the slot index is valid
|
||||
if (slotIndex >= 0 && slotIndex < this.getSizeInventory())
|
||||
{
|
||||
this.setInventorySlotContents(slotIndex, ItemStack.loadItemStackFromNBT(itemTag));
|
||||
}
|
||||
}
|
||||
|
||||
if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
|
||||
{
|
||||
this.setCustomName(compound.getString("CustomName"));
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound)
|
||||
{
|
||||
//Create a new items list to write to
|
||||
NBTTagList itemsList = new NBTTagList();
|
||||
|
||||
//Iterate over all valid slot indexes
|
||||
for (int slotIndex = 0; slotIndex < this.getSizeInventory(); ++slotIndex)
|
||||
{
|
||||
if (this.getStackInSlot(slotIndex) != null)
|
||||
{
|
||||
//Create a new item tag and populate it with data
|
||||
NBTTagCompound itemTag = new NBTTagCompound();
|
||||
itemTag.setByte("Slot", (byte)slotIndex);
|
||||
this.getStackInSlot(slotIndex).writeToNBT(itemTag);
|
||||
itemsList.appendTag(itemTag);
|
||||
}
|
||||
}
|
||||
|
||||
//Update the Items compound with our new data
|
||||
compound.setTag("Items", itemsList);
|
||||
|
||||
if (this.hasCustomName())
|
||||
{
|
||||
compound.setString("CustomName", this.getName());
|
||||
}
|
||||
|
||||
//We can't assume the basket is always open because the inventory may be accessed
|
||||
//outside of the gui
|
||||
compound.setBoolean("BasketOpen", ItemFlowerBasket.isBasketOpen(getBasketStack()));
|
||||
}
|
||||
|
||||
private ItemStack getBasketStack()
|
||||
{
|
||||
return this.ownerStack != null ? this.ownerStack : ItemFlowerBasket.findOpenBasketStack(this.player);
|
||||
}
|
||||
}
|
120
src/main/java/biomesoplenty/common/item/ItemFlowerBasket.java
Normal file
120
src/main/java/biomesoplenty/common/item/ItemFlowerBasket.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright 2016, the Biomes O' Plenty Team
|
||||
*
|
||||
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
|
||||
*
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
|
||||
******************************************************************************/
|
||||
|
||||
package biomesoplenty.common.item;
|
||||
|
||||
import biomesoplenty.common.handler.GuiHandler;
|
||||
import biomesoplenty.common.util.NBTUtil;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
|
||||
public class ItemFlowerBasket extends Item
|
||||
{
|
||||
public ItemFlowerBasket()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
NBTTagCompound compound = NBTUtil.getOrCreateStackNBT(stack);
|
||||
|
||||
//Ensure there are no other open baskets in the player's inventory
|
||||
//This oculd potentially happen if the inventory is never properly closed
|
||||
clearOpenBaskets(player);
|
||||
//Tag this basket as open
|
||||
compound.setBoolean("BasketOpen", true);
|
||||
//Set the stack's data in case it didn't previously have any
|
||||
player.openGui(BiomesOPlenty.instance, GuiHandler.FLOWER_BASKET_ID, world, 0, 0, 0);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack findBasketStack(EntityPlayer player)
|
||||
{
|
||||
//Search every item in the player's main inventory for a basket
|
||||
for (ItemStack stack : player.inventory.mainInventory)
|
||||
{
|
||||
if (stack != null && stack.getItem() instanceof ItemFlowerBasket)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack findOpenBasketStack(EntityPlayer player)
|
||||
{
|
||||
//Search every item in the player's main inventory for a basket
|
||||
for (ItemStack stack : player.inventory.mainInventory)
|
||||
{
|
||||
if (isBasketOpen(stack))
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isBasketOpen(ItemStack stack)
|
||||
{
|
||||
if (stack != null && stack.getItem() instanceof ItemFlowerBasket && stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
|
||||
if (compound.hasKey("BasketOpen"))
|
||||
{
|
||||
return compound.getBoolean("BasketOpen");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void clearOpenBaskets(EntityPlayer player)
|
||||
{
|
||||
//Search every item in the player's main inventory for a basket
|
||||
for (ItemStack stack : player.inventory.mainInventory)
|
||||
{
|
||||
closeIfBasket(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeIfBasket(ItemStack stack)
|
||||
{
|
||||
//Validate to ensure the stack is a basket and it is open
|
||||
if (isBasketOpen(stack))
|
||||
{
|
||||
NBTTagCompound compound = stack.getTagCompound();
|
||||
//Ensure the basket is closed
|
||||
compound.setBoolean("BasketOpen", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isStackSuitableForBasket(ItemStack stack)
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
Block block = Block.getBlockFromItem(item);
|
||||
|
||||
return !(item instanceof ItemFlowerBasket) && block != null && (block instanceof IPlantable || block instanceof IGrowable || block instanceof IShearable);
|
||||
}
|
||||
}
|
26
src/main/java/biomesoplenty/common/util/NBTUtil.java
Normal file
26
src/main/java/biomesoplenty/common/util/NBTUtil.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package biomesoplenty.common.util;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class NBTUtil
|
||||
{
|
||||
/**
|
||||
* Retrieve a stack's nbt data if it has any. If it doesn't, return a new
|
||||
* compound.
|
||||
*/
|
||||
public static NBTTagCompound getOrCreateStackNBT(ItemStack stack)
|
||||
{
|
||||
if (stack == null)
|
||||
throw new IllegalArgumentException("ItemStack cannot be null!");
|
||||
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound stackCompound = new NBTTagCompound();
|
||||
stack.setTagCompound(stackCompound);
|
||||
return stackCompound;
|
||||
}
|
||||
|
||||
return stack.getTagCompound();
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import biomesoplenty.common.command.BOPCommand;
|
||||
import biomesoplenty.common.handler.GuiHandler;
|
||||
import biomesoplenty.common.init.ModBiomes;
|
||||
import biomesoplenty.common.init.ModBlockQueries;
|
||||
import biomesoplenty.common.init.ModBlocks;
|
||||
|
@ -35,6 +36,7 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
|
||||
@Mod(modid = BiomesOPlenty.MOD_ID, name = BiomesOPlenty.MOD_NAME, dependencies = "required-after:Forge@[11.14.3.1468,)")
|
||||
public class BiomesOPlenty
|
||||
|
@ -76,7 +78,10 @@ public class BiomesOPlenty
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {}
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
|
|
|
@ -14,6 +14,8 @@ commands.biomesoplenty.stats.entities=Entities: %s
|
|||
commands.biomesoplenty.stats.biomes=Biomes: %s
|
||||
commands.biomesoplenty.stripchunk.usage=/biomesoplenty stripchunk [radius] <include|exclude> [block] [metadata]
|
||||
|
||||
container.flower_basket=Flower Basket
|
||||
|
||||
generator.BIOMESOP=Biomes O' Plenty
|
||||
generator.BIOMESOP.info=Notice: Biomes O' Plenty 1.8 is in a very early state
|
||||
|
||||
|
@ -52,6 +54,7 @@ item.filled_honeycomb.name=Filled Honeycomb
|
|||
item.fir_door.name=Fir Door
|
||||
item.fleshchunk.name=Chunk of Flesh
|
||||
item.flippers.name=Flippers
|
||||
item.flower_basket.name=Flower Basket
|
||||
item.gem_amber.name=Amber
|
||||
item.gem_amethyst.name=Ender Amethyst
|
||||
item.gem_malachite.name=Malachite
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "biomesoplenty:items/flower_basket_empty"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ -90, 0, 0 ],
|
||||
"translation": [ 0, 1, -3 ],
|
||||
"scale": [ 0.55, 0.55, 0.55 ]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [ 0, -135, 25 ],
|
||||
"translation": [ 0, 4, 2 ],
|
||||
"scale": [ 1.7, 1.7, 1.7 ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"parent": "builtin/generated",
|
||||
"textures": {
|
||||
"layer0": "biomesoplenty:items/flower_basket_full"
|
||||
},
|
||||
"display": {
|
||||
"thirdperson": {
|
||||
"rotation": [ -90, 0, 0 ],
|
||||
"translation": [ 0, 1, -3 ],
|
||||
"scale": [ 0.55, 0.55, 0.55 ]
|
||||
},
|
||||
"firstperson": {
|
||||
"rotation": [ 0, -135, 25 ],
|
||||
"translation": [ 0, 4, 2 ],
|
||||
"scale": [ 1.7, 1.7, 1.7 ]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 272 B |
Binary file not shown.
After Width: | Height: | Size: 290 B |
Loading…
Reference in a new issue