Skip to content

Commit 5a8fcec

Browse files
committed
Test whether the module is installed properly
1 parent b5f7768 commit 5a8fcec

File tree

6 files changed

+150
-86
lines changed

6 files changed

+150
-86
lines changed

src/main/java/mekanism/common/block/states/BlockStateMachine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ public boolean isEnabled() {
212212
}
213213

214214
public boolean isValidMachine() {
215-
return this != MODIFICATION_STATION;
216-
// return true;
215+
// return this != MODIFICATION_STATION;
216+
return true;
217217
}
218218

219219
public TileEntity create() {

src/main/java/mekanism/common/item/ItemGasMask.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import net.minecraft.inventory.EntityEquipmentSlot;
1111
import net.minecraft.item.ItemArmor;
1212
import net.minecraft.item.ItemStack;
13-
import net.minecraft.util.DamageSource;
1413
import net.minecraftforge.common.util.EnumHelper;
1514
import net.minecraftforge.event.entity.living.LivingAttackEvent;
1615
import net.minecraftforge.event.entity.living.LivingDamageEvent;

src/main/java/mekanism/common/item/armour/ItemMekAsuitArmour.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import mekanism.common.integration.ic2.IC2ItemManager;
1313
import mekanism.common.integration.redstoneflux.RFIntegration;
1414
import mekanism.common.integration.tesla.TeslaItemWrapper;
15+
import mekanism.common.moduleUpgrade;
1516
import mekanism.common.util.ItemDataUtils;
17+
import mekanism.common.util.MekanismUtils;
1618
import net.minecraft.creativetab.CreativeTabs;
1719
import net.minecraft.entity.Entity;
1820
import net.minecraft.init.SoundEvents;
@@ -28,6 +30,10 @@
2830
import net.minecraftforge.fml.common.Optional;
2931

3032
import javax.annotation.Nonnull;
33+
import java.util.EnumMap;
34+
import java.util.EnumSet;
35+
import java.util.Map;
36+
import java.util.Set;
3137

3238
@Optional.InterfaceList({
3339
@Optional.Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = MekanismHooks.IC2_MOD_ID),
@@ -36,18 +42,21 @@
3642
})
3743
public abstract class ItemMekAsuitArmour extends ItemArmor implements IEnergizedItem, ISpecialElectricItem, IEnergyContainerItem, ISpecialArmor {
3844

45+
public Map<moduleUpgrade, Integer> upgrades = new EnumMap<>(moduleUpgrade.class);
46+
public Set<moduleUpgrade> supported = EnumSet.noneOf(moduleUpgrade.class);
47+
3948
public ItemMekAsuitArmour(EntityEquipmentSlot slot) {
4049
super(EnumHelper.addArmorMaterial("MEKASUIT", "mekasuit", 0, new int[]{0, 0, 0, 0}, 0, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0), 3, slot);
4150
setMaxStackSize(1);
4251
setCreativeTab(Mekanism.tabMekanism);
52+
setSupported(moduleUpgrade.EnergyUnit);
4353
}
4454

4555
@Override
4656
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
4757
return "mekanism:render/MekAsuit.png";
4858
}
4959

50-
5160
@Override
5261
public double getEnergy(ItemStack itemStack) {
5362
return ItemDataUtils.getDouble(itemStack, "energyStored");
@@ -68,8 +77,8 @@ public void setEnergy(ItemStack itemStack, double amount) {
6877

6978
@Override
7079
public double getMaxEnergy(ItemStack itemStack) {
71-
return 4096000000D;
72-
// return ItemDataUtils.hasData(itemStack, "module") ? MekanismUtils.getModuleMaxEnergy(itemStack, 16000000D) : 16000000D;
80+
// return 4096000000D;
81+
return ItemDataUtils.hasData(itemStack, "module") ? MekanismUtils.getModuleMaxEnergy(itemStack, 16000000D) : 16000000D;
7382
}
7483

7584
@Override
@@ -165,4 +174,53 @@ public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt)
165174
return new ItemCapabilityWrapper(stack, new TeslaItemWrapper(), new ForgeEnergyItemWrapper());
166175
}
167176

177+
178+
public int getUpgrades(moduleUpgrade upgrade) {
179+
return upgrades.getOrDefault(upgrade, 0);
180+
}
181+
182+
183+
public void removeUpgrade(moduleUpgrade upgrade, boolean removeAll) {
184+
int installed = getUpgrades(upgrade);
185+
if (installed > 0) {
186+
int toRemove = removeAll ? installed : 1;
187+
upgrades.put(upgrade, Math.max(0, getUpgrades(upgrade) - toRemove));
188+
}
189+
if (upgrades.get(upgrade) == 0) {
190+
upgrades.remove(upgrade);
191+
}
192+
}
193+
194+
public void setSupported(moduleUpgrade upgrade) {
195+
setSupported(upgrade, true);
196+
}
197+
198+
public void setSupported(moduleUpgrade upgrade, boolean isSupported) {
199+
if (isSupported) {
200+
supported.add(upgrade);
201+
} else {
202+
supported.remove(upgrade);
203+
}
204+
}
205+
206+
public void clearSupportedTypes() {
207+
supported.clear();
208+
}
209+
210+
public boolean supports(moduleUpgrade upgrade) {
211+
return supported.contains(upgrade);
212+
}
213+
214+
public Set<moduleUpgrade> getSupportedTypes() {
215+
return supported;
216+
}
217+
218+
public boolean isUpgradeInstalled(ItemStack stack, moduleUpgrade upgrade) {
219+
if (ItemDataUtils.hasData(stack, "module")) {
220+
Map<moduleUpgrade, Integer> module = moduleUpgrade.buildMap(ItemDataUtils.getDataMap(stack));
221+
return module.containsKey(upgrade);
222+
}
223+
return false;
224+
}
225+
168226
}

src/main/java/mekanism/common/item/armour/ItemMekAsuitHeadArmour.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import mekanism.common.MekanismFluids;
1212
import mekanism.common.MekanismItems;
1313
import mekanism.common.config.MekanismConfig;
14+
import mekanism.common.moduleUpgrade;
1415
import mekanism.common.util.ItemDataUtils;
1516
import net.minecraft.block.material.Material;
1617
import net.minecraft.client.Minecraft;
@@ -42,6 +43,7 @@ public class ItemMekAsuitHeadArmour extends ItemMekAsuitArmour implements IGasIt
4243

4344
public ItemMekAsuitHeadArmour() {
4445
super(EntityEquipmentSlot.HEAD);
46+
setSupported(moduleUpgrade.SolarRechargingUnit);
4547
}
4648

4749
@Override
@@ -58,22 +60,21 @@ public ModelBiped getArmorModel(EntityLivingBase entityLiving, ItemStack itemSta
5860
if (render instanceof RenderPlayer) {
5961
armorModel.setModelAttributes(_default);
6062
}
61-
// if () {
62-
// if (armorModel.helmet_armor.childModels.contains(armorModel.hide)) {
63-
armorModel.helmet_armor.childModels.remove(armorModel.hide);
64-
// }
65-
// if (!armorModel.helmet_armor.childModels.contains(Solar.solar_helmet)) {
66-
armorModel.bipedHead.addChild(Solar.solar_helmet);
67-
// }
68-
/* } else {
63+
if (isUpgradeInstalled(itemStack, moduleUpgrade.SolarRechargingUnit)) {
64+
if (armorModel.helmet_armor.childModels.contains(armorModel.hide)) {
65+
armorModel.helmet_armor.childModels.remove(armorModel.hide);
66+
}
67+
if (!armorModel.helmet_armor.childModels.contains(Solar.solar_helmet)) {
68+
armorModel.bipedHead.addChild(Solar.solar_helmet);
69+
}
70+
} else {
6971
if (armorModel.helmet_armor.childModels.contains(Solar.solar_helmet)) {
7072
armorModel.helmet_armor.childModels.remove(Solar.solar_helmet);
7173
}
7274
if (!armorModel.helmet_armor.childModels.contains(armorModel.hide)) {
7375
armorModel.helmet_armor.childModels.add(armorModel.hide);
7476
}
75-
} */
76-
77+
}
7778
return armorModel;
7879
}
7980

@@ -240,23 +241,23 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
240241
} else if (nv != null) {
241242
nv.duration = 0;
242243
}
243-
//if()
244-
245244
//if()
246-
if (player.getEntityWorld().isDaytime() && player.getEntityWorld().canSeeSky(player.getPosition())) {
247-
Biome b = player.getEntityWorld().provider.getBiomeForCoords(player.getPosition());
248-
float tempEff = 0.3f * (0.8f - b.getTemperature(player.getPosition()));
249-
float humidityEff = -0.3f * (b.canRain() ? b.getRainfall() : 0.0f);
250-
boolean needsRainCheck = b.canRain();
251-
double peakOutput = 500 * (1.0f + tempEff + humidityEff);
252-
float brightness = player.getEntityWorld().getSunBrightnessFactor(1.0f);
253-
double production = peakOutput * brightness;
254-
if (needsRainCheck && (world.isRaining() || world.isThundering())) {
255-
production *= 0.2;
245+
246+
if (isUpgradeInstalled(headStack, moduleUpgrade.SolarRechargingUnit)) {
247+
if (player.getEntityWorld().isDaytime() && player.getEntityWorld().canSeeSky(player.getPosition())) {
248+
Biome b = player.getEntityWorld().provider.getBiomeForCoords(player.getPosition());
249+
float tempEff = 0.3f * (0.8f - b.getTemperature(player.getPosition()));
250+
float humidityEff = -0.3f * (b.canRain() ? b.getRainfall() : 0.0f);
251+
boolean needsRainCheck = b.canRain();
252+
double peakOutput = 500 * (1.0f + tempEff + humidityEff);
253+
float brightness = player.getEntityWorld().getSunBrightnessFactor(1.0f);
254+
double production = peakOutput * brightness;
255+
if (needsRainCheck && (world.isRaining() || world.isThundering())) {
256+
production *= 0.2;
257+
}
258+
item.setEnergy(headStack, item.getEnergy(headStack) + production * getUpgrades(moduleUpgrade.SolarRechargingUnit));
256259
}
257-
item.setEnergy(headStack, item.getEnergy(headStack) + production * 8);
258260
}
259-
260261
}
261262
}
262263
}

src/main/java/mekanism/common/moduleUpgrade.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package mekanism.common;
22

3-
import mekanism.api.EnumColor;
43
import mekanism.common.util.LangUtils;
54
import net.minecraft.nbt.NBTTagCompound;
65
import net.minecraft.nbt.NBTTagList;
@@ -14,32 +13,16 @@
1413
public enum moduleUpgrade {
1514

1615
// EMPTY("base",1,),
17-
EnergyUnit("EnergyUnit", 8, EnumColor.GREY);
16+
EnergyUnit("EnergyUnit", 8),
17+
SolarRechargingUnit("SolarRechargingUnit", 8);
1818

1919
private String name;
2020
private int maxStack;
21-
private EnumColor color;
2221

23-
moduleUpgrade(String s, int max, EnumColor c) {
22+
23+
moduleUpgrade(String s, int max) {
2424
name = s;
2525
maxStack = max;
26-
color = c;
27-
}
28-
29-
public String getName() {
30-
return name;
31-
}
32-
33-
public String getDescription() {
34-
return LangUtils.localize("module." + name + ".desc");
35-
}
36-
37-
public int getMax() {
38-
return maxStack;
39-
}
40-
41-
public EnumColor getColor() {
42-
return color;
4326
}
4427

4528
public static Map<moduleUpgrade, Integer> buildMap(@Nullable NBTTagCompound nbtTags) {
@@ -57,7 +40,6 @@ public static Map<moduleUpgrade, Integer> buildMap(@Nullable NBTTagCompound nbtT
5740
return modules;
5841
}
5942

60-
6143
public static void saveMap(Map<moduleUpgrade, Integer> module, NBTTagCompound nbtTags) {
6244
NBTTagList list = new NBTTagList();
6345
for (Entry<moduleUpgrade, Integer> entry : module.entrySet()) {
@@ -73,4 +55,16 @@ public static NBTTagCompound getTagFor(moduleUpgrade module, int amount) {
7355
return compound;
7456
}
7557

58+
public String getName() {
59+
return name;
60+
}
61+
62+
public String getDescription() {
63+
return LangUtils.localize("module." + name + ".desc");
64+
}
65+
66+
public int getMax() {
67+
return maxStack;
68+
}
69+
7670
}

0 commit comments

Comments
 (0)