use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity in project PublicCrafters by BananaPuncher714.
the class CustomContainerAnvil method e.
public void e() {
EntityHuman player = ((CraftHumanEntity) this.player).getHandle();
ItemStack itemstack = subcontainer.getItem(0);
this.a = 1;
int i = 0;
byte b0 = 0;
byte b1 = 0;
if (itemstack.isEmpty()) {
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
this.a = 0;
} else {
ItemStack itemstack1 = itemstack.cloneItemStack();
if ((itemstack1.getCount() > 1) && (!player.abilities.canInstantlyBuild) && (!(itemstack1.getItem() instanceof ItemNameTag))) {
itemstack1.setCount(1);
}
ItemStack itemstack2 = subcontainer.getItem(1);
Map map = EnchantmentManager.a(itemstack1);
int j = b0 + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost());
xpCost = 0;
if (!itemstack2.isEmpty()) {
boolean flag = (itemstack2.getItem() == Items.ENCHANTED_BOOK) && (!Items.ENCHANTED_BOOK.h(itemstack2).isEmpty());
if ((itemstack1.f()) && (itemstack1.getItem().a(itemstack, itemstack2))) {
int k = Math.min(itemstack1.i(), itemstack1.k() / 4);
if (k <= 0) {
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
this.a = 0;
return;
}
for (int l = 0; (k > 0) && (l < itemstack2.getCount()); l++) {
int i1 = itemstack1.i() - k;
itemstack1.setData(i1);
i++;
k = Math.min(itemstack1.i(), itemstack1.k() / 4);
xpCost = l;
}
} else {
if ((!flag) && ((itemstack1.getItem() != itemstack2.getItem()) || (!itemstack1.f()))) {
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
this.a = 0;
return;
}
if ((itemstack1.f()) && (!flag)) {
int k = itemstack.k() - itemstack.i();
int l = itemstack2.k() - itemstack2.i();
int i1 = l + itemstack1.k() * 12 / 100;
int j1 = k + i1;
int k1 = itemstack1.k() - j1;
if (k1 < 0) {
k1 = 0;
}
if (k1 < itemstack1.getData()) {
itemstack1.setData(k1);
i += 2;
}
}
Map<Enchantment, Integer> map1 = EnchantmentManager.a(itemstack2);
boolean flag1 = false;
boolean flag2 = false;
Iterator iterator = map1.keySet().iterator();
while (iterator.hasNext()) {
Enchantment enchantment = (Enchantment) iterator.next();
if (enchantment != null) {
int l1 = map.containsKey(enchantment) ? ((Integer) map.get(enchantment)).intValue() : 0;
int i2 = ((Integer) map1.get(enchantment)).intValue();
i2 = l1 == i2 ? i2 + 1 : Math.max(i2, l1);
boolean flag3 = enchantment.canEnchant(itemstack);
if ((player.abilities.canInstantlyBuild) || (itemstack.getItem() == Items.ENCHANTED_BOOK)) {
flag3 = true;
}
Iterator iterator1 = map.keySet().iterator();
while (iterator1.hasNext()) {
Enchantment enchantment1 = (Enchantment) iterator1.next();
if ((enchantment1 != enchantment) && (!enchantment.c(enchantment1))) {
flag3 = false;
i++;
}
}
if (!flag3) {
flag2 = true;
} else {
flag1 = true;
if (i2 > enchantment.getMaxLevel()) {
i2 = enchantment.getMaxLevel();
}
map.put(enchantment, Integer.valueOf(i2));
int j2 = 0;
switch(enchantment.e()) {
case COMMON:
j2 = 1;
break;
case RARE:
j2 = 2;
break;
case UNCOMMON:
j2 = 4;
break;
case VERY_RARE:
j2 = 8;
}
if (flag) {
j2 = Math.max(1, j2 / 2);
}
i += j2 * i2;
}
}
}
if ((flag2) && (!flag1)) {
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
this.a = 0;
return;
}
}
}
if (StringUtils.isBlank(this.l)) {
if (itemstack.hasName()) {
b1 = 1;
i += b1;
itemstack1.s();
}
} else if (!this.l.equals(itemstack.getName())) {
b1 = 1;
i += b1;
itemstack1.g(this.l);
}
this.a = (j + i);
if (i <= 0) {
itemstack1 = ItemStack.a;
}
if ((b1 == i) && (b1 > 0) && (this.a >= 40)) {
this.a = 39;
}
if ((this.a >= 40) && (!player.abilities.canInstantlyBuild)) {
itemstack1 = ItemStack.a;
}
if (!itemstack1.isEmpty()) {
int k2 = itemstack1.getRepairCost();
if ((!itemstack2.isEmpty()) && (k2 < itemstack2.getRepairCost())) {
k2 = itemstack2.getRepairCost();
}
if ((b1 != i) || (b1 == 0)) {
k2 = k2 * 2 + 1;
}
itemstack1.setRepairCost(k2);
EnchantmentManager.a(map, itemstack1);
}
CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1);
b();
}
}
use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity in project Mohist by MohistMC.
the class CraftLootTable method convertContext.
public static LootContext convertContext(net.minecraft.world.level.storage.loot.LootContext info) {
Vec3 position = info.getParamOrNull(LootContextParams.ORIGIN);
if (position == null) {
// Every vanilla context has origin or this_entity, see LootContextParameterSets
position = info.getParamOrNull(LootContextParams.THIS_ENTITY).position();
}
Location location = new Location(info.getLevel().getWorld(), position.x(), position.y(), position.z());
LootContext.Builder contextBuilder = new LootContext.Builder(location);
if (info.hasParam(LootContextParams.KILLER_ENTITY)) {
CraftEntity killer = info.getParamOrNull(LootContextParams.KILLER_ENTITY).getBukkitEntity();
if (killer instanceof CraftHumanEntity) {
contextBuilder.killer((CraftHumanEntity) killer);
}
}
if (info.hasParam(LootContextParams.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getParamOrNull(LootContextParams.THIS_ENTITY).getBukkitEntity());
}
if (info.hasParam(LootContextParams.LOOTING_MOD)) {
contextBuilder.lootingModifier(info.getParamOrNull(LootContextParams.LOOTING_MOD));
}
contextBuilder.luck(info.getLuck());
return contextBuilder.build();
}
use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity in project WildChests by BG-Software-LLC.
the class NMSAdapter_v1_17_R1 method dropItemAsPlayer.
@Override
public void dropItemAsPlayer(HumanEntity humanEntity, org.bukkit.inventory.ItemStack bukkitItem) {
EntityHuman entityHuman = ((CraftHumanEntity) humanEntity).getHandle();
ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem);
entityHuman.drop(itemStack, false);
}
use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity in project Magma-1.16.x by magmafoundation.
the class CraftLootTable method convertContext.
public static LootContext convertContext(net.minecraft.loot.LootContext info) {
Vector3d position = info.getParamOrNull(LootParameters.ORIGIN);
if (position == null) {
// Every vanilla context has origin or this_entity, see LootContextParameterSets
position = info.getParamOrNull(LootParameters.THIS_ENTITY).position();
}
Location location = new Location(info.getLevel().getWorldCB(), position.x(), position.y(), position.z());
LootContext.Builder contextBuilder = new LootContext.Builder(location);
if (info.hasParam(LootParameters.KILLER_ENTITY)) {
CraftEntity killer = info.getParamOrNull(LootParameters.KILLER_ENTITY).getBukkitEntity();
if (killer instanceof CraftHumanEntity) {
contextBuilder.killer((CraftHumanEntity) killer);
}
}
if (info.hasParam(LootParameters.THIS_ENTITY)) {
contextBuilder.lootedEntity(info.getParamOrNull(LootParameters.THIS_ENTITY).getBukkitEntity());
}
if (info.hasParam(LootParameters.LOOTING_MOD)) {
contextBuilder.lootingModifier(info.getParamOrNull(LootParameters.LOOTING_MOD));
}
contextBuilder.luck(info.getLuck());
return contextBuilder.build();
}
use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftHumanEntity in project Magma-1.16.x by magmafoundation.
the class CraftLootTable method convertContext.
private net.minecraft.loot.LootContext convertContext(LootContext context) {
Location loc = context.getLocation();
ServerWorld handle = ((CraftWorld) loc.getWorld()).getHandle();
net.minecraft.loot.LootContext.Builder builder = new net.minecraft.loot.LootContext.Builder(handle);
setMaybe(builder, LootParameters.ORIGIN, new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
if (getHandle() != LootTable.EMPTY) {
if (context.getLootedEntity() != null) {
Entity nmsLootedEntity = ((CraftEntity) context.getLootedEntity()).getHandle();
setMaybe(builder, LootParameters.THIS_ENTITY, nmsLootedEntity);
setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.GENERIC);
setMaybe(builder, LootParameters.POSITION, new BlockPos(nmsLootedEntity));
}
if (context.getKiller() != null) {
PlayerEntity nmsKiller = ((CraftHumanEntity) context.getKiller()).getHandle();
setMaybe(builder, LootParameters.KILLER_ENTITY, nmsKiller);
// If there is a player killer, damage source should reflect that in case loot tables use that information
setMaybe(builder, LootParameters.DAMAGE_SOURCE, DamageSource.playerAttack(nmsKiller));
// SPIGOT-5603 - Set minecraft:killed_by_player
setMaybe(builder, LootParameters.LAST_DAMAGE_PLAYER, nmsKiller);
}
// SPIGOT-5603 - Use LootContext#lootingModifier
if (context.getLootingModifier() != LootContext.DEFAULT_LOOT_MODIFIER) {
setMaybe(builder, LootParameters.LOOTING_MOD, context.getLootingModifier());
}
}
// SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build()
// PAIL rename Builder
LootParameterSet.Builder nmsBuilder = new LootParameterSet.Builder();
for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
// PAIL rename required
// PAIL rename addRequired
nmsBuilder.required(param);
}
for (LootParameter<?> param : getHandle().getParamSet().getAllowed()) {
// PAIL rename optional
if (!getHandle().getParamSet().getAllowed().contains(param)) {
// PAIL rename required
// PAIL rename addOptional
nmsBuilder.optional(param);
}
}
nmsBuilder.optional(LootParameters.LOOTING_MOD);
return builder.create(nmsBuilder.build());
}
Aggregations