forked from wormzjl/ModularMachinery
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathTileItemBus.java
More file actions
107 lines (86 loc) · 3.29 KB
/
Copy pathTileItemBus.java
File metadata and controls
107 lines (86 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*******************************************************************************
* HellFirePvP / Modular Machinery 2019
*
* This project is licensed under GNU GENERAL PUBLIC LICENSE Version 3.
* The source code is available on github: https://github.com/HellFirePvP/ModularMachinery
* For further details, see the License file there.
******************************************************************************/
package hellfirepvp.modularmachinery.common.tiles.base;
import hellfirepvp.modularmachinery.common.block.prop.ItemBusSize;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
/**
* This class is part of the Modular Machinery Mod
* The complete source code for this mod can be found on github.
* Class: TileItemBus
* Created by HellFirePvP
* Date: 09.07.2017 / 17:37
*/
public abstract class TileItemBus extends TileInventory implements SelectiveUpdateTileEntity {
private static final String NBT_EXTERNAL_IO_DISABLED = "disableExternalIO";
protected int successCounter = 0;
protected boolean inventoryChanged = false;
private ItemBusSize size;
private boolean externalIODisabled = false;
public TileItemBus() {
}
public TileItemBus(ItemBusSize size) {
super(size.getSlotCount());
this.size = size;
}
@Override
public void doRestrictedTick() {
}
protected boolean canWork(int minWorkDelay, int maxWorkDelay) {
if (inventoryChanged) {
inventoryChanged = false;
return true;
}
if (successCounter <= 0) {
return ticksExisted % maxWorkDelay == 0;
}
int workDelay = Math.max(minWorkDelay, maxWorkDelay - (successCounter * 5));
return ticksExisted % workDelay == 0;
}
protected void incrementSuccessCounter(int maxWorkDelay, int minWorkDelay) {
int max = (maxWorkDelay - minWorkDelay) / 5;
if (successCounter < max) {
successCounter++;
}
}
protected void decrementSuccessCounter() {
if (successCounter > 0) {
successCounter--;
}
}
public ItemBusSize getSize() {
return size;
}
public boolean isExternalIODisabled() {
return externalIODisabled;
}
public boolean setExternalIODisabled(boolean externalIODisabled) {
if (this.externalIODisabled == externalIODisabled) return false;
this.externalIODisabled = externalIODisabled;
this.successCounter = 0;
this.inventoryChanged = true;
if (getWorld() != null && !getWorld().isRemote) markForUpdate();
return true;
}
@Override
public void readCustomNBT(NBTTagCompound compound) {
super.readCustomNBT(compound);
this.size = ItemBusSize.values()[MathHelper.clamp(compound.getInteger("busSize"), 0, ItemBusSize.values().length - 1)];
this.externalIODisabled = compound.getBoolean(NBT_EXTERNAL_IO_DISABLED);
}
@Override
public void writeCustomNBT(NBTTagCompound compound) {
super.writeCustomNBT(compound);
compound.setInteger("busSize", this.size.ordinal());
if (this.externalIODisabled) {
compound.setBoolean(NBT_EXTERNAL_IO_DISABLED, true);
} else {
compound.removeTag(NBT_EXTERNAL_IO_DISABLED);
}
}
}