use of net.minecraft.world.entity.EquipmentSlot in project MinecraftForge by MinecraftForge.
the class EntityEquipmentInvWrapper method insertItem.
@Nonnull
@Override
public ItemStack insertItem(final int slot, @Nonnull final ItemStack stack, final boolean simulate) {
if (stack.isEmpty())
return ItemStack.EMPTY;
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
final ItemStack existing = entity.getItemBySlot(equipmentSlot);
int limit = getStackLimit(slot, stack);
if (!existing.isEmpty()) {
if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
return stack;
limit -= existing.getCount();
}
if (limit <= 0)
return stack;
boolean reachedLimit = stack.getCount() > limit;
if (!simulate) {
if (existing.isEmpty()) {
entity.setItemSlot(equipmentSlot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
} else {
existing.grow(reachedLimit ? limit : stack.getCount());
}
}
return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
use of net.minecraft.world.entity.EquipmentSlot in project MinecraftForge by MinecraftForge.
the class EntityEquipmentInvWrapper method extractItem.
@Nonnull
@Override
public ItemStack extractItem(final int slot, final int amount, final boolean simulate) {
if (amount == 0)
return ItemStack.EMPTY;
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
final ItemStack existing = entity.getItemBySlot(equipmentSlot);
if (existing.isEmpty())
return ItemStack.EMPTY;
final int toExtract = Math.min(amount, existing.getMaxStackSize());
if (existing.getCount() <= toExtract) {
if (!simulate) {
entity.setItemSlot(equipmentSlot, ItemStack.EMPTY);
}
return existing;
} else {
if (!simulate) {
entity.setItemSlot(equipmentSlot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
}
return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
}
}
use of net.minecraft.world.entity.EquipmentSlot in project Denizen-For-Bukkit by DenizenScript.
the class EnchantmentHelperImpl method registerFakeEnchantment.
@Override
public org.bukkit.enchantments.Enchantment registerFakeEnchantment(EnchantmentScriptContainer.EnchantmentReference script) {
try {
EquipmentSlot[] slots = new EquipmentSlot[script.script.slots.size()];
for (int i = 0; i < slots.length; i++) {
slots[i] = EquipmentSlot.valueOf(script.script.slots.get(i).toUpperCase());
}
net.minecraft.world.item.enchantment.Enchantment nmsEnchant = new net.minecraft.world.item.enchantment.Enchantment(net.minecraft.world.item.enchantment.Enchantment.Rarity.valueOf(script.script.rarity), EnchantmentCategory.valueOf(script.script.category), slots) {
@Override
public int getMinLevel() {
return script.script.minLevel;
}
@Override
public int getMaxLevel() {
return script.script.maxLevel;
}
@Override
public int getMinCost(int level) {
return script.script.getMinCost(level);
}
@Override
public int getMaxCost(int level) {
return script.script.getMaxCost(level);
}
@Override
public int getDamageProtection(int level, DamageSource src) {
return script.script.getDamageProtection(level, src.msgId, src.getEntity() == null ? null : src.getEntity().getBukkitEntity());
}
@Override
public float getDamageBonus(int level, MobType type) {
String typeName = "UNDEFINED";
if (type == MobType.ARTHROPOD) {
typeName = "ARTHROPOD";
} else if (type == MobType.ILLAGER) {
typeName = "ILLAGER";
} else if (type == MobType.UNDEAD) {
typeName = "UNDEAD";
} else if (type == MobType.WATER) {
typeName = "WATER";
}
return script.script.getDamageBonus(level, typeName);
}
@Override
protected boolean checkCompatibility(net.minecraft.world.item.enchantment.Enchantment nmsEnchantment) {
ResourceLocation nmsKey = Registry.ENCHANTMENT.getKey(nmsEnchantment);
NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(nmsKey);
org.bukkit.enchantments.Enchantment bukkitEnchant = CraftEnchantment.getByKey(bukkitKey);
return script.script.isCompatible(bukkitEnchant);
}
@Override
protected String getOrCreateDescriptionId() {
return script.script.descriptionId;
}
@Override
public String getDescriptionId() {
return script.script.descriptionId;
}
@Override
public Component getFullname(int level) {
return Handler.componentToNMS(script.script.getFullName(level));
}
@Override
public boolean canEnchant(net.minecraft.world.item.ItemStack var0) {
return super.canEnchant(var0) && script.script.canEnchant(CraftItemStack.asBukkitCopy(var0));
}
@Override
public void doPostAttack(LivingEntity attacker, Entity victim, int level) {
script.script.doPostAttack(attacker.getBukkitEntity(), victim.getBukkitEntity(), level);
}
@Override
public void doPostHurt(LivingEntity victim, Entity attacker, int level) {
script.script.doPostHurt(victim.getBukkitEntity(), attacker.getBukkitEntity(), level);
}
@Override
public boolean isTreasureOnly() {
return script.script.isTreasureOnly;
}
@Override
public boolean isCurse() {
return script.script.isCurse;
}
@Override
public boolean isTradeable() {
return script.script.isTradable;
}
@Override
public boolean isDiscoverable() {
return script.script.isDiscoverable;
}
};
String enchName = script.script.id.toUpperCase();
Registry.register(Registry.ENCHANTMENT, "denizen:" + script.script.id, nmsEnchant);
CraftEnchantment ench = new CraftEnchantment(nmsEnchant) {
@Override
public String getName() {
return enchName;
}
};
ENCHANTMENTS_BY_KEY.put(ench.getKey(), ench);
ENCHANTMENTS_BY_NAME.put(enchName, ench);
return ench;
} catch (Throwable ex) {
Debug.echoError("Failed to register enchantment " + script.script.id);
Debug.echoError(ex);
return null;
}
}
use of net.minecraft.world.entity.EquipmentSlot in project Denizen-For-Bukkit by DenizenScript.
the class EnchantmentHelperImpl method registerFakeEnchantment.
@Override
public org.bukkit.enchantments.Enchantment registerFakeEnchantment(EnchantmentScriptContainer.EnchantmentReference script) {
try {
EquipmentSlot[] slots = new EquipmentSlot[script.script.slots.size()];
for (int i = 0; i < slots.length; i++) {
slots[i] = EquipmentSlot.valueOf(script.script.slots.get(i).toUpperCase());
}
net.minecraft.world.item.enchantment.Enchantment nmsEnchant = new net.minecraft.world.item.enchantment.Enchantment(net.minecraft.world.item.enchantment.Enchantment.Rarity.valueOf(script.script.rarity), EnchantmentCategory.valueOf(script.script.category), slots) {
@Override
public int getMinLevel() {
return script.script.minLevel;
}
@Override
public int getMaxLevel() {
return script.script.maxLevel;
}
@Override
public int getMinCost(int level) {
return script.script.getMinCost(level);
}
@Override
public int getMaxCost(int level) {
return script.script.getMaxCost(level);
}
@Override
public int getDamageProtection(int level, DamageSource src) {
return script.script.getDamageProtection(level, src.msgId, src.getEntity() == null ? null : src.getEntity().getBukkitEntity());
}
@Override
public float getDamageBonus(int level, MobType type) {
String typeName = "UNDEFINED";
if (type == MobType.ARTHROPOD) {
typeName = "ARTHROPOD";
} else if (type == MobType.ILLAGER) {
typeName = "ILLAGER";
} else if (type == MobType.UNDEAD) {
typeName = "UNDEAD";
} else if (type == MobType.WATER) {
typeName = "WATER";
}
return script.script.getDamageBonus(level, typeName);
}
@Override
protected boolean checkCompatibility(net.minecraft.world.item.enchantment.Enchantment nmsEnchantment) {
ResourceLocation nmsKey = Registry.ENCHANTMENT.getKey(nmsEnchantment);
NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(nmsKey);
org.bukkit.enchantments.Enchantment bukkitEnchant = CraftEnchantment.getByKey(bukkitKey);
return script.script.isCompatible(bukkitEnchant);
}
@Override
protected String getOrCreateDescriptionId() {
return script.script.descriptionId;
}
@Override
public String getDescriptionId() {
return script.script.descriptionId;
}
@Override
public Component getFullname(int level) {
return Handler.componentToNMS(script.script.getFullName(level));
}
@Override
public boolean canEnchant(net.minecraft.world.item.ItemStack var0) {
return super.canEnchant(var0) && script.script.canEnchant(CraftItemStack.asBukkitCopy(var0));
}
@Override
public void doPostAttack(LivingEntity attacker, Entity victim, int level) {
script.script.doPostAttack(attacker.getBukkitEntity(), victim.getBukkitEntity(), level);
}
@Override
public void doPostHurt(LivingEntity victim, Entity attacker, int level) {
script.script.doPostHurt(victim.getBukkitEntity(), attacker.getBukkitEntity(), level);
}
@Override
public boolean isTreasureOnly() {
return script.script.isTreasureOnly;
}
@Override
public boolean isCurse() {
return script.script.isCurse;
}
@Override
public boolean isTradeable() {
return script.script.isTradable;
}
@Override
public boolean isDiscoverable() {
return script.script.isDiscoverable;
}
};
String enchName = script.script.id.toUpperCase();
Registry.register(Registry.ENCHANTMENT, "denizen:" + script.script.id, nmsEnchant);
CraftEnchantment ench = new CraftEnchantment(nmsEnchant) {
@Override
public String getName() {
return enchName;
}
};
ENCHANTMENTS_BY_KEY.put(ench.getKey(), ench);
ENCHANTMENTS_BY_NAME.put(enchName, ench);
return ench;
} catch (Throwable ex) {
Debug.echoError("Failed to register enchantment " + script.script.id);
Debug.echoError(ex);
return null;
}
}
use of net.minecraft.world.entity.EquipmentSlot in project MinecraftForge by MinecraftForge.
the class EntityEquipmentInvWrapper method setStackInSlot.
@Override
public void setStackInSlot(final int slot, @Nonnull final ItemStack stack) {
final EquipmentSlot equipmentSlot = validateSlotIndex(slot);
if (ItemStack.matches(entity.getItemBySlot(equipmentSlot), stack))
return;
entity.setItemSlot(equipmentSlot, stack);
}
Aggregations