Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GuiArcFurnace extends GuiContainer {
- private static final ResourceLocation TEXTURES = new ResourceLocation(Exkva.MODID + ":textures/gui/arc_furnace.png");
- private final InventoryPlayer player;
- private final TileEntityArcFurnace tileentity;
- public GuiArcFurnace(InventoryPlayer player, TileEntityArcFurnace tileentity) {
- super(new ContainerArcFurnace(player, tileentity));
- this.player = player;
- this.tileentity = tileentity;
- }
- @Override
- protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
- String tileName = this.tileentity.getBlockType().getLocalizedName();
- this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) + 3, 8, 4210752);
- this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
- }
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks){
- this.drawDefaultBackground();
- super.drawScreen(mouseX, mouseY, partialTicks);
- this.renderHoveredToolTip(mouseX, mouseY);
- }
- @Override
- protected void drawGuiContainerBackgroundLayer(float v, int i, int i1) {
- GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
- this.mc.getTextureManager().bindTexture(TEXTURES);
- this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
- int progressMax = getRefineProgressScaled();
- this.drawTexturedModalRect(82, 33, 176, 14, progressMax, 17);
- }
- private int getRefineProgressScaled() {
- int progress = tileentity.getActiveTime();
- int end = tileentity.getRefineTime();
- System.out.println(progress + " " + end);
- return (progress / end) * 34;
- }
- }
- public class TileEntityArcFurnace extends TileEntity implements ITickable {
- private static final int IN1 = 0;
- private static final int IN2 = 1;
- private static final int IN3 = 2;
- private static final int FUEL = 3;
- private static final int OUT = 4;
- protected final ItemStackHandler inventory = new ItemStackHandler(5) {
- public ItemStack insertItem(int index, ItemStack stack, boolean simulate) {
- if(isItemValid(index, stack)) {
- return super.insertItem(index, stack, simulate);
- }
- return stack;
- }
- public boolean isItemValid(int index, ItemStack stack) {
- if(index == 4) {
- return false;
- } else if(index != 3) {
- return true;
- } else {
- return TileEntityFurnace.isItemFuel(stack);
- }
- }
- };
- private boolean active;
- private int activeTime;
- @Override
- public NBTTagCompound getUpdateTag() {
- NBTTagCompound tagCompound = new NBTTagCompound();
- tagCompound.setInteger("time_active", activeTime);
- return tagCompound;
- }
- @Override
- public void handleUpdateTag(NBTTagCompound tag) {
- this.activeTime = tag.getInteger("time_active");
- }
- @Override
- public void update() {
- if(world.isRemote) { return; }
- if(this.canRefine() && !this.isActive()) {
- this.activeTime = 0;
- this.active = true;
- world.setBlockState(pos, world.getBlockState(pos).withProperty(MachineArcFurnace.ACTIVE, true));
- }
- if(inventory.getStackInSlot(IN1).isEmpty() && inventory.getStackInSlot(IN2).isEmpty() && inventory.getStackInSlot(IN3).isEmpty()) {
- this.activeTime = 0;
- this.active = false;
- world.setBlockState(pos, world.getBlockState(pos).withProperty(MachineArcFurnace.ACTIVE, false));
- }
- if(this.isActive()) {
- this.activeTime++;
- if(this.activeTime == this.getRefineTime()) {
- this.refineItem();
- this.activeTime = 0;
- this.active = false;
- world.setBlockState(pos, world.getBlockState(pos).withProperty(MachineArcFurnace.ACTIVE, false));
- }
- } else {
- this.active = false;
- this.activeTime = 0;
- }
- markDirty();
- }
- public void refineItem() {
- ItemStack[] in = { inventory.getStackInSlot(IN1), inventory.getStackInSlot(IN2), inventory.getStackInSlot(IN3) };
- ItemStack out = getResult();
- ItemStack currentOut = inventory.getStackInSlot(OUT);
- if(currentOut.isEmpty()) {
- inventory.setStackInSlot(OUT, out);
- } else if(ItemHandlerHelper.canItemStacksStack(currentOut, out)) {
- currentOut.grow(out.getCount());
- }
- for(ItemStack i : in) {
- i.shrink(1);
- }
- markDirty();
- }
- @Override
- public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
- return (oldState.getBlock() != newState.getBlock());
- }
- public int getActiveTime() {
- return this.activeTime;
- }
- public int getRefineTime() {
- return 200;
- }
- public ItemStackHandler getInventory() {
- return inventory;
- }
- public boolean isActive() {
- return active;
- }
- protected boolean canRefine() {
- return inventory.getStackInSlot(OUT).isEmpty() && !this.getResult().isEmpty();
- }
- @Override
- public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
- if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return true; }
- return super.hasCapability(capability, facing);
- }
- private ItemStack getResult() {
- ItemStack[] in = { inventory.getStackInSlot(IN1), inventory.getStackInSlot(IN2), inventory.getStackInSlot(IN3) };
- for(RecipeArcFurnace recipe : Exkva.ARC_FURNACE_RECIPES) {
- if(recipe.matches(in)) {
- return (recipe.getOutput().copy());
- }
- }
- return ItemStack.EMPTY;
- }
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- inventory.deserializeNBT(compound.getCompoundTag("inv"));
- activeTime = compound.getInteger("active_time");
- }
- @Override
- public NBTTagCompound writeToNBT(NBTTagCompound compound) {
- compound = super.writeToNBT(compound);
- compound.setTag("inv", inventory.serializeNBT());
- compound.setInteger("active", activeTime);
- return compound;
- }
- @Override
- public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
- return super.getCapability(capability, facing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement