forked from KryptonCaptain/Et-Futurum
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new brewing stand mechanics. Need to find out a way to replace …
…them in world still
- Loading branch information
ganymedes01
committed
Oct 15, 2015
1 parent
79a3c69
commit 1954099
Showing
11 changed files
with
579 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
48 changes: 48 additions & 0 deletions
48
src/main/java/ganymedes01/etfuturum/blocks/NewBrewingStand.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ganymedes01.etfuturum.blocks; | ||
|
||
import ganymedes01.etfuturum.EtFuturum; | ||
import ganymedes01.etfuturum.core.utils.Utils; | ||
import ganymedes01.etfuturum.lib.GUIsID; | ||
import ganymedes01.etfuturum.tileentities.TileEntityNewBrewingStand; | ||
import net.minecraft.block.BlockBrewingStand; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.tileentity.TileEntityBrewingStand; | ||
import net.minecraft.world.World; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
|
||
public class NewBrewingStand extends BlockBrewingStand { | ||
|
||
public NewBrewingStand() { | ||
setHardness(0.5F); | ||
setLightLevel(0.125F); | ||
setBlockTextureName("brewing_stand"); | ||
setBlockName(Utils.getUnlocalisedName("brewing_stand")); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { | ||
if (world.isRemote) | ||
return true; | ||
else { | ||
TileEntityBrewingStand tile = (TileEntityBrewingStand) world.getTileEntity(x, y, z); | ||
if (tile != null) | ||
player.openGui(EtFuturum.instance, GUIsID.BREWING_STAND, world, x, y, z); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public Item getItem(World world, int x, int y, int z) { | ||
return Item.getItemFromBlock(this); | ||
} | ||
|
||
@Override | ||
public TileEntity createNewTileEntity(World world, int meta) { | ||
return new TileEntityNewBrewingStand(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/ganymedes01/etfuturum/client/gui/inventory/GuiNewBrewingStand.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package ganymedes01.etfuturum.client.gui.inventory; | ||
|
||
import ganymedes01.etfuturum.core.utils.Utils; | ||
import ganymedes01.etfuturum.inventory.ContainerNewBrewingStand; | ||
import ganymedes01.etfuturum.lib.Reference; | ||
import ganymedes01.etfuturum.tileentities.TileEntityNewBrewingStand; | ||
import net.minecraft.client.gui.inventory.GuiContainer; | ||
import net.minecraft.client.resources.I18n; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import org.lwjgl.opengl.GL11; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class GuiNewBrewingStand extends GuiContainer { | ||
|
||
private static final ResourceLocation TEXTURE = Utils.getResource(Reference.MOD_ID + ":textures/gui/container/brewing_stand.png"); | ||
private TileEntityNewBrewingStand tile; | ||
|
||
public GuiNewBrewingStand(InventoryPlayer playerInvt, TileEntityNewBrewingStand tile) { | ||
super(new ContainerNewBrewingStand(playerInvt, tile)); | ||
this.tile = tile; | ||
} | ||
|
||
@Override | ||
protected void drawGuiContainerForegroundLayer(int x, int y) { | ||
String s = tile.hasCustomInventoryName() ? tile.getInventoryName() : I18n.format(tile.getInventoryName()); | ||
fontRendererObj.drawString(s, xSize / 2 - fontRendererObj.getStringWidth(s) / 2, 6, 4210752); | ||
fontRendererObj.drawString(I18n.format("container.inventory"), 8, ySize - 96 + 2, 4210752); | ||
} | ||
|
||
@Override | ||
protected void drawGuiContainerBackgroundLayer(float f0, int x, int y) { | ||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); | ||
mc.getTextureManager().bindTexture(TEXTURE); | ||
int k = (width - xSize) / 2; | ||
int l = (height - ySize) / 2; | ||
drawTexturedModalRect(k, l, 0, 0, xSize, ySize); | ||
int i1 = tile.getBrewTime(); | ||
|
||
if (i1 > 0) { | ||
int j1 = (int) (28.0F * (1.0F - i1 / 400.0F)); | ||
|
||
if (j1 > 0) | ||
drawTexturedModalRect(k + 97, l + 16, 176, 0, 9, j1); | ||
|
||
int k1 = i1 / 2 % 7; | ||
|
||
switch (k1) { | ||
case 0: | ||
j1 = 29; | ||
break; | ||
case 1: | ||
j1 = 24; | ||
break; | ||
case 2: | ||
j1 = 20; | ||
break; | ||
case 3: | ||
j1 = 16; | ||
break; | ||
case 4: | ||
j1 = 11; | ||
break; | ||
case 5: | ||
j1 = 6; | ||
break; | ||
case 6: | ||
j1 = 0; | ||
} | ||
|
||
if (j1 > 0) | ||
drawTexturedModalRect(k + 65, l + 14 + 29 - j1, 185, 29 - j1, 12, j1); | ||
} | ||
|
||
int fuel = tile.getFuel(); | ||
if (fuel > 0) { | ||
int size = (int) (18 * (fuel / 30F)); | ||
drawTexturedModalRect(k + 60, l + 44, 176, 29, size, 4); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
173 changes: 173 additions & 0 deletions
173
src/main/java/ganymedes01/etfuturum/inventory/ContainerNewBrewingStand.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package ganymedes01.etfuturum.inventory; | ||
|
||
import ganymedes01.etfuturum.tileentities.TileEntityNewBrewingStand; | ||
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.ICrafting; | ||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.inventory.Slot; | ||
import net.minecraft.item.ItemPotion; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.stats.AchievementList; | ||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
|
||
public class ContainerNewBrewingStand extends Container { | ||
|
||
private TileEntityNewBrewingStand tile; | ||
private final Slot ingredientSlot; | ||
private int prevBrewTime, prevFuel; | ||
|
||
public ContainerNewBrewingStand(InventoryPlayer playerInvt, TileEntityNewBrewingStand tile) { | ||
this.tile = tile; | ||
addSlotToContainer(new PotionSlot(tile, 0, 56, 51)); | ||
addSlotToContainer(new PotionSlot(tile, 1, 79, 58)); | ||
addSlotToContainer(new PotionSlot(tile, 2, 102, 51)); | ||
ingredientSlot = addSlotToContainer(new IngredientSlot(tile, 3, 79, 17)); | ||
addSlotToContainer(new BlazePowderSlot(tile, 4, 17, 17)); | ||
|
||
for (int i = 0; i < 3; i++) | ||
for (int j = 0; j < 9; j++) | ||
addSlotToContainer(new Slot(playerInvt, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); | ||
|
||
for (int i = 0; i < 9; i++) | ||
addSlotToContainer(new Slot(playerInvt, i, 8 + i * 18, 142)); | ||
} | ||
|
||
@Override | ||
public void addCraftingToCrafters(ICrafting crafting) { | ||
super.addCraftingToCrafters(crafting); | ||
crafting.sendProgressBarUpdate(this, 0, tile.getBrewTime()); | ||
crafting.sendProgressBarUpdate(this, 1, tile.getFuel()); | ||
} | ||
|
||
@Override | ||
public void detectAndSendChanges() { | ||
super.detectAndSendChanges(); | ||
|
||
for (int i = 0; i < crafters.size(); i++) { | ||
ICrafting icrafting = (ICrafting) crafters.get(i); | ||
|
||
if (prevBrewTime != tile.getBrewTime()) | ||
icrafting.sendProgressBarUpdate(this, 0, tile.getBrewTime()); | ||
if (prevFuel != tile.getFuel()) | ||
icrafting.sendProgressBarUpdate(this, 1, tile.getFuel()); | ||
} | ||
prevBrewTime = tile.getBrewTime(); | ||
prevFuel = tile.getFuel(); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void updateProgressBar(int id, int value) { | ||
if (id == 0) | ||
tile.func_145938_d(value); | ||
else if (id == 1) | ||
tile.setFuel(value); | ||
} | ||
|
||
@Override | ||
public boolean canInteractWith(EntityPlayer player) { | ||
return tile.isUseableByPlayer(player); | ||
} | ||
|
||
@Override | ||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) { | ||
ItemStack itemstack = null; | ||
Slot slot = (Slot) inventorySlots.get(slotIndex); | ||
|
||
if (slot != null && slot.getHasStack()) { | ||
ItemStack itemstack1 = slot.getStack(); | ||
itemstack = itemstack1.copy(); | ||
|
||
if ((slotIndex < 0 || slotIndex > 2) && slotIndex != 3) { | ||
if (!ingredientSlot.getHasStack() && ingredientSlot.isItemValid(itemstack1)) { | ||
if (!mergeItemStack(itemstack1, 3, 4, false)) | ||
return null; | ||
} else if (PotionSlot.canHoldPotion(itemstack)) { | ||
if (!mergeItemStack(itemstack1, 0, 3, false)) | ||
return null; | ||
} else if (slotIndex >= 4 && slotIndex < 31) { | ||
if (!mergeItemStack(itemstack1, 31, 40, false)) | ||
return null; | ||
} else if (slotIndex >= 31 && slotIndex < 40) { | ||
if (!mergeItemStack(itemstack1, 4, 31, false)) | ||
return null; | ||
} else if (!mergeItemStack(itemstack1, 4, 40, false)) | ||
return null; | ||
} else { | ||
if (!mergeItemStack(itemstack1, 4, 40, true)) | ||
return null; | ||
|
||
slot.onSlotChange(itemstack1, itemstack); | ||
} | ||
|
||
if (itemstack1.stackSize == 0) | ||
slot.putStack((ItemStack) null); | ||
else | ||
slot.onSlotChanged(); | ||
|
||
if (itemstack1.stackSize == itemstack.stackSize) | ||
return null; | ||
|
||
slot.onPickupFromSlot(player, itemstack1); | ||
} | ||
|
||
return itemstack; | ||
} | ||
|
||
class BlazePowderSlot extends Slot { | ||
|
||
public BlazePowderSlot(IInventory inventory, int index, int x, int y) { | ||
super(inventory, index, x, y); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(ItemStack stack) { | ||
return stack != null && stack.getItem() == Items.blaze_powder; | ||
} | ||
} | ||
|
||
class IngredientSlot extends Slot { | ||
|
||
public IngredientSlot(IInventory inventory, int index, int x, int y) { | ||
super(inventory, index, x, y); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(ItemStack stack) { | ||
return stack != null && stack.getItem().isPotionIngredient(stack); | ||
} | ||
} | ||
|
||
static class PotionSlot extends Slot { | ||
|
||
public PotionSlot(IInventory inventory, int index, int x, int y) { | ||
super(inventory, index, x, y); | ||
} | ||
|
||
@Override | ||
public boolean isItemValid(ItemStack stack) { | ||
return canHoldPotion(stack); | ||
} | ||
|
||
@Override | ||
public int getSlotStackLimit() { | ||
return 1; | ||
} | ||
|
||
@Override | ||
public void onPickupFromSlot(EntityPlayer player, ItemStack stack) { | ||
if (stack.getItem() instanceof ItemPotion && stack.getItemDamage() > 0) | ||
player.addStat(AchievementList.potion, 1); | ||
|
||
super.onPickupFromSlot(player, stack); | ||
} | ||
|
||
public static boolean canHoldPotion(ItemStack stack) { | ||
return stack != null && (stack.getItem() instanceof ItemPotion || stack.getItem() == Items.glass_bottle); | ||
} | ||
} | ||
} |
Oops, something went wrong.