Fixed potential NPEs and added @Nonnull and @Nullable annotations
This commit is contained in:
@@ -17,6 +17,7 @@ import exopandora.worldhandler.gui.widget.IContainerWidget.EnumLayer;
|
||||
import exopandora.worldhandler.gui.widget.WidgetCommandSyntax;
|
||||
import exopandora.worldhandler.gui.widget.WidgetNameField;
|
||||
import exopandora.worldhandler.gui.widget.WidgetShortcuts;
|
||||
import exopandora.worldhandler.gui.widget.WidgetTabRenderer;
|
||||
import exopandora.worldhandler.gui.widget.WidgetWatch;
|
||||
import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip;
|
||||
import exopandora.worldhandler.util.ActionHelper;
|
||||
|
||||
@@ -23,9 +23,11 @@ import exopandora.worldhandler.util.CommandHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
@@ -115,18 +117,24 @@ public class ContentButcher extends Content
|
||||
slaughter.active = enabled;
|
||||
}
|
||||
|
||||
public static void slaughter(String player, Collection<EntityType<?>> entities, int radius)
|
||||
public static void slaughter(String username, Collection<EntityType<?>> entities, int radius)
|
||||
{
|
||||
AxisAlignedBB aabb = new AxisAlignedBB(Minecraft.getInstance().player.getPosition()).grow(radius);
|
||||
PlayerEntity player = Minecraft.getInstance().player;
|
||||
World world = Minecraft.getInstance().world;
|
||||
|
||||
for(EntityType<?> entity : entities)
|
||||
if(player != null && world != null)
|
||||
{
|
||||
List<? extends Entity> targets = Minecraft.getInstance().world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
|
||||
targets.removeIf(target -> Minecraft.getInstance().player.equals(target));
|
||||
AxisAlignedBB aabb = new AxisAlignedBB(player.getPosition()).grow(radius);
|
||||
|
||||
if(!targets.isEmpty())
|
||||
for(EntityType<?> entity : entities)
|
||||
{
|
||||
CommandHelper.sendCommand(player, new BuilderButcher(entity.getRegistryName(), radius));
|
||||
List<? extends Entity> targets = world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
|
||||
targets.removeIf(target -> player.equals(target));
|
||||
|
||||
if(!targets.isEmpty())
|
||||
{
|
||||
CommandHelper.sendCommand(username, new BuilderButcher(entity.getRegistryName(), radius));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,11 @@ public class ContentChangeWorld extends ContentChild
|
||||
return new IntegratedConnection(folder, worldSettings, dimensionGeneratorSettings);
|
||||
}
|
||||
|
||||
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
|
||||
Minecraft.getInstance().unloadWorld();
|
||||
if(Minecraft.getInstance().world != null)
|
||||
{
|
||||
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
|
||||
Minecraft.getInstance().unloadWorld();
|
||||
}
|
||||
|
||||
if(isRealms)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
|
||||
@@ -240,7 +242,12 @@ public class ContentCommandStack extends ContentChild
|
||||
|
||||
private void setCommand(int index, String command)
|
||||
{
|
||||
this.builderCommandStack.getPassenger(index + HEAD_LENGTH).setCommand(command);
|
||||
EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH);
|
||||
|
||||
if(entity != null)
|
||||
{
|
||||
entity.setCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCommand(int index)
|
||||
@@ -253,9 +260,17 @@ public class ContentCommandStack extends ContentChild
|
||||
this.builderCommandStack.removePassenger(index + HEAD_LENGTH);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getCommand(int index)
|
||||
{
|
||||
return this.builderCommandStack.getPassenger(index + HEAD_LENGTH).getCommand();
|
||||
EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH);
|
||||
|
||||
if(entity != null)
|
||||
{
|
||||
return entity.getCommand();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getCommandCount()
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -211,7 +212,14 @@ public class ContentNoteEditor extends Content
|
||||
|
||||
private SoundEvent getSoundEvent(BlockPos blockPos)
|
||||
{
|
||||
return NoteBlockInstrument.byState(Minecraft.getInstance().world.getBlockState(blockPos)).getSound();
|
||||
World world = Minecraft.getInstance().world;
|
||||
|
||||
if(world != null)
|
||||
{
|
||||
return NoteBlockInstrument.byState(world.getBlockState(blockPos)).getSound();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,8 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.AbstractGui;
|
||||
import net.minecraft.client.gui.screen.inventory.InventoryScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
@@ -119,11 +120,13 @@ public class ContentPlayer extends Content
|
||||
|
||||
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.position.copy_position"), () ->
|
||||
{
|
||||
int posX = MathHelper.floor(Minecraft.getInstance().player.getPosX());
|
||||
int posY = MathHelper.floor(Minecraft.getInstance().player.getPosY());
|
||||
int posZ = MathHelper.floor(Minecraft.getInstance().player.getPosZ());
|
||||
PlayerEntity player = Minecraft.getInstance().player;
|
||||
|
||||
Minecraft.getInstance().keyboardListener.setClipboardString(posX + " " + posY + " " + posZ);
|
||||
if(player != null)
|
||||
{
|
||||
BlockPos position = player.getPosition();
|
||||
Minecraft.getInstance().keyboardListener.setClipboardString(position.getX() + " " + position.getY() + " " + position.getZ());
|
||||
}
|
||||
}));
|
||||
}
|
||||
else if(Page.MISC.equals(this.page))
|
||||
@@ -152,18 +155,25 @@ public class ContentPlayer extends Content
|
||||
@Override
|
||||
public void tick(Container container)
|
||||
{
|
||||
this.posXField.setText("X: " + MathHelper.floor(Minecraft.getInstance().player.getPosX()));
|
||||
this.posYField.setText("Y: " + MathHelper.floor(Minecraft.getInstance().player.getPosY()));
|
||||
this.posZField.setText("Z: " + MathHelper.floor(Minecraft.getInstance().player.getPosZ()));
|
||||
this.scoreField.setText(I18n.format("gui.worldhandler.entities.player.score") + ": " + Minecraft.getInstance().player.getScore());
|
||||
this.coinsField.setText(I18n.format("gui.worldhandler.entities.player.score.experience") + ": " + Minecraft.getInstance().player.experienceLevel + "L");
|
||||
this.xpField.setText(I18n.format("gui.worldhandler.entities.player.score.experience_coins") + ": " + Minecraft.getInstance().player.experienceTotal);
|
||||
PlayerEntity player = Minecraft.getInstance().player;
|
||||
|
||||
if(player != null)
|
||||
{
|
||||
BlockPos position = player.getPosition();
|
||||
|
||||
this.posXField.setText("X: " + position.getX());
|
||||
this.posYField.setText("Y: " + position.getY());
|
||||
this.posZField.setText("Z: " + position.getZ());
|
||||
this.scoreField.setText(I18n.format("gui.worldhandler.entities.player.score") + ": " + player.getScore());
|
||||
this.coinsField.setText(I18n.format("gui.worldhandler.entities.player.score.experience") + ": " + player.experienceLevel + "L");
|
||||
this.xpField.setText(I18n.format("gui.worldhandler.entities.player.score.experience_coins") + ": " + player.experienceTotal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(MatrixStack matrix, Container container, int x, int y, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
if(Page.START.equals(this.page))
|
||||
if(Page.START.equals(this.page) && Minecraft.getInstance().player != null)
|
||||
{
|
||||
int xPos = x + 175;
|
||||
int yPos = y + 82;
|
||||
|
||||
@@ -147,12 +147,22 @@ public class ContentWorldInfo extends Content
|
||||
|
||||
private void updateCurrentTime()
|
||||
{
|
||||
this.currentTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.world_time") + ": " + TextUtils.formatWorldTime(Minecraft.getInstance().world.getWorldInfo().getDayTime()));
|
||||
World world = Minecraft.getInstance().world;
|
||||
|
||||
if(world != null)
|
||||
{
|
||||
this.currentTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.world_time") + ": " + TextUtils.formatWorldTime(world.getWorldInfo().getDayTime()));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTotalTime()
|
||||
{
|
||||
this.totalTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.played") + ": " + TextUtils.formatTotalTime(Minecraft.getInstance().world.getWorldInfo().getGameTime()));
|
||||
World world = Minecraft.getInstance().world;
|
||||
|
||||
if(world != null)
|
||||
{
|
||||
this.totalTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.played") + ": " + TextUtils.formatTotalTime(world.getWorldInfo().getGameTime()));
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> String format(T object, Function<T, Object> function)
|
||||
|
||||
@@ -106,7 +106,10 @@ public class GuiButtonPiano extends GuiButtonBase
|
||||
@Override
|
||||
public void playDownSound(SoundHandler soundHandler)
|
||||
{
|
||||
soundHandler.play(SimpleSound.master(this.sound, this.pitch));
|
||||
if(this.sound != null)
|
||||
{
|
||||
soundHandler.play(SimpleSound.master(this.sound, this.pitch));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isHoveringBlack(double mouseX, double mouseY)
|
||||
|
||||
Reference in New Issue
Block a user