mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-17 02:55:19 +00:00
Merge my branch into the main one, initial work on the thaumic apiary
Might have messed something up. Not quite sure
This commit is contained in:
1 parent
33b0af6682
commit
016049ef67
12 files changed
+339
-37
No files matched your search
@@ -3,53 +3,112 @@ package magicbees.block;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import magicbees.client.gui.UIScreens;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.MagicBees;
|
||||
import magicbees.main.utils.TabMagicBees;
|
||||
import magicbees.tileentity.TileEntityThaumicApiary;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class BlockThaumicApiary extends BlockContainer
|
||||
{
|
||||
public BlockThaumicApiary()
|
||||
{
|
||||
super(Material.wood);
|
||||
this.setCreativeTab(TabMagicBees.tabMagicBees);
|
||||
this.setBlockName("thaumicApiary");
|
||||
this.setHardness(1f);
|
||||
this.setResistance(1.5f);
|
||||
this.setHarvestLevel("axe", 0);
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon[] icons;
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
|
||||
{
|
||||
boolean activate = false;
|
||||
public BlockThaumicApiary()
|
||||
{
|
||||
super(Material.wood);
|
||||
this.setCreativeTab(TabMagicBees.tabMagicBees);
|
||||
this.setBlockName("thaumicApiary");
|
||||
this.setHardness(1f);
|
||||
this.setResistance(1.5f);
|
||||
this.setHarvestLevel("axe", 0);
|
||||
}
|
||||
|
||||
if (!player.isSneaking())
|
||||
{
|
||||
player.openGui(MagicBees.object, UIScreens.THAUMIC_APIARY.ordinal(), world, x, y, z);
|
||||
activate = true;
|
||||
}
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9 )
|
||||
{
|
||||
boolean activate = false;
|
||||
|
||||
return activate;
|
||||
}
|
||||
if (!player.isSneaking())
|
||||
{
|
||||
player.openGui(MagicBees.object, UIScreens.THAUMIC_APIARY.ordinal(), world, x, y, z);
|
||||
activate = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister register)
|
||||
{
|
||||
return activate;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int meta){
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
|
||||
{
|
||||
return new TileEntityThaumicApiary();
|
||||
}
|
||||
if (side == 0){
|
||||
return icons[0];
|
||||
}else if (side == 1){
|
||||
return icons[1];
|
||||
}else if (side == 2 || side == 3){
|
||||
return icons[2];
|
||||
}else{
|
||||
return icons[4];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister register)
|
||||
{
|
||||
icons = new IIcon[5];
|
||||
|
||||
icons[0] = register.registerIcon(CommonProxy.DOMAIN + ":thaumicapiary.0");
|
||||
icons[1] = register.registerIcon(CommonProxy.DOMAIN + ":thaumicapiary.1");
|
||||
icons[2] = register.registerIcon(CommonProxy.DOMAIN + ":thaumicapiary.2");
|
||||
icons[4] = register.registerIcon(CommonProxy.DOMAIN + ":thaumicapiary.4");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileEntityThaumicApiary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta){
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te != null && te instanceof IInventory){
|
||||
IInventory inventory = (IInventory)te;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++){
|
||||
ItemStack itemStack = inventory.getStackInSlotOnClosing(i);
|
||||
|
||||
if (itemStack != null){
|
||||
float spawnX = x + world.rand.nextFloat();
|
||||
float spawnY = y + world.rand.nextFloat();
|
||||
float spawnZ = z + world.rand.nextFloat();
|
||||
|
||||
EntityItem droppedItem = new EntityItem(world, spawnX, spawnY, spawnZ, itemStack);
|
||||
|
||||
float mult = 0.05F;
|
||||
|
||||
droppedItem.motionX = (-0.5F + world.rand.nextFloat()) * mult;
|
||||
droppedItem.motionY = (4 + world.rand.nextFloat()) * mult;
|
||||
droppedItem.motionZ = (-0.5F + world.rand.nextFloat()) * mult;
|
||||
|
||||
world.spawnEntityInWorld(droppedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
public class ContainerMB extends Container
|
||||
{
|
||||
protected final int PLAYER_INVENTORY_ROWS = 3;
|
||||
protected final int PLAYER_INVENTORY_COLUMNS = 9;
|
||||
|
||||
public void addPlayerInventory(InventoryPlayer inventoryPlayer, int xStart, int yStart)
|
||||
{
|
||||
for (int x = 0; x < PLAYER_INVENTORY_COLUMNS; x++){
|
||||
addSlotToContainer(new Slot(inventoryPlayer, x, 8 + 18 * x, yStart + 4 + PLAYER_INVENTORY_ROWS * 18));
|
||||
}
|
||||
|
||||
for (int y = 0; y < PLAYER_INVENTORY_ROWS; y++){
|
||||
for (int x = 0; x < PLAYER_INVENTORY_COLUMNS; x++){
|
||||
addSlotToContainer(new Slot(inventoryPlayer, x + y * 9 + 9, 8 + 18 * x, yStart + y * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import forestry.api.apiculture.hives.IHive;
|
||||
import forestry.plugins.PluginApiculture;
|
||||
import magicbees.main.utils.ItemInterface;
|
||||
import magicbees.main.utils.LogHelper;
|
||||
import magicbees.tileentity.TileEntityThaumicApiary;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerThaumicApiary extends ContainerMB {
|
||||
|
||||
private TileEntityThaumicApiary thaumicApiary;
|
||||
public int maxSlot = 0;
|
||||
|
||||
// Constants
|
||||
private static final int SLOT_QUEEN = 0;
|
||||
private static final int SLOT_DRONE = 1;
|
||||
private static final int SLOT_FRAME_START = 2;
|
||||
private static final int SLOT_INVENTORY_START = 5;
|
||||
private static final int SLOT_FRAME_COUNT = 3;
|
||||
private static final int SLOT_INVENTORY_COUNT = 7;
|
||||
|
||||
public ContainerThaumicApiary(InventoryPlayer inventoryPlayer, TileEntityThaumicApiary thaumicApiary){
|
||||
this.thaumicApiary = thaumicApiary;
|
||||
|
||||
// Queen/Princess slot
|
||||
addSlotToContainer(new SlotCustomItems(this.thaumicApiary, 0, 29, 39, ItemInterface.getItemStack("Forestry", "beeQueenGE", 1), ItemInterface.getItemStack("Forestry", "beePrincessGE", 1)));
|
||||
// Drone slot
|
||||
addSlotToContainer(new SlotCustomItems(this.thaumicApiary, 1, 29, 65, ItemInterface.getItemStack("Forestry", "beeDroneGE", 64)));
|
||||
|
||||
int currentSlot = 1;
|
||||
|
||||
// Frame slots
|
||||
for (int x = 0; x < 3; x++){
|
||||
currentSlot++;
|
||||
addSlotToContainer(new SlotFrame(thaumicApiary, currentSlot, 66, 23 + x * 29));
|
||||
//LogHelper.info("[1] CURRENTSLOT: " + currentSlot);
|
||||
}
|
||||
|
||||
for (int x = 0; x < 3; x++){
|
||||
currentSlot++;
|
||||
addSlotToContainer(new Slot(thaumicApiary, currentSlot, 116, 26 + x * 26));
|
||||
//LogHelper.info("[2] CURRENTSLOT: " + currentSlot);
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (int y = 0; y < 2; y++){
|
||||
for (int x = 0; x < 2; x++){
|
||||
currentSlot++;
|
||||
addSlotToContainer(new Slot(thaumicApiary, currentSlot, 95 + x * 42, 39 + j * 26));
|
||||
//LogHelper.info("[3] CURRENTSLOT: " + currentSlot);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
|
||||
addPlayerInventory(inventoryPlayer, 0, 108);
|
||||
|
||||
maxSlot = currentSlot;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex){
|
||||
Slot itemSlot = this.getSlot(slotIndex);
|
||||
boolean clearSlot = false;
|
||||
|
||||
if (itemSlot != null && itemSlot.getHasStack()) {
|
||||
ItemStack srcStack = itemSlot.getStack();
|
||||
|
||||
if (slotIndex <= maxSlot && srcStack != null){
|
||||
clearSlot = this.mergeItemStack(srcStack, maxSlot + 1, maxSlot + 36, false);
|
||||
}else{
|
||||
if (slotIndex > maxSlot && srcStack != null){
|
||||
if (PluginApiculture.beeInterface.isMember(srcStack)){
|
||||
if (!PluginApiculture.beeInterface.isDrone(srcStack)){
|
||||
if (this.getSlot(SLOT_QUEEN).getHasStack() == false) {
|
||||
clearSlot = this.mergeItemStack(srcStack, SLOT_QUEEN, SLOT_QUEEN, false);
|
||||
}
|
||||
}else{
|
||||
if (this.getSlot(SLOT_DRONE).isItemValid(srcStack)){
|
||||
clearSlot = this.mergeItemStack(srcStack, SLOT_DRONE, SLOT_DRONE, false);
|
||||
}
|
||||
}
|
||||
}else if(srcStack.getItem() instanceof IHiveFrame){
|
||||
clearSlot = this.mergeItemStack(srcStack, SLOT_FRAME_START, SLOT_FRAME_START + SLOT_FRAME_COUNT, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (clearSlot){
|
||||
itemSlot.putStack(null);
|
||||
}
|
||||
|
||||
itemSlot.onSlotChanged();
|
||||
player.inventory.markDirty();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
||||
return thaumicApiary.isUseableByPlayer(entityPlayer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
thaumicApiary.getGUINetworkData(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
for (Object crafter : crafters) {
|
||||
thaumicApiary.sendGUINetworkData(this, (ICrafting) crafter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import magicbees.tileentity.TileEntityEffectJar;
|
||||
import magicbees.tileentity.TileEntityThaumicApiary;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
|
||||
public class GUIHandler implements IGuiHandler
|
||||
{
|
||||
@@ -12,15 +14,16 @@ public class GUIHandler implements IGuiHandler
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
Object value = null;
|
||||
|
||||
|
||||
if (ID == UIScreens.EFFECT_JAR.ordinal())
|
||||
{
|
||||
value = new ContainerEffectJar((TileEntityEffectJar)world.getTileEntity(x, y, z), player);
|
||||
}
|
||||
else if (ID == UIScreens.THAUMIC_APIARY.ordinal())
|
||||
{
|
||||
//value = new Container((TileEntityThaumicApiary)world.getTileEntity(x, y, z), player);
|
||||
}
|
||||
else if (ID == UIScreens.THAUMIC_APIARY.ordinal())
|
||||
{
|
||||
TileEntityThaumicApiary tileEntityThaumicApiary = (TileEntityThaumicApiary) world.getTileEntity(x, y, z);
|
||||
value = new ContainerThaumicApiary(player.inventory, tileEntityThaumicApiary);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -33,7 +36,11 @@ public class GUIHandler implements IGuiHandler
|
||||
if (ID == UIScreens.EFFECT_JAR.ordinal())
|
||||
{
|
||||
value = new GUIEffectJar((TileEntityEffectJar)world.getTileEntity(x, y, z), player);
|
||||
}
|
||||
}else if (ID == UIScreens.THAUMIC_APIARY.ordinal())
|
||||
{
|
||||
TileEntityThaumicApiary tileEntityThaumicApiary = (TileEntityThaumicApiary) world.getTileEntity(x, y, z);
|
||||
value = new GuiThaumicApiary(player.inventory, tileEntityThaumicApiary);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.tileentity.TileEntityThaumicApiary;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiThaumicApiary extends GuiContainer
|
||||
{
|
||||
public static final ResourceLocation BACKGROUND_LOCATION = new ResourceLocation(CommonProxy.DOMAIN, CommonProxy.GUI_TEXTURE + "apiary.png");
|
||||
|
||||
private static final int WIDTH = 176;
|
||||
private static final int HEIGHT = 190;
|
||||
|
||||
public GuiThaumicApiary(InventoryPlayer inventoryPlayer, TileEntityThaumicApiary thaumicApiary) {
|
||||
super(new ContainerThaumicApiary(inventoryPlayer, thaumicApiary));
|
||||
|
||||
this.xSize = WIDTH;
|
||||
this.ySize = HEIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float opacity, int x, int y) {
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
this.mc.getTextureManager().bindTexture(BACKGROUND_LOCATION);
|
||||
|
||||
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package magicbees.client.gui;
|
||||
|
||||
import forestry.api.apiculture.IHiveFrame;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotFrame extends SlotCustomItems {
|
||||
public SlotFrame(IInventory inventory, int slotIndex, int xPos, int yPos) {
|
||||
super(inventory, slotIndex, xPos, yPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack){
|
||||
if (itemStack == null){
|
||||
return false;
|
||||
}
|
||||
if (!inventory.isItemValidForSlot(getSlotIndex(), itemStack)){
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean flag = false;
|
||||
|
||||
if(itemStack.getItem() instanceof IHiveFrame){
|
||||
flag = true;
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package magicbees.reference;
|
||||
|
||||
public class Names {
|
||||
public static final class Blocks
|
||||
{
|
||||
public static final String THAUMIC_APIARY = "thaumicApiary";
|
||||
}
|
||||
|
||||
public static final class Containers
|
||||
{
|
||||
public static final String THAUMIC_APIARY = "container.mb." + Blocks.THAUMIC_APIARY;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user