Merge remote-tracking branch 'origin/master'

This commit is contained in:
Drullkus committed 2015-01-07 22:33:52 -08:00
commit fc09e8f894
14 files changed
+261 -148

No files matched your search

@@ -3,10 +3,37 @@ package com.cricketcraft.chisel.api;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
public interface IFacade {
/**
* To be implemented on blocks that "hide" another block inside, so connected textuers can still be
* accomplished.
*/
public interface IFacade
{
/**
* Gets the block this facade is acting as.
*
* @param world {@link World}
* @param x X coord of your block
* @param y Y coord of your block
* @param z Z coord of your block
* @param side The side being rendered, NOT the side being connected from.
* <p>
* This value can be -1 if no side is specified. Please handle this appropriately.
* @return The block inside of your facade block.
*/
Block getFacade(IBlockAccess world, int x, int y, int z, int side);
int getFacadeMetadata(IBlockAccess world, int x, int y, int z, int side);
Block getFacade(IBlockAccess world, int x, int y, int z, int side);
}
/**
* Gets the metadata of the block that this facade is acting as.
*
* @param world {@link World}
* @param x X coord of your block
* @param y Y coord of your block
* @param z Z coord of your block
* @param side The side being rendered, NOT the side being connected from.
* <p>
* This value can be -1 if no side is specified. Please handle this appropriately.
* @return The metadata of your facade block.
*/
int getFacadeMetadata(IBlockAccess world, int x, int y, int z, int side);
}
@@ -1,9 +1,10 @@
package com.cricketcraft.chisel.block.tileentity;
import java.util.ArrayList;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -11,7 +12,9 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.init.ModItems;
import cpw.mods.fml.relauncher.Side;
@@ -19,8 +22,19 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
private final int BASE = 0, TARGET = 1, OUTPUT = 2, AUTOMATION = 3, STACK = 4, SPEED = 5;
private boolean isAutomated, isStackMode, isFaster;
public enum Upgrade {
SPEED, AUTOMATION, STACK;
public String getUnlocalizedName() {
return ModItems.upgrade.getUnlocalizedName() + "_" + this.name().toLowerCase();
}
public String getLocalizedName() {
return StatCollector.translateToLocal(getUnlocalizedName() + ".name");
}
}
private final int BASE = 0, TARGET = 1, OUTPUT = 2, MIN_UPGRADE = 3;
private static EntityItem ghostItem;
boolean equal = false;
private ItemStack[] inventory = new ItemStack[6];
@@ -72,81 +86,79 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public void updateEntity() {
if (inventory[SPEED] == new ItemStack(ModItems.upgrade, 1, 0)) {
isFaster = true;
} else {
isFaster = false;
}
int checkPeriod = hasUpgrade(Upgrade.SPEED) ? 10 : 40;
if (inventory[AUTOMATION] == new ItemStack(ModItems.upgrade, 1, 1)) {
isAutomated = true;
} else {
isAutomated = false;
}
ItemStack base = inventory[BASE], target = inventory[TARGET], output = inventory[OUTPUT];
if (inventory[STACK] == new ItemStack(ModItems.upgrade, 1, 2)) {
isStackMode = true;
} else {
isStackMode = false;
}
if (!worldObj.isRemote && worldObj.getWorldTime() % checkPeriod == 0) {
if (base != null && target != null) {
if (canBeMadeFrom(base, target)) {
// the max possible for this craft
int canBeMade = target.getMaxStackSize();
if (isFaster) {
if (!worldObj.isRemote && worldObj.getWorldTime() % 10 == 0) {
if (inventory[BASE] != null && inventory[TARGET] != null) {
if (inventory[BASE].getItem() instanceof ItemBlock && inventory[TARGET].getItem() instanceof ItemBlock) {
if (inventory[BASE].getUnlocalizedName().equalsIgnoreCase(inventory[TARGET].getUnlocalizedName())) {
if (isStackMode) {
if (inventory[BASE].stackSize == inventory[BASE].getMaxStackSize()) {
if (inventory[OUTPUT] == null) {
inventory[OUTPUT] = new ItemStack(inventory[TARGET].getItem(), 64, inventory[TARGET].getItemDamage());
inventory[BASE] = null;
}
}
} else {
if (inventory[OUTPUT] == null) {
inventory[OUTPUT] = new ItemStack(inventory[TARGET].getItem(), 1, inventory[TARGET].getItemDamage());
inventory[BASE].stackSize--;
} else if (inventory[BASE].stackSize != 0) {
inventory[OUTPUT].stackSize++;
inventory[BASE].stackSize--;
} else {
inventory[BASE] = null;
}
}
}
// if there are items in the output, they count towards the max we can make
if (output != null) {
canBeMade -= output.stackSize;
}
}
}
} else {
if (!worldObj.isRemote && worldObj.getWorldTime() % 40 == 0) {
if (inventory[BASE] != null && inventory[TARGET] != null) {
if (inventory[BASE].getItem() instanceof ItemBlock && inventory[TARGET].getItem() instanceof ItemBlock) {
if (inventory[BASE].getUnlocalizedName().equalsIgnoreCase(inventory[TARGET].getUnlocalizedName())) {
if (isStackMode) {
if (inventory[BASE].stackSize == inventory[BASE].getMaxStackSize()) {
if (inventory[OUTPUT] == null) {
inventory[OUTPUT] = new ItemStack(inventory[TARGET].getItem(), 64, inventory[TARGET].getItemDamage());
inventory[BASE] = null;
}
}
} else {
if (inventory[OUTPUT] == null) {
inventory[OUTPUT] = new ItemStack(inventory[TARGET].getItem(), 1, inventory[TARGET].getItemDamage());
inventory[BASE].stackSize--;
} else if (inventory[BASE].stackSize != 0) {
inventory[OUTPUT].stackSize++;
inventory[BASE].stackSize--;
} else {
inventory[BASE] = null;
}
}
// can't make more than we have
canBeMade = Math.min(base.stackSize, canBeMade);
// if we can't make any, forget it
if (canBeMade <= 0) {
return;
}
// result will always be a copy of the target, of course
ItemStack chiseled = target.copy();
// if we have the stack upgrade, boost the stack size to the max possible, otherwise just one
chiseled.stackSize = hasUpgrade(Upgrade.STACK) ? canBeMade : 1;
// if we can place the result in the output
if (canMerge(chiseled)) {
// if our output is empty, just use the current result
if (output == null) {
inventory[OUTPUT] = chiseled;
} else {
// otherwise just add our result to the existing stack
inventory[OUTPUT].stackSize += chiseled.stackSize;
}
// remove what we made from the stack
base.stackSize -= chiseled.stackSize;
if (base.stackSize <= 0) {
inventory[BASE] = null; // clear out 0 size itemstacks
}
// we changed something, so we need to tell the chunk to save
markDirty();
}
}
}
}
}
markDirty();
// lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target
private boolean canBeMadeFrom(ItemStack from, ItemStack to) {
ArrayList<ItemStack> results = Carving.chisel.getItems(from);
for (ItemStack s : results) {
if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) {
return true;
}
}
return false;
}
private boolean canMerge(ItemStack toMerge) {
// if the output slot is empty we can merge without checking
if (inventory[OUTPUT] == null) {
return true;
}
// need to check NBT as well as item
if (toMerge.isItemEqual(inventory[OUTPUT]) && ItemStack.areItemStackTagsEqual(toMerge, inventory[OUTPUT])) {
// we only care about metadata if the item has subtypes
return toMerge.getHasSubtypes() && toMerge.getItemDamage() == inventory[OUTPUT].getItemDamage();
}
return false;
}
@Override
@@ -232,7 +244,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
if (isAutomated) {
if (hasUpgrade(Upgrade.AUTOMATION)) {
if (side != 0 || side != 1 && slot == BASE) {
return true;
}
@@ -242,7 +254,7 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
@Override
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
if (isAutomated) {
if (hasUpgrade(Upgrade.AUTOMATION)) {
if (side == 0 || side == 1 && slot == OUTPUT) {
return true;
}
@@ -286,4 +298,12 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readFromNBT(packet.func_148857_g());
}
public boolean hasUpgrade(Upgrade upgrade) {
ItemStack stack = inventory[MIN_UPGRADE + upgrade.ordinal()];
if (stack != null) {
return stack.getItem() == ModItems.upgrade && stack.getItemDamage() == upgrade.ordinal();
}
return false;
}
}
@@ -208,8 +208,8 @@ public class CarvableHelper {
return variation.iconTop;
Block block = world.getBlock(x, y, z);
boolean topConnected = block.equals(CTM.getBlockOrFacade(world, x, y + 1, z, side)) && metadata == CTM.getBlockOrFacadeMetadata(world, x, y + 1, z, side);
boolean botConnected = block.equals(CTM.getBlockOrFacade(world, x, y - 1, z, side)) && metadata == CTM.getBlockOrFacadeMetadata(world, x, y - 1, z, side);
boolean topConnected = CTM.isConnected(world, x, y + 1, z, side, block, metadata);
boolean botConnected = CTM.isConnected(world, x, y - 1, z, side, block, metadata);
if (topConnected && botConnected)
return variation.seamsCtmVert.icons[2];
@@ -230,11 +230,11 @@ public class CarvableHelper {
boolean reverse = side == 2 || side == 4;
if (side < 4) {
p = isSame(world, x - 1, y, z, block, metadata, side);
n = isSame(world, x + 1, y, z, block, metadata, side);
p = CTM.isConnected(world, x - 1, y, z, side, block, metadata);
n = CTM.isConnected(world, x + 1, y, z, side, block, metadata);
} else {
p = isSame(world, x, y, z + 1, block, metadata, side);
n = isSame(world, x, y, z - 1, block, metadata, side);
p = CTM.isConnected(world, x, y, z - 1, side, block, metadata);
n = CTM.isConnected(world, x, y, z + 1, side, block, metadata);
}
if (p && n)
@@ -381,10 +381,6 @@ public class CarvableHelper {
}
}
private boolean isSame(IBlockAccess world, int x, int y, int z, Block block, int meta, int side) {
return CTM.getBlockOrFacade(world, x, y, z, side).equals(block) && CTM.getBlockOrFacadeMetadata(world, x, y, z, side) == meta;
}
public void setChiselBlockName(String name) {
blockName = name;
}
@@ -1,13 +1,19 @@
package com.cricketcraft.chisel.client.gui;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel.SlotUpgrade;
import com.google.common.collect.Lists;
public class GuiAutoChisel extends GuiContainer {
@@ -17,6 +23,29 @@ public class GuiAutoChisel extends GuiContainer {
super(new ContainerAutoChisel(inventoryPlayer, tileEntityAutoChisel));
}
@SuppressWarnings("unchecked")
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
int x = (this.width - this.xSize) / 2;
int y = (this.height - this.ySize) / 2;
for (Slot slot : (List<Slot>) inventorySlots.inventorySlots) {
if (mouseInside(slot, mouseX - x, mouseY - y)) {
if (slot instanceof SlotUpgrade) {
this.func_146283_a(Lists.newArrayList(((SlotUpgrade) slot).upgradeType.getLocalizedName()), mouseX - x, mouseY - y);
} else if (slot.slotNumber == 1) {
this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal("autochisel.slot.target.tooltip")), mouseX - x, mouseY - y);
}
}
}
}
private boolean mouseInside(Slot slot, int x, int y) {
return x >= slot.xDisplayPosition && x <= slot.xDisplayPosition + 16 && y >= slot.yDisplayPosition && y <= slot.yDisplayPosition + 16;
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -2,6 +2,7 @@ package com.cricketcraft.chisel.client.render;
import net.minecraft.block.Block;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import com.cricketcraft.chisel.api.IFacade;
@@ -187,34 +188,16 @@ public class CTM {
return texture;
}
protected static boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) {
int x2 = x, y2 = y, z2 = z;
public static boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, int meta) {
switch (side) {
case 0:
y2--;
break;
case 1:
y2++;
break;
case 2:
z2--;
break;
case 3:
z2++;
break;
case 4:
x2--;
break;
case 5:
x2++;
break;
}
if (getBlockOrFacade(world, x2, y2, z2, side) == null || getBlockOrFacade(world, x, y, z, side) == null || block == null)
return false;
ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[side];
int x2 = x + dir.offsetX;
int y2 = y + dir.offsetY;
int z2 = z + dir.offsetZ;
return getBlockOrFacade(world, x, y, z, side).equals(block) && getBlockOrFacadeMetadata(world, x, y, z, side) == meta
&& (!getBlockOrFacade(world, x2, y2, z2, side).equals(block) || getBlockOrFacadeMetadata(world, x2, y2, z2, side) != meta);
&& !(getBlockOrFacade(world, x2, y2, z2, side).equals(block) && getBlockOrFacadeMetadata(world, x2, y2, z2, side) == meta);
}
public static int getBlockOrFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) {
@@ -16,7 +16,7 @@ public class RenderBlocksColumn extends RenderBlocks {
}
boolean connected(IBlockAccess world, int x, int y, int z, Block block, int meta) {
return world.getBlock(x, y, z).equals(block) && world.getBlockMetadata(x, y, z) == meta;
return CTM.getBlockOrFacade(world, x, y, z, -1).equals(block) && CTM.getBlockOrFacadeMetadata(world, x, y, z, -1) == meta;
}
@Override
@@ -7,9 +7,26 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel.Upgrade;
import com.cricketcraft.chisel.init.ModItems;
public class ContainerAutoChisel extends Container {
public static class SlotUpgrade extends Slot {
public Upgrade upgradeType;
public SlotUpgrade(TileEntityAutoChisel inv, int id, int x, int y, Upgrade upgrade) {
super(inv, id, x, y);
this.upgradeType = upgrade;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() == ModItems.upgrade && stack.getItemDamage() == upgradeType.ordinal();
}
}
public static TileEntityAutoChisel autoChisel;
public static EntityPlayer player;
@@ -21,9 +38,9 @@ public class ContainerAutoChisel extends Container {
addSlotToContainer(new Slot(tileEntityAutoChisel, 0, 53, 15));
addSlotToContainer(new Slot(tileEntityAutoChisel, 1, 78, 51));
addSlotToContainer(new Slot(tileEntityAutoChisel, 2, 103, 15));
addSlotToContainer(new Slot(tileEntityAutoChisel, 3, 151, 51));
addSlotToContainer(new Slot(tileEntityAutoChisel, 4, 151, 31));
addSlotToContainer(new Slot(tileEntityAutoChisel, 5, 151, 11));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 3, 151, 11, Upgrade.SPEED));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 4, 151, 31, Upgrade.AUTOMATION));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 5, 151, 51, Upgrade.STACK));
bindPlayerInventory(player);
}
@@ -49,29 +66,33 @@ public class ContainerAutoChisel extends Container {
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
ItemStack itemStack = null;
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
System.out.println(slotNumber);
if (slot != null && slot.getHasStack()) {
ItemStack itemStack1 = slot.getStack();
itemStack = itemStack1.copy();
if (slotNumber == 2) {
if (!this.mergeItemStack(itemStack1, 3, 39, true)) {
return null;
}
slot.onSlotChange(itemStack1, itemStack);
} else if (slotNumber != 1 && slotNumber != 0) {
if (!this.mergeItemStack(itemStack1, 0, 1, true)) {
return null;
} else if (slotNumber >= 3 && slotNumber < 30) {
if (this.mergeItemStack(itemStack1, 30, 39, false)) {
// if we are in the auto chisel
if (slotNumber <= 5) {
// merge hotbar
if (!this.mergeItemStack(itemStack1, 33, 42, false)) {
// merge rest of inventory
if (!this.mergeItemStack(itemStack1, 6, 33, false)) {
return null;
}
}
} else {
// if this is an upgrade, check the upgrade slots
if (itemStack1.getItem() == ModItems.upgrade) {
if (!this.mergeItemStack(itemStack1, 3, 6, false)) {
return null;
}
} else {
// otherwise just put it in one of the 3 other slots
if (!this.mergeItemStack(itemStack1, 1, 3, false)) {
return null;
}
} else if (slotNumber >= 30 && slotNumber < 39 && !this.mergeItemStack(itemStack1, 3, 30, false)) {
return null;
}
} else if (this.mergeItemStack(itemStack1, 3, 39, false)) {
return null;
}
if (itemStack1.stackSize == 0) {
@@ -88,8 +88,51 @@ public class ContainerChisel extends Container {
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entity, int i) {
return null;
public ItemStack transferStackInSlot(EntityPlayer entity, int slotIdx) {
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(slotIdx);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (slotIdx > 24) {
if (!this.mergeItemStack(itemstack1, 24, 25, false)) {
return null;
}
} else {
if (slotIdx < 24 && itemstack1 != null) {
entity.inventory.setItemStack(itemstack1.copy());
slot.onPickupFromSlot(entity, itemstack1);
itemstack1 = entity.inventory.getItemStack();
entity.inventory.setItemStack(null);
}
if (!this.mergeItemStack(itemstack1, 52, 61, false)) {
if (!this.mergeItemStack(itemstack1, 25, 52, false)) {
return null;
}
}
}
slot.onSlotChange(itemstack1, itemstack);
if (itemstack1.stackSize == 0) {
slot.putStack((ItemStack) null);
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize) {
return null;
}
if (slotIdx >= 24) {
slot.onPickupFromSlot(entity, itemstack1);
}
if (itemstack1.stackSize == 0) {
slot.putStack(null);
return null;
}
}
return itemstack;
}
public void onChiselSlotChanged() {
@@ -13,6 +13,7 @@ import net.minecraft.world.World;
import com.cricketcraft.chisel.Chisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel.Upgrade;
public class ItemUpgrade extends BaseItem {
@@ -22,6 +23,7 @@ public class ItemUpgrade extends BaseItem {
super();
this.setUnlocalizedName(unlocalizedName);
this.setCreativeTab(CreativeTabs.tabMaterials);
setHasSubtypes(true);
}
@Override
@@ -36,16 +38,15 @@ public class ItemUpgrade extends BaseItem {
@Override
public IIcon getIconFromDamage(int meta) {
if (meta > 3)
meta = 0;
return this.icons[meta];
// using modulo throughout to prevent AIOB
return this.icons[meta % Upgrade.values().length];
}
@Override
public void registerIcons(IIconRegister reg) {
for (int i = 0; i < 3; i++) {
this.icons[i] = reg.registerIcon(Chisel.MOD_ID + ":upgradeItem_" + i);
Upgrade[] upgrades = Upgrade.values();
for (int i = 0; i < upgrades.length; i++) {
this.icons[i] = reg.registerIcon(Chisel.MOD_ID + ":upgrade_" + upgrades[i].name().toLowerCase());
}
}
@@ -59,15 +60,7 @@ public class ItemUpgrade extends BaseItem {
@Override
public String getUnlocalizedName(ItemStack stack) {
switch (stack.getItemDamage()) {
case 0:
return this.getUnlocalizedName() + "_speed";
case 1:
return this.getUnlocalizedName() + "_automation";
case 2:
return this.getUnlocalizedName() + "_stack";
default:
return this.getUnlocalizedName();
}
Upgrade[] upgrades = Upgrade.values();
return upgrades[stack.getItemDamage() % upgrades.length].getUnlocalizedName();
}
}