parent
fcc143a24f
commit
f9499a729a
|
@ -8,6 +8,7 @@ import org.bukkit.craftbukkit.v.entity.CraftHumanEntity;
|
||||||
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
|
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
|
||||||
import org.bukkit.event.entity.EntityTargetEvent;
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
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;
|
||||||
|
@ -24,7 +25,7 @@ public abstract class TemptGoalMixin {
|
||||||
@Shadow @Final protected CreatureEntity creature;
|
@Shadow @Final protected CreatureEntity creature;
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
@Inject(method = "shouldExecute", cancellable = true, at = @At(value = "INVOKE_ASSIGN", ordinal = 0, target = "Lnet/minecraft/world/World;getClosestPlayer(Lnet/minecraft/entity/EntityPredicate;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/entity/player/PlayerEntity;"))
|
@Inject(method = "shouldExecute", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/entity/ai/goal/TemptGoal;closestPlayer:Lnet/minecraft/entity/player/PlayerEntity;"))
|
||||||
public void arclight$tempt(CallbackInfoReturnable<Boolean> cir) {
|
public void arclight$tempt(CallbackInfoReturnable<Boolean> cir) {
|
||||||
boolean tempt = this.closestPlayer != null && (this.isTempting(this.closestPlayer.getHeldItemMainhand()) || this.isTempting(this.closestPlayer.getHeldItemOffhand()));
|
boolean tempt = this.closestPlayer != null && (this.isTempting(this.closestPlayer.getHeldItemMainhand()) || this.isTempting(this.closestPlayer.getHeldItemOffhand()));
|
||||||
if (tempt) {
|
if (tempt) {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.izzel.arclight.common.mixin.core.entity.player;
|
package io.izzel.arclight.common.mixin.core.entity.player;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.mojang.datafixers.util.Either;
|
import com.mojang.datafixers.util.Either;
|
||||||
import io.izzel.arclight.common.bridge.block.PortalInfoBridge;
|
import io.izzel.arclight.common.bridge.block.PortalInfoBridge;
|
||||||
import io.izzel.arclight.common.bridge.entity.EntityBridge;
|
import io.izzel.arclight.common.bridge.entity.EntityBridge;
|
||||||
|
@ -320,13 +319,16 @@ public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implemen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator();
|
boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator();
|
||||||
List<ItemEntity> loot = new ArrayList<>();
|
|
||||||
this.captureDrops(new ArrayList<>());
|
|
||||||
this.spawnDrops(damagesource);
|
this.spawnDrops(damagesource);
|
||||||
|
|
||||||
ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage();
|
ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage();
|
||||||
String deathmessage = defaultMessage.getString();
|
String deathmessage = defaultMessage.getString();
|
||||||
PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, Lists.transform(loot, (ItemEntity entity) -> CraftItemStack.asCraftMirror(entity.getItem())), deathmessage, keepInventory);
|
List<org.bukkit.inventory.ItemStack> loot = new ArrayList<>();
|
||||||
|
for (ItemEntity entity : this.captureDrops(null)) {
|
||||||
|
CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem());
|
||||||
|
loot.add(craftItemStack);
|
||||||
|
}
|
||||||
|
PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, loot, deathmessage, keepInventory);
|
||||||
if (this.openContainer != this.container) {
|
if (this.openContainer != this.container) {
|
||||||
this.closeScreen();
|
this.closeScreen();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package io.izzel.arclight.common.mixin.core.loot;
|
package io.izzel.arclight.common.mixin.core.loot;
|
||||||
|
|
||||||
import io.izzel.arclight.common.mod.ArclightConstants;
|
|
||||||
import net.minecraft.loot.LootParameter;
|
import net.minecraft.loot.LootParameter;
|
||||||
import net.minecraft.loot.LootParameters;
|
import net.minecraft.loot.LootParameters;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
|
||||||
@Mixin(LootParameters.class)
|
@Mixin(LootParameters.class)
|
||||||
public class LootParametersMixin {
|
public class LootParametersMixin {
|
||||||
|
|
||||||
private static final LootParameter<Integer> LOOTING_MOD = ArclightConstants.LOOTING_MOD;
|
private static final LootParameter<Integer> LOOTING_MOD = new LootParameter<>(new ResourceLocation("bukkit:looting_mod"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.util.IProgressUpdate;
|
import net.minecraft.util.IProgressUpdate;
|
||||||
import net.minecraft.util.RegistryKey;
|
import net.minecraft.util.RegistryKey;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.DimensionType;
|
import net.minecraft.world.DimensionType;
|
||||||
import net.minecraft.world.Explosion;
|
import net.minecraft.world.Explosion;
|
||||||
|
@ -383,6 +384,10 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileEntity fixTileEntity(BlockPos pos, BlockState state, Block type, TileEntity found) {
|
private TileEntity fixTileEntity(BlockPos pos, BlockState state, Block type, TileEntity found) {
|
||||||
|
ResourceLocation registryName = found.getType().getRegistryName();
|
||||||
|
if (registryName == null || !registryName.getNamespace().equals("minecraft")) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
this.getServer().getLogger().log(Level.SEVERE, "Block at {0}, {1}, {2} is {3} but has {4}" + ". "
|
this.getServer().getLogger().log(Level.SEVERE, "Block at {0}, {1}, {2} is {3} but has {4}" + ". "
|
||||||
+ "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.", new Object[]{pos.getX(), pos.getY(), pos.getZ(), type, found});
|
+ "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.", new Object[]{pos.getX(), pos.getY(), pos.getZ(), type, found});
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,16 @@ package io.izzel.arclight.common.mod;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import io.izzel.arclight.api.EnumHelper;
|
import io.izzel.arclight.api.EnumHelper;
|
||||||
|
import io.izzel.arclight.api.Unsafe;
|
||||||
import net.minecraft.loot.LootParameter;
|
import net.minecraft.loot.LootParameter;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.loot.LootParameters;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
|
|
||||||
public class ArclightConstants {
|
public class ArclightConstants {
|
||||||
|
|
||||||
public static final TreeType MOD = EnumHelper.addEnum(TreeType.class, "MOD", ImmutableList.of(), ImmutableList.of());
|
public static final TreeType MOD = EnumHelper.addEnum(TreeType.class, "MOD", ImmutableList.of(), ImmutableList.of());
|
||||||
|
|
||||||
public static final LootParameter<Integer> LOOTING_MOD = new LootParameter<>(new ResourceLocation("bukkit:looting_mod"));
|
public static final LootParameter<Integer> LOOTING_MOD = Unsafe.getStatic(LootParameters.class, "LOOTING_MOD");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arclight marker magic value for non-used custom dimension
|
* Arclight marker magic value for non-used custom dimension
|
||||||
|
|
|
@ -54,13 +54,13 @@ public class BukkitRegistry {
|
||||||
private static final List<Class<?>> MAT_CTOR = ImmutableList.of(int.class);
|
private static final List<Class<?>> MAT_CTOR = ImmutableList.of(int.class);
|
||||||
private static final List<Class<?>> ENTITY_CTOR = ImmutableList.of(String.class, Class.class, int.class);
|
private static final List<Class<?>> ENTITY_CTOR = ImmutableList.of(String.class, Class.class, int.class);
|
||||||
private static final List<Class<?>> ENV_CTOR = ImmutableList.of(int.class);
|
private static final List<Class<?>> ENV_CTOR = ImmutableList.of(int.class);
|
||||||
private static final Map<String, Material> BY_NAME = getStatic(Material.class, "BY_NAME");
|
private static final Map<String, Material> BY_NAME = Unsafe.getStatic(Material.class, "BY_NAME");
|
||||||
private static final Map<Block, Material> BLOCK_MATERIAL = getStatic(CraftMagicNumbers.class, "BLOCK_MATERIAL");
|
private static final Map<Block, Material> BLOCK_MATERIAL = Unsafe.getStatic(CraftMagicNumbers.class, "BLOCK_MATERIAL");
|
||||||
private static final Map<Item, Material> ITEM_MATERIAL = getStatic(CraftMagicNumbers.class, "ITEM_MATERIAL");
|
private static final Map<Item, Material> ITEM_MATERIAL = Unsafe.getStatic(CraftMagicNumbers.class, "ITEM_MATERIAL");
|
||||||
private static final Map<Material, Item> MATERIAL_ITEM = getStatic(CraftMagicNumbers.class, "MATERIAL_ITEM");
|
private static final Map<Material, Item> MATERIAL_ITEM = Unsafe.getStatic(CraftMagicNumbers.class, "MATERIAL_ITEM");
|
||||||
private static final Map<Material, Block> MATERIAL_BLOCK = getStatic(CraftMagicNumbers.class, "MATERIAL_BLOCK");
|
private static final Map<Material, Block> MATERIAL_BLOCK = Unsafe.getStatic(CraftMagicNumbers.class, "MATERIAL_BLOCK");
|
||||||
private static final Map<String, EntityType> ENTITY_NAME_MAP = getStatic(EntityType.class, "NAME_MAP");
|
private static final Map<String, EntityType> ENTITY_NAME_MAP = Unsafe.getStatic(EntityType.class, "NAME_MAP");
|
||||||
private static final Map<Integer, World.Environment> ENVIRONMENT_MAP = getStatic(World.Environment.class, "lookup");
|
private static final Map<Integer, World.Environment> ENVIRONMENT_MAP = Unsafe.getStatic(World.Environment.class, "lookup");
|
||||||
static final BiMap<RegistryKey<DimensionType>, World.Environment> DIM_MAP =
|
static final BiMap<RegistryKey<DimensionType>, World.Environment> DIM_MAP =
|
||||||
HashBiMap.create(ImmutableMap.<RegistryKey<DimensionType>, World.Environment>builder()
|
HashBiMap.create(ImmutableMap.<RegistryKey<DimensionType>, World.Environment>builder()
|
||||||
.put(DimensionType.OVERWORLD, World.Environment.NORMAL)
|
.put(DimensionType.OVERWORLD, World.Environment.NORMAL)
|
||||||
|
@ -264,18 +264,6 @@ public class BukkitRegistry {
|
||||||
return ArclightConfig.spec().getCompat().getEntity(location.toString()).orElse(EntityPropertySpec.EMPTY);
|
return ArclightConfig.spec().getCompat().getEntity(location.toString()).orElse(EntityPropertySpec.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> T getStatic(Class<?> cl, String name) {
|
|
||||||
try {
|
|
||||||
Unsafe.ensureClassInitialized(cl);
|
|
||||||
Field field = cl.getDeclaredField(name);
|
|
||||||
Object materialByNameBase = Unsafe.staticFieldBase(field);
|
|
||||||
long materialByNameOffset = Unsafe.staticFieldOffset(field);
|
|
||||||
return (T) Unsafe.getObject(materialByNameBase, materialByNameOffset);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void putStatic(Class<?> cl, String name, Object o) {
|
private static void putStatic(Class<?> cl, String name, Object o) {
|
||||||
try {
|
try {
|
||||||
Unsafe.ensureClassInitialized(cl);
|
Unsafe.ensureClassInitialized(cl);
|
||||||
|
|
|
@ -23,6 +23,8 @@ public class EntityEventDispatcher {
|
||||||
@SubscribeEvent(receiveCanceled = true)
|
@SubscribeEvent(receiveCanceled = true)
|
||||||
public void onLivingDeath(LivingDropsEvent event) {
|
public void onLivingDeath(LivingDropsEvent event) {
|
||||||
if (event.getEntityLiving() instanceof ServerPlayerEntity) {
|
if (event.getEntityLiving() instanceof ServerPlayerEntity) {
|
||||||
|
// recapture for ServerPlayerEntityMixin#onDeath
|
||||||
|
event.getEntityLiving().captureDrops(event.getDrops());
|
||||||
// handled at ServerPlayerEntityMixin
|
// handled at ServerPlayerEntityMixin
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user