From b0d7b16da38d363465cb74992d156181f333f353 Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 29 Jun 2022 17:00:24 +0200 Subject: [PATCH] NTL storage manifest, a bit more compat --- .../java/api/hbm/ntl/EnumStorageType.java | 6 ++ .../java/api/hbm/ntl/IStorageComponent.java | 29 +++++++ .../java/api/hbm/ntl/StorageManifest.java | 46 ++++++++++ src/main/java/api/hbm/ntl/StorageStack.java | 27 ++++++ .../com/hbm/config/FalloutConfigJSON.java | 4 +- .../hbm/entity/effect/EntityFalloutRain.java | 79 +++++------------- .../java/com/hbm/handler/HazmatRegistry.java | 20 +---- src/main/java/com/hbm/util/Compat.java | 39 +++++++++ .../blocks/mass_storage_side_iron.png | Bin 0 -> 285 bytes .../textures/blocks/mass_storage_top_iron.png | Bin 0 -> 292 bytes 10 files changed, 174 insertions(+), 76 deletions(-) create mode 100644 src/main/java/api/hbm/ntl/EnumStorageType.java create mode 100644 src/main/java/api/hbm/ntl/IStorageComponent.java create mode 100644 src/main/java/api/hbm/ntl/StorageManifest.java create mode 100644 src/main/java/api/hbm/ntl/StorageStack.java create mode 100644 src/main/resources/assets/hbm/textures/blocks/mass_storage_side_iron.png create mode 100644 src/main/resources/assets/hbm/textures/blocks/mass_storage_top_iron.png diff --git a/src/main/java/api/hbm/ntl/EnumStorageType.java b/src/main/java/api/hbm/ntl/EnumStorageType.java new file mode 100644 index 000000000..287f18c77 --- /dev/null +++ b/src/main/java/api/hbm/ntl/EnumStorageType.java @@ -0,0 +1,6 @@ +package api.hbm.ntl; + +public enum EnumStorageType { + CLUTTER, //potentially unsorted storage (like crates) with many slots that have low capacity + MASS //storage with very few lots (usually 1) and very high capacity +} diff --git a/src/main/java/api/hbm/ntl/IStorageComponent.java b/src/main/java/api/hbm/ntl/IStorageComponent.java new file mode 100644 index 000000000..adb46ead0 --- /dev/null +++ b/src/main/java/api/hbm/ntl/IStorageComponent.java @@ -0,0 +1,29 @@ +package api.hbm.ntl; + +import net.minecraft.item.ItemStack; + +public interface IStorageComponent { + + /** + * @return The type of storage this tile entity represents. + */ + public EnumStorageType getType(); + + /** + * @return A StorageManifest instance containing all managed stacks + */ + public StorageManifest getManifest(); + + /** + * @return An integer representing the version of the manifest. The higher the numberm, the more recent the manifest + * (i.e. always count up), the version has to change every time the manifest updates. + */ + public int getManifestVersion(); + + /** + * @param stack The stack to be stored + * @param simulate Whether the changes should actually be written or if the operation is only for checking + * @return The remainder of the stack after being stored, null if nothing remains + */ + public ItemStack storeStack(ItemStack stack, boolean simulate); +} diff --git a/src/main/java/api/hbm/ntl/StorageManifest.java b/src/main/java/api/hbm/ntl/StorageManifest.java new file mode 100644 index 000000000..3106dcb98 --- /dev/null +++ b/src/main/java/api/hbm/ntl/StorageManifest.java @@ -0,0 +1,46 @@ +package api.hbm.ntl; + +import java.util.HashMap; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class StorageManifest { + + public HashMap itemMeta = new HashMap(); + + public void writeStack(ItemStack stack) { + int id = Item.getIdFromItem(stack.getItem()); + + MetaNode meta = itemMeta.get(id); + + if(meta == null) { + meta = new MetaNode(); + itemMeta.put(id, meta); + } + + NBTNode nbt = meta.metaNBT.get(stack.getItemDamage()); + + if(nbt == null) { + nbt = new NBTNode(); + meta.metaNBT.put(stack.getItemDamage(), nbt); + } + + long amount = nbt.nbtAmount.containsKey(stack.stackTagCompound) ? nbt.nbtAmount.get(stack.stackTagCompound) : 0; + + amount += stack.stackSize; + + nbt.nbtAmount.put(stack.stackTagCompound, amount); + } + + public class MetaNode { + + public HashMap metaNBT = new HashMap(); + } + + public class NBTNode { + + public HashMap nbtAmount = new HashMap(); + } +} diff --git a/src/main/java/api/hbm/ntl/StorageStack.java b/src/main/java/api/hbm/ntl/StorageStack.java new file mode 100644 index 000000000..71fdd8b66 --- /dev/null +++ b/src/main/java/api/hbm/ntl/StorageStack.java @@ -0,0 +1,27 @@ +package api.hbm.ntl; + +import net.minecraft.item.ItemStack; + +public class StorageStack { + + private ItemStack type; + private long amount; + + public StorageStack(ItemStack type) { + this(type, type.stackSize); + } + + public StorageStack(ItemStack type, long amount) { + this.type = type.copy(); + this.amount = amount; + this.type.stackSize = 0; + } + + public ItemStack getType() { + return this.type.copy(); + } + + public long getAmount() { + return this.amount; + } +} diff --git a/src/main/java/com/hbm/config/FalloutConfigJSON.java b/src/main/java/com/hbm/config/FalloutConfigJSON.java index 79deb710d..2287a3b9d 100644 --- a/src/main/java/com/hbm/config/FalloutConfigJSON.java +++ b/src/main/java/com/hbm/config/FalloutConfigJSON.java @@ -164,11 +164,11 @@ public class FalloutConfigJSON { public FalloutEntry max(double max) { this.maxDist = max; return this; } public FalloutEntry sol(boolean solid) { this.isSolid = solid; return this; } - public boolean eval(World world, int x, int y, int z, Block b, double dist) { + public boolean eval(World world, int x, int y, int z, Block b, int meta, double dist) { if(matchesBlock != null && b != matchesBlock) return false; if(matchesMaterial != null && b.getMaterial() != matchesMaterial) return false; - if(matchesMeta != -1 && world.getBlockMetadata(x, y, z) != matchesMeta) return false; + if(matchesMeta != -1 && meta != matchesMeta) return false; if(matchesOpaque && !b.isOpaqueCube()) return false; if(dist > maxDist || dist < minDist) return false; diff --git a/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java b/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java index 82bcc3308..43e8e550f 100644 --- a/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java +++ b/src/main/java/com/hbm/entity/effect/EntityFalloutRain.java @@ -2,6 +2,8 @@ package com.hbm.entity.effect; import com.hbm.blocks.ModBlocks; import com.hbm.config.BombConfig; +import com.hbm.config.FalloutConfigJSON; +import com.hbm.config.FalloutConfigJSON.FalloutEntry; import com.hbm.config.VersatileConfig; import com.hbm.saveddata.AuxSavedData; import com.hbm.util.Tuple.Quintet; @@ -46,7 +48,6 @@ public class EntityFalloutRain extends Entity { if(firstTick) { if (chunksToProcess.isEmpty() && outerChunksToProcess.isEmpty()) gatherChunks(); - //initConversion(); firstTick = false; } @@ -130,6 +131,9 @@ public class EntityFalloutRain extends Entity { int depth = 0; for(int y = 255; y >= 0; y--) { + + if(depth >= 3) + return; Block b = worldObj.getBlock(x, y, z); Block ab = worldObj.getBlock(x, y + 1, z); @@ -152,6 +156,24 @@ public class EntityFalloutRain extends Entity { if(rand.nextInt(5) == 0) worldObj.setBlock(x, y + 1, z, Blocks.fire); } + + boolean eval = false; + + for(FalloutEntry entry : FalloutConfigJSON.entries) { + + if(entry.eval(worldObj, x, y, z, b, meta, dist)) { + if(entry.isSolid()) { + depth++; + } + + eval = true; + break; + } + } + + if(!eval && b.isNormalCube()) { + return; + } /*if (b == Blocks.leaves || b == Blocks.leaves2) { worldObj.setBlock(x, y, z, Blocks.air); @@ -244,24 +266,6 @@ public class EntityFalloutRain extends Entity { }*/ } } - - /*public HashMap directConversions = new HashMap(); - - private void initConversion() { - - directConversions.put(Blocks.stone, new BlockConversion() { @Override public boolean convert() { - if(dist < 5) set(ModBlocks.sellafield_1); - else if(dist < 15) set(ModBlocks.sellafield_0); - else if(dist < 75) set(ModBlocks.sellafield_slaked); - return true; - } - }); - - directConversions.put(Blocks.grass, new BlockConversion() { boolean convert() { set(ModBlocks.waste_earth); return false; }}); - directConversions.put(Blocks.mycelium, new BlockConversion() { boolean convert() { set(ModBlocks.waste_mycelium); return false; }}); - directConversions.put(Blocks.leaves, new BlockConversion() { boolean convert() { destroy(); return false; }}); - directConversions.put(Blocks.leaves2, new BlockConversion() { boolean convert() { destroy(); return false; }}); - }*/ @Override protected void entityInit() { @@ -311,41 +315,4 @@ public class EntityFalloutRain extends Entity { int scale = this.dataWatcher.getWatchableObjectInt(16); return scale == 0 ? 1 : scale; } - - /*private abstract class BlockConversion { - - protected World world; - protected int x; - protected int y; - protected int z; - protected double dist; - - public boolean invoke(World world, int x, int y, int z, double dist) { - this.world = world; - this.x = x; - this.y = y; - this.z = z; - this.dist = dist; - - return convert(); - } - - abstract boolean convert(); - - protected void destroy() { - world.setBlock(x, y, z, Blocks.air); - } - - protected void set(Block b) { - world.setBlock(x, y, z, b); - } - - protected void setChance(Block b, float f) { - if(world.rand.nextFloat() < f) world.setBlock(x, y, z, b); - } - - protected void setConditional(Block b, float f) { - if(world.rand.nextFloat() < f) world.setBlock(x, y, z, b); - } - }*/ } diff --git a/src/main/java/com/hbm/handler/HazmatRegistry.java b/src/main/java/com/hbm/handler/HazmatRegistry.java index 5fd370f7f..7e4e2c4d6 100644 --- a/src/main/java/com/hbm/handler/HazmatRegistry.java +++ b/src/main/java/com/hbm/handler/HazmatRegistry.java @@ -67,24 +67,6 @@ public class HazmatRegistry { HazmatRegistry.registerHazmat(ModItems.hazmat_legs_grey, hazGray * legs); HazmatRegistry.registerHazmat(ModItems.hazmat_boots_grey, hazGray * boots); - Item rec_helmet = Compat.tryLoadItem(Compat.MOD_REC, "reactorcraft_item_hazhelmet"); - Item rec_chest = Compat.tryLoadItem(Compat.MOD_REC, "reactorcraft_item_hazchest"); - Item rec_legs = Compat.tryLoadItem(Compat.MOD_REC, "reactorcraft_item_hazlegs"); - Item rec_boots = Compat.tryLoadItem(Compat.MOD_REC, "reactorcraft_item_hazboots"); - if(rec_helmet != null) HazmatRegistry.registerHazmat(rec_helmet, hazGray * helmet); - if(rec_chest != null) HazmatRegistry.registerHazmat(rec_chest, hazGray * chest); - if(rec_legs != null) HazmatRegistry.registerHazmat(rec_legs, hazGray * legs); - if(rec_boots != null) HazmatRegistry.registerHazmat(rec_boots, hazGray * boots); - - Item efn_helmet = Compat.tryLoadItem(Compat.MOD_EF, "netherite_helmet"); - Item efn_chest = Compat.tryLoadItem(Compat.MOD_EF, "netherite_chestplate"); - Item efn_legs = Compat.tryLoadItem(Compat.MOD_EF, "netherite_leggings"); - Item efn_boots = Compat.tryLoadItem(Compat.MOD_EF, "netherite_boots"); - if(efn_helmet != null) HazmatRegistry.registerHazmat(efn_helmet, star * helmet); - if(efn_chest != null) HazmatRegistry.registerHazmat(efn_chest, star * chest); - if(efn_legs != null) HazmatRegistry.registerHazmat(efn_legs, star * legs); - if(efn_boots != null) HazmatRegistry.registerHazmat(efn_boots, star * boots); - HazmatRegistry.registerHazmat(ModItems.liquidator_helmet, liquidator * helmet); HazmatRegistry.registerHazmat(ModItems.liquidator_plate, liquidator * chest); HazmatRegistry.registerHazmat(ModItems.liquidator_legs, liquidator * legs); @@ -204,6 +186,8 @@ public class HazmatRegistry { HazmatRegistry.registerHazmat(ModItems.euphemium_plate, euph * chest); HazmatRegistry.registerHazmat(ModItems.euphemium_legs, euph * legs); HazmatRegistry.registerHazmat(ModItems.euphemium_boots, euph * boots); + + Compat.registerCompatHazmat(); } private static HashMap entries = new HashMap(); diff --git a/src/main/java/com/hbm/util/Compat.java b/src/main/java/com/hbm/util/Compat.java index ed5eb304d..eb01a021b 100644 --- a/src/main/java/com/hbm/util/Compat.java +++ b/src/main/java/com/hbm/util/Compat.java @@ -3,6 +3,7 @@ package com.hbm.util; import java.util.ArrayList; import java.util.List; +import com.hbm.handler.HazmatRegistry; import com.hbm.hazard.HazardRegistry; import net.minecraft.item.Item; @@ -93,4 +94,42 @@ public class Compat { return stacks; } + + public static void registerCompatHazmat() { + + double helmet = 0.2D; + double chest = 0.4D; + double legs = 0.3D; + double boots = 0.1D; + + double p90 = 1.0D; // 90% + double p99 = 2D; // 99% + + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.radiation.head", p90 * helmet); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.radiation.chest", p90 * chest); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.radiation.legs", p90 * legs); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.radiation.boots", p90 * boots); + + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.universal.head", p99 * helmet); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.universal.chest", p99 * chest); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.universal.legs", p99 * legs); + tryRegisterHazmat(Compat.MOD_GT6, "gt.armor.hazmat.universal.boots", p99 * boots); + + tryRegisterHazmat(Compat.MOD_REC, "reactorcraft_item_hazhelmet", p99 * helmet); + tryRegisterHazmat(Compat.MOD_REC, "reactorcraft_item_hazchest", p99 * chest); + tryRegisterHazmat(Compat.MOD_REC, "reactorcraft_item_hazlegs", p99 * legs); + tryRegisterHazmat(Compat.MOD_REC, "reactorcraft_item_hazboots", p99 * boots); + + tryRegisterHazmat(Compat.MOD_EF, "netherite_helmet", p90 * helmet); + tryRegisterHazmat(Compat.MOD_EF, "netherite_chestplate", p90 * chest); + tryRegisterHazmat(Compat.MOD_EF, "netherite_leggings", p90 * legs); + tryRegisterHazmat(Compat.MOD_EF, "netherite_boots", p90 * boots); + } + + private static void tryRegisterHazmat(String mod, String name, double resistance) { + Item item = Compat.tryLoadItem(mod, name); + if(item != null) { + HazmatRegistry.registerHazmat(item, resistance); + } + } } diff --git a/src/main/resources/assets/hbm/textures/blocks/mass_storage_side_iron.png b/src/main/resources/assets/hbm/textures/blocks/mass_storage_side_iron.png new file mode 100644 index 0000000000000000000000000000000000000000..77e1dd359cc22133375ac70faa1ec4081421571b GIT binary patch literal 285 zcmV+&0pk9NP)-w?iPV+pU1_0Z({nc#Agul2f%d2K7rHe(lIgX=? z^E`L4C2X4JQXd&;t)nJ@<2aHukwH~e(e%*FH@zj$T9aj2)DRJb@BTy(t|gCP2}0!5 zbfwh$J4l&65`=f~`W3paOBUYgVj!i&7{f3O0JLojaLJ3JxEiE>TUnO3c~~#t{8hf} j+1GV-xl)R0nxbJpl@e+$l}r+w00000NkvXXu0mjfe*Ac3 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/hbm/textures/blocks/mass_storage_top_iron.png b/src/main/resources/assets/hbm/textures/blocks/mass_storage_top_iron.png new file mode 100644 index 0000000000000000000000000000000000000000..62c59cfded372c973f5032fd2d737d0c2e4b18e9 GIT binary patch literal 292 zcmV+<0o(qGP)2%k z0RUR-;A7@s_kAD5X956F*ENVJtk3eCb6IRAptS}OVOf@t1vA4Kll6(2QI#@~LQT^| z<)l>UyGw{Dx>fe#vIJ&^_a4lQbzLK0inX@fL;x_x1pDrf6a}1fkEve@r0@JhBp`p- qYk{X}layi=a7>k?RI|0VDEb2n=w!+MV@Y=a0000