Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed NPE in wearable packet #142

Merged
merged 2 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void removeSleepingBag(World world)
public int[] getAccessibleSlotsFromSide(int side)
{
if (GeneralReference.isDimensionAllowed(worldObj.provider.dimensionId))
return MAIN_INVENTORY_SLOTS;
return MAIN_INVENTORY_SLOTS.clone();

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void onRenderExperienceBar(RenderGameOverlayEvent.Post event)
}
if (Wearing.isWearingBackpack(player))
{
int u[] = {10, 10};
int v[] = {0, 0};
int[] u = {10, 10};
int[] v = {0, 0};
int[] xStart = {xPos, xPos + textureWidth + 1};
int[] yStart = {yPos, yPos};
short tank = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ModGuiConfig(GuiScreen guiScreen)

private static List<IConfigElement> getConfigElements()
{
List<IConfigElement> configElements = new ArrayList<IConfigElement>();
List<IConfigElement> configElements = new ArrayList<>();

List<String> topCategories = Arrays.asList("gameplay", "graphics", "sound", "items", "worldgen", "experimental");
for (String categoryName : topCategories)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void detectAndSendChanges()
requestedUpdate = false;
}

if ((detectItemChanges() | detectFluidChanges()))
if (detectItemChanges() | detectFluidChanges())
{
requestedUpdate = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,8 @@ private void makeSlots(InventoryPlayer invPlayer)
int startX = 62;
int startY = 7;
for (int row = 0; row < BACK_INV_ROWS; row++) // 6*8 inventory, 48 Slots (#1-#48) [36-83]
{
for (int col = 0; col < BACK_INV_COLUMNS; col++)
{
int offsetX = startX + (18 * col);
int offsetY = startY + (18 * row);

addSlotToContainer(new SlotBackpack((IInventoryBackpack) inventory, (row * BACK_INV_COLUMNS + col), offsetX, offsetY));
}
}
addSlotToContainer(new SlotBackpack(inventory, (row * BACK_INV_COLUMNS + col), (startX + 18 * col), (startY + 18 * row)));

addSlotToContainer(new SlotTool(inventory, TOOL_UPPER, 44, 79)); // #49 [84]
addSlotToContainer(new SlotTool(inventory, TOOL_LOWER, 44, 97)); // #50 [85]
Expand All @@ -82,17 +75,10 @@ private void makeSlots(InventoryPlayer invPlayer)
addSlotToContainer(new SlotFluid(inventory, BUCKET_OUT_RIGHT, 226, 37)); // #54 [89]

startX = 215;
startY = -2500;
//startY = LoadedMods.DEV_ENV ? 125 : -2500;
startY = -2500; //startY = LoadedMods.DEV_ENV ? 125 : -2500;
for (int row = 0; row < MATRIX_DIMENSION; row++) // craftMatrix, usually 9 slots, [90-98]
{
for (int col = 0; col < MATRIX_DIMENSION; col++)
{
int offsetX = startX + (18 * col);
int offsetY = startY + (18 * row);
addSlotToContainer(new SlotCraftMatrix(craftMatrix, (row * MATRIX_DIMENSION + col), offsetX, offsetY));
}
}
addSlotToContainer(new SlotCraftMatrix(craftMatrix, (row * MATRIX_DIMENSION + col), (startX + 18 * col), (startY + 18 * row)));

addSlotToContainer(new SlotCraftResult(this, invPlayer.player, craftMatrix, craftResult, 0, 226, 97)); // craftResult [99]
syncCraftMatrixWithInventory(true);
Expand Down Expand Up @@ -241,12 +227,9 @@ protected void dropContentOnClose()
public void onCraftMatrixChanged(IInventory inventory)
{
if (ConfigHandler.tinkerToolsMaintenance && TinkersUtils.isToolOrWeapon(craftMatrix.getStackInSlot(4)))
{
craftResult.setInventorySlotContents(0, TinkersUtils.getTinkersRecipe(craftMatrix));
return;
}

craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftMatrix, player.worldObj));
else
craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftMatrix, player.worldObj));
}

protected void syncCraftMatrixWithInventory(boolean preCraft)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.darkona.adventurebackpack.inventory;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -29,7 +30,7 @@ public class SlotBackpack extends SlotAdventure
// Project Red Exploration Backpacks
"mrtjp.projectred.exploration.ItemBackpack",};

SlotBackpack(IInventoryBackpack inventory, int slotIndex, int posX, int posY)
SlotBackpack(IInventory inventory, int slotIndex, int posX, int posY)
{
super(inventory, slotIndex, posX, posY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,11 @@ static boolean isFilled(ItemStack stack)
return FluidContainerRegistry.isFilledContainer(stack);
}

static boolean isBucket(ItemStack stack)
{
return FluidContainerRegistry.isBucket(stack);
}

static boolean isEmptyBucket(ItemStack stack)
{
return FluidContainerRegistry.isBucket(stack) && isEmpty(stack);
}

static boolean isFilledBucket(ItemStack stack)
{
return FluidContainerRegistry.isBucket(stack) && isFilled(stack);
}

static boolean isEqualFluid(ItemStack container, FluidTank tank)
{
return getFluidID(container) == getFluidID(tank);
}

static String getFluidName(ItemStack stack)
{
if (stack == null || isEmpty(stack))
return "";
return FluidContainerRegistry.getFluidForFilledItem(stack).getFluid().getName();
}

static String getFluidName(FluidTank tank)
{
if (tank == null || tank.getFluidAmount() <= 0)
return "";
return tank.getFluid().getFluid().getName();
}

static int getFluidID(ItemStack stack)
{
if (stack == null || isEmpty(stack))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.netty.buffer.ByteBuf;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
Expand Down Expand Up @@ -32,21 +33,22 @@ public IMessage onMessage(ActionMessage message, MessageContext ctx)
{
EntityPlayerMP player = ctx.getServerHandler().playerEntity;

if (player != null)
if (player != null && !player.isDead)
{
if (message.type == SPIDER_JUMP)
{
if (player.ridingEntity != null && player.ridingEntity instanceof EntityFriendlySpider)
if (player.ridingEntity instanceof EntityFriendlySpider)
{
((EntityFriendlySpider) player.ridingEntity).setJumping(true);
}
}

if (message.type == JETPACK_IN_USE || message.type == JETPACK_NOT_IN_USE)
{
if (Wearing.isWearingJetpack(player))
ItemStack jetpack = Wearing.getWearingJetpack(player);
if (jetpack != null)
{
InventoryCoalJetpack inv = new InventoryCoalJetpack(Wearing.getWearingJetpack(player));
InventoryCoalJetpack inv = new InventoryCoalJetpack(jetpack);
inv.setInUse(message.type == JETPACK_IN_USE);
inv.markDirty();
}
Expand Down Expand Up @@ -77,10 +79,7 @@ public static class ActionMessage implements IMessage
{
private byte type;

public ActionMessage()
{

}
public ActionMessage() {}

public ActionMessage(byte type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.netty.buffer.ByteBuf;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
Expand Down Expand Up @@ -31,24 +32,34 @@ public Message onMessage(Message message, MessageContext ctx)
{
EntityPlayerMP player = ctx.getServerHandler().playerEntity;

if (player != null)
if (player != null && !player.isDead)
{
if ((message.type == COPTER_ON_OFF || message.type == COPTER_TOGGLE))
ServerActions.toggleCopterPack(player, Wearing.getWearingCopter(player), message.type);

if (message.type == COPTER_ON_OFF || message.type == COPTER_TOGGLE)
{
ItemStack copter = Wearing.getWearingCopter(player);
// for concurrency reasons, at the time of death with OpenBlocks mod, the copter may already be
// in the grave, and Wearing#getWearingCopter will return null (c) Relvl
if (copter != null)
ServerActions.toggleCopterPack(player, copter, message.type);
}
if (message.type == JETPACK_ON_OFF)
ServerActions.toggleCoalJetpack(player, Wearing.getWearingJetpack(player));

if (message.type == CYCLING_ON_OFF)
ServerActions.toggleToolCycling(player, Wearing.getWearingBackpack(player));

if (message.type == NIGHTVISION_ON_OFF)
ServerActions.toggleNightVision(player, Wearing.getWearingBackpack(player));
{
ItemStack jetpack = Wearing.getWearingJetpack(player);
if (jetpack != null) // so now we are well-defended
ServerActions.toggleCoalJetpack(player, jetpack);
}
if (message.type == CYCLING_ON_OFF || message.type == NIGHTVISION_ON_OFF)
{
ItemStack backpack = Wearing.getWearingBackpack(player);
if (backpack != null) // null shall not pass!
{
if (message.type == CYCLING_ON_OFF)
ServerActions.toggleToolCycling(player, backpack);
if (message.type == NIGHTVISION_ON_OFF)
ServerActions.toggleNightVision(player, backpack);
}
}
}
}
if (ctx.side.isClient())
{

}
return null;
}
Expand All @@ -58,10 +69,7 @@ public static class Message implements IMessage
private byte type;
private String playerID;

public Message()
{

}
public Message() {}

public Message(byte type, String playerID)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public enum BackpackTypes

this.meta = (byte) meta;
this.skinName = skin.isEmpty() ? generateSkinName() : skin;
this.props = Sets.immutableEnumSet((Arrays.asList(props)));
this.props = Sets.immutableEnumSet(Arrays.asList(props));
}

BackpackTypes(int meta, Props... props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static boolean isContainerForFluid(ItemStack container, Fluid fluid)
if (data.fluid != null && data.fluid.getFluid() != null
&& data.fluid.getFluid().getID() == fluid.getID()
&& (data.emptyContainer.getItem().equals(container.getItem())
|| data.filledContainer.getItem().equals(container.getItem())))
|| data.filledContainer.getItem().equals(container.getItem())))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public static boolean isToolOrWeapon(@Nullable ItemStack stack)
String cn = stack.getItem().getClass().getName();
return cn.startsWith(PACKAGE_TCONSTRUCT)
&& (cn.startsWith(PACKAGE_TOOLS) || cn.startsWith(PACKAGE_WEAPONS) || cn.startsWith(PACKAGE_AMMO));

}

public static boolean isTool(@Nonnull ItemStack stack)
Expand Down