improve gui
This commit is contained in:
parent
a7dacc36f8
commit
cc2c78d995
41 changed files with 369 additions and 579 deletions
|
@ -12,52 +12,50 @@ import java.util.Set;
|
|||
|
||||
public abstract class SmeltingRegistry {
|
||||
private static final Map<ItemStack, ItemStack> smeltingList = Maps.<ItemStack, ItemStack>newHashMap();
|
||||
private static final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
|
||||
|
||||
private static boolean compareItemStacks(ItemStack stack1, ItemStack stack2) {
|
||||
return stack2.getItem() == stack1.getItem();
|
||||
}
|
||||
|
||||
static void register() {
|
||||
add(Items.sand, Items.glass, 0.1F);
|
||||
add(Items.red_sand, Items.glass, 0.1F);
|
||||
add(Items.porkchop, Items.cooked_porkchop, 0.35F);
|
||||
add(Items.beef, Items.cooked_beef, 0.35F);
|
||||
add(Items.chicken, Items.cooked_chicken, 0.35F);
|
||||
add(Items.cobblestone, Items.stone, 0.1F);
|
||||
add(Items.stonebrick, Items.cracked_stonebrick, 0.1F);
|
||||
add(Items.clay_lump, Items.brick, 0.3F);
|
||||
add(Items.clay, Items.hardened_clay, 0.35F);
|
||||
add(Items.hellrock, Items.bloodbrick, 0.1F);
|
||||
add(Items.sand, Items.glass);
|
||||
add(Items.red_sand, Items.glass);
|
||||
add(Items.porkchop, Items.cooked_porkchop);
|
||||
add(Items.beef, Items.cooked_beef);
|
||||
add(Items.chicken, Items.cooked_chicken);
|
||||
add(Items.cobblestone, Items.stone);
|
||||
add(Items.stonebrick, Items.cracked_stonebrick);
|
||||
add(Items.clay_lump, Items.brick);
|
||||
add(Items.clay, Items.hardened_clay);
|
||||
add(Items.hellrock, Items.bloodbrick);
|
||||
|
||||
for(ItemFishFood.FishType fish : ItemFishFood.FishType.values()) {
|
||||
add(ItemRegistry.byName(fish.getName()), ItemRegistry.byName("cooked_" + fish.getName()), 0.35F);
|
||||
add(ItemRegistry.byName(fish.getName()), ItemRegistry.byName("cooked_" + fish.getName()));
|
||||
}
|
||||
|
||||
for(OreType ore : OreType.values()) {
|
||||
Item item = ItemRegistry.byName(ore.item);
|
||||
add(ItemRegistry.byName(ore.name + "_ore"), item, ((float)ore.experience) / 3.0F);
|
||||
add(ItemRegistry.byName(ore.name + "_ore"), item);
|
||||
}
|
||||
for(MetalType metal : MetalType.values()) {
|
||||
Item item = ItemRegistry.byName(metal.isPowder ? (metal.name + "_powder") : (metal.name + "_ingot"));
|
||||
add(ItemRegistry.byName(metal.name + "_ore"), item, 0.7F);
|
||||
add(ItemRegistry.byName(metal.name + "_ore"), item);
|
||||
}
|
||||
for(WoodType wood : WoodType.values()) {
|
||||
add(ItemRegistry.byName(wood.getName() + "_log"), Items.charcoal, 0.15F);
|
||||
add(ItemRegistry.byName(wood.getName() + "_log"), Items.charcoal);
|
||||
}
|
||||
for(MineralType mineral : MineralType.values()) {
|
||||
Item item = ItemRegistry.byName(mineral.name);
|
||||
add(ItemRegistry.byName(mineral.name + "_ore"), item, ((float)mineral.experience) / 10.0F);
|
||||
add(ItemRegistry.byName(mineral.name + "_ore"), item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void add(Item input, Item output, float experience) {
|
||||
add(new ItemStack(input), new ItemStack(output), experience);
|
||||
private static void add(Item input, Item output) {
|
||||
add(new ItemStack(input), new ItemStack(output));
|
||||
}
|
||||
|
||||
private static void add(ItemStack input, ItemStack stack, float experience) {
|
||||
private static void add(ItemStack input, ItemStack stack) {
|
||||
smeltingList.put(input, stack);
|
||||
experienceList.put(stack, Float.valueOf(experience));
|
||||
}
|
||||
|
||||
public static ItemStack getResult(ItemStack stack) {
|
||||
|
@ -70,16 +68,6 @@ public abstract class SmeltingRegistry {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static float getExperience(ItemStack stack) {
|
||||
for(Entry<ItemStack, Float> entry : experienceList.entrySet()) {
|
||||
if(compareItemStacks(stack, (ItemStack)entry.getKey())) {
|
||||
return ((Float)entry.getValue()).floatValue();
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
public static void getSmeltingList(Set<Item> set) {
|
||||
for(ItemStack itemstack : smeltingList.values()) {
|
||||
set.add(itemstack.getItem());
|
||||
|
|
|
@ -19,7 +19,7 @@ public class ContainerFurnace extends Container
|
|||
this.tileFurnace = furnaceInventory;
|
||||
this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17));
|
||||
this.addSlotToContainer(new SlotFurnaceFuel(furnaceInventory, 1, 56, 53));
|
||||
this.addSlotToContainer(new SlotFurnaceOutput(playerInventory, furnaceInventory, 2, 116, 35));
|
||||
this.addSlotToContainer(new SlotOutput(furnaceInventory, 2, 116, 35));
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,8 @@ public class ContainerTile extends Container
|
|||
private final IInventory tileInv;
|
||||
private final Device tile;
|
||||
private int temperature;
|
||||
private int progress;
|
||||
private int total;
|
||||
private Status status = Status.OFF;
|
||||
private final int[] resources;
|
||||
|
||||
|
@ -20,17 +22,27 @@ public class ContainerTile extends Container
|
|||
this.tile = tile;
|
||||
this.resources = new int[tile.getNumResources()];
|
||||
tileInv.openInventory(player);
|
||||
int i = 71;
|
||||
int i = 112;
|
||||
|
||||
for (int j = 0; j < tileInv.getSizeInventory(); ++j)
|
||||
int input = 0;
|
||||
int output = 0;
|
||||
for (int idx = 0; idx < tileInv.getSizeInventory(); ++idx)
|
||||
{
|
||||
final int index = j;
|
||||
this.addSlotToContainer(new Slot(tileInv, j, 8 + j * 18, 40) {
|
||||
final int index = idx;
|
||||
this.addSlotToContainer(new Slot(tileInv, idx, 8 + (this.tile.isInput(index) ? input : 8 - output) * 18, 81) {
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return ContainerTile.this.tile.isItemValidForSlot(index, stack);
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return ContainerTile.this.tile.isInput(index);
|
||||
}
|
||||
});
|
||||
if(this.tile.isInput(index))
|
||||
++input;
|
||||
else
|
||||
++output;
|
||||
}
|
||||
|
||||
for (int l = 0; l < 3; ++l)
|
||||
|
@ -101,7 +113,9 @@ public class ContainerTile extends Container
|
|||
{
|
||||
super.onCraftGuiOpened(listener);
|
||||
listener.sendProperty(this, this.resources.length, this.tile.getTemperature());
|
||||
listener.sendProperty(this, this.resources.length + 1, this.tile.getStatus().ordinal());
|
||||
listener.sendProperty(this, this.resources.length + 1, this.tile.getProgress());
|
||||
listener.sendProperty(this, this.resources.length + 2, this.tile.getTotal());
|
||||
listener.sendProperty(this, this.resources.length + 3, this.tile.getStatus().ordinal());
|
||||
for(int z = 0; z < this.resources.length; z++) {
|
||||
listener.sendProperty(this, z, this.tile.getResource(z).getValue());
|
||||
}
|
||||
|
@ -112,6 +126,10 @@ public class ContainerTile extends Container
|
|||
if(id == this.resources.length)
|
||||
this.tile.setTemperature(data);
|
||||
else if(id == this.resources.length + 1)
|
||||
this.tile.setProgress(data);
|
||||
else if(id == this.resources.length + 2)
|
||||
this.tile.setTotal(data);
|
||||
else if(id == this.resources.length + 3)
|
||||
this.tile.setStatus(Status.values()[data % Status.values().length]);
|
||||
else
|
||||
this.tile.getResource(id).setValue(data);
|
||||
|
@ -126,15 +144,21 @@ public class ContainerTile extends Container
|
|||
IPlayer listener = this.crafters.get(i);
|
||||
if(this.temperature != this.tile.getTemperature())
|
||||
listener.sendProperty(this, this.resources.length, this.tile.getTemperature());
|
||||
if(this.progress != this.tile.getProgress())
|
||||
listener.sendProperty(this, this.resources.length + 1, this.tile.getProgress());
|
||||
if(this.total != this.tile.getTotal())
|
||||
listener.sendProperty(this, this.resources.length + 2, this.tile.getTotal());
|
||||
if(this.status != this.tile.getStatus())
|
||||
listener.sendProperty(this, this.resources.length + 1, this.tile.getStatus().ordinal());
|
||||
listener.sendProperty(this, this.resources.length + 3, this.tile.getStatus().ordinal());
|
||||
for(int z = 0; z < this.resources.length; z++) {
|
||||
if(this.resources[z] != this.tile.getResource(z).getValue())
|
||||
listener.sendProperty(this, z, this.tile.getResource(z).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.temperature = this.tile.getTemperature();
|
||||
this.progress = this.tile.getProgress();
|
||||
this.total = this.tile.getTotal();
|
||||
this.status = this.tile.getStatus();
|
||||
for(int z = 0; z < this.resources.length; z++) {
|
||||
this.resources[z] = this.tile.getResource(z).getValue();
|
||||
|
|
|
@ -11,9 +11,6 @@ public class SlotFurnaceFuel extends Slot
|
|||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return TileEntityFurnace.isItemFuel(stack) || isBucket(stack);
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.entity.item.EntityXp;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.SmeltingRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.util.ExtMath;
|
||||
import common.vars.Vars;
|
||||
|
||||
public class SlotFurnaceOutput extends Slot
|
||||
{
|
||||
/** The player that is using the GUI where this slot resides. */
|
||||
private EntityNPC thePlayer;
|
||||
private int smelted;
|
||||
|
||||
public SlotFurnaceOutput(EntityNPC player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition)
|
||||
{
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
this.thePlayer = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
|
||||
*/
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
|
||||
* stack.
|
||||
*/
|
||||
public ItemStack decrStackSize(int amount)
|
||||
{
|
||||
if (this.getHasStack())
|
||||
{
|
||||
this.smelted += Math.min(amount, this.getStack().getSize());
|
||||
}
|
||||
|
||||
return super.decrStackSize(amount);
|
||||
}
|
||||
|
||||
public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
|
||||
{
|
||||
this.onCrafting(stack);
|
||||
super.onPickupFromSlot(playerIn, stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
|
||||
* internal count then calls onCrafting(item).
|
||||
*/
|
||||
protected void onCrafting(ItemStack stack, int amount)
|
||||
{
|
||||
this.smelted += amount;
|
||||
this.onCrafting(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
|
||||
*/
|
||||
protected void onCrafting(ItemStack stack)
|
||||
{
|
||||
// stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.smelted);
|
||||
|
||||
if (!this.thePlayer.worldObj.client && Vars.smeltingXP)
|
||||
{
|
||||
int xp = this.smelted;
|
||||
float smeltXp = SmeltingRegistry.getExperience(stack);
|
||||
|
||||
if (smeltXp == 0.0F)
|
||||
{
|
||||
xp = 0;
|
||||
}
|
||||
else if (smeltXp < 1.0F)
|
||||
{
|
||||
int mxp = ExtMath.floorf((float)xp * smeltXp);
|
||||
|
||||
if (mxp < ExtMath.ceilf((float)xp * smeltXp) && Math.random() < (double)((float)xp * smeltXp - (float)mxp))
|
||||
{
|
||||
++mxp;
|
||||
}
|
||||
|
||||
xp = mxp;
|
||||
}
|
||||
|
||||
while (xp > 0)
|
||||
{
|
||||
int split = EntityXp.getXPSplit(xp);
|
||||
xp -= split;
|
||||
this.thePlayer.worldObj.spawnEntityInWorld(new EntityXp(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, split));
|
||||
}
|
||||
}
|
||||
|
||||
this.smelted = 0;
|
||||
|
||||
// if (stack.getItem() == Items.iron_ingot)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.acquireIron);
|
||||
// }
|
||||
//
|
||||
// if (stack.getItem() == Items.cooked_fish)
|
||||
// {
|
||||
// this.thePlayer.triggerAchievement(AchievementList.cookFish);
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
17
common/src/main/java/common/inventory/SlotOutput.java
Executable file
17
common/src/main/java/common/inventory/SlotOutput.java
Executable file
|
@ -0,0 +1,17 @@
|
|||
package common.inventory;
|
||||
|
||||
import common.item.ItemStack;
|
||||
|
||||
public class SlotOutput extends Slot {
|
||||
public SlotOutput(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) {
|
||||
super(inventoryIn, slotIndex, xPosition, yPosition);
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCheatItem() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -46,7 +46,6 @@ import common.packet.SPacketEntityVelocity;
|
|||
import common.packet.SPacketHeldItemChange;
|
||||
import common.packet.SPacketJoinGame;
|
||||
import common.packet.SPacketKeepAlive;
|
||||
import common.packet.SPacketLoading;
|
||||
import common.packet.SPacketMapChunkBulk;
|
||||
import common.packet.SPacketMessage;
|
||||
import common.packet.SPacketMultiBlockChange;
|
||||
|
@ -97,7 +96,6 @@ public interface IClientPlayer extends NetHandler {
|
|||
void handleDisconnect(SPacketDisconnect packet);
|
||||
void handleCollectItem(SPacketCollectItem packet);
|
||||
void handleMessage(SPacketMessage packet);
|
||||
void handleLoading(SPacketLoading packet);
|
||||
void handleAnimation(SPacketAnimation packet);
|
||||
void handleSpawnMob(SPacketSpawnMob packet);
|
||||
void handleTimeUpdate(SPacketTimeUpdate packet);
|
||||
|
|
|
@ -83,7 +83,6 @@ import common.packet.SPacketEntityVelocity;
|
|||
import common.packet.SPacketHeldItemChange;
|
||||
import common.packet.SPacketJoinGame;
|
||||
import common.packet.SPacketKeepAlive;
|
||||
import common.packet.SPacketLoading;
|
||||
import common.packet.SPacketMapChunkBulk;
|
||||
import common.packet.SPacketMessage;
|
||||
import common.packet.SPacketMultiBlockChange;
|
||||
|
@ -181,7 +180,6 @@ public enum PacketRegistry {
|
|||
this.server(SPacketDimensionName.class);
|
||||
this.server(SPacketCharacterList.class);
|
||||
this.server(SPacketServerTick.class);
|
||||
this.server(SPacketLoading.class);
|
||||
this.server(SPacketDisplayForm.class);
|
||||
this.server(SPacketServerConfig.class);
|
||||
this.server(SPacketCelestials.class);
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
package common.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import common.network.IClientPlayer;
|
||||
import common.network.Packet;
|
||||
import common.network.PacketBuffer;
|
||||
|
||||
public class SPacketLoading implements Packet<IClientPlayer> {
|
||||
private String message;
|
||||
private String task;
|
||||
private int total = -1;
|
||||
private int progress = -2;
|
||||
|
||||
public SPacketLoading() {
|
||||
}
|
||||
|
||||
public SPacketLoading(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public SPacketLoading(String task, int total) {
|
||||
this.task = task;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public SPacketLoading(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||
this.message = buf.readString(128);
|
||||
this.message = this.message != null && this.message.isEmpty() ? null : this.message;
|
||||
if(this.message == null) {
|
||||
this.task = buf.readString(128);
|
||||
this.task = this.task != null && this.task.isEmpty() ? null : this.task;
|
||||
this.total = buf.readInt();
|
||||
this.progress = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||
buf.writeString(this.message == null ? "" : this.message);
|
||||
if(this.message == null) {
|
||||
buf.writeString(this.task == null ? "" : this.task);
|
||||
buf.writeInt(this.total);
|
||||
buf.writeInt(this.progress);
|
||||
}
|
||||
}
|
||||
|
||||
public void processPacket(IClientPlayer handler) {
|
||||
handler.handleLoading(this);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public String getTask() {
|
||||
return this.task;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ import common.util.Color;
|
|||
|
||||
public abstract class Device extends TileEntity implements IInventory, ITickable {
|
||||
public static enum Status {
|
||||
OFF(Color.DARK_GRAY, "Inaktiv"),
|
||||
OFF(Color.GRAY, "Inaktiv"),
|
||||
COOLING(Color.YELLOW, "Abkühlen ..."),
|
||||
RUNNING(Color.GREEN, "Aktiv"),
|
||||
OVERHEAT(Color.RED, "Überhitzt!"),
|
||||
|
@ -33,11 +33,15 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
protected final ItemStack[] inventory;
|
||||
protected final MachineResource[] resources;
|
||||
protected final Random rand = new Random();
|
||||
protected final int inputs;
|
||||
protected int temperature;
|
||||
protected int progress = -1;
|
||||
protected int total;
|
||||
protected Status status = Status.OFF;
|
||||
|
||||
protected Device(int slots, MachineResource ... resources) {
|
||||
this.inventory = new ItemStack[slots];
|
||||
protected Device(int inputs, int outputs, MachineResource ... resources) {
|
||||
this.inventory = new ItemStack[inputs + outputs];
|
||||
this.inputs = inputs;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
|
@ -49,10 +53,14 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
return -1;
|
||||
}
|
||||
|
||||
protected int getMaxTemp() {
|
||||
public int getMaxTemp() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public boolean hasTemperature() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean executeFunction();
|
||||
|
||||
public MachineResource getResource(int slot) {
|
||||
|
@ -71,6 +79,26 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
this.temperature = temp;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public boolean hasProgress() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
@ -101,7 +129,12 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
this.resources[i].fromTag(list.get(i));
|
||||
}
|
||||
|
||||
this.temperature = tag.getInt("Temperature");
|
||||
if(this.hasTemperature())
|
||||
this.temperature = tag.getInt("Temperature");
|
||||
if(this.hasProgress()) {
|
||||
this.progress = tag.getInt("Progress");
|
||||
this.total = tag.getInt("Total");
|
||||
}
|
||||
this.status = Status.values()[(int)tag.getByte("Status") % Status.values().length];
|
||||
}
|
||||
|
||||
|
@ -127,7 +160,12 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
}
|
||||
tag.setList("Resources", list);
|
||||
|
||||
tag.setInt("Temperature", this.temperature);
|
||||
if(this.hasTemperature())
|
||||
tag.setInt("Temperature", this.temperature);
|
||||
if(this.hasProgress()) {
|
||||
tag.setInt("Progress", this.progress);
|
||||
tag.setInt("Total", this.total);
|
||||
}
|
||||
tag.setByte("Status", (byte)this.status.ordinal());
|
||||
}
|
||||
|
||||
|
@ -196,7 +234,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
}
|
||||
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return true;
|
||||
return index < this.inputs;
|
||||
}
|
||||
|
||||
public void detonate() {
|
||||
|
@ -208,83 +246,75 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) {
|
||||
int envTemp = (int)this.worldObj.getTemperatureC(this.getPos());
|
||||
if(this.executeFunction()) {
|
||||
if(this.getTempIncrement() < 0)
|
||||
this.temperature = envTemp;
|
||||
else
|
||||
this.temperature += this.getTempIncrement();
|
||||
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING;
|
||||
if(this.temperature > this.getMaxTemp()) {
|
||||
this.status = Status.BROKEN;
|
||||
this.markDirty();
|
||||
this.detonate();
|
||||
return;
|
||||
if(this.hasTemperature()) {
|
||||
if(this.getTempIncrement() < 0)
|
||||
this.temperature = envTemp;
|
||||
else
|
||||
this.temperature += this.getTempIncrement();
|
||||
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING;
|
||||
if(this.temperature > this.getMaxTemp()) {
|
||||
this.status = Status.BROKEN;
|
||||
this.markDirty();
|
||||
this.detonate();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.status = Status.RUNNING;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
else {
|
||||
int dec = this.getTempDecrement();
|
||||
if(dec != 0) {
|
||||
int prev = this.temperature;
|
||||
if(dec < 0)
|
||||
this.temperature = envTemp;
|
||||
else
|
||||
this.temperature -= dec;
|
||||
this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE);
|
||||
if(prev != this.temperature)
|
||||
if(this.hasTemperature()) {
|
||||
int dec = this.getTempDecrement();
|
||||
if(dec != 0) {
|
||||
int prev = this.temperature;
|
||||
if(dec < 0)
|
||||
this.temperature = envTemp;
|
||||
else
|
||||
this.temperature -= dec;
|
||||
this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE);
|
||||
if(prev != this.temperature)
|
||||
this.markDirty();
|
||||
else
|
||||
dec = 0;
|
||||
}
|
||||
Status prev = this.status;
|
||||
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT :
|
||||
(this.temperature == envTemp ? Status.OFF : Status.COOLING);
|
||||
if(dec == 0 && prev != this.status) {
|
||||
this.markDirty();
|
||||
else
|
||||
dec = 0;
|
||||
}
|
||||
}
|
||||
Status prev = this.status;
|
||||
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT :
|
||||
(this.temperature == envTemp ? Status.OFF : Status.COOLING);
|
||||
if(dec == 0 && prev != this.status) {
|
||||
else if(this.status != Status.OFF) {
|
||||
this.status = Status.OFF;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
if(this.temperature < envTemp) {
|
||||
if(this.hasTemperature() && this.temperature < envTemp) {
|
||||
this.temperature = envTemp;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty(int slot) {
|
||||
if(slot == -1) {
|
||||
for(ItemStack itemstack : this.inventory) {
|
||||
if(itemstack != null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return this.inventory[slot] == null || this.inventory[slot].isEmpty();
|
||||
}
|
||||
public boolean isInput(int slot) {
|
||||
return slot < this.inputs;
|
||||
}
|
||||
|
||||
public boolean hasAmount(int slot, int amount) {
|
||||
if(slot == -1) {
|
||||
int n = 0;
|
||||
for(ItemStack itemstack : this.inventory) {
|
||||
if(itemstack != null && !itemstack.isEmpty())
|
||||
n += itemstack.getSize();
|
||||
}
|
||||
return n >= amount;
|
||||
}
|
||||
else {
|
||||
return this.inventory[slot] != null && this.inventory[slot].getSize() >= amount;
|
||||
}
|
||||
public boolean isInputEmpty(int slot) {
|
||||
return this.inventory[slot] == null || this.inventory[slot].isEmpty();
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
for(ItemStack itemstack : this.inventory) {
|
||||
if(itemstack == null || !itemstack.isFull()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
public boolean hasInput(int slot, int amount) {
|
||||
return this.inventory[slot] != null && this.inventory[slot].getSize() >= amount;
|
||||
}
|
||||
|
||||
public boolean isOutputFull(int slot) {
|
||||
return this.inventory[slot - this.inputs] != null && this.inventory[slot - this.inputs].isFull();
|
||||
}
|
||||
|
||||
public int getField(int id) {
|
||||
|
@ -312,5 +342,7 @@ public abstract class Device extends TileEntity implements IInventory, ITickable
|
|||
return 0x8080ff;
|
||||
}
|
||||
|
||||
public abstract String formatDisplay(ContainerTile inv);
|
||||
public String formatDisplay(ContainerTile inv) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,18 +13,18 @@ import common.world.World;
|
|||
|
||||
public class DeviceEffectGenerator extends Device {
|
||||
public DeviceEffectGenerator() {
|
||||
super(2);
|
||||
super(2, 0);
|
||||
}
|
||||
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return index == 0 ? stack.getItem() instanceof ItemPotion : (index == 1 ? stack.getItem() == Items.blazing_powder : false);
|
||||
return index == 0 ? stack.getItem() instanceof ItemPotion potion && potion.getEffect() != null : (index == 1 ? stack.getItem() == Items.blazing_powder : false);
|
||||
}
|
||||
|
||||
protected boolean executeFunction() {
|
||||
if(!this.hasAmount(0, 1) || !this.hasAmount(1, 1) || !(this.getStackInSlot(0).getItem() instanceof ItemPotion potion))
|
||||
if(!this.hasInput(0, 1) || !this.hasInput(1, 1) || !(this.getStackInSlot(0).getItem() instanceof ItemPotion potion))
|
||||
return false;
|
||||
StatusEffect effect = potion.getEffect();
|
||||
if(effect == null || !this.hasAmount(1, effect.getAmplifier() + 1))
|
||||
if(effect == null || !this.hasInput(1, effect.getAmplifier() + 1))
|
||||
return false;
|
||||
int levels = 4; // TODO: energy + selector (MachineControl)
|
||||
double r = (double)(levels * 10 + 10);
|
||||
|
@ -37,7 +37,7 @@ public class DeviceEffectGenerator extends Device {
|
|||
if(!entity.hasEffect(effect.getPotion()) || entity.getEffect(effect.getPotion()).getAmplifier() < effect.getAmplifier() || entity.getEffect(effect.getPotion()).getRemaining() < 40) {
|
||||
entity.addEffect(new StatusEffect(effect.getPotion(), 180, effect.getAmplifier()));
|
||||
this.decrStackSize(1, effect.getAmplifier() + 1);
|
||||
if(!this.hasAmount(1, effect.getAmplifier() + 1))
|
||||
if(!this.hasInput(1, effect.getAmplifier() + 1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ public class DeviceEffectGenerator extends Device {
|
|||
public String formatDisplay(ContainerTile inv) {
|
||||
ItemStack stack = inv.getSlot(0).getStack();
|
||||
if(stack == null)
|
||||
return "Kein Trank vorhanden";
|
||||
return String.format("Effekt: %s",
|
||||
stack.getItem() instanceof ItemPotion potion ? (potion.getEffect() != null ? potion.getEffect().getEffectName() : "Keiner") : "<?>");
|
||||
return "Trank einlegen";
|
||||
return "Gebe Effekt " + (stack.getItem() instanceof ItemPotion potion && potion.getEffect() != null ? potion.getEffect().getEffectName() : "<?>");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,17 @@ import common.vars.Vars;
|
|||
public class DeviceMobSpawner extends Device implements ITickable
|
||||
{
|
||||
public DeviceMobSpawner() {
|
||||
super(1);
|
||||
super(1, 0);
|
||||
}
|
||||
|
||||
private int spawnDelay = 20;
|
||||
private int minSpawnDelay = 200;
|
||||
private int maxSpawnDelay = 800;
|
||||
private int spawnRange = 4;
|
||||
|
||||
public boolean hasProgress() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return index == 0 ? stack.getItem() instanceof ItemMobTemplate || stack.getItem() instanceof ItemCharTemplate : false;
|
||||
|
@ -27,12 +31,12 @@ public class DeviceMobSpawner extends Device implements ITickable
|
|||
public String formatDisplay(ContainerTile inv) {
|
||||
ItemStack stack = inv.getSlot(0).getStack();
|
||||
if(stack == null)
|
||||
return "Keine DNA-Probe vorhanden";
|
||||
return String.format("Erschaffe: %s", stack.getItem() instanceof ItemMobTemplate egg ? EntityRegistry.getEntityName(egg.getSpawnedId()) : ((stack.getItem() instanceof ItemCharTemplate egg ? egg.getCharName() : "<?>")));
|
||||
return "DNA-Probe einlegen";
|
||||
return "Erzeuge " + (stack.getItem() instanceof ItemMobTemplate egg ? EntityRegistry.getEntityName(egg.getSpawnedId()) : ((stack.getItem() instanceof ItemCharTemplate egg ? egg.getCharName() : "<?>")));
|
||||
}
|
||||
|
||||
protected boolean executeFunction() {
|
||||
if(!Vars.mobs || !Vars.spawners || !this.hasAmount(0, 1))
|
||||
if(!Vars.mobs || !Vars.spawners || !this.hasInput(0, 1))
|
||||
return false;
|
||||
if (this.spawnDelay == -1)
|
||||
this.resetTimer();
|
||||
|
|
|
@ -4,14 +4,15 @@ import common.init.Items;
|
|||
import common.inventory.ContainerTile;
|
||||
import common.item.ItemStack;
|
||||
import common.tileentity.MachineResource.Type;
|
||||
import common.util.Color;
|
||||
|
||||
public class DeviceTianReactor extends Device {
|
||||
public DeviceTianReactor() {
|
||||
super(2, new MachineResource(Type.OUTPUT, "output.energy", 1024, 0, 0));
|
||||
super(2, 0, new MachineResource(Type.OUTPUT, "Gespeichert: $amount/$capacity TF", 1024, 0, 0));
|
||||
}
|
||||
|
||||
protected boolean executeFunction() {
|
||||
if(!this.hasAmount(0, 2))
|
||||
if(!this.hasInput(0, 2))
|
||||
return false;
|
||||
if(this.rand.rarity(5))
|
||||
return true;
|
||||
|
@ -20,29 +21,37 @@ public class DeviceTianReactor extends Device {
|
|||
this.getResource(0).add(this.rand.range(this.temperature / 200, this.temperature / 50), 20, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasTemperature() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int getTempIncrement() {
|
||||
return this.isEmpty(1) ? this.rand.range(20, 50) : (this.temperature >= this.rand.range(4200, 4250) ? 0 : this.rand.range(10, 15));
|
||||
return this.isInputEmpty(1) ? this.rand.range(20, 50) : (this.temperature >= this.rand.range(4200, 4250) ? 0 : this.rand.range(10, 15));
|
||||
}
|
||||
|
||||
protected int getTempDecrement() {
|
||||
return this.isEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3);
|
||||
return this.isInputEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3);
|
||||
}
|
||||
|
||||
public boolean hasProgress() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return index == 0 ? stack.getItem() == Items.aluminium_ingot : (index == 1 ? stack.getItem() == Items.lead_block : false);
|
||||
}
|
||||
|
||||
protected int getMaxTemp() {
|
||||
public int getMaxTemp() {
|
||||
return 8200;
|
||||
}
|
||||
|
||||
public String formatDisplay(ContainerTile inv) {
|
||||
return String.format("Gespeicherte Energie: %d TF", this.getResource(0).getValue());
|
||||
}
|
||||
|
||||
public void detonate() {
|
||||
this.worldObj.setBlockToAir(getPos());
|
||||
this.worldObj.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120);
|
||||
}
|
||||
|
||||
public String formatDisplay(ContainerTile inv) {
|
||||
return this.status == Status.OVERHEAT ? Color.RED + "!!! GEFAHR !!! Reaktor ist\n" + Color.RED + "überhitzt und muss sofort\n" + Color.RED + "heruntergekühlt werden,\n" + Color.RED + "sonst droht Detonation!" : "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,4 +105,8 @@ public class MachineResource {
|
|||
public boolean isAtCapacity(boolean over) {
|
||||
return this.amount >= (this.capacity + (over ? this.overcharge : 0));
|
||||
}
|
||||
|
||||
public String format() {
|
||||
return this.name.replace("$amount", "" + this.amount).replace("$undercharge", "" + this.undercharge).replace("$overcharge", "" + this.overcharge).replace("$capacity", "" + this.capacity).replace("$entropy", "" + this.entropy);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ public abstract class Vars {
|
|||
public static boolean blockXP = true;
|
||||
@Var(name = "dropBreedingXP")
|
||||
public static boolean breedingXP = true;
|
||||
@Var(name = "dropSmeltingXP")
|
||||
public static boolean smeltingXP = true;
|
||||
@Var(name = "dropFishingXP")
|
||||
public static boolean fishingXP = true;
|
||||
@Var(name = "dropMobXP")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue