1.16: blocks, brain tasks

This commit is contained in:
IzzelAliz 2020-08-20 17:00:19 +08:00
parent f05961d60e
commit 35c30347a7
71 changed files with 881 additions and 443 deletions

View File

@ -6,6 +6,7 @@ public class ArclightVersion {
public static final ArclightVersion v1_14 = new ArclightVersion("1.14.4", 1140, "v1_14_R1"); public static final ArclightVersion v1_14 = new ArclightVersion("1.14.4", 1140, "v1_14_R1");
public static final ArclightVersion v1_15 = new ArclightVersion("1.15.2", 1152, "v1_15_R1"); public static final ArclightVersion v1_15 = new ArclightVersion("1.15.2", 1152, "v1_15_R1");
public static final ArclightVersion v1_16 = new ArclightVersion("1.16.2", 1162, "v1_16_R2");
private final String name; private final String name;
private final int num; private final int num;

View File

@ -3,9 +3,9 @@ package io.izzel.arclight.common.bridge.block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
public interface BlockBridge { public interface BlockBridge {
int bridge$getExpDrop(BlockState blockState, World world, BlockPos blockPos, ItemStack itemStack); int bridge$getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack);
} }

View File

@ -1,9 +0,0 @@
package io.izzel.arclight.common.bridge.block;
public interface NetherPortalBlockBridge {
interface SizeBridge {
boolean bridge$createPortal();
}
}

View File

@ -0,0 +1,15 @@
package io.izzel.arclight.common.bridge.block;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftPortalEvent;
public interface PortalInfoBridge {
void bridge$setPortalEventInfo(CraftPortalEvent event);
CraftPortalEvent bridge$getPortalEventInfo();
void bridge$setWorld(ServerWorld world);
ServerWorld bridge$getWorld();
}

View File

@ -0,0 +1,6 @@
package io.izzel.arclight.common.bridge.block;
public interface PortalSizeBridge {
boolean bridge$createPortal();
}

View File

@ -6,12 +6,12 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public interface EntityTypeBridge<T extends Entity> { public interface EntityTypeBridge<T extends Entity> {
T bridge$spawnCreature(World worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason); T bridge$spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason);
} }

View File

@ -3,7 +3,6 @@ package io.izzel.arclight.common.bridge.entity.player;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.bukkit.craftbukkit.v.entity.CraftPlayer;
@ -34,5 +33,5 @@ public interface ServerPlayerEntityBridge extends PlayerEntityBridge {
void bridge$reset(); void bridge$reset();
Entity bridge$changeDimension(DimensionType dimensionType, PlayerTeleportEvent.TeleportCause cause); Entity bridge$changeDimension(ServerWorld world, PlayerTeleportEvent.TeleportCause cause);
} }

View File

@ -0,0 +1,8 @@
package io.izzel.arclight.common.bridge.world;
import net.minecraft.world.server.ServerWorld;
public interface IWorldBridge {
ServerWorld bridge$getMinecraftWorld();
}

View File

@ -7,7 +7,7 @@ import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.spigotmc.SpigotWorldConfig; import org.spigotmc.SpigotWorldConfig;
public interface WorldBridge extends IWorldWriterBridge { public interface WorldBridge extends IWorldWriterBridge, IWorldBridge {
CraftServer bridge$getServer(); CraftServer bridge$getServer();

View File

@ -36,7 +36,7 @@ public class AbstractButtonBlockMixin {
// @formatter:on // @formatter:on
@Inject(method = "checkPressed", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, @Inject(method = "checkPressed", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/IProperty;)Ljava/lang/Comparable;")) at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/Property;)Ljava/lang/Comparable;"))
public void arclight$entityInteract(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci, public void arclight$entityInteract(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci,
List<? extends Entity> list, boolean flag) { List<? extends Entity> list, boolean flag) {
boolean flag1 = state.get(AbstractButtonBlock.POWERED); boolean flag1 = state.get(AbstractButtonBlock.POWERED);

View File

@ -0,0 +1,22 @@
package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(AbstractFireBlock.class)
public class AbstractFireBlockMixin {
@Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
public boolean arclight$extinguish2(World world, BlockPos pos, boolean isMoving) {
if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.getDefaultState()).isCancelled()) {
world.removeBlock(pos, isMoving);
}
return false;
}
}

View File

@ -0,0 +1,21 @@
package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.AbstractTopPlantBlock;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.Random;
@Mixin(AbstractTopPlantBlock.class)
public class AbstractTopPlantBlockMixin {
@Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
private boolean arclight$blockGrow(ServerWorld world, BlockPos to, BlockState state, BlockState state1, ServerWorld worldIn, BlockPos from, Random random) {
return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state);
}
}

View File

@ -37,10 +37,10 @@ public abstract class BambooBlockMixin extends BlockMixin {
boolean update = false; boolean update = false;
if (height >= 1) { if (height >= 1) {
if (blockstate.getBlock() == Blocks.BAMBOO && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) { if (blockstate.isIn(Blocks.BAMBOO) && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) {
if (blockstate.getBlock() == Blocks.BAMBOO && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) { if (blockstate.isIn(Blocks.BAMBOO) && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) {
bambooleaves = BambooLeaves.LARGE; bambooleaves = BambooLeaves.LARGE;
if (blockstate1.getBlock() == Blocks.BAMBOO) { if (blockstate1.isIn(Blocks.BAMBOO)) {
update = true; update = true;
} }
} }
@ -49,7 +49,7 @@ public abstract class BambooBlockMixin extends BlockMixin {
} }
} }
int newAge = blockStateIn.get(PROPERTY_AGE) != 1 && blockstate1.getBlock() != Blocks.BAMBOO ? 0 : 1; int newAge = blockStateIn.get(PROPERTY_AGE) != 1 && !blockstate1.isIn(Blocks.BAMBOO) ? 0 : 1;
int newState = (height < 11 || !(rand.nextFloat() < 0.25F)) && height != 15 ? 0 : 1; int newState = (height < 11 || !(rand.nextFloat() < 0.25F)) && height != 15 ? 0 : 1;
if (CraftEventFactory.handleBlockSpreadEvent(worldIn, posIn, posIn.up(), if (CraftEventFactory.handleBlockSpreadEvent(worldIn, posIn, posIn.up(),

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(BambooSaplingBlock.class) @Mixin(BambooSaplingBlock.class)
public class BambooSaplingBlockMixin { public class BambooSaplingBlockMixin {
@Redirect(method = "func_220087_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "growBamboo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$blockSpread(World world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$blockSpread(World world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockSpreadEvent(world, pos.down(), pos, newState, flags); return CraftEventFactory.handleBlockSpreadEvent(world, pos.down(), pos, newState, flags);
} }

View File

@ -0,0 +1,20 @@
package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.entity.MobEntityBridge;
import net.minecraft.block.BeehiveBlock;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.BeeEntity;
import org.bukkit.event.entity.EntityTargetEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(BeehiveBlock.class)
public class BeehiveBlockMixin {
@Redirect(method = "angerNearbyBees", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/BeeEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V"))
private void arclight$targetReason(BeeEntity beeEntity, LivingEntity livingEntity) {
((MobEntityBridge) beeEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true);
beeEntity.setAttackTarget(livingEntity);
}
}

View File

@ -6,7 +6,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
@ -17,11 +16,8 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.LootParameters;
import net.minecraftforge.common.extensions.IForgeBlock; import net.minecraftforge.common.extensions.IForgeBlock;
import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
@ -44,7 +40,6 @@ public abstract class BlockMixin implements BlockBridge {
@Shadow public abstract BlockState getDefaultState(); @Shadow public abstract BlockState getDefaultState();
@Shadow @Nullable public BlockState getStateForPlacement(BlockItemUseContext context) { return null; } @Shadow @Nullable public BlockState getStateForPlacement(BlockItemUseContext context) { return null; }
@Shadow public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { return null; } @Shadow public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { return null; }
@Shadow public abstract int tickRate(IWorldReader worldIn);
// @formatter:on // @formatter:on
/** /**
@ -69,24 +64,14 @@ public abstract class BlockMixin implements BlockBridge {
} }
} }
/** public int getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack) {
* @author IzzelAliz
* @reason
*/
@Overwrite
public static List<ItemStack> getDrops(BlockState state, ServerWorld worldIn, BlockPos pos, @Nullable TileEntity tileEntityIn, Entity entityIn, ItemStack stack) {
LootContext.Builder lootcontext$builder = (new LootContext.Builder(worldIn)).withRandom(worldIn.rand).withParameter(LootParameters.POSITION, pos).withParameter(LootParameters.TOOL, stack).withNullableParameter(LootParameters.THIS_ENTITY, entityIn).withNullableParameter(LootParameters.BLOCK_ENTITY, tileEntityIn);
return state.getDrops(lootcontext$builder);
}
public int getExpDrop(BlockState blockState, World world, BlockPos blockPos, ItemStack itemStack) {
int silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemStack); int silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemStack);
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack); int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack);
return ((IForgeBlock) this).getExpDrop(blockState, world, blockPos, fortune, silkTouch); return ((IForgeBlock) this).getExpDrop(blockState, world, blockPos, fortune, silkTouch);
} }
@Override @Override
public int bridge$getExpDrop(BlockState blockState, World world, BlockPos blockPos, ItemStack itemStack) { public int bridge$getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack) {
return getExpDrop(blockState, world, blockPos, itemStack); return getExpDrop(blockState, world, blockPos, itemStack);
} }

View File

@ -27,7 +27,7 @@ public class CactusBlockMixin {
CraftEventFactory.blockDamage = null; CraftEventFactory.blockDamage = null;
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
private boolean arclight$blockGrow(ServerWorld serverWorld, BlockPos pos, BlockState state) { private boolean arclight$blockGrow(ServerWorld serverWorld, BlockPos pos, BlockState state) {
return CraftEventFactory.handleBlockGrowEvent(serverWorld, pos, state); return CraftEventFactory.handleBlockGrowEvent(serverWorld, pos, state);
} }

View File

@ -2,7 +2,7 @@ package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.CampfireBlock; import net.minecraft.block.CampfireBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class CampfireBlockMixin { public class CampfireBlockMixin {
@Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void arclight$onFire(World worldIn, BlockState state, BlockRayTraceResult hit, Entity projectile, CallbackInfo ci) { public void arclight$onFire(World worldIn, BlockState state, BlockRayTraceResult hit, ProjectileEntity projectile, CallbackInfo ci) {
if (CraftEventFactory.callBlockIgniteEvent(worldIn, hit.getPos(), projectile).isCancelled()) { if (CraftEventFactory.callBlockIgniteEvent(worldIn, hit.getPos(), projectile).isCancelled()) {
ci.cancel(); ci.cancel();
} }

View File

@ -83,7 +83,7 @@ public class CauldronBlockMixin {
@Inject(method = "fillWithRain", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Inject(method = "fillWithRain", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public void arclight$fillRain(World worldIn, BlockPos pos, CallbackInfo ci) { public void arclight$fillRain(World worldIn, BlockPos pos, CallbackInfo ci) {
BlockState state = worldIn.getBlockState(pos); BlockState state = worldIn.getBlockState(pos);
BlockState cycle = state.cycle(CauldronBlock.LEVEL); BlockState cycle = state.func_235896_a_(CauldronBlock.LEVEL);
int newLevel = cycle.get(CauldronBlock.LEVEL); int newLevel = cycle.get(CauldronBlock.LEVEL);
if (!changeLevel(worldIn, pos, state, newLevel, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN)) { if (!changeLevel(worldIn, pos, state, newLevel, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN)) {
ci.cancel(); ci.cancel();

View File

@ -11,7 +11,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -37,80 +36,76 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin {
* @reason * @reason
*/ */
@Overwrite @Overwrite
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
if (!state.isValidPosition(worldIn, pos)) { BlockPos blockpos = pos.up();
worldIn.destroyBlock(pos, true); if (worldIn.isAirBlock(blockpos) && blockpos.getY() < 256) {
} else { int i = state.get(AGE);
BlockPos blockpos = pos.up(); if (i < 5 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true)) {
if (worldIn.isAirBlock(blockpos) && blockpos.getY() < worldIn.getDimension().getHeight()) { boolean flag = false;
int i = state.get(AGE); boolean flag1 = false;
if (i < 5 && ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true)) { BlockState blockstate = worldIn.getBlockState(pos.down());
boolean flag = false; Block block = blockstate.getBlock();
boolean flag1 = false; if (block == Blocks.END_STONE) {
BlockState blockstate = worldIn.getBlockState(pos.down()); flag = true;
Block block = blockstate.getBlock(); } else if (block == this.plantBlock) {
if (block == Blocks.END_STONE) { int j = 1;
flag = true;
} else if (block == this.plantBlock) {
int j = 1;
for (int k = 0; k < 4; ++k) { for (int k = 0; k < 4; ++k) {
Block block1 = worldIn.getBlockState(pos.down(j + 1)).getBlock(); Block block1 = worldIn.getBlockState(pos.down(j + 1)).getBlock();
if (block1 != this.plantBlock) { if (block1 != this.plantBlock) {
if (block1 == Blocks.END_STONE) { if (block1 == Blocks.END_STONE) {
flag1 = true; flag1 = true;
}
break;
} }
break;
++j;
} }
if (j < 2 || j <= random.nextInt(flag1 ? 5 : 4)) { ++j;
flag = true;
}
} else if (blockstate.isAir(worldIn, pos.down())) {
flag = true;
} }
if (flag && areAllNeighborsEmpty(worldIn, blockpos, null) && worldIn.isAirBlock(pos.up(2))) { if (j < 2 || j <= random.nextInt(flag1 ? 5 : 4)) {
if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, pos.up(), state.with(ChorusFlowerBlock.AGE, i), 2)) { flag = true;
worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2); }
this.placeGrownFlower(worldIn, blockpos, i); } else if (blockstate.isAir(worldIn, pos.down())) {
} flag = true;
} else if (i < 4) { }
int l = random.nextInt(4);
if (flag1) {
++l;
}
boolean flag2 = false; if (flag && areAllNeighborsEmpty(worldIn, blockpos, (Direction) null) && worldIn.isAirBlock(pos.up(2))) {
if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, this.getDefaultState().with(ChorusFlowerBlock.AGE, i), 2)) {
worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2);
this.placeGrownFlower(worldIn, blockpos, i);
}
} else if (i < 4) {
int l = random.nextInt(4);
if (flag1) {
++l;
}
for (int i1 = 0; i1 < l; ++i1) { boolean flag2 = false;
Direction direction = Direction.Plane.HORIZONTAL.random(random);
BlockPos blockpos1 = pos.offset(direction); for (int i1 = 0; i1 < l; ++i1) {
if (worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, direction.getOpposite())) { Direction direction = Direction.Plane.HORIZONTAL.random(random);
if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, state.with(ChorusFlowerBlock.AGE, i + 1), 2)) { BlockPos blockpos1 = pos.offset(direction);
this.placeGrownFlower(worldIn, blockpos1, i + 1); if (worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, direction.getOpposite())) {
flag2 = true; if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, this.getDefaultState().with(ChorusFlowerBlock.AGE, i + 1), 2)) {
} this.placeGrownFlower(worldIn, blockpos1, i + 1);
flag2 = true;
} }
} }
}
if (flag2) { if (flag2) {
worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2); worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2);
} else {
if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) {
this.placeDeadFlower(worldIn, pos);
}
}
} else { } else {
if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) { if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) {
this.placeDeadFlower(worldIn, pos); this.placeDeadFlower(worldIn, pos);
} }
} }
ForgeHooks.onCropsGrowPost(worldIn, pos, state); } else {
if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) {
this.placeDeadFlower(worldIn, pos);
}
} }
net.minecraftforge.common.ForgeHooks.onCropsGrowPost(worldIn, pos, state);
} }
} }
} }

View File

@ -12,8 +12,13 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(CocoaBlock.class) @Mixin(CocoaBlock.class)
public class CocoaBlockMixin { public class CocoaBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$blockGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$blockGrow1(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
}
@Redirect(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean arclight$blockGrow2(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
} }
} }

View File

@ -6,22 +6,16 @@ import net.minecraft.block.CommandBlockBlock;
import net.minecraft.tileentity.CommandBlockTileEntity; import net.minecraft.tileentity.CommandBlockTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockRedstoneEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(CommandBlockBlock.class) @Mixin(CommandBlockBlock.class)
public abstract class CommandBlockBlockMixin { public abstract class CommandBlockBlockMixin {
// @formatter:off
@Shadow public abstract int tickRate(IWorldReader worldIn);
// @formatter:on
/** /**
* @author IzzelAliz * @author IzzelAliz
* @reason * @reason
@ -46,7 +40,7 @@ public abstract class CommandBlockBlockMixin {
if (!flag1 && !commandblocktileentity.isAuto() && commandblocktileentity.getMode() != CommandBlockTileEntity.Mode.SEQUENCE) { if (!flag1 && !commandblocktileentity.isAuto() && commandblocktileentity.getMode() != CommandBlockTileEntity.Mode.SEQUENCE) {
if (flag) { if (flag) {
commandblocktileentity.setConditionMet(); commandblocktileentity.setConditionMet();
worldIn.getPendingBlockTicks().scheduleTick(pos, (CommandBlockBlock) (Object) this, this.tickRate(worldIn)); worldIn.getPendingBlockTicks().scheduleTick(pos, (CommandBlockBlock) (Object) this, 1);
} }
} }

View File

@ -1,17 +1,39 @@
package io.izzel.arclight.common.mixin.core.block; package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ComposterBlock; import net.minecraft.block.ComposterBlock;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.IntegerProperty;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder;
import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ComposterBlock.class) @Mixin(ComposterBlock.class)
public class ComposterBlockMixin { public abstract class ComposterBlockMixin {
// @formatter:off
@Shadow @Final public static IntegerProperty LEVEL;
@Shadow @Final public static Object2FloatMap<IItemProvider> CHANCES;
@Shadow private static BlockState resetFillState(BlockState state, IWorld world, BlockPos pos) { return null; }
@Shadow public static BlockState empty(BlockState state, World world, BlockPos pos) { return null; }
// @formatter:on
@SuppressWarnings("UnresolvedMixinReference") @SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "createInventory", at = @At(value = "NEW", target = "()Lnet/minecraft/block/ComposterBlock$EmptyInventory;")) @Redirect(method = "createInventory", at = @At(value = "NEW", target = "()Lnet/minecraft/block/ComposterBlock$EmptyInventory;"))
@ -20,4 +42,63 @@ public class ComposterBlockMixin {
((IInventoryBridge) inventory).setOwner(new CraftBlockInventoryHolder(world, blockPos, inventory)); ((IInventoryBridge) inventory).setOwner(new CraftBlockInventoryHolder(world, blockPos, inventory));
return inventory; return inventory;
} }
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static BlockState attemptFill(BlockState state, ServerWorld world, ItemStack stack, BlockPos pos) {
int i = state.get(LEVEL);
if (i < 7 && CHANCES.containsKey(stack.getItem())) {
double rand = world.rand.nextDouble();
BlockState state1 = attemptCompost(state, DummyGeneratorAccess.INSTANCE, pos, stack, rand);
if (state == state1 || CraftEventFactory.callEntityChangeBlockEvent(ArclightCaptures.getEntityChangeBlock(), pos, state1).isCancelled()) {
return state;
}
state1 = attemptCompost(state, world, pos, stack, rand);
stack.shrink(1);
return state1;
} else {
return state;
}
}
@Inject(method = "empty", cancellable = true, at = @At("HEAD"))
private static void arclight$emptyComposter(BlockState state, World world, BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
Entity entity = ArclightCaptures.getEntityChangeBlock();
if (entity != null) {
BlockState blockState = resetFillState(state, DummyGeneratorAccess.INSTANCE, pos);
if (CraftEventFactory.callEntityChangeBlockEvent(entity, pos, blockState).isCancelled()) {
cir.setReturnValue(state);
}
}
}
private static BlockState d(BlockState state, World world, BlockPos pos, Entity entity) {
ArclightCaptures.captureEntityChangeBlock(entity);
return empty(state, world, pos);
}
private static BlockState b(BlockState state, IWorld world, BlockPos pos, ItemStack stack, double rand) {
return attemptCompost(state, world, pos, stack, rand);
}
private static BlockState attemptCompost(BlockState state, IWorld world, BlockPos pos, ItemStack stack, double rand) {
int i = state.get(LEVEL);
float f = CHANCES.getFloat(stack.getItem());
if ((i != 0 || !(f > 0.0F)) && !(rand < (double) f)) {
return state;
} else {
int j = i + 1;
BlockState blockstate = state.with(LEVEL, j);
world.setBlockState(pos, blockstate, 3);
if (j == 7) {
world.getPendingBlockTicks().scheduleTick(pos, state.getBlock(), 20);
}
return blockstate;
}
}
} }

View File

@ -37,7 +37,7 @@ public abstract class ComposterBlock_FullInventoryMixin extends InventoryMixin {
@Overwrite @Overwrite
public void markDirty() { public void markDirty() {
if (this.isEmpty()) { if (this.isEmpty()) {
ComposterBlock.clear(this.state, this.world, this.pos); ComposterBlock.resetFillState(this.state, this.world, this.pos);
this.extracted = true; this.extracted = true;
} else { } else {
this.world.setBlockState(this.pos, this.state, 3); this.world.setBlockState(this.pos, this.state, 3);

View File

@ -46,6 +46,9 @@ public abstract class ConcretePowderBlockMixin extends FallingBlockMixin {
@Redirect(method = "updatePostPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;")) @Redirect(method = "updatePostPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;"))
public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (!(worldIn instanceof World)) {
return this.solidifiedState;
}
CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos); CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos);
blockState.setData(this.solidifiedState); blockState.setData(this.solidifiedState);
BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState); BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState);

View File

@ -29,7 +29,7 @@ public class CropsBlockMixin {
return event.isCancelled(); return event.isCancelled();
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$blockGrowTick(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$blockGrowTick(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
} }

View File

@ -21,7 +21,7 @@ public class DetectorRailBlockMixin {
private transient boolean arclight$flag; private transient boolean arclight$flag;
@Inject(method = "updatePoweredState", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "JUMP", ordinal = 0, opcode = Opcodes.IFEQ)) @Inject(method = "updatePoweredState", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ))
public void arclight$blockRedstone(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci, boolean flag, boolean flag1) { public void arclight$blockRedstone(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci, boolean flag, boolean flag1) {
if (flag != flag1) { if (flag != flag1) {
Block block = CraftBlock.at(worldIn, pos); Block block = CraftBlock.at(worldIn, pos);
@ -34,7 +34,7 @@ public class DetectorRailBlockMixin {
} }
// todo 注入顺序 // todo 注入顺序
@ModifyVariable(method = "updatePoweredState", index = 5, name = "flag1", at = @At(value = "JUMP", ordinal = 0, opcode = Opcodes.IFEQ)) @ModifyVariable(method = "updatePoweredState", index = 5, name = "flag1", at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ))
public boolean arclight$blockRedstone(boolean flag1) { public boolean arclight$blockRedstone(boolean flag1) {
return arclight$flag; return arclight$flag;
} }

View File

@ -12,7 +12,7 @@ import net.minecraft.tileentity.DispenserTileEntity;
import net.minecraft.tileentity.HopperTileEntity; import net.minecraft.tileentity.HopperTileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest; import org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
@ -33,7 +33,7 @@ public class DropperBlockMixin {
* @reason * @reason
*/ */
@Overwrite @Overwrite
public void dispense(World worldIn, BlockPos pos) { public void dispense(ServerWorld worldIn, BlockPos pos) {
ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos); ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos);
DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity(); DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity();
int i = dispensertileentity.getDispenseSlot(); int i = dispensertileentity.getDispenseSlot();
@ -63,7 +63,7 @@ public class DropperBlockMixin {
return; return;
} }
itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite()); itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite());
if (event.getItem().equals(craftItemStack) &&itemstack1.isEmpty()) { if (event.getItem().equals(craftItemStack) && itemstack1.isEmpty()) {
itemstack1 = itemstack.copy(); itemstack1 = itemstack.copy();
itemstack1.shrink(1); itemstack1.shrink(1);
} else { } else {

View File

@ -7,30 +7,32 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.EndPortalBlock; import net.minecraft.block.EndPortalBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.event.entity.EntityPortalEnterEvent; import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; 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.CallbackInfo;
@Mixin(EndPortalBlock.class) @Mixin(EndPortalBlock.class)
public class EndPortalBlockMixin { public class EndPortalBlockMixin {
@Inject(method = "onEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;changeDimension(Lnet/minecraft/world/dimension/DimensionType;)Lnet/minecraft/entity/Entity;")) @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getWorld(Lnet/minecraft/util/RegistryKey;)Lnet/minecraft/world/server/ServerWorld;"))
public void arclight$enterPortal(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { public ServerWorld arclight$enterPortal(MinecraftServer minecraftServer, RegistryKey<World> dimension, BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
ServerWorld world = minecraftServer.getWorld(dimension);
EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(),
new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ())); new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ()));
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (entityIn instanceof ServerPlayerEntity) { if (entityIn instanceof ServerPlayerEntity && world != null) {
((ServerPlayerEntityBridge) entityIn).bridge$changeDimension(worldIn.dimension.getType() == DimensionType.THE_END ? DimensionType.OVERWORLD : DimensionType.THE_END, ((ServerPlayerEntityBridge) entityIn).bridge$changeDimension(world, PlayerTeleportEvent.TeleportCause.END_PORTAL);
PlayerTeleportEvent.TeleportCause.END_PORTAL); return null;
ci.cancel();
} }
return world;
} }
} }

View File

@ -23,7 +23,7 @@ public abstract class FarmlandBlockMixin extends BlockMixin {
} }
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$moistureChange(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$moistureChange(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleMoistureChangeEvent(world, pos, newState, flags); return CraftEventFactory.handleMoistureChangeEvent(world, pos, newState, flags);
} }

View File

@ -32,7 +32,7 @@ import java.util.Random;
public abstract class FireBlockMixin implements FireBlockBridge { public abstract class FireBlockMixin implements FireBlockBridge {
// @formatter:off // @formatter:off
@Shadow public abstract BlockState getStateForPlacement(IBlockReader p_196448_1_, BlockPos p_196448_2_); @Shadow protected abstract BlockState getStateForPlacement(IBlockReader p_196448_1_, BlockPos p_196448_2_);
@Shadow @Final private Object2IntMap<net.minecraft.block.Block> flammabilities; @Shadow @Final private Object2IntMap<net.minecraft.block.Block> flammabilities;
// @formatter:on // @formatter:on
@ -68,6 +68,9 @@ public abstract class FireBlockMixin implements FireBlockBridge {
@Redirect(method = "updatePostPlacement", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDefaultState()Lnet/minecraft/block/BlockState;")) @Redirect(method = "updatePostPlacement", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDefaultState()Lnet/minecraft/block/BlockState;"))
public BlockState arclight$blockFade(net.minecraft.block.Block block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { public BlockState arclight$blockFade(net.minecraft.block.Block block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
if (!(worldIn instanceof World)) {
return Blocks.AIR.getDefaultState();
}
CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos); CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos);
blockState.setData(Blocks.AIR.getDefaultState()); blockState.setData(Blocks.AIR.getDefaultState());
BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState); BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState);
@ -79,14 +82,6 @@ public abstract class FireBlockMixin implements FireBlockBridge {
} }
} }
@Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
public boolean arclight$extinguish2(World world, BlockPos pos, boolean isMoving) {
if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.getDefaultState()).isCancelled()) {
world.removeBlock(pos, isMoving);
}
return false;
}
@Override @Override
public boolean bridge$canBurn(net.minecraft.block.Block block) { public boolean bridge$canBurn(net.minecraft.block.Block block) {
return this.flammabilities.containsKey(block); return this.flammabilities.containsKey(block);

View File

@ -0,0 +1,29 @@
package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FungusBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.TreeType;
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.CallbackInfo;
import java.util.Random;
@Mixin(FungusBlock.class)
public class FungusBlockMixin {
@SuppressWarnings("ConstantConditions")
@Inject(method = "grow", at = @At("HEAD"))
private void arclight$captureTree(ServerWorld worldIn, Random rand, BlockPos pos, BlockState state, CallbackInfo ci) {
if ((Object) this == Blocks.WARPED_FUNGUS) {
ArclightCaptures.captureTreeType(TreeType.WARPED_FUNGUS);
} else if ((Object) this == Blocks.CRIMSON_FUNGUS) {
ArclightCaptures.captureTreeType(TreeType.CRIMSON_FUNGUS);
}
}
}

View File

@ -16,7 +16,7 @@ public class IceBlockMixin {
@Inject(method = "turnIntoWater", cancellable = true, at = @At("HEAD")) @Inject(method = "turnIntoWater", cancellable = true, at = @At("HEAD"))
public void arclight$blockFade(BlockState blockState, World world, BlockPos blockPos, CallbackInfo ci) { public void arclight$blockFade(BlockState blockState, World world, BlockPos blockPos, CallbackInfo ci) {
if (CraftEventFactory.callBlockFadeEvent(world, blockPos, world.dimension.doesWaterVaporize() if (CraftEventFactory.callBlockFadeEvent(world, blockPos, world.func_230315_m_().func_236040_e_()
? Blocks.AIR.getDefaultState() : Blocks.WATER.getDefaultState()).isCancelled()) { ? Blocks.AIR.getDefaultState() : Blocks.WATER.getDefaultState()).isCancelled()) {
ci.cancel(); ci.cancel();
} }

View File

@ -1,19 +1,36 @@
package io.izzel.arclight.common.mixin.core.block; package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.MushroomBlock; import net.minecraft.block.MushroomBlock;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import org.bukkit.TreeType;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; 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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Random;
@Mixin(MushroomBlock.class) @Mixin(MushroomBlock.class)
public class MushroomBlockMixin { public class MushroomBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$blockSpread(ServerWorld world, BlockPos toPos, BlockState newState, int flags, BlockState state, ServerWorld worldIn, BlockPos fromPos) { public boolean arclight$blockSpread(ServerWorld world, BlockPos toPos, BlockState newState, int flags, BlockState state, ServerWorld worldIn, BlockPos fromPos) {
return CraftEventFactory.handleBlockSpreadEvent(world, fromPos, toPos, newState, flags); return CraftEventFactory.handleBlockSpreadEvent(world, fromPos, toPos, newState, flags);
} }
@SuppressWarnings("ConstantConditions")
@Inject(method = "grow(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Ljava/util/Random;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/feature/ConfiguredFeature;func_242765_a(Lnet/minecraft/world/ISeedReader;Lnet/minecraft/world/gen/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;)Z"))
private void arclight$captureTree(ServerWorld world, BlockPos pos, BlockState state, Random rand, CallbackInfoReturnable<Boolean> cir) {
if ((Object) this == Blocks.BROWN_MUSHROOM) {
ArclightCaptures.captureTreeType(TreeType.BROWN_MUSHROOM);
} else if ((Object) this == Blocks.RED_MUSHROOM) {
ArclightCaptures.captureTreeType(TreeType.RED_MUSHROOM);
}
}
} }

View File

@ -1,6 +1,5 @@
package io.izzel.arclight.common.mixin.core.block; package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.block.NetherPortalBlockBridge;
import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.EntityTypeBridge; import io.izzel.arclight.common.bridge.entity.EntityTypeBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.WorldBridge;
@ -13,8 +12,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
@ -24,23 +23,15 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 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(NetherPortalBlock.class) @Mixin(NetherPortalBlock.class)
public class NetherPortalBlockMixin { public class NetherPortalBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawn(Lnet/minecraft/world/World;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;"))
public Entity arclight$spawn(EntityType<?> entityType, World worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1) { public Entity arclight$spawn(EntityType<?> entityType, ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1) {
return ((EntityTypeBridge<?>) entityType).bridge$spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, CreatureSpawnEvent.SpawnReason.NETHER_PORTAL); return ((EntityTypeBridge<?>) entityType).bridge$spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
} }
@Inject(method = "trySpawnPortal", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/NetherPortalBlock$Size;placePortalBlocks()V"))
public void arclight$spawnPortal(IWorld worldIn, BlockPos pos, CallbackInfoReturnable<Boolean> cir, NetherPortalBlock.Size size) {
cir.setReturnValue(((NetherPortalBlockBridge.SizeBridge) size).bridge$createPortal());
}
@Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPortal(Lnet/minecraft/util/math/BlockPos;)V")) @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPortal(Lnet/minecraft/util/math/BlockPos;)V"))
public void arclight$portalEnter(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { public void arclight$portalEnter(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) {
EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(),

View File

@ -1,130 +0,0 @@
package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.block.NetherPortalBlockBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.NetherPortalBlock;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.block.CraftBlockState;
import org.bukkit.event.world.PortalCreateEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@Mixin(NetherPortalBlock.Size.class)
public abstract class NetherPortalBlock_SizeMixin implements NetherPortalBlockBridge.SizeBridge {
// @formatter:off
@Shadow public abstract void placePortalBlocks();
@Shadow @Final private IWorld world;
@Shadow private int width;
@Shadow @Nullable private BlockPos bottomLeft;
@Shadow @Final private Direction rightDir;
@Shadow private int height;
@Shadow @Final private Direction.Axis axis;
@Shadow protected abstract boolean func_196900_a(net.minecraft.block.BlockState pos);
@Shadow private int portalBlockCount;
@Shadow @Final private Direction leftDir;
// @formatter:on
List<BlockState> blocks = new ArrayList<>();
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
protected int calculatePortalHeight() {
this.blocks.clear();
label56:
for (this.height = 0; this.height < 21; ++this.height) {
for (int i = 0; i < this.width; ++i) {
BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i).up(this.height);
net.minecraft.block.BlockState blockstate = this.world.getBlockState(blockpos);
if (!this.func_196900_a(blockstate)) {
break label56;
}
Block block = blockstate.getBlock();
if (block == Blocks.NETHER_PORTAL) {
++this.portalBlockCount;
}
if (i == 0) {
BlockPos framePos = blockpos.offset(this.leftDir);
if (!this.world.getBlockState(framePos).isPortalFrame(this.world, framePos)) {
break label56;
} else {
blocks.add(CraftBlock.at(world, framePos).getState());
}
} else if (i == this.width - 1) {
BlockPos framePos = blockpos.offset(this.rightDir);
if (!this.world.getBlockState(framePos).isPortalFrame(this.world, framePos)) {
break label56;
} else {
blocks.add(CraftBlock.at(world, framePos).getState());
}
}
}
}
for (int j = 0; j < this.width; ++j) {
BlockPos framePos = this.bottomLeft.offset(this.rightDir, j).up(this.height);
if (!this.world.getBlockState(framePos).isPortalFrame(this.world, framePos)) {
this.height = 0;
break;
} else {
blocks.add(CraftBlock.at(world, framePos).getState());
}
}
if (this.height <= 21 && this.height >= 3) {
return this.height;
} else {
this.bottomLeft = null;
this.width = 0;
this.height = 0;
return 0;
}
}
public boolean createPortal() {
CraftWorld craftWorld = ((WorldBridge) this.world.getWorld()).bridge$getWorld();
for (int i = 0; i < this.width; ++i) {
BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i);
for (int j = 0; j < this.height; ++j) {
BlockPos blockPos = blockpos.up(j);
CraftBlockState blockState = CraftBlockState.getBlockState(this.world.getWorld(), blockPos, 18);
blockState.setData(Blocks.NETHER_PORTAL.getDefaultState().with(NetherPortalBlock.AXIS, this.axis));
blocks.add(blockState);
}
}
PortalCreateEvent event = new PortalCreateEvent(blocks, craftWorld, null, PortalCreateEvent.CreateReason.FIRE);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
this.placePortalBlocks();
return true;
}
@Override
public boolean bridge$createPortal() {
return createPortal();
}
}

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(NetherWartBlock.class) @Mixin(NetherWartBlock.class)
public class NetherWartBlockMixin { public class NetherWartBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
} }

View File

@ -0,0 +1,34 @@
package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.block.PortalInfoBridge;
import net.minecraft.block.PortalInfo;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftPortalEvent;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(PortalInfo.class)
public class PortalInfoMixin implements PortalInfoBridge {
public ServerWorld world;
public CraftPortalEvent portalEventInfo;
@Override
public void bridge$setPortalEventInfo(CraftPortalEvent event) {
this.portalEventInfo = event;
}
@Override
public CraftPortalEvent bridge$getPortalEventInfo() {
return this.portalEventInfo;
}
@Override
public void bridge$setWorld(ServerWorld world) {
this.world = world;
}
@Override
public ServerWorld bridge$getWorld() {
return this.world;
}
}

View File

@ -0,0 +1,107 @@
package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.block.PortalInfoBridge;
import io.izzel.arclight.common.bridge.block.PortalSizeBridge;
import io.izzel.arclight.common.bridge.world.IWorldBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Blocks;
import net.minecraft.block.NetherPortalBlock;
import net.minecraft.block.PortalInfo;
import net.minecraft.block.PortalSize;
import net.minecraft.entity.EntitySize;
import net.minecraft.util.Direction;
import net.minecraft.util.TeleportationRepositioner;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.block.CraftBlockState;
import org.bukkit.craftbukkit.v.event.CraftPortalEvent;
import org.bukkit.event.world.PortalCreateEvent;
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.CallbackInfo;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@Mixin(PortalSize.class)
public abstract class PortalSizeMixin implements PortalSizeBridge {
// @formatter:off
@Shadow @Final private IWorld world;
@Shadow public abstract void placePortalBlocks();
@Shadow @Final private Direction.Axis axis;
@Shadow @Nullable private BlockPos bottomLeft;
@Shadow private int height;
@Shadow @Final private Direction rightDir;
@Shadow private int width;
@Shadow public static PortalInfo func_242963_a(ServerWorld p_242963_0_, TeleportationRepositioner.Result p_242963_1_, Direction.Axis p_242963_2_, Vector3d p_242963_3_, EntitySize p_242963_4_, Vector3d p_242963_5_, float p_242963_6_, float p_242963_7_) { return null; }
// @formatter:on
List<BlockState> blocks = new ArrayList<>();
@Redirect(method = "func_242972_a", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/block/AbstractBlock$IPositionPredicate;test(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;)Z"))
private boolean arclight$captureBlock(AbstractBlock.IPositionPredicate predicate, net.minecraft.block.BlockState p_test_1_, IBlockReader p_test_2_, BlockPos pos) {
boolean test = predicate.test(p_test_1_, p_test_2_, pos);
if (test) {
blocks.add(CraftBlock.at(this.world, pos).getState());
}
return test;
}
@Inject(method = "placePortalBlocks", cancellable = true, at = @At("HEAD"))
private void arclight$buildPortal(CallbackInfo ci) {
World world = ((WorldBridge) ((IWorldBridge) this.world).bridge$getMinecraftWorld()).bridge$getWorld();
net.minecraft.block.BlockState blockState = Blocks.NETHER_PORTAL.getDefaultState().with(NetherPortalBlock.AXIS, this.axis);
BlockPos.getAllInBoxMutable(this.bottomLeft, this.bottomLeft.offset(Direction.UP, this.height - 1).offset(this.rightDir, this.width - 1)).forEach(pos -> {
CraftBlockState state = CraftBlockState.getBlockState(((IWorldBridge) this.world).bridge$getMinecraftWorld(), pos, 18);
state.setData(blockState);
this.blocks.add(state);
});
PortalCreateEvent event = new PortalCreateEvent(this.blocks, world, null, PortalCreateEvent.CreateReason.FIRE);
Bukkit.getPluginManager().callEvent(event);
arclight$ret = !event.isCancelled();
if (event.isCancelled()) {
ci.cancel();
}
}
private transient boolean arclight$ret;
public boolean createPortal() {
this.placePortalBlocks();
return arclight$ret;
}
@Override
public boolean bridge$createPortal() {
return createPortal();
}
@SuppressWarnings("ConstantConditions")
@Redirect(method = "func_242963_a", at = @At(value = "NEW", target = "net/minecraft/block/PortalInfo"))
private static PortalInfo arclight$setPortalInfo(Vector3d p_i242042_1_, Vector3d p_i242042_2_, float p_i242042_3_, float p_i242042_4_, ServerWorld world) {
PortalInfo portalInfo = new PortalInfo(p_i242042_1_, p_i242042_2_, p_i242042_3_, p_i242042_4_);
((PortalInfoBridge) portalInfo).bridge$setWorld(world);
((PortalInfoBridge) portalInfo).bridge$setPortalEventInfo(ArclightCaptures.getCraftPortalEvent());
return portalInfo;
}
private static PortalInfo a(ServerWorld p_242963_0_, TeleportationRepositioner.Result p_242963_1_, Direction.Axis p_242963_2_, Vector3d p_242963_3_, EntitySize p_242963_4_, Vector3d p_242963_5_, float p_242963_6_, float p_242963_7_, CraftPortalEvent event) {
ArclightCaptures.captureCraftPortalEvent(event);
return func_242963_a(p_242963_0_, p_242963_1_, p_242963_2_, p_242963_3_, p_242963_4_, p_242963_5_, p_242963_6_, p_242963_7_);
}
}

View File

@ -63,7 +63,7 @@ public abstract class RedstoneOreBlockMixin {
arclight$entity = player; arclight$entity = player;
} }
@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { private void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) {
if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, state.with(RedstoneOreBlock.LIT, false)).isCancelled()) { if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, state.with(RedstoneOreBlock.LIT, false)).isCancelled()) {
ci.cancel(); ci.cancel();

View File

@ -3,7 +3,7 @@ package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.RedstoneTorchBlock; import net.minecraft.block.RedstoneTorchBlock;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockRedstoneEvent;
@ -17,8 +17,8 @@ import java.util.Random;
@Mixin(RedstoneTorchBlock.class) @Mixin(RedstoneTorchBlock.class)
public class RedstoneTorchBlockMixin { public class RedstoneTorchBlockMixin {
@Inject(method = "update", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private static void arclight$blockRedstone1(BlockState state, World worldIn, BlockPos pos, Random random, boolean flag, CallbackInfo ci) { private static void arclight$blockRedstone1(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) {
int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0; int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0;
if (oldCurrent != 0) { if (oldCurrent != 0) {
CraftBlock block = CraftBlock.at(worldIn, pos); CraftBlock block = CraftBlock.at(worldIn, pos);
@ -30,8 +30,8 @@ public class RedstoneTorchBlockMixin {
} }
} }
@Inject(method = "update", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private static void arclight$blockRedstone2(BlockState state, World worldIn, BlockPos pos, Random random, boolean flag, CallbackInfo ci) { private static void arclight$blockRedstone2(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) {
int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0; int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0;
if (oldCurrent != 15) { if (oldCurrent != 15) {
CraftBlock block = CraftBlock.at(worldIn, pos); CraftBlock block = CraftBlock.at(worldIn, pos);

View File

@ -7,22 +7,27 @@ import net.minecraft.world.World;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.block.BlockRedstoneEvent;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(RedstoneWireBlock.class) @Mixin(RedstoneWireBlock.class)
public class RedstoneWireBlockMixin { public abstract class RedstoneWireBlockMixin {
@ModifyVariable(method = "updatePower", name = "l", index = 8, at = @At(value = "JUMP", ordinal = 0, opcode = Opcodes.IF_ICMPEQ)) // @formatter:off
public int arclight$blockRedstone(int l, World world, BlockPos pos, BlockState state) { @Shadow protected abstract int getStrongestSignal(World world, BlockPos pos);
int i = state.get(RedstoneWireBlock.POWER); // @formatter:on
if (i != l) {
BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), i, l); @Redirect(method = "func_235547_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;getStrongestSignal(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I"))
public int arclight$blockRedstone(RedstoneWireBlock redstoneWireBlock, World world, BlockPos pos, World world1, BlockPos pos1, BlockState state) {
int i = this.getStrongestSignal(world, pos);
int oldPower = state.get(RedstoneWireBlock.POWER);
if (oldPower != i) {
BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), oldPower, i);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
return event.getNewCurrent(); i = event.getNewCurrent();
} }
return l; return i;
} }
} }

View File

@ -3,7 +3,7 @@ package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.ScaffoldingBlock; import net.minecraft.block.ScaffoldingBlock;
import net.minecraft.state.IProperty; import net.minecraft.state.Property;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
@ -16,8 +16,8 @@ import java.util.Random;
@Mixin(ScaffoldingBlock.class) @Mixin(ScaffoldingBlock.class)
public class ScaffoldingBlockMixin { public class ScaffoldingBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/IProperty;)Ljava/lang/Comparable;")) @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/Property;)Ljava/lang/Comparable;"))
public Comparable<Integer> arclight$blockFade(BlockState state, IProperty<Integer> property, BlockState blockState, ServerWorld worldIn, BlockPos pos, Random random) { public Comparable<Integer> arclight$blockFade(BlockState state, Property<Integer> property, BlockState blockState, ServerWorld worldIn, BlockPos pos, Random random) {
Integer integer = state.get(property); Integer integer = state.get(property);
if (integer == 7) { if (integer == 7) {
if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) {

View File

@ -1,11 +1,9 @@
package io.izzel.arclight.common.mixin.core.block; package io.izzel.arclight.common.mixin.core.block;
import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.WorldBridge;
import net.minecraft.block.BlockState;
import net.minecraft.block.SilverfishBlock; import net.minecraft.block.SilverfishBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@ -15,8 +13,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(SilverfishBlock.class) @Mixin(SilverfishBlock.class)
public class SilverfishBlockMixin { public class SilverfishBlockMixin {
@Inject(method = "spawnAdditionalDrops", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) @Inject(method = "spawnSilverFish", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z"))
public void arclight$spawn(BlockState state, World worldIn, BlockPos pos, ItemStack stack, CallbackInfo ci) { public void arclight$spawn(ServerWorld world, BlockPos pos, CallbackInfo ci) {
((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK); ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK);
} }
} }

View File

@ -16,7 +16,7 @@ import java.util.Random;
@Mixin(SnowBlock.class) @Mixin(SnowBlock.class)
public class SnowBlockMixin { public class SnowBlockMixin {
@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/SnowBlock;spawnDrops(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/SnowBlock;spawnDrops(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V"))
public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) {
if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) {
ci.cancel(); ci.cancel();

View File

@ -8,8 +8,8 @@ import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.IBucketPickupHandler; import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.block.SpongeBlock; import net.minecraft.block.SpongeBlock;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.tags.FluidTags; import net.minecraft.tags.FluidTags;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
@ -50,7 +50,7 @@ public class SpongeBlockMixin {
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
BlockPos blockpos1 = blockpos.offset(direction); BlockPos blockpos1 = blockpos.offset(direction);
BlockState blockstate = blockList.getBlockState(blockpos1); BlockState blockstate = blockList.getBlockState(blockpos1);
IFluidState ifluidstate = blockList.getFluidState(blockpos1); FluidState ifluidstate = blockList.getFluidState(blockpos1);
Material material = blockstate.getMaterial(); Material material = blockstate.getMaterial();
if (ifluidstate.isTagged(FluidTags.WATER)) { if (ifluidstate.isTagged(FluidTags.WATER)) {
if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) { if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
@ -95,7 +95,7 @@ public class SpongeBlockMixin {
for (CraftBlockState block : blocks) { for (CraftBlockState block : blocks) {
BlockPos blockposition2 = block.getPosition(); BlockPos blockposition2 = block.getPosition();
BlockState iblockdata = worldIn.getBlockState(blockposition2); BlockState iblockdata = worldIn.getBlockState(blockposition2);
IFluidState fluid = worldIn.getFluidState(blockposition2); FluidState fluid = worldIn.getFluidState(blockposition2);
Material material = iblockdata.getMaterial(); Material material = iblockdata.getMaterial();
if (fluid.isTagged(FluidTags.WATER)) { if (fluid.isTagged(FluidTags.WATER)) {

View File

@ -17,14 +17,14 @@ import java.util.Random;
@Mixin(SpreadableSnowyDirtBlock.class) @Mixin(SpreadableSnowyDirtBlock.class)
public class SpreadableSnowyDirtBlockMixin { public class SpreadableSnowyDirtBlockMixin {
@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) {
if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.getDefaultState()).isCancelled()) { if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.getDefaultState()).isCancelled()) {
ci.cancel(); ci.cancel();
} }
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
public boolean arclight$blockSpread(ServerWorld world, BlockPos to, BlockState state, BlockState state1, ServerWorld worldIn, BlockPos from) { public boolean arclight$blockSpread(ServerWorld world, BlockPos to, BlockState state, BlockState state1, ServerWorld worldIn, BlockPos from) {
return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state); return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state);
} }

View File

@ -18,12 +18,12 @@ public class StemBlockMixin {
private transient boolean arclight$success = false; private transient boolean arclight$success = false;
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$cropGrow1(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$cropGrow1(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
} }
@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
public void arclight$returnIfFail(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { public void arclight$returnIfFail(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) {
if (!arclight$success) { if (!arclight$success) {
ci.cancel(); ci.cancel();
@ -31,7 +31,7 @@ public class StemBlockMixin {
arclight$success = false; arclight$success = false;
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
public boolean arclight$cropGrow2(ServerWorld world, BlockPos pos, BlockState state) { public boolean arclight$cropGrow2(ServerWorld world, BlockPos pos, BlockState state) {
return arclight$success = CraftEventFactory.handleBlockGrowEvent(world, pos, state); return arclight$success = CraftEventFactory.handleBlockGrowEvent(world, pos, state);
} }

View File

@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(SugarCaneBlock.class) @Mixin(SugarCaneBlock.class)
public class SugarCaneBlockMixin { public class SugarCaneBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState state) { public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState state) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, state); return CraftEventFactory.handleBlockGrowEvent(world, pos, state);
} }

View File

@ -1,23 +1,34 @@
package io.izzel.arclight.common.mixin.core.block; package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SweetBerryBushBlock; import net.minecraft.block.SweetBerryBushBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.player.PlayerHarvestBlockEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Collections;
@Mixin(SweetBerryBushBlock.class) @Mixin(SweetBerryBushBlock.class)
public class SweetBerryBushBlockMixin { public class SweetBerryBushBlockMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags);
} }
@ -31,4 +42,24 @@ public class SweetBerryBushBlockMixin {
public void arclight$damagePost(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { public void arclight$damagePost(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) {
CraftEventFactory.blockDamage = null; CraftEventFactory.blockDamage = null;
} }
@Redirect(method = "onBlockActivated", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/SweetBerryBushBlock;spawnAsEntity(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/ItemStack;)V"))
private void arclight$playerHarvest(World worldIn, BlockPos pos, ItemStack stack, BlockState state, World worldIn1, BlockPos pos1, PlayerEntity player) {
PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(worldIn, pos, player, Collections.singletonList(stack));
arclight$ret = event.isCancelled();
if (!event.isCancelled()) {
for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) {
Block.spawnAsEntity(worldIn, pos, CraftItemStack.asNMSCopy(itemStack));
}
}
}
private transient boolean arclight$ret;
@Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V"))
private void arclight$returnIfFail(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable<ActionResultType> cir) {
if (arclight$ret) {
cir.setReturnValue(ActionResultType.SUCCESS);
}
}
} }

View File

@ -3,7 +3,7 @@ package io.izzel.arclight.common.mixin.core.block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.TNTBlock; import net.minecraft.block.TNTBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public class TNTBlockMixin { public class TNTBlockMixin {
@Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/block/TNTBlock;catchFire(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Direction;Lnet/minecraft/entity/LivingEntity;)V")) @Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/block/TNTBlock;catchFire(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Direction;Lnet/minecraft/entity/LivingEntity;)V"))
public void arclight$entityChangeBlock(World worldIn, BlockState state, BlockRayTraceResult hit, Entity projectile, CallbackInfo ci) { public void arclight$entityChangeBlock(World worldIn, BlockState state, BlockRayTraceResult hit, ProjectileEntity projectile, CallbackInfo ci) {
if (CraftEventFactory.callEntityChangeBlockEvent(projectile, hit.getPos(), Blocks.AIR.getDefaultState()).isCancelled()) { if (CraftEventFactory.callEntityChangeBlockEvent(projectile, hit.getPos(), Blocks.AIR.getDefaultState()).isCancelled()) {
ci.cancel(); ci.cancel();
} }

View File

@ -86,7 +86,7 @@ public abstract class TripWireBlockMixin extends BlockMixin {
} }
if (flag1) { if (flag1) {
worldIn.getPendingBlockTicks().scheduleTick(new BlockPos(pos), (Block) (Object) this, this.tickRate(worldIn)); worldIn.getPendingBlockTicks().scheduleTick(new BlockPos(pos), (Block) (Object) this, 10);
} }
} }

View File

@ -34,7 +34,7 @@ public class TurtleEggBlockMixin {
@Shadow @Final public static IntegerProperty HATCH; @Shadow @Final public static IntegerProperty HATCH;
@Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, @Inject(method = "randomTick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V"))
private void arclight$hatch(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci, int i) { private void arclight$hatch(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci, int i) {
if (!CraftEventFactory.handleBlockGrowEvent(worldIn, pos, state.with(HATCH, i + 1), 2)) { if (!CraftEventFactory.handleBlockGrowEvent(worldIn, pos, state.with(HATCH, i + 1), 2)) {
@ -42,12 +42,12 @@ public class TurtleEggBlockMixin {
} }
} }
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean arclight$handledHatch(ServerWorld world, BlockPos pos, BlockState newState, int flags) { private boolean arclight$handledHatch(ServerWorld world, BlockPos pos, BlockState newState, int flags) {
return true; return true;
} }
@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V"))
private void arclight$born(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { private void arclight$born(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) {
if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) {
ci.cancel(); ci.cancel();

View File

@ -20,8 +20,6 @@ import java.util.Random;
public abstract class VineBlockMixin extends BlockMixin { public abstract class VineBlockMixin extends BlockMixin {
// @formatter:off // @formatter:off
@Shadow protected abstract BlockState func_196545_h(BlockState p_196545_1_, IBlockReader p_196545_2_, BlockPos p_196545_3_);
@Shadow protected abstract boolean func_196543_i(BlockState p_196543_1_);
@Shadow public static BooleanProperty getPropertyFor(Direction side) { return null; } @Shadow public static BooleanProperty getPropertyFor(Direction side) { return null; }
@Shadow protected abstract boolean func_196539_a(IBlockReader p_196539_1_, BlockPos p_196539_2_); @Shadow protected abstract boolean func_196539_a(IBlockReader p_196539_1_, BlockPos p_196539_2_);
@Shadow public static boolean canAttachTo(IBlockReader p_196542_0_, BlockPos worldIn, Direction neighborPos) { return false; } @Shadow public static boolean canAttachTo(IBlockReader p_196542_0_, BlockPos worldIn, Direction neighborPos) { return false; }
@ -37,24 +35,15 @@ public abstract class VineBlockMixin extends BlockMixin {
*/ */
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@Overwrite @Overwrite
public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) {
BlockState blockstate = this.func_196545_h(state, worldIn, pos); if (worldIn.rand.nextInt(4) == 0 && worldIn.isAreaLoaded(pos, 4)) { // Forge: check area to prevent loading unloaded chunks
if (blockstate != state) { Direction direction = Direction.getRandomDirection(random);
if (this.func_196543_i(blockstate)) {
worldIn.setBlockState(pos, blockstate, 2);
} else {
Block.spawnDrops(state, worldIn, pos);
worldIn.removeBlock(pos, false);
}
} else if (worldIn.rand.nextInt(4) == 0 && worldIn.isAreaLoaded(pos, 4)) { // Forge: check area to prevent loading unloaded chunks
Direction direction = Direction.random(random);
BlockPos blockpos = pos.up(); BlockPos blockpos = pos.up();
if (direction.getAxis().isHorizontal() && !state.get(getPropertyFor(direction))) { if (direction.getAxis().isHorizontal() && !state.get(getPropertyFor(direction))) {
if (this.func_196539_a(worldIn, pos)) { if (this.func_196539_a(worldIn, pos)) {
BlockPos blockpos4 = pos.offset(direction); BlockPos blockpos4 = pos.offset(direction);
BlockState blockstate5 = worldIn.getBlockState(blockpos4); BlockState blockstate4 = worldIn.getBlockState(blockpos4);
if (blockstate5.isAir()) { if (blockstate4.isAir(worldIn, blockpos4)) {
Direction direction3 = direction.rotateY(); Direction direction3 = direction.rotateY();
Direction direction4 = direction.rotateYCCW(); Direction direction4 = direction.rotateYCCW();
boolean flag = state.get(getPropertyFor(direction3)); boolean flag = state.get(getPropertyFor(direction3));
@ -62,28 +51,28 @@ public abstract class VineBlockMixin extends BlockMixin {
BlockPos blockpos2 = blockpos4.offset(direction3); BlockPos blockpos2 = blockpos4.offset(direction3);
BlockPos blockpos3 = blockpos4.offset(direction4); BlockPos blockpos3 = blockpos4.offset(direction4);
if (flag && canAttachTo(worldIn, blockpos2, direction3)) { if (flag && canAttachTo(worldIn, blockpos2, direction3)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction3), true), 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction3), Boolean.TRUE), 2);
} else if (flag1 && canAttachTo(worldIn, blockpos3, direction4)) { } else if (flag1 && canAttachTo(worldIn, blockpos3, direction4)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction4), true), 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction4), Boolean.TRUE), 2);
} else { } else {
Direction direction1 = direction.getOpposite(); Direction direction1 = direction.getOpposite();
if (flag && worldIn.isAirBlock(blockpos2) && canAttachTo(worldIn, pos.offset(direction3), direction1)) { if (flag && worldIn.isAirBlock(blockpos2) && canAttachTo(worldIn, pos.offset(direction3), direction1)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos2, this.getDefaultState().with(getPropertyFor(direction1), true), 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos2, this.getDefaultState().with(getPropertyFor(direction1), Boolean.TRUE), 2);
} else if (flag1 && worldIn.isAirBlock(blockpos3) && canAttachTo(worldIn, pos.offset(direction4), direction1)) { } else if (flag1 && worldIn.isAirBlock(blockpos3) && canAttachTo(worldIn, pos.offset(direction4), direction1)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos3, this.getDefaultState().with(getPropertyFor(direction1), true), 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos3, this.getDefaultState().with(getPropertyFor(direction1), Boolean.TRUE), 2);
} else if ((double) worldIn.rand.nextFloat() < 0.05D && canAttachTo(worldIn, blockpos4.up(), Direction.UP)) { } else if ((double) worldIn.rand.nextFloat() < 0.05D && canAttachTo(worldIn, blockpos4.up(), Direction.UP)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(UP, true), 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(UP, Boolean.TRUE), 2);
} }
} }
} else if (canAttachTo(worldIn, blockpos4, direction)) { } else if (canAttachTo(worldIn, blockpos4, direction)) {
worldIn.setBlockState(pos, state.with(getPropertyFor(direction), true), 2); worldIn.setBlockState(pos, state.with(getPropertyFor(direction), Boolean.TRUE), 2);
} }
} }
} else { } else {
if (direction == Direction.UP && pos.getY() < 255) { if (direction == Direction.UP && pos.getY() < 255) {
if (this.func_196541_a(worldIn, pos, direction)) { if (this.func_196541_a(worldIn, pos, direction)) {
worldIn.setBlockState(pos, state.with(UP, true), 2); worldIn.setBlockState(pos, state.with(UP, Boolean.TRUE), 2);
return; return;
} }
@ -92,16 +81,16 @@ public abstract class VineBlockMixin extends BlockMixin {
return; return;
} }
BlockState blockstate4 = state; BlockState blockstate3 = state;
for (Direction direction2 : Direction.Plane.HORIZONTAL) { for (Direction direction2 : Direction.Plane.HORIZONTAL) {
if (random.nextBoolean() || !canAttachTo(worldIn, blockpos.offset(direction2), Direction.UP)) { if (random.nextBoolean() || !canAttachTo(worldIn, blockpos.offset(direction2), Direction.UP)) {
blockstate4 = blockstate4.with(getPropertyFor(direction2), false); blockstate3 = blockstate3.with(getPropertyFor(direction2), Boolean.FALSE);
} }
} }
if (this.func_196540_x(blockstate4)) { if (this.func_196540_x(blockstate3)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, blockstate4, 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, blockstate3, 2);
} }
return; return;
@ -110,12 +99,12 @@ public abstract class VineBlockMixin extends BlockMixin {
if (pos.getY() > 0) { if (pos.getY() > 0) {
BlockPos blockpos1 = pos.down(); BlockPos blockpos1 = pos.down();
BlockState blockstate1 = worldIn.getBlockState(blockpos1); BlockState blockstate = worldIn.getBlockState(blockpos1);
if (blockstate1.isAir() || blockstate1.getBlock() == (Object) this) { if (blockstate.isAir(worldIn, blockpos) || blockstate.isIn((Block) (Object) this)) {
BlockState blockstate2 = blockstate1.isAir() ? this.getDefaultState() : blockstate1; BlockState blockstate1 = blockstate.isAir() ? this.getDefaultState() : blockstate;
BlockState blockstate3 = this.func_196544_a(state, blockstate2, random); BlockState blockstate2 = this.func_196544_a(state, blockstate1, random);
if (blockstate2 != blockstate3 && this.func_196540_x(blockstate3)) { if (blockstate1 != blockstate2 && this.func_196540_x(blockstate2)) {
CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, blockstate3, 2); CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, blockstate2, 2);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package io.izzel.arclight.common.mixin.core.command.arguments;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import net.minecraft.command.arguments.BlockStateParser; import net.minecraft.command.arguments.BlockStateParser;
import net.minecraft.state.IProperty; import net.minecraft.state.Property;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Mutable;
@ -18,7 +18,7 @@ import java.util.Map;
public class BlockStateParserMixin { public class BlockStateParserMixin {
// @formatter:off // @formatter:off
@Shadow @Final @Mutable private Map<IProperty<?>, Comparable<?>> properties; @Shadow @Final @Mutable private Map<Property<?>, Comparable<?>> properties;
// @formatter:on // @formatter:on
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))

View File

@ -11,7 +11,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -26,15 +26,15 @@ import javax.annotation.Nullable;
public abstract class EntityTypeMixin<T extends Entity> implements EntityTypeBridge<T> { public abstract class EntityTypeMixin<T extends Entity> implements EntityTypeBridge<T> {
// @formatter:off // @formatter:off
@Shadow @Nullable public abstract T create(World worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220349_7_, boolean p_220349_8_); @Shadow @Nullable public abstract T create(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220349_7_, boolean p_220349_8_);
// @formatter:on // @formatter:on
@Inject(method = "spawn(Lnet/minecraft/world/World;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", at = @At("HEAD")) @Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", at = @At("HEAD"))
public void arclight$spawnReason(World worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable<T> cir) { public void arclight$spawnReason(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable<T> cir) {
((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); ((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
} }
public T spawnCreature(World worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) { public T spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) {
T t = this.create(worldIn, compound, customName, playerIn, pos, reason, flag, flag1); T t = this.create(worldIn, compound, customName, playerIn, pos, reason, flag, flag1);
if (t instanceof MobEntity && ForgeEventFactory.doSpecialSpawn((MobEntity) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason)) { if (t instanceof MobEntity && ForgeEventFactory.doSpecialSpawn((MobEntity) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason)) {
return null; return null;
@ -43,7 +43,7 @@ public abstract class EntityTypeMixin<T extends Entity> implements EntityTypeBri
} }
@Override @Override
public T bridge$spawnCreature(World worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) { public T bridge$spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) {
return spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, spawnReason); return spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, spawnReason);
} }
} }

View File

@ -1,18 +1,35 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain; package io.izzel.arclight.common.mixin.core.entity.ai.brain;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.BrainUtil; import net.minecraft.entity.ai.brain.BrainUtil;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3d;
import org.bukkit.Bukkit;
import org.bukkit.entity.Item;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(BrainUtil.class) @Mixin(BrainUtil.class)
public class BrainUtilMixin { public class BrainUtilMixin {
@Inject(method = "throwItemAt", cancellable = true, at = @At("HEAD")) @Inject(method = "func_233865_a_", cancellable = true, at = @At("HEAD"))
private static void arclight$noEmptyLoot(LivingEntity from, ItemStack stack, LivingEntity to, CallbackInfo ci) { private static void arclight$noEmptyLoot(LivingEntity entity, ItemStack stack, Vector3d p_233865_2_, CallbackInfo ci) {
if (stack.isEmpty()) ci.cancel(); if (stack.isEmpty()) ci.cancel();
} }
@Inject(method = "func_233865_a_", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD,
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
private static void arclight$entityDropItem(LivingEntity entity, ItemStack stack, Vector3d p_233865_2_, CallbackInfo ci, double d, ItemEntity itemEntity) {
EntityDropItemEvent event = new EntityDropItemEvent(((EntityBridge) entity).bridge$getBukkitEntity(), (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
ci.cancel();
}
}
} }

View File

@ -15,33 +15,30 @@ import org.bukkit.event.entity.VillagerCareerChangeEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import java.util.Optional;
@Mixin(AssignProfessionTask.class) @Mixin(AssignProfessionTask.class)
public class AssignProfessionTaskMixin { public class AssignProfessionTaskMixin {
/*
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "*(Lnet/minecraft/entity/merchant/villager/VillagerEntity;Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/merchant/villager/VillagerProfession;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;setVillagerData(Lnet/minecraft/entity/merchant/villager/VillagerData;)V"))
private void arclight$careerChangeHook(VillagerEntity villagerEntity, VillagerData villagerData) {
VillagerProfession profession = villagerData.getProfession();
VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(villagerEntity, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
if (!event.isCancelled()) {
VillagerData newData = villagerEntity.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession()));
villagerEntity.setVillagerData(newData);
}
}*/
/** /**
* @author IzzelAliz * @author IzzelAliz
* @reason * @reason
*/ */
@Overwrite @Overwrite
protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) { protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) {
GlobalPos globalpos = entityIn.getBrain().getMemory(MemoryModuleType.JOB_SITE).get(); GlobalPos globalpos = entityIn.getBrain().getMemory(MemoryModuleType.POTENTIAL_JOB_SITE).get();
MinecraftServer minecraftserver = worldIn.getServer(); entityIn.getBrain().removeMemory(MemoryModuleType.POTENTIAL_JOB_SITE);
minecraftserver.getWorld(globalpos.getDimension()).getPointOfInterestManager().getType(globalpos.getPos()).ifPresent((p_220390_2_) -> { entityIn.getBrain().setMemory(MemoryModuleType.JOB_SITE, globalpos);
Registry.VILLAGER_PROFESSION.stream().filter((p_220389_1_) -> { worldIn.setEntityState(entityIn, (byte) 14);
return p_220389_1_.getPointOfInterest() == p_220390_2_; if (entityIn.getVillagerData().getProfession() == VillagerProfession.NONE) {
}).findFirst().ifPresent((p_220388_2_) -> { MinecraftServer minecraftserver = worldIn.getServer();
Optional.ofNullable(minecraftserver.getWorld(globalpos.getDimension())).flatMap((p_241376_1_) -> {
return p_241376_1_.getPointOfInterestManager().getType(globalpos.getPos());
}).flatMap((p_220390_0_) -> {
return Registry.VILLAGER_PROFESSION.stream().filter((p_220389_1_) -> {
return p_220389_1_.getPointOfInterest() == p_220390_0_;
}).findFirst();
}).ifPresent((p_220388_2_) -> {
VillagerData villagerData = entityIn.getVillagerData().withProfession(p_220388_2_); VillagerData villagerData = entityIn.getVillagerData().withProfession(p_220388_2_);
VillagerProfession profession = villagerData.getProfession(); VillagerProfession profession = villagerData.getProfession();
VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityIn, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED); VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityIn, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED);
@ -51,6 +48,6 @@ public class AssignProfessionTaskMixin {
entityIn.resetBrain(worldIn); entityIn.resetBrain(worldIn);
} }
}); });
}); }
} }
} }

View File

@ -1,29 +1,27 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; package io.izzel.arclight.common.mixin.core.entity.ai.brain.task;
import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.WorldBridge;
import net.minecraft.entity.AgeableEntity;
import net.minecraft.entity.ai.brain.task.CreateBabyVillagerTask; import net.minecraft.entity.ai.brain.task.CreateBabyVillagerTask;
import net.minecraft.entity.merchant.villager.VillagerEntity; import net.minecraft.entity.merchant.villager.VillagerEntity;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; 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;
import java.util.Optional;
@Mixin(CreateBabyVillagerTask.class) @Mixin(CreateBabyVillagerTask.class)
public class CreateBabyVillagerTaskMixin { public class CreateBabyVillagerTaskMixin {
@Inject(method = "func_220480_a", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, @Redirect(method = "func_242307_b", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;func_241840_a(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/AgeableEntity;)Lnet/minecraft/entity/merchant/villager/VillagerEntity;"))
at = @At(value = "JUMP", ordinal = 0, opcode = Opcodes.IFNONNULL)) private VillagerEntity arclight$entityBreed(VillagerEntity lona, ServerWorld world, AgeableEntity anonymous) {
private void arclight$entityBreed(VillagerEntity lona, VillagerEntity anonymous, CallbackInfoReturnable<Optional<VillagerEntity>> cir, VillagerEntity child) { VillagerEntity child = lona.func_241840_a(world, anonymous);
if (CraftEventFactory.callEntityBreedEvent(child, lona, anonymous, null, null, 0).isCancelled()) { if (child != null && !CraftEventFactory.callEntityBreedEvent(child, lona, anonymous, null, null, 0).isCancelled()) {
cir.setReturnValue(Optional.empty()); ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING);
} else if (child != null) { return child;
((WorldBridge) lona.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); } else {
return null;
} }
} }
} }

View File

@ -0,0 +1,26 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain.task;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.block.BlockState;
import net.minecraft.entity.ai.brain.task.FarmerWorkTask;
import net.minecraft.entity.merchant.villager.VillagerEntity;
import net.minecraft.util.math.GlobalPos;
import net.minecraft.world.server.ServerWorld;
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.CallbackInfo;
@Mixin(FarmerWorkTask.class)
public class FarmerWorkTaskMixin {
@Inject(method = "func_234016_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ComposterBlock;empty(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"))
private static void arclight$captureVillager1(ServerWorld p_234016_1_, VillagerEntity p_234016_2_, GlobalPos p_234016_3_, BlockState p_234016_4_, CallbackInfo ci) {
ArclightCaptures.captureEntityChangeBlock(p_234016_2_);
}
@Inject(method = "func_234016_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ComposterBlock;attemptFill(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"))
private static void arclight$captureVillager2(ServerWorld p_234016_1_, VillagerEntity p_234016_2_, GlobalPos p_234016_3_, BlockState p_234016_4_, CallbackInfo ci) {
ArclightCaptures.captureEntityChangeBlock(p_234016_2_);
}
}

View File

@ -0,0 +1,31 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain.task;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
import net.minecraft.entity.ai.brain.task.FindNewAttackTargetTask;
import org.bukkit.craftbukkit.v.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityTargetEvent;
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.CallbackInfo;
@Mixin(FindNewAttackTargetTask.class)
public class FindNewAttackTargetTaskMixin<E extends MobEntity> {
@Inject(method = "func_233987_d_", cancellable = true, at = @At("HEAD"))
private void arclight$attackEvent(E mob, CallbackInfo ci) {
LivingEntity old = mob.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(mob, old, (old != null && !old.isAlive()) ? EntityTargetEvent.TargetReason.TARGET_DIED : EntityTargetEvent.TargetReason.FORGOT_TARGET);
if (event.isCancelled()) {
ci.cancel();
return;
}
if (event.getTarget() != null) {
mob.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, ((CraftLivingEntity)event.getTarget()).getHandle());
ci.cancel();
}
}
}

View File

@ -0,0 +1,31 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain.task;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
import net.minecraft.entity.ai.brain.task.ForgetAttackTargetTask;
import net.minecraft.entity.player.ServerPlayerEntity;
import org.bukkit.craftbukkit.v.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityTargetEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(ForgetAttackTargetTask.class)
public class ForgetAttackTargetTaskMixin<E extends MobEntity> {
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private void func_233976_a_(E mob, LivingEntity livingEntity) {
EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(mob, livingEntity, (livingEntity instanceof ServerPlayerEntity) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY);
if (event.isCancelled()) {
return;
}
livingEntity = ((event.getTarget() != null) ? ((CraftLivingEntity) event.getTarget()).getHandle() : null);
mob.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, livingEntity);
mob.getBrain().removeMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE);
}
}

View File

@ -1,68 +1,76 @@
package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; package io.izzel.arclight.common.mixin.core.entity.ai.brain.task;
import com.google.common.collect.Sets; import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock; import net.minecraft.block.DoorBlock;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.Brain;
import net.minecraft.entity.ai.brain.memory.MemoryModuleType; import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
import net.minecraft.entity.ai.brain.task.InteractWithDoorTask; import net.minecraft.entity.ai.brain.task.InteractWithDoorTask;
import net.minecraft.pathfinding.Path;
import net.minecraft.pathfinding.PathPoint;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.GlobalPos;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlock;
import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityInteractEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List; import javax.annotation.Nullable;
import java.util.Set;
@Mixin(InteractWithDoorTask.class) @Mixin(InteractWithDoorTask.class)
public class InteractWithDoorTaskMixin { public abstract class InteractWithDoorTaskMixin {
// @formatter:off
@Shadow @Nullable private PathPoint field_242292_b;
@Shadow protected abstract void func_242301_c(ServerWorld p_242301_1_, LivingEntity p_242301_2_, BlockPos p_242301_3_);
@Shadow public static void func_242294_a(ServerWorld p_242294_0_, LivingEntity p_242294_1_, @org.jetbrains.annotations.Nullable PathPoint p_242294_2_, @org.jetbrains.annotations.Nullable PathPoint p_242294_3_) { }
// @formatter:on
/** /**
* @author IzzelAliz * @author IzzelAliz
* @reason * @reason
*/ */
@Overwrite @Overwrite
private void func_220434_a(ServerWorld serverWorld, List<BlockPos> blockPosList, Set<BlockPos> blockPosSet, int i, LivingEntity livingEntity, Brain<?> brain) { protected void startExecuting(ServerWorld worldIn, LivingEntity entityIn, long gameTimeIn) {
blockPosSet.forEach((blockPos) -> { Path path = entityIn.getBrain().getMemory(MemoryModuleType.PATH).get();
int j = blockPosList.indexOf(blockPos); this.field_242292_b = path.func_237225_h_();
BlockState blockstate = serverWorld.getBlockState(blockPos); PathPoint pathpoint = path.func_242950_i();
Block block = blockstate.getBlock(); PathPoint pathpoint1 = path.func_237225_h_();
if (BlockTags.WOODEN_DOORS.contains(block) && block instanceof DoorBlock) { BlockPos blockpos = pathpoint.func_224759_a();
boolean flag = j >= i; BlockState blockstate = worldIn.getBlockState(blockpos);
if (blockstate.isIn(BlockTags.WOODEN_DOORS)) {
// CraftBukkit start - entities opening doors DoorBlock doorblock = (DoorBlock) blockstate.getBlock();
EntityInteractEvent event = new EntityInteractEvent(((LivingEntityBridge) livingEntity).bridge$getBukkitEntity(), CraftBlock.at(livingEntity.world, blockPos)); if (!doorblock.func_242664_h(blockstate)) {
EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.world, blockpos));
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
// CaftBukkit end doorblock.func_242663_a(worldIn, blockstate, blockpos, true);
((DoorBlock) block).toggleDoor(serverWorld, blockPos, flag);
GlobalPos globalpos = GlobalPos.of(serverWorld.getDimension().getType(), blockPos);
if (!brain.getMemory(MemoryModuleType.field_225462_q).isPresent() && flag) {
brain.setMemory(MemoryModuleType.field_225462_q, Sets.newHashSet(globalpos));
} else {
brain.getMemory(MemoryModuleType.field_225462_q).ifPresent((globalPosSet) -> {
if (flag) {
globalPosSet.add(globalpos);
} else {
globalPosSet.remove(globalpos);
}
});
}
} }
}); this.func_242301_c(worldIn, entityIn, blockpos);
InteractWithDoorTask.func_225449_a(serverWorld, blockPosList, i, livingEntity, brain); }
BlockPos blockpos1 = pathpoint1.func_224759_a();
BlockState blockstate1 = worldIn.getBlockState(blockpos1);
if (blockstate1.isIn(BlockTags.WOODEN_DOORS)) {
DoorBlock doorblock1 = (DoorBlock) blockstate1.getBlock();
if (!doorblock1.func_242664_h(blockstate1)) {
// todo check this blockpos1
EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.world, blockpos1));
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
doorblock1.func_242663_a(worldIn, blockstate1, blockpos1, true);
this.func_242301_c(worldIn, entityIn, blockpos1);
}
}
func_242294_a(worldIn, entityIn, pathpoint, pathpoint1);
} }
} }

View File

@ -414,6 +414,7 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
if (!isSleeping()) ci.cancel(); if (!isSleeping()) ci.cancel();
} }
// todo
@Override @Override
public Entity bridge$changeDimension(DimensionType dimensionType, PlayerTeleportEvent.TeleportCause cause) { public Entity bridge$changeDimension(DimensionType dimensionType, PlayerTeleportEvent.TeleportCause cause) {
return a(dimensionType, cause); return a(dimensionType, cause);

View File

@ -0,0 +1,20 @@
package io.izzel.arclight.common.mixin.core.world;
import io.izzel.arclight.common.bridge.world.IWorldBridge;
import net.minecraft.world.IServerWorld;
import net.minecraft.world.server.ServerWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(IServerWorld.class)
public interface IServerWorldMixin extends IWorldBridge {
// @formatter:off
@Shadow ServerWorld getWorld();
// @formatter:on
@Override
default ServerWorld bridge$getMinecraftWorld() {
return this.getWorld();
}
}

View File

@ -0,0 +1,11 @@
package io.izzel.arclight.common.mixin.core.world;
import io.izzel.arclight.common.bridge.world.IWorldBridge;
import net.minecraft.world.server.ServerWorld;
public interface IWorldMixin extends IWorldBridge {
default ServerWorld getMinecraftWorld() {
return this.bridge$getMinecraftWorld();
}
}

View File

@ -393,4 +393,9 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld
} }
arclight$timeSkipCancelled = false; arclight$timeSkipCancelled = false;
} }
@Override
public ServerWorld bridge$getMinecraftWorld() {
return (ServerWorld) (Object) this;
}
} }

View File

@ -10,6 +10,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.bukkit.TreeType; import org.bukkit.TreeType;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v.event.CraftPortalEvent;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,11 +21,7 @@ public class ArclightCaptures {
private static Entity entityChangeBlock; private static Entity entityChangeBlock;
public static void captureEntityChangeBlock(Entity entity) { public static void captureEntityChangeBlock(Entity entity) {
if (entityChangeBlock == null) { entityChangeBlock = entity;
entityChangeBlock = entity;
} else {
recapture("entity change block");
}
} }
public static Entity getEntityChangeBlock() { public static Entity getEntityChangeBlock() {
@ -187,6 +184,20 @@ public class ArclightCaptures {
containerOwner = null; containerOwner = null;
} }
private static transient CraftPortalEvent craftPortalEvent;
public static void captureCraftPortalEvent(CraftPortalEvent event) {
craftPortalEvent = event;
}
public static CraftPortalEvent getCraftPortalEvent() {
try {
return craftPortalEvent;
} finally {
craftPortalEvent = null;
}
}
private static void recapture(String type) { private static void recapture(String type) {
throw new IllegalStateException("Recapturing " + type); throw new IllegalStateException("Recapturing " + type);
} }

View File

@ -39,6 +39,8 @@ public net.minecraft.entity.passive.BeeEntity.PollinateGoal func_226504_l_()V #c
public net.minecraft.tileentity.BeehiveTileEntity$Bee public net.minecraft.tileentity.BeehiveTileEntity$Bee
public net.minecraft.tileentity.BeehiveTileEntity$Bee field_226977_a_ #entityData public net.minecraft.tileentity.BeehiveTileEntity$Bee field_226977_a_ #entityData
public net.minecraft.entity.passive.BeeEntity$PollinateGoal func_226504_l_()V #cancel public net.minecraft.entity.passive.BeeEntity$PollinateGoal func_226504_l_()V #cancel
# Arclight 1.16
public net.minecraft.block.ComposterBlock func_235490_d_(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState; #resetFillState
# Bukkit # Bukkit
public net.minecraft.entity.player.PlayerEntity func_190531_bD()I public net.minecraft.entity.player.PlayerEntity func_190531_bD()I
public net.minecraft.entity.item.ItemFrameEntity func_174859_a(Lnet/minecraft/util/Direction;)V public net.minecraft.entity.item.ItemFrameEntity func_174859_a(Lnet/minecraft/util/Direction;)V
@ -352,3 +354,60 @@ public net.minecraft.item.crafting.Ingredient$SingleItemList <init>(Lnet/minecra
public net.minecraft.tileentity.BeehiveTileEntity field_226959_b_ public net.minecraft.tileentity.BeehiveTileEntity field_226959_b_
public net.minecraft.tileentity.StructureBlockTileEntity field_184427_l public net.minecraft.tileentity.StructureBlockTileEntity field_184427_l
public net.minecraft.world.World field_217407_c public net.minecraft.world.World field_217407_c
public net.minecraft.block.DispenserBlock func_176439_d(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;)V
public net.minecraft.block.DropperBlock func_176439_d(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;)V
public net.minecraft.block.AbstractBlock$AbstractBlockState field_235705_i_
public net.minecraft.util.text.Color field_240741_d_
public net.minecraft.world.storage.SaveFormat$LevelSave field_237279_c_
public net.minecraft.world.storage.SaveFormat field_215786_c
public net.minecraft.util.datafix.fixes.BlockStateFlatteningMap func_199194_a(ILjava/lang/String;[Ljava/lang/String;)V
public net.minecraft.world.end.DragonFightManager field_186119_m
public net.minecraft.world.end.DragonFightManager field_186121_o
public net.minecraft.world.end.DragonFightManager func_186094_a(Z)V
public net.minecraft.world.end.DragonFightManager func_186091_h()Lnet/minecraft/block/pattern/BlockPattern$PatternHelper;
public net.minecraft.world.end.DragonFightManager field_186122_p
public net.minecraft.world.end.DragonFightManager func_186095_a(Lnet/minecraft/world/end/DragonSpawnState;)V
public net.minecraft.world.end.DragonFightManager field_186110_d
public net.minecraft.entity.Entity field_242273_aw
public net.minecraft.entity.passive.BeeEntity field_226364_bD_
public net.minecraft.entity.projectile.EyeOfEnderEntity field_70223_e
public net.minecraft.entity.projectile.EyeOfEnderEntity field_70221_f
public net.minecraft.entity.projectile.EyeOfEnderEntity field_70224_b
public net.minecraft.entity.projectile.EyeOfEnderEntity field_70225_c
public net.minecraft.entity.projectile.EyeOfEnderEntity field_70222_d
public net.minecraft.entity.projectile.AbstractFireballEntity func_213896_l()Lnet/minecraft/item/ItemStack;
public net.minecraft.entity.projectile.FireworkRocketEntity field_184566_a
public net.minecraft.entity.projectile.FireworkRocketEntity field_213895_d
public net.minecraft.entity.projectile.FireworkRocketEntity field_92055_b
public net.minecraft.entity.monster.HoglinEntity field_234359_bz_
public net.minecraft.entity.monster.HoglinEntity field_234358_by_
public net.minecraft.entity.monster.HoglinEntity func_234368_eV_()Z
public net.minecraft.entity.passive.horse.HorseEntity func_234238_a_(Lnet/minecraft/entity/passive/horse/CoatColors;Lnet/minecraft/entity/passive/horse/CoatTypes;)V
public net.minecraft.entity.item.ItemFrameEntity field_234259_an_
public net.minecraft.entity.effect.LightningBoltEntity field_184529_d
public net.minecraft.entity.item.minecart.CommandBlockMinecartEntity field_184273_a
public net.minecraft.entity.passive.PigEntity field_234214_bx_
public net.minecraft.entity.monster.piglin.PiglinEntity field_234407_bB_
public net.minecraft.entity.monster.piglin.AbstractPiglinEntity field_242334_c
public net.minecraft.entity.monster.piglin.AbstractPiglinEntity func_242335_eK()Z
public net.minecraft.entity.projectile.ProjectileItemEntity func_213882_k()Lnet/minecraft/item/ItemStack;
public net.minecraft.entity.passive.RabbitEntity func_184651_r()V
public net.minecraft.entity.passive.StriderEntity field_234313_bz_
public net.minecraft.state.StateHolder field_235890_a_
public net.minecraft.server.Main func_240761_a_(Lnet/minecraft/world/storage/SaveFormat$LevelSave;Lcom/mojang/datafixers/DataFixer;ZLjava/util/function/BooleanSupplier;Lcom/google/common/collect/ImmutableSet;)V
public net.minecraft.server.MinecraftServer field_195576_ac
public net.minecraft.server.MinecraftServer field_240766_e_
public net.minecraft.network.play.client.CClientSettingsPacket field_149530_a
public net.minecraft.network.play.server.SWorldSpawnChangedPacket field_240831_a_
public net.minecraft.item.crafting.RecipeBook field_194077_a
public net.minecraft.tileentity.BarrelTileEntity func_213963_a(Lnet/minecraft/block/BlockState;Z)V
public net.minecraft.tileentity.BarrelTileEntity func_213965_a(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/SoundEvent;)V
public net.minecraft.tileentity.ChestTileEntity func_195483_a(Lnet/minecraft/util/SoundEvent;)V
public net.minecraft.tileentity.ChestTileEntity field_145987_o
public net.minecraft.tileentity.ShulkerBoxTileEntity field_190598_h
public net.minecraft.tileentity.SignTileEntity field_145915_a
public net.minecraft.world.server.ServerWorld field_241103_E_
public-f net.minecraft.resources.DataPackRegistries field_240953_c_
protected-f net.minecraft.server.MinecraftServer field_240768_i_
public-f net.minecraft.world.WorldSettings field_77170_d
public-f net.minecraft.world.WorldSettings field_234943_a_

View File

@ -14,9 +14,12 @@
"advancements.AdvancementMixin", "advancements.AdvancementMixin",
"advancements.PlayerAdvancementsMixin", "advancements.PlayerAdvancementsMixin",
"block.AbstractButtonBlockMixin", "block.AbstractButtonBlockMixin",
"block.AbstractFireBlockMixin",
"block.AbstractPressurePlateBlockMixin", "block.AbstractPressurePlateBlockMixin",
"block.AbstractTopPlantBlockMixin",
"block.BambooBlockMixin", "block.BambooBlockMixin",
"block.BambooSaplingBlockMixin", "block.BambooSaplingBlockMixin",
"block.BeehiveBlockMixin",
"block.BlockMixin", "block.BlockMixin",
"block.BlockStateMixin", "block.BlockStateMixin",
"block.BushBlockMixin", "block.BushBlockMixin",
@ -53,6 +56,7 @@
"block.FenceGateBlockMixin", "block.FenceGateBlockMixin",
"block.FireBlockMixin", "block.FireBlockMixin",
"block.FlowingFluidBlockMixin", "block.FlowingFluidBlockMixin",
"block.FungusBlockMixin",
"block.GrassBlockMixin", "block.GrassBlockMixin",
"block.IceBlockMixin", "block.IceBlockMixin",
"block.JukeBoxBlockMixin", "block.JukeBoxBlockMixin",
@ -69,6 +73,8 @@
"block.NoteBlockMixin", "block.NoteBlockMixin",
"block.ObserverBlockMixin", "block.ObserverBlockMixin",
"block.PistonBlockMixin", "block.PistonBlockMixin",
"block.PortalInfoMixin",
"block.PortalSizeMixin",
"block.PoweredRailBlockMixin", "block.PoweredRailBlockMixin",
"block.PressurePlateBlockMixin", "block.PressurePlateBlockMixin",
"block.RedstoneDiodeBlockMixin", "block.RedstoneDiodeBlockMixin",
@ -120,7 +126,10 @@
"entity.ai.brain.task.AssignProfessionTaskMixin", "entity.ai.brain.task.AssignProfessionTaskMixin",
"entity.ai.brain.task.ChangeJobTaskMixin", "entity.ai.brain.task.ChangeJobTaskMixin",
"entity.ai.brain.task.CreateBabyVillagerTaskMixin", "entity.ai.brain.task.CreateBabyVillagerTaskMixin",
"entity.ai.brain.task.FarmerWorkTaskMixin",
"entity.ai.brain.task.FarmTaskMixin", "entity.ai.brain.task.FarmTaskMixin",
"entity.ai.brain.task.FindNewAttackTargetTaskMixin",
"entity.ai.brain.task.ForgetAttackTargetTaskMixin",
"entity.ai.brain.task.InteractWithDoorTaskMixin", "entity.ai.brain.task.InteractWithDoorTaskMixin",
"entity.ai.goal.BreakBlockGoalMixin", "entity.ai.goal.BreakBlockGoalMixin",
"entity.ai.goal.BreakDoorGoalMixin", "entity.ai.goal.BreakDoorGoalMixin",
@ -380,6 +389,7 @@
"village.VillageSiegeMixin", "village.VillageSiegeMixin",
"world.ExplosionMixin", "world.ExplosionMixin",
"world.IBlockReaderMixin", "world.IBlockReaderMixin",
"world.IServerWorldMixin",
"world.IWorldWriterMixin", "world.IWorldWriterMixin",
"world.TeleporterMixin", "world.TeleporterMixin",
"world.TrackedEntityMixin", "world.TrackedEntityMixin",

View File

@ -1,8 +1,6 @@
package io.izzel.arclight.impl; package io.izzel.arclight.impl;
import io.izzel.arclight.common.mod.ArclightConnector; import io.izzel.arclight.common.mod.ArclightConnector;
import io.izzel.arclight.i18n.ArclightConfig;
import org.spongepowered.asm.mixin.Mixins;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ArclightConnector_1_16 extends ArclightConnector { public class ArclightConnector_1_16 extends ArclightConnector {
@ -10,9 +8,10 @@ public class ArclightConnector_1_16 extends ArclightConnector {
@Override @Override
public void connect() { public void connect() {
super.connect(); super.connect();
/*
if (ArclightConfig.spec().getOptimization().isRemoveStream()) { if (ArclightConfig.spec().getOptimization().isRemoveStream()) {
Mixins.addConfiguration("mixins.arclight.impl.optimization.stream.1_15.json"); Mixins.addConfiguration("mixins.arclight.impl.optimization.stream.1_15.json");
} }
LOGGER.info("mixin-load.optimization"); LOGGER.info("mixin-load.optimization");*/
} }
} }