Added ItemStack#getAirItem

This commit is contained in:
Felix Cravic 2020-04-23 12:30:49 +02:00
parent 3f15701256
commit 4570e7a013
14 changed files with 35 additions and 26 deletions

View File

@ -247,7 +247,7 @@ public abstract class Entity implements Viewable, DataContainer {
int firstBlock = 0;
for (int y = (int) position.getY(); y > 0; y--) {
BlockPosition blockPosition = new BlockPosition(position.getX(), y + 1, position.getZ());
BlockPosition blockPosition = new BlockPosition(position.getX(), y, position.getZ());
short blockId = instance.getBlockId(blockPosition);
//if (y == 70)
// System.out.println("id: " + blockId);

View File

@ -139,7 +139,7 @@ public abstract class EntityCreature extends LivingEntity {
pathFinder.getPath(position, blockPositions -> {
if (blockPositions.isEmpty()) {
// Didn't find path
System.out.println("NOT FOUND");
System.out.println("PATH NOT FOUND");
return;
}
this.blockPositions = blockPositions;

View File

@ -82,10 +82,10 @@ public class Player extends LivingEntity {
private float fieldViewModifier = 0.1f;
// Statistics
private Map<PlayerStatistic, Integer> statisticValueMap = new HashMap<>();
private Map<PlayerStatistic, Integer> statisticValueMap = new Hashtable<>();
// Vehicle
private PlayerVehicleInformation vehicleInformation;
private PlayerVehicleInformation vehicleInformation = new PlayerVehicleInformation();
public Player(UUID uuid, String username, PlayerConnection playerConnection) {
super(EntityType.PLAYER.getId());

View File

@ -42,7 +42,10 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
this.offset = inventoryType.getAdditionalSlot();
this.itemStacks = new ItemStack[inventoryType.getAdditionalSlot()];
Arrays.fill(itemStacks, ItemStack.AIR_ITEM);
for (int i = 0; i < itemStacks.length; i++) {
itemStacks[i] = ItemStack.getAirItem();
}
}
private static int generateId() {
@ -117,12 +120,12 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
}
public ItemStack getCursorItem(Player player) {
return cursorPlayersItem.getOrDefault(player, ItemStack.AIR_ITEM);
return cursorPlayersItem.getOrDefault(player, ItemStack.getAirItem());
}
private void safeItemInsert(int slot, ItemStack itemStack) {
synchronized (this) {
itemStack = itemStack == null ? ItemStack.AIR_ITEM : itemStack;
itemStack = itemStack == null ? ItemStack.getAirItem() : itemStack;
this.itemStacks[slot] = itemStack;
SetSlotPacket setSlotPacket = new SetSlotPacket();
setSlotPacket.windowId = 1;

View File

@ -23,7 +23,7 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
private Player player;
private ItemStack[] items = new ItemStack[INVENTORY_SIZE];
private ItemStack cursorItem = ItemStack.AIR_ITEM;
private ItemStack cursorItem = ItemStack.getAirItem();
private InventoryCondition inventoryCondition;
private InventoryClickProcessor clickProcessor = new InventoryClickProcessor();
@ -31,7 +31,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
public PlayerInventory(Player player) {
this.player = player;
Arrays.fill(items, ItemStack.AIR_ITEM);
for (int i = 0; i < items.length; i++) {
items[i] = ItemStack.getAirItem();
}
}
@Override
@ -176,13 +178,14 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
return getLeggings();
case BOOTS:
return getBoots();
default:
throw new NullPointerException("Equipment slot cannot be null");
}
return ItemStack.AIR_ITEM;
}
private void safeItemInsert(int slot, ItemStack itemStack) {
synchronized (this) {
itemStack = itemStack == null ? ItemStack.AIR_ITEM : itemStack;
itemStack = itemStack == null ? ItemStack.getAirItem() : itemStack;
EntityEquipmentPacket.Slot equipmentSlot;

View File

@ -136,12 +136,12 @@ public class InventoryClickProcessor {
if (clicked.isAir()) {
// Set held item [key] to slot
resultClicked = ItemStack.AIR_ITEM;
resultClicked = ItemStack.getAirItem();
resultHeld = clicked.clone();
} else {
if (cursor.isAir()) {
// if held item [key] is air then set clicked to held
resultClicked = ItemStack.AIR_ITEM;
resultClicked = ItemStack.getAirItem();
resultHeld = clicked.clone();
} else {
// Otherwise replace held item and held
@ -218,7 +218,7 @@ public class InventoryClickProcessor {
// Switch
itemSetter.accept(index, resultClicked);
itemSetter.accept(slot, ItemStack.AIR_ITEM);
itemSetter.accept(slot, ItemStack.getAirItem());
filled = true;
break;
}
@ -347,7 +347,7 @@ public class InventoryClickProcessor {
public InventoryClickResult doubleClick(InventoryCondition inventoryCondition, Player player, int slot,
ItemStack cursor, InventoryClickLoopHandler... loopHandlers) {
InventoryClickResult clickResult = new InventoryClickResult(ItemStack.AIR_ITEM, cursor);
InventoryClickResult clickResult = new InventoryClickResult(ItemStack.getAirItem(), cursor);
if (clickResult.isCancel()) {
return clickResult;

View File

@ -8,7 +8,10 @@ import java.util.ArrayList;
public class ItemStack implements DataContainer {
public static final ItemStack AIR_ITEM = new ItemStack((short) 0, (byte) 0);
public static ItemStack getAirItem() {
return new ItemStack((short) 0, (byte) 0);
}
private static StackingRule defaultStackingRule;
private short materialId;

View File

@ -22,7 +22,7 @@ public class VanillaStackingRule extends StackingRule {
@Override
public ItemStack apply(ItemStack item, int newAmount) {
if (newAmount <= 0)
return ItemStack.AIR_ITEM;
return ItemStack.getAirItem();
item.setAmount((byte) newAmount);
return item;

View File

@ -66,7 +66,7 @@ public class PlayerDiggingListener {
break;
case DROP_ITEM_STACK:
ItemStack droppedItemStack = player.getInventory().getItemInMainHand().clone();
dropItem(player, droppedItemStack, ItemStack.AIR_ITEM);
dropItem(player, droppedItemStack, ItemStack.getAirItem());
break;
case DROP_ITEM:
ItemStack droppedItemStack2 = player.getInventory().getItemInMainHand().clone();
@ -74,7 +74,7 @@ public class PlayerDiggingListener {
ItemStack handItem = player.getInventory().getItemInMainHand();
handItem.setAmount((byte) (handItem.getAmount() - 1));
handItem = handItem.getAmount() <= 0 ? ItemStack.AIR_ITEM : handItem;
handItem = handItem.getAmount() <= 0 ? ItemStack.getAirItem() : handItem;
dropItem(player, droppedItemStack2, handItem);
break;

View File

@ -42,9 +42,9 @@ public class UseItemListener {
ItemStack armorItem = armorEquipEvent.getArmorItem();
if (hand == Player.Hand.MAIN) {
playerInventory.setItemInMainHand(ItemStack.AIR_ITEM);
playerInventory.setItemInMainHand(ItemStack.getAirItem());
} else {
playerInventory.setItemInOffHand(ItemStack.AIR_ITEM);
playerInventory.setItemInOffHand(ItemStack.getAirItem());
}
switch (armorSlot) {

View File

@ -12,7 +12,7 @@ public class ShapedRecipe extends Recipe {
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
private ItemStack result = ItemStack.AIR_ITEM;
private ItemStack result = ItemStack.getAirItem();
public ShapedRecipe(String recipeId, String group, int width, int height) {
super(RecipeType.SHAPED, recipeId);

View File

@ -10,7 +10,7 @@ public class ShapelessRecipe extends Recipe {
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
private ItemStack result = ItemStack.AIR_ITEM;
private ItemStack result = ItemStack.getAirItem();
public ShapelessRecipe(String recipeId, String group) {
super(RecipeType.SHAPELESS, recipeId);

View File

@ -7,7 +7,7 @@ public class SmeltingRecipe extends Recipe {
private DeclareRecipesPacket.Ingredient ingredient;
private ItemStack result = ItemStack.AIR_ITEM;
private ItemStack result = ItemStack.getAirItem();
private float experience;

View File

@ -141,13 +141,13 @@ public class Utils {
boolean present = reader.readBoolean();
if (!present) {
return ItemStack.AIR_ITEM;
return ItemStack.getAirItem();
}
int id = reader.readVarInt();
if (id == -1) {
// Drop mode
return ItemStack.AIR_ITEM;
return ItemStack.getAirItem();
}
byte count = reader.readByte();