|
| 1 | +package github.kasuminova.novaeng.mixin.actuallyadditions; |
| 2 | + |
| 3 | +import de.ellpeck.actuallyadditions.api.tile.IPhantomTile; |
| 4 | +import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase; |
| 5 | +import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomface; |
| 6 | +import net.minecraft.util.math.BlockPos; |
| 7 | +import org.spongepowered.asm.mixin.Mixin; |
| 8 | +import org.spongepowered.asm.mixin.Overwrite; |
| 9 | +import org.spongepowered.asm.mixin.Shadow; |
| 10 | +import org.spongepowered.asm.mixin.injection.At; |
| 11 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 12 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 13 | + |
| 14 | +@Mixin(TileEntityPhantomface.class) |
| 15 | +public abstract class MixinTileEntityPhantomface extends TileEntityInventoryBase { |
| 16 | + |
| 17 | + @Shadow public BlockPos boundPosition; |
| 18 | + |
| 19 | + public MixinTileEntityPhantomface(int slots, String name) { |
| 20 | + super(slots, name); |
| 21 | + } |
| 22 | + |
| 23 | + @Inject(method = "updateEntity",at = @At(value = "INVOKE", target = "Lde/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface;upgradeRange(ILnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I",shift = At.Shift.BEFORE,remap = false), cancellable = true) |
| 24 | + public void updateEntity(CallbackInfo ci) { |
| 25 | + if (boundPosition != null) { |
| 26 | + if (!world.isBlockLoaded(boundPosition)) { |
| 27 | + ci.cancel(); |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @author circulation |
| 34 | + * @reason 防止意外的区块加载 |
| 35 | + */ |
| 36 | + @Overwrite(remap = false) |
| 37 | + public boolean hasBoundPosition() { |
| 38 | + if (this.boundPosition == null || !world.isBlockLoaded(this.boundPosition)) { |
| 39 | + return false; |
| 40 | + } else if (!(this.world.getTileEntity(this.boundPosition) instanceof IPhantomTile) && (this.getPos().getX() != this.boundPosition.getX() || this.getPos().getY() != this.boundPosition.getY() || this.getPos().getZ() != this.boundPosition.getZ())) { |
| 41 | + return true; |
| 42 | + } else { |
| 43 | + this.boundPosition = null; |
| 44 | + return false; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments