Merge pull request #2099 from Lazzzycatwastaken/structur

fix for Ticking entity crash when spawning skeletors with guns
This commit is contained in:
HbmMods 2025-04-22 08:21:28 +02:00 committed by GitHub
commit 334cffe04e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -417,7 +417,7 @@ public class ModEventHandler {
})); }));
ItemStack bowReplacement = getSkelegun(soot, world.rand); ItemStack bowReplacement = getSkelegun(soot, world.rand);
slotPools.put(0, createSlotPool(100, bowReplacement != null ? new Object[][]{{bowReplacement, 1}} : new Object[][]{})); slotPools.put(0, createSlotPool(50, bowReplacement != null ? new Object[][]{{bowReplacement, 1}} : new Object[][]{}));
} }
assignItemsToEntity(entity, slotPools); assignItemsToEntity(entity, slotPools);
} }
@ -429,15 +429,23 @@ public class ModEventHandler {
entity.setCurrentItemOrArmor(1, new ItemStack(boots)); entity.setCurrentItemOrArmor(1, new ItemStack(boots));
} }
private List<WeightedRandomObject> createSlotPool(int nullWeight, Object[][] items) { // nullWeight is the weight of the empty slot (no shit) private List<WeightedRandomObject> createSlotPool(int nullWeight, Object[][] items) {
List<WeightedRandomObject> pool = new ArrayList<>(); List<WeightedRandomObject> pool = new ArrayList<>();
pool.add(new WeightedRandomObject(null, nullWeight)); pool.add(new WeightedRandomObject(null, nullWeight));
for (Object[] item : items) { for (Object[] item : items) {
pool.add(new WeightedRandomObject(new ItemStack((Item) item[0]), (int) item[1])); Object obj = item[0];
int weight = (int) item[1];
if (obj instanceof Item) {
pool.add(new WeightedRandomObject(new ItemStack((Item) obj), weight));
} else if (obj instanceof ItemStack) { //lol just make it pass ItemStack aswell
pool.add(new WeightedRandomObject(obj, weight));
}
} }
return pool; return pool;
} }
private void assignItemsToEntity(EntityLivingBase entity, Map<Integer, List<WeightedRandomObject>> slotPools) { private void assignItemsToEntity(EntityLivingBase entity, Map<Integer, List<WeightedRandomObject>> slotPools) {
for (Map.Entry<Integer, List<WeightedRandomObject>> entry : slotPools.entrySet()) { for (Map.Entry<Integer, List<WeightedRandomObject>> entry : slotPools.entrySet()) {
int slot = entry.getKey(); int slot = entry.getKey();