Iron furnace accumulates and drops experience. Closes #1817

This commit is contained in:
drcrazy 2019-08-29 02:43:39 +03:00
parent 528b868abe
commit fbfa24b6ff
4 changed files with 116 additions and 28 deletions

View file

@ -28,6 +28,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.Direction;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
@ -46,11 +47,10 @@ import techreborn.init.TRContent;
public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
implements IToolDrop, InventoryProvider, IContainerProvider {
public int tickTime;
public RebornInventory<IronAlloyFurnaceBlockEntity> inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this);
public int burnTime;
public int totalBurnTime;
public int cookTime;
public int progress;
int input1 = 0;
int input2 = 1;
int output = 2;
@ -73,6 +73,23 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
return AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(stack.getItem(), 0);
}
@Override
public void fromTag(CompoundTag compoundTag) {
super.fromTag(compoundTag);
burnTime = compoundTag.getInt("BurnTime");
totalBurnTime = compoundTag.getInt("TotalBurnTime");
progress = compoundTag.getInt("Progress");
}
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}
@Override
public void tick() {
super.tick();
@ -96,14 +113,14 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
}
}
if (isBurning() && canSmelt()) {
++cookTime;
if (cookTime == 200) {
cookTime = 0;
++progress;
if (progress == 200) {
progress = 0;
smeltItem();
updateInventory = true;
}
} else {
cookTime = 0;
progress = 0;
}
}
if (isBurning != isBurning()) {
@ -212,7 +229,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
}
public int getCookProgressScaled(int scale) {
return cookTime * scale / 200;
return progress * scale / 200;
}
public void updateState() {
@ -256,11 +273,11 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity
}
public int getCookTime() {
return cookTime;
return progress;
}
public void setCookTime(int cookTime) {
this.cookTime = cookTime;
this.progress = cookTime;
}
@Override

View file

@ -50,7 +50,6 @@ import techreborn.utils.RecipeUtils;
public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
implements InventoryProvider, IContainerProvider {
public int tickTime;
public RebornInventory<IronFurnaceBlockEntity> inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess());
public int burnTime;
public int totalBurnTime;
@ -179,12 +178,18 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
public void fromTag(CompoundTag compoundTag) {
super.fromTag(compoundTag);
experience = compoundTag.getFloat("Experience");
burnTime = compoundTag.getInt("BurnTime");
totalBurnTime = compoundTag.getInt("TotalBurnTime");
progress = compoundTag.getInt("Progress");
}
@Override
public CompoundTag toTag(CompoundTag compoundTag) {
super.toTag(compoundTag);
compoundTag.putFloat("Experience", experience);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}

View file

@ -25,13 +25,14 @@
package techreborn.client.gui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonSimple;
@ -39,6 +40,7 @@ import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.common.network.NetworkManager;
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
import techreborn.packets.ServerboundPackets;
import techreborn.utils.PlayerUtils;
public class GuiIronFurnace extends GuiBase<BuiltContainer> {
@ -56,16 +58,48 @@ public class GuiIronFurnace extends GuiBase<BuiltContainer> {
@Override
public void init() {
super.init();
addButton(new GuiButtonSimple(getGuiLeft() + 116, getGuiTop() + 57, 18, 18, "Exp", b -> onClick()) {
addButton(new GuiButtonSimple(getGuiLeft() + 116, getGuiTop() + 57, 18, 18, "", b -> onClick()) {
@Override
public void renderToolTip(int mouseX, int mouseY) {
PlayerEntity player = playerInventory.player;
if (player == null) {
return;
}
String message = "Experience: ";
float furnaceExp = blockEntity.experience;
if (furnaceExp <= 0) {
message = message + "0";
} else {
float expTillLevel = (1.0F - player.experienceProgress) * player.getNextLevelExperience();
if (furnaceExp <= expTillLevel) {
int percentage = (int) (blockEntity.experience * 100 / player.getNextLevelExperience());
message = message + "+"
+ (percentage > 0 ? String.valueOf(percentage) : "<1")
+ "%";
} else {
int levels = 0;
furnaceExp -= expTillLevel;
while (furnaceExp > 0) {
furnaceExp -= PlayerUtils.getLevelExperience(player.experienceLevel);
++levels;
}
message = message + "+" + String.valueOf(levels) + "L";
}
}
List<String> list = new ArrayList<>();
list.add("Expirience accumulated: " + blockEntity.experience);
renderTooltip(list, mouseX - getGuiLeft(), mouseY - getGuiTop());
list.add(message);
renderTooltip(list, mouseX, mouseY);
GlStateManager.disableLighting();
GlStateManager.color4f(1, 1, 1, 1);
}
@Override
public void renderBg(MinecraftClient mc, int mouseX, int mouseY) {
mc.getItemRenderer().renderGuiItem(new ItemStack(Items.EXPERIENCE_BOTTLE), x, y);
}
});
}
@ -90,14 +124,5 @@ public class GuiIronFurnace extends GuiBase<BuiltContainer> {
builder.drawProgressBar(this, blockEntity.gaugeProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer);
builder.drawBurnBar(this, blockEntity.gaugeFuelScaled(100), 100, 56, 36, mouseX, mouseY, layer);
Iterator<AbstractButtonWidget> buttonsList = this.buttons.iterator();
while (buttonsList.hasNext()) {
AbstractButtonWidget abstractButtonWidget = (AbstractButtonWidget) buttonsList.next();
if (abstractButtonWidget.isHovered()) {
abstractButtonWidget.renderToolTip(mouseX, mouseY);
break;
}
}
}
}

View file

@ -0,0 +1,41 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.utils;
/**
* @author drcrazy
*
*/
public class PlayerUtils {
public static int getLevelExperience(int level) {
if (level >= 30) {
return 112 + (level - 30) * 9;
}
return level >= 15 ? 37 + (level - 15) * 5 : 7 + level * 2;
}
}