Skip to content
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 @@ -8,6 +8,7 @@
import static com.darkona.adventurebackpack.common.Constants.TAG_DISABLE_NVISION;
import static com.darkona.adventurebackpack.common.Constants.TAG_EXTENDED_COMPOUND;
import static com.darkona.adventurebackpack.common.Constants.TAG_INVENTORY;
import static com.darkona.adventurebackpack.common.Constants.TAG_LAST_TIME;
import static com.darkona.adventurebackpack.common.Constants.TAG_LEFT_TANK;
import static com.darkona.adventurebackpack.common.Constants.TAG_RIGHT_TANK;
import static com.darkona.adventurebackpack.common.Constants.TAG_TYPE;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void loadFromNBT(NBTTagCompound compound) {
extendedProperties = backpackTag.getCompoundTag(TAG_EXTENDED_COMPOUND);
disableCycling = backpackTag.getBoolean(TAG_DISABLE_CYCLING);
disableNVision = backpackTag.getBoolean(TAG_DISABLE_NVISION);
lastTime = backpackTag.getInteger("lastTime");
lastTime = backpackTag.getInteger(TAG_LAST_TIME);
}

@Override
Expand All @@ -161,7 +162,7 @@ public void saveToNBT(NBTTagCompound compound) {
backpackTag.setTag(TAG_EXTENDED_COMPOUND, extendedProperties);
backpackTag.setBoolean(TAG_DISABLE_CYCLING, disableCycling);
backpackTag.setBoolean(TAG_DISABLE_NVISION, disableNVision);
backpackTag.setInteger("lastTime", lastTime);
backpackTag.setInteger(TAG_LAST_TIME, lastTime);

compound.setTag(TAG_WEARABLE_COMPOUND, backpackTag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void update() {
return;
}

status = BackpackUtils.getWearableCompound(copter).getByte(TAG_STATUS);
status = BackpackUtils.getOrCreateWearableCompound(copter).getByte(TAG_STATUS);
if (status == ItemCopterPack.OFF_MODE) {
setDonePlaying();
} else if (status == ItemCopterPack.HOVER_MODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void renderCopterPack(Entity entity, float scale) {
InventoryCopterPack copterInv = new InventoryCopterPack(this.copterPack);
copterInv.openInventory();
Axis.isHidden = true;
if (BackpackUtils.getWearableCompound(copterPack).getByte(TAG_STATUS) != ItemCopterPack.OFF_MODE) {
if (BackpackUtils.getOrCreateWearableCompound(copterPack).getByte(TAG_STATUS) != ItemCopterPack.OFF_MODE) {
Axis.isHidden = false;
int degrees;
if (entity.onGround || (entity.isSneaking())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum Source // TODO move to separate class?
public static final String TAG_RIGHT_TANK = "rightTank";
public static final String TAG_DISABLE_CYCLING = "disableCycling";
public static final String TAG_DISABLE_NVISION = "disableNVision";
public static final String TAG_LAST_TIME = "lastTime";

// NBT: Extended Properties
public static final String TAG_HOLDING_SPACE = "holdingSpace";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,16 @@ public static void pistonBootsJump(EntityPlayer player) {
}

public static void copterSoundAtLogin(EntityPlayer player) {
byte status = BackpackUtils.getWearableCompound(BackpackProperty.get(player).getWearable()).getByte(TAG_STATUS);
byte status = BackpackUtils.getOrCreateWearableCompound(BackpackProperty.get(player).getWearable())
.getByte(TAG_STATUS);

if (!player.worldObj.isRemote && status != ItemCopterPack.OFF_MODE) {
ModNetwork.sendToNearby(new EntitySoundPacket.Message(EntitySoundPacket.COPTER_SOUND, player), player);
}
}

public static void jetpackSoundAtLogin(EntityPlayer player) {
boolean isBoiling = BackpackUtils.getWearableCompound(BackpackProperty.get(player).getWearable())
boolean isBoiling = BackpackUtils.getOrCreateWearableCompound(BackpackProperty.get(player).getWearable())
.getBoolean("boiling");

if (!player.worldObj.isRemote && isBoiling) {
Expand All @@ -271,7 +272,7 @@ public static void jetpackSoundAtLogin(EntityPlayer player) {
public static void toggleCopterPack(EntityPlayer player, ItemStack copter, byte type) {
String message = "";
boolean actionPerformed = false;
byte mode = BackpackUtils.getWearableCompound(copter).getByte(TAG_STATUS);
byte mode = BackpackUtils.getOrCreateWearableCompound(copter).getByte(TAG_STATUS);
byte newMode = ItemCopterPack.OFF_MODE;

if (type == WearableModePacket.COPTER_ON_OFF) {
Expand Down Expand Up @@ -305,7 +306,7 @@ public static void toggleCopterPack(EntityPlayer player, ItemStack copter, byte
}

if (actionPerformed) {
BackpackUtils.getWearableCompound(copter).setByte(TAG_STATUS, newMode);
BackpackUtils.getOrCreateWearableCompound(copter).setByte(TAG_STATUS, newMode);
if (player.worldObj.isRemote && ConfigHandler.chatSpam) {
player.addChatComponentMessage(new ChatComponentTranslation(message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public ItemStack getCraftingResult(InventoryCrafting craftMatrix) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
ItemStack matrixStack = craftMatrix.getStackInSlot(i);
if (matrixStack != null && matrixStack.getItem() == ModItems.adventureBackpack
&& BackpackUtils.getWearableCompound(matrixStack).hasKey(TAG_INVENTORY)) {
NBTTagList itemList = BackpackUtils.getWearableInventory(matrixStack);
BackpackUtils.getWearableCompound(craftResult).setTag(TAG_INVENTORY, itemList);
&& BackpackUtils.getOrCreateWearableCompound(matrixStack).hasKey(TAG_INVENTORY)) {
NBTTagList itemList = BackpackUtils.getOrCreateWearableInventory(matrixStack);
BackpackUtils.getOrCreateWearableCompound(craftResult).setTag(TAG_INVENTORY, itemList);

LogHelper.info(
"Successfully transferred inventory from the ingredient backpack ["
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void dirtyInventory() {
}

protected NBTTagCompound getWearableCompound() {
return BackpackUtils.getWearableCompound(containerStack);
return BackpackUtils.getOrCreateWearableCompound(containerStack);
}

protected void setInventoryFromTagList(NBTTagList items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static com.darkona.adventurebackpack.common.Constants.TAG_DISABLE_NVISION;
import static com.darkona.adventurebackpack.common.Constants.TAG_EXTENDED_COMPOUND;
import static com.darkona.adventurebackpack.common.Constants.TAG_INVENTORY;
import static com.darkona.adventurebackpack.common.Constants.TAG_LAST_TIME;
import static com.darkona.adventurebackpack.common.Constants.TAG_LEFT_TANK;
import static com.darkona.adventurebackpack.common.Constants.TAG_RIGHT_TANK;
import static com.darkona.adventurebackpack.common.Constants.TAG_TYPE;
Expand Down Expand Up @@ -103,7 +104,7 @@ public void loadFromNBT(NBTTagCompound compound) {
loadSleepingBag();
disableCycling = backpackTag.getBoolean(TAG_DISABLE_CYCLING);
disableNVision = backpackTag.getBoolean(TAG_DISABLE_NVISION);
lastTime = backpackTag.getInteger("lastTime");
lastTime = backpackTag.getInteger(TAG_LAST_TIME);
}

@Override
Expand All @@ -117,7 +118,7 @@ public void saveToNBT(NBTTagCompound compound) {
saveSleepingBag();
backpackTag.setBoolean(TAG_DISABLE_CYCLING, disableCycling);
backpackTag.setBoolean(TAG_DISABLE_NVISION, disableNVision);
backpackTag.setInteger("lastTime", lastTime);
backpackTag.setInteger(TAG_LAST_TIME, lastTime);

compound.setTag(TAG_WEARABLE_COMPOUND, backpackTag);
}
Expand Down Expand Up @@ -145,7 +146,7 @@ public void dirtyExtended() // TODO is it redundant?

@Override
public void dirtyTime() {
getWearableCompound().setInteger("lastTime", lastTime);
getWearableCompound().setInteger(TAG_LAST_TIME, lastTime);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List subItems)
@SuppressWarnings({ "unchecked" })
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List tooltips, boolean advanced) {
NBTTagCompound backpackTag = BackpackUtils.getWearableCompound(stack);
NBTTagCompound backpackTag = BackpackUtils.getOrCreateWearableCompound(stack);

BackpackTypes type = BackpackTypes.getType(backpackTag.getByte(TAG_TYPE));
tooltips.add(Utils.getColoredSkinName(type));
Expand Down Expand Up @@ -278,7 +278,7 @@ public double getDurabilityForDisplay(ItemStack stack) {
}

private int getItemCount(ItemStack backpack) {
NBTTagList itemList = BackpackUtils.getWearableInventory(backpack);
NBTTagList itemList = BackpackUtils.getOrCreateWearableInventory(backpack);
int itemCount = itemList.tagCount();
for (int i = itemCount - 1; i >= 0; i--) {
int slotAtI = itemList.getCompoundTagAt(i).getInteger(Constants.TAG_SLOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void getSubItems(Item item, CreativeTabs tab, List list) {
public void addInformation(ItemStack stack, EntityPlayer player, List tooltips, boolean advanced) {
FluidTank waterTank = new FluidTank(Constants.Jetpack.WATER_CAPACITY);
FluidTank steamTank = new FluidTank(Constants.Jetpack.STEAM_CAPACITY);
NBTTagCompound jetpackTag = BackpackUtils.getWearableCompound(stack);
NBTTagCompound jetpackTag = BackpackUtils.getOrCreateWearableCompound(stack);

if (GuiScreen.isShiftKeyDown()) {
NBTTagList itemList = jetpackTag.getTagList(Constants.TAG_INVENTORY, NBT.TAG_COMPOUND);
Expand Down Expand Up @@ -265,7 +265,7 @@ public double getDurabilityForDisplay(ItemStack stack) {
}

private int getTemperature(ItemStack jetpack) {
return BackpackUtils.getWearableCompound(jetpack).getInteger("temperature");
return BackpackUtils.getOrCreateWearableCompound(jetpack).getInteger("temperature");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void getSubItems(Item item, CreativeTabs tab, List list) {
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List tooltips, boolean advanced) {
FluidTank fuelTank = new FluidTank(FUEL_CAPACITY);
NBTTagCompound copterTag = BackpackUtils.getWearableCompound(stack);
NBTTagCompound copterTag = BackpackUtils.getOrCreateWearableCompound(stack);

if (GuiScreen.isShiftKeyDown()) {
fuelTank.readFromNBT(copterTag.getCompoundTag(TAG_FUEL_TANK));
Expand Down Expand Up @@ -96,7 +96,7 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla

@Override
public void onEquipped(World world, EntityPlayer player, ItemStack stack) {
BackpackUtils.getWearableCompound(stack).setByte(TAG_STATUS, OFF_MODE);
BackpackUtils.getOrCreateWearableCompound(stack).setByte(TAG_STATUS, OFF_MODE);
}

@Override
Expand Down Expand Up @@ -257,7 +257,7 @@ private void pushEntities(World world, EntityPlayer player, float speed) {

@Override
public void onUnequipped(World world, EntityPlayer player, ItemStack stack) {
BackpackUtils.getWearableCompound(stack).setByte(TAG_STATUS, OFF_MODE);
BackpackUtils.getOrCreateWearableCompound(stack).setByte(TAG_STATUS, OFF_MODE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static BackpackTypes getType(ItemStack backpack) {
if (backpack == null) // well... Wearing.getWearingBackpack() may return null... //TODO solve this damn null
return null;

NBTTagCompound backpackTag = BackpackUtils.getWearableCompound(backpack);
NBTTagCompound backpackTag = BackpackUtils.getOrCreateWearableCompound(backpack);
if (backpackTag.getByte(TAG_TYPE) == UNKNOWN.meta) // TODO remove? are we rly need to normalize it?
{
backpackTag.setByte(TAG_TYPE, STANDARD.meta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public void run() {
}
}

public static NBTTagCompound getWearableCompound(ItemStack stack) {
// it also creates wearable compound if stack has no own, so maybe worth to rename the method
public static NBTTagCompound getOrCreateWearableCompound(ItemStack stack) {
if (!stack.hasTagCompound() || !stack.stackTagCompound.hasKey(TAG_WEARABLE_COMPOUND))
createWearableCompound(stack);

Expand All @@ -93,15 +92,14 @@ private static void createWearableCompound(ItemStack stack) {
stack.stackTagCompound.setTag(TAG_WEARABLE_COMPOUND, new NBTTagCompound());
}

public static NBTTagList getWearableInventory(ItemStack stack) {
// it also creates TagList if stack has no own, so maybe worth to rename the method
if (!getWearableCompound(stack).hasKey(TAG_INVENTORY)) createWearableInventory(stack);
public static NBTTagList getOrCreateWearableInventory(ItemStack stack) {
if (!getOrCreateWearableCompound(stack).hasKey(TAG_INVENTORY)) createWearableInventory(stack);

return getWearableCompound(stack).getTagList(TAG_INVENTORY, Constants.NBT.TAG_COMPOUND);
return getOrCreateWearableCompound(stack).getTagList(TAG_INVENTORY, Constants.NBT.TAG_COMPOUND);
}

private static void createWearableInventory(ItemStack stack) {
getWearableCompound(stack).setTag(TAG_INVENTORY, new NBTTagList());
getOrCreateWearableCompound(stack).setTag(TAG_INVENTORY, new NBTTagList());
}

public static ItemStack createBackpackStack(BackpackTypes type) {
Expand All @@ -111,7 +109,7 @@ public static ItemStack createBackpackStack(BackpackTypes type) {
}

public static void setBackpackType(ItemStack stack, BackpackTypes type) {
getWearableCompound(stack).setByte(TAG_TYPE, BackpackTypes.getMeta(type));
getOrCreateWearableCompound(stack).setByte(TAG_TYPE, BackpackTypes.getMeta(type));
}

public static ItemStack createCopterStack() {
Expand Down