This commit is contained in:
IzzelAliz 2020-06-14 17:05:42 +08:00
parent 73ca496686
commit b1a5121a37
22 changed files with 540 additions and 86 deletions

View File

@ -0,0 +1,9 @@
package io.izzel.arclight.common.bridge.world.storage.loot;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.storage.loot.LootContext;
public interface LootTableBridge {
void bridge$fillInventory(IInventory inv, LootContext context, boolean plugin);
}

View File

@ -1,55 +0,0 @@
package io.izzel.arclight.common.mixin.core.entity.monster;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.ZombiePigmanEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DamageSource;
import org.bukkit.Bukkit;
import org.bukkit.entity.PigZombie;
import org.bukkit.event.entity.PigZombieAngerEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ZombiePigmanEntity.class)
public abstract class ZombiePigmanEntityMixin extends ZombieEntityMixin {
// @formatter:off
@Shadow protected abstract boolean becomeAngryAt(Entity p_70835_1_);
@Shadow protected abstract int func_223336_ef();
// @formatter:on
public boolean attackEntityFrom(DamageSource damagesource, float f) {
if (this.isInvulnerableTo(damagesource)) {
return false;
}
Entity entity = damagesource.getTrueSource();
boolean result = super.attackEntityFrom(damagesource, f);
if (result && entity instanceof PlayerEntity && !((PlayerEntity) entity).isCreative() && this.canEntityBeSeen(entity)) {
this.becomeAngryAt(entity);
}
return result;
}
@Inject(method = "becomeAngryAt", cancellable = true, at = @At("HEAD"))
private void arclight$anger(Entity entity, CallbackInfoReturnable<Boolean> cir) {
PigZombieAngerEvent event = new PigZombieAngerEvent((PigZombie) this.getBukkitEntity(), (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), this.func_223336_ef());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
cir.setReturnValue(false);
} else {
arclight$capture = event.getNewAnger();
}
}
private transient int arclight$capture;
@Redirect(method = "becomeAngryAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombiePigmanEntity;func_223336_ef()I"))
private int arclight$useAnger(ZombiePigmanEntity pigmanEntity) {
return arclight$capture;
}
}

View File

@ -1,33 +1,102 @@
package io.izzel.arclight.common.mixin.core.item;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.BoatEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BoatItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
import java.util.function.Predicate;
@Mixin(BoatItem.class)
public class BoatItemMixin {
public class BoatItemMixin extends Item {
@Inject(method = "onItemRightClick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "NEW", target = "net/minecraft/entity/item/BoatEntity"))
public void arclight$playerInteract(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack itemStack, RayTraceResult rayTraceResult) {
BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) rayTraceResult;
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockRayTraceResult.getPos(), blockRayTraceResult.getFace(), itemStack, handIn);
// @formatter:off
@Shadow @Final private static Predicate<Entity> field_219989_a;
@Shadow @Final private BoatEntity.Type type;
// @formatter:on
if (event.isCancelled()) {
cir.setReturnValue(new ActionResult<>(ActionResultType.PASS, itemStack));
public BoatItemMixin(Properties properties) {
super(properties);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);
RayTraceResult raytraceresult = rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.ANY);
if (raytraceresult.getType() == RayTraceResult.Type.MISS) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
} else {
Vec3d vec3d = playerIn.getLook(1.0F);
double d0 = 5.0D;
List<Entity> list = worldIn.getEntitiesInAABBexcluding(playerIn, playerIn.getBoundingBox().expand(vec3d.scale(5.0D)).grow(1.0D), field_219989_a);
if (!list.isEmpty()) {
Vec3d vec3d1 = playerIn.getEyePosition(1.0F);
for (Entity entity : list) {
AxisAlignedBB axisalignedbb = entity.getBoundingBox().grow((double) entity.getCollisionBorderSize());
if (axisalignedbb.contains(vec3d1)) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
}
}
}
if (raytraceresult.getType() == RayTraceResult.Type.BLOCK) {
BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) raytraceresult;
PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockRayTraceResult.getPos(), blockRayTraceResult.getFace(), itemstack, handIn);
if (event.isCancelled()) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
}
BoatEntity boatentity = new BoatEntity(worldIn, raytraceresult.getHitVec().x, raytraceresult.getHitVec().y, raytraceresult.getHitVec().z);
boatentity.setBoatType(this.type);
boatentity.rotationYaw = playerIn.rotationYaw;
if (!worldIn.hasNoCollisions(boatentity, boatentity.getBoundingBox().grow(-0.1D))) {
return new ActionResult<>(ActionResultType.FAIL, itemstack);
} else {
if (!worldIn.isRemote) {
if (CraftEventFactory.callEntityPlaceEvent(worldIn, blockRayTraceResult.getPos(), blockRayTraceResult.getFace(), playerIn, boatentity).isCancelled()) {
return new ActionResult<>(ActionResultType.FAIL, itemstack);
}
if (!worldIn.addEntity(boatentity)) {
return new ActionResult<>(ActionResultType.PASS, itemstack);
}
if (!playerIn.abilities.isCreativeMode) {
itemstack.shrink(1);
}
}
playerIn.addStat(Stats.ITEM_USED.get(this));
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}
} else {
return new ActionResult<>(ActionResultType.PASS, itemstack);
}
}
}
}

View File

@ -0,0 +1,108 @@
package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.block.BlockState;
import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SChangeBlockPacket;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(BucketItem.class)
public abstract class BucketItemMixin {
// @formatter:off
@Shadow public abstract boolean tryPlaceContainedLiquid(@javax.annotation.Nullable PlayerEntity player, World worldIn, BlockPos posIn, @javax.annotation.Nullable BlockRayTraceResult p_180616_4_);
// @formatter:on
@Inject(method = "onItemRightClick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/IBucketPickupHandler;pickupFluid(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/Fluid;"))
private void arclight$bucketFill(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack stack, RayTraceResult result) {
BlockPos pos = ((BlockRayTraceResult) result).getPos();
BlockState state = worldIn.getBlockState(pos);
Fluid dummyFluid = ((IBucketPickupHandler) state.getBlock()).pickupFluid(DummyGeneratorAccess.INSTANCE, pos, state);
PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(worldIn, playerIn, pos, pos, ((BlockRayTraceResult) result).getFace(), stack, dummyFluid.getFilledBucket());
if (event.isCancelled()) {
((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(worldIn, pos));
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, stack));
} else {
arclight$captureItem = event.getItemStack();
}
}
@Inject(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BucketItem;tryPlaceContainedLiquid(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockRayTraceResult;)Z"))
private void arclight$capture(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack stack, RayTraceResult result) {
BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result;
arclight$direction = blockRayTraceResult.getFace();
arclight$click = blockRayTraceResult.getPos();
arclight$stack = stack;
}
@Inject(method = "onItemRightClick", at = @At("RETURN"))
private void arclight$clean(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir) {
arclight$captureItem = null;
arclight$direction = null;
arclight$click = null;
arclight$stack = null;
}
private transient org.bukkit.inventory.@Nullable ItemStack arclight$captureItem;
@Redirect(method = "fillBucket", at = @At(value = "NEW", target = "net/minecraft/item/ItemStack"))
private ItemStack arclight$useCapture(Item fillBucket) {
return arclight$captureItem == null ? new ItemStack(fillBucket) : CraftItemStack.asNMSCopy(arclight$captureItem);
}
public boolean a(PlayerEntity entity, World world, BlockPos pos, @Nullable BlockRayTraceResult result, Direction direction, BlockPos clicked, ItemStack itemstack) {
arclight$direction = direction;
arclight$click = clicked;
arclight$stack = itemstack;
try {
return this.tryPlaceContainedLiquid(entity, world, pos, result);
} finally {
arclight$direction = null;
arclight$click = null;
arclight$stack = null;
}
}
private transient Direction arclight$direction;
private transient BlockPos arclight$click;
private transient ItemStack arclight$stack;
@Inject(method = "tryPlaceContainedLiquid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/dimension/Dimension;doesWaterVaporize()Z"))
private void arclight$bucketEmpty(PlayerEntity player, World worldIn, BlockPos posIn, BlockRayTraceResult p_180616_4_, CallbackInfoReturnable<Boolean> cir) {
if (player != null) {
PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack);
if (event.isCancelled()) {
((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(worldIn, posIn));
((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory();
cir.setReturnValue(false);
}
}
}
}

View File

@ -0,0 +1,47 @@
package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.entity.projectile.EggEntity;
import net.minecraft.item.EggItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(EggItem.class)
public abstract class EggItemMixin extends Item {
public EggItemMixin(Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack stack = playerIn.getHeldItem(handIn);
if (!worldIn.isRemote) {
EggEntity eggEntity = new EggEntity(worldIn, playerIn);
eggEntity.setItem(stack);
eggEntity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0f, 1.5f, 1.0f);
if (!worldIn.addEntity(eggEntity)) {
if (playerIn instanceof ServerPlayerEntity) {
((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
}
return ActionResult.resultFail(stack);
}
}
worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5f, 0.4f / (random.nextFloat() * 0.4f + 0.8f));
playerIn.addStat(Stats.ITEM_USED.get(this));
if (!playerIn.abilities.isCreativeMode) {
stack.shrink(1);
}
return ActionResult.resultSuccess(stack);
}
}

View File

@ -43,15 +43,14 @@ public class EnderPearlItemMixin extends Item {
}
}
if (!playerIn.abilities.isCreativeMode) {
itemstack.shrink(1);
}
worldIn.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
playerIn.getCooldownTracker().setCooldown(this, 20);
playerIn.addStat(Stats.ITEM_USED.get(this));
if (!playerIn.abilities.isCreativeMode) {
itemstack.shrink(1);
}
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}
}

View File

@ -1,18 +1,20 @@
package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.world.storage.MapDataBridge;
import net.minecraft.item.FilledMapItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.storage.MapData;
import org.bukkit.Bukkit;
import org.bukkit.event.server.MapInitializeEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import io.izzel.arclight.common.bridge.world.storage.MapDataBridge;
@Mixin(FilledMapItem.class)
public class FilledMapItemMixin {
@ -24,4 +26,14 @@ public class FilledMapItemMixin {
MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapData).bridge$getMapView());
Bukkit.getPluginManager().callEvent(event);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static int getMapId(ItemStack stack) {
CompoundNBT compoundnbt = stack.getTag();
return compoundnbt != null && compoundnbt.contains("map", 99) ? compoundnbt.getInt("map") : -1;
}
}

View File

@ -62,7 +62,7 @@ public class FishingRodItemMixin extends Item {
worldIn.addEntity(new FishingBobberEntity(playerIn, worldIn, j, k));
}
playerIn.swingArm(handIn);
// playerIn.swingArm(handIn);
playerIn.addStat(Stats.ITEM_USED.get(this));
}

View File

@ -1,14 +1,22 @@
package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.item.MerchantOfferBridge;
import net.minecraft.item.ItemStack;
import net.minecraft.item.MerchantOffer;
import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe;
import org.spongepowered.asm.mixin.Mixin;
import io.izzel.arclight.common.bridge.item.MerchantOfferBridge;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(MerchantOffer.class)
public class MerchantOfferMixin implements MerchantOfferBridge {
// @formatter:off
@Shadow public ItemStack buyingStackFirst;
// @formatter:on
private CraftMerchantRecipe bukkitHandle;
public CraftMerchantRecipe asBukkit() {
@ -28,4 +36,11 @@ public class MerchantOfferMixin implements MerchantOfferBridge {
public CraftMerchantRecipe bridge$asBukkit() {
return asBukkit();
}
@Inject(method = "func_222205_b", at = @At("HEAD"))
private void arclight$fix(CallbackInfoReturnable<ItemStack> cir) {
if (this.buyingStackFirst.getCount() <= 0) {
cir.setReturnValue(ItemStack.EMPTY);
}
}
}

View File

@ -2,6 +2,7 @@ package io.izzel.arclight.common.mixin.core.item;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.entity.projectile.TridentEntityBridge;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
@ -24,7 +25,8 @@ public class TridentItemMixin {
@Redirect(method = "onPlayerStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damageItem(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V"))
public void arclight$muteDamage(ItemStack stack, int amount, LivingEntity entityIn, Consumer<LivingEntity> onBroken) {
// do nothing
int j = EnchantmentHelper.getRiptideModifier(stack);
if (j != 0) stack.damageItem(amount, entityIn, onBroken);
}
private transient boolean arclight$success;

View File

@ -0,0 +1,45 @@
package io.izzel.arclight.common.mixin.v1_15.entity.ai.goal;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import net.minecraft.entity.ai.goal.FollowOwnerGoal;
import net.minecraft.entity.passive.TameableEntity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(FollowOwnerGoal.class)
public class FollowOwnerGoalMixin_1_15 {
// @formatter:off
@Shadow @Final private TameableEntity tameable;
// @formatter:on
private transient boolean arclight$cancelled;
@Redirect(method = "func_226328_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V"))
public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) {
CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity();
Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch);
EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location);
Bukkit.getPluginManager().callEvent(event);
if (!(arclight$cancelled = event.isCancelled())) {
tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}
@Inject(method = "func_226328_a_", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/pathfinding/PathNavigator;clearPath()V"))
public void arclight$returnIfFail(int p_226328_1_, int p_226328_2_, int p_226328_3_, CallbackInfoReturnable<Boolean> cir) {
if (arclight$cancelled) {
cir.setReturnValue(false);
}
arclight$cancelled = false;
}
}

View File

@ -0,0 +1,38 @@
package io.izzel.arclight.common.mixin.v1_15.entity.item;
import io.izzel.arclight.common.mixin.core.entity.EntityMixin;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.item.FallingBlockEntity;
import net.minecraft.util.math.BlockPos;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(FallingBlockEntity.class)
public abstract class FallingBlockEntityMixin_1_15 extends EntityMixin {
@Shadow private BlockState fallTile;
@Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private void arclight$entityChangeBlock(CallbackInfo ci, Block block, BlockPos pos) {
if (CraftEventFactory.callEntityChangeBlockEvent((FallingBlockEntity) (Object) this, pos, this.fallTile).isCancelled()) {
ci.cancel();
}
}
@Inject(method = "onLivingFall", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z"))
private void arclight$damageSource(float distance, float damageMultiplier, CallbackInfoReturnable<Boolean> cir) {
CraftEventFactory.entityDamage = (FallingBlockEntity) (Object) this;
}
@Inject(method = "onLivingFall", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z"))
private void arclight$damageSourceReset(float distance, float damageMultiplier, CallbackInfoReturnable<Boolean> cir) {
CraftEventFactory.entityDamage = null;
}
}

View File

@ -0,0 +1,61 @@
package io.izzel.arclight.common.mixin.v1_15.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.item.LeashKnotEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.LeadItem;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(LeadItem.class)
public class LeadItemMixin_1_15 {
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static ActionResultType func_226641_a_(PlayerEntity player, World worldIn, BlockPos fence) {
LeashKnotEntity leashknotentity = null;
boolean flag = false;
double d0 = 7.0D;
int i = fence.getX();
int j = fence.getY();
int k = fence.getZ();
for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) {
if (mobentity.getLeashHolder() == player) {
if (leashknotentity == null) {
leashknotentity = LeashKnotEntity.create(worldIn, fence);
HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
leashknotentity.remove();
return ActionResultType.PASS;
}
}
if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) {
continue;
}
mobentity.setLeashHolder(leashknotentity, true);
flag = true;
}
}
return flag ? ActionResultType.SUCCESS : ActionResultType.PASS;
}
}

View File

@ -0,0 +1,33 @@
package io.izzel.arclight.common.mixin.v1_15.world.storage.loot;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonObject;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(LootTableManager.class)
public class LootTableManagerMixin {
// @formatter:off
@Shadow private Map<ResourceLocation, LootTable> registeredLootTables;
// @formatter:on
public Map<LootTable, ResourceLocation> lootTableToKey = ImmutableMap.of();
@Inject(method = "apply", at = @At("RETURN"))
private void arclight$buildRev(Map<ResourceLocation, JsonObject> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn, CallbackInfo ci) {
ImmutableMap.Builder<LootTable, ResourceLocation> lootTableToKeyBuilder = ImmutableMap.builder();
this.registeredLootTables.forEach((lootTable, key) -> lootTableToKeyBuilder.put(key, lootTable));
this.lootTableToKey = lootTableToKeyBuilder.build();
}
}

View File

@ -0,0 +1,59 @@
package io.izzel.arclight.common.mixin.v1_15.world.storage.loot;
import io.izzel.arclight.common.bridge.world.storage.loot.LootTableBridge;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootTable;
import org.apache.logging.log4j.Logger;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.world.LootGenerateEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
@Mixin(LootTable.class)
public abstract class LootTableMixin implements LootTableBridge {
// @formatter:off
@Shadow @Final private static Logger LOGGER;
@Shadow public abstract List<ItemStack> generate(LootContext context);
@Shadow protected abstract List<Integer> getEmptySlotsRandomized(IInventory inventory, Random rand);
@Shadow protected abstract void shuffleItems(List<ItemStack> stacks, int p_186463_2_, Random rand);
// @formatter:on
public void fillInventory(IInventory inv, LootContext context, boolean plugin) {
List<ItemStack> list = this.generate(context);
Random random = context.getRandom();
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, plugin);
if (event.isCancelled()) {
return;
}
list = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList());
List<Integer> list1 = this.getEmptySlotsRandomized(inv, random);
this.shuffleItems(list, list1.size(), random);
for (ItemStack itemstack : list) {
if (list1.isEmpty()) {
LOGGER.warn("Tried to over-fill a container");
return;
}
if (itemstack.isEmpty()) {
inv.setInventorySlotContents(list1.remove(list1.size() - 1), ItemStack.EMPTY);
} else {
inv.setInventorySlotContents(list1.remove(list1.size() - 1), itemstack);
}
}
}
@Override
public void bridge$fillInventory(IInventory inv, LootContext context, boolean plugin) {
this.fillInventory(inv, context, plugin);
}
}

View File

@ -51,8 +51,10 @@
"enchantment.FrostWalkerEnchantmentMixin_1_15",
"entity.EntityMixin_1_15",
"entity.LivingEntityMixin_1_15",
"entity.ai.goal.FollowOwnerGoalMixin_1_15",
"entity.boss.WitherEntityMixin_1_15",
"entity.item.ArmorStandEntityMixin_1_15",
"entity.item.FallingBlockEntityMixin_1_15",
"entity.item.ItemEntityMixin_1_15",
"entity.monster.AbstractRaiderEntityMixin",
"entity.monster.RavagerEntityMixin_1_15",
@ -62,11 +64,14 @@
"entity.passive.BeeEntityMixin",
"entity.player.PlayerEntityMixin_1_15",
"entity.player.ServerPlayerEntityMixin_1_15",
"item.LeadItemMixin_1_15",
"item.crafting.SpecialRecipeMixin",
"world.ExplosionMixin_1_15",
"world.biome.BiomeContainerMixin",
"world.chunk.ChunkMixin_1_15",
"world.dimension.DimensionTypeMixin_1_15",
"world.server.TicketManagerMixin_1_15"
"world.server.TicketManagerMixin_1_15",
"world.storage.loot.LootTableManagerMixin",
"world.storage.loot.LootTableMixin"
]
}

View File

@ -98,7 +98,6 @@
"entity.ai.goal.BreedGoalMixin",
"entity.ai.goal.DefendVillageTargetGoalMixin",
"entity.ai.goal.EatGrassGoalMixin",
"entity.ai.goal.FollowOwnerGoalMixin",
"entity.ai.goal.HurtByTargetGoalMixin",
"entity.ai.goal.NearestAttackableTargetGoalMixin",
"entity.ai.goal.OwnerHurtByTargetGoalMixin",
@ -115,7 +114,6 @@
"entity.item.EnderPearlEntityMixin",
"entity.item.ExperienceBottleEntityMixin",
"entity.item.ExperienceOrbEntityMixin",
"entity.item.FallingBlockEntityMixin",
"entity.item.FireworkRocketEntityMixin",
"entity.item.HangingEntityMixin",
"entity.item.ItemEntityMixin",
@ -152,7 +150,6 @@
"entity.monster.WitherSkeletonEntityMixin",
"entity.monster.ZombieEntityMixin",
"entity.monster.ZombiePigmanEntity_HurtByAggressorGoalMixin",
"entity.monster.ZombiePigmanEntityMixin",
"entity.monster.ZombieVillagerEntityMixin",
"entity.passive.AnimalEntityMixin",
"entity.passive.BatEntityMixin",
@ -245,9 +242,11 @@
"item.BlockItemMixin",
"item.BoatItemMixin",
"item.BowItemMixin",
"item.BucketItemMixin",
"item.ChorusFruitItemMixin",
"item.CrossbowItemMixin",
"item.DyeItemMixin",
"item.EggItemMixin",
"item.EnderCrystalItemMixin",
"item.EnderPearlItemMixin",
"item.FilledMapItemMixin",
@ -256,7 +255,6 @@
"item.FlintAndSteelItemMixin",
"item.HangingEntityItemMixin",
"item.ItemStackMixin",
"item.LeadItemMixin",
"item.MerchantOfferMixin",
"item.MilkBucketItemMixin",
"item.MinecartItemMixin",

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.entity.ai.goal;
package io.izzel.arclight.impl.mixin.v1_14.entity.ai.goal;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import net.minecraft.entity.ai.goal.FollowOwnerGoal;
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(FollowOwnerGoal.class)
public class FollowOwnerGoalMixin {
public class FollowOwnerGoalMixin_1_14 {
// @formatter:off
@Shadow @Final protected TameableEntity tameable;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.entity.item;
package io.izzel.arclight.impl.mixin.v1_14.entity.item;
import io.izzel.arclight.common.mixin.core.entity.EntityMixin;
import net.minecraft.block.Block;
@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(FallingBlockEntity.class)
public abstract class FallingBlockEntityMixin extends EntityMixin {
public abstract class FallingBlockEntityMixin_1_14 extends EntityMixin {
@Shadow private BlockState fallTile;

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.item;
package io.izzel.arclight.impl.mixin.v1_14.entity.item;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(LeadItem.class)
public class LeadItemMixin {
public class LeadItemMixin_1_14 {
/**
* @author IzzelAliz

View File

@ -10,6 +10,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.PigZombie;
import org.bukkit.event.entity.PigZombieAngerEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -24,6 +25,11 @@ public abstract class ZombiePigmanEntityMixin_1_14 extends ZombieEntityMixin {
@Shadow protected abstract int func_223336_ef();
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public boolean attackEntityFrom(DamageSource damagesource, float f) {
if (this.isInvulnerableTo(damagesource)) {
return false;

View File

@ -50,9 +50,12 @@
"enchantment.FrostWalkerEnchantmentMixin_1_14",
"entity.EntityMixin_1_14",
"entity.LivingEntityMixin_1_14",
"entity.ai.goal.FollowOwnerGoalMixin_1_14",
"entity.boss.WitherEntityMixin_1_14",
"entity.item.ArmorStandEntityMixin_1_14",
"entity.item.FallingBlockEntityMixin_1_14",
"entity.item.ItemEntityMixin_1_14",
"entity.item.LeadItemMixin_1_14",
"entity.monster.PillagerEntityMixin_1_14",
"entity.monster.RavagerEntityMixin_1_14",
"entity.monster.ShulkerEntityMixin_1_14",