mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 07:22:20 +00:00
Merge pull request #254 from Kirill Epifanov: code cleanup and null-safety fixes
This commit is contained in:
commit
f175e3fb82
22 files changed
+78
-57
No files matched your search
@@ -4,6 +4,8 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 3D Vector helper class for lightning calculations.
|
||||
* Adapted from Botania's Vector3 by ChickenBones.
|
||||
@@ -181,4 +183,9 @@ public class Vec3d {
|
||||
Vec3d v = (Vec3d) o;
|
||||
return x == v.x && y == v.y && z == v.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -550,14 +550,13 @@ public class NoppesUtilPlayer {
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||
return false;
|
||||
|
||||
|
||||
Quest quest = data.quest;
|
||||
if (quest == null)
|
||||
return false;
|
||||
|
||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||
return false;
|
||||
|
||||
if (data.quest.completion == EnumQuestCompletion.Instant)
|
||||
EventHooks.onPartyFinished(party, data.quest);
|
||||
|
||||
|
||||
@@ -343,11 +343,6 @@ public class NoppesUtilServer {
|
||||
sendOpenGui(player, gui, npc, 0, 0, 0);
|
||||
}
|
||||
|
||||
public static void sendOpenGuiNoDelay(EntityPlayer player,
|
||||
EnumGuiType gui, EntityNPCInterface npc) {
|
||||
sendOpenGuiNoDelay(player, gui, npc, 0, 0, 0);
|
||||
}
|
||||
|
||||
public static void sendOpenGui(final EntityPlayer player,
|
||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
@@ -369,28 +364,6 @@ public class NoppesUtilServer {
|
||||
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
|
||||
}
|
||||
|
||||
public static void sendOpenGuiNoDelay(final EntityPlayer player,
|
||||
final EnumGuiType gui, final EntityNPCInterface npc, final int i, final int j, final int k) {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
setEditingNpc(player, npc);
|
||||
sendExtraData(player, npc, gui, i, j, k);
|
||||
|
||||
if (CustomNpcs.proxy.getServerGuiElement(gui.ordinal(), player, player.worldObj, i, j, k) != null) {
|
||||
player.openGui(CustomNpcs.instance, gui.ordinal(), player.worldObj, i, j, k);
|
||||
return;
|
||||
} else {
|
||||
GuiOpenPacket.openGUI((EntityPlayerMP) player, gui, i, j, k);
|
||||
}
|
||||
ArrayList<String> list = getScrollData(player, gui, npc);
|
||||
if (list == null || list.isEmpty())
|
||||
return;
|
||||
|
||||
ScrollListPacket.sendList((EntityPlayerMP) player, list, EnumScrollData.OPTIONAL);
|
||||
}
|
||||
|
||||
|
||||
private static void sendExtraData(EntityPlayer player, EntityNPCInterface npc, EnumGuiType gui, int i, int j, int k) {
|
||||
if (gui == EnumGuiType.PlayerFollower || gui == EnumGuiType.PlayerFollowerHire || gui == EnumGuiType.PlayerTrader || gui == EnumGuiType.PlayerTransporter) {
|
||||
sendRoleData(player, npc);
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ServerEventsHandler {
|
||||
mounted = event.target;
|
||||
if (isRemote)
|
||||
CustomNpcs.proxy.openGui(MathHelper.floor_double(mounted.posX), MathHelper.floor_double(mounted.posY), MathHelper.floor_double(mounted.posZ), EnumGuiType.MobSpawnerMounter, event.entityPlayer);
|
||||
} else if (item.getItem() == CustomItems.wand && !isRemote && event.target instanceof EntityVillager) {
|
||||
} else if (item.getItem() == CustomItems.wand && event.target instanceof EntityVillager) {
|
||||
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.EDIT_VILLAGER))
|
||||
return;
|
||||
event.setCanceled(true);
|
||||
|
||||
@@ -40,7 +40,6 @@ public class BlockCampfire extends BlockLightable {
|
||||
ItemStack item = player.inventory.getCurrentItem();
|
||||
if (item == null)
|
||||
return true;
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if ((item.getItem() == Items.flint || item.getItem() == Items.flint_and_steel) && unlitBlock() == this) {
|
||||
super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
|
||||
|
||||
@@ -344,7 +344,6 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.shortLamp), new ItemShortLampRenderer());
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(CustomItems.tallLamp), new ItemTallLampRenderer());
|
||||
}
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
NPCButton = new KeyBinding("NPC Inventory", Keyboard.KEY_N, "key.categories.customnpc");
|
||||
SpecialKey = new KeyBinding("key.customnpcs.special", Keyboard.KEY_GRAVE, "key.categories.customnpc");
|
||||
@@ -712,9 +711,7 @@ public class ClientProxy extends CommonProxy {
|
||||
if (!player.worldObj.isRemote || !(guiscreen instanceof GuiScreen))
|
||||
return;
|
||||
|
||||
if (guiscreen != null) {
|
||||
minecraft.displayGuiScreen((GuiScreen) guiscreen);
|
||||
}
|
||||
minecraft.displayGuiScreen((GuiScreen) guiscreen);
|
||||
}
|
||||
|
||||
|
||||
@@ -809,8 +806,7 @@ public class ClientProxy extends CommonProxy {
|
||||
if (location == null)
|
||||
return;
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
if (location != null)
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
texturemanager.bindTexture((ResourceLocation) location);
|
||||
} catch (NullPointerException ex) {
|
||||
|
||||
} catch (ReportedException ex) {
|
||||
|
||||
@@ -257,10 +257,7 @@ public class ClientTickHandler {
|
||||
|
||||
if (player == null || mc.theWorld == null)
|
||||
return;
|
||||
|
||||
if (ClientHudManager.getInstance() == null || ClientHudManager.getInstance().getHudComponents() == null)
|
||||
return;
|
||||
|
||||
|
||||
// Update compass
|
||||
HudComponent compass = ClientHudManager.getInstance()
|
||||
.getHudComponents().get(EnumHudComponent.QuestCompass);
|
||||
|
||||
@@ -127,7 +127,6 @@ public class GuiNpcMobSpawnerMounter extends GuiNPCInterface implements IGuiData
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
this.list = ClientCloneController.Instance.getClones(activeTab);
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@ public class SubGuiNpcBiomes extends SubGuiInterface {
|
||||
if (scroll1.hasSelected()) {
|
||||
data.biomes.add(scroll1.getSelected());
|
||||
scroll1.selected = -1;
|
||||
scroll1.selected = -1;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,12 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface {
|
||||
|
||||
// Compute the repair status message based on container.repairCost and player's XP.
|
||||
String status = "";
|
||||
int textColor = CustomNpcResourceListener.DefaultTextColor;
|
||||
|
||||
if (container.repairCost > 0) {
|
||||
if (container.repairCost > mc.thePlayer.experienceTotal) {
|
||||
status = "Repair cost: " + container.repairCost + " XP";
|
||||
textColor = 0xFF0000; // red when not enough XP
|
||||
} else {
|
||||
status = "Repair cost: " + container.repairCost + " XP";
|
||||
}
|
||||
@@ -72,10 +75,6 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface {
|
||||
status = "Item is already fully repaired";
|
||||
}
|
||||
}
|
||||
int textColor = CustomNpcResourceListener.DefaultTextColor;
|
||||
if (container.repairCost > mc.thePlayer.experienceTotal) {
|
||||
textColor = 0xFF0000; // red when not enough XP
|
||||
}
|
||||
fontRendererObj.drawString(status, guiLeft + 5, guiTop + 75, textColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class JavaTextContainer extends TextContainer {
|
||||
public void init(String text, int width, int height) {
|
||||
this.text = text == null ? "" : text.replaceAll("\\r?\\n|\\r", "\n");
|
||||
lines.clear();
|
||||
String[] split = text.split("\n", -1);
|
||||
String[] split = this.text.split("\n", -1);
|
||||
|
||||
int totalChars = 0;
|
||||
for (String l : split) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class KeyPreset {
|
||||
@@ -187,6 +188,11 @@ public class KeyPreset {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash( currentState);
|
||||
}
|
||||
|
||||
public static class KeyState {
|
||||
public int keyCode = -1;
|
||||
public boolean hasCtrl, hasAlt, hasShift;
|
||||
@@ -235,6 +241,11 @@ public class KeyPreset {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(keyCode, hasCtrl, hasAlt, hasShift);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("keyCode", keyCode);
|
||||
|
||||
@@ -22,6 +22,9 @@ import noppes.npcs.client.model.ModelNPCMale;
|
||||
import noppes.npcs.constants.EnumAnimation;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.items.ItemClaw;
|
||||
import noppes.npcs.items.ItemRotatedShield;
|
||||
import noppes.npcs.items.ItemShield;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED;
|
||||
@@ -314,7 +317,7 @@ public class RenderNPCHumanMale extends RenderNPCInterface {
|
||||
|
||||
Class<?> clazz = itemstack2.getItem().getClass();
|
||||
boolean pluginMod = itemstack2.getItem().getUnlocalizedName().contains("plug:");
|
||||
if (clazz.getSimpleName().equals("ItemShield") || clazz.getSimpleName().equals("ItemRotatedShield") || clazz.getSimpleName().equals("ItemClaw"))
|
||||
if (clazz.equals(ItemShield.class) || clazz.equals(ItemRotatedShield.class) || clazz.equals(ItemClaw.class))
|
||||
GL11.glTranslatef(0.30f, 0, 0f);
|
||||
|
||||
if (itemstack2.getItem() instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemstack2.getItem()).getRenderType()))) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ScriptContainer implements IScriptUnit {
|
||||
private static final String lock = "lock";
|
||||
private static final Object lock = new Object();
|
||||
public static ScriptContainer Current;
|
||||
private static String CurrentType;
|
||||
public String fullscript = "";
|
||||
|
||||
@@ -62,7 +62,7 @@ public class EntityCustomNpc extends EntityNPCFlying {
|
||||
@Override
|
||||
public void updateHitbox() {
|
||||
Entity entity = modelData.getEntity(this);
|
||||
if (modelData == null || entity == null) {
|
||||
if (entity == null) {
|
||||
baseHeight = 1.9f - modelData.getBodyY() + (modelData.modelScale.head.scaleY - 1) / 2;
|
||||
super.updateHitbox();
|
||||
} else {
|
||||
|
||||
@@ -165,8 +165,6 @@ public class ModelDataShared implements IModelData {
|
||||
public float getBodyY() {
|
||||
if (legParts.type == 3)
|
||||
return (0.9f - modelScale.body.scaleY) * 0.75f + getLegsY();
|
||||
if (legParts.type == 3)
|
||||
return (0.5f - modelScale.body.scaleY) * 0.75f + getLegsY();
|
||||
return (1 - modelScale.body.scaleY) * 0.75f + getLegsY();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ItemNpcWand extends Item {
|
||||
par3World.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
|
||||
NoppesUtilServer.sendOpenGuiNoDelay(player, EnumGuiType.MainMenuDisplay, npc);
|
||||
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, npc);
|
||||
return true;
|
||||
} else
|
||||
player.addChatMessage(new ChatComponentTranslation("availability.permission"));
|
||||
|
||||
@@ -328,7 +328,7 @@ public class RoleCompanion extends RoleInterface {
|
||||
((CompanionTrader) jobInterface).interact(player);
|
||||
if (player != owner || !npc.isEntityAlive() || npc.isAttacking())
|
||||
return;
|
||||
if (player.isSneaking()) {
|
||||
if (player != null && player.isSneaking()) {
|
||||
openGui(player);
|
||||
} else {
|
||||
setSitting(!isSitting());
|
||||
|
||||
@@ -15,6 +15,8 @@ import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
import noppes.npcs.api.IWorld;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptBlock implements IBlock {
|
||||
protected IWorld world;
|
||||
protected Block block;
|
||||
@@ -224,4 +226,9 @@ public class ScriptBlock implements IBlock {
|
||||
((ScriptBlock) obj).getWorld() == this.getWorld() &&
|
||||
((ScriptBlock) obj).getPos().equals(this.getPos());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getWorld(), block, getPos());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.util.Vec3i;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import noppes.npcs.api.IPos;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ScriptBlockPos implements IPos {
|
||||
public BlockPos blockPos;
|
||||
|
||||
@@ -169,4 +171,9 @@ public class ScriptBlockPos implements IPos {
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof IPos && ((IPos) object).toLong() == this.toLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(blockPos);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
@@ -979,6 +980,14 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
return object instanceof IEntity && ((IEntity<?>) object).getMCEntity().equals(this.entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Must key on exactly what equals compares. tempData is mutable and swapped wholesale by
|
||||
// copyTempData, so including it would give two wrappers of the same entity different
|
||||
// hashes - and would change an entry's hash while it sat in a map.
|
||||
return Objects.hashCode(entity);
|
||||
}
|
||||
|
||||
public void updateEntity() {
|
||||
IWorld world = NpcAPI.Instance().getIWorld(entity.worldObj);
|
||||
entity.dimension = world.getDimensionID();
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class ScriptItemStack implements IItemStack {
|
||||
@@ -355,6 +356,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns whether this item is a book
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public boolean isWrittenBook() {
|
||||
return item.getItem() == Items.written_book || item.getItem() == Items.writable_book;
|
||||
}
|
||||
@@ -363,6 +365,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns the books title
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String getBookTitle() {
|
||||
return item.getTagCompound().getString("title");
|
||||
}
|
||||
@@ -371,6 +374,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return Returns the books author
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String getBookAuthor() {
|
||||
return item.getTagCompound().getString("author");
|
||||
}
|
||||
@@ -379,6 +383,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
* @return If the item is a book, returns a string array with book pages
|
||||
* @since 1.7.10d
|
||||
*/
|
||||
@Override
|
||||
public String[] getBookText() {
|
||||
if (!isWrittenBook())
|
||||
return null;
|
||||
@@ -399,6 +404,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
/**
|
||||
* @return Returns whether or not this item is a block
|
||||
*/
|
||||
@Override
|
||||
public boolean isBlock() {
|
||||
Block block = Block.getBlockFromItem(item.getItem());
|
||||
if (block == null || block == Blocks.air)
|
||||
@@ -415,6 +421,7 @@ public class ScriptItemStack implements IItemStack {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INbt getNbt() {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
@@ -424,18 +431,21 @@ public class ScriptItemStack implements IItemStack {
|
||||
return NpcAPI.Instance().getINbt(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INbt getItemNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.item.writeToNBT(compound);
|
||||
return NpcAPI.Instance().getINbt(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.item.writeToNBT(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMCNbt(NBTTagCompound compound) {
|
||||
}
|
||||
|
||||
@@ -444,18 +454,26 @@ public class ScriptItemStack implements IItemStack {
|
||||
*
|
||||
* @return Minecraft ItemStack
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getMCItemStack() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int itemHash() {
|
||||
return item.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object instanceof ScriptItemStack && ((ScriptItemStack) object).getMCItemStack().equals(this.getMCItemStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(IItemStack item, boolean ignoreNBT) {
|
||||
return NoppesUtilPlayer.compareItems(getMCItemStack(), item.getMCItemStack(), false, ignoreNBT);
|
||||
|
||||
Reference in new issue
Block a user