Containers and entity

This commit is contained in:
IzzelAliz 2020-06-02 22:32:43 +08:00
parent c652025fed
commit be9ed9abe6
60 changed files with 1384 additions and 239 deletions

View File

@ -0,0 +1,59 @@
package io.izzel.arclight.api;
import java.util.Objects;
public class ArclightVersion {
public static final ArclightVersion v1_14 = new ArclightVersion("1.14.4", 1140);
public static final ArclightVersion v1_15 = new ArclightVersion("1.15.2", 1152);
private final String name;
private final int num;
public ArclightVersion(String name, int num) {
this.name = name;
this.num = num;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "ArclightVersion{" +
"name='" + name + '\'' +
", num=" + num +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArclightVersion that = (ArclightVersion) o;
return num == that.num &&
Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(name, num);
}
private static ArclightVersion version;
public static void setVersion(ArclightVersion version) {
if (ArclightVersion.version != null) throw new IllegalStateException("Version is already set!");
if (version == null) throw new IllegalArgumentException("Version cannot be null!");
ArclightVersion.version = version;
}
public static boolean atLeast(ArclightVersion v) {
return v.num <= version.num;
}
public static boolean lesserThan(ArclightVersion v) {
return v.num > version.num;
}
}

View File

@ -0,0 +1,6 @@
package io.izzel.arclight.common.bridge.command;
public interface CommandNodeBridge {
void bridge$removeCommand(String name);
}

View File

@ -1,6 +1,7 @@
package io.izzel.arclight.common.bridge.command; package io.izzel.arclight.common.bridge.command;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import org.bukkit.command.CommandSender;
public interface CommandSourceBridge { public interface CommandSourceBridge {
@ -9,4 +10,6 @@ public interface CommandSourceBridge {
void bridge$setCurrentCommand(CommandNode<?> node); void bridge$setCurrentCommand(CommandNode<?> node);
boolean bridge$hasPermission(int i, String bukkitPermission); boolean bridge$hasPermission(int i, String bukkitPermission);
CommandSender bridge$getBukkitSender();
} }

View File

@ -1,8 +1,11 @@
package io.izzel.arclight.common.bridge.entity; package io.izzel.arclight.common.bridge.entity;
import net.minecraft.util.math.BlockPos;
import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.craftbukkit.v.entity.CraftEntity;
public interface InternalEntityBridge { public interface InternalEntityBridge {
CraftEntity internal$getBukkitEntity(); CraftEntity internal$getBukkitEntity();
BlockPos internal$capturedPos();
} }

View File

@ -0,0 +1,6 @@
package io.izzel.arclight.common.bridge.inventory.container;
public interface SlotBridge {
void bridge$onSwapCraft(int numItemsCrafted);
}

View File

@ -8,6 +8,8 @@ public interface ChunkBridge {
Chunk bridge$getBukkitChunk(); Chunk bridge$getBukkitChunk();
void bridge$setBukkitChunk(Chunk chunk);
BlockState bridge$setType(BlockPos pos, BlockState state, boolean isMoving, boolean doPlace); BlockState bridge$setType(BlockPos pos, BlockState state, boolean isMoving, boolean doPlace);
boolean bridge$isMustNotSave(); boolean bridge$isMustNotSave();

View File

@ -1,7 +1,5 @@
package io.izzel.arclight.common.bridge.world.server; package io.izzel.arclight.common.bridge.world.server;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.Ticket; import net.minecraft.world.server.Ticket;
import net.minecraft.world.server.TicketType; import net.minecraft.world.server.TicketType;
@ -18,7 +16,5 @@ public interface TicketManagerBridge {
void bridge$tick(); void bridge$tick();
Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> bridge$getTickets();
<T> void bridge$removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier); <T> void bridge$removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier);
} }

View File

@ -1,8 +1,9 @@
package io.izzel.arclight.common.mixin.bukkit; package io.izzel.arclight.common.mixin.core.command;
import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.ArgumentCommandNode;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import io.izzel.arclight.common.bridge.command.CommandNodeBridge;
import io.izzel.arclight.common.bridge.command.CommandSourceBridge; import io.izzel.arclight.common.bridge.command.CommandSourceBridge;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -15,14 +16,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
@Mixin(CommandNode.class) @Mixin(value = CommandNode.class, remap = false)
public class CommandNodeMixin<S> { public class CommandNodeMixin<S> implements CommandNodeBridge {
// @formatter:off // @formatter:off
@Shadow(remap = false) private Map<String, CommandNode<S>> children; @Shadow private Map<String, CommandNode<S>> children;
@Shadow(remap = false) private Map<String, LiteralCommandNode<S>> literals; @Shadow private Map<String, LiteralCommandNode<S>> literals;
@Shadow(remap = false) private Map<String, ArgumentCommandNode<S, ?>> arguments; @Shadow private Map<String, ArgumentCommandNode<S, ?>> arguments;
@Shadow(remap = false) @Final private Predicate<S> requirement; @Shadow @Final private Predicate<S> requirement;
// @formatter:on // @formatter:on
public void removeCommand(String name) { public void removeCommand(String name) {
@ -31,7 +32,12 @@ public class CommandNodeMixin<S> {
arguments.remove(name); arguments.remove(name);
} }
@Inject(method = "canUse", remap = false, cancellable = true, at = @At("HEAD")) @Override
public void bridge$removeCommand(String name) {
removeCommand(name);
}
@Inject(method = "canUse", cancellable = true, at = @At("HEAD"))
public void on(S source, CallbackInfoReturnable<Boolean> cir) { public void on(S source, CallbackInfoReturnable<Boolean> cir) {
if (source instanceof CommandSource) { if (source instanceof CommandSource) {
try { try {

View File

@ -22,7 +22,7 @@ public abstract class CommandSourceMixin implements CommandSourceBridge {
// @formatter:off // @formatter:off
@Shadow @Final public ICommandSource source; @Shadow @Final public ICommandSource source;
@Shadow public abstract ServerWorld func_197023_e(); @Shadow public abstract ServerWorld getWorld();
@Shadow @Final private int permissionLevel; @Shadow @Final private int permissionLevel;
// @formatter:on // @formatter:on
@ -37,7 +37,7 @@ public abstract class CommandSourceMixin implements CommandSourceBridge {
public boolean hasPermission(int i, String bukkitPermission) { public boolean hasPermission(int i, String bukkitPermission) {
// World is null when loading functions // World is null when loading functions
return ((func_197023_e() == null || !((CraftServer) Bukkit.getServer()).ignoreVanillaPermissions) && this.permissionLevel >= i) || getBukkitSender().hasPermission(bukkitPermission); return ((getWorld() == null || !((CraftServer) Bukkit.getServer()).ignoreVanillaPermissions) && this.permissionLevel >= i) || getBukkitSender().hasPermission(bukkitPermission);
} }
@Override @Override
@ -58,4 +58,9 @@ public abstract class CommandSourceMixin implements CommandSourceBridge {
public CommandSender getBukkitSender() { public CommandSender getBukkitSender() {
return ((ICommandSourceBridge) this.source).bridge$getBukkitSender((CommandSource) (Object) this); return ((ICommandSourceBridge) this.source).bridge$getBukkitSender((CommandSource) (Object) this);
} }
@Override
public CommandSender bridge$getBukkitSender() {
return getBukkitSender();
}
} }

View File

@ -0,0 +1,39 @@
package io.izzel.arclight.common.mixin.core.command;
import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.RootCommandNode;
import io.izzel.arclight.common.bridge.command.CommandNodeBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.ISuggestionProvider;
import net.minecraft.entity.player.ServerPlayerEntity;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerCommandSendEvent;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.LinkedHashSet;
import java.util.Map;
@Mixin(Commands.class)
public class CommandsMixin {
@Inject(method = "send", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/command/Commands;commandSourceNodesToSuggestionNodes(Lcom/mojang/brigadier/tree/CommandNode;Lcom/mojang/brigadier/tree/CommandNode;Lnet/minecraft/command/CommandSource;Ljava/util/Map;)V"))
private void arclight$playerCommandSend(ServerPlayerEntity player, CallbackInfo ci, Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map , RootCommandNode<ISuggestionProvider> node) {
LinkedHashSet<String> set = new LinkedHashSet<>();
for (CommandNode<ISuggestionProvider> child : node.getChildren()) {
set.add(child.getName());
}
PlayerCommandSendEvent event = new PlayerCommandSendEvent(((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(), new LinkedHashSet<>(set));
Bukkit.getPluginManager().callEvent(event);
for (String s : set) {
if (!event.getCommands().contains(s)) {
((CommandNodeBridge) node).bridge$removeCommand(s);
}
}
}
}

View File

@ -17,6 +17,6 @@ public class SummonCommandMixin {
@Inject(method = "summonEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addLightningBolt(Lnet/minecraft/entity/effect/LightningBoltEntity;)V")) @Inject(method = "summonEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addLightningBolt(Lnet/minecraft/entity/effect/LightningBoltEntity;)V"))
private static void arclight$strikeReason(CommandSource source, ResourceLocation type, Vec3d pos, CompoundNBT nbt, boolean randomizeProperties, CallbackInfoReturnable<Integer> cir) { private static void arclight$strikeReason(CommandSource source, ResourceLocation type, Vec3d pos, CompoundNBT nbt, boolean randomizeProperties, CallbackInfoReturnable<Integer> cir) {
((ServerWorldBridge) source.func_197023_e()).bridge$pushStrikeLightningCause(LightningStrikeEvent.Cause.COMMAND); ((ServerWorldBridge) source.getWorld()).bridge$pushStrikeLightningCause(LightningStrikeEvent.Cause.COMMAND);
} }
} }

View File

@ -7,10 +7,8 @@ import io.izzel.arclight.common.bridge.entity.LivingEntityBridge;
import io.izzel.arclight.common.bridge.entity.MobEntityBridge; import io.izzel.arclight.common.bridge.entity.MobEntityBridge;
import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge;
import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge;
import io.izzel.arclight.common.bridge.world.storage.SaveHandlerBridge; import io.izzel.arclight.common.bridge.world.storage.SaveHandlerBridge;
import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
@ -29,7 +27,6 @@ import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.scoreboard.Team; import net.minecraft.scoreboard.Team;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -38,11 +35,8 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -58,7 +52,6 @@ import org.bukkit.event.entity.EntityCombustByBlockEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDropItemEvent; import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityPoseChangeEvent; import org.bukkit.event.entity.EntityPoseChangeEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
@ -69,7 +62,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
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.Overwrite;
import org.spongepowered.asm.mixin.Shadow; 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.Inject;
@ -121,8 +113,6 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
@Shadow @Deprecated public boolean removed; @Shadow @Deprecated public boolean removed;
@Shadow @Nullable public abstract MinecraftServer getServer(); @Shadow @Nullable public abstract MinecraftServer getServer();
@Shadow public abstract Vec3d getMotion(); @Shadow public abstract Vec3d getMotion();
@Shadow public abstract Vec3d getLastPortalVec();
@Shadow public abstract Direction getTeleportDirection();
@Shadow public abstract EntityType<?> getType(); @Shadow public abstract EntityType<?> getType();
@Shadow public abstract void remove(boolean keepData); @Shadow public abstract void remove(boolean keepData);
@Shadow @Final protected Random rand; @Shadow @Final protected Random rand;
@ -176,11 +166,10 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
@Shadow public abstract int getEntityId(); @Shadow public abstract int getEntityId();
@Shadow @Nullable public abstract ITextComponent getCustomName(); @Shadow @Nullable public abstract ITextComponent getCustomName();
@Shadow protected abstract void applyEnchantments(LivingEntity entityLivingBaseIn, Entity entityIn); @Shadow protected abstract void applyEnchantments(LivingEntity entityLivingBaseIn, Entity entityIn);
@Shadow public abstract float getEyeHeight();
@Shadow @Nullable public abstract Entity changeDimension(DimensionType destination);
// @formatter:on // @formatter:on
@Shadow
public abstract float getEyeHeight();
private static final int CURRENT_LEVEL = 2; private static final int CURRENT_LEVEL = 2;
public boolean persist; public boolean persist;
public boolean valid; public boolean valid;
@ -452,6 +441,11 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
} }
} }
@Inject(method = "setPositionAndRotation", at = @At("RETURN"))
private void arclight$loadChunk(double x, double y, double z, float yaw, float pitch, CallbackInfo ci) {
this.world.getChunk((int)Math.floor(this.posX) >> 4, (int)Math.floor(this.posZ) >> 4);
}
@Inject(method = "writeUnlessRemoved", cancellable = true, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/Entity;getEntityString()Ljava/lang/String;")) @Inject(method = "writeUnlessRemoved", cancellable = true, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/Entity;getEntityString()Ljava/lang/String;"))
public void arclight$writeUnlessRemoved$persistCheck(CompoundNBT compound, CallbackInfoReturnable<Boolean> cir) { public void arclight$writeUnlessRemoved$persistCheck(CompoundNBT compound, CallbackInfoReturnable<Boolean> cir) {
if (!this.persist) if (!this.persist)
@ -520,7 +514,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
} }
if (bworld == null) { if (bworld == null) {
bworld = ((WorldBridge) ((CraftServer) server).getServer().func_71218_a(DimensionType.OVERWORLD)).bridge$getWorld(); bworld = ((WorldBridge) ((CraftServer) server).getServer().getWorld(DimensionType.OVERWORLD)).bridge$getWorld();
} }
setWorld(bworld == null ? null : ((CraftWorld) bworld).getHandle()); setWorld(bworld == null ? null : ((CraftWorld) bworld).getHandle());
@ -741,6 +735,15 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
private transient BlockPos arclight$tpPos; private transient BlockPos arclight$tpPos;
@Override
public BlockPos internal$capturedPos() {
try {
return arclight$tpPos;
} finally {
arclight$tpPos = null;
}
}
public Entity teleportTo(DimensionType type, BlockPos blockPos) { public Entity teleportTo(DimensionType type, BlockPos blockPos) {
arclight$tpPos = blockPos; arclight$tpPos = blockPos;
return changeDimension(type); return changeDimension(type);
@ -751,101 +754,4 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge,
return teleportTo(type, blockPos); return teleportTo(type, blockPos);
} }
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
@Nullable
public Entity changeDimension(DimensionType destination) {
BlockPos location = arclight$tpPos;
arclight$tpPos = null;
if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination)) return null;
if (!this.world.isRemote && !this.removed) {
this.world.getProfiler().startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
DimensionType dimensiontype = this.dimension;
ServerWorld serverworld = minecraftserver.func_71218_a(dimensiontype);
ServerWorld serverworld1 = minecraftserver.func_71218_a(destination);
if (serverworld1 == null) {
return null;
}
// this.dimension = destination;
// this.detach();
this.world.getProfiler().startSection("reposition");
Vec3d vec3d = this.getMotion();
float f = 0.0F;
BlockPos blockpos = location;
if (blockpos == null) {
if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
blockpos = serverworld1.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1.getSpawnPoint());
} else if (destination == DimensionType.THE_END) {
blockpos = serverworld1.getSpawnCoordinate();
} else {
double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1.getDimension().getMovementFactor();
double d0 = this.posX * movementFactor;
double d1 = this.posZ * movementFactor;
double d3 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minX() + 16.0D);
double d4 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minZ() + 16.0D);
double d5 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxX() - 16.0D);
double d6 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxZ() - 16.0D);
d0 = MathHelper.clamp(d0, d3, d5);
d1 = MathHelper.clamp(d1, d4, d6);
Vec3d vec3d1 = this.getLastPortalVec();
blockpos = new BlockPos(d0, this.posY, d1);
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1.getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
}
blockpos = new BlockPos(blockpattern$portalinfo.pos);
vec3d = blockpattern$portalinfo.motion;
f = (float) blockpattern$portalinfo.rotation;
}
}
if (location == null) {
Location enter = this.getBukkitEntity().getLocation();
Location exit = new Location(((ServerWorldBridge) serverworld1).bridge$getWorld(), blockpos.getX(), blockpos.getY(), blockpos.getZ());
EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit);
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !this.isAlive()) {
return null;
}
exit = event.getTo();
serverworld1 = ((CraftWorld) exit.getWorld()).getHandle();
blockpos = new BlockPos(exit.getX(), exit.getY(), exit.getZ());
}
this.dimension = destination;
this.detach();
this.world.getProfiler().endStartSection("reloading");
Entity entity = this.getType().create(serverworld1);
if (entity != null) {
entity.copyDataFromOld((Entity) (Object) this);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
entity.setMotion(vec3d);
serverworld1.func_217460_e(entity);
this.getBukkitEntity().setHandle(entity);
((EntityBridge) entity).bridge$setBukkitEntity(getBukkitEntity());
if ((Object) this instanceof MobEntity) {
((MobEntity) (Object) this).clearLeashed(true, false);
}
}
this.remove(false);
this.world.getProfiler().endSection();
serverworld.resetUpdateEntityTick();
serverworld1.resetUpdateEntityTick();
this.world.getProfiler().endSection();
return entity;
} else {
return null;
}
}
} }

View File

@ -13,8 +13,12 @@ public abstract class MinecartCommandBlockEntity_MinecartCommandLogicMixin imple
@Shadow(aliases = {"this$0", "field_210168_a"}) private MinecartCommandBlockEntity outerThis; @Shadow(aliases = {"this$0", "field_210168_a"}) private MinecartCommandBlockEntity outerThis;
@Override public CommandSender getBukkitSender(CommandSource wrapper) {
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return ((EntityBridge) outerThis).bridge$getBukkitEntity(); return ((EntityBridge) outerThis).bridge$getBukkitEntity();
} }
@Override
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return getBukkitSender(wrapper);
}
} }

View File

@ -22,7 +22,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(AbstractFurnaceContainer.class) @Mixin(AbstractFurnaceContainer.class)
public class AbstractFurnaceContainerMixin extends ContainerMixin { public abstract class AbstractFurnaceContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory furnaceInventory; @Shadow @Final private IInventory furnaceInventory;

View File

@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BeaconContainer.class) @Mixin(BeaconContainer.class)
public class BeaconContainerMixin extends ContainerMixin { public abstract class BeaconContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory tileBeacon; @Shadow @Final private IInventory tileBeacon;

View File

@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BrewingStandContainer.class) @Mixin(BrewingStandContainer.class)
public class BrewingStandContainerMixin extends ContainerMixin { public abstract class BrewingStandContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory tileBrewingStand; @Shadow @Final private IInventory tileBrewingStand;

View File

@ -21,11 +21,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(CartographyContainer.class) @Mixin(CartographyContainer.class)
public class CartographyContainerMixin extends ContainerMixin implements CartographyContainerBridge { public abstract class CartographyContainerMixin extends ContainerMixin implements CartographyContainerBridge {
// @formatter:off // @formatter:off
@Shadow @Final private IWorldPosCallable field_216999_d; @Shadow @Final private IWorldPosCallable worldPosCallable;
@Shadow @Final public IInventory field_216998_c; @Shadow @Final public IInventory tableInventory;
@Shadow @Final private CraftResultInventory field_217001_f; @Shadow @Final private CraftResultInventory field_217001_f;
// @formatter:on // @formatter:on
@ -48,13 +48,13 @@ public class CartographyContainerMixin extends ContainerMixin implements Cartogr
return bukkitEntity; return bukkitEntity;
} }
CraftInventoryCartography inventory = new CraftInventoryCartography(this.field_216998_c, this.field_217001_f); CraftInventoryCartography inventory = new CraftInventoryCartography(this.tableInventory, this.field_217001_f);
bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }
@Override @Override
public IWorldPosCallable bridge$getContainerAccess() { public IWorldPosCallable bridge$getContainerAccess() {
return this.field_216999_d; return this.worldPosCallable;
} }
} }

View File

@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ChestContainer.class) @Mixin(ChestContainer.class)
public class ChestContainerMixin extends ContainerMixin { public abstract class ChestContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory lowerChestInventory; @Shadow @Final private IInventory lowerChestInventory;

View File

@ -3,19 +3,54 @@ package io.izzel.arclight.common.mixin.core.inventory.container;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge;
import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge;
import io.izzel.arclight.common.bridge.inventory.container.SlotBridge;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SSetSlotPacket;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventory;
import org.bukkit.craftbukkit.v.inventory.CraftItemStack;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
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.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Mixin(Container.class) @Mixin(Container.class)
public abstract class ContainerMixin implements ContainerBridge { public abstract class ContainerMixin implements ContainerBridge {
// @formatter:off // @formatter:off
@Shadow public void detectAndSendChanges() {} @Shadow public void detectAndSendChanges() {}
@Shadow private int dragEvent;
@Shadow protected abstract void resetDrag();
@Shadow private int dragMode;
@Shadow @Final private Set<Slot> dragSlots;
@Shadow public List<Slot> inventorySlots;
@Shadow public abstract boolean canDragIntoSlot(Slot slotIn);
@Shadow public abstract ItemStack transferStackInSlot(PlayerEntity playerIn, int index);
@Shadow public abstract boolean canMergeSlot(ItemStack stack, Slot slotIn);
@Shadow @Final public int windowId;
@Shadow public abstract Slot getSlot(int slotId);
// @formatter:on // @formatter:on
public boolean checkReachable = true; public boolean checkReachable = true;
@ -43,6 +78,269 @@ public abstract class ContainerMixin implements ContainerBridge {
this.title = title; this.title = title;
} }
@Redirect(method = "onContainerClosed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/ItemEntity;"))
private ItemEntity arclight$cleanBeforeDrop(PlayerEntity playerEntity, ItemStack itemStackIn, boolean unused) {
playerEntity.inventory.setItemStack(ItemStack.EMPTY);
return playerEntity.dropItem(itemStackIn, unused);
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public ItemStack slotClick(int i, int j, ClickType clickType, PlayerEntity entity) {
ItemStack itemstack = ItemStack.EMPTY;
PlayerInventory playerinventory = entity.inventory;
if (clickType == ClickType.QUICK_CRAFT) {
int i2 = this.dragEvent;
this.dragEvent = Container.getDragEvent(j);
if ((i2 != 1 || this.dragEvent != 2) && i2 != this.dragEvent) {
this.resetDrag();
} else if (playerinventory.getItemStack().isEmpty()) {
this.resetDrag();
} else if (this.dragEvent == 0) {
this.dragMode = Container.extractDragMode(j);
if (Container.isValidDragMode(this.dragMode, entity)) {
this.dragEvent = 1;
this.dragSlots.clear();
} else {
this.resetDrag();
}
} else if (this.dragEvent == 1) {
Slot slot = this.inventorySlots.get(i);
ItemStack itemstack2 = playerinventory.getItemStack();
if (slot != null && Container.canAddItemToSlot(slot, itemstack2, true) && slot.isItemValid(itemstack2) && (this.dragMode == 2 || itemstack2.getCount() > this.dragSlots.size()) && this.canDragIntoSlot(slot)) {
this.dragSlots.add(slot);
}
} else if (this.dragEvent == 2) {
if (!this.dragSlots.isEmpty()) {
ItemStack itemstack3 = playerinventory.getItemStack().copy();
int k = playerinventory.getItemStack().getCount();
Iterator<Slot> iterator = this.dragSlots.iterator();
Map<Integer, ItemStack> draggedSlots = new HashMap<>();
while (iterator.hasNext()) {
Slot slot2 = iterator.next();
ItemStack itemstack4 = playerinventory.getItemStack();
if (slot2 != null && Container.canAddItemToSlot(slot2, itemstack4, true) && slot2.isItemValid(itemstack4) && (this.dragMode == 2 || itemstack4.getCount() >= this.dragSlots.size()) && this.canDragIntoSlot(slot2)) {
ItemStack itemstack5 = itemstack3.copy();
int j2 = slot2.getHasStack() ? slot2.getStack().getCount() : 0;
Container.computeStackSize(this.dragSlots, this.dragMode, itemstack5, j2);
int l = Math.min(itemstack5.getMaxStackSize(), slot2.getItemStackLimit(itemstack5));
if (itemstack5.getCount() > l) {
itemstack5.setCount(l);
}
k -= itemstack5.getCount() - j2;
draggedSlots.put(slot2.slotNumber, itemstack5);
}
}
InventoryView view = this.getBukkitView();
org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack3);
newcursor.setAmount(k);
Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<>();
for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet()) {
eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
}
ItemStack oldCursor = playerinventory.getItemStack();
playerinventory.setItemStack(CraftItemStack.asNMSCopy(newcursor));
InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != Material.AIR) ? newcursor : null, CraftItemStack.asBukkitCopy(oldCursor), this.dragMode == 1, eventmap);
Bukkit.getPluginManager().callEvent(event);
boolean needsUpdate = event.getResult() != Event.Result.DEFAULT;
if (event.getResult() != Event.Result.DENY) {
for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet()) {
view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue()));
}
if (playerinventory.getItemStack() != null) {
playerinventory.setItemStack(CraftItemStack.asNMSCopy(event.getCursor()));
needsUpdate = true;
}
} else {
playerinventory.setItemStack(oldCursor);
}
if (needsUpdate && entity instanceof ServerPlayerEntity) {
((ServerPlayerEntity) entity).sendContainerToPlayer((Container) (Object) this);
}
}
this.resetDrag();
} else {
this.resetDrag();
}
} else if (this.dragEvent != 0) {
this.resetDrag();
} else if ((clickType == ClickType.PICKUP || clickType == ClickType.QUICK_MOVE) && (j == 0 || j == 1)) {
if (i == -999) {
if (!playerinventory.getItemStack().isEmpty()) {
if (j == 0) {
ItemStack carried = playerinventory.getItemStack();
playerinventory.setItemStack(ItemStack.EMPTY);
entity.dropItem(carried, true);
}
if (j == 1) {
entity.dropItem(playerinventory.getItemStack().split(1), true);
}
}
} else if (clickType == ClickType.QUICK_MOVE) {
if (i < 0) {
return ItemStack.EMPTY;
}
Slot slot3 = this.inventorySlots.get(i);
if (slot3 == null || !slot3.canTakeStack(entity)) {
return ItemStack.EMPTY;
}
for (ItemStack itemstack3 = this.transferStackInSlot(entity, i); !itemstack3.isEmpty(); itemstack3 = this.transferStackInSlot(entity, i)) {
if (!ItemStack.areItemsEqual(slot3.getStack(), itemstack3)) {
break;
}
itemstack = itemstack3.copy();
}
} else {
if (i < 0) {
return ItemStack.EMPTY;
}
Slot slot3 = this.inventorySlots.get(i);
if (slot3 != null) {
ItemStack itemstack3 = slot3.getStack();
ItemStack itemstack2 = playerinventory.getItemStack();
if (!itemstack3.isEmpty()) {
itemstack = itemstack3.copy();
}
if (itemstack3.isEmpty()) {
if (!itemstack2.isEmpty() && slot3.isItemValid(itemstack2)) {
int k2 = (j == 0) ? itemstack2.getCount() : 1;
if (k2 > slot3.getItemStackLimit(itemstack2)) {
k2 = slot3.getItemStackLimit(itemstack2);
}
slot3.putStack(itemstack2.split(k2));
}
} else if (slot3.canTakeStack(entity)) {
if (itemstack2.isEmpty()) {
if (itemstack3.isEmpty()) {
slot3.putStack(ItemStack.EMPTY);
playerinventory.setItemStack(ItemStack.EMPTY);
} else {
int k2 = (j == 0) ? itemstack3.getCount() : ((itemstack3.getCount() + 1) / 2);
playerinventory.setItemStack(slot3.decrStackSize(k2));
if (itemstack3.isEmpty()) {
slot3.putStack(ItemStack.EMPTY);
}
slot3.onTake(entity, playerinventory.getItemStack());
}
} else if (slot3.isItemValid(itemstack2)) {
if (Container.areItemsAndTagsEqual(itemstack3, itemstack2)) {
int k2 = (j == 0) ? itemstack2.getCount() : 1;
if (k2 > slot3.getItemStackLimit(itemstack2) - itemstack3.getCount()) {
k2 = slot3.getItemStackLimit(itemstack2) - itemstack3.getCount();
}
if (k2 > itemstack2.getMaxStackSize() - itemstack3.getCount()) {
k2 = itemstack2.getMaxStackSize() - itemstack3.getCount();
}
itemstack2.shrink(k2);
itemstack3.grow(k2);
} else if (itemstack2.getCount() <= slot3.getItemStackLimit(itemstack2)) {
slot3.putStack(itemstack2);
playerinventory.setItemStack(itemstack3);
}
} else if (itemstack2.getMaxStackSize() > 1 && Container.areItemsAndTagsEqual(itemstack3, itemstack2) && !itemstack3.isEmpty()) {
int k2 = itemstack3.getCount();
if (k2 + itemstack2.getCount() <= itemstack2.getMaxStackSize()) {
itemstack2.grow(k2);
itemstack3 = slot3.decrStackSize(k2);
if (itemstack3.isEmpty()) {
slot3.putStack(ItemStack.EMPTY);
}
slot3.onTake(entity, playerinventory.getItemStack());
}
}
}
slot3.onSlotChanged();
if (entity instanceof ServerPlayerEntity && slot3.getSlotStackLimit() != 64) {
((ServerPlayerEntity) entity).connection.sendPacket(new SSetSlotPacket(this.windowId, slot3.slotNumber, slot3.getStack()));
if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) {
((ServerPlayerEntity) entity).connection.sendPacket(new SSetSlotPacket(this.windowId, 0, this.getSlot(0).getStack()));
}
}
}
}
} else if (clickType == ClickType.SWAP && j >= 0 && j < 9) {
Slot slot3 = this.inventorySlots.get(i);
ItemStack itemstack3 = playerinventory.getStackInSlot(j);
ItemStack itemstack2 = slot3.getStack();
if (!itemstack3.isEmpty() || !itemstack2.isEmpty()) {
if (itemstack3.isEmpty()) {
if (slot3.canTakeStack(entity)) {
playerinventory.setInventorySlotContents(j, itemstack2);
((SlotBridge) slot3).bridge$onSwapCraft(itemstack2.getCount());
slot3.putStack(ItemStack.EMPTY);
slot3.onTake(entity, itemstack2);
}
} else if (itemstack2.isEmpty()) {
if (slot3.isItemValid(itemstack3)) {
int k2 = slot3.getItemStackLimit(itemstack3);
if (itemstack3.getCount() > k2) {
slot3.putStack(itemstack3.split(k2));
} else {
slot3.putStack(itemstack3);
playerinventory.setInventorySlotContents(j, ItemStack.EMPTY);
}
}
} else if (slot3.canTakeStack(entity) && slot3.isItemValid(itemstack3)) {
int k2 = slot3.getItemStackLimit(itemstack3);
if (itemstack3.getCount() > k2) {
slot3.putStack(itemstack3.split(k2));
slot3.onTake(entity, itemstack2);
if (!playerinventory.addItemStackToInventory(itemstack2)) {
entity.dropItem(itemstack2, true);
}
} else {
slot3.putStack(itemstack3);
playerinventory.setInventorySlotContents(j, itemstack2);
slot3.onTake(entity, itemstack2);
}
}
}
} else if (clickType == ClickType.CLONE && entity.abilities.isCreativeMode && playerinventory.getItemStack().isEmpty() && i >= 0) {
Slot slot3 = this.inventorySlots.get(i);
if (slot3 != null && slot3.getHasStack()) {
ItemStack itemstack3 = slot3.getStack().copy();
itemstack3.setCount(itemstack3.getMaxStackSize());
playerinventory.setItemStack(itemstack3);
}
} else if (clickType == ClickType.THROW && playerinventory.getItemStack().isEmpty() && i >= 0) {
Slot slot3 = this.inventorySlots.get(i);
if (slot3 != null && slot3.getHasStack() && slot3.canTakeStack(entity)) {
ItemStack itemstack3 = slot3.decrStackSize((j == 0) ? 1 : slot3.getStack().getCount());
slot3.onTake(entity, itemstack3);
entity.dropItem(itemstack3, true);
}
} else if (clickType == ClickType.PICKUP_ALL && i >= 0) {
Slot slot3 = this.inventorySlots.get(i);
ItemStack itemstack3 = playerinventory.getItemStack();
if (!itemstack3.isEmpty() && (slot3 == null || !slot3.getHasStack() || !slot3.canTakeStack(entity))) {
int k = (j == 0) ? 0 : (this.inventorySlots.size() - 1);
int k2 = (j == 0) ? 1 : -1;
for (int l2 = 0; l2 < 2; ++l2) {
for (int i3 = k; i3 >= 0 && i3 < this.inventorySlots.size() && itemstack3.getCount() < itemstack3.getMaxStackSize(); i3 += k2) {
Slot slot4 = this.inventorySlots.get(i3);
if (slot4.getHasStack() && Container.canAddItemToSlot(slot4, itemstack3, true) && slot4.canTakeStack(entity) && this.canMergeSlot(itemstack3, slot4)) {
ItemStack itemstack6 = slot4.getStack();
if (l2 != 0 || itemstack6.getCount() != itemstack6.getMaxStackSize()) {
int l = Math.min(itemstack3.getMaxStackSize() - itemstack3.getCount(), itemstack6.getCount());
ItemStack itemstack7 = slot4.decrStackSize(l);
itemstack3.grow(l);
if (itemstack7.isEmpty()) {
slot4.putStack(ItemStack.EMPTY);
}
slot4.onTake(entity, itemstack7);
}
}
}
}
}
this.detectAndSendChanges();
}
return itemstack;
}
@Override @Override
public boolean bridge$isCheckReachable() { public boolean bridge$isCheckReachable() {
return checkReachable; return checkReachable;

View File

@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(DispenserContainer.class) @Mixin(DispenserContainer.class)
public class DispenserContainerMixin extends ContainerMixin { public abstract class DispenserContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final public IInventory dispenserInventory; @Shadow @Final public IInventory dispenserInventory;

View File

@ -54,7 +54,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
// @formatter:off // @formatter:off
@Shadow @Final private IInventory tableInventory; @Shadow @Final private IInventory tableInventory;
@Shadow @Final private IWorldPosCallable field_217006_g; @Shadow @Final private IWorldPosCallable worldPosCallable;
@Shadow protected abstract float getPower(World world, BlockPos pos); @Shadow protected abstract float getPower(World world, BlockPos pos);
@Shadow @Final private Random rand; @Shadow @Final private Random rand;
@Shadow @Final private IntReferenceHolder xpSeed; @Shadow @Final private IntReferenceHolder xpSeed;
@ -86,7 +86,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
if (inventoryIn == this.tableInventory) { if (inventoryIn == this.tableInventory) {
ItemStack itemstack = inventoryIn.getStackInSlot(0); ItemStack itemstack = inventoryIn.getStackInSlot(0);
if (!itemstack.isEmpty()) { if (!itemstack.isEmpty()) {
this.field_217006_g.consume((p_217002_2_, p_217002_3_) -> { this.worldPosCallable.consume((p_217002_2_, p_217002_3_) -> {
float power = 0; float power = 0;
for (int k = -1; k <= 1; ++k) { for (int k = -1; k <= 1; ++k) {
@ -136,7 +136,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.worldClue[j], this.enchantLevels[j]) : null; offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.worldClue[j], this.enchantLevels[j]) : null;
} }
PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), ((IWorldPosCallableBridge) this.field_217006_g).bridge$getLocation().getBlock(), item, offers, (int) power); PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, offers, (int) power);
event.setCancelled(!itemstack.isEnchantable()); event.setCancelled(!itemstack.isEnchantable());
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@ -189,7 +189,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
} else if (this.enchantLevels[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.enchantLevels[id]) && !playerIn.abilities.isCreativeMode) { } else if (this.enchantLevels[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.enchantLevels[id]) && !playerIn.abilities.isCreativeMode) {
return false; return false;
} else { } else {
this.field_217006_g.consume((p_217003_6_, p_217003_7_) -> { this.worldPosCallable.consume((p_217003_6_, p_217003_7_) -> {
ItemStack itemstack2 = itemstack; ItemStack itemstack2 = itemstack;
List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]); List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
if (true || !list.isEmpty()) { if (true || !list.isEmpty()) {
@ -202,7 +202,7 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
} }
CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2); CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
EnchantItemEvent event = new EnchantItemEvent(((Player) ((PlayerEntityBridge) playerIn).bridge$getBukkitEntity()), this.getBukkitView(), ((IWorldPosCallableBridge) this.field_217006_g).bridge$getLocation().getBlock(), item, this.enchantLevels[i], enchants, i); EnchantItemEvent event = new EnchantItemEvent(((Player) ((PlayerEntityBridge) playerIn).bridge$getBukkitEntity()), this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, this.enchantLevels[i], enchants, i);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
int level = event.getExpLevelCost(); int level = event.getExpLevelCost();
@ -271,6 +271,6 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement
@Override @Override
public IWorldPosCallable bridge$getContainerAccess() { public IWorldPosCallable bridge$getContainerAccess() {
return this.field_217006_g; return this.worldPosCallable;
} }
} }

View File

@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import io.izzel.arclight.common.bridge.inventory.container.GrindstoneContainerBridge; import io.izzel.arclight.common.bridge.inventory.container.GrindstoneContainerBridge;
@Mixin(GrindstoneContainer.class) @Mixin(GrindstoneContainer.class)
public class GrindstoneContainerMixin extends ContainerMixin implements GrindstoneContainerBridge { public abstract class GrindstoneContainerMixin extends ContainerMixin implements GrindstoneContainerBridge {
@Shadow @Final private IInventory inputInventory; @Shadow @Final private IInventory inputInventory;
@Shadow @Final private IInventory outputInventory; @Shadow @Final private IInventory outputInventory;

View File

@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(HopperContainer.class) @Mixin(HopperContainer.class)
public class HopperContainerMixin extends ContainerMixin { public abstract class HopperContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory hopperInventory; @Shadow @Final private IInventory hopperInventory;

View File

@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(HorseInventoryContainer.class) @Mixin(HorseInventoryContainer.class)
public class HorseInventoryContainerMixin extends ContainerMixin { public abstract class HorseInventoryContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory horseInventory; @Shadow @Final private IInventory horseInventory;

View File

@ -21,10 +21,10 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LecternContainer.class) @Mixin(LecternContainer.class)
public class LecternContainerMixin extends ContainerMixin implements LecternContainerBridge { public abstract class LecternContainerMixin extends ContainerMixin implements LecternContainerBridge {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory field_217018_c; @Shadow @Final private IInventory lecternInventory;
// @formatter:on // @formatter:on
private CraftInventoryView bukkitEntity; private CraftInventoryView bukkitEntity;
@ -67,7 +67,7 @@ public class LecternContainerMixin extends ContainerMixin implements LecternCont
if (bukkitEntity != null) { if (bukkitEntity != null) {
return bukkitEntity; return bukkitEntity;
} }
CraftInventoryLectern inventory = new CraftInventoryLectern(this.field_217018_c); CraftInventoryLectern inventory = new CraftInventoryLectern(this.lecternInventory);
bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }

View File

@ -21,11 +21,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import io.izzel.arclight.common.bridge.inventory.container.LoomContainerBridge; import io.izzel.arclight.common.bridge.inventory.container.LoomContainerBridge;
@Mixin(LoomContainer.class) @Mixin(LoomContainer.class)
public class LoomContainerMixin extends ContainerMixin implements LoomContainerBridge { public abstract class LoomContainerMixin extends ContainerMixin implements LoomContainerBridge {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory field_217040_j; // crafting @Shadow @Final private IInventory inputInventory;
@Shadow @Final private IInventory field_217041_k; // result @Shadow @Final private IInventory outputInventory;
@Shadow @Final private IWorldPosCallable worldPos; @Shadow @Final private IWorldPosCallable worldPos;
// @formatter:on // @formatter:on
@ -50,7 +50,7 @@ public class LoomContainerMixin extends ContainerMixin implements LoomContainerB
return bukkitEntity; return bukkitEntity;
} }
CraftInventoryLoom inventory = new CraftInventoryLoom(this.field_217040_j, this.field_217041_k); CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputInventory, this.outputInventory);
bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }

View File

@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MerchantContainer.class) @Mixin(MerchantContainer.class)
public class MerchantContainerMixin extends ContainerMixin { public abstract class MerchantContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IMerchant merchant; @Shadow @Final private IMerchant merchant;

View File

@ -22,11 +22,11 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerContainer.class) @Mixin(PlayerContainer.class)
public class PlayerContainerMixin extends ContainerMixin { public abstract class PlayerContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private CraftingInventory field_75181_e; @Shadow @Final private CraftingInventory craftMatrix;
@Shadow @Final private CraftResultInventory field_75179_f; @Shadow @Final private CraftResultInventory craftResult;
// @formatter:on // @formatter:on
private CraftInventoryView bukkitEntity; private CraftInventoryView bukkitEntity;
@ -35,8 +35,8 @@ public class PlayerContainerMixin extends ContainerMixin {
@Inject(method = "<init>", at = @At("RETURN")) @Inject(method = "<init>", at = @At("RETURN"))
public void arclight$init(PlayerInventory playerInventory, boolean localWorld, PlayerEntity playerIn, CallbackInfo ci) { public void arclight$init(PlayerInventory playerInventory, boolean localWorld, PlayerEntity playerIn, CallbackInfo ci) {
this.player = playerInventory; this.player = playerInventory;
((CraftingInventoryBridge) this.field_75181_e).bridge$setOwner(playerInventory.player); ((CraftingInventoryBridge) this.craftMatrix).bridge$setOwner(playerInventory.player);
((CraftingInventoryBridge) this.field_75181_e).bridge$setResultInventory(this.field_75179_f); ((CraftingInventoryBridge) this.craftMatrix).bridge$setResultInventory(this.craftResult);
this.setTitle(new TranslationTextComponent("container.crafting")); this.setTitle(new TranslationTextComponent("container.crafting"));
} }
@ -51,7 +51,7 @@ public class PlayerContainerMixin extends ContainerMixin {
return bukkitEntity; return bukkitEntity;
} }
CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.field_75181_e, this.field_75179_f); CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }

View File

@ -36,7 +36,7 @@ import java.util.Map;
public abstract class RepairContainerMixin extends ContainerMixin { public abstract class RepairContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IWorldPosCallable field_216980_g; @Shadow @Final private IWorldPosCallable worldPosCallable;
@Shadow @Final private IInventory inputSlots; @Shadow @Final private IInventory inputSlots;
@Shadow @Final private IInventory outputSlot; @Shadow @Final private IInventory outputSlot;
@Shadow @Final private PlayerEntity player; @Shadow @Final private PlayerEntity player;
@ -249,7 +249,7 @@ public abstract class RepairContainerMixin extends ContainerMixin {
} }
CraftInventory inventory = new CraftInventoryAnvil( CraftInventory inventory = new CraftInventoryAnvil(
((IWorldPosCallableBridge) this.field_216980_g).bridge$getLocation(), this.inputSlots, this.outputSlot, (RepairContainer) (Object) this); ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation(), this.inputSlots, this.outputSlot, (RepairContainer) (Object) this);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }

View File

@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ShulkerBoxContainer.class) @Mixin(ShulkerBoxContainer.class)
public class ShulkerBoxContainerMixin extends ContainerMixin { public abstract class ShulkerBoxContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final private IInventory inventory; @Shadow @Final private IInventory inventory;

View File

@ -0,0 +1,19 @@
package io.izzel.arclight.common.mixin.core.inventory.container;
import io.izzel.arclight.common.bridge.inventory.container.SlotBridge;
import net.minecraft.inventory.container.Slot;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(Slot.class)
public abstract class SlotMixin implements SlotBridge {
// @formatter:off
@Shadow protected abstract void onSwapCraft(int numItemsCrafted);
// @formatter:on
@Override
public void bridge$onSwapCraft(int numItemsCrafted) {
onSwapCraft(numItemsCrafted);
}
}

View File

@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(StonecutterContainer.class) @Mixin(StonecutterContainer.class)
public class StonecutterContainerMixin extends ContainerMixin { public abstract class StonecutterContainerMixin extends ContainerMixin {
// @formatter:off // @formatter:off
@Shadow @Final public IInventory inputInventory; @Shadow @Final public IInventory inputInventory;

View File

@ -40,9 +40,9 @@ import java.util.Optional;
public abstract class WorkbenchContainerMixin extends ContainerMixin implements WorkbenchContainerBridge { public abstract class WorkbenchContainerMixin extends ContainerMixin implements WorkbenchContainerBridge {
// @formatter:off // @formatter:off
@Mutable @Shadow @Final private CraftingInventory field_75162_e; @Mutable @Shadow @Final private CraftingInventory craftMatrix;
@Shadow @Final private CraftResultInventory field_75160_f; @Shadow @Final private CraftResultInventory craftResult;
@Accessor("field_217070_e") public abstract IWorldPosCallable bridge$getContainerAccess(); @Accessor("worldPosCallable") public abstract IWorldPosCallable bridge$getContainerAccess();
// @formatter:on // @formatter:on
private CraftInventoryView bukkitEntity; private CraftInventoryView bukkitEntity;
@ -55,7 +55,7 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements
private static void a(int p_217066_0_, World p_217066_1_, PlayerEntity p_217066_2_, CraftingInventory p_217066_3_, CraftResultInventory p_217066_4_, Container container) { private static void a(int p_217066_0_, World p_217066_1_, PlayerEntity p_217066_2_, CraftingInventory p_217066_3_, CraftResultInventory p_217066_4_, Container container) {
ArclightCaptures.captureWorkbenchContainer(container); ArclightCaptures.captureWorkbenchContainer(container);
func_217066_a(p_217066_0_, p_217066_1_, p_217066_2_, p_217066_3_, p_217066_4_); updateCraftingResult(p_217066_0_, p_217066_1_, p_217066_2_, p_217066_3_, p_217066_4_);
} }
@Inject(method = "onCraftMatrixChanged", at = @At("HEAD")) @Inject(method = "onCraftMatrixChanged", at = @At("HEAD"))
@ -68,7 +68,7 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements
* @reason * @reason
*/ */
@Overwrite @Overwrite
protected static void func_217066_a(int i, World world, PlayerEntity playerEntity, CraftingInventory inventory, CraftResultInventory resultInventory) { protected static void updateCraftingResult(int i, World world, PlayerEntity playerEntity, CraftingInventory inventory, CraftResultInventory resultInventory) {
Container container = ArclightCaptures.getWorkbenchContainer(); Container container = ArclightCaptures.getWorkbenchContainer();
if (!world.isRemote) { if (!world.isRemote) {
ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) playerEntity; ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) playerEntity;
@ -90,8 +90,8 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements
@Inject(method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) @Inject(method = "<init>(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN"))
public void arclight$init(int i, PlayerInventory playerInventory, IWorldPosCallable callable, CallbackInfo ci) { public void arclight$init(int i, PlayerInventory playerInventory, IWorldPosCallable callable, CallbackInfo ci) {
((CraftingInventoryBridge) this.field_75162_e).bridge$setOwner(playerInventory.player); ((CraftingInventoryBridge) this.craftMatrix).bridge$setOwner(playerInventory.player);
((CraftingInventoryBridge) this.field_75162_e).bridge$setResultInventory(this.field_75160_f); ((CraftingInventoryBridge) this.craftMatrix).bridge$setResultInventory(this.craftResult);
this.player = playerInventory; this.player = playerInventory;
} }
@ -101,7 +101,7 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements
return bukkitEntity; return bukkitEntity;
} }
CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.field_75162_e, this.field_75160_f); CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult);
bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
return bukkitEntity; return bukkitEntity;
} }

View File

@ -49,6 +49,10 @@ public abstract class RecipeManagerMixin implements RecipeManagerBridge {
this.someRecipesErrored = false; this.someRecipesErrored = false;
Map<IRecipeType<?>, Object2ObjectLinkedOpenHashMap<ResourceLocation, IRecipe<?>>> map = Maps.newHashMap(); Map<IRecipeType<?>, Object2ObjectLinkedOpenHashMap<ResourceLocation, IRecipe<?>>> map = Maps.newHashMap();
for (IRecipeType<?> type : Registry.RECIPE_TYPE) {
map.put(type, new Object2ObjectLinkedOpenHashMap<>());
}
for (Map.Entry<ResourceLocation, JsonObject> entry : splashList.entrySet()) { for (Map.Entry<ResourceLocation, JsonObject> entry : splashList.entrySet()) {
ResourceLocation resourcelocation = entry.getKey(); ResourceLocation resourcelocation = entry.getKey();
if (resourcelocation.getPath().startsWith("_")) if (resourcelocation.getPath().startsWith("_"))

View File

@ -24,6 +24,8 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerProfileCache; import net.minecraft.server.management.PlayerProfileCache;
import net.minecraft.util.SharedConstants; import net.minecraft.util.SharedConstants;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.concurrent.RecursiveEventLoop;
import net.minecraft.util.concurrent.TickDelayedTask;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldSettings;
import net.minecraft.world.WorldType; import net.minecraft.world.WorldType;
@ -65,7 +67,7 @@ import java.util.Date;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
@Mixin(MinecraftServer.class) @Mixin(MinecraftServer.class)
public abstract class MinecraftServerMixin implements MinecraftServerBridge, ICommandSourceBridge { public abstract class MinecraftServerMixin extends RecursiveEventLoop<TickDelayedTask> implements MinecraftServerBridge, ICommandSourceBridge {
// @formatter:off // @formatter:off
@Shadow private int tickCounter; @Shadow private int tickCounter;
@ -91,8 +93,13 @@ public abstract class MinecraftServerMixin implements MinecraftServerBridge, ICo
@Shadow private boolean serverStopped; @Shadow private boolean serverStopped;
@Shadow protected abstract void stopServer(); @Shadow protected abstract void stopServer();
@Shadow protected abstract void systemExitNow(); @Shadow protected abstract void systemExitNow();
@Shadow public abstract Commands getCommandManager();
// @formatter:on // @formatter:on
public MinecraftServerMixin(String name) {
super(name);
}
public CraftServer server; public CraftServer server;
public OptionSet options; public OptionSet options;
public ConsoleCommandSender console; public ConsoleCommandSender console;
@ -169,7 +176,7 @@ public abstract class MinecraftServerMixin implements MinecraftServerBridge, ICo
this.serverTime += 50L; this.serverTime += 50L;
if (this.startProfiling) { if (this.startProfiling) {
this.startProfiling = false; this.startProfiling = false;
this.profiler.func_219899_d().func_219939_d(); this.profiler.getFixedProfiler().enable();
} }
this.profiler.startTick(); this.profiler.startTick();
@ -319,9 +326,13 @@ public abstract class MinecraftServerMixin implements MinecraftServerBridge, ICo
processQueue.add(runnable); processQueue.add(runnable);
} }
public CommandSender getBukkitSender(CommandSource wrapper) {
return console;
}
@Override @Override
public CommandSender bridge$getBukkitSender(CommandSource wrapper) { public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return console; return getBukkitSender(wrapper);
} }
private static MinecraftServer getServer() { private static MinecraftServer getServer() {

View File

@ -2,18 +2,23 @@ package io.izzel.arclight.common.mixin.core.server.dedicated;
import io.izzel.arclight.common.mixin.core.server.MinecraftServerMixin; import io.izzel.arclight.common.mixin.core.server.MinecraftServerMixin;
import io.izzel.arclight.common.mod.server.BukkitRegistry; import io.izzel.arclight.common.mod.server.BukkitRegistry;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.network.rcon.RConConsoleSource; import net.minecraft.network.rcon.RConConsoleSource;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.util.text.ITextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.command.CraftRemoteConsoleCommandSender; import org.bukkit.craftbukkit.v.command.CraftRemoteConsoleCommandSender;
import org.bukkit.event.server.RemoteServerCommandEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.plugin.PluginLoadOrder; import org.bukkit.plugin.PluginLoadOrder;
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.Overwrite;
import org.spongepowered.asm.mixin.Shadow; 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.Inject;
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.CallbackInfoReturnable;
@ -24,6 +29,10 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin {
@Shadow @Final public RConConsoleSource rconConsoleSource; @Shadow @Final public RConConsoleSource rconConsoleSource;
// @formatter:on // @formatter:on
public DedicatedServerMixin(String name) {
super(name);
}
@Inject(method = "init", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/dedicated/DedicatedServer;setPlayerList(Lnet/minecraft/server/management/PlayerList;)V")) @Inject(method = "init", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/dedicated/DedicatedServer;setPlayerList(Lnet/minecraft/server/management/PlayerList;)V"))
public void arclight$loadPlugins(CallbackInfoReturnable<Boolean> cir) { public void arclight$loadPlugins(CallbackInfoReturnable<Boolean> cir) {
BukkitRegistry.unlockRegistries(); BukkitRegistry.unlockRegistries();
@ -37,10 +46,37 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin {
this.remoteConsole = new CraftRemoteConsoleCommandSender(this.rconConsoleSource); this.remoteConsole = new CraftRemoteConsoleCommandSender(this.rconConsoleSource);
} }
@Inject(method = "sendMessage", cancellable = true, at = @At("HEAD")) @Redirect(method = "executePendingCommands", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/Commands;handleCommand(Lnet/minecraft/command/CommandSource;Ljava/lang/String;)I"))
public void arclight$consoleLog(ITextComponent message, CallbackInfo ci) { private int arclight$serverCommandEvent(Commands commands, CommandSource source, String command) {
Bukkit.getConsoleSender().sendMessage(message.getFormattedText()); ServerCommandEvent event = new ServerCommandEvent(console, command);
ci.cancel(); Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
return commands.handleCommand(source, event.getCommand());
}
return 0;
}
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public String handleRConCommand(String command) {
this.rconConsoleSource.resetLog();
this.runImmediately(() -> {
RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, command);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
ServerCommandEvent event2 = new ServerCommandEvent(console, event.getCommand());
Bukkit.getPluginManager().callEvent(event2);
if (event2.isCancelled()) {
return;
}
this.getCommandManager().handleCommand(this.rconConsoleSource.getCommandSource(), event2.getCommand());
});
return this.rconConsoleSource.getLogContents();
} }
@Inject(method = "systemExitNow", at = @At("RETURN")) @Inject(method = "systemExitNow", at = @At("RETURN"))

View File

@ -1,12 +1,20 @@
package io.izzel.arclight.common.mixin.core.tileentity; package io.izzel.arclight.common.mixin.core.tileentity;
import com.google.common.base.Joiner;
import io.izzel.arclight.common.bridge.command.CommandSourceBridge;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.tileentity.CommandBlockLogic; import net.minecraft.tileentity.CommandBlockLogic;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.event.server.ServerCommandEvent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(CommandBlockLogic.class) @Mixin(CommandBlockLogic.class)
@ -16,11 +24,43 @@ public class CommandBlockLogicMixin {
@Shadow private ITextComponent customName; @Shadow private ITextComponent customName;
// @formatter:on // @formatter:on
@Inject(method = "setName", cancellable = true, at = @At("HEAD")) @Redirect(method = "trigger", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/Commands;handleCommand(Lnet/minecraft/command/CommandSource;Ljava/lang/String;)I"))
private int arclight$serverCommand(Commands commands, CommandSource sender, String command) {
Joiner joiner = Joiner.on(" ");
if (command.startsWith("/")) {
command = command.substring(1);
}
ServerCommandEvent event = new ServerCommandEvent(((CommandSourceBridge) sender).bridge$getBukkitSender(), command);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return 0;
}
command = event.getCommand();
String[] args = command.split(" ");
String cmd = args[0];
if (cmd.startsWith("minecraft:")) cmd = cmd.substring("minecraft:".length());
if (cmd.startsWith("bukkit:")) cmd = cmd.substring("bukkit:".length());
if (cmd.equalsIgnoreCase("stop") || cmd.equalsIgnoreCase("kick") || cmd.equalsIgnoreCase("op")
|| cmd.equalsIgnoreCase("deop") || cmd.equalsIgnoreCase("ban") || cmd.equalsIgnoreCase("ban-ip")
|| cmd.equalsIgnoreCase("pardon") || cmd.equalsIgnoreCase("pardon-ip") || cmd.equalsIgnoreCase("reload")) {
return 0;
}
if (((CraftServer) Bukkit.getServer()).getCommandBlockOverride(args[0])) {
args[0] = "minecraft:" + args[0];
}
return commands.handleCommand(sender, joiner.join(args));
}
@Inject(method = "setName", at = @At("RETURN"))
public void arclight$setName(ITextComponent nameIn, CallbackInfo ci) { public void arclight$setName(ITextComponent nameIn, CallbackInfo ci) {
if (nameIn == null) { if (this.customName == null) {
this.customName = new StringTextComponent("@"); this.customName = new StringTextComponent("@");
ci.cancel();
} }
} }
} }

View File

@ -13,8 +13,12 @@ public class CommandBlockTileEntity1Mixin implements ICommandSourceBridge {
@Shadow(aliases = {"this$0", "field_145767_a"}, remap = false) private CommandBlockTileEntity outerThis; @Shadow(aliases = {"this$0", "field_145767_a"}, remap = false) private CommandBlockTileEntity outerThis;
@Override public CommandSender getBukkitSender(CommandSource wrapper) {
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return new CraftBlockCommandSender(wrapper, outerThis); return new CraftBlockCommandSender(wrapper, outerThis);
} }
@Override
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return getBukkitSender(wrapper);
}
} }

View File

@ -73,8 +73,12 @@ public abstract class LecternTileEntityMixin extends TileEntityMixin implements
return false; return false;
} }
@Override public CommandSender getBukkitSender(CommandSource wrapper) {
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this); return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this);
} }
@Override
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return getBukkitSender(wrapper);
}
} }

View File

@ -63,8 +63,12 @@ public abstract class SignTileEntityMixin extends TileEntityMixin implements Sig
return false; return false;
} }
@Override public CommandSender getBukkitSender(CommandSource wrapper) {
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this); return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this);
} }
@Override
public CommandSender bridge$getBukkitSender(CommandSource wrapper) {
return getBukkitSender(wrapper);
}
} }

View File

@ -2,20 +2,13 @@ package io.izzel.arclight.common.mixin.core.world.chunk;
import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.WorldBridge;
import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge; import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ITickList;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkPrimer; import net.minecraft.world.chunk.ChunkPrimer;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.UpgradeData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v.CraftChunk;
import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkLoadEvent;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -27,7 +20,6 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.function.Consumer;
@Mixin(Chunk.class) @Mixin(Chunk.class)
public abstract class ChunkMixin implements ChunkBridge { public abstract class ChunkMixin implements ChunkBridge {
@ -136,12 +128,6 @@ public abstract class ChunkMixin implements ChunkBridge {
this.mustNotSave = !unloadEvent.isSaveChunk(); this.mustNotSave = !unloadEvent.isSaveChunk();
} }
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/util/math/ChunkPos;[Lnet/minecraft/world/biome/Biome;Lnet/minecraft/world/chunk/UpgradeData;Lnet/minecraft/world/ITickList;Lnet/minecraft/world/ITickList;J[Lnet/minecraft/world/chunk/ChunkSection;Ljava/util/function/Consumer;)V",
at = @At("RETURN"))
public void arclight$setBukkitChunk(World worldIn, ChunkPos p_i49946_2_, Biome[] p_i49946_3_, UpgradeData p_i49946_4_, ITickList<Block> p_i49946_5_, ITickList<Fluid> p_i49946_6_, long p_i49946_7_, ChunkSection[] p_i49946_9_, Consumer<Chunk> p_i49946_10_, CallbackInfo ci) {
this.bukkitChunk = new CraftChunk((Chunk) (Object) this);
}
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;)V", @Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;)V",
at = @At("RETURN")) at = @At("RETURN"))
public void arclight$setNeedsDecoration(World worldIn, ChunkPrimer p_i49947_2_, CallbackInfo ci) { public void arclight$setNeedsDecoration(World worldIn, ChunkPrimer p_i49947_2_, CallbackInfo ci) {

View File

@ -41,6 +41,7 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri
@Shadow protected abstract void invalidateCaches(); @Shadow protected abstract void invalidateCaches();
@Shadow @Nullable protected abstract ChunkHolder func_217213_a(long chunkPosIn); @Shadow @Nullable protected abstract ChunkHolder func_217213_a(long chunkPosIn);
@Shadow protected abstract boolean func_217235_l(); @Shadow protected abstract boolean func_217235_l();
@Shadow protected abstract boolean func_217224_a(@Nullable ChunkHolder chunkHolderIn, int p_217224_2_);
@Invoker("func_217235_l") public abstract boolean bridge$tickDistanceManager(); @Invoker("func_217235_l") public abstract boolean bridge$tickDistanceManager();
@Accessor("lightManager") public abstract ServerWorldLightManager bridge$getLightManager(); @Accessor("lightManager") public abstract ServerWorldLightManager bridge$getLightManager();
// @formatter:on // @formatter:on
@ -57,12 +58,12 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri
ChunkHolder chunkholder = this.func_217213_a(i); ChunkHolder chunkholder = this.func_217213_a(i);
boolean unloading = false; boolean unloading = false;
if (chunkholder != null) { if (chunkholder != null) {
ChunkHolder.LocationType chunkStatus = ChunkHolder.func_219286_c(((ChunkHolderBridge) chunkholder).bridge$getOldTicketLevel()); ChunkHolder.LocationType chunkStatus = ChunkHolder.getLocationTypeFromLevel(((ChunkHolderBridge) chunkholder).bridge$getOldTicketLevel());
ChunkHolder.LocationType currentStatus = ChunkHolder.func_219286_c(chunkholder.func_219299_i()); ChunkHolder.LocationType currentStatus = ChunkHolder.getLocationTypeFromLevel(chunkholder.getChunkLevel());
unloading = chunkStatus.func_219065_a(ChunkHolder.LocationType.BORDER) && !currentStatus.func_219065_a(ChunkHolder.LocationType.BORDER); unloading = chunkStatus.isAtLeast(ChunkHolder.LocationType.BORDER) && !currentStatus.isAtLeast(ChunkHolder.LocationType.BORDER);
} }
if (load && !unloading) { if (load && !unloading) {
this.ticketManager.func_219356_a(TicketType.UNKNOWN, chunkpos, j, chunkpos); this.ticketManager.registerWithLevel(TicketType.UNKNOWN, chunkpos, j, chunkpos);
if (this.func_217224_a(chunkholder, j)) { if (this.func_217224_a(chunkholder, j)) {
IProfiler iprofiler = this.world.getProfiler(); IProfiler iprofiler = this.world.getProfiler();
iprofiler.startSection("chunkLoad"); iprofiler.startSection("chunkLoad");
@ -78,15 +79,6 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri
return this.func_217224_a(chunkholder, j) ? ChunkHolder.MISSING_CHUNK_FUTURE : chunkholder.func_219276_a(requiredStatus, this.chunkManager); return this.func_217224_a(chunkholder, j) ? ChunkHolder.MISSING_CHUNK_FUTURE : chunkholder.func_219276_a(requiredStatus, this.chunkManager);
} }
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private boolean func_217224_a(@Nullable ChunkHolder chunkHolderIn, int p_217224_2_) {
return chunkHolderIn == null || ((ChunkHolderBridge) chunkHolderIn).bridge$getOldTicketLevel() > p_217224_2_;
}
public void close(boolean save) throws IOException { public void close(boolean save) throws IOException {
if (save) { if (save) {
this.save(true); this.save(true);
@ -115,7 +107,7 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri
this.purgeUnload(); this.purgeUnload();
} }
@Redirect(method = "func_217224_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ChunkHolder;func_219299_i()I")) @Redirect(method = "func_217224_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ChunkHolder;getChunkLevel()I"))
public int arclight$useOldTicketLevel(ChunkHolder chunkHolder) { public int arclight$useOldTicketLevel(ChunkHolder chunkHolder) {
return ((ChunkHolderBridge) chunkHolder).bridge$getOldTicketLevel(); return ((ChunkHolderBridge) chunkHolder).bridge$getOldTicketLevel();
} }

View File

@ -0,0 +1,102 @@
package io.izzel.arclight.common.mixin.v1_15.command.impl;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge;
import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge;
import net.minecraft.command.CommandSource;
import net.minecraft.command.impl.TeleportCommand;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.server.TicketType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import javax.annotation.Nullable;
import java.util.Set;
@Mixin(TeleportCommand.class)
public class TeleportCommandMixin_1_15 {
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private static void teleport(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set<SPlayerPositionLookPacket.Flags> relativeList, float yaw, float pitch, @Nullable TeleportCommand.Facing facing) {
if (entityIn instanceof ServerPlayerEntity) {
ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z));
worldIn.getChunkProvider().registerTicket(TicketType.POST_TELEPORT, chunkpos, 1, entityIn.getEntityId());
entityIn.stopRiding();
if (((ServerPlayerEntity) entityIn).isSleeping()) {
((ServerPlayerEntity) entityIn).stopSleepInBed(true, true);
}
((ServerPlayNetHandlerBridge) ((ServerPlayerEntity) entityIn).connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.COMMAND);
if (worldIn == entityIn.world) {
((ServerPlayerEntity) entityIn).connection.setPlayerLocation(x, y, z, yaw, pitch, relativeList);
} else {
((ServerPlayerEntity) entityIn).teleport(worldIn, x, y, z, yaw, pitch);
}
entityIn.setRotationYawHead(yaw);
} else {
float f1 = MathHelper.wrapDegrees(yaw);
float f = MathHelper.wrapDegrees(pitch);
f = MathHelper.clamp(f, -90.0F, 90.0F);
Location to = new Location(((ServerWorldBridge) worldIn).bridge$getWorld(), x, y, z, f1, f);
EntityTeleportEvent event = new EntityTeleportEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity().getLocation(), to);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
to = event.getTo();
x = to.getX();
y = to.getY();
z = to.getZ();
f1 = to.getYaw();
f = to.getPitch();
worldIn = ((CraftWorld) to.getWorld()).getHandle();
if (worldIn == entityIn.world) {
entityIn.setLocationAndAngles(x, y, z, f1, f);
entityIn.setRotationYawHead(f1);
} else {
entityIn.detach();
entityIn.dimension = worldIn.dimension.getType();
Entity entity = entityIn;
entityIn = entityIn.getType().create(worldIn);
if (entityIn == null) {
return;
}
entityIn.copyDataFromOld(entity);
entityIn.setLocationAndAngles(x, y, z, f1, f);
entityIn.setRotationYawHead(f1);
worldIn.addFromAnotherDimension(entityIn);
entity.removed = true;
}
}
if (facing != null) {
facing.updateLook(source, entityIn);
}
if (!(entityIn instanceof LivingEntity) || !((LivingEntity) entityIn).isElytraFlying()) {
entityIn.setMotion(entityIn.getMotion().mul(1.0D, 0.0D, 1.0D));
entityIn.onGround = true;
}
}
}

View File

@ -0,0 +1,32 @@
package io.izzel.arclight.common.mixin.v1_15.command.impl;
import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge;
import net.minecraft.command.impl.TimeCommand;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.Bukkit;
import org.bukkit.event.world.TimeSkipEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(TimeCommand.class)
public class TimeCommandMixin {
@Redirect(method = "addTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setDayTime(J)V"))
private static void arclight$addTimeEvent(ServerWorld serverWorld, long time) {
TimeSkipEvent event = new TimeSkipEvent(((ServerWorldBridge) serverWorld).bridge$getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - serverWorld.getDayTime());
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
serverWorld.setDayTime(serverWorld.getDayTime() + event.getSkipAmount());
}
}
@Redirect(method = "setTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setDayTime(J)V"))
private static void arclight$setTimeEvent(ServerWorld serverWorld, long time) {
TimeSkipEvent event = new TimeSkipEvent(((ServerWorldBridge) serverWorld).bridge$getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - serverWorld.getDayTime());
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
serverWorld.setDayTime(serverWorld.getDayTime() + event.getSkipAmount());
}
}
}

View File

@ -0,0 +1,52 @@
package io.izzel.arclight.common.mixin.v1_15.enchantment;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.FrostWalkerEnchantment;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.world.World;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.ForgeEventFactory;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(FrostWalkerEnchantment.class)
public class FrostWalkerEnchantmentMixin_1_15 {
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static void freezeNearby(LivingEntity living, World worldIn, BlockPos pos, int level) {
if (living.onGround) {
BlockState blockstate = Blocks.FROSTED_ICE.getDefaultState();
float f = (float) Math.min(16, 2 + level);
BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable();
for (BlockPos blockpos : BlockPos.getAllInBoxMutable(pos.add(-f, -1.0D, -f), pos.add(f, -1.0D, f))) {
if (blockpos.withinDistance(living.getPositionVec(), f)) {
blockpos$mutable.setPos(blockpos.getX(), blockpos.getY() + 1, blockpos.getZ());
BlockState blockstate1 = worldIn.getBlockState(blockpos$mutable);
if (blockstate1.isAir(worldIn, blockpos$mutable)) {
BlockState blockstate2 = worldIn.getBlockState(blockpos);
boolean isFull = blockstate2.getBlock() == Blocks.WATER && blockstate2.get(FlowingFluidBlock.LEVEL) == 0; //TODO: Forge, modded waters?
if (blockstate2.getMaterial() == Material.WATER && isFull && blockstate.isValidPosition(worldIn, blockpos) && worldIn.func_226663_a_(blockstate, blockpos, ISelectionContext.dummy()) && !ForgeEventFactory.onBlockPlace(living, new BlockSnapshot(worldIn, blockpos, blockstate2), Direction.UP)) {
worldIn.setBlockState(blockpos, blockstate);
if (CraftEventFactory.handleBlockFormEvent(worldIn, blockpos, blockstate, living)) {
worldIn.getPendingBlockTicks().scheduleTick(blockpos, Blocks.FROSTED_ICE, MathHelper.nextInt(living.getRNG(), 60, 120));
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,159 @@
package io.izzel.arclight.common.mixin.v1_15.entity;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.InternalEntityBridge;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.ITeleporter;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityPortalEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import javax.annotation.Nullable;
@Mixin(Entity.class)
public abstract class EntityMixin_1_15 {
// @formatter:off
@Shadow public World world;
@Shadow @Deprecated public boolean removed;
@Shadow @Nullable public abstract MinecraftServer getServer();
@Shadow public DimensionType dimension;
@Shadow public abstract void detach();
@Shadow public float rotationYaw;
@Shadow public float rotationPitch;
@Shadow public abstract void setMotion(Vec3d motionIn);
@Shadow public abstract void remove(boolean keepData);
@Shadow public abstract Vec3d getMotion();
@Shadow public abstract double getPosX();
@Shadow public abstract double getPosZ();
@Shadow public abstract Vec3d getLastPortalVec();
@Shadow public abstract double getPosY();
@Shadow public abstract Direction getTeleportDirection();
@Shadow public abstract EntityType<?> getType();
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
@Nullable
public Entity changeDimension(DimensionType destination, ITeleporter teleporter) {
BlockPos location = ((InternalEntityBridge) this).internal$capturedPos();
if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination)) return null;
if (!this.world.isRemote && !this.removed) {
this.world.getProfiler().startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
DimensionType dimensiontype = this.dimension;
ServerWorld serverworld = minecraftserver.getWorld(dimensiontype);
ServerWorld[] serverworld1 = new ServerWorld[]{minecraftserver.getWorld(destination)};
if (serverworld1 == null) {
return null;
}
//this.dimension = destination;
//this.detach();
this.world.getProfiler().startSection("reposition");
Entity transportedEntity = teleporter.placeEntity((Entity) (Object) this, serverworld, serverworld1[0], this.rotationYaw, spawnPortal -> { //Forge: Start vanilla logic
Vec3d vec3d = this.getMotion();
float f = 0.0F;
BlockPos blockpos;
if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint()), 0);
if (event == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
//blockpos = serverworld1[0].getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1[0].getSpawnPoint());
} else if (destination == DimensionType.THE_END) {
EntityPortalEvent event = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], (serverworld1[0].getSpawnCoordinate() != null) ? serverworld1[0].getSpawnCoordinate() : serverworld1[0].getSpawnPoint(), 0);
if (event == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ());
//blockpos = serverworld1[0].getSpawnCoordinate();
} else {
double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1[0].getDimension().getMovementFactor();
double d0 = this.getPosX() * movementFactor;
double d1 = this.getPosZ() * movementFactor;
double d3 = Math.min(-2.9999872E7D, serverworld1[0].getWorldBorder().minX() + 16.0D);
double d4 = Math.min(-2.9999872E7D, serverworld1[0].getWorldBorder().minZ() + 16.0D);
double d5 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxX() - 16.0D);
double d6 = Math.min(2.9999872E7D, serverworld1[0].getWorldBorder().maxZ() - 16.0D);
d0 = MathHelper.clamp(d0, d3, d5);
d1 = MathHelper.clamp(d1, d4, d6);
Vec3d vec3d1 = this.getLastPortalVec();
blockpos = new BlockPos(d0, this.getPosY(), d1);
EntityPortalEvent event2 = CraftEventFactory.callEntityPortalEvent((Entity) (Object) this, serverworld1[0], blockpos, 128);
if (event2 == null) {
return null;
}
serverworld1[0] = ((CraftWorld) event2.getTo().getWorld()).getHandle();
blockpos = new BlockPos(event2.getTo().getX(), event2.getTo().getY(), event2.getTo().getZ());
int searchRadius = event2.getSearchRadius();
// todo 实现 radius
if (spawnPortal) {
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1[0].getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
}
blockpos = new BlockPos(blockpattern$portalinfo.pos);
vec3d = blockpattern$portalinfo.motion;
f = (float) blockpattern$portalinfo.rotation;
}
}
this.dimension = destination;
this.detach();
this.world.getProfiler().endStartSection("reloading");
Entity entity = this.getType().create(serverworld1[0]);
if (entity != null) {
entity.copyDataFromOld((Entity) (Object) this);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
entity.setMotion(vec3d);
serverworld1[0].addFromAnotherDimension(entity);
((InternalEntityBridge) this).internal$getBukkitEntity().setHandle(entity);
((EntityBridge) entity).bridge$setBukkitEntity(((InternalEntityBridge) this).internal$getBukkitEntity());
if ((Object) this instanceof MobEntity) {
((MobEntity) (Object) this).clearLeashed(true, false);
}
}
return entity;
});//Forge: End vanilla logic
this.remove(false);
this.world.getProfiler().endSection();
serverworld.resetUpdateEntityTick();
serverworld1[0].resetUpdateEntityTick();
this.world.getProfiler().endSection();
return transportedEntity;
} else {
return null;
}
}
}

View File

@ -0,0 +1,28 @@
package io.izzel.arclight.common.mixin.v1_15.world.chunk;
import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge;
import net.minecraft.block.Block;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.palette.UpgradeData;
import net.minecraft.world.ITickList;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeContainer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import org.bukkit.craftbukkit.v.CraftChunk;
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.function.Consumer;
@Mixin(Chunk.class)
public abstract class ChunkMixin_1_15 implements ChunkBridge {
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/util/math/ChunkPos;Lnet/minecraft/world/biome/BiomeContainer;Lnet/minecraft/util/palette/UpgradeData;Lnet/minecraft/world/ITickList;Lnet/minecraft/world/ITickList;J[Lnet/minecraft/world/chunk/ChunkSection;Ljava/util/function/Consumer;)V", at = @At("RETURN"))
private void arclight$init(World worldIn, ChunkPos chunkPosIn, BiomeContainer biomeContainerIn, UpgradeData upgradeDataIn, ITickList<Block> tickBlocksIn, ITickList<Fluid> tickFluidsIn, long inhabitedTimeIn, ChunkSection[] sectionsIn, Consumer<Chunk> postLoadConsumerIn, CallbackInfo ci) {
bridge$setBukkitChunk(new CraftChunk((Chunk) (Object) this));
}
}

View File

@ -0,0 +1,28 @@
package io.izzel.arclight.common.mixin.v1_15.world.dimension;
import net.minecraft.world.World;
import net.minecraft.world.biome.IBiomeMagnifier;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.dimension.DimensionType;
import org.spongepowered.asm.mixin.Mixin;
import java.util.function.BiFunction;
@Mixin(DimensionType.class)
public class DimensionTypeMixin_1_15 {
protected void arclight$constructor(int idIn, String suffixIn, String directoryIn, BiFunction<World, DimensionType, ? extends Dimension> p_i49935_4_, boolean p_i49935_5_, IBiomeMagnifier p_i225789_6_) {
throw new RuntimeException();
}
public void arclight$constructor(int idIn, String suffixIn, String directoryIn, BiFunction<World, DimensionType, ? extends Dimension> p_i49935_4_, boolean p_i49935_5_, IBiomeMagnifier p_i225789_6_, DimensionType type) {
arclight$constructor(idIn, suffixIn, directoryIn, p_i49935_4_, p_i49935_5_, p_i225789_6_);
this.type = type;
}
private DimensionType type;
public DimensionType getType() {
return (type == null) ? (DimensionType) (Object) this : type;
}
}

View File

@ -0,0 +1,123 @@
package io.izzel.arclight.common.mixin.v1_15.world.server;
import io.izzel.arclight.common.bridge.world.server.TicketManagerBridge;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.util.SortedArraySet;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.server.Ticket;
import net.minecraft.world.server.TicketManager;
import net.minecraft.world.server.TicketType;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.Iterator;
@Mixin(TicketManager.class)
public abstract class TicketManagerMixin_1_15 implements TicketManagerBridge {
// @formatter:off
@Shadow private long currentTime;
@Shadow @Final private TicketManager.ChunkTicketTracker ticketTracker;
@Shadow protected abstract SortedArraySet<Ticket<?>> getTicketSet(long p_229848_1_);
@Shadow private static int getLevel(SortedArraySet<Ticket<?>> p_229844_0_) { return 0; }
@Shadow @Final public Long2ObjectOpenHashMap<SortedArraySet<Ticket<?>>> tickets;
@Invoker("tick") public abstract void bridge$tick();
// @formatter:on
@SuppressWarnings("unused") // mock
public <T> boolean func_219356_a(TicketType<T> type, ChunkPos pos, int level, T value) {
return addTicketAtLevel(type, pos, level, value);
}
@SuppressWarnings("unused") // mock
public <T> boolean func_219345_b(TicketType<T> type, ChunkPos pos, int level, T value) {
return removeTicketAtLevel(type, pos, level, value);
}
public <T> boolean addTicketAtLevel(TicketType<T> type, ChunkPos pos, int level, T value) {
Ticket<T> ticket = new Ticket<>(type, level, value);
return this.addTicket(pos.asLong(), ticket);
}
public <T> boolean removeTicketAtLevel(TicketType<T> type, ChunkPos pos, int level, T value) {
Ticket<T> ticket = new Ticket<>(type, level, value);
return this.removeTicket(pos.asLong(), ticket);
}
@Override
public <T> boolean bridge$addTicketAtLevel(TicketType<T> type, ChunkPos pos, int level, T value) {
return addTicketAtLevel(type, pos, level, value);
}
@Override
public <T> boolean bridge$removeTicketAtLevel(TicketType<T> type, ChunkPos pos, int level, T value) {
return removeTicketAtLevel(type, pos, level, value);
}
@SuppressWarnings("unused") // mock
private boolean func_219349_b(long chunkPosIn, Ticket<?> ticketIn) {
return removeTicket(chunkPosIn, ticketIn);
}
private boolean removeTicket(long chunkPosIn, Ticket<?> ticketIn) {
SortedArraySet<Ticket<?>> ticketSet = this.getTicketSet(chunkPosIn);
boolean removed = false;
if (ticketSet.remove(ticketIn)) {
removed = true;
}
if (ticketSet.isEmpty()) {
this.tickets.remove(chunkPosIn);
}
this.ticketTracker.updateSourceLevel(chunkPosIn, getLevel(ticketSet), false);
return removed;
}
@Override
public boolean bridge$removeTicket(long chunkPos, Ticket<?> ticket) {
return removeTicket(chunkPos, ticket);
}
@SuppressWarnings("unused") // mock
private boolean func_219347_a(long chunkPosIn, Ticket<?> ticketIn) {
return addTicket(chunkPosIn, ticketIn);
}
private boolean addTicket(long chunkPosIn, Ticket<?> ticketIn) {
SortedArraySet<Ticket<?>> ticketSet = this.getTicketSet(chunkPosIn);
int level = getLevel(ticketSet);
Ticket<?> ticket = ticketSet.func_226175_a_(ticketIn);
ticket.setTimestamp(this.currentTime);
if (ticketIn.getLevel() < level) {
this.ticketTracker.updateSourceLevel(chunkPosIn, ticketIn.getLevel(), true);
}
return ticketIn == ticket;
}
@Override
public boolean bridge$addTicket(long chunkPos, Ticket<?> ticket) {
return addTicket(chunkPos, ticket);
}
public <T> void removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier) {
Ticket<T> target = new Ticket<>(ticketType, ticketLevel, ticketIdentifier);
Iterator<Long2ObjectMap.Entry<SortedArraySet<Ticket<?>>>> iterator = this.tickets.long2ObjectEntrySet().fastIterator();
while (iterator.hasNext()) {
Long2ObjectMap.Entry<SortedArraySet<Ticket<?>>> entry = iterator.next();
SortedArraySet<Ticket<?>> tickets = entry.getValue();
if (tickets.remove(target)) {
this.ticketTracker.updateSourceLevel(entry.getLongKey(), getLevel(tickets), false);
if (tickets.isEmpty()) {
iterator.remove();
}
}
}
}
@Override
public <T> void bridge$removeAllTicketsFor(TicketType<T> ticketType, int ticketLevel, T ticketIdentifier) {
removeAllTicketsFor(ticketType, ticketLevel, ticketIdentifier);
}
}

View File

@ -24,6 +24,12 @@ public net.minecraft.entity.Entity field_70163_u #posY
public net.minecraft.entity.Entity field_70161_v #posZ public net.minecraft.entity.Entity field_70161_v #posZ
public net.minecraft.block.ComposterBlock func_220294_d(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)V #clear public net.minecraft.block.ComposterBlock func_220294_d(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)V #clear
public net.minecraft.tileentity.TileEntity field_145850_b #world public net.minecraft.tileentity.TileEntity field_145850_b #world
public net.minecraft.world.server.Ticket <init>(Lnet/minecraft/world/server/TicketType;ILjava/lang/Object;)V
public net.minecraft.world.server.Ticket func_229861_a_(J)V #setTimestamp
public net.minecraft.world.end.DragonFightManager func_186095_a(Lnet/minecraft/world/end/DragonSpawnState;)V #setRespawnState
public net.minecraft.world.end.DragonFightManager field_186119_m #dragonUniqueId
public net.minecraft.world.end.DragonFightManager field_186121_o #exitPortalLocation
public net.minecraft.world.end.DragonFightManager field_186122_p #respawnState
# 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

View File

@ -8,7 +8,6 @@
"mixins": [ "mixins": [
"BukkitCommandWrapperMixin", "BukkitCommandWrapperMixin",
"ColouredConsoleSenderMixin", "ColouredConsoleSenderMixin",
"CommandNodeMixin",
"CraftBlockStateMixin", "CraftBlockStateMixin",
"CraftChunkMixin", "CraftChunkMixin",
"CraftConsoleCommandSenderMixin", "CraftConsoleCommandSenderMixin",

View File

@ -45,7 +45,13 @@
"block.TurtleEggBlockMixin_1_15", "block.TurtleEggBlockMixin_1_15",
"block.VineBlockMixin_1_15", "block.VineBlockMixin_1_15",
"block.WitherRoseBlockMixin", "block.WitherRoseBlockMixin",
"io.izzel.arclight.impl.mixin.v1_14.block.FarmlandBlockMixin_1_14", "command.impl.TeleportCommandMixin_1_15",
"world.biome.BiomeContainerMixin" "command.impl.TimeCommandMixin",
"enchantment.FrostWalkerEnchantmentMixin_1_15",
"entity.EntityMixin_1_15",
"world.biome.BiomeContainerMixin",
"world.chunk.ChunkMixin_1_15",
"world.dimension.DimensionTypeMixin_1_15",
"world.server.TicketManagerMixin_1_15"
] ]
} }

View File

@ -60,20 +60,17 @@
"block.RedstoneTorchBlockMixin", "block.RedstoneTorchBlockMixin",
"block.RedstoneWireBlockMixin", "block.RedstoneWireBlockMixin",
"block.SaplingBlockMixin", "block.SaplingBlockMixin",
"block.ScaffoldingBlockMixin",
"block.SilverfishBlockMixin", "block.SilverfishBlockMixin",
"block.SnowBlockMixin",
"block.SpongeBlockMixin", "block.SpongeBlockMixin",
"block.StemBlockMixin",
"block.SweetBerryBushBlockMixin",
"block.TNTBlockMixin", "block.TNTBlockMixin",
"block.TrapDoorBlockMixin", "block.TrapDoorBlockMixin",
"block.TripWireBlockMixin", "block.TripWireBlockMixin",
"block.TripWireHookBlockMixin", "block.TripWireHookBlockMixin",
"block.TurtleEggBlockMixin", "block.TurtleEggBlockMixin",
"block.VineBlockMixin",
"block.WeightedPressurePlateBlockMixin", "block.WeightedPressurePlateBlockMixin",
"block.WitherSkeletonSkullBlockMixin", "block.WitherSkeletonSkullBlockMixin",
"command.CommandNodeMixin",
"command.CommandsMixin",
"command.CommandSourceMixin", "command.CommandSourceMixin",
"command.ICommandSourceMixin", "command.ICommandSourceMixin",
"command.arguments.BlockStateParserMixin", "command.arguments.BlockStateParserMixin",
@ -247,6 +244,7 @@
"inventory.container.PlayerContainerMixin", "inventory.container.PlayerContainerMixin",
"inventory.container.RepairContainerMixin", "inventory.container.RepairContainerMixin",
"inventory.container.ShulkerBoxContainerMixin", "inventory.container.ShulkerBoxContainerMixin",
"inventory.container.SlotMixin",
"inventory.container.StonecutterContainerMixin", "inventory.container.StonecutterContainerMixin",
"inventory.container.WorkbenchContainerMixin", "inventory.container.WorkbenchContainerMixin",
"item.ArmorStandItemMixin", "item.ArmorStandItemMixin",
@ -357,7 +355,6 @@
"world.server.ServerChunkProvider_ChunkExecutorMixin", "world.server.ServerChunkProvider_ChunkExecutorMixin",
"world.server.ServerChunkProviderMixin", "world.server.ServerChunkProviderMixin",
"world.server.ServerWorldMixin", "world.server.ServerWorldMixin",
"world.server.TicketManagerMixin",
"world.server.TicketTypeMixin", "world.server.TicketTypeMixin",
"world.spawner.AbstractSpawnerMixin", "world.spawner.AbstractSpawnerMixin",
"world.spawner.PatrolSpawnerMixin", "world.spawner.PatrolSpawnerMixin",

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.command.impl; package io.izzel.arclight.impl.mixin.v1_14.command.impl;
import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge;
@ -26,7 +26,7 @@ import javax.annotation.Nullable;
import java.util.Set; import java.util.Set;
@Mixin(TeleportCommand.class) @Mixin(TeleportCommand.class)
public class TeleportCommandMixin { public class TeleportCommandMixin_1_14 {
/** /**
* @author IzzelAliz * @author IzzelAliz
@ -85,6 +85,7 @@ public class TeleportCommandMixin {
entityIn.setLocationAndAngles(x, y, z, f1, f); entityIn.setLocationAndAngles(x, y, z, f1, f);
entityIn.setRotationYawHead(f1); entityIn.setRotationYawHead(f1);
worldIn.func_217460_e(entityIn); worldIn.func_217460_e(entityIn);
entity.removed = true;
} }
} }

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.enchantment; package io.izzel.arclight.impl.mixin.v1_14.enchantment;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
@Mixin(FrostWalkerEnchantment.class) @Mixin(FrostWalkerEnchantment.class)
public class FrostWalkerEnchantmentMixin { public class FrostWalkerEnchantmentMixin_1_14 {
/** /**
* @author IzzelAliz * @author IzzelAliz

View File

@ -0,0 +1,146 @@
package io.izzel.arclight.impl.mixin.v1_14.entity;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.entity.InternalEntityBridge;
import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.ForgeHooks;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.event.entity.EntityPortalEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import javax.annotation.Nullable;
@Mixin(Entity.class)
public abstract class EntityMixin_1_14 {
// @formatter:off
@Shadow public World world;
@Shadow @Deprecated public boolean removed;
@Shadow public DimensionType dimension;
@Shadow public double posX;
@Shadow public double posZ;
@Shadow public double posY;
@Shadow @Nullable public abstract MinecraftServer getServer();
@Shadow public abstract Vec3d getMotion();
@Shadow public abstract Vec3d getLastPortalVec();
@Shadow public abstract boolean isAlive();
@Shadow public abstract Direction getTeleportDirection();
@Shadow public abstract void detach();
@Shadow public abstract EntityType<?> getType();
@Shadow public abstract void remove(boolean keepData);
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
@Nullable
public Entity changeDimension(DimensionType destination) {
BlockPos location = ((InternalEntityBridge) this).internal$capturedPos();
if (!ForgeHooks.onTravelToDimension((Entity) (Object) this, destination)) return null;
if (!this.world.isRemote && !this.removed) {
this.world.getProfiler().startSection("changeDimension");
MinecraftServer minecraftserver = this.getServer();
DimensionType dimensiontype = this.dimension;
ServerWorld serverworld = minecraftserver.func_71218_a(dimensiontype);
ServerWorld serverworld1 = minecraftserver.func_71218_a(destination);
if (serverworld1 == null) {
return null;
}
// this.dimension = destination;
// this.detach();
this.world.getProfiler().startSection("reposition");
Vec3d vec3d = this.getMotion();
float f = 0.0F;
BlockPos blockpos = location;
if (blockpos == null) {
if (dimensiontype == DimensionType.THE_END && destination == DimensionType.OVERWORLD) {
blockpos = serverworld1.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, serverworld1.getSpawnPoint());
} else if (destination == DimensionType.THE_END) {
blockpos = serverworld1.getSpawnCoordinate();
} else {
double movementFactor = serverworld.getDimension().getMovementFactor() / serverworld1.getDimension().getMovementFactor();
double d0 = this.posX * movementFactor;
double d1 = this.posZ * movementFactor;
double d3 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minX() + 16.0D);
double d4 = Math.min(-2.9999872E7D, serverworld1.getWorldBorder().minZ() + 16.0D);
double d5 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxX() - 16.0D);
double d6 = Math.min(2.9999872E7D, serverworld1.getWorldBorder().maxZ() - 16.0D);
d0 = MathHelper.clamp(d0, d3, d5);
d1 = MathHelper.clamp(d1, d4, d6);
Vec3d vec3d1 = this.getLastPortalVec();
blockpos = new BlockPos(d0, this.posY, d1);
BlockPattern.PortalInfo blockpattern$portalinfo = serverworld1.getDefaultTeleporter().placeInExistingPortal(blockpos, vec3d, this.getTeleportDirection(), vec3d1.x, vec3d1.y, (Object) this instanceof PlayerEntity);
if (blockpattern$portalinfo == null) {
return null;
}
blockpos = new BlockPos(blockpattern$portalinfo.pos);
vec3d = blockpattern$portalinfo.motion;
f = (float) blockpattern$portalinfo.rotation;
}
}
if (location == null) {
Location enter = ((InternalEntityBridge) this).internal$getBukkitEntity().getLocation();
Location exit = new Location(((ServerWorldBridge) serverworld1).bridge$getWorld(), blockpos.getX(), blockpos.getY(), blockpos.getZ());
EntityPortalEvent event = new EntityPortalEvent(((InternalEntityBridge) this).internal$getBukkitEntity(), enter, exit);
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !this.isAlive()) {
return null;
}
exit = event.getTo();
serverworld1 = ((CraftWorld) exit.getWorld()).getHandle();
blockpos = new BlockPos(exit.getX(), exit.getY(), exit.getZ());
}
this.dimension = destination;
this.detach();
this.world.getProfiler().endStartSection("reloading");
Entity entity = this.getType().create(serverworld1);
if (entity != null) {
entity.copyDataFromOld((Entity) (Object) this);
entity.moveToBlockPosAndAngles(blockpos, entity.rotationYaw + f, entity.rotationPitch);
entity.setMotion(vec3d);
serverworld1.func_217460_e(entity);
((InternalEntityBridge) this).internal$getBukkitEntity().setHandle(entity);
((EntityBridge) entity).bridge$setBukkitEntity(((InternalEntityBridge) this).internal$getBukkitEntity());
if ((Object) this instanceof MobEntity) {
((MobEntity) (Object) this).clearLeashed(true, false);
}
}
this.remove(false);
this.world.getProfiler().endSection();
serverworld.resetUpdateEntityTick();
serverworld1.resetUpdateEntityTick();
this.world.getProfiler().endSection();
return entity;
} else {
return null;
}
}
}

View File

@ -0,0 +1,29 @@
package io.izzel.arclight.impl.mixin.v1_14.world.chunk;
import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge;
import net.minecraft.block.Block;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ITickList;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.UpgradeData;
import org.bukkit.craftbukkit.v.CraftChunk;
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.function.Consumer;
@Mixin(Chunk.class)
public abstract class ChunkMixin_1_14 implements ChunkBridge {
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/util/math/ChunkPos;[Lnet/minecraft/world/biome/Biome;Lnet/minecraft/world/chunk/UpgradeData;Lnet/minecraft/world/ITickList;Lnet/minecraft/world/ITickList;J[Lnet/minecraft/world/chunk/ChunkSection;Ljava/util/function/Consumer;)V",
at = @At("RETURN"))
private void arclight$init(World worldIn, ChunkPos p_i49946_2_, Biome[] p_i49946_3_, UpgradeData p_i49946_4_, ITickList<Block> p_i49946_5_, ITickList<Fluid> p_i49946_6_, long p_i49946_7_, ChunkSection[] p_i49946_9_, Consumer<Chunk> p_i49946_10_, CallbackInfo ci) {
bridge$setBukkitChunk(new CraftChunk((Chunk) (Object) this));
}
}

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.world.dimension; package io.izzel.arclight.impl.mixin.v1_14.world.dimension;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.dimension.Dimension; import net.minecraft.world.dimension.Dimension;
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.Mixin;
import java.util.function.BiFunction; import java.util.function.BiFunction;
@Mixin(DimensionType.class) @Mixin(DimensionType.class)
public class DimensionTypeMixin { public class DimensionTypeMixin_1_14 {
protected void arclight$constructor(int idIn, String suffixIn, String directoryIn, BiFunction<World, DimensionType, ? extends Dimension> p_i49935_4_, boolean p_i49935_5_) { protected void arclight$constructor(int idIn, String suffixIn, String directoryIn, BiFunction<World, DimensionType, ? extends Dimension> p_i49935_4_, boolean p_i49935_5_) {
throw new RuntimeException(); throw new RuntimeException();

View File

@ -1,4 +1,4 @@
package io.izzel.arclight.common.mixin.core.world.server; package io.izzel.arclight.impl.mixin.v1_14.world.server;
import io.izzel.arclight.common.bridge.world.server.TicketManagerBridge; import io.izzel.arclight.common.bridge.world.server.TicketManagerBridge;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@ -12,22 +12,20 @@ import net.minecraft.world.server.TicketType;
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.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.Iterator; import java.util.Iterator;
@Mixin(TicketManager.class) @Mixin(TicketManager.class)
public abstract class TicketManagerMixin implements TicketManagerBridge { public abstract class TicketManagerMixin_1_14 implements TicketManagerBridge {
// @formatter:off // @formatter:off
@Shadow @Final private Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> tickets; @Shadow @Final public Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> tickets;
@Shadow private long currentTime; @Shadow private long currentTime;
@Shadow protected abstract ObjectSortedSet<Ticket<?>> getTickets(long chunkPosIn); @Shadow protected abstract ObjectSortedSet<Ticket<?>> getTickets(long chunkPosIn);
@Shadow @Final private TicketManager.ChunkTicketTracker ticketTracker; @Shadow @Final private TicketManager.ChunkTicketTracker ticketTracker;
@Shadow protected abstract int getChunkLevel(ObjectSortedSet<Ticket<?>> ticketsIn); @Shadow protected abstract int getChunkLevel(ObjectSortedSet<Ticket<?>> ticketsIn);
@Invoker("tick") public abstract void bridge$tick(); @Invoker("tick") public abstract void bridge$tick();
@Accessor("tickets") public abstract Long2ObjectOpenHashMap<ObjectSortedSet<Ticket<?>>> bridge$getTickets();
// @formatter:on // @formatter:on
@SuppressWarnings("unused") // mock @SuppressWarnings("unused") // mock

View File

@ -44,6 +44,12 @@
"block.SugarCaneBlockMixin_1_14", "block.SugarCaneBlockMixin_1_14",
"block.SweetBerryBushBlockMixin_1_14", "block.SweetBerryBushBlockMixin_1_14",
"block.TurtleEggBlockMixin_1_14", "block.TurtleEggBlockMixin_1_14",
"block.VineBlockMixin_1_14" "block.VineBlockMixin_1_14",
"command.impl.TeleportCommandMixin_1_14",
"enchantment.FrostWalkerEnchantmentMixin_1_14",
"entity.EntityMixin_1_14",
"world.chunk.ChunkMixin_1_14",
"world.dimension.DimensionTypeMixin_1_14",
"world.server.TicketManagerMixin_1_14"
] ]
} }