Fix various NPE with the matter clusters (#44)

This commit is contained in:
Alexdoru authored and GitHub committed 2024-10-11 11:47:24 +02:00
1 parent 0d3bb47272
commit b8571dbd5d
10 files changed
+74 -94

No files matched your search

@@ -1,7 +1,5 @@
package fox.spiteful.avaritia;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ChatComponentTranslation;
@@ -10,19 +8,17 @@ import net.minecraft.util.IChatComponent;
public class DamageSourceInfinitySword extends EntityDamageSource {
private static final Random randy = new Random();
public DamageSourceInfinitySword(Entity source) {
super("infinity", source);
}
@Override
public IChatComponent func_151519_b(EntityLivingBase p_151519_1_) { // getDeathMessage
public IChatComponent func_151519_b(EntityLivingBase entity) { // getDeathMessage
String s = "death.attack.infinity";
int rando = randy.nextInt(5);
int rando = entity.worldObj.rand.nextInt(5);
if (rando != 0) s = s + "." + rando;
// func_145748_c_ = getFormattedCommandSenderName
return new ChatComponentTranslation(s, p_151519_1_.func_145748_c_(), this.damageSourceEntity.func_145748_c_());
return new ChatComponentTranslation(s, entity.func_145748_c_(), this.damageSourceEntity.func_145748_c_());
}
@Override
@@ -5,7 +5,6 @@ import static net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@@ -39,7 +38,6 @@ import fox.spiteful.avaritia.items.tools.ToolHelper;
public class LudicrousEvents {
private static Random randy = new Random();
static final String[] trash = new String[] { "dirt", "sand", "gravel", "cobblestone", "netherrack" };
@SubscribeEvent
@@ -66,7 +64,7 @@ public class LudicrousEvents {
event.entityPlayer);
} else {
if (block.quantityDropped(randy) == 0) {
if (block.quantityDropped(event.world.rand) == 0) {
ItemStack drop = block.getPickBlock(
ToolHelper.raytraceFromEntity(event.world, event.entityPlayer, true, 10),
event.world,
@@ -168,9 +166,9 @@ public class LudicrousEvents {
public static void dropItem(ItemStack drop, World world, int x, int y, int z) {
float f = 0.7F;
double d0 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(world, (double) x + d0, (double) y + d1, (double) z + d2, drop);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
@@ -1,7 +1,5 @@
package fox.spiteful.avaritia.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@@ -25,7 +23,6 @@ import fox.spiteful.avaritia.tile.TileEntityCompressor;
public class BlockCompressor extends BlockContainer {
private IIcon top, sides, front;
private Random randy = new Random();
public BlockCompressor() {
super(Material.iron);
@@ -104,12 +101,12 @@ public class BlockCompressor extends BlockContainer {
ItemStack itemstack = compressor.getStackInSlot(i);
if (itemstack != null) {
float f = this.randy.nextFloat() * 0.8F + 0.1F;
float f1 = this.randy.nextFloat() * 0.8F + 0.1F;
float f2 = this.randy.nextFloat() * 0.8F + 0.1F;
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int j1 = this.randy.nextInt(21) + 10;
int j1 = world.rand.nextInt(21) + 10;
if (j1 > itemstack.stackSize) {
j1 = itemstack.stackSize;
@@ -118,9 +115,9 @@ public class BlockCompressor extends BlockContainer {
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(
world,
(double) ((float) x + f),
(double) ((float) y + f1),
(double) ((float) z + f2),
(float) x + f,
(float) y + f1,
(float) z + f2,
new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound()) {
@@ -129,9 +126,9 @@ public class BlockCompressor extends BlockContainer {
}
float f3 = 0.05F;
entityitem.motionX = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionY = (double) ((float) this.randy.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
}
}
@@ -1,7 +1,5 @@
package fox.spiteful.avaritia.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@@ -22,7 +20,6 @@ import fox.spiteful.avaritia.tile.TileEntityDireCrafting;
public class BlockDireCrafting extends BlockContainer {
private static IIcon top, sides, bottom;
private Random randy = new Random();
public BlockDireCrafting() {
super(Material.iron);
@@ -74,12 +71,12 @@ public class BlockDireCrafting extends BlockContainer {
ItemStack itemstack = craft.getStackInSlot(i);
if (itemstack != null) {
float f = this.randy.nextFloat() * 0.8F + 0.1F;
float f1 = this.randy.nextFloat() * 0.8F + 0.1F;
float f2 = this.randy.nextFloat() * 0.8F + 0.1F;
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int j1 = this.randy.nextInt(21) + 10;
int j1 = world.rand.nextInt(21) + 10;
if (j1 > itemstack.stackSize) {
j1 = itemstack.stackSize;
@@ -88,9 +85,9 @@ public class BlockDireCrafting extends BlockContainer {
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(
world,
(double) ((float) x + f),
(double) ((float) y + f1),
(double) ((float) z + f2),
(float) x + f,
(float) y + f1,
(float) z + f2,
new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound()) {
@@ -99,9 +96,9 @@ public class BlockDireCrafting extends BlockContainer {
}
float f3 = 0.05F;
entityitem.motionX = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionY = (double) ((float) this.randy.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
}
}
@@ -1,7 +1,5 @@
package fox.spiteful.avaritia.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@@ -25,7 +23,6 @@ import fox.spiteful.avaritia.tile.TileEntityNeutron;
public class BlockNeutronCollector extends BlockContainer {
private IIcon top, sides, front;
private Random randy = new Random();
public BlockNeutronCollector() {
super(Material.iron);
@@ -103,12 +100,12 @@ public class BlockNeutronCollector extends BlockContainer {
ItemStack itemstack = collector.getStackInSlot(0);
if (itemstack != null) {
float f = this.randy.nextFloat() * 0.8F + 0.1F;
float f1 = this.randy.nextFloat() * 0.8F + 0.1F;
float f2 = this.randy.nextFloat() * 0.8F + 0.1F;
float f = world.rand.nextFloat() * 0.8F + 0.1F;
float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int j1 = this.randy.nextInt(21) + 10;
int j1 = world.rand.nextInt(21) + 10;
if (j1 > itemstack.stackSize) {
j1 = itemstack.stackSize;
@@ -117,9 +114,9 @@ public class BlockNeutronCollector extends BlockContainer {
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(
world,
(double) ((float) x + f),
(double) ((float) y + f1),
(double) ((float) z + f2),
(float) x + f,
(float) y + f1,
(float) z + f2,
new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound()) {
@@ -127,9 +124,9 @@ public class BlockNeutronCollector extends BlockContainer {
}
float f3 = 0.05F;
entityitem.motionX = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionY = (double) ((float) this.randy.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double) ((float) this.randy.nextGaussian() * f3);
entityitem.motionX = (float) world.rand.nextGaussian() * f3;
entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
world.spawnEntityInWorld(entityitem);
}
}
@@ -1,7 +1,5 @@
package fox.spiteful.avaritia.compat.ticon;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
@@ -24,8 +22,6 @@ import tconstruct.library.tools.ToolCore;
public class TonkersEvents {
private Random randy = new Random();
@SubscribeEvent
public void craftTool(ToolCraftEvent.NormalTool event) {
NBTTagCompound toolTag = event.toolTag.getCompoundTag("InfiTool");
@@ -142,7 +138,7 @@ public class TonkersEvents {
if (toolTag != null && toolTag.getInteger("Head") == Tonkers.infinityMetalId
&& tool.canHarvestBlock(Blocks.stone, held)) {
if (block.quantityDropped(randy) == 0) {
if (block.quantityDropped(event.world.rand) == 0) {
ItemStack drop = block.getPickBlock(
ToolHelper.raytraceFromEntity(event.world, event.entityPlayer, true, 10),
event.world,
@@ -1,7 +1,6 @@
package fox.spiteful.avaritia.entity;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.command.IEntitySelector;
@@ -16,7 +15,6 @@ import net.minecraft.world.World;
public class EntityGapingVoid extends Entity {
private static Random randy = new Random();
public static final int maxLifetime = 186;
public static double collapse = .95;
public static double suckrange = 20.0;
@@ -96,8 +94,8 @@ public class EntityGapingVoid extends Entity {
double size = getVoidScale(age) * 0.5 - 0.2;
for (int i = 0; i < 50; i++) {
Vec3 pootdir = Vec3.createVectorHelper(0, 0, size);
pootdir.rotateAroundY(randy.nextFloat() * 180f);
pootdir.rotateAroundX(randy.nextFloat() * 360f);
pootdir.rotateAroundY(rand.nextFloat() * 180f);
pootdir.rotateAroundX(rand.nextFloat() * 360f);
Vec3 pootspeed = pootdir.normalize();
pootspeed.xCoord *= particlespeed;
@@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -29,8 +28,6 @@ import fox.spiteful.avaritia.render.ICosmicRenderItem;
public class ItemMatterCluster extends Item implements ICosmicRenderItem {
protected static Random randy = new Random();
public static final String MAINTAG = "clusteritems";
public static final String LISTTAG = "items";
public static final String ITEMTAG = "item";
@@ -85,12 +82,15 @@ public class ItemMatterCluster extends Item implements ICosmicRenderItem {
NBTTagCompound tag = list.getCompoundTagAt(i);
ItemStack countstack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag(ITEMTAG));
int count = tag.getInteger(COUNTTAG);
tooltip.add(
countstack.getItem().getRarity(countstack).rarityColor + countstack.getDisplayName()
+ EnumChatFormatting.GRAY
+ " x "
+ count);
if (countstack != null) {
tooltip.add(
countstack.getItem().getRarity(countstack).rarityColor + countstack.getDisplayName()
+ EnumChatFormatting.GRAY
+ " x "
+ count);
} else {
tooltip.add(EnumChatFormatting.RED + "DELETED" + EnumChatFormatting.GRAY + " x " + count);
}
}
} else {
tooltip.add(EnumChatFormatting.DARK_GRAY + StatCollector.translateToLocal("tooltip.matter_cluster.desc"));
@@ -102,12 +102,11 @@ public class ItemMatterCluster extends Item implements ICosmicRenderItem {
public static List<ItemStack> makeClusters(List<ItemStack> input) {
Map<ItemStackWrapper, Integer> items = ToolHelper.collateMatterCluster(input);
List<ItemStack> clusters = new ArrayList<ItemStack>();
List<Entry<ItemStackWrapper, Integer>> itemlist = new ArrayList<Entry<ItemStackWrapper, Integer>>();
itemlist.addAll(items.entrySet());
List<ItemStack> clusters = new ArrayList<>();
List<Entry<ItemStackWrapper, Integer>> itemlist = new ArrayList<>(items.entrySet());
int currentTotal = 0;
Map<ItemStackWrapper, Integer> currentItems = new HashMap<ItemStackWrapper, Integer>();
Map<ItemStackWrapper, Integer> currentItems = new HashMap<>();
while (!itemlist.isEmpty()) {
Entry<ItemStackWrapper, Integer> e = itemlist.get(0);
@@ -134,7 +133,7 @@ public class ItemMatterCluster extends Item implements ICosmicRenderItem {
clusters.add(cluster);
currentTotal = 0;
currentItems = new HashMap<ItemStackWrapper, Integer>();
currentItems = new HashMap<>();
}
}
@@ -159,15 +158,21 @@ public class ItemMatterCluster extends Item implements ICosmicRenderItem {
public static Map<ItemStackWrapper, Integer> getClusterData(ItemStack cluster) {
if (!cluster.hasTagCompound() || !cluster.getTagCompound().hasKey(MAINTAG)) {
return null;
return new HashMap<>();
}
NBTTagCompound tag = cluster.getTagCompound().getCompoundTag(MAINTAG);
NBTTagList list = tag.getTagList(LISTTAG, 10);
Map<ItemStackWrapper, Integer> data = new HashMap<ItemStackWrapper, Integer>();
Map<ItemStackWrapper, Integer> data = new HashMap<>();
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound entry = list.getCompoundTagAt(i);
ItemStackWrapper wrap = new ItemStackWrapper(ItemStack.loadItemStackFromNBT(entry.getCompoundTag(ITEMTAG)));
final ItemStack stack = ItemStack.loadItemStackFromNBT(entry.getCompoundTag(ITEMTAG));
if (stack == null) {
// item might be null if the cluster contains items that don't exist
// anymore by removing a mod for example
continue;
}
ItemStackWrapper wrap = new ItemStackWrapper(stack);
int count = entry.getInteger(COUNTTAG);
data.put(wrap, count);
}
@@ -211,8 +216,7 @@ public class ItemMatterCluster extends Item implements ICosmicRenderItem {
Map<ItemStackWrapper, Integer> donordata = getClusterData(donor);
Map<ItemStackWrapper, Integer> recipientdata = getClusterData(recipient);
List<Entry<ItemStackWrapper, Integer>> datalist = new ArrayList<Entry<ItemStackWrapper, Integer>>();
datalist.addAll(donordata.entrySet());
List<Entry<ItemStackWrapper, Integer>> datalist = new ArrayList<>(donordata.entrySet());
while (recipientcount < capacity && donorcount > 0) {
Entry<ItemStackWrapper, Integer> e = datalist.get(0);
@@ -13,7 +13,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.WeakHashMap;
@@ -42,10 +41,8 @@ public class ToolHelper {
public static Material[] materialsAxe = new Material[] { Material.coral, Material.leaves, Material.plants,
Material.wood, Material.vine };
private static Random randy = new Random();
public static Set<EntityPlayer> hammering = new HashSet<EntityPlayer>();
public static Map<EntityPlayer, List<ItemStack>> hammerdrops = new WeakHashMap<EntityPlayer, List<ItemStack>>();
public static Set<EntityPlayer> hammering = new HashSet<>();
public static Map<EntityPlayer, List<ItemStack>> hammerdrops = new WeakHashMap<>();
public static void removeBlocksInIteration(EntityPlayer player, ItemStack stack, World world, int x, int y, int z,
int xs, int ys, int zs, int xe, int ye, int ze, Block block, Material[] materialsListing, boolean silk,
@@ -53,7 +50,7 @@ public class ToolHelper {
float blockHardness = block == null ? 1F : block.getBlockHardness(world, x, y, z);
if (!hammerdrops.containsKey(player) || hammerdrops.get(player) == null) {
hammerdrops.put(player, new ArrayList<ItemStack>());
hammerdrops.put(player, new ArrayList<>());
}
if (!hammering.contains(player)) {
@@ -129,7 +126,7 @@ public class ToolHelper {
if (!dispose) {
if (blk.getPlayerRelativeBlockHardness(player, world, x, y, z) < 0
&& blk.quantityDropped(randy) == 0) {
&& blk.quantityDropped(world.rand) == 0) {
ItemStack drop = blk
.getPickBlock(raytraceFromEntity(world, player, true, 10), world, x, y, z, player);
if (drop == null) drop = new ItemStack(blk, 1, meta);
@@ -171,9 +168,9 @@ public class ToolHelper {
public static void dropItem(ItemStack drop, World world, int x, int y, int z) {
float f = 0.7F;
double d0 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (randy.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(world, (double) x + d0, (double) y + d1, (double) z + d2, drop);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
@@ -184,8 +181,8 @@ public class ToolHelper {
}
public static List<ItemStack> collateMatterClusterContents(Map<ItemStackWrapper, Integer> input) {
List<ItemStack> collated = new ArrayList<ItemStack>();
List<ItemStack> collated = new ArrayList<>();
if (input == null) return collated;
for (Entry<ItemStackWrapper, Integer> e : input.entrySet()) {
int count = e.getValue();
ItemStackWrapper wrap = e.getKey();
@@ -211,7 +208,7 @@ public class ToolHelper {
}
public static Map<ItemStackWrapper, Integer> collateMatterCluster(List<ItemStack> input) {
Map<ItemStackWrapper, Integer> counts = new HashMap<ItemStackWrapper, Integer>();
Map<ItemStackWrapper, Integer> counts = new HashMap<>();
if (input != null) {
for (ItemStack stack : input) {
@@ -76,7 +76,7 @@ tooltip.infinity_ingot.desc=The fury of the universe in the palm of your hand.
tooltip.record_fragment.desc=One likes to believe in the freedom of music~
tooltip.starfuel.desc=The light of the cosmos in a convenient chunk of earth
tooltip.skullfire_sword.desc=Beheads skeletons and scorches them black.
tooltip.matter_cluster.desc=Use to deconstruct.
tooltip.matter_cluster.desc=Right click to deconstruct.
tooltip.matter_cluster.desc2=Hold SHIFT for contents.
tooltip.matter_cluster.counter=items
tooltip.morvinabox.desc=Instant housing