Merge branch 'master' into 1.17

# Conflicts:
#	src/main/java/carpet/script/value/NBTSerializableValue.java
This commit is contained in:
gnembon committed 2020-11-26 03:03:03 -04:00
commit f4f289b0ec
14 files changed
+830 -188

No files matched your search

@@ -0,0 +1,126 @@
package carpet.script.utils;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import java.util.Arrays;
import java.util.List;
public class EquipmentInventory implements Inventory
{
private static final List<EquipmentSlot> slotToSlot = Arrays.asList(
EquipmentSlot.MAINHAND,
EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.CHEST, EquipmentSlot.HEAD,
EquipmentSlot.OFFHAND
);
LivingEntity mob;
public EquipmentInventory(LivingEntity mob)
{
this.mob = mob;
}
@Override
public int size()
{
return 6;
}
@Override
public boolean isEmpty()
{
for (EquipmentSlot slot: slotToSlot)
if (!mob.getEquippedStack(slot).isEmpty()) return false;
return true;
}
@Override
public ItemStack getStack(int slot)
{
EquipmentSlot slotSlot;
try
{
slotSlot = slotToSlot.get(slot);
}
catch (IndexOutOfBoundsException ignored)
{
//going out of the index should be really exceptional
return null;
}
return mob.getEquippedStack(slotSlot);
}
@Override
public ItemStack removeStack(int slot, int amount)
{
EquipmentSlot slotSlot;
try
{
slotSlot = slotToSlot.get(slot);
}
catch (IndexOutOfBoundsException ignored)
{
//going out of the index should be really exceptional
return null;
}
ItemStack stack = mob.getEquippedStack(slotSlot);
stack.decrement(amount);
return stack;
}
@Override
public ItemStack removeStack(int slot)
{
EquipmentSlot slotSlot;
try
{
slotSlot = slotToSlot.get(slot);
}
catch (IndexOutOfBoundsException ignored)
{
//going out of the index should be really exceptional
return null;
}
ItemStack previous = mob.getEquippedStack(slotSlot);
mob.equipStack(slotSlot, ItemStack.EMPTY);
return previous;
}
@Override
public void setStack(int slot, ItemStack stack)
{
EquipmentSlot slotSlot;
try
{
slotSlot = slotToSlot.get(slot);
}
catch (IndexOutOfBoundsException ignored)
{
//going out of the index should be really exceptional
return;
}
mob.equipStack(slotSlot, stack);
}
@Override
public void markDirty()
{
}
@Override
public boolean canPlayerUse(PlayerEntity player)
{
return false;
}
@Override
public void clear()
{
for (EquipmentSlot slot: slotToSlot)
mob.equipStack(slot, ItemStack.EMPTY);
}
}
@@ -1,96 +0,0 @@
package carpet.script.utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
public class LivingInventory implements Inventory
{
private static final Int2ObjectMap<EquipmentSlot> slotToSlot = new Int2ObjectOpenHashMap<EquipmentSlot>(){{
put(0, EquipmentSlot.MAINHAND);
put(1, EquipmentSlot.FEET);
put(2, EquipmentSlot.LEGS);
put(3, EquipmentSlot.CHEST);
put(4, EquipmentSlot.HEAD);
put(5, EquipmentSlot.OFFHAND);
}};
LivingEntity mob;
public LivingInventory(LivingEntity mob)
{
this.mob = mob;
}
@Override
public int size()
{
return 6;
}
@Override
public boolean isEmpty()
{
for (EquipmentSlot slot: EquipmentSlot.values())
if (!mob.getEquippedStack(slot).isEmpty()) return false;
return true;
}
@Override
public ItemStack getStack(int slot)
{
EquipmentSlot slotSlot = slotToSlot.getOrDefault(slot, null);
if (slotSlot == null) return null;
return mob.getEquippedStack(slotToSlot.get(slot));
}
@Override
public ItemStack removeStack(int slot, int amount)
{
EquipmentSlot slotSlot = slotToSlot.getOrDefault(slot, null);
if (slotSlot == null) return null;
ItemStack stack = mob.getEquippedStack(slotSlot);
stack.decrement(amount);
return stack;
}
@Override
public ItemStack removeStack(int slot)
{
EquipmentSlot slotSlot = slotToSlot.getOrDefault(slot, null);
if (slotSlot == null) return null;
ItemStack previous = mob.getEquippedStack(slotSlot);
mob.equipStack(slotSlot, ItemStack.EMPTY);
return previous;
}
@Override
public void setStack(int slot, ItemStack stack)
{
EquipmentSlot slotSlot = slotToSlot.getOrDefault(slot, null);
if (slotSlot == null) return;
mob.equipStack(slotSlot, stack);
}
@Override
public void markDirty()
{
}
@Override
public boolean canPlayerUse(PlayerEntity player)
{
return false;
}
@Override
public void clear()
{
for (EquipmentSlot slot: EquipmentSlot.values())
mob.equipStack(slot, ItemStack.EMPTY);
}
}