Skip to content

Commit

Permalink
Added new brewing stand mechanics. Need to find out a way to replace …
Browse files Browse the repository at this point in the history
…them in world still
  • Loading branch information
ganymedes01 committed Oct 15, 2015
1 parent 79a3c69 commit 1954099
Show file tree
Hide file tree
Showing 11 changed files with 579 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/ganymedes01/etfuturum/EtFuturum.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public Item getTabIconItem() {
public static boolean enableElytra = true;
public static boolean enableFrostWalker = true;
public static boolean enableMending = true;
public static boolean enableBrewingStands = true;

public static int maxStonesPerCluster = 33;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ganymedes01/etfuturum/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ganymedes01.etfuturum.blocks.GrassPath;
import ganymedes01.etfuturum.blocks.InvertedDaylightDetector;
import ganymedes01.etfuturum.blocks.IronTrapdoor;
import ganymedes01.etfuturum.blocks.NewBrewingStand;
import ganymedes01.etfuturum.blocks.OldGravel;
import ganymedes01.etfuturum.blocks.PrismarineBlocks;
import ganymedes01.etfuturum.blocks.PurpurBlock;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class ModBlocks {
public static final Block chorus_flower = new ChorusFlower();
public static final Block crying_obsidian = new CryingObsidian();
public static final Block frosted_ice = new FrostedIce();
public static final Block brewing_stand = new NewBrewingStand();

public static final Block[] doors = new Block[BlockWood.field_150096_a.length - 1];
public static final Block[] fences = new Block[BlockWood.field_150096_a.length];
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/ganymedes01/etfuturum/blocks/NewBrewingStand.java
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();
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void syncConfigs() {
EtFuturum.enableFrostWalker = configBoolean("Frost Walker", true, EtFuturum.enableFrostWalker);
FrostWalker.ID = configInteger("Frost Walker ID", true, FrostWalker.ID);
Mending.ID = configInteger("Mending ID", true, Mending.ID);
EtFuturum.enableBrewingStands = configBoolean("Brewing Stands", true, EtFuturum.enableBrewingStands);

EtFuturum.maxStonesPerCluster = configInteger("Max number of 1.8 stones in a cluster", true, EtFuturum.maxStonesPerCluster);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.client.gui.inventory.GuiAnvil;
import ganymedes01.etfuturum.client.gui.inventory.GuiEnchantment;
import ganymedes01.etfuturum.client.gui.inventory.GuiNewBrewingStand;
import ganymedes01.etfuturum.configuration.ConfigurationHandler;
import ganymedes01.etfuturum.core.handlers.ServerEventHandler;
import ganymedes01.etfuturum.core.utils.Utils;
Expand All @@ -16,9 +17,11 @@
import ganymedes01.etfuturum.entities.ModEntityList;
import ganymedes01.etfuturum.inventory.ContainerAnvil;
import ganymedes01.etfuturum.inventory.ContainerEnchantment;
import ganymedes01.etfuturum.inventory.ContainerNewBrewingStand;
import ganymedes01.etfuturum.lib.GUIsID;
import ganymedes01.etfuturum.tileentities.TileEntityBanner;
import ganymedes01.etfuturum.tileentities.TileEntityEndRod;
import ganymedes01.etfuturum.tileentities.TileEntityNewBrewingStand;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -53,6 +56,8 @@ public void registerEntities() {
GameRegistry.registerTileEntity(TileEntityEndRod.class, Utils.getUnlocalisedName("end_rod"));
if (EtFuturum.enableTippedArrows)
ModEntityList.registerEntity(EntityTippedArrow.class, "tipped_arrow", 2, EtFuturum.instance, 64, 20, true);
if (EtFuturum.enableBrewingStands)
GameRegistry.registerTileEntity(TileEntityNewBrewingStand.class, Utils.getUnlocalisedName("brewing_stand"));

if (EtFuturum.enableRabbit) {
ModEntityList.registerEntity(EntityRabbit.class, "rabbit", 3, EtFuturum.instance, 80, 3, true, 10051392, 7555121);
Expand Down Expand Up @@ -92,6 +97,8 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int
return new ContainerEnchantment(player.inventory, world, x, y, z);
case GUIsID.ANVIL:
return new ContainerAnvil(player, world, x, y, z);
case GUIsID.BREWING_STAND:
return new ContainerNewBrewingStand(player.inventory, (TileEntityNewBrewingStand) world.getTileEntity(x, y, z));
default:
return null;
}
Expand All @@ -104,6 +111,8 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
return new GuiEnchantment(player.inventory, world, null);
case GUIsID.ANVIL:
return new GuiAnvil(player, world, x, y, z);
case GUIsID.BREWING_STAND:
return new GuiNewBrewingStand(player.inventory, (TileEntityNewBrewingStand) world.getTileEntity(x, y, z));
default:
return null;
}
Expand Down
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);
}
}
}
Loading

0 comments on commit 1954099

Please sign in to comment.