diff --git a/README.md b/README.md index e92e36c5..0d2cfa2a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ A Bukkit server implementation utilizing Mixin. | Minecraft | Forge | Status | Build | | :----: | :----: | :---: | :---: | +| 1.17.x | 37.0.1 | ACTIVE | - | | 1.16.x | 36.2.0 | ACTIVE | [![1.16 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-16?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-16) | | 1.15.x | 31.2.48 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.15/1.0.19) | [![1.15 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-15?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-15) | | 1.14.x | 28.2.0 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.0.6) | [![1.14 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight) | diff --git a/arclight-common/build.gradle b/arclight-common/build.gradle index 554afab7..2839d422 100644 --- a/arclight-common/build.gradle +++ b/arclight-common/build.gradle @@ -1,6 +1,6 @@ buildscript { repositories { - maven { url = 'https://files.minecraftforge.net/maven' } + maven { url = 'https://maven.minecraftforge.net' } maven { url = 'https://repo.spongepowered.org/maven' } mavenCentral() maven { url = 'https://maven.izzel.io/releases' } @@ -21,17 +21,17 @@ apply plugin: 'io.izzel.arclight' arclight { mcVersion = minecraftVersion forgeVersion = project.ext.forgeVersion - bukkitVersion = 'v1_16_R3' + bukkitVersion = 'v1_17_R1' wipeVersion = true reobfVersion = false accessTransformer = project.file('bukkit.at') - packageName = 'spigot' + // packageName = 'spigot' } -sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' +// sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '11' minecraft { - mappings channel: 'snapshot', version: "20210215-1.16.3" + mappings channel: 'official', version: minecraftVersion accessTransformer = project.file('src/main/resources/META-INF/accesstransformer.cfg') } @@ -48,13 +48,13 @@ dependencies { minecraft "net.minecraftforge:forge:$minecraftVersion-$forgeVersion" implementation "org.spigotmc:spigot-api:$minecraftVersion-R0.1-SNAPSHOT@jar" implementation 'org.jetbrains:annotations:19.0.0' - + implementation 'org.spongepowered:mixin:0.8.2' annotationProcessor 'org.spongepowered:mixin:0.8.2:processor' - + implementation 'com.github.ArclightTeam:mixin-tools:1.0.0' annotationProcessor 'com.github.ArclightTeam:mixin-tools:1.0.0' - + implementation 'jline:jline:2.12.1' implementation 'net.md-5:SpecialSource:1.9.0' implementation 'org.apache.logging.log4j:log4j-jul:2.11.2' @@ -71,12 +71,6 @@ remapSpigotJar { includes.add('net/minecraft/tileentity/LecternTileEntity$LecternInventory') } -processMapping { - process { csrg, srg -> - csrg.classes.put('net/minecraft/world/level/ColorResolver', "net/minecraft/server/$bukkitVersion/ColorResolver".toString()) - } -} - generateArclightMeta { doFirst { throw new StopExecutionException() diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/BlockBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/BlockBridge.java index b0fa550d..4a2aaaa7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/BlockBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/BlockBridge.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.bridge.block; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; public interface BlockBridge { - int bridge$getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack); + int bridge$getExpDrop(BlockState blockState, ServerLevel world, BlockPos blockPos, ItemStack itemStack); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/FireBlockBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/FireBlockBridge.java index ab8f1558..5c2a5124 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/FireBlockBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/FireBlockBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.block; -import net.minecraft.block.Block; +import net.minecraft.world.level.block.Block; public interface FireBlockBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/NoteBlockBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/NoteBlockBridge.java index 5c22583f..a65c9343 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/NoteBlockBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/NoteBlockBridge.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.bridge.block; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; public interface NoteBlockBridge { - void bridge$play(World worldIn, BlockPos pos, BlockState state); + void bridge$play(Level worldIn, BlockPos pos, BlockState state); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/PortalInfoBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/PortalInfoBridge.java index 2a082d3f..b3a5db10 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/PortalInfoBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/block/PortalInfoBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.block; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; import org.bukkit.craftbukkit.v.event.CraftPortalEvent; import org.jetbrains.annotations.Nullable; @@ -10,7 +10,7 @@ public interface PortalInfoBridge { CraftPortalEvent bridge$getPortalEventInfo(); - void bridge$setWorld(ServerWorld world); + void bridge$setWorld(ServerLevel world); - @Nullable ServerWorld bridge$getWorld(); + @Nullable ServerLevel bridge$getWorld(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftItemStackBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftItemStackBridge.java index 52d290aa..684d398b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftItemStackBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftItemStackBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.bukkit; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; public interface CraftItemStackBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftServerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftServerBridge.java index f2bbf4c7..c7abf321 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftServerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/CraftServerBridge.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.bridge.bukkit; -import net.minecraft.server.management.PlayerList; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.players.PlayerList; public interface CraftServerBridge { void bridge$setPlayerList(PlayerList playerList); - void bridge$removeWorld(ServerWorld world); + void bridge$removeWorld(ServerLevel world); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/EntityTypeBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/EntityTypeBridge.java index 28ed3a46..ce42a5ae 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/EntityTypeBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/EntityTypeBridge.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.bridge.bukkit; import io.izzel.arclight.i18n.conf.EntityPropertySpec; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.util.ResourceLocation; import org.bukkit.Location; import java.util.function.Function; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; public interface EntityTypeBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/ItemMetaBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/ItemMetaBridge.java index bc2a9129..b0675f26 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/ItemMetaBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/ItemMetaBridge.java @@ -1,19 +1,18 @@ package io.izzel.arclight.common.bridge.bukkit; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; - import java.util.Map; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; public interface ItemMetaBridge { - CompoundNBT bridge$getForgeCaps(); + CompoundTag bridge$getForgeCaps(); - void bridge$setForgeCaps(CompoundNBT nbt); + void bridge$setForgeCaps(CompoundTag nbt); - void bridge$offerUnhandledTags(CompoundNBT nbt); + void bridge$offerUnhandledTags(CompoundTag nbt); - Map bridge$getUnhandledTags(); + Map bridge$getUnhandledTags(); - void bridge$setUnhandledTags(Map tags); + void bridge$setUnhandledTags(Map tags); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/MaterialBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/MaterialBridge.java index a1c6b1ef..c51a30a2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/MaterialBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/bukkit/MaterialBridge.java @@ -1,15 +1,15 @@ package io.izzel.arclight.common.bridge.bukkit; import io.izzel.arclight.i18n.conf.MaterialPropertySpec; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.inventory.CraftMetaItem; import org.bukkit.inventory.meta.ItemMeta; import javax.annotation.Nullable; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import java.util.function.Function; public interface MaterialBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/ICommandSourceBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/ICommandSourceBridge.java index f2be5bb3..44027520 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/ICommandSourceBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/ICommandSourceBridge.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.bridge.command; -import net.minecraft.command.CommandSource; +import net.minecraft.commands.CommandSourceStack; import org.bukkit.command.CommandSender; public interface ICommandSourceBridge { - CommandSender bridge$getBukkitSender(CommandSource wrapper); + CommandSender bridge$getBukkitSender(CommandSourceStack wrapper); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntityArgumentBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntityArgumentBridge.java index 830aff49..4ec72eb2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntityArgumentBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntityArgumentBridge.java @@ -2,7 +2,7 @@ package io.izzel.arclight.common.bridge.command.arguments; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.arguments.EntitySelector; +import net.minecraft.commands.arguments.selector.EntitySelector; public interface EntityArgumentBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntitySelectorParserBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntitySelectorParserBridge.java index a760cc2c..9fc8a84a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntitySelectorParserBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/command/arguments/EntitySelectorParserBridge.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.bridge.command.arguments; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.command.arguments.EntitySelector; +import net.minecraft.commands.arguments.selector.EntitySelector; public interface EntitySelectorParserBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityBridge.java index a48dfc42..83f20f9c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityBridge.java @@ -1,17 +1,17 @@ package io.izzel.arclight.common.bridge.entity; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.projectiles.ProjectileSource; import java.util.List; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; public interface EntityBridge extends ICommandSourceBridge { - Entity bridge$teleportTo(ServerWorld world, BlockPos blockPos); + Entity bridge$teleportTo(ServerLevel world, BlockPos blockPos); void bridge$setOnFire(int tick, boolean callEvent); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityTypeBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityTypeBridge.java index e9005b18..3f10741b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityTypeBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/EntityTypeBridge.java @@ -1,17 +1,17 @@ package io.izzel.arclight.common.bridge.entity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.server.ServerWorld; import org.bukkit.event.entity.CreatureSpawnEvent; import javax.annotation.Nullable; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.player.Player; public interface EntityTypeBridge { - T bridge$spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason); + T bridge$spawnCreature(ServerLevel worldIn, @Nullable CompoundTag compound, @Nullable Component customName, @Nullable Player playerIn, BlockPos pos, MobSpawnType reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/InternalEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/InternalEntityBridge.java index 982a4fb9..71b9887f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/InternalEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/InternalEntityBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.entity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; import org.bukkit.craftbukkit.v.entity.CraftEntity; public interface InternalEntityBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/LivingEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/LivingEntityBridge.java index 028667b2..eedd76a0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/LivingEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/LivingEntityBridge.java @@ -1,18 +1,18 @@ package io.izzel.arclight.common.bridge.entity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Effect; -import net.minecraft.potion.EffectInstance; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import java.util.Optional; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.item.ItemStack; public interface LivingEntityBridge extends EntityBridge { - void bridge$setSlot(EquipmentSlotType slotIn, ItemStack stack, boolean silent); + void bridge$setSlot(EquipmentSlot slotIn, ItemStack stack, boolean silent); void bridge$playEquipSound(ItemStack stack, boolean silent); @@ -32,9 +32,9 @@ public interface LivingEntityBridge extends EntityBridge { void bridge$pushEffectCause(EntityPotionEffectEvent.Cause cause); - boolean bridge$addEffect(EffectInstance effect, EntityPotionEffectEvent.Cause cause); + boolean bridge$addEffect(MobEffectInstance effect, EntityPotionEffectEvent.Cause cause); - boolean bridge$removeEffect(Effect effect, EntityPotionEffectEvent.Cause cause); + boolean bridge$removeEffect(MobEffect effect, EntityPotionEffectEvent.Cause cause); boolean bridge$removeAllEffects(EntityPotionEffectEvent.Cause cause); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/MobEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/MobEntityBridge.java index c256f63e..7086653d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/MobEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/MobEntityBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTransformEvent; @@ -25,9 +25,4 @@ public interface MobEntityBridge extends LivingEntityBridge { void bridge$setAware(boolean aware); void bridge$captureItemDrop(ItemEntity itemEntity); - - interface Hack { - - ResourceLocation getLootTable(); - } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/EndermanEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/EndermanEntityBridge.java index d732c23e..a3527ea7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/EndermanEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/EndermanEntityBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.entity.monster; -import net.minecraft.entity.LivingEntity; +import net.minecraft.world.entity.LivingEntity; public interface EndermanEntityBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/piglin/PiglinBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/piglin/PiglinBridge.java new file mode 100644 index 00000000..5eadc808 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/monster/piglin/PiglinBridge.java @@ -0,0 +1,12 @@ +package io.izzel.arclight.common.bridge.entity.monster.piglin; + +import net.minecraft.world.item.Item; + +import java.util.Set; + +public interface PiglinBridge { + + Set bridge$getAllowedBarterItems(); + + Set bridge$getInterestItems(); +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/passive/AnimalEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/passive/AnimalEntityBridge.java index 9d63603a..a7d34454 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/passive/AnimalEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/passive/AnimalEntityBridge.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.bridge.entity.passive; -import net.minecraft.item.ItemStack; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.item.ItemStack; public interface AnimalEntityBridge extends MobEntityBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerEntityBridge.java index 298f4446..fe3dd60e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerEntityBridge.java @@ -2,10 +2,11 @@ package io.izzel.arclight.common.bridge.entity.player; import com.mojang.datafixers.util.Either; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.core.BlockPos; import net.minecraft.util.Unit; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.entity.player.Player; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; +import org.bukkit.event.entity.EntityExhaustionEvent; public interface PlayerEntityBridge extends LivingEntityBridge { @@ -14,5 +15,7 @@ public interface PlayerEntityBridge extends LivingEntityBridge { @Override CraftHumanEntity bridge$getBukkitEntity(); - Either bridge$trySleep(BlockPos at, boolean force); + Either bridge$trySleep(BlockPos at, boolean force); + + void bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason reason); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerInventoryBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerInventoryBridge.java index 55462d9e..09e8951a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerInventoryBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/PlayerInventoryBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.entity.player; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; public interface PlayerInventoryBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/ServerPlayerEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/ServerPlayerEntityBridge.java index 7535d5c3..c53a26b3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/ServerPlayerEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/player/ServerPlayerEntityBridge.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.bridge.entity.player; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.bukkit.event.player.PlayerTeleportEvent; @@ -20,21 +20,21 @@ public interface ServerPlayerEntityBridge extends PlayerEntityBridge { Optional bridge$getTeleportCause(); - BlockPos bridge$getSpawnPoint(ServerWorld world); + BlockPos bridge$getSpawnPoint(ServerLevel world); boolean bridge$isMovementBlocked(); void bridge$setCompassTarget(Location location); - void bridge$sendMessage(ITextComponent[] ichatbasecomponent, UUID uuid); + void bridge$sendMessage(Component[] ichatbasecomponent, UUID uuid); - void bridge$sendMessage(ITextComponent component, UUID uuid); + void bridge$sendMessage(Component component, UUID uuid); boolean bridge$isJoining(); void bridge$reset(); - Entity bridge$changeDimension(ServerWorld world, PlayerTeleportEvent.TeleportCause cause); + Entity bridge$changeDimension(ServerLevel world, PlayerTeleportEvent.TeleportCause cause); boolean bridge$initialized(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/ProjectileItemEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/ProjectileItemEntityBridge.java deleted file mode 100644 index 934ca538..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/ProjectileItemEntityBridge.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.izzel.arclight.common.bridge.entity.projectile; - -import net.minecraft.item.Item; - -public interface ProjectileItemEntityBridge { - - interface Hack { - - Item getDefaultItem(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/TridentEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/TridentEntityBridge.java index 74e671ce..40832316 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/TridentEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/entity/projectile/TridentEntityBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.entity.projectile; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; public interface TridentEntityBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/CraftingInventoryBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/CraftingInventoryBridge.java index 2abe9403..606887b0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/CraftingInventoryBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/CraftingInventoryBridge.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.bridge.inventory; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.IInventory; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; public interface CraftingInventoryBridge extends IInventoryBridge { - void bridge$setOwner(PlayerEntity owner); + void bridge$setOwner(Player owner); - void bridge$setResultInventory(IInventory resultInventory); + void bridge$setResultInventory(Container resultInventory); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/IInventoryBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/IInventoryBridge.java index 98535328..103149a3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/IInventoryBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/IInventoryBridge.java @@ -2,9 +2,6 @@ package io.izzel.arclight.common.bridge.inventory; import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.util.WrappedContents; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v.inventory.CraftInventory; @@ -13,13 +10,16 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import java.util.List; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; public interface IInventoryBridge { int MAX_STACK = 64; default List getContents() { - return new WrappedContents((IInventory) this); + return new WrappedContents((Container) this); } void onOpen(CraftHumanEntity who); @@ -36,11 +36,11 @@ public interface IInventoryBridge { Location getLocation(); - default IRecipe getCurrentRecipe() { + default Recipe getCurrentRecipe() { return null; } - default void setCurrentRecipe(IRecipe recipe) { + default void setCurrentRecipe(Recipe recipe) { } default Inventory getOwnerInventory() { @@ -49,7 +49,7 @@ public interface IInventoryBridge { return owner.getInventory(); } else { ArclightMod.LOGGER.warn("No owner for inventory {}/{}", this, this.getClass()); - return new CraftInventory((IInventory) this); + return new CraftInventory((Container) this); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/ContainerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/ContainerBridge.java index 9632a0d0..874c0a93 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/ContainerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/ContainerBridge.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.bridge.inventory.container; -import net.minecraft.inventory.container.Container; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.world.inventory.AbstractContainerMenu; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.inventory.InventoryView; @@ -9,11 +9,11 @@ public interface ContainerBridge { InventoryView bridge$getBukkitView(); - void bridge$transferTo(Container other, CraftHumanEntity player); + void bridge$transferTo(AbstractContainerMenu other, CraftHumanEntity player); - ITextComponent bridge$getTitle(); + Component bridge$getTitle(); - void bridge$setTitle(ITextComponent title); + void bridge$setTitle(Component title); boolean bridge$isCheckReachable(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/LecternContainerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/LecternContainerBridge.java index cae435f6..05ccb708 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/LecternContainerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/LecternContainerBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.inventory.container; -import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.world.entity.player.Inventory; public interface LecternContainerBridge { - void bridge$setPlayerInventory(PlayerInventory playerInventory); + void bridge$setPlayerInventory(Inventory playerInventory); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/PosContainerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/PosContainerBridge.java index dbb7921e..ca9b3a99 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/PosContainerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inventory/container/PosContainerBridge.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.bridge.inventory.container; import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.inventory.ContainerLevelAccess; import org.bukkit.Location; public interface PosContainerBridge extends ContainerBridge { - IWorldPosCallable bridge$getWorldPos(); + ContainerLevelAccess bridge$getWorldPos(); default Location bridge$getWorldLocation() { return ((IWorldPosCallableBridge) bridge$getWorldPos()).bridge$getLocation(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/ItemStackBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/ItemStackBridge.java index 7f765e72..10fd7312 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/ItemStackBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/ItemStackBridge.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.bridge.item; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.CompoundTag; public interface ItemStackBridge { void bridge$convertStack(int version); - CompoundNBT bridge$getForgeCaps(); + CompoundTag bridge$getForgeCaps(); - void bridge$setForgeCaps(CompoundNBT caps); + void bridge$setForgeCaps(CompoundTag caps); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/crafting/RecipeManagerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/crafting/RecipeManagerBridge.java index 6198fb8f..f97e1ad1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/crafting/RecipeManagerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/item/crafting/RecipeManagerBridge.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.bridge.item.crafting; -import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.item.crafting.Recipe; public interface RecipeManagerBridge { - void bridge$addRecipe(IRecipe recipe); + void bridge$addRecipe(Recipe recipe); void bridge$clearRecipes(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/network/datasync/EntityDataManagerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/network/datasync/EntityDataManagerBridge.java index 0f29b037..3b548052 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/network/datasync/EntityDataManagerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/network/datasync/EntityDataManagerBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.network.datasync; -import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.syncher.EntityDataAccessor; public interface EntityDataManagerBridge { - void bridge$markDirty(DataParameter key); + void bridge$markDirty(EntityDataAccessor key); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/MinecraftServerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/MinecraftServerBridge.java index c290aa95..bab218a8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/MinecraftServerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/MinecraftServerBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.server; -import net.minecraft.command.Commands; +import net.minecraft.commands.Commands; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.RemoteConsoleCommandSender; import org.bukkit.craftbukkit.v.CraftServer; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/management/PlayerListBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/management/PlayerListBridge.java index 79c575f4..c4e00f76 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/management/PlayerListBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/server/management/PlayerListBridge.java @@ -1,23 +1,23 @@ package io.izzel.arclight.common.bridge.server.management; import com.mojang.authlib.GameProfile; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.login.ServerLoginNetHandler; -import net.minecraft.util.text.ITextComponent; import org.bukkit.craftbukkit.v.CraftServer; import java.net.SocketAddress; import java.util.List; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerLoginPacketListenerImpl; public interface PlayerListBridge { - void bridge$setPlayers(List players); + void bridge$setPlayers(List players); - List bridge$getPlayers(); + List bridge$getPlayers(); CraftServer bridge$getCraftServer(); - ServerPlayerEntity bridge$canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile, ServerLoginNetHandler handler); + ServerPlayer bridge$canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile, ServerLoginPacketListenerImpl handler); - void bridge$sendMessage(ITextComponent[] components); + void bridge$sendMessage(Component[] components); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/tileentity/AbstractFurnaceTileEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/tileentity/AbstractFurnaceTileEntityBridge.java index dec6ed2b..edec2e48 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/tileentity/AbstractFurnaceTileEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/tileentity/AbstractFurnaceTileEntityBridge.java @@ -1,14 +1,13 @@ package io.izzel.arclight.common.bridge.tileentity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.World; - import java.util.List; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; public interface AbstractFurnaceTileEntityBridge { - List> bridge$dropExp(World world, Vector3d pos, PlayerEntity entity, ItemStack itemStack, int amount); + List> bridge$dropExp(Level world, Vec3 pos, Player entity, ItemStack itemStack, int amount); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/DamageSourceBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/DamageSourceBridge.java index 39110b87..1557fb2a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/DamageSourceBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/DamageSourceBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.util; -import net.minecraft.util.DamageSource; +import net.minecraft.world.damagesource.DamageSource; public interface DamageSourceBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/FoodStatsBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/FoodStatsBridge.java index 8fe5871c..2fc0f16e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/FoodStatsBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/FoodStatsBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.util; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.player.Player; public interface FoodStatsBridge { - void bridge$setEntityHuman(PlayerEntity playerEntity); + void bridge$setEntityHuman(Player playerEntity); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IWorldPosCallableBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IWorldPosCallableBridge.java index d0d28287..4f81d10e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IWorldPosCallableBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IWorldPosCallableBridge.java @@ -1,20 +1,20 @@ package io.izzel.arclight.common.bridge.util; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.util.IWorldPosCallable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.Level; import org.bukkit.Location; import org.bukkit.craftbukkit.v.CraftWorld; public interface IWorldPosCallableBridge { - default World bridge$getWorld() { - return ((IWorldPosCallable) this).apply((a, b) -> a).orElse(null); + default Level bridge$getWorld() { + return ((ContainerLevelAccess) this).evaluate((a, b) -> a).orElse(null); } default BlockPos bridge$getPosition() { - return ((IWorldPosCallable) this).apply((a, b) -> b).orElse(null); + return ((ContainerLevelAccess) this).evaluate((a, b) -> b).orElse(null); } default Location bridge$getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IndirectEntityDamageSourceBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IndirectEntityDamageSourceBridge.java index f82e4ed0..cd84cbcc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IndirectEntityDamageSourceBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/IndirectEntityDamageSourceBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.util; -import net.minecraft.entity.Entity; +import net.minecraft.world.entity.Entity; public interface IndirectEntityDamageSourceBridge extends DamageSourceBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/text/ITextComponentBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/text/ITextComponentBridge.java index 72ed973c..f0fd5dd7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/text/ITextComponentBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/util/text/ITextComponentBridge.java @@ -1,13 +1,12 @@ package io.izzel.arclight.common.bridge.util.text; -import net.minecraft.util.text.ITextComponent; - import java.util.Iterator; import java.util.stream.Stream; +import net.minecraft.network.chat.Component; public interface ITextComponentBridge { - Stream bridge$stream(); + Stream bridge$stream(); - Iterator bridge$iterator(); + Iterator bridge$iterator(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/ExplosionBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/ExplosionBridge.java index 1b003fc0..d62ef4d6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/ExplosionBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/ExplosionBridge.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.entity.Entity; -import net.minecraft.world.Explosion; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Explosion; public interface ExplosionBridge { @@ -11,7 +11,7 @@ public interface ExplosionBridge { void bridge$setSize(float size); - Explosion.Mode bridge$getMode(); + Explosion.BlockInteraction bridge$getMode(); boolean bridge$wasCancelled(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IBlockReaderBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IBlockReaderBridge.java index ea14b85f..a4383142 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IBlockReaderBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IBlockReaderBridge.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceContext; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.phys.BlockHitResult; public interface IBlockReaderBridge { - BlockRayTraceResult bridge$rayTraceBlock(RayTraceContext context, BlockPos pos); + BlockHitResult bridge$rayTraceBlock(ClipContext context, BlockPos pos); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldBridge.java index 759d57b9..08b86e19 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; public interface IWorldBridge { - ServerWorld bridge$getMinecraftWorld(); + ServerLevel bridge$getMinecraftWorld(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldWriterBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldWriterBridge.java index 1b937c73..61cd2cb3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldWriterBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/IWorldWriterBridge.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.entity.Entity; +import net.minecraft.world.entity.Entity; import org.bukkit.event.entity.CreatureSpawnEvent; public interface IWorldWriterBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TeleporterBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TeleporterBridge.java index aae2a08f..cda48c61 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TeleporterBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TeleporterBridge.java @@ -1,15 +1,14 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.entity.Entity; -import net.minecraft.util.Direction; -import net.minecraft.util.TeleportationRepositioner; -import net.minecraft.util.math.BlockPos; - import java.util.Optional; +import net.minecraft.BlockUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; public interface TeleporterBridge { - Optional bridge$findPortal(BlockPos pos, int searchRadius); + Optional bridge$findPortal(BlockPos pos, int searchRadius); - Optional bridge$createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius); + Optional bridge$createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TrackedEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TrackedEntityBridge.java index 63a7116f..6ca920e8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TrackedEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/TrackedEntityBridge.java @@ -1,10 +1,9 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.entity.player.ServerPlayerEntity; - import java.util.Set; +import net.minecraft.server.level.ServerPlayer; public interface TrackedEntityBridge { - void bridge$setTrackedPlayers(Set trackedPlayers); + void bridge$setTrackedPlayers(Set trackedPlayers); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/WorldBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/WorldBridge.java index c7cc0dce..579fe20a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/WorldBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/WorldBridge.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.bridge.world; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.DimensionType; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.dimension.DimensionType; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.generator.ChunkGenerator; @@ -25,7 +25,7 @@ public interface WorldBridge extends IWorldWriterBridge, IWorldBridge { ChunkGenerator bridge$getGenerator(); - TileEntity bridge$getTileEntity(BlockPos pos, boolean validate); + BlockEntity bridge$getTileEntity(BlockPos pos, boolean validate); SpigotWorldConfig bridge$spigotConfig(); @@ -39,5 +39,5 @@ public interface WorldBridge extends IWorldWriterBridge, IWorldBridge { long bridge$ticksPerWaterAmbientSpawns(); - RegistryKey bridge$getTypeKey(); + ResourceKey bridge$getTypeKey(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/border/WorldBorderBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/border/WorldBorderBridge.java index 56529532..7a4774c3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/border/WorldBorderBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/border/WorldBorderBridge.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.bridge.world.border; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; public interface WorldBorderBridge { - World bridge$getWorld(); + Level bridge$getWorld(); - void bridge$setWorld(World world); + void bridge$setWorld(Level world); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/ChunkBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/ChunkBridge.java index 1be8e521..4b89256f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/ChunkBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/ChunkBridge.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.bridge.world.chunk; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Chunk; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/storage/RegionFileCacheBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/storage/RegionFileCacheBridge.java index 31d41208..32a2dedb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/storage/RegionFileCacheBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/chunk/storage/RegionFileCacheBridge.java @@ -1,8 +1,7 @@ package io.izzel.arclight.common.bridge.world.chunk.storage; -import net.minecraft.util.math.ChunkPos; - import java.io.IOException; +import net.minecraft.world.level.ChunkPos; public interface RegionFileCacheBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/raid/RaidBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/raid/RaidBridge.java index 367f8076..eabcacf2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/raid/RaidBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/raid/RaidBridge.java @@ -1,10 +1,9 @@ package io.izzel.arclight.common.bridge.world.raid; -import net.minecraft.entity.monster.AbstractRaiderEntity; - import java.util.Collection; +import net.minecraft.world.entity.raid.Raider; public interface RaidBridge { - Collection bridge$getRaiders(); + Collection bridge$getRaiders(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkHolderBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkHolderBridge.java index 48cc1cb9..6465dc1d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkHolderBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkHolderBridge.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.bridge.world.server; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.chunk.LevelChunk; public interface ChunkHolderBridge { int bridge$getOldTicketLevel(); - Chunk bridge$getFullChunk(); + LevelChunk bridge$getFullChunk(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkManagerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkManagerBridge.java index ac1598c4..f04dc090 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkManagerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ChunkManagerBridge.java @@ -1,11 +1,10 @@ package io.izzel.arclight.common.bridge.world.server; import io.izzel.arclight.common.mod.util.ArclightCallbackExecutor; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.server.ChunkHolder; - import java.util.function.BooleanSupplier; +import net.minecraft.server.level.ChunkHolder; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.ChunkGenerator; public interface ChunkManagerBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerChunkProviderBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerChunkProviderBridge.java index fc1c117e..59fe21f1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerChunkProviderBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerChunkProviderBridge.java @@ -1,9 +1,8 @@ package io.izzel.arclight.common.bridge.world.server; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.server.ServerWorldLightManager; - import java.io.IOException; +import net.minecraft.server.level.ThreadedLevelLightEngine; +import net.minecraft.world.level.chunk.ChunkGenerator; public interface ServerChunkProviderBridge { @@ -15,7 +14,7 @@ public interface ServerChunkProviderBridge { boolean bridge$isChunkLoaded(int x, int z); - ServerWorldLightManager bridge$getLightManager(); + ThreadedLevelLightEngine bridge$getLightManager(); void bridge$setChunkGenerator(ChunkGenerator chunkGenerator); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerWorldBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerWorldBridge.java index 3eaccab4..2f4ae347 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerWorldBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/ServerWorldBridge.java @@ -1,24 +1,24 @@ package io.izzel.arclight.common.bridge.world.server; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.particles.IParticleData; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.storage.SaveFormat; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.weather.LightningStrikeEvent; import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.storage.LevelStorageSource; public interface ServerWorldBridge extends WorldBridge { - int bridge$sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force); + int bridge$sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force); void bridge$pushStrikeLightningCause(LightningStrikeEvent.Cause cause); - void bridge$strikeLightning(LightningBoltEntity entity, LightningStrikeEvent.Cause cause); + void bridge$strikeLightning(LightningBolt entity, LightningStrikeEvent.Cause cause); - TileEntity bridge$getTileEntity(BlockPos blockPos); + BlockEntity bridge$getTileEntity(BlockPos blockPos); boolean bridge$addEntitySerialized(Entity entity, CreatureSpawnEvent.SpawnReason reason); @@ -26,10 +26,10 @@ public interface ServerWorldBridge extends WorldBridge { boolean bridge$addAllEntitiesSafely(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason); - SaveFormat.LevelSave bridge$getConvertable(); + LevelStorageSource.LevelStorageAccess bridge$getConvertable(); interface Hack { - TileEntity getTileEntity(BlockPos blockPos); + BlockEntity getTileEntity(BlockPos blockPos); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/TicketManagerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/TicketManagerBridge.java index 627ce03c..ac87b376 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/TicketManagerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/server/TicketManagerBridge.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.bridge.world.server; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.server.Ticket; -import net.minecraft.world.server.TicketType; +import net.minecraft.server.level.Ticket; +import net.minecraft.server.level.TicketType; +import net.minecraft.world.level.ChunkPos; public interface TicketManagerBridge { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/spawner/WorldEntitySpawnerBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/spawner/WorldEntitySpawnerBridge.java index 67cfc6ef..12d056b0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/spawner/WorldEntitySpawnerBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/spawner/WorldEntitySpawnerBridge.java @@ -1,19 +1,19 @@ package io.izzel.arclight.common.bridge.world.spawner; -import net.minecraft.entity.EntityClassification; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MobEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.IChunk; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.chunk.ChunkAccess; public interface WorldEntitySpawnerBridge { interface EntityDensityManagerBridge { - void bridge$updateDensity(MobEntity mobEntity, IChunk chunk); + void bridge$updateDensity(Mob mobEntity, ChunkAccess chunk); - boolean bridge$canSpawn(EntityClassification classification, int limit); + boolean bridge$canSpawn(MobCategory classification, int limit); - boolean bridge$canSpawn(EntityType entityType, BlockPos pos, IChunk chunk); + boolean bridge$canSpawn(EntityType entityType, BlockPos pos, ChunkAccess chunk); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/DerivedWorldInfoBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/DerivedWorldInfoBridge.java index 20e4571f..cd3d4bc4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/DerivedWorldInfoBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/DerivedWorldInfoBridge.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.bridge.world.storage; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.DimensionType; -import net.minecraft.world.storage.IServerWorldInfo; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.ServerLevelData; public interface DerivedWorldInfoBridge { - IServerWorldInfo bridge$getDelegate(); + ServerLevelData bridge$getDelegate(); - void bridge$setDimType(RegistryKey typeKey); + void bridge$setDimType(ResourceKey typeKey); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/PlayerDataBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/PlayerDataBridge.java index 9fb744a5..46992391 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/PlayerDataBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/PlayerDataBridge.java @@ -1,12 +1,11 @@ package io.izzel.arclight.common.bridge.world.storage; -import net.minecraft.nbt.CompoundNBT; - import java.io.File; +import net.minecraft.nbt.CompoundTag; public interface PlayerDataBridge { File bridge$getPlayerDir(); - CompoundNBT bridge$getPlayerData(String uuid); + CompoundTag bridge$getPlayerData(String uuid); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/SaveFormatBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/SaveFormatBridge.java index 2427a2e1..6f280fec 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/SaveFormatBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/SaveFormatBridge.java @@ -1,17 +1,16 @@ package io.izzel.arclight.common.bridge.world.storage; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.Dimension; -import net.minecraft.world.storage.SaveFormat; - import java.io.IOException; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.storage.LevelStorageSource; public interface SaveFormatBridge { - SaveFormat.LevelSave bridge$getLevelSave(String saveName, RegistryKey world) throws IOException; + LevelStorageSource.LevelStorageAccess bridge$getLevelSave(String saveName, ResourceKey world) throws IOException; interface LevelSaveBridge { - void bridge$setDimType(RegistryKey typeKey); + void bridge$setDimType(ResourceKey typeKey); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/WorldInfoBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/WorldInfoBridge.java index 4883ab27..9286f4d2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/WorldInfoBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/WorldInfoBridge.java @@ -1,16 +1,16 @@ package io.izzel.arclight.common.bridge.world.storage; import com.mojang.serialization.Lifecycle; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.LevelSettings; public interface WorldInfoBridge { - void bridge$setWorld(ServerWorld world); + void bridge$setWorld(ServerLevel world); - ServerWorld bridge$getWorld(); + ServerLevel bridge$getWorld(); - WorldSettings bridge$getWorldSettings(); + LevelSettings bridge$getWorldSettings(); Lifecycle bridge$getLifecycle(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/loot/LootTableBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/loot/LootTableBridge.java index a6c1478d..c0ee9ce0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/loot/LootTableBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/world/storage/loot/LootTableBridge.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.bridge.world.storage.loot; -import net.minecraft.inventory.IInventory; -import net.minecraft.loot.LootContext; +import net.minecraft.world.Container; +import net.minecraft.world.level.storage.loot.LootContext; public interface LootTableBridge { - void bridge$fillInventory(IInventory inv, LootContext context, boolean plugin); + void bridge$fillInventory(Container inv, LootContext context, boolean plugin); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftAbstractVillagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftAbstractVillagerMixin.java index 7c45c885..15debe5a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftAbstractVillagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftAbstractVillagerMixin.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mixin.bukkit; -import net.minecraft.entity.merchant.villager.AbstractVillagerEntity; +import net.minecraft.world.entity.npc.AbstractVillager; import org.bukkit.craftbukkit.v.entity.CraftAbstractVillager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -13,7 +13,7 @@ public abstract class CraftAbstractVillagerMixin extends CraftEntityMixin { * @reason */ @Overwrite - public AbstractVillagerEntity getHandle() { - return (AbstractVillagerEntity) this.entity; + public AbstractVillager getHandle() { + return (AbstractVillager) this.entity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockMixin.java index 4bc48465..bbc4bf24 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockMixin.java @@ -2,7 +2,7 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.bridge.bukkit.MaterialBridge; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.util.registry.Registry; +import net.minecraft.core.Registry; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.Material; import org.bukkit.block.Biome; @@ -36,7 +36,7 @@ public abstract class CraftBlockMixin { * @reason */ @Overwrite - public static Biome biomeBaseToBiome(Registry registry, net.minecraft.world.biome.Biome base) { + public static Biome biomeBaseToBiome(Registry registry, net.minecraft.world.level.biome.Biome base) { return Biome.valueOf(ResourceLocationUtil.standardize(base.getRegistryName())); } @@ -45,7 +45,7 @@ public abstract class CraftBlockMixin { * @reason */ @Overwrite - public static net.minecraft.world.biome.Biome biomeToBiomeBase(Registry registry, Biome bio) { + public static net.minecraft.world.level.biome.Biome biomeToBiomeBase(Registry registry, Biome bio) { return ForgeRegistries.BIOMES.getValue(CraftNamespacedKey.toMinecraft(bio.getKey())); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockStateMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockStateMixin.java index 2da1dc83..a4e92fce 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockStateMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftBlockStateMixin.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mixin.bukkit; -import net.minecraft.block.BlockState; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.block.CraftBlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftChunkMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftChunkMixin.java index 78cb98c4..ebda1978 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftChunkMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftChunkMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.level.chunk.LevelChunk; import org.bukkit.World; import org.bukkit.craftbukkit.v.CraftChunk; import org.bukkit.entity.Entity; @@ -18,7 +18,7 @@ public abstract class CraftChunkMixin { @Shadow public abstract World getWorld(); @Shadow @Final private int x; @Shadow @Final private int z; - @Shadow public abstract Chunk getHandle(); + @Shadow public abstract LevelChunk getHandle(); // @formatter:on /** @@ -32,16 +32,16 @@ public abstract class CraftChunkMixin { } int count = 0; int index = 0; - net.minecraft.world.chunk.Chunk chunk = this.getHandle(); + net.minecraft.world.level.chunk.LevelChunk chunk = this.getHandle(); for (int i = 0; i < 16; ++i) { - count += chunk.entityLists[i].size(); + count += chunk.entitySections[i].size(); } Entity[] entities = new Entity[count]; for (int j = 0; j < 16; ++j) { Object[] array; - for (int length = (array = chunk.entityLists[j].toArray()).length, k = 0; k < length; ++k) { + for (int length = (array = chunk.entitySections[j].toArray()).length, k = 0; k < length; ++k) { Object obj = array[k]; - if (obj instanceof net.minecraft.entity.Entity) { + if (obj instanceof net.minecraft.world.entity.Entity) { entities[index++] = ((EntityBridge) obj).bridge$getBukkitEntity(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java index 811baef3..3d0b083b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEntityMixin.java @@ -11,20 +11,20 @@ import io.izzel.arclight.common.mod.server.entity.ArclightModMob; import io.izzel.arclight.common.mod.server.entity.ArclightModProjectile; import io.izzel.arclight.common.mod.server.entity.ArclightModRaider; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.AgeableEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.FlyingEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.item.minecart.AbstractMinecartEntity; -import net.minecraft.entity.item.minecart.ContainerMinecartEntity; -import net.minecraft.entity.monster.AbstractRaiderEntity; -import net.minecraft.entity.passive.GolemEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.passive.horse.AbstractChestedHorseEntity; -import net.minecraft.entity.passive.horse.AbstractHorseEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.AgableMob; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.FlyingMob; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.AbstractGolem; +import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; +import net.minecraft.world.entity.animal.horse.AbstractHorse; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.entity.raid.Raider; +import net.minecraft.world.entity.vehicle.AbstractMinecart; +import net.minecraft.world.entity.vehicle.AbstractMinecartContainer; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; @@ -77,50 +77,50 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.Entity { @Inject(method = "getEntity", cancellable = true, at = @At(value = "NEW", target = "java/lang/AssertionError")) private static void arclight$modEntity(CraftServer server, Entity entity, CallbackInfoReturnable cir) { if (entity instanceof LivingEntity) { - if (entity instanceof MobEntity) { - if (entity instanceof AgeableEntity) { - if (entity instanceof AbstractHorseEntity) { - if (entity instanceof AbstractChestedHorseEntity) { - cir.setReturnValue(new ArclightModChestedHorse(server, (AbstractChestedHorseEntity) entity)); + if (entity instanceof Mob) { + if (entity instanceof AgableMob) { + if (entity instanceof AbstractHorse) { + if (entity instanceof AbstractChestedHorse) { + cir.setReturnValue(new ArclightModChestedHorse(server, (AbstractChestedHorse) entity)); return; } - cir.setReturnValue(new ArclightModHorse(server, (AbstractHorseEntity) entity)); + cir.setReturnValue(new ArclightModHorse(server, (AbstractHorse) entity)); return; } - if (entity instanceof TameableEntity) { - cir.setReturnValue(new CraftTameableAnimal(server, (TameableEntity) entity)); + if (entity instanceof TamableAnimal) { + cir.setReturnValue(new CraftTameableAnimal(server, (TamableAnimal) entity)); return; } - cir.setReturnValue(new CraftAgeable(server, (AgeableEntity) entity)); + cir.setReturnValue(new CraftAgeable(server, (AgableMob) entity)); return; } - if (entity instanceof FlyingEntity) { - cir.setReturnValue(new CraftFlying(server, (FlyingEntity) entity)); + if (entity instanceof FlyingMob) { + cir.setReturnValue(new CraftFlying(server, (FlyingMob) entity)); return; } - if (entity instanceof AbstractRaiderEntity) { - cir.setReturnValue(new ArclightModRaider(server, (AbstractRaiderEntity) entity)); + if (entity instanceof Raider) { + cir.setReturnValue(new ArclightModRaider(server, (Raider) entity)); return; } - if (entity instanceof GolemEntity) { - cir.setReturnValue(new CraftGolem(server, (GolemEntity) entity)); + if (entity instanceof AbstractGolem) { + cir.setReturnValue(new CraftGolem(server, (AbstractGolem) entity)); return; } - cir.setReturnValue(new ArclightModMob(server, (MobEntity) entity)); + cir.setReturnValue(new ArclightModMob(server, (Mob) entity)); return; } cir.setReturnValue(new ArclightModLivingEntity(server, (LivingEntity) entity)); return; } - if (entity instanceof AbstractMinecartEntity) { - if (entity instanceof ContainerMinecartEntity) { - cir.setReturnValue(new ArclightModMinecartContainer(server, (ContainerMinecartEntity) entity)); + if (entity instanceof AbstractMinecart) { + if (entity instanceof AbstractMinecartContainer) { + cir.setReturnValue(new ArclightModMinecartContainer(server, (AbstractMinecartContainer) entity)); return; } - cir.setReturnValue(new ArclightModMinecart(server, (AbstractMinecartEntity) entity)); + cir.setReturnValue(new ArclightModMinecart(server, (AbstractMinecart) entity)); return; } - if (entity instanceof ProjectileEntity) { + if (entity instanceof Projectile) { cir.setReturnValue(new ArclightModProjectile(server, entity)); return; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java index 38528af4..20ab7826 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEventFactoryMixin.java @@ -4,9 +4,6 @@ import com.google.common.base.Function; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.entity.Entity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.BlockPos; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -20,6 +17,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Map; +import net.minecraft.core.BlockPos; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; @Mixin(value = CraftEventFactory.class, remap = false) public class CraftEventFactoryMixin { @@ -27,33 +27,33 @@ public class CraftEventFactoryMixin { @Shadow public static Entity entityDamage; @Shadow public static Block blockDamage; - @Inject(method = "handleEntityDamageEvent(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", at = @At("HEAD")) + @Inject(method = "handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", at = @At("HEAD")) private static void arclight$captureSource(Entity entity, DamageSource source, Map modifiers, Map> modifierFunctions, boolean cancelled, CallbackInfoReturnable cir) { Entity damageEventEntity = ArclightCaptures.getDamageEventEntity(); BlockPos damageEventBlock = ArclightCaptures.getDamageEventBlock(); if (damageEventEntity != null && entityDamage == null) { - if (source.damageType.equals(DamageSource.LIGHTNING_BOLT.damageType)) { + if (source.msgId.equals(DamageSource.LIGHTNING_BOLT.msgId)) { entityDamage = damageEventEntity; } } if (damageEventBlock != null && blockDamage == null) { - if (source.damageType.equals(DamageSource.CACTUS.damageType) - || source.damageType.equals(DamageSource.SWEET_BERRY_BUSH.damageType) - || source.damageType.equals(DamageSource.HOT_FLOOR.damageType)) { - blockDamage = CraftBlock.at(entity.getEntityWorld(), damageEventBlock); + if (source.msgId.equals(DamageSource.CACTUS.msgId) + || source.msgId.equals(DamageSource.SWEET_BERRY_BUSH.msgId) + || source.msgId.equals(DamageSource.HOT_FLOOR.msgId)) { + blockDamage = CraftBlock.at(entity.getCommandSenderWorld(), damageEventBlock); } } } - @Inject(method = "handleEntityDamageEvent(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", cancellable = true, at = @At(value = "NEW", target = "java/lang/IllegalStateException")) + @Inject(method = "handleEntityDamageEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Ljava/util/Map;Ljava/util/Map;Z)Lorg/bukkit/event/entity/EntityDamageEvent;", cancellable = true, at = @At(value = "NEW", target = "java/lang/IllegalStateException")) private static void arclight$unhandledDamage(Entity entity, DamageSource source, Map modifiers, Map> modifierFunctions, boolean cancelled, CallbackInfoReturnable cir) { // todo blockDamage is lost EntityDamageEvent event; - if (source.getTrueSource() != null) { - ArclightMod.LOGGER.debug("Unhandled damage of {} by {} from {}", entity, source.getTrueSource(), source.damageType); - event = new EntityDamageByEntityEvent(((EntityBridge) source.getTrueSource()).bridge$getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions); + if (source.getEntity() != null) { + ArclightMod.LOGGER.debug("Unhandled damage of {} by {} from {}", entity, source.getEntity(), source.msgId); + event = new EntityDamageByEntityEvent(((EntityBridge) source.getEntity()).bridge$getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions); } else { - ArclightMod.LOGGER.debug("Unhandled damage of {} from {}", entity, source.damageType); + ArclightMod.LOGGER.debug("Unhandled damage of {} from {}", entity, source.msgId); event = new EntityDamageEvent(((EntityBridge) entity).bridge$getBukkitEntity(), EntityDamageEvent.DamageCause.CUSTOM, modifiers, modifierFunctions); } event.setCancelled(cancelled); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftHumanEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftHumanEntityMixin.java index 0a6a90a3..6d5df883 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftHumanEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftHumanEntityMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.bukkit; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftEntity; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -27,7 +27,7 @@ public abstract class CraftHumanEntityMixin extends CraftEntity { @Override public void setHandle(Entity entity) { super.setHandle(entity); - this.inventory = new CraftInventoryPlayer(((PlayerEntity) entity).inventory); - this.enderChest = new CraftInventory(((PlayerEntity) entity).getInventoryEnderChest()); + this.inventory = new CraftInventoryPlayer(((Player) entity).inventory); + this.enderChest = new CraftInventory(((Player) entity).getEnderChestInventory()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftInventoryMixin.java index a185f30d..04ac9d09 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftInventoryMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.bukkit; -import net.minecraft.inventory.IInventory; -import net.minecraft.tileentity.LecternTileEntity; +import net.minecraft.world.Container; +import net.minecraft.world.level.block.entity.LecternBlockEntity; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.event.inventory.InventoryType; import org.spongepowered.asm.mixin.Final; @@ -14,11 +14,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(value = CraftInventory.class, remap = false) public class CraftInventoryMixin { - @Shadow @Final protected IInventory inventory; + @Shadow @Final protected Container inventory; @Inject(method = "getType", cancellable = true, at = @At("HEAD")) private void arclight$lecternType(CallbackInfoReturnable cir) { - if (inventory.getClass().getDeclaringClass() == LecternTileEntity.class) { + if (inventory.getClass().getDeclaringClass() == LecternBlockEntity.class) { cir.setReturnValue(InventoryType.LECTERN); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftItemStackMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftItemStackMixin.java index 611c43f4..5d2f2027 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftItemStackMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftItemStackMixin.java @@ -3,8 +3,6 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.bridge.bukkit.CraftItemStackBridge; import io.izzel.arclight.common.bridge.bukkit.ItemMetaBridge; import io.izzel.arclight.common.bridge.item.ItemStackBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; import org.bukkit.Material; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.legacy.CraftLegacy; @@ -17,6 +15,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Objects; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.ItemStack; @Mixin(value = CraftItemStack.class, remap = false) public abstract class CraftItemStackMixin implements CraftItemStackBridge { @@ -28,11 +28,11 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge { @Shadow public abstract boolean hasItemMeta(); // @formatter:on - @Inject(method = "getItemMeta(Lnet/minecraft/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;", at = @At("RETURN")) + @Inject(method = "getItemMeta(Lnet/minecraft/world/item/ItemStack;)Lorg/bukkit/inventory/meta/ItemMeta;", at = @At("RETURN")) private static void arclight$offerCaps(ItemStack item, CallbackInfoReturnable cir) { if (item == null) return; ItemMeta meta = cir.getReturnValue(); - CompoundNBT tag = item.getTag(); + CompoundTag tag = item.getTag(); if (tag != null) { ((ItemMetaBridge) meta).bridge$offerUnhandledTags(tag); } @@ -40,9 +40,9 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge { } // check when update - @Inject(method = "setItemMeta(Lnet/minecraft/item/ItemStack;Lorg/bukkit/inventory/meta/ItemMeta;)Z", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/item/ItemStack;func_77973_b()Lnet/minecraft/item/Item;")) + @Inject(method = "setItemMeta(Lnet/minecraft/world/item/ItemStack;Lorg/bukkit/inventory/meta/ItemMeta;)Z", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/item/ItemStack;func_77973_b()Lnet/minecraft/world/item/Item;")) private static void arclight$setCaps(ItemStack item, ItemMeta itemMeta, CallbackInfoReturnable cir) { - CompoundNBT forgeCaps = ((ItemMetaBridge) itemMeta).bridge$getForgeCaps(); + CompoundTag forgeCaps = ((ItemMetaBridge) itemMeta).bridge$getForgeCaps(); if (forgeCaps != null) { ((ItemStackBridge)(Object) item).bridge$setForgeCaps(forgeCaps.copy()); } @@ -82,10 +82,10 @@ public abstract class CraftItemStackMixin implements CraftItemStackBridge { : !that.hasItemMeta(); } - @Inject(method = "hasItemMeta(Lnet/minecraft/item/ItemStack;)Z", cancellable = true, at = @At("HEAD")) + @Inject(method = "hasItemMeta(Lnet/minecraft/world/item/ItemStack;)Z", cancellable = true, at = @At("HEAD")) private static void arclight$hasMeta(ItemStack item, CallbackInfoReturnable cir) { if (item != null) { - CompoundNBT forgeCaps = ((ItemStackBridge) (Object) item).bridge$getForgeCaps(); + CompoundTag forgeCaps = ((ItemStackBridge) (Object) item).bridge$getForgeCaps(); if (forgeCaps != null && !forgeCaps.isEmpty()) { cir.setReturnValue(true); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftMetaItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftMetaItemMixin.java index 45ea126b..13bd6a0e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftMetaItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftMetaItemMixin.java @@ -3,9 +3,6 @@ package io.izzel.arclight.common.mixin.bukkit; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import io.izzel.arclight.common.bridge.bukkit.ItemMetaBridge; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.INBT; import org.apache.commons.codec.binary.Base64; import org.apache.logging.log4j.LogManager; import org.bukkit.craftbukkit.v.inventory.CraftMetaItem; @@ -24,12 +21,15 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Map; import java.util.Set; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; +import net.minecraft.nbt.Tag; @Mixin(value = CraftMetaItem.class, remap = false) public class CraftMetaItemMixin implements ItemMetaBridge { // @formatter:off - @Shadow(remap = false) @Final private Map unhandledTags; + @Shadow(remap = false) @Final private Map unhandledTags; // @formatter:on private static final Set EXTEND_TAGS = ImmutableSet.of( @@ -60,27 +60,27 @@ public class CraftMetaItemMixin implements ItemMetaBridge { "LodestoneTracked" ); - @ModifyVariable(method = "(Lnet/minecraft/nbt/CompoundNBT;)V", at = @At(value = "INVOKE", target = "Lorg/bukkit/UnsafeValues;getDataVersion()I")) - private CompoundNBT arclight$provideTag(CompoundNBT tag) { - return tag == null ? new CompoundNBT() : tag; + @ModifyVariable(method = "(Lnet/minecraft/nbt/CompoundTag;)V", at = @At(value = "INVOKE", target = "Lorg/bukkit/UnsafeValues;getDataVersion()I")) + private CompoundTag arclight$provideTag(CompoundTag tag) { + return tag == null ? new CompoundTag() : tag; } - private CompoundNBT forgeCaps; + private CompoundTag forgeCaps; @Override - public CompoundNBT bridge$getForgeCaps() { + public CompoundTag bridge$getForgeCaps() { return this.forgeCaps; } @Override - public void bridge$setForgeCaps(CompoundNBT nbt) { + public void bridge$setForgeCaps(CompoundTag nbt) { this.forgeCaps = nbt; } @Override - public void bridge$offerUnhandledTags(CompoundNBT nbt) { + public void bridge$offerUnhandledTags(CompoundTag nbt) { if (getClass().equals(CraftMetaItem.class)) { - for (String s : nbt.keySet()) { + for (String s : nbt.getAllKeys()) { if (EXTEND_TAGS.contains(s)) { this.unhandledTags.put(s, nbt.get(s)); } @@ -89,12 +89,12 @@ public class CraftMetaItemMixin implements ItemMetaBridge { } @Override - public Map bridge$getUnhandledTags() { + public Map bridge$getUnhandledTags() { return this.unhandledTags; } @Override - public void bridge$setUnhandledTags(Map tags) { + public void bridge$setUnhandledTags(Map tags) { this.unhandledTags.putAll(tags); } @@ -102,7 +102,7 @@ public class CraftMetaItemMixin implements ItemMetaBridge { private void arclight$serializeForgeCaps(ImmutableMap.Builder builder, CallbackInfoReturnable> cir) throws IOException { if (this.forgeCaps != null) { ByteArrayOutputStream buf = new ByteArrayOutputStream(); - CompressedStreamTools.writeCompressed(this.forgeCaps, buf); + NbtIo.writeCompressed(this.forgeCaps, buf); builder.put("forgeCaps", Base64.encodeBase64String(buf.toByteArray())); } } @@ -131,7 +131,7 @@ public class CraftMetaItemMixin implements ItemMetaBridge { @Inject(method = "equalsCommon", cancellable = true, at = @At("HEAD")) private void arclight$forgeCapsEquals(CraftMetaItem that, CallbackInfoReturnable cir) { - CompoundNBT forgeCaps = ((ItemMetaBridge) that).bridge$getForgeCaps(); + CompoundTag forgeCaps = ((ItemMetaBridge) that).bridge$getForgeCaps(); boolean ret; if (this.forgeCaps == null) { ret = forgeCaps != null && forgeCaps.size() != 0; @@ -149,7 +149,7 @@ public class CraftMetaItemMixin implements ItemMetaBridge { Object forgeCaps = map.get("forgeCaps"); try { ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(forgeCaps.toString())); - this.forgeCaps = CompressedStreamTools.readCompressed(buf); + this.forgeCaps = NbtIo.readCompressed(buf); } catch (IOException e) { LogManager.getLogger(getClass()).error("Reading forge caps", e); } @@ -159,7 +159,7 @@ public class CraftMetaItemMixin implements ItemMetaBridge { @Inject(method = "*", at = @At("RETURN")) private void arclight$copyForgeCaps(CraftMetaItem meta, CallbackInfo ci) { if (meta != null) { - CompoundNBT forgeCaps = ((ItemMetaBridge) meta).bridge$getForgeCaps(); + CompoundTag forgeCaps = ((ItemMetaBridge) meta).bridge$getForgeCaps(); if (forgeCaps != null) { this.forgeCaps = forgeCaps.copy(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftServerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftServerMixin.java index 113d84e6..b8f90658 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftServerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftServerMixin.java @@ -6,11 +6,11 @@ import io.izzel.arclight.common.bridge.bukkit.CraftServerBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.mod.server.ArclightServer; import jline.console.ConsoleReader; -import net.minecraft.command.CommandSource; +import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.dedicated.DedicatedPlayerList; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.management.PlayerList; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.players.PlayerList; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.world.WorldEvent; @@ -90,7 +90,7 @@ public abstract class CraftServerMixin implements CraftServerBridge { this.playerList = (DedicatedPlayerList) playerList; } - @Inject(method = "unloadWorld(Lorg/bukkit/World;Z)Z", require = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;getChunkProvider()Lnet/minecraft/world/server/ServerChunkProvider;")) + @Inject(method = "unloadWorld(Lorg/bukkit/World;Z)Z", require = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;getChunkSource()Lnet/minecraft/server/level/ServerChunkCache;")) private void arclight$unloadForge(World world, boolean save, CallbackInfoReturnable cir) { MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(((CraftWorld) world).getHandle())); this.console.markWorldsDirty(); @@ -98,11 +98,11 @@ public abstract class CraftServerMixin implements CraftServerBridge { @ModifyVariable(method = "dispatchCommand", remap = false, index = 2, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lorg/spigotmc/AsyncCatcher;catchOp(Ljava/lang/String;)V")) private String arclight$forgeCommandEvent(String commandLine, CommandSender sender) { - CommandSource commandSource; + CommandSourceStack commandSource; if (sender instanceof CraftEntity) { - commandSource = ((CraftEntity) sender).getHandle().getCommandSource(); + commandSource = ((CraftEntity) sender).getHandle().createCommandSourceStack(); } else if (sender == Bukkit.getConsoleSender()) { - commandSource = ArclightServer.getMinecraftServer().getCommandSource(); + commandSource = ArclightServer.getMinecraftServer().createCommandSourceStack(); } else if (sender instanceof CraftBlockCommandSender) { commandSource = ((CraftBlockCommandSender) sender).getWrapper(); } else { @@ -112,7 +112,7 @@ public abstract class CraftServerMixin implements CraftServerBridge { if (stringreader.canRead() && stringreader.peek() == '/') { stringreader.skip(); } - ParseResults parse = ArclightServer.getMinecraftServer().getCommandManager() + ParseResults parse = ArclightServer.getMinecraftServer().getCommands() .getDispatcher().parse(stringreader, commandSource); CommandEvent event = new CommandEvent(parse); if (MinecraftForge.EVENT_BUS.post(event)) { @@ -133,7 +133,7 @@ public abstract class CraftServerMixin implements CraftServerBridge { } @Override - public void bridge$removeWorld(ServerWorld world) { + public void bridge$removeWorld(ServerLevel world) { if (world == null) { return; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftVillagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftVillagerMixin.java index b87c2f6f..9aa97ce4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftVillagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftVillagerMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.merchant.villager.VillagerProfession; +import net.minecraft.world.entity.npc.VillagerProfession; import org.bukkit.craftbukkit.v.entity.CraftVillager; import org.bukkit.entity.Villager; import org.spongepowered.asm.mixin.Mixin; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftWorldMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftWorldMixin.java index 6ddf9183..3c127424 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftWorldMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftWorldMixin.java @@ -2,7 +2,6 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Location; import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.entity.Entity; @@ -18,18 +17,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.io.File; import java.util.function.Function; +import net.minecraft.server.level.ServerLevel; @Mixin(value = CraftWorld.class, remap = false) public abstract class CraftWorldMixin { // @formatter:off - @Shadow @Final private ServerWorld world; - @Shadow public abstract T addEntity(net.minecraft.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException; + @Shadow @Final private ServerLevel world; + @Shadow public abstract T addEntity(net.minecraft.world.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException; // @formatter:on @Inject(method = "spawnEntity", cancellable = true, at = @At("HEAD")) private void arclight$useFactory(Location loc, EntityType entityType, CallbackInfoReturnable cir) { - Function factory = ((EntityTypeBridge) (Object) entityType).bridge$entityFactory(); + Function factory = ((EntityTypeBridge) (Object) entityType).bridge$entityFactory(); if (factory != null) { cir.setReturnValue(this.addEntity(factory.apply(loc), CreatureSpawnEvent.SpawnReason.CUSTOM)); } @@ -41,6 +41,6 @@ public abstract class CraftWorldMixin { */ @Overwrite public File getWorldFolder() { - return ((ServerWorldBridge) this.world).bridge$getConvertable().getDimensionFolder(this.world.getDimensionKey()); + return ((ServerWorldBridge) this.world).bridge$getConvertable().getDimensionPath(this.world.dimension()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/EntityTypeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/EntityTypeMixin.java index 05fc5b1b..71fef4a0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/EntityTypeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/EntityTypeMixin.java @@ -4,8 +4,6 @@ import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge; import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.i18n.LocalizedException; import io.izzel.arclight.i18n.conf.EntityPropertySpec; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.v.CraftWorld; @@ -18,6 +16,8 @@ import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import java.util.function.Function; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; @Mixin(value = EntityType.class, remap = false) public class EntityTypeMixin implements EntityTypeBridge { @@ -28,12 +28,12 @@ public class EntityTypeMixin implements EntityTypeBridge { @Shadow @Final @Mutable private String name; // @formatter:on - private net.minecraft.entity.EntityType handleType; + private net.minecraft.world.entity.EntityType handleType; private EntityPropertySpec spec; - private Function factory; + private Function factory; @Override - public void bridge$setup(ResourceLocation location, net.minecraft.entity.EntityType entityType, EntityPropertySpec spec) { + public void bridge$setup(ResourceLocation location, net.minecraft.world.entity.EntityType entityType, EntityPropertySpec spec) { this.key = CraftNamespacedKey.fromMinecraft(location); this.name = location.toString(); this.handleType = entityType; @@ -60,10 +60,10 @@ public class EntityTypeMixin implements EntityTypeBridge { } this.factory = loc -> { if (loc != null && loc.getWorld() != null) { - ServerWorld world = ((CraftWorld) loc.getWorld()).getHandle(); - net.minecraft.entity.Entity entity = handleType.create(world); + ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle(); + net.minecraft.world.entity.Entity entity = handleType.create(world); if (entity != null) { - entity.setPositionAndRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); + entity.absMoveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); } return entity; } else return null; @@ -71,7 +71,7 @@ public class EntityTypeMixin implements EntityTypeBridge { } @Override - public net.minecraft.entity.EntityType bridge$getHandle() { + public net.minecraft.world.entity.EntityType bridge$getHandle() { return this.handleType; } @@ -81,12 +81,12 @@ public class EntityTypeMixin implements EntityTypeBridge { } @Override - public Function bridge$entityFactory() { + public Function bridge$entityFactory() { return factory; } @Override - public void bridge$setEntityFactory(Function function) { + public void bridge$setEntityFactory(Function function) { this.factory = function; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/MaterialMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/MaterialMixin.java index 184f6ceb..441869e6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/MaterialMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/MaterialMixin.java @@ -7,14 +7,6 @@ import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.server.block.ArclightTileInventory; import io.izzel.arclight.i18n.LocalizedException; import io.izzel.arclight.i18n.conf.MaterialPropertySpec; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.block.FallingBlock; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.block.BlockState; @@ -54,6 +46,14 @@ import java.lang.reflect.Constructor; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Container; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FallingBlock; +import net.minecraft.world.level.block.entity.BlockEntity; @Mixin(value = Material.class, remap = false) public abstract class MaterialMixin implements MaterialBridge { @@ -313,13 +313,13 @@ public abstract class MaterialMixin implements MaterialBridge { arclight$spec.record = false; } if (arclight$spec.solid == null) { - arclight$spec.solid = block != null && block.getDefaultState().isSolid(); + arclight$spec.solid = block != null && block.defaultBlockState().canOcclude(); } if (arclight$spec.air == null) { - arclight$spec.air = block != null && block.getDefaultState().isAir(); + arclight$spec.air = block != null && block.defaultBlockState().isAir(); } if (arclight$spec.transparent == null) { - arclight$spec.transparent = block != null && block.getDefaultState().isTransparent(); + arclight$spec.transparent = block != null && block.defaultBlockState().useShapeForLightOcclusion(); } if (arclight$spec.flammable == null) { arclight$spec.flammable = block != null && ((FireBlockBridge) Blocks.FIRE).bridge$canBurn(block); @@ -340,7 +340,7 @@ public abstract class MaterialMixin implements MaterialBridge { arclight$spec.interactable = true; } if (arclight$spec.hardness == null) { - arclight$spec.hardness = block != null ? block.getDefaultState().hardness : 0; + arclight$spec.hardness = block != null ? block.defaultBlockState().destroySpeed : 0; } if (arclight$spec.blastResistance == null) { arclight$spec.blastResistance = block != null ? block.getExplosionResistance() : 0; @@ -391,8 +391,8 @@ public abstract class MaterialMixin implements MaterialBridge { } if (this.arclight$stateFunc == null) { this.arclight$stateFunc = b -> { - TileEntity tileEntity = b.getCraftWorld().getHandle().getTileEntity(b.getPosition()); - if (tileEntity instanceof IInventory) { + BlockEntity tileEntity = b.getCraftWorld().getHandle().getBlockEntity(b.getPosition()); + if (tileEntity instanceof Container) { return new ArclightTileInventory(b, tileEntity.getClass()); } return tileEntity == null ? new CraftBlockState(b) : new CraftBlockEntityState<>(b, tileEntity.getClass()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/RecipeIteratorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/RecipeIteratorMixin.java index 2da95948..bd804104 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/RecipeIteratorMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/RecipeIteratorMixin.java @@ -1,9 +1,6 @@ package io.izzel.arclight.common.mixin.bukkit; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.util.ResourceLocation; import org.bukkit.craftbukkit.v.inventory.RecipeIterator; import org.bukkit.inventory.Recipe; import org.spongepowered.asm.mixin.Final; @@ -13,13 +10,15 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.Iterator; import java.util.Map; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.RecipeType; @Mixin(value = RecipeIterator.class, remap = false) public class RecipeIteratorMixin { // @formatter:off - @Shadow private Iterator> current; - @Shadow @Final private Iterator, Map>>> recipes; + @Shadow private Iterator> current; + @Shadow @Final private Iterator, Map>>> recipes; // @formatter:on /** diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlockMixin.java deleted file mode 100644 index 472014ec..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlockMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.BlockState; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(AbstractBlock.class) -public abstract class AbstractBlockMixin { - - // @formatter:off - @Shadow public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { return null; } - // @formatter:on -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlock_AbstractBlockStateMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlock_AbstractBlockStateMixin.java deleted file mode 100644 index 899f3ab8..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractBlock_AbstractBlockStateMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.AbstractBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(AbstractBlock.AbstractBlockState.class) -public class AbstractBlock_AbstractBlockStateMixin { - - @Inject(method = "onEntityCollision", at = @At("HEAD")) - private void arclight$captureBlockCollide(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - ArclightCaptures.captureDamageEventBlock(pos); - } - - @Inject(method = "onEntityCollision", at = @At("RETURN")) - private void arclight$resetBlockCollide(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - ArclightCaptures.captureDamageEventBlock(null); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractFireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractFireBlockMixin.java deleted file mode 100644 index 0fd1e7d6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractFireBlockMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractFireBlock; -import net.minecraft.block.Blocks; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(AbstractFireBlock.class) -public class AbstractFireBlockMixin { - - @Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public boolean arclight$extinguish2(World world, BlockPos pos, boolean isMoving) { - if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.getDefaultState()).isCancelled()) { - world.removeBlock(pos, isMoving); - } - return false; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractPressurePlateBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractPressurePlateBlockMixin.java deleted file mode 100644 index 144e311b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractPressurePlateBlockMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractPressurePlateBlock; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.block.BlockRedstoneEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(AbstractPressurePlateBlock.class) -public abstract class AbstractPressurePlateBlockMixin { - - // @formatter:off - @Shadow protected abstract int computeRedstoneStrength(World worldIn, BlockPos pos); - @Shadow @Final protected static AxisAlignedBB PRESSURE_AABB; - // @formatter:on - - @Redirect(method = "updateState", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractPressurePlateBlock;computeRedstoneStrength(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I")) - public int arclight$blockRedstone(AbstractPressurePlateBlock abstractPressurePlateBlock, World worldIn, BlockPos pos, World world, BlockPos blockPos, BlockState state, int oldRedstoneStrength) { - int newStrength = this.computeRedstoneStrength(worldIn, pos); - boolean flag = oldRedstoneStrength > 0; - boolean flag1 = newStrength > 0; - - if (flag != flag1) { - BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(worldIn, blockPos), oldRedstoneStrength, newStrength); - Bukkit.getPluginManager().callEvent(event); - newStrength = event.getNewCurrent(); - } - return newStrength; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractTopPlantBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractTopPlantBlockMixin.java deleted file mode 100644 index b0098312..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractTopPlantBlockMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractTopPlantBlock; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.Random; - -@Mixin(AbstractTopPlantBlock.class) -public class AbstractTopPlantBlockMixin { - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private boolean arclight$blockGrow(ServerWorld world, BlockPos to, BlockState state, BlockState state1, ServerWorld worldIn, BlockPos from, Random random) { - return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooBlockMixin.java deleted file mode 100644 index 7cbe0031..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooBlockMixin.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BambooBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.state.EnumProperty; -import net.minecraft.state.IntegerProperty; -import net.minecraft.state.properties.BambooLeaves; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(BambooBlock.class) -public abstract class BambooBlockMixin extends BlockMixin { - - @Shadow @Final public static EnumProperty PROPERTY_BAMBOO_LEAVES; - @Shadow @Final public static IntegerProperty PROPERTY_AGE; - @Shadow @Final public static IntegerProperty PROPERTY_STAGE; - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void grow(BlockState blockStateIn, World worldIn, BlockPos posIn, Random rand, int height) { - BlockState blockstate = worldIn.getBlockState(posIn.down()); - BlockPos blockpos = posIn.down(2); - BlockState blockstate1 = worldIn.getBlockState(blockpos); - BambooLeaves bambooleaves = BambooLeaves.NONE; - - boolean update = false; - - if (height >= 1) { - if (blockstate.isIn(Blocks.BAMBOO) && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) { - if (blockstate.isIn(Blocks.BAMBOO) && blockstate.get(PROPERTY_BAMBOO_LEAVES) != BambooLeaves.NONE) { - bambooleaves = BambooLeaves.LARGE; - if (blockstate1.isIn(Blocks.BAMBOO)) { - update = true; - } - } - } else { - bambooleaves = BambooLeaves.SMALL; - } - } - - int newAge = blockStateIn.get(PROPERTY_AGE) != 1 && !blockstate1.isIn(Blocks.BAMBOO) ? 0 : 1; - int newState = (height < 11 || !(rand.nextFloat() < 0.25F)) && height != 15 ? 0 : 1; - - if (CraftEventFactory.handleBlockSpreadEvent(worldIn, posIn, posIn.up(), - this.getDefaultState().with(PROPERTY_AGE, newAge).with(PROPERTY_BAMBOO_LEAVES, bambooleaves).with(PROPERTY_STAGE, newState), 3)) { - if (update) { - worldIn.setBlockState(posIn.down(), blockstate.with(PROPERTY_BAMBOO_LEAVES, BambooLeaves.SMALL), 3); - worldIn.setBlockState(blockpos, blockstate1.with(PROPERTY_BAMBOO_LEAVES, BambooLeaves.NONE), 3); - } - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooSaplingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooSaplingBlockMixin.java deleted file mode 100644 index 735d6b8a..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BambooSaplingBlockMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BambooSaplingBlock; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BambooSaplingBlock.class) -public class BambooSaplingBlockMixin { - - @Redirect(method = "growBamboo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockSpread(World world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockSpreadEvent(world, pos.down(), pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BlockMixin.java deleted file mode 100644 index 55ab2cb3..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BlockMixin.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.block.BlockBridge; -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.common.extensions.IForgeBlock; -import org.bukkit.craftbukkit.v.CraftWorld; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.block.BlockBreakEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; -import java.util.List; - -@Mixin(Block.class) -public abstract class BlockMixin extends AbstractBlockMixin implements BlockBridge { - - // @formatter:off - @Shadow public abstract BlockState getDefaultState(); - @Shadow @Nullable public BlockState getStateForPlacement(BlockItemUseContext context) { return null; } - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public static void spawnAsEntity(World worldIn, BlockPos pos, ItemStack stack) { - if (!worldIn.isRemote && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.DO_TILE_DROPS) && !worldIn.restoringBlockSnapshots) { - float f = 0.5F; - double d0 = (double) (worldIn.rand.nextFloat() * 0.5F) + 0.25D; - double d1 = (double) (worldIn.rand.nextFloat() * 0.5F) + 0.25D; - double d2 = (double) (worldIn.rand.nextFloat() * 0.5F) + 0.25D; - ItemEntity itemEntity = new ItemEntity(worldIn, (double) pos.getX() + d0, (double) pos.getY() + d1, (double) pos.getZ() + d2, stack); - itemEntity.setDefaultPickupDelay(); - List blockDrops = ArclightCaptures.getBlockDrops(); - if (blockDrops == null) { - worldIn.addEntity(itemEntity); - } else { - blockDrops.add(itemEntity); - } - } - } - - public int getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack) { - int silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, itemStack); - int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack); - return ((IForgeBlock) this).getExpDrop(blockState, world, blockPos, fortune, silkTouch); - } - - @Override - public int bridge$getExpDrop(BlockState blockState, ServerWorld world, BlockPos blockPos, ItemStack itemStack) { - return getExpDrop(blockState, world, blockPos, itemStack); - } - - @Inject(method = "harvestBlock", at = @At("RETURN")) - private void arclight$handleBlockDrops(World worldIn, PlayerEntity player, BlockPos pos, BlockState blockState, TileEntity te, ItemStack stack, CallbackInfo ci) { - List blockDrops = ArclightCaptures.getBlockDrops(); - org.bukkit.block.BlockState state = ArclightCaptures.getBlockBreakPlayerState(); - BlockBreakEvent breakEvent = ArclightCaptures.resetBlockBreakPlayer(); - if (player instanceof ServerPlayerEntity && blockDrops != null && (breakEvent == null || breakEvent.isDropItems())) { - CraftBlock craftBlock = CraftBlock.at(((CraftWorld) state.getWorld()).getHandle(), pos); - CraftEventFactory.handleBlockDropItemEvent(craftBlock, state, ((ServerPlayerEntity) player), blockDrops); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BushBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BushBlockMixin.java deleted file mode 100644 index 5878991b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BushBlockMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.BushBlock; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BushBlock.class) -public abstract class BushBlockMixin extends BlockMixin { - - @Redirect(method = "updatePostPlacement", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDefaultState()Lnet/minecraft/block/BlockState;")) - public BlockState arclight$blockFade(Block block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (!CraftEventFactory.callBlockPhysicsEvent(worldIn, currentPos).isCancelled()) { - return block.getDefaultState(); - } else { - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CakeBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CakeBlockMixin.java deleted file mode 100644 index dd4326cd..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CakeBlockMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.CakeBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.FoodStats; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CakeBlock.class) -public class CakeBlockMixin { - - @Redirect(method = "eatSlice", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/FoodStats;addStats(IF)V")) - private void arclight$eatCake(FoodStats foodStats, int foodLevelIn, float foodSaturationModifier, IWorld worldIn, BlockPos pos, BlockState state, PlayerEntity player) { - int old = foodStats.getFoodLevel(); - FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(player, old + foodLevelIn); - if (!event.isCancelled()) { - foodStats.addStats(event.getFoodLevel() - old, foodSaturationModifier); - } - ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().sendHealthUpdate(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CampfireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CampfireBlockMixin.java deleted file mode 100644 index a9c7e6c6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CampfireBlockMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.CampfireBlock; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(CampfireBlock.class) -public class CampfireBlockMixin { - - @Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$onFire(World worldIn, BlockState state, BlockRayTraceResult hit, ProjectileEntity projectile, CallbackInfo ci) { - if (CraftEventFactory.callBlockIgniteEvent(worldIn, hit.getPos(), projectile).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CauldronBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CauldronBlockMixin.java deleted file mode 100644 index 141366c7..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CauldronBlockMixin.java +++ /dev/null @@ -1,103 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.CauldronBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.potion.PotionUtils; -import net.minecraft.potion.Potions; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.block.CauldronLevelChangeEvent; -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.CallbackInfoReturnable; - -@Mixin(CauldronBlock.class) -public class CauldronBlockMixin { - - @Inject(method = "onEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;extinguish()V")) - public void arclight$extinguish(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - int i = state.get(CauldronBlock.LEVEL); - if (!changeLevel(worldIn, pos, state, i - 1, entityIn, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH)) { - ci.cancel(); - } - } - - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;abilities:Lnet/minecraft/entity/player/PlayerAbilities;")) - public void arclight$levelChange(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - ItemStack itemStack = player.getHeldItem(handIn); - Item item = itemStack.getItem(); - int i = state.get(CauldronBlock.LEVEL); - int newLevel; - CauldronLevelChangeEvent.ChangeReason reason; - if (item == Items.WATER_BUCKET) { - reason = CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY; - newLevel = 3; - } else if (item == Items.BUCKET) { - reason = CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL; - newLevel = 0; - } else if (item == Items.GLASS_BOTTLE) { - reason = CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL; - newLevel = i - 1; - } else if (item == Items.POTION && PotionUtils.getPotionFromItem(itemStack) == Potions.WATER) { - reason = CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY; - newLevel = i + 1; - } else { - reason = null; - newLevel = 0; - } - if (reason != null && !changeLevel(worldIn, pos, state, newLevel, player, reason)) { - cir.setReturnValue(ActionResultType.SUCCESS); - } - } - - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/IDyeableArmorItem;removeColor(Lnet/minecraft/item/ItemStack;)V")) - public void arclight$removeColor(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - int i = state.get(CauldronBlock.LEVEL); - if (!changeLevel(worldIn, pos, state, i - 1, player, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) { - cir.setReturnValue(ActionResultType.SUCCESS); - } - } - - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/BannerTileEntity;removeBannerData(Lnet/minecraft/item/ItemStack;)V")) - public void arclight$removeBanner(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - int i = state.get(CauldronBlock.LEVEL); - if (!changeLevel(worldIn, pos, state, i - 1, player, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) { - cir.setReturnValue(ActionResultType.SUCCESS); - } - } - - @Inject(method = "fillWithRain", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$fillRain(World worldIn, BlockPos pos, CallbackInfo ci) { - BlockState state = worldIn.getBlockState(pos); - BlockState cycle = state.cycleValue(CauldronBlock.LEVEL); - int newLevel = cycle.get(CauldronBlock.LEVEL); - if (!changeLevel(worldIn, pos, state, newLevel, null, CauldronLevelChangeEvent.ChangeReason.UNKNOWN)) { - ci.cancel(); - } - } - - private boolean changeLevel(World world, BlockPos pos, BlockState state, int i, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { - int newLevel = MathHelper.clamp(i, 0, 3); - CauldronLevelChangeEvent event = new CauldronLevelChangeEvent( - CraftBlock.at(world, pos), - (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), - reason, state.get(CauldronBlock.LEVEL), newLevel - ); - Bukkit.getPluginManager().callEvent(event); - return !event.isCancelled(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChestBlock2Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChestBlock2Mixin.java deleted file mode 100644 index ba53ebe5..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChestBlock2Mixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.mod.util.ChestBlockDoubleInventoryHacks; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.tileentity.ChestTileEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -import java.util.Optional; - -@Mixin(targets = "net/minecraft/block/ChestBlock$2") -public class ChestBlock2Mixin { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public Optional func_225539_a_(final ChestTileEntity p_225539_1_, final ChestTileEntity p_225539_2_) { - final DoubleSidedInventory iinventory = new DoubleSidedInventory(p_225539_1_, p_225539_2_); - return Optional.ofNullable(ChestBlockDoubleInventoryHacks.create(p_225539_1_, p_225539_2_, iinventory)); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CocoaBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CocoaBlockMixin.java deleted file mode 100644 index 2e19316f..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CocoaBlockMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.CocoaBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CocoaBlock.class) -public class CocoaBlockMixin { - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockGrow1(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } - - @Redirect(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private boolean arclight$blockGrow2(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CommandBlockBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CommandBlockBlockMixin.java deleted file mode 100644 index 4121abc3..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CommandBlockBlockMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CommandBlockBlock; -import net.minecraft.tileentity.CommandBlockTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.block.BlockRedstoneEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(CommandBlockBlock.class) -public abstract class CommandBlockBlockMixin { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { - if (!worldIn.isRemote) { - TileEntity tileentity = worldIn.getTileEntity(pos); - if (tileentity instanceof CommandBlockTileEntity) { - CommandBlockTileEntity commandblocktileentity = (CommandBlockTileEntity) tileentity; - boolean flag = worldIn.isBlockPowered(pos); - boolean flag1 = commandblocktileentity.isPowered(); - - org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldIn, pos); - int old = flag1 ? 15 : 0; - int current = flag ? 15 : 0; - BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current); - Bukkit.getPluginManager().callEvent(eventRedstone); - flag = eventRedstone.getNewCurrent() > 0; - - commandblocktileentity.setPowered(flag); - if (!flag1 && !commandblocktileentity.isAuto() && commandblocktileentity.getMode() != CommandBlockTileEntity.Mode.SEQUENCE) { - if (flag) { - commandblocktileentity.setConditionMet(); - worldIn.getPendingBlockTicks().scheduleTick(pos, (CommandBlockBlock) (Object) this, 1); - } - - } - } - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComparatorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComparatorBlockMixin.java deleted file mode 100644 index f61fc5ac..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComparatorBlockMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.ComparatorBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ComparatorBlock.class) -public class ComparatorBlockMixin { - - @Inject(method = "onStateChange", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockRedstone1(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci) { - if (CraftEventFactory.callRedstoneChange(worldIn, pos, 15, 0).getNewCurrent() != 0) { - ci.cancel(); - } - } - - @Inject(method = "onStateChange", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockRedstone2(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci) { - if (CraftEventFactory.callRedstoneChange(worldIn, pos, 0, 15).getNewCurrent() != 15) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_FullInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_FullInventoryMixin.java deleted file mode 100644 index 2a986190..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_FullInventoryMixin.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComposterBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.block.ComposterBlock$FullInventory") -public abstract class ComposterBlock_FullInventoryMixin extends InventoryMixin { - - // @formatter:off - @Shadow @Final private BlockState state; - @Shadow @Final private IWorld world; - @Shadow @Final private BlockPos pos; - @Shadow private boolean extracted; - // @formatter:on - - @Inject(method = "(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/ItemStack;)V", at = @At("RETURN")) - public void arclight$setOwner(BlockState blockState, IWorld world, BlockPos blockPos, ItemStack itemStack, CallbackInfo ci) { - this.setOwner(new CraftBlockInventoryHolder(world, blockPos, this)); - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void markDirty() { - if (this.isEmpty()) { - ComposterBlock.resetFillState(this.state, this.world, this.pos); - this.extracted = true; - } else { - this.world.setBlockState(this.pos, this.state, 3); - this.extracted = false; - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_PartialInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_PartialInventoryMixin.java deleted file mode 100644 index d31ae7f6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_PartialInventoryMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.block.ComposterBlock$PartialInventory") -public abstract class ComposterBlock_PartialInventoryMixin extends InventoryMixin { - - @Inject(method = "(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)V", at = @At("RETURN")) - public void arclight$setOwner(BlockState blockState, IWorld world, BlockPos blockPos, CallbackInfo ci) { - this.setOwner(new CraftBlockInventoryHolder(world, blockPos, this)); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralFinBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralFinBlockMixin.java deleted file mode 100644 index cf462861..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralFinBlockMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractCoralPlantBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralFinBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(CoralFinBlock.class) -public class CoralFinBlockMixin { - - // @formatter:off - @Shadow @Final private Block deadBlock; - // @formatter:on - - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.getDefaultState().with(AbstractCoralPlantBlock.WATERLOGGED, false)).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralWallFanBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralWallFanBlockMixin.java deleted file mode 100644 index 03773f04..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralWallFanBlockMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.AbstractCoralPlantBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralWallFanBlock; -import net.minecraft.block.DeadCoralWallFanBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(CoralWallFanBlock.class) -public class CoralWallFanBlockMixin { - - // @formatter:off - @Shadow @Final private Block deadBlock; - // @formatter:on - - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.getDefaultState() - .with(AbstractCoralPlantBlock.WATERLOGGED, Boolean.FALSE) - .with(DeadCoralWallFanBlock.FACING, state.get(DeadCoralWallFanBlock.FACING))).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CropsBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CropsBlockMixin.java deleted file mode 100644 index 05306608..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CropsBlockMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.CropsBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.ForgeEventFactory; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CropsBlock.class) -public class CropsBlockMixin { - - @Redirect(method = "grow(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockGrowGrow(World world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } - - @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;)Z")) - public boolean arclight$entityChangeBlock(World world, Entity entity, BlockState state, World worldIn, BlockPos pos) { - boolean result = ForgeEventFactory.getMobGriefingEvent(world, entity); - EntityChangeBlockEvent event = CraftEventFactory.callEntityChangeBlockEvent(entity, pos, state, result); - return event.isCancelled(); - } - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockGrowTick(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DaylightDetectorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DaylightDetectorBlockMixin.java deleted file mode 100644 index 35cb36d9..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DaylightDetectorBlockMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.DaylightDetectorBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -@Mixin(DaylightDetectorBlock.class) -public class DaylightDetectorBlockMixin { - - @ModifyVariable(method = "updatePower", index = 3, name = "i", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static int arclight$blockRedstone(int i, BlockState blockState, World world, BlockPos blockPos) { - return CraftEventFactory.callRedstoneChange(world, blockPos, blockState.get(DaylightDetectorBlock.POWER), i).getNewCurrent(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DispenserBlockMixin_Accessor.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DispenserBlockMixin_Accessor.java deleted file mode 100644 index da9dbe5c..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DispenserBlockMixin_Accessor.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.DispenserBlock; -import net.minecraft.dispenser.IDispenseItemBehavior; -import net.minecraft.item.Item; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(DispenserBlock.class) -public interface DispenserBlockMixin_Accessor { - - @Accessor("DISPENSE_BEHAVIOR_REGISTRY") - static Map getDispenseBehaviorRegistry() { - return null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoublePlantBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoublePlantBlockMixin.java deleted file mode 100644 index 05b17160..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoublePlantBlockMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.DoublePlantBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(DoublePlantBlock.class) -public class DoublePlantBlockMixin { - - @Inject(method = "onBlockHarvested", cancellable = true, at = @At("HEAD")) - public void arclight$blockPhysics(World worldIn, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) { - if (CraftEventFactory.callBlockPhysicsEvent(worldIn, pos).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FallingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FallingBlockMixin.java deleted file mode 100644 index 684b67de..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FallingBlockMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.FallingBlock; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(FallingBlock.class) -public abstract class FallingBlockMixin extends BlockMixin { - - // @formatter:off - @Shadow public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { return null; } - // @formatter:on -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FarmlandBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FarmlandBlockMixin.java deleted file mode 100644 index 77a84d82..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FarmlandBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FarmlandBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(FarmlandBlock.class) -public abstract class FarmlandBlockMixin extends BlockMixin { - - @Inject(method = "turnToDirt", cancellable = true, at = @At("HEAD")) - private static void arclight$blockFade(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$moistureChange(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleMoistureChangeEvent(world, pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FlowingFluidBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FlowingFluidBlockMixin.java deleted file mode 100644 index baa98550..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FlowingFluidBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.FlowingFluidBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(FlowingFluidBlock.class) -public class FlowingFluidBlockMixin { - - private transient boolean arclight$fizz = true; - - @Redirect(method = "reactWithNeighbors", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public boolean arclight$blockForm(World world, BlockPos pos, BlockState state) { - return arclight$fizz = CraftEventFactory.handleBlockFormEvent(world, pos, state); - } - - @Inject(method = "triggerMixEffects", cancellable = true, at = @At("HEAD")) - public void arclight$fizz(IWorld worldIn, BlockPos pos, CallbackInfo ci) { - if (!arclight$fizz) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/GrassBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/GrassBlockMixin.java deleted file mode 100644 index 2c42b23b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/GrassBlockMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.GrassBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(GrassBlock.class) -public class GrassBlockMixin { - - @Redirect(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/IceBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/IceBlockMixin.java deleted file mode 100644 index 0e9e4a03..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/IceBlockMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.IceBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(IceBlock.class) -public class IceBlockMixin { - - @Inject(method = "turnIntoWater", cancellable = true, at = @At("HEAD")) - public void arclight$blockFade(BlockState blockState, World world, BlockPos blockPos, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(world, blockPos, world.getDimensionType().isUltrawarm() - ? Blocks.AIR.getDefaultState() : Blocks.WATER.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LecternBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LecternBlockMixin.java deleted file mode 100644 index 7c953b27..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LecternBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.LecternBlock; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.LecternTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(LecternBlock.class) -public class LecternBlockMixin { - - @Redirect(method = "dropBook", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getTileEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/tileentity/TileEntity;")) - private TileEntity arclight$noValidate(World world, BlockPos pos) { - return ((WorldBridge) world).bridge$getTileEntity(pos, false); - } - - @Inject(method = "dropBook", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Direction;getXOffset()I")) - private void arclight$returnIfEmpty(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci, TileEntity tileEntity, LecternTileEntity lecternTileEntity, Direction direction, ItemStack itemStack) { - if (itemStack.isEmpty()) ci.cancel(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LilyPadBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LilyPadBlockMixin.java deleted file mode 100644 index 3c640f79..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LilyPadBlockMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.LilyPadBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(LilyPadBlock.class) -public class LilyPadBlockMixin { - - @Inject(method = "onEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;destroyBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) - public void arclight$entityChangeBlock(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - if (CraftEventFactory.callEntityChangeBlockEvent(entityIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MagmaBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MagmaBlockMixin.java deleted file mode 100644 index 6042a1cc..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MagmaBlockMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.MagmaBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(MagmaBlock.class) -public class MagmaBlockMixin { - - @Inject(method = "onEntityWalk", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - public void arclight$blockDamagePre(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - CraftEventFactory.blockDamage = CraftBlock.at(worldIn, pos); - } - - @Inject(method = "onEntityWalk", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - public void arclight$blockDamagePost(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - CraftEventFactory.blockDamage = null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NoteBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NoteBlockMixin.java deleted file mode 100644 index 050a0010..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NoteBlockMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.block.NoteBlockBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.NoteBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.block.NotePlayEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(NoteBlock.class) -public abstract class NoteBlockMixin implements NoteBlockBridge { - - // @formatter:off - @Shadow protected abstract void triggerNote(World worldIn, BlockPos pos); - // @formatter:on - - @Redirect(method = "onBlockActivated", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/NoteBlock;triggerNote(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$callNote2(NoteBlock noteBlock, World worldIn, BlockPos pos, BlockState blockState) { - this.bridge$play(worldIn, pos, blockState); - } - - @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/NoteBlock;triggerNote(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$callNote1(NoteBlock noteBlock, World worldIn, BlockPos pos, BlockState blockState) { - this.play(worldIn, pos, blockState); - } - - @Redirect(method = "onBlockClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/NoteBlock;triggerNote(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$callNote3(NoteBlock noteBlock, World worldIn, BlockPos pos, BlockState blockState) { - this.play(worldIn, pos, blockState); - } - - private transient BlockState arclight$state; - - private void play(World worldIn, BlockPos pos, BlockState state) { - arclight$state = state; - this.triggerNote(worldIn, pos); - arclight$state = null; - } - - @Override - public void bridge$play(World worldIn, BlockPos pos, BlockState state) { - this.play(worldIn, pos, state); - } - - @Inject(method = "triggerNote", cancellable = true, require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addBlockEvent(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;II)V")) - private void arclight$notePlay(World worldIn, BlockPos pos, CallbackInfo ci) { - NotePlayEvent event = CraftEventFactory.callNotePlayEvent(worldIn, pos, arclight$state.get(NoteBlock.INSTRUMENT), arclight$state.get(NoteBlock.NOTE)); - if (event.isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalSizeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalSizeMixin.java deleted file mode 100644 index 41646c6e..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalSizeMixin.java +++ /dev/null @@ -1,107 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.block.PortalInfoBridge; -import io.izzel.arclight.common.bridge.block.PortalSizeBridge; -import io.izzel.arclight.common.bridge.world.IWorldBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.AbstractBlock; -import net.minecraft.block.Blocks; -import net.minecraft.block.NetherPortalBlock; -import net.minecraft.block.PortalInfo; -import net.minecraft.block.PortalSize; -import net.minecraft.entity.EntitySize; -import net.minecraft.util.Direction; -import net.minecraft.util.TeleportationRepositioner; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.block.BlockState; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.block.CraftBlockState; -import org.bukkit.craftbukkit.v.event.CraftPortalEvent; -import org.bukkit.event.world.PortalCreateEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - -@Mixin(PortalSize.class) -public abstract class PortalSizeMixin implements PortalSizeBridge { - - // @formatter:off - @Shadow @Final private IWorld world; - @Shadow public abstract void placePortalBlocks(); - @Shadow @Final private Direction.Axis axis; - @Shadow @Nullable private BlockPos bottomLeft; - @Shadow private int height; - @Shadow @Final private Direction rightDir; - @Shadow private int width; - @Shadow public static PortalInfo func_242963_a(ServerWorld world, TeleportationRepositioner.Result result, Direction.Axis axis, Vector3d offsetVector, EntitySize size, Vector3d motion, float rotationYaw, float rotationPitch) { return null; } - // @formatter:on - - List blocks = new ArrayList<>(); - - @Redirect(method = "func_242972_a", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/block/AbstractBlock$IPositionPredicate;test(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;)Z")) - private boolean arclight$captureBlock(AbstractBlock.IPositionPredicate predicate, net.minecraft.block.BlockState p_test_1_, IBlockReader p_test_2_, BlockPos pos) { - boolean test = predicate.test(p_test_1_, p_test_2_, pos); - if (test) { - blocks.add(CraftBlock.at(this.world, pos).getState()); - } - return test; - } - - @Inject(method = "placePortalBlocks", cancellable = true, at = @At("HEAD")) - private void arclight$buildPortal(CallbackInfo ci) { - World world = ((WorldBridge) ((IWorldBridge) this.world).bridge$getMinecraftWorld()).bridge$getWorld(); - net.minecraft.block.BlockState blockState = Blocks.NETHER_PORTAL.getDefaultState().with(NetherPortalBlock.AXIS, this.axis); - BlockPos.getAllInBoxMutable(this.bottomLeft, this.bottomLeft.offset(Direction.UP, this.height - 1).offset(this.rightDir, this.width - 1)).forEach(pos -> { - CraftBlockState state = CraftBlockState.getBlockState(((IWorldBridge) this.world).bridge$getMinecraftWorld(), pos, 18); - state.setData(blockState); - this.blocks.add(state); - }); - PortalCreateEvent event = new PortalCreateEvent(this.blocks, world, null, PortalCreateEvent.CreateReason.FIRE); - Bukkit.getPluginManager().callEvent(event); - arclight$ret = !event.isCancelled(); - if (event.isCancelled()) { - ci.cancel(); - } - } - - private transient boolean arclight$ret; - - public boolean createPortal() { - this.placePortalBlocks(); - return arclight$ret; - } - - @Override - public boolean bridge$createPortal() { - return createPortal(); - } - - @SuppressWarnings("ConstantConditions") - @Redirect(method = "func_242963_a", at = @At(value = "NEW", target = "net/minecraft/block/PortalInfo")) - private static PortalInfo arclight$setPortalInfo(Vector3d pos, Vector3d motion, float rotationYaw, float rotationPitch, ServerWorld world) { - PortalInfo portalInfo = new PortalInfo(pos, motion, rotationYaw, rotationPitch); - ((PortalInfoBridge) portalInfo).bridge$setWorld(world); - ((PortalInfoBridge) portalInfo).bridge$setPortalEventInfo(ArclightCaptures.getCraftPortalEvent()); - return portalInfo; - } - - private static PortalInfo a(ServerWorld world, TeleportationRepositioner.Result result, Direction.Axis axis, Vector3d offsetVector, EntitySize size, Vector3d motion, float rotationYaw, float rotationPitch, CraftPortalEvent event) { - ArclightCaptures.captureCraftPortalEvent(event); - return func_242963_a(world, result, axis, offsetVector, size, motion, rotationYaw, rotationPitch); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneOreBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneOreBlockMixin.java deleted file mode 100644 index 756c822f..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneOreBlockMixin.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneOreBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityInteractEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Random; - -@Mixin(RedstoneOreBlock.class) -public abstract class RedstoneOreBlockMixin { - - // @formatter:off - @Shadow private static void activate(BlockState state, World world, BlockPos pos) { } - // @formatter:on - - private static transient Entity arclight$entity; - - @Inject(method = "onBlockClicked", at = @At(value = "HEAD")) - public void arclight$interact1(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, CallbackInfo ci) { - arclight$entity = player; - } - - @Inject(method = "onEntityWalk", cancellable = true, at = @At(value = "HEAD")) - public void arclight$entityInteract(World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - if (entityIn instanceof PlayerEntity) { - PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(((PlayerEntity) entityIn), Action.PHYSICAL, pos, null, null, null); - if (event.isCancelled()) { - ci.cancel(); - return; - } - } else { - EntityInteractEvent event = new EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos)); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - ci.cancel(); - return; - } - } - arclight$entity = entityIn; - } - - @Inject(method = "onBlockActivated", at = @At(value = "HEAD")) - public void arclight$interact3(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - arclight$entity = player; - } - - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, state.with(RedstoneOreBlock.LIT, false)).isCancelled()) { - ci.cancel(); - } - } - - private static void interact(BlockState blockState, World world, BlockPos blockPos, Entity entity) { - arclight$entity = entity; - activate(blockState, world, blockPos); - } - - @Inject(method = "activate", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static void arclight$entityChangeBlock(BlockState blockState, World world, BlockPos blockPos, CallbackInfo ci) { - if (CraftEventFactory.callEntityChangeBlockEvent(arclight$entity, blockPos, blockState.with(RedstoneOreBlock.LIT, true)).isCancelled()) { - ci.cancel(); - } - arclight$entity = null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneWireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneWireBlockMixin.java deleted file mode 100644 index 19ea02a1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneWireBlockMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneWireBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.block.BlockRedstoneEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(RedstoneWireBlock.class) -public abstract class RedstoneWireBlockMixin { - - // @formatter:off - @Shadow protected abstract int getStrongestSignal(World world, BlockPos pos); - // @formatter:on - - @Redirect(method = "updatePower", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;getStrongestSignal(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I")) - public int arclight$blockRedstone(RedstoneWireBlock redstoneWireBlock, World world, BlockPos pos, World world1, BlockPos pos1, BlockState state) { - int i = this.getStrongestSignal(world, pos); - int oldPower = state.get(RedstoneWireBlock.POWER); - if (oldPower != i) { - BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), oldPower, i); - Bukkit.getPluginManager().callEvent(event); - i = event.getNewCurrent(); - } - return i; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ScaffoldingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ScaffoldingBlockMixin.java deleted file mode 100644 index 711fb0c4..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ScaffoldingBlockMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.ScaffoldingBlock; -import net.minecraft.state.Property; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.Random; - -@Mixin(ScaffoldingBlock.class) -public class ScaffoldingBlockMixin { - - @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/Property;)Ljava/lang/Comparable;")) - public Comparable arclight$blockFade(BlockState state, Property property, BlockState blockState, ServerWorld worldIn, BlockPos pos, Random random) { - Integer integer = state.get(property); - if (integer == 7) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { - return 6; - } else { - return integer; - } - } else { - return integer; - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SilverfishBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SilverfishBlockMixin.java deleted file mode 100644 index fc12bd4e..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SilverfishBlockMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.SilverfishBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(SilverfishBlock.class) -public class SilverfishBlockMixin { - - @Inject(method = "spawnSilverFish", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public void arclight$spawn(ServerWorld world, BlockPos pos, CallbackInfo ci) { - ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SnowBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SnowBlockMixin.java deleted file mode 100644 index 20ea3288..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SnowBlockMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.SnowBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(SnowBlock.class) -public class SnowBlockMixin { - - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/SnowBlock;spawnDrops(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpreadableSnowyDirtBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpreadableSnowyDirtBlockMixin.java deleted file mode 100644 index bc884920..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpreadableSnowyDirtBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.SpreadableSnowyDirtBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(SpreadableSnowyDirtBlock.class) -public class SpreadableSnowyDirtBlockMixin { - - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public boolean arclight$blockSpread(ServerWorld world, BlockPos to, BlockState state, BlockState state1, ServerWorld worldIn, BlockPos from) { - return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/StemBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/StemBlockMixin.java deleted file mode 100644 index 53fdecc2..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/StemBlockMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.StemBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(StemBlock.class) -public class StemBlockMixin { - - private transient boolean arclight$success = false; - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$cropGrow1(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } - - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public void arclight$returnIfFail(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (!arclight$success) { - ci.cancel(); - } - arclight$success = false; - } - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public boolean arclight$cropGrow2(ServerWorld world, BlockPos pos, BlockState state) { - return arclight$success = CraftEventFactory.handleBlockGrowEvent(world, pos, state); - } - - @Redirect(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$cropGrow3(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SugarCaneBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SugarCaneBlockMixin.java deleted file mode 100644 index f5ed2d62..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SugarCaneBlockMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.SugarCaneBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(SugarCaneBlock.class) -public class SugarCaneBlockMixin { - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState state) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, state); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SweetBerryBushBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SweetBerryBushBlockMixin.java deleted file mode 100644 index de6978b1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SweetBerryBushBlockMixin.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.SweetBerryBushBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.inventory.CraftItemStack; -import org.bukkit.event.player.PlayerHarvestBlockEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Collections; - -@Mixin(SweetBerryBushBlock.class) -public class SweetBerryBushBlockMixin { - - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { - return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); - } - - @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - public void arclight$damagePre(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - CraftEventFactory.blockDamage = CraftBlock.at(worldIn, pos); - } - - @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - public void arclight$damagePost(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { - CraftEventFactory.blockDamage = null; - } - - @Redirect(method = "onBlockActivated", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/SweetBerryBushBlock;spawnAsEntity(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/ItemStack;)V")) - private void arclight$playerHarvest(World worldIn, BlockPos pos, ItemStack stack, BlockState state, World worldIn1, BlockPos pos1, PlayerEntity player) { - PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(worldIn, pos, player, Collections.singletonList(stack)); - arclight$ret = event.isCancelled(); - if (!event.isCancelled()) { - for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) { - Block.spawnAsEntity(worldIn, pos, CraftItemStack.asNMSCopy(itemStack)); - } - } - } - - private transient boolean arclight$ret; - - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) - private void arclight$returnIfFail(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - if (arclight$ret) { - cir.setReturnValue(ActionResultType.SUCCESS); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TNTBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TNTBlockMixin.java deleted file mode 100644 index 865ad09e..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TNTBlockMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.TNTBlock; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TNTBlock.class) -public class TNTBlockMixin { - - @Inject(method = "onProjectileCollision", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/block/TNTBlock;catchFire(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/Direction;Lnet/minecraft/entity/LivingEntity;)V")) - public void arclight$entityChangeBlock(World worldIn, BlockState state, BlockRayTraceResult hit, ProjectileEntity projectile, CallbackInfo ci) { - if (CraftEventFactory.callEntityChangeBlockEvent(projectile, hit.getPos(), Blocks.AIR.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/VineBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/VineBlockMixin.java deleted file mode 100644 index db436371..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/VineBlockMixin.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.VineBlock; -import net.minecraft.state.BooleanProperty; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(VineBlock.class) -public abstract class VineBlockMixin extends BlockMixin { - - // @formatter:off - @Shadow public static BooleanProperty getPropertyFor(Direction side) { return null; } - @Shadow protected abstract boolean hasVineBelow(IBlockReader blockReader, BlockPos pos); - @Shadow public static boolean canAttachTo(IBlockReader blockReader, BlockPos worldIn, Direction neighborPos) { return false; } - @Shadow @Final public static BooleanProperty UP; - @Shadow protected abstract boolean hasAttachment(IBlockReader blockReader, BlockPos pos, Direction direction); - @Shadow protected abstract boolean isFacingCardinal(BlockState state); - @Shadow protected abstract BlockState func_196544_a(BlockState state, BlockState state2, Random rand); - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @SuppressWarnings("ConstantConditions") - @Overwrite - public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { - if (worldIn.rand.nextInt(4) == 0 && worldIn.isAreaLoaded(pos, 4)) { // Forge: check area to prevent loading unloaded chunks - Direction direction = Direction.getRandomDirection(random); - BlockPos blockpos = pos.up(); - if (direction.getAxis().isHorizontal() && !state.get(getPropertyFor(direction))) { - if (this.hasVineBelow(worldIn, pos)) { - BlockPos blockpos4 = pos.offset(direction); - BlockState blockstate4 = worldIn.getBlockState(blockpos4); - if (blockstate4.isAir(worldIn, blockpos4)) { - Direction direction3 = direction.rotateY(); - Direction direction4 = direction.rotateYCCW(); - boolean flag = state.get(getPropertyFor(direction3)); - boolean flag1 = state.get(getPropertyFor(direction4)); - BlockPos blockpos2 = blockpos4.offset(direction3); - BlockPos blockpos3 = blockpos4.offset(direction4); - if (flag && canAttachTo(worldIn, blockpos2, direction3)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction3), Boolean.TRUE), 2); - } else if (flag1 && canAttachTo(worldIn, blockpos3, direction4)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(getPropertyFor(direction4), Boolean.TRUE), 2); - } else { - Direction direction1 = direction.getOpposite(); - if (flag && worldIn.isAirBlock(blockpos2) && canAttachTo(worldIn, pos.offset(direction3), direction1)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos2, this.getDefaultState().with(getPropertyFor(direction1), Boolean.TRUE), 2); - } else if (flag1 && worldIn.isAirBlock(blockpos3) && canAttachTo(worldIn, pos.offset(direction4), direction1)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos3, this.getDefaultState().with(getPropertyFor(direction1), Boolean.TRUE), 2); - } else if ((double) worldIn.rand.nextFloat() < 0.05D && canAttachTo(worldIn, blockpos4.up(), Direction.UP)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.getDefaultState().with(UP, Boolean.TRUE), 2); - } - } - } else if (canAttachTo(worldIn, blockpos4, direction)) { - worldIn.setBlockState(pos, state.with(getPropertyFor(direction), Boolean.TRUE), 2); - } - - } - } else { - if (direction == Direction.UP && pos.getY() < 255) { - if (this.hasAttachment(worldIn, pos, direction)) { - worldIn.setBlockState(pos, state.with(UP, Boolean.TRUE), 2); - return; - } - - if (worldIn.isAirBlock(blockpos)) { - if (!this.hasVineBelow(worldIn, pos)) { - return; - } - - BlockState blockstate3 = state; - - for (Direction direction2 : Direction.Plane.HORIZONTAL) { - if (random.nextBoolean() || !canAttachTo(worldIn, blockpos.offset(direction2), Direction.UP)) { - blockstate3 = blockstate3.with(getPropertyFor(direction2), Boolean.FALSE); - } - } - - if (this.isFacingCardinal(blockstate3)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, blockstate3, 2); - } - - return; - } - } - - if (pos.getY() > 0) { - BlockPos blockpos1 = pos.down(); - BlockState blockstate = worldIn.getBlockState(blockpos1); - boolean isAir = blockstate.isAir(worldIn, blockpos1); - if (isAir || blockstate.isIn((Block) (Object) this)) { - BlockState blockstate1 = isAir ? this.getDefaultState() : blockstate; - BlockState blockstate2 = this.func_196544_a(state, blockstate1, random); - if (blockstate1 != blockstate2 && this.isFacingCardinal(blockstate2)) { - CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, blockstate2, 2); - } - } - } - } - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherSkeletonSkullBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherSkeletonSkullBlockMixin.java deleted file mode 100644 index 86acbea9..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherSkeletonSkullBlockMixin.java +++ /dev/null @@ -1,60 +0,0 @@ -package io.izzel.arclight.common.mixin.core.block; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.WitherSkeletonSkullBlock; -import net.minecraft.entity.Entity; -import net.minecraft.tileentity.SkullTileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.util.Constants; -import org.bukkit.craftbukkit.v.util.BlockStateListPopulator; -import org.bukkit.event.entity.CreatureSpawnEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(WitherSkeletonSkullBlock.class) -public class WitherSkeletonSkullBlockMixin { - - private static transient BlockStateListPopulator arclight$populator; - private static transient boolean arclight$success = false; - - @Redirect(method = "checkWitherSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static boolean arclight$storeUpdate1(World world, BlockPos pos, BlockState newState, int flags) { - if (arclight$populator == null) { - arclight$populator = new BlockStateListPopulator(world); - } - return arclight$populator.setBlockState(pos, newState, flags); - } - - @Redirect(method = "checkWitherSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playEvent(ILnet/minecraft/util/math/BlockPos;I)V")) - private static void arclight$storeUpdate2(World world, int type, BlockPos pos, int data) { - // do nothing - } - - @Inject(method = "checkWitherSpawn", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private static void arclight$returnIfFail(World worldIn, BlockPos blockPos, SkullTileEntity tileEntity, CallbackInfo ci) { - if (arclight$success) { - if (arclight$populator != null) { - for (BlockPos pos : arclight$populator.getBlocks()) { - worldIn.playEvent(Constants.WorldEvents.BREAK_BLOCK_EFFECTS, pos, Block.getStateId(worldIn.getBlockState(pos))); - } - arclight$populator.updateList(); - } - } else { - ci.cancel(); - } - arclight$populator = null; - arclight$success = false; - } - - @Redirect(method = "checkWitherSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private static boolean arclight$spawnWither(World world, Entity entityIn) { - ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BUILD_WITHER); - return arclight$success = world.addEntity(entityIn); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/ICommandSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/ICommandSourceMixin.java deleted file mode 100644 index 8216574a..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/ICommandSourceMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command; - -import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.ICommandSource; -import org.bukkit.command.CommandSender; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(ICommandSource.class) -public interface ICommandSourceMixin extends ICommandSourceBridge { - - default CommandSender getBukkitSender(CommandSource wrapper) { - return this.bridge$getBukkitSender(wrapper); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorMixin.java deleted file mode 100644 index 568b8620..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command.arguments; - -import io.izzel.arclight.common.bridge.command.CommandSourceBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.arguments.EntitySelector; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(EntitySelector.class) -public class EntitySelectorMixin { - - @Redirect(method = "checkPermission", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/CommandSource;hasPermissionLevel(I)Z")) - private boolean arclight$stringPermission(CommandSource commandSource, int level) { - return ((CommandSourceBridge) commandSource).bridge$hasPermission(level, "minecraft.command.selector"); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/GameRuleCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/GameRuleCommandMixin.java deleted file mode 100644 index ea16377c..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/GameRuleCommandMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command.impl; - -import com.mojang.brigadier.context.CommandContext; -import net.minecraft.command.CommandSource; -import net.minecraft.command.impl.GameRuleCommand; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.GameRules; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(GameRuleCommand.class) -public class GameRuleCommandMixin { - - @Redirect(method = "func_223485_b", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getGameRules()Lnet/minecraft/world/GameRules;")) - private static GameRules arclight$perWorldGameRule(MinecraftServer minecraftServer, CommandContext context) { - return context.getSource().getWorld().getGameRules(); - } - - @Redirect(method = "func_223486_b", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getGameRules()Lnet/minecraft/world/GameRules;")) - private static GameRules arclight$perWorldGameRule2(MinecraftServer minecraftServer, CommandSource source) { - return source.getWorld().getGameRules(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/ReloadCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/ReloadCommandMixin.java deleted file mode 100644 index 1cd6fce6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/ReloadCommandMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command.impl; - -import net.minecraft.command.impl.ReloadCommand; -import net.minecraft.resources.ResourcePackList; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.storage.IServerConfiguration; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Collection; - -@Mixin(ReloadCommand.class) -public abstract class ReloadCommandMixin { - - // @formatter:off - @Shadow private static Collection func_241058_a_(ResourcePackList p_241058_0_, IServerConfiguration p_241058_1_, Collection p_241058_2_) { return null; } - // @formatter:on - - private static void reload(MinecraftServer minecraftserver) { - ResourcePackList resourcePackList = minecraftserver.getResourcePacks(); - IServerConfiguration configuration = minecraftserver.getServerConfiguration(); - Collection collection = resourcePackList.func_232621_d_(); - Collection collection2 = func_241058_a_(resourcePackList, configuration, collection); - minecraftserver.func_240780_a_(collection2); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/SummonCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/SummonCommandMixin.java deleted file mode 100644 index a741be52..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/SummonCommandMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command.impl; - -import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.impl.SummonCommand; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.vector.Vector3d; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(SummonCommand.class) -public class SummonCommandMixin { - - @Inject(method = "summonEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntityAndUniquePassengers(Lnet/minecraft/entity/Entity;)Z")) - private static void arclight$summonReason(CommandSource source, ResourceLocation type, Vector3d pos, CompoundNBT nbt, boolean randomizeProperties, CallbackInfoReturnable cir) { - ((ServerWorldBridge) source.getWorld()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.COMMAND); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TeleportCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TeleportCommandMixin.java deleted file mode 100644 index 37d023f5..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TeleportCommandMixin.java +++ /dev/null @@ -1,116 +0,0 @@ -package io.izzel.arclight.common.mixin.core.command.impl; - -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.impl.TeleportCommand; -import net.minecraft.entity.CreatureEntity; -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.World; -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.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import javax.annotation.Nullable; -import java.util.Set; - -@Mixin(TeleportCommand.class) -public class TeleportCommandMixin { - - // @formatter:off - @Shadow @Final private static SimpleCommandExceptionType field_241077_a_; - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - private static void teleport(CommandSource source, Entity entityIn, ServerWorld worldIn, double x, double y, double z, Set relativeList, float yaw, float pitch, @Nullable TeleportCommand.Facing facing) throws CommandSyntaxException { - BlockPos blockpos = new BlockPos(x, y, z); - if (!World.isInvalidPosition(blockpos)) { - throw field_241077_a_.create(); - } else { - 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); - } - - 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(); - 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); - } - } - - 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.setOnGround(true); - } - - if (entityIn instanceof CreatureEntity) { - ((CreatureEntity) entityIn).getNavigator().clearPath(); - } - - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandNodeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandNodeMixin.java similarity index 80% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandNodeMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandNodeMixin.java index 35d26849..59647da0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandNodeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandNodeMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.command; +package io.izzel.arclight.common.mixin.core.commands; import com.mojang.brigadier.tree.ArgumentCommandNode; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import io.izzel.arclight.common.bridge.command.CommandNodeBridge; import io.izzel.arclight.common.bridge.command.CommandSourceBridge; -import net.minecraft.command.CommandSource; +import net.minecraft.commands.CommandSourceStack; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -20,9 +20,9 @@ import java.util.function.Predicate; public class CommandNodeMixin implements CommandNodeBridge { // @formatter:off - @Shadow private Map> children; - @Shadow private Map> literals; - @Shadow private Map> arguments; + @Shadow @Final private Map> children; + @Shadow @Final private Map> literals; + @Shadow @Final private Map> arguments; @Shadow @Final private Predicate requirement; // @formatter:on @@ -39,7 +39,7 @@ public class CommandNodeMixin implements CommandNodeBridge { @Inject(method = "canUse", cancellable = true, at = @At("HEAD")) public void on(S source, CallbackInfoReturnable cir) { - if (source instanceof CommandSource) { + if (source instanceof CommandSourceStack) { try { ((CommandSourceBridge) source).bridge$setCurrentCommand((CommandNode) (Object) this); cir.setReturnValue(requirement.test(source)); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceMixin.java new file mode 100644 index 00000000..6ebbb193 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceMixin.java @@ -0,0 +1,15 @@ +package io.izzel.arclight.common.mixin.core.commands; + +import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import org.bukkit.command.CommandSender; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(CommandSource.class) +public interface CommandSourceMixin extends ICommandSourceBridge { + + default CommandSender getBukkitSender(CommandSourceStack wrapper) { + return this.bridge$getBukkitSender(wrapper); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceStackMixin.java similarity index 76% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandSourceMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceStackMixin.java index 3b855937..b7f3268b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandSourceMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandSourceStackMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.command; +package io.izzel.arclight.common.mixin.core.commands; import com.mojang.brigadier.tree.CommandNode; import io.izzel.arclight.common.bridge.command.CommandSourceBridge; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.ICommandSource; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v.CraftServer; @@ -17,18 +17,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(CommandSource.class) -public abstract class CommandSourceMixin implements CommandSourceBridge { +@Mixin(CommandSourceStack.class) +public abstract class CommandSourceStackMixin implements CommandSourceBridge { // @formatter:off - @Shadow @Final public ICommandSource source; - @Shadow public abstract ServerWorld getWorld(); + @Shadow @Final public CommandSource source; + @Shadow public abstract ServerLevel getLevel(); @Shadow @Final private int permissionLevel; // @formatter:on public CommandNode currentCommand; - @Inject(method = "hasPermissionLevel", cancellable = true, at = @At("HEAD")) + @Inject(method = "hasPermission", cancellable = true, at = @At("HEAD")) public void arclight$checkPermission(int level, CallbackInfoReturnable cir) { if (currentCommand != null) { cir.setReturnValue(hasPermission(level, VanillaCommandWrapper.getPermission(currentCommand))); @@ -37,7 +37,7 @@ public abstract class CommandSourceMixin implements CommandSourceBridge { public boolean hasPermission(int i, String bukkitPermission) { // World is null when loading functions - return ((getWorld() == null || !((CraftServer) Bukkit.getServer()).ignoreVanillaPermissions) && this.permissionLevel >= i) || getBukkitSender().hasPermission(bukkitPermission); + return ((getLevel() == null || !((CraftServer) Bukkit.getServer()).ignoreVanillaPermissions) && this.permissionLevel >= i) || getBukkitSender().hasPermission(bukkitPermission); } @Override @@ -56,7 +56,7 @@ public abstract class CommandSourceMixin implements CommandSourceBridge { } public CommandSender getBukkitSender() { - return ((ICommandSourceBridge) this.source).bridge$getBukkitSender((CommandSource) (Object) this); + return ((ICommandSourceBridge) this.source).bridge$getBukkitSender((CommandSourceStack) (Object) this); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandsMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandsMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandsMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandsMixin.java index 60de505e..75ed17e7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/CommandsMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/CommandsMixin.java @@ -1,4 +1,4 @@ -package io.izzel.arclight.common.mixin.core.command; +package io.izzel.arclight.common.mixin.core.commands; import com.google.common.collect.Maps; import com.mojang.brigadier.CommandDispatcher; @@ -8,11 +8,11 @@ import io.izzel.arclight.common.bridge.command.CommandNodeBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; import io.izzel.arclight.common.mod.util.BukkitDispatcher; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.command.ISuggestionProvider; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.play.server.SCommandListPacket; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.protocol.game.ClientboundCommandsPacket; +import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.event.player.PlayerCommandSendEvent; import org.spigotmc.SpigotConfig; @@ -29,9 +29,9 @@ import java.util.Map; public abstract class CommandsMixin { // @formatter:off - @Shadow public abstract int handleCommand(CommandSource source, String command); - @Mutable @Shadow @Final private CommandDispatcher dispatcher; - @Shadow protected abstract void commandSourceNodesToSuggestionNodes(CommandNode rootCommandSource, CommandNode rootSuggestion, CommandSource source, Map, CommandNode> commandNodeToSuggestionNode); + @Shadow public abstract int performCommand(CommandSourceStack source, String command); + @Mutable @Shadow @Final private CommandDispatcher dispatcher; + @Shadow protected abstract void fillUsableCommands(CommandNode rootCommandSource, CommandNode rootSuggestion, CommandSourceStack source, Map, CommandNode> commandNodeToSuggestionNode); // @formatter:on public void arclight$constructor() { @@ -39,8 +39,8 @@ public abstract class CommandsMixin { this.dispatcher.setConsumer((context, b, i) -> context.getSource().onCommandComplete(context, b, i)); } - public int a(CommandSource source, String command, String label, boolean strip) { - return this.handleCommand(source, command); + public int a(CommandSourceStack source, String command, String label, boolean strip) { + return this.performCommand(source, command); } /** @@ -48,21 +48,21 @@ public abstract class CommandsMixin { * @reason */ @Overwrite - public void send(ServerPlayerEntity player) { + public void sendCommands(ServerPlayer player) { if (SpigotConfig.tabComplete < 0) return; - Map, CommandNode> map = Maps.newIdentityHashMap(); + Map, CommandNode> map = Maps.newIdentityHashMap(); - RootCommandNode vanillaRoot = new RootCommandNode<>(); + RootCommandNode vanillaRoot = new RootCommandNode<>(); Commands vanillaCommands = ((MinecraftServerBridge) player.server).bridge$getVanillaCommands(); map.put(vanillaCommands.getDispatcher().getRoot(), vanillaRoot); - this.commandSourceNodesToSuggestionNodes(vanillaCommands.getDispatcher().getRoot(), vanillaRoot, player.getCommandSource(), map); + this.fillUsableCommands(vanillaCommands.getDispatcher().getRoot(), vanillaRoot, player.createCommandSourceStack(), map); - RootCommandNode node = new RootCommandNode<>(); + RootCommandNode node = new RootCommandNode<>(); map.put(this.dispatcher.getRoot(), node); - this.commandSourceNodesToSuggestionNodes(this.dispatcher.getRoot(), node, player.getCommandSource(), map); + this.fillUsableCommands(this.dispatcher.getRoot(), node, player.createCommandSourceStack(), map); LinkedHashSet set = new LinkedHashSet<>(); - for (CommandNode child : node.getChildren()) { + for (CommandNode child : node.getChildren()) { set.add(child.getName()); } PlayerCommandSendEvent event = new PlayerCommandSendEvent(((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(), new LinkedHashSet<>(set)); @@ -72,6 +72,6 @@ public abstract class CommandsMixin { ((CommandNodeBridge) node).bridge$removeCommand(s); } } - player.connection.sendPacket(new SCommandListPacket(node)); + player.connection.send(new ClientboundCommandsPacket(node)); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntityArgumentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/EntityArgumentMixin.java similarity index 62% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntityArgumentMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/EntityArgumentMixin.java index ef8e00fe..c47042fc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntityArgumentMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/EntityArgumentMixin.java @@ -1,26 +1,26 @@ -package io.izzel.arclight.common.mixin.core.command.arguments; +package io.izzel.arclight.common.mixin.core.commands.arguments; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.izzel.arclight.common.bridge.command.arguments.EntityArgumentBridge; import io.izzel.arclight.common.bridge.command.arguments.EntitySelectorParserBridge; -import net.minecraft.command.arguments.EntityArgument; -import net.minecraft.command.arguments.EntitySelector; -import net.minecraft.command.arguments.EntitySelectorParser; +import net.minecraft.commands.arguments.EntityArgument; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.commands.arguments.selector.EntitySelectorParser; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import static net.minecraft.command.arguments.EntityArgument.ONLY_PLAYERS_ALLOWED; -import static net.minecraft.command.arguments.EntityArgument.TOO_MANY_ENTITIES; -import static net.minecraft.command.arguments.EntityArgument.TOO_MANY_PLAYERS; +import static net.minecraft.commands.arguments.EntityArgument.ERROR_ONLY_PLAYERS_ALLOWED; +import static net.minecraft.commands.arguments.EntityArgument.ERROR_NOT_SINGLE_ENTITY; +import static net.minecraft.commands.arguments.EntityArgument.ERROR_NOT_SINGLE_PLAYER; @Mixin(EntityArgument.class) public class EntityArgumentMixin implements EntityArgumentBridge { // @formatter:off - @Shadow @Final private boolean single; - @Shadow @Final private boolean playersOnly; + @Shadow @Final boolean single; + @Shadow @Final boolean playersOnly; // @formatter:on @Override @@ -32,17 +32,17 @@ public class EntityArgumentMixin implements EntityArgumentBridge { int i = 0; EntitySelectorParser entityselectorparser = new EntitySelectorParser(reader); EntitySelector entityselector = ((EntitySelectorParserBridge) entityselectorparser).bridge$parse(overridePermissions); - if (entityselector.getLimit() > 1 && this.single) { + if (entityselector.getMaxResults() > 1 && this.single) { if (this.playersOnly) { reader.setCursor(0); - throw TOO_MANY_PLAYERS.createWithContext(reader); + throw ERROR_NOT_SINGLE_PLAYER.createWithContext(reader); } else { reader.setCursor(0); - throw TOO_MANY_ENTITIES.createWithContext(reader); + throw ERROR_NOT_SINGLE_ENTITY.createWithContext(reader); } } else if (entityselector.includesEntities() && this.playersOnly && !entityselector.isSelfSelector()) { reader.setCursor(0); - throw ONLY_PLAYERS_ALLOWED.createWithContext(reader); + throw ERROR_ONLY_PLAYERS_ALLOWED.createWithContext(reader); } else { return entityselector; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/BlockStateParserMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/blocks/BlockStateParserMixin.java similarity index 80% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/BlockStateParserMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/blocks/BlockStateParserMixin.java index 8ea1e6ed..e15ab803 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/BlockStateParserMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/blocks/BlockStateParserMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.command.arguments; +package io.izzel.arclight.common.mixin.core.commands.arguments.blocks; import com.mojang.brigadier.StringReader; -import net.minecraft.command.arguments.BlockStateParser; -import net.minecraft.state.Property; +import net.minecraft.commands.arguments.blocks.BlockStateParser; +import net.minecraft.world.level.block.state.properties.Property; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorMixin.java new file mode 100644 index 00000000..ff39f61b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorMixin.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.common.mixin.core.commands.arguments.selector; + +import io.izzel.arclight.common.bridge.command.CommandSourceBridge; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.selector.EntitySelector; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(EntitySelector.class) +public class EntitySelectorMixin { + + @Redirect(method = "checkPermissions", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/CommandSourceStack;hasPermission(I)Z")) + private boolean arclight$stringPermission(CommandSourceStack commandSource, int level) { + return ((CommandSourceBridge) commandSource).bridge$hasPermission(level, "minecraft.command.selector"); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorParserMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorParserMixin.java similarity index 82% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorParserMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorParserMixin.java index 78f75cc2..1787a892 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/EntitySelectorParserMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/arguments/selector/EntitySelectorParserMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.command.arguments; +package io.izzel.arclight.common.mixin.core.commands.arguments.selector; import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.izzel.arclight.common.bridge.command.arguments.EntitySelectorParserBridge; -import net.minecraft.command.arguments.EntitySelector; -import net.minecraft.command.arguments.EntitySelectorParser; +import net.minecraft.commands.arguments.selector.EntitySelector; +import net.minecraft.commands.arguments.selector.EntitySelectorParser; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public abstract class EntitySelectorParserMixin implements EntitySelectorParserBridge { // @formatter:off - @Shadow private boolean checkPermission; + @Shadow private boolean usesSelectors; @Shadow protected abstract void shadow$parseSelector() throws CommandSyntaxException; @Shadow public abstract EntitySelector parse() throws CommandSyntaxException; // @formatter:on @@ -41,14 +41,14 @@ public abstract class EntitySelectorParserMixin implements EntitySelectorParserB } public void parseSelector(boolean overridePermissions) throws CommandSyntaxException { - this.checkPermission = !overridePermissions; + this.usesSelectors = !overridePermissions; this.shadow$parseSelector(); } @Inject(method = "parseSelector", at = @At("HEAD")) public void arclight$onParserSelector(CallbackInfo ci) { if (this.arclight$overridePermissions != null) { - this.checkPermission = !this.arclight$overridePermissions; + this.usesSelectors = !this.arclight$overridePermissions; } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/ArgumentTypesMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/synchronization/ArgumentTypesMixin.java similarity index 70% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/ArgumentTypesMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/synchronization/ArgumentTypesMixin.java index d3daa2a3..8dbce190 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/arguments/ArgumentTypesMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/commands/synchronization/ArgumentTypesMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.command.arguments; +package io.izzel.arclight.common.mixin.core.commands.synchronization; import com.mojang.brigadier.arguments.ArgumentType; import io.netty.buffer.Unpooled; -import net.minecraft.command.arguments.ArgumentTypes; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; +import net.minecraft.commands.synchronization.ArgumentTypes; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; import org.apache.logging.log4j.Logger; import org.spigotmc.SpigotConfig; import org.spongepowered.asm.mixin.Final; @@ -26,19 +26,19 @@ public abstract class ArgumentTypesMixin { // @formatter:off @Shadow @Final private static Logger LOGGER; @Shadow @Nullable private static ArgumentTypes.Entry get(ArgumentType type) { return null; } - @Shadow @Final private static Map> ID_TYPE_MAP; + @Shadow @Final private static Map> BY_NAME; // @formatter:on private static final Set INTERNAL_TYPES = new HashSet<>(); - @Inject(method = "registerArgumentTypes", at = @At("HEAD")) + @Inject(method = "bootStrap", at = @At("HEAD")) private static void arclight$beginRegister(CallbackInfo ci) { - INTERNAL_TYPES.addAll(ID_TYPE_MAP.keySet()); + INTERNAL_TYPES.addAll(BY_NAME.keySet()); } - @Inject(method = "registerArgumentTypes", at = @At("RETURN")) + @Inject(method = "bootStrap", at = @At("RETURN")) private static void arclight$endRegister(CallbackInfo ci) { - HashSet set = new HashSet<>(ID_TYPE_MAP.keySet()); + HashSet set = new HashSet<>(BY_NAME.keySet()); set.removeAll(INTERNAL_TYPES); INTERNAL_TYPES.clear(); INTERNAL_TYPES.addAll(set); @@ -51,19 +51,19 @@ public abstract class ArgumentTypesMixin { * @reason */ @Overwrite - public static > void serialize(PacketBuffer buffer, T type) { + public static > void serialize(FriendlyByteBuf buffer, T type) { ArgumentTypes.Entry entry = (ArgumentTypes.Entry) get(type); if (entry == null) { LOGGER.error("Could not serialize {} ({}) - will not be sent to client!", type, type.getClass()); buffer.writeResourceLocation(new ResourceLocation("")); } else { - boolean wrap = SpigotConfig.bungee && !INTERNAL_TYPES.contains(entry.id); + boolean wrap = SpigotConfig.bungee && !INTERNAL_TYPES.contains(entry.name); if (wrap) { - buffer.writeString("arclight:wrapped"); + buffer.writeUtf("arclight:wrapped"); } - buffer.writeResourceLocation(entry.id); - PacketBuffer buf = wrap ? new PacketBuffer(Unpooled.buffer()) : buffer; - entry.serializer.write(type, buf); + buffer.writeResourceLocation(entry.name); + FriendlyByteBuf buf = wrap ? new FriendlyByteBuf(Unpooled.buffer()) : buffer; + entry.serializer.serializeToNetwork(type, buf); if (wrap) { buffer.writeVarInt(buf.writerIndex()); buffer.writeBytes(buf); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/FrostWalkerEnchantmentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/FrostWalkerEnchantmentMixin.java deleted file mode 100644 index 173de8d9..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/FrostWalkerEnchantmentMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.izzel.arclight.common.mixin.core.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.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.world.World; -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 { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public static void freezeNearby(LivingEntity living, World worldIn, BlockPos pos, int level) { - if (living.isOnGround()) { - 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((double) (-f), -1.0D, (double) (-f)), pos.add((double) f, -1.0D, (double) f))) { - if (blockpos.withinDistance(living.getPositionVec(), (double) 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.placedBlockCollides(blockstate, blockpos, ISelectionContext.dummy()) && !net.minecraftforge.event.ForgeEventFactory.onBlockPlace(living, net.minecraftforge.common.util.BlockSnapshot.create(worldIn.getDimensionKey(), worldIn, blockpos), net.minecraft.util.Direction.UP)) { - if (CraftEventFactory.handleBlockFormEvent(worldIn, blockpos, blockstate, living)) { - worldIn.getPendingBlockTicks().scheduleTick(blockpos, Blocks.FROSTED_ICE, MathHelper.nextInt(living.getRNG(), 60, 120)); - } - } - } - } - } - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AgeableEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AgeableEntityMixin.java deleted file mode 100644 index 808f49cc..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AgeableEntityMixin.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity; - -import io.izzel.arclight.common.bridge.entity.AgeableEntityBridge; -import net.minecraft.entity.AgeableEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; - -@Mixin(AgeableEntity.class) -public abstract class AgeableEntityMixin extends CreatureEntityMixin implements AgeableEntityBridge { - - // @formatter:off - @Shadow public abstract boolean isChild(); - @Shadow @Nullable public abstract AgeableEntity createChild(ServerWorld world, AgeableEntity mate); - @Shadow public abstract void setGrowingAge(int age); - // @formatter:on - - public boolean ageLocked; - - @Inject(method = "writeAdditional", at = @At("RETURN")) - private void arclight$writeAgeLocked(CompoundNBT compound, CallbackInfo ci) { - compound.putBoolean("AgeLocked", ageLocked); - } - - @Inject(method = "readAdditional", at = @At("RETURN")) - private void arclight$readAgeLocked(CompoundNBT compound, CallbackInfo ci) { - ageLocked = compound.getBoolean("AgeLocked"); - } - - @Redirect(method = "livingTick", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;isRemote:Z")) - private boolean arclight$tickIfNotLocked(World world) { - return world.isRemote || ageLocked; - } - - @Override - public boolean bridge$isAgeLocked() { - return this.ageLocked; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AreaEffectCloudEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AreaEffectCloudEntityMixin.java deleted file mode 100644 index 3935ee61..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/AreaEffectCloudEntityMixin.java +++ /dev/null @@ -1,222 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity; - -import com.google.common.collect.Lists; -import io.izzel.arclight.common.bridge.entity.AreaEffectCloudEntityBridge; -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.AreaEffectCloudEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.particles.IParticleData; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.potion.EffectInstance; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtils; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.registry.Registry; -import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.AreaEffectCloudApplyEvent; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; - -@Mixin(AreaEffectCloudEntity.class) -@Implements(@Interface(iface = AreaEffectCloudEntityBridge.Hack.class, prefix = "hack$")) -public abstract class AreaEffectCloudEntityMixin extends EntityMixin implements AreaEffectCloudEntityBridge { - - // @formatter:off - @Shadow private boolean colorSet; - @Shadow @Final private static DataParameter COLOR; - @Shadow public List effects; - @Shadow private Potion potion; - @Shadow public abstract void setPotion(Potion potionIn); - @Shadow public abstract boolean shouldIgnoreRadius(); - @Shadow public abstract float getRadius(); - @Shadow public abstract IParticleData getParticleData(); - @Shadow public abstract int getColor(); - @Shadow public int waitTime; - @Shadow private int duration; - @Shadow protected abstract void setIgnoreRadius(boolean ignoreRadius); - @Shadow public float radiusPerTick; - @Shadow public abstract void setRadius(float radiusIn); - @Shadow @Final private Map reapplicationDelayMap; - @Shadow public int reapplicationDelay; - @Shadow @Nullable public abstract LivingEntity getOwner(); - @Shadow public float radiusOnUse; - @Shadow public int durationOnUse; - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void tick() { - super.tick(); - boolean flag = this.shouldIgnoreRadius(); - float f = this.getRadius(); - if (this.world.isRemote) { - IParticleData iparticledata = this.getParticleData(); - if (flag) { - if (this.rand.nextBoolean()) { - for (int i = 0; i < 2; ++i) { - float f1 = this.rand.nextFloat() * ((float) Math.PI * 2F); - float f2 = MathHelper.sqrt(this.rand.nextFloat()) * 0.2F; - float f3 = MathHelper.cos(f1) * f2; - float f4 = MathHelper.sin(f1) * f2; - if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) { - int j = this.rand.nextBoolean() ? 16777215 : this.getColor(); - int k = j >> 16 & 255; - int l = j >> 8 & 255; - int i1 = j & 255; - this.world.addOptionalParticle(iparticledata, this.getPosX() + (double) f3, this.getPosY(), this.getPosZ() + (double) f4, (float) k / 255.0F, (float) l / 255.0F, (float) i1 / 255.0F); - } else { - this.world.addOptionalParticle(iparticledata, this.getPosX() + (double) f3, this.getPosY(), this.getPosZ() + (double) f4, 0.0D, 0.0D, 0.0D); - } - } - } - } else { - float f5 = (float) Math.PI * f * f; - - for (int k1 = 0; (float) k1 < f5; ++k1) { - float f6 = this.rand.nextFloat() * ((float) Math.PI * 2F); - float f7 = MathHelper.sqrt(this.rand.nextFloat()) * f; - float f8 = MathHelper.cos(f6) * f7; - float f9 = MathHelper.sin(f6) * f7; - if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) { - int l1 = this.getColor(); - int i2 = l1 >> 16 & 255; - int j2 = l1 >> 8 & 255; - int j1 = l1 & 255; - this.world.addOptionalParticle(iparticledata, this.getPosX() + (double) f8, this.getPosY(), this.getPosZ() + (double) f9, (float) i2 / 255.0F, (float) j2 / 255.0F, (float) j1 / 255.0F); - } else { - this.world.addOptionalParticle(iparticledata, this.getPosX() + (double) f8, this.getPosY(), this.getPosZ() + (double) f9, (0.5D - this.rand.nextDouble()) * 0.15D, 0.01F, (0.5D - this.rand.nextDouble()) * 0.15D); - } - } - } - } else { - if (this.ticksExisted >= this.waitTime + this.duration) { - this.remove(); - return; - } - - boolean flag1 = this.ticksExisted < this.waitTime; - if (flag != flag1) { - this.setIgnoreRadius(flag1); - } - - if (flag1) { - return; - } - - if (this.radiusPerTick != 0.0F) { - f += this.radiusPerTick; - if (f < 0.5F) { - this.remove(); - return; - } - - this.setRadius(f); - } - - if (this.ticksExisted % 5 == 0) { - - this.reapplicationDelayMap.entrySet().removeIf(entry -> this.ticksExisted >= entry.getValue()); - - List effects = Lists.newArrayList(); - - for (EffectInstance effectinstance1 : this.potion.getEffects()) { - effects.add(new EffectInstance(effectinstance1.getPotion(), effectinstance1.getDuration() / 4, effectinstance1.getAmplifier(), effectinstance1.isAmbient(), effectinstance1.doesShowParticles())); - } - - effects.addAll(this.effects); - if (effects.isEmpty()) { - this.reapplicationDelayMap.clear(); - } else { - List list = this.world.getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox()); - if (!list.isEmpty()) { - List entities = new java.util.ArrayList<>(); - for (LivingEntity livingentity : list) { - if (!this.reapplicationDelayMap.containsKey(livingentity) && livingentity.canBeHitWithPotion()) { - double d0 = livingentity.getPosX() - this.getPosX(); - double d1 = livingentity.getPosZ() - this.getPosZ(); - double d2 = d0 * d0 + d1 * d1; - if (d2 <= (double) (f * f)) { - entities.add(livingentity); - } - } - } - - AreaEffectCloudApplyEvent event = CraftEventFactory.callAreaEffectCloudApplyEvent((AreaEffectCloudEntity) (Object) this, Lists.transform(entities, living -> ((LivingEntityBridge) living).bridge$getBukkitEntity())); - if (!event.isCancelled()) { - for (org.bukkit.entity.LivingEntity entity : event.getAffectedEntities()) { - if (entity instanceof CraftLivingEntity) { - LivingEntity livingentity = ((CraftLivingEntity) entity).getHandle(); - - this.reapplicationDelayMap.put(livingentity, this.ticksExisted + this.reapplicationDelay); - - for (EffectInstance effectinstance : effects) { - if (effectinstance.getPotion().isInstant()) { - effectinstance.getPotion().affectEntity((AreaEffectCloudEntity) (Object) this, this.getOwner(), livingentity, effectinstance.getAmplifier(), 0.5D); - } else { - ((LivingEntityBridge) livingentity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); - livingentity.addPotionEffect(new EffectInstance(effectinstance)); - } - } - - if (this.radiusOnUse != 0.0F) { - f += this.radiusOnUse; - if (f < 0.5F) { - this.remove(); - return; - } - - this.setRadius(f); - } - - if (this.durationOnUse != 0) { - this.duration += this.durationOnUse; - if (this.duration <= 0) { - this.remove(); - return; - } - } - } - } - } - } - } - } - } - - } - - public void refreshEffects() { - if (!this.colorSet) { - this.getDataManager().set(COLOR, PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.effects))); - } - } - - public String hack$getType() { - return Registry.POTION.getKey(this.potion).toString(); - } - - public void hack$setType(final String string) { - this.setPotion(Registry.POTION.getOrDefault(new ResourceLocation(string))); - } - - @Override - public void bridge$refreshEffects() { - refreshEffects(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/BoostHelperMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/BoostHelperMixin.java deleted file mode 100644 index 40955dab..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/BoostHelperMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity; - -import net.minecraft.entity.BoostHelper; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.EntityDataManager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(BoostHelper.class) -public class BoostHelperMixin { - - // @formatter:off - @Shadow public boolean saddledRaw; - @Shadow public int field_233611_b_; - @Shadow public int boostTimeRaw; - @Shadow @Final private EntityDataManager manager; - @Shadow @Final private DataParameter boostTime; - // @formatter:on - - public void setBoostTicks(int ticks) { - this.saddledRaw = true; - this.field_233611_b_ = 0; - this.boostTimeRaw = ticks; - this.manager.set(this.boostTime, this.boostTimeRaw); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityTypeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityTypeMixin.java deleted file mode 100644 index 96e2effc..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityTypeMixin.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity; - -import io.izzel.arclight.common.bridge.entity.EntityTypeBridge; -import io.izzel.arclight.common.bridge.world.IWorldWriterBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Slice; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import javax.annotation.Nullable; - -@Mixin(EntityType.class) -public abstract class EntityTypeMixin implements EntityTypeBridge { - - // @formatter:off - @Shadow @Nullable public abstract T create(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220349_7_, boolean p_220349_8_); - // @formatter:on - - @Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$spawnReason(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable cir) { - CreatureSpawnEvent.SpawnReason spawnReason = ((IWorldWriterBridge) worldIn).bridge$getAddEntityReason(); - if (spawnReason == null) { - ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); - } - } - - @Inject(method = "spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;", - cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"))) - private void arclight$returnIfSuccess(ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable cir, T t) { - if (t != null) { - cir.setReturnValue(t.removed ? null : t); - } - } - - public T spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean p_220342_7_, boolean p_220342_8_, CreatureSpawnEvent.SpawnReason spawnReason) { - T t = this.create(worldIn, compound, customName, playerIn, pos, reason, p_220342_7_, p_220342_8_); - if (t != null) { - if (t instanceof net.minecraft.entity.MobEntity && net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn((net.minecraft.entity.MobEntity) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason)) - return null; - ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(spawnReason); - worldIn.func_242417_l(t); - return t.removed ? null : t; - } - return null; - } - - @Override - public T bridge$spawnCreature(ServerWorld worldIn, @Nullable CompoundNBT compound, @Nullable ITextComponent customName, @Nullable PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) { - return spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, spawnReason); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/CreateBabyVillagerTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/CreateBabyVillagerTaskMixin.java deleted file mode 100644 index 652c69da..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/CreateBabyVillagerTaskMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.AgeableEntity; -import net.minecraft.entity.ai.brain.task.CreateBabyVillagerTask; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(CreateBabyVillagerTask.class) -public class CreateBabyVillagerTaskMixin { - - @Redirect(method = "createChild", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;createChild(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/AgeableEntity;)Lnet/minecraft/entity/merchant/villager/VillagerEntity;")) - private VillagerEntity arclight$entityBreed(VillagerEntity lona, ServerWorld world, AgeableEntity anonymous) { - VillagerEntity child = lona.createChild(world, anonymous); - if (child != null && !CraftEventFactory.callEntityBreedEvent(child, lona, anonymous, null, null, 0).isCancelled()) { - ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); - return child; - } else { - return null; - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmTaskMixin.java deleted file mode 100644 index 49ec8ae6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmTaskMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; - -import net.minecraft.entity.ai.brain.task.FarmTask; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.world.server.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import io.izzel.arclight.common.mod.util.ArclightCaptures; - -@Mixin(FarmTask.class) -public abstract class FarmTaskMixin { - - @Inject(method = "updateTask", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void on(ServerWorld worldIn, VillagerEntity owner, long gameTime, CallbackInfo ci) { - ArclightCaptures.captureEntityChangeBlock(owner); - } - -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmerWorkTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmerWorkTaskMixin.java deleted file mode 100644 index 287e7ca1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FarmerWorkTaskMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; - -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.BlockState; -import net.minecraft.entity.ai.brain.task.FarmerWorkTask; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.util.math.GlobalPos; -import net.minecraft.world.server.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(FarmerWorkTask.class) -public class FarmerWorkTaskMixin { - - @Inject(method = "compost", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ComposterBlock;empty(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) - private void arclight$captureVillager1(ServerWorld world, VillagerEntity villager, GlobalPos p_234016_3_, BlockState state, CallbackInfo ci) { - ArclightCaptures.captureEntityChangeBlock(villager); - } - - @Inject(method = "compost", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ComposterBlock;attemptFill(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) - private void arclight$captureVillager2(ServerWorld world, VillagerEntity villager, GlobalPos p_234016_3_, BlockState state, CallbackInfo ci) { - ArclightCaptures.captureEntityChangeBlock(villager); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/InteractWithDoorTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/InteractWithDoorTaskMixin.java deleted file mode 100644 index 0d7e6515..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/InteractWithDoorTaskMixin.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.brain.memory.MemoryModuleType; -import net.minecraft.entity.ai.brain.task.InteractWithDoorTask; -import net.minecraft.pathfinding.Path; -import net.minecraft.pathfinding.PathPoint; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.entity.EntityInteractEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import javax.annotation.Nullable; - -@Mixin(InteractWithDoorTask.class) -public abstract class InteractWithDoorTaskMixin { - - // @formatter:off - @Shadow @Nullable private PathPoint field_242292_b; - @Shadow protected abstract void func_242301_c(ServerWorld p_242301_1_, LivingEntity p_242301_2_, BlockPos p_242301_3_); - @Shadow public static void func_242294_a(ServerWorld p_242294_0_, LivingEntity p_242294_1_, @org.jetbrains.annotations.Nullable PathPoint p_242294_2_, @org.jetbrains.annotations.Nullable PathPoint p_242294_3_) { } - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void startExecuting(ServerWorld worldIn, LivingEntity entityIn, long gameTimeIn) { - Path path = entityIn.getBrain().getMemory(MemoryModuleType.PATH).get(); - this.field_242292_b = path.getCurrentPoint(); - PathPoint pathpoint = path.func_242950_i(); - PathPoint pathpoint1 = path.getCurrentPoint(); - BlockPos blockpos = pathpoint.func_224759_a(); - BlockState blockstate = worldIn.getBlockState(blockpos); - if (blockstate.isIn(BlockTags.WOODEN_DOORS)) { - DoorBlock doorblock = (DoorBlock) blockstate.getBlock(); - if (!doorblock.isOpen(blockstate)) { - EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.world, blockpos)); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - doorblock.openDoor(worldIn, blockstate, blockpos, true); - } - - this.func_242301_c(worldIn, entityIn, blockpos); - } - - BlockPos blockpos1 = pathpoint1.func_224759_a(); - BlockState blockstate1 = worldIn.getBlockState(blockpos1); - if (blockstate1.isIn(BlockTags.WOODEN_DOORS)) { - DoorBlock doorblock1 = (DoorBlock) blockstate1.getBlock(); - if (!doorblock1.isOpen(blockstate1)) { - // todo check this blockpos1 - EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.world, blockpos1)); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - doorblock1.openDoor(worldIn, blockstate1, blockpos1, true); - this.func_242301_c(worldIn, entityIn, blockpos1); - } - } - - func_242294_a(worldIn, entityIn, pathpoint, pathpoint1); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakDoorGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakDoorGoalMixin.java deleted file mode 100644 index 00e5e98a..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakDoorGoalMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; - -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.goal.BreakDoorGoal; -import net.minecraft.entity.ai.goal.InteractDoorGoal; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(BreakDoorGoal.class) -public abstract class BreakDoorGoalMixin extends InteractDoorGoal { - - public BreakDoorGoalMixin(MobEntity entityIn) { - super(entityIn); - } - - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void arclight$breakDoor(CallbackInfo ci) { - if (CraftEventFactory.callEntityBreakDoorEvent(this.entity, this.doorPosition).isCancelled()) { - this.startExecuting(); - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/NearestAttackableTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/NearestAttackableTargetGoalMixin.java deleted file mode 100644 index 38d65574..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/NearestAttackableTargetGoalMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal; -import net.minecraft.entity.player.ServerPlayerEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(NearestAttackableTargetGoal.class) -public class NearestAttackableTargetGoalMixin extends TargetGoalMixin { - - @Shadow protected LivingEntity nearestTarget; - - @Inject(method = "startExecuting", at = @At("HEAD")) - public void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(this.nearestTarget instanceof ServerPlayerEntity ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TemptGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TemptGoalMixin.java deleted file mode 100644 index c34fb432..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TemptGoalMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; - -import net.minecraft.entity.CreatureEntity; -import net.minecraft.entity.ai.goal.TemptGoal; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.entity.EntityTargetLivingEntityEvent; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(TemptGoal.class) -public abstract class TemptGoalMixin { - - // @formatter:off - @Shadow protected PlayerEntity closestPlayer; - @Shadow protected abstract boolean isTempting(ItemStack stack); - @Shadow @Final protected CreatureEntity creature; - // @formatter:on - - @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 cir) { - boolean tempt = this.closestPlayer != null && (this.isTempting(this.closestPlayer.getHeldItemMainhand()) || this.isTempting(this.closestPlayer.getHeldItemOffhand())); - if (tempt) { - EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this.creature, this.closestPlayer, EntityTargetEvent.TargetReason.TEMPT); - if (event.isCancelled()) { - cir.setReturnValue(false); - return; - } - this.closestPlayer = (event.getTarget() == null) ? null : ((CraftHumanEntity) event.getTarget()).getHandle(); - } - cir.setReturnValue(tempt); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/WitherEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/WitherEntityMixin.java deleted file mode 100644 index 40ad2f83..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/WitherEntityMixin.java +++ /dev/null @@ -1,179 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.boss; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityPredicate; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.boss.WitherEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.Difficulty; -import net.minecraft.world.Explosion; -import net.minecraft.world.server.ServerBossInfo; -import net.minecraftforge.event.ForgeEventFactory; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.List; - -@Mixin(WitherEntity.class) -public abstract class WitherEntityMixin extends CreatureEntityMixin { - - // @formatter:off - @Shadow public abstract int getInvulTime(); - @Shadow public abstract void setInvulTime(int time); - @Shadow @Final private int[] nextHeadUpdate; - @Shadow @Final private int[] idleHeadUpdates; - @Shadow protected abstract void launchWitherSkullToCoords(int head, double x, double y, double z, boolean invulnerable); - @Shadow public abstract int getWatchedTargetId(int head); - @Shadow public abstract void updateWatchedTargetId(int targetOffset, int newId); - @Shadow protected abstract void launchWitherSkullToEntity(int head, LivingEntity target); - @Shadow @Final private static EntityPredicate ENEMY_CONDITION; - @Shadow private int blockBreakCounter; - @Shadow @Final public ServerBossInfo bossInfo; - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void updateAITasks() { - if (this.getInvulTime() > 0) { - int j1 = this.getInvulTime() - 1; - if (j1 <= 0) { - Explosion.Mode explosion$mode = ForgeEventFactory.getMobGriefingEvent(this.world, (WitherEntity) (Object) this) ? Explosion.Mode.DESTROY : Explosion.Mode.NONE; - ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.world.createExplosion((WitherEntity) (Object) this, this.getPosX(), this.getPosYEye(), this.getPosZ(), event.getRadius(), event.getFire(), explosion$mode); - } - if (!this.isSilent()) { - this.world.playBroadcastSound(1023, this.getPosition(), 0); - } - } - - this.setInvulTime(j1); - if (this.ticksExisted % 10 == 0) { - bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); - this.heal(10.0F); - } - - } else { - super.updateAITasks(); - - for (int i = 1; i < 3; ++i) { - if (this.ticksExisted >= this.nextHeadUpdate[i - 1]) { - this.nextHeadUpdate[i - 1] = this.ticksExisted + 10 + this.rand.nextInt(10); - if (this.world.getDifficulty() == Difficulty.NORMAL || this.world.getDifficulty() == Difficulty.HARD) { - int j3 = i - 1; - int k3 = this.idleHeadUpdates[i - 1]; - this.idleHeadUpdates[j3] = this.idleHeadUpdates[i - 1] + 1; - if (k3 > 15) { - float f = 10.0F; - float f1 = 5.0F; - double d0 = MathHelper.nextDouble(this.rand, this.getPosX() - 10.0D, this.getPosX() + 10.0D); - double d1 = MathHelper.nextDouble(this.rand, this.getPosY() - 5.0D, this.getPosY() + 5.0D); - double d2 = MathHelper.nextDouble(this.rand, this.getPosZ() - 10.0D, this.getPosZ() + 10.0D); - this.launchWitherSkullToCoords(i + 1, d0, d1, d2, true); - this.idleHeadUpdates[i - 1] = 0; - } - } - - int k1 = this.getWatchedTargetId(i); - if (k1 > 0) { - Entity entity = this.world.getEntityByID(k1); - if (entity != null && entity.isAlive() && !(this.getDistanceSq(entity) > 900.0D) && this.canEntityBeSeen(entity)) { - if (entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.disableDamage) { - this.updateWatchedTargetId(i, 0); - } else { - this.launchWitherSkullToEntity(i + 1, (LivingEntity) entity); - this.nextHeadUpdate[i - 1] = this.ticksExisted + 40 + this.rand.nextInt(20); - this.idleHeadUpdates[i - 1] = 0; - } - } else { - this.updateWatchedTargetId(i, 0); - } - } else { - List list = this.world.getTargettableEntitiesWithinAABB(LivingEntity.class, ENEMY_CONDITION, (WitherEntity) (Object) this, this.getBoundingBox().grow(20.0D, 8.0D, 20.0D)); - - for (int j2 = 0; j2 < 10 && !list.isEmpty(); ++j2) { - LivingEntity livingentity = list.get(this.rand.nextInt(list.size())); - if (livingentity != (Object) this && livingentity.isAlive() && this.canEntityBeSeen(livingentity)) { - if (livingentity instanceof PlayerEntity) { - if (!((PlayerEntity) livingentity).abilities.disableDamage) { - if (CraftEventFactory.callEntityTargetLivingEvent((WitherEntity) (Object) this, livingentity, EntityTargetEvent.TargetReason.CLOSEST_ENTITY).isCancelled()) - continue; - this.updateWatchedTargetId(i, livingentity.getEntityId()); - } - } else { - if (CraftEventFactory.callEntityTargetLivingEvent((WitherEntity) (Object) this, livingentity, EntityTargetEvent.TargetReason.CLOSEST_ENTITY).isCancelled()) - continue; - this.updateWatchedTargetId(i, livingentity.getEntityId()); - } - break; - } - - list.remove(livingentity); - } - } - } - } - - if (this.getAttackTarget() != null) { - this.updateWatchedTargetId(0, this.getAttackTarget().getEntityId()); - } else { - this.updateWatchedTargetId(0, 0); - } - - if (this.blockBreakCounter > 0) { - --this.blockBreakCounter; - if (this.blockBreakCounter == 0 && ForgeEventFactory.getMobGriefingEvent(this.world, (WitherEntity) (Object) this)) { - int i1 = MathHelper.floor(this.getPosY()); - int l1 = MathHelper.floor(this.getPosX()); - int i2 = MathHelper.floor(this.getPosZ()); - boolean flag = false; - - for (int k2 = -1; k2 <= 1; ++k2) { - for (int l2 = -1; l2 <= 1; ++l2) { - for (int j = 0; j <= 3; ++j) { - int i3 = l1 + k2; - int k = i1 + j; - int l = i2 + l2; - BlockPos blockpos = new BlockPos(i3, k, l); - BlockState blockstate = this.world.getBlockState(blockpos); - if (blockstate.canEntityDestroy(this.world, blockpos, (WitherEntity) (Object) this) && ForgeEventFactory.onEntityDestroyBlock((WitherEntity) (Object) this, blockpos, blockstate)) { - if (CraftEventFactory.callEntityChangeBlockEvent((WitherEntity) (Object) this, blockpos, Blocks.AIR.getDefaultState()).isCancelled()) { - continue; - } - flag = this.world.destroyBlock(blockpos, true, (WitherEntity) (Object) this) || flag; - } - } - } - } - - if (flag) { - this.world.playEvent(null, 1022, this.getPosition(), 0); - } - } - } - - if (this.ticksExisted % 20 == 0) { - bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.REGEN); - this.heal(1.0F); - } - - this.bossInfo.setPercent(this.getHealth() / this.getMaxHealth()); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/EnderDragonEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/EnderDragonEntityMixin.java deleted file mode 100644 index 3561de66..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/EnderDragonEntityMixin.java +++ /dev/null @@ -1,128 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.boss.dragon; - -import io.izzel.arclight.common.mixin.core.entity.MobEntityMixin; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.material.Material; -import net.minecraft.entity.boss.dragon.EnderDragonEntity; -import net.minecraft.entity.boss.dragon.phase.IPhase; -import net.minecraft.entity.boss.dragon.phase.PhaseType; -import net.minecraft.item.ItemStack; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameters; -import net.minecraft.tags.BlockTags; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.Explosion; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.ArrayList; -import java.util.List; - -@Mixin(EnderDragonEntity.class) -public abstract class EnderDragonEntityMixin extends MobEntityMixin { - - private Explosion explosionSource = new Explosion(null, (EnderDragonEntity) (Object) this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.Mode.DESTROY); - - @Redirect(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/phase/IPhase;getTargetLocation()Lnet/minecraft/util/math/vector/Vector3d;")) - private Vector3d arclight$noMoveHovering(IPhase phase) { - Vector3d vec3d = phase.getTargetLocation(); - return vec3d != null && phase.getType() != PhaseType.HOVER ? vec3d : null; - } - - @Redirect(method = "updateDragonEnderCrystal", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/EnderDragonEntity;setHealth(F)V")) - private void arclight$regainHealth(EnderDragonEntity enderDragonEntity, float health) { - EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - this.setHealth((float) (this.getHealth() + event.getAmount())); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - private boolean destroyBlocksInAABB(final AxisAlignedBB axisalignedbb) { - final int i = MathHelper.floor(axisalignedbb.minX); - final int j = MathHelper.floor(axisalignedbb.minY); - final int k = MathHelper.floor(axisalignedbb.minZ); - final int l = MathHelper.floor(axisalignedbb.maxX); - final int i2 = MathHelper.floor(axisalignedbb.maxY); - final int j2 = MathHelper.floor(axisalignedbb.maxZ); - boolean flag = false; - boolean flag2 = false; - final List destroyedBlocks = new ArrayList<>(); - for (int k2 = i; k2 <= l; ++k2) { - for (int l2 = j; l2 <= i2; ++l2) { - for (int i3 = k; i3 <= j2; ++i3) { - final BlockPos blockposition = new BlockPos(k2, l2, i3); - final BlockState iblockdata = this.world.getBlockState(blockposition); - final net.minecraft.block.Block block = iblockdata.getBlock(); - if (!iblockdata.isAir() && iblockdata.getMaterial() != Material.FIRE) { - if (net.minecraftforge.common.ForgeHooks.canEntityDestroy(this.world, blockposition, (EnderDragonEntity) (Object) this) && !BlockTags.DRAGON_IMMUNE.contains(block)) { - flag2 = true; - destroyedBlocks.add(CraftBlock.at(this.world, blockposition)); - } else { - flag = true; - } - } - } - } - } - if (!flag2) { - return flag; - } - final org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity(); - final EntityExplodeEvent event = new EntityExplodeEvent(bukkitEntity, bukkitEntity.getLocation(), destroyedBlocks, 0.0f); - bukkitEntity.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - return flag; - } - if (event.getYield() == 0.0f) { - for (final org.bukkit.block.Block block2 : event.blockList()) { - this.world.removeBlock(new BlockPos(block2.getX(), block2.getY(), block2.getZ()), false); - } - } else { - for (final org.bukkit.block.Block block2 : event.blockList()) { - final org.bukkit.Material blockId = block2.getType(); - if (blockId.isAir()) { - continue; - } - final CraftBlock craftBlock = (CraftBlock) block2; - final BlockPos blockposition2 = craftBlock.getPosition(); - final net.minecraft.block.Block nmsBlock = craftBlock.getNMS().getBlock(); - if (nmsBlock.canDropFromExplosion(this.explosionSource)) { - TileEntity tileentity = nmsBlock.hasTileEntity(craftBlock.getNMS()) ? this.world.getTileEntity(blockposition2) : null; - LootContext.Builder loottableinfo_builder = new LootContext.Builder((ServerWorld)this.world).withRandom(this.world.rand).withParameter(LootParameters.ORIGIN, Vector3d.copyCentered(blockposition2)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withParameter(LootParameters.EXPLOSION_RADIUS, 1.0f / event.getYield()).withNullableParameter(LootParameters.BLOCK_ENTITY, tileentity); - for (ItemStack stack : craftBlock.getNMS().getDrops(loottableinfo_builder)) { - Block.spawnAsEntity(this.world, blockposition2, stack); - } - craftBlock.getNMS().spawnAdditionalDrops((ServerWorld) this.world, blockposition2, ItemStack.EMPTY); - // net.minecraft.block.Block.spawnDrops(craftBlock.getNMS(), loottableinfo_builder); - } - nmsBlock.onExplosionDestroy(this.world, blockposition2, this.explosionSource); - this.world.removeBlock(blockposition2, false); - } - } - if (flag2) { - final BlockPos blockposition3 = new BlockPos(i + this.rand.nextInt(l - i + 1), j + this.rand.nextInt(i2 - j + 1), k + this.rand.nextInt(j2 - k + 1)); - this.world.playEvent(2008, blockposition3, 0); - } - return flag; - } - -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/phase/PhaseManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/phase/PhaseManagerMixin.java deleted file mode 100644 index 00632ffd..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/boss/dragon/phase/PhaseManagerMixin.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.boss.dragon.phase; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.entity.boss.dragon.EnderDragonEntity; -import net.minecraft.entity.boss.dragon.phase.IPhase; -import net.minecraft.entity.boss.dragon.phase.PhaseManager; -import net.minecraft.entity.boss.dragon.phase.PhaseType; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.entity.CraftEnderDragon; -import org.bukkit.event.entity.EnderDragonChangePhaseEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(PhaseManager.class) -public abstract class PhaseManagerMixin { - - // @formatter:off - @Shadow @Final private static Logger LOGGER; - @Shadow @Final private EnderDragonEntity dragon; - @Shadow private IPhase phase; - @Shadow public abstract T getPhase(PhaseType phaseIn); - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void setPhase(PhaseType phaseIn) { - if (this.phase == null || phaseIn != this.phase.getType()) { - if (this.phase != null) { - this.phase.removeAreaEffect(); - } - - EnderDragonChangePhaseEvent event = new EnderDragonChangePhaseEvent( - (CraftEnderDragon) ((EntityBridge) this.dragon).bridge$getBukkitEntity(), - (this.phase == null) ? null : CraftEnderDragon.getBukkitPhase(this.phase.getType()), - CraftEnderDragon.getBukkitPhase(phaseIn) - ); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - phaseIn = CraftEnderDragon.getMinecraftPhase(event.getNewPhase()); - - this.phase = this.getPhase(phaseIn); - if (!this.dragon.world.isRemote) { - this.dragon.getDataManager().set(EnderDragonEntity.PHASE, phaseIn.getId()); - } - - LOGGER.debug("Dragon is now in phase {} on the {}", phaseIn, this.dragon.world.isRemote ? "client" : "server"); - this.phase.initPhase(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/effect/LightningBoltEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/effect/LightningBoltEntityMixin.java deleted file mode 100644 index 0e4b797c..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/effect/LightningBoltEntityMixin.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.effect; - -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(LightningBoltEntity.class) -public abstract class LightningBoltEntityMixin extends EntityMixin { - - public boolean isSilent = false; - - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;causeLightningStrike(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/effect/LightningBoltEntity;)V")) - private void arclight$captureEntity(CallbackInfo ci) { - ArclightCaptures.captureDamageEventEntity((Entity) (Object) this); - } - - @Inject(method = "tick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;causeLightningStrike(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/entity/effect/LightningBoltEntity;)V")) - private void arclight$resetEntity(CallbackInfo ci) { - ArclightCaptures.captureDamageEventEntity(null); - } - - @Redirect(method = "igniteBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private boolean arclight$blockIgnite(World world, BlockPos pos, BlockState state) { - if (!CraftEventFactory.callBlockIgniteEvent(world, pos, (LightningBoltEntity) (Object) this).isCancelled()) { - return world.setBlockState(pos, state); - } else { - return false; - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderCrystalEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderCrystalEntityMixin.java deleted file mode 100644 index 4c39343b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderCrystalEntityMixin.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EnderCrystalEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.world.Explosion; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.ExplosionPrimeEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(EnderCrystalEntity.class) -public abstract class EnderCrystalEntityMixin extends EntityMixin { - - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private void arclight$blockIgnite(CallbackInfo ci) { - if (CraftEventFactory.callBlockIgniteEvent(this.world, this.getPosition(), (EnderCrystalEntity) (Object) this).isCancelled()) { - ci.cancel(); - } - } - - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EnderCrystalEntity;remove()V")) - private void arclight$entityDamage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((EnderCrystalEntity) (Object)this, source, amount)) { - cir.setReturnValue(false); - } - } - - @Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;DDDFLnet/minecraft/world/Explosion$Mode;)Lnet/minecraft/world/Explosion;")) - private Explosion arclight$blockPrime(World world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, Explosion.Mode modeIn) { - ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), explosionRadius, false); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - this.removed = false; - return null; - } else { - return world.createExplosion(entityIn, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderPearlEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderPearlEntityMixin.java deleted file mode 100644 index 8f274f47..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/EnderPearlEntityMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.projectile.ThrowableEntityMixin; -import net.minecraft.entity.item.EnderPearlEntity; -import net.minecraft.util.math.RayTraceResult; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(EnderPearlEntity.class) -public abstract class EnderPearlEntityMixin extends ThrowableEntityMixin { - - @Inject(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$spawnEndermite(RayTraceResult result, CallbackInfo ci) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.ENDER_PEARL); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceBottleEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceBottleEntityMixin.java deleted file mode 100644 index 6e0b36bd..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceBottleEntityMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import io.izzel.arclight.common.mixin.core.entity.projectile.ProjectileItemEntityMixin; -import net.minecraft.entity.item.ExperienceBottleEntity; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.potion.PotionUtils; -import net.minecraft.potion.Potions; -import net.minecraft.util.math.RayTraceResult; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.ExpBottleEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(ExperienceBottleEntity.class) -public abstract class ExperienceBottleEntityMixin extends ProjectileItemEntityMixin { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void onImpact(RayTraceResult result) { - super.onImpact(result); - if (!this.world.isRemote) { - int i = 3 + this.world.rand.nextInt(5) + this.world.rand.nextInt(5); - ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ExperienceBottleEntity) (Object) this, i); - i = event.getExperience(); - if (event.getShowEffect()) { - this.world.playEvent(2002, this.getPosition(), PotionUtils.getPotionColor(Potions.WATER)); - } - while (i > 0) { - int j = ExperienceOrbEntity.getXPSplit(i); - i -= j; - this.world.addEntity(new ExperienceOrbEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), j)); - } - this.remove(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceOrbEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceOrbEntityMixin.java deleted file mode 100644 index 0cb4a8c7..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ExperienceOrbEntityMixin.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import net.minecraft.util.DamageSource; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.PlayerXpEvent; -import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.entity.EntityTargetLivingEntityEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.Map; - -@Mixin(ExperienceOrbEntity.class) -public abstract class ExperienceOrbEntityMixin extends EntityMixin { - - // @formatter:off - @Shadow private PlayerEntity closestPlayer; - @Shadow public abstract boolean attackEntityFrom(DamageSource source, float amount); - @Shadow public int delayBeforeCanPickup; - @Shadow public int xpValue; - @Shadow protected abstract int durabilityToXp(int durability); - // @formatter:on - - private transient PlayerEntity arclight$lastPlayer; - - @Inject(method = "tick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;tick()V")) - private void arclight$captureLast(CallbackInfo ci) { - arclight$lastPlayer = this.closestPlayer; - } - - @Inject(method = "tick", at = @At("RETURN")) - private void arclight$captureReset(CallbackInfo ci) { - arclight$lastPlayer = null; - } - - @Redirect(method = "tick", at = @At(value = "FIELD", ordinal = 6, target = "Lnet/minecraft/entity/item/ExperienceOrbEntity;closestPlayer:Lnet/minecraft/entity/player/PlayerEntity;")) - private PlayerEntity arclight$targetPlayer(ExperienceOrbEntity entity) { - if (this.closestPlayer != arclight$lastPlayer) { - EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent((ExperienceOrbEntity) (Object) this, this.closestPlayer, (this.closestPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET); - LivingEntity target = (event.getTarget() == null) ? null : ((CraftLivingEntity) event.getTarget()).getHandle(); - - if (event.isCancelled()) { - this.closestPlayer = arclight$lastPlayer; - return null; - } else { - this.closestPlayer = (target instanceof PlayerEntity) ? (PlayerEntity) target : null; - } - } - return this.closestPlayer; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void onCollideWithPlayer(PlayerEntity entityIn) { - if (!this.world.isRemote) { - if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0) { - if (MinecraftForge.EVENT_BUS.post(new PlayerXpEvent.PickupXp(entityIn, (ExperienceOrbEntity) (Object) this))) - return; - entityIn.xpCooldown = 2; - entityIn.onItemPickup((ExperienceOrbEntity) (Object) this, 1); - Map.Entry entry = EnchantmentHelper.getRandomItemWithEnchantment(Enchantments.MENDING, entityIn); - if (entry != null) { - ItemStack itemstack = entry.getValue(); - if (!itemstack.isEmpty() && itemstack.isDamaged()) { - int i = Math.min((int) (this.xpValue * itemstack.getXpRepairRatio()), itemstack.getDamage()); - org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityIn, (ExperienceOrbEntity) (Object) this, itemstack, i); - i = event.getRepairAmount(); - if (!event.isCancelled()) { - this.xpValue -= this.durabilityToXp(i); - itemstack.setDamage(itemstack.getDamage() - i); - } - } - } - - if (this.xpValue > 0) { - entityIn.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(entityIn, this.xpValue).getAmount()); - } - - this.remove(); - } - - } - } - - @Inject(method = "getXPSplit", cancellable = true, at = @At("HEAD")) - private static void arclight$higherLevelSplit(int expValue, CallbackInfoReturnable cir) { - // @formatter:off - if (expValue > 162670129) { cir.setReturnValue(expValue - 100000); return; } - if (expValue > 81335063) { cir.setReturnValue(81335063); return; } - if (expValue > 40667527) { cir.setReturnValue(40667527); return; } - if (expValue > 20333759) { cir.setReturnValue(20333759); return; } - if (expValue > 10166857) { cir.setReturnValue(10166857); return; } - if (expValue > 5083423) { cir.setReturnValue(5083423); return; } - if (expValue > 2541701) { cir.setReturnValue(2541701); return; } - if (expValue > 1270849) { cir.setReturnValue(1270849); return; } - if (expValue > 635413) { cir.setReturnValue(635413); return; } - if (expValue > 317701) { cir.setReturnValue(317701); return; } - if (expValue > 158849) { cir.setReturnValue(158849); return; } - if (expValue > 79423) { cir.setReturnValue(79423); return; } - if (expValue > 39709) { cir.setReturnValue(39709); return; } - if (expValue > 19853) { cir.setReturnValue(19853); return; } - if (expValue > 9923) { cir.setReturnValue(9923); return; } - if (expValue > 4957) { cir.setReturnValue(4957); } - // @formatter:on - } - - @Override - public void burn(float amount) { - this.attackEntityFrom(DamageSource.IN_FIRE, amount); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/LeashKnotEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/LeashKnotEntityMixin.java deleted file mode 100644 index 5ad9a35c..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/LeashKnotEntityMixin.java +++ /dev/null @@ -1,68 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.item.LeashKnotEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.play.server.SMountEntityPacket; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.AxisAlignedBB; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(LeashKnotEntity.class) -public abstract class LeashKnotEntityMixin extends HangingEntityMixin { - - @Inject(method = "updateBoundingBox", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;chunkCheck(Lnet/minecraft/entity/Entity;)V")) - private void arclight$checkIfValid(CallbackInfo ci) { - if (!valid) ci.cancel(); - } - - /** - * @author IzzelAliz - * @reason - */ - @SuppressWarnings("ConstantConditions") - @Overwrite - public ActionResultType processInitialInteract(final PlayerEntity entityhuman, final Hand enumhand) { - if (this.world.isRemote) { - return ActionResultType.SUCCESS; - } - boolean flag = false; - final double d0 = 7.0; - final List list = this.world.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB(this.getPosX() - 7.0, this.getPosY() - 7.0, this.getPosZ() - 7.0, this.getPosX() + 7.0, this.getPosY() + 7.0, this.getPosZ() + 7.0)); - for (final MobEntity entityinsentient : list) { - if (entityinsentient.getLeashHolder() == entityhuman) { - if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, (LeashKnotEntity) (Object) this, entityhuman).isCancelled()) { - ((ServerPlayerEntity) entityhuman).connection.sendPacket(new SMountEntityPacket(entityinsentient, entityinsentient.getLeashHolder())); - } else { - entityinsentient.setLeashHolder((LeashKnotEntity) (Object) this, true); - flag = true; - } - } - } - if (!flag) { - boolean die = true; - for (final MobEntity entityinsentient : list) { - if (entityinsentient.getLeashed() && entityinsentient.getLeashHolder() == (Object) this) { - if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) { - die = false; - } else { - entityinsentient.clearLeashed(true, !entityhuman.abilities.isCreativeMode); - } - } - } - if (die) { - this.remove(); - } - } - return ActionResultType.CONSUME; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/PaintingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/PaintingEntityMixin.java deleted file mode 100644 index e06274d1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/PaintingEntityMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import com.google.common.collect.Lists; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.item.PaintingEntity; -import net.minecraft.entity.item.PaintingType; -import net.minecraft.world.World; -import net.minecraftforge.registries.ForgeRegistries; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(PaintingEntity.class) -public abstract class PaintingEntityMixin extends HangingEntityMixin { - - @Shadow public PaintingType art; - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { - final List list = Lists.newArrayList(ForgeRegistries.PAINTING_TYPES.getValues()); - this.art = list.get(this.rand.nextInt(list.size())); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/TNTEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/TNTEntityMixin.java deleted file mode 100644 index 2d957a0b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/TNTEntityMixin.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item; - -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.item.TNTEntity; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.world.Explosion; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.entity.Explosive; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TNTEntity.class) -public abstract class TNTEntityMixin extends EntityMixin { - - @Shadow private int fuse; - - public float yield; - public boolean isIncendiary; - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { - yield = 4; - isIncendiary = false; - } - - @Inject(method = "(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/LivingEntity;)V", at = @At("RETURN")) - private void arclight$init(World worldIn, double x, double y, double z, LivingEntity igniter, CallbackInfo ci) { - yield = 4; - isIncendiary = false; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void tick() { - if (!this.hasNoGravity()) { - this.setMotion(this.getMotion().add(0.0D, -0.04D, 0.0D)); - } - - this.move(MoverType.SELF, this.getMotion()); - this.setMotion(this.getMotion().scale(0.98D)); - if (this.onGround) { - this.setMotion(this.getMotion().mul(0.7D, -0.5D, 0.7D)); - } - - --this.fuse; - if (this.fuse <= 0) { - if (!this.world.isRemote) { - this.explode(); - } - this.remove(); - } else { - this.func_233566_aG_(); - if (this.world.isRemote) { - this.world.addParticle(ParticleTypes.SMOKE, this.getPosX(), this.getPosY() + 0.5D, this.getPosZ(), 0.0D, 0.0D, 0.0D); - } - } - - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void explode() { - ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) this.getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.world.createExplosion((TNTEntity) (Object) this, this.getPosX(), this.getPosY() + this.getHeight() / 16.0f, this.getPosZ(), event.getRadius(), event.getFire(), Explosion.Mode.BREAK); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/AbstractMinecartEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/AbstractMinecartEntityMixin.java deleted file mode 100644 index c83b8bcf..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/AbstractMinecartEntityMixin.java +++ /dev/null @@ -1,317 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item.minecart; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.block.AbstractRailBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.PoweredRailBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.item.minecart.AbstractMinecartEntity; -import net.minecraft.entity.passive.IronGolemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EntityPredicates; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Vehicle; -import org.bukkit.event.vehicle.VehicleDamageEvent; -import org.bukkit.event.vehicle.VehicleDestroyEvent; -import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; -import org.bukkit.event.vehicle.VehicleMoveEvent; -import org.bukkit.event.vehicle.VehicleUpdateEvent; -import org.bukkit.util.Vector; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(AbstractMinecartEntity.class) -public abstract class AbstractMinecartEntityMixin extends EntityMixin { - - // @formatter:off - @Shadow public abstract void setRollingDirection(int rollingDirection); - @Shadow public abstract int getRollingDirection(); - @Shadow public abstract void setRollingAmplitude(int rollingAmplitude); - @Shadow public abstract void setDamage(float damage); - @Shadow public abstract float getDamage(); - @Shadow public abstract void killMinecart(DamageSource source); - @Shadow public abstract int getRollingAmplitude(); - @Shadow private int turnProgress; - @Shadow private double minecartX; - @Shadow private double minecartY; - @Shadow private double minecartZ; - @Shadow private double minecartYaw; - @Shadow private double minecartPitch; - @Shadow protected abstract void moveAlongTrack(BlockPos pos, BlockState state); - @Shadow public abstract void onActivatorRailPass(int x, int y, int z, boolean receivingPower); - @Shadow private boolean isInReverse; - @Shadow public abstract AbstractMinecartEntity.Type getMinecartType(); - @Shadow(remap = false) public abstract boolean canUseRail(); - // @formatter:on - - public boolean slowWhenEmpty = true; - private double derailedX = 0.5; - private double derailedY = 0.5; - private double derailedZ = 0.5; - private double flyingX = 0.95; - private double flyingY = 0.95; - private double flyingZ = 0.95; - public double maxSpeed = 0.4D; - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { - slowWhenEmpty = true; - derailedX = 0.5; - derailedY = 0.5; - derailedZ = 0.5; - flyingX = 0.95; - flyingY = 0.95; - flyingZ = 0.95; - maxSpeed = 0.4D; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean attackEntityFrom(DamageSource source, float amount) { - if (this.world.isRemote || this.removed) { - return true; - } - if (this.isInvulnerableTo(source)) { - return false; - } - Vehicle vehicle = (Vehicle) this.getBukkitEntity(); - org.bukkit.entity.Entity passenger = (source.getTrueSource() == null) ? null : ((EntityBridge) source.getTrueSource()).bridge$getBukkitEntity(); - VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, amount); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return false; - } - amount = (float) event.getDamage(); - this.setRollingDirection(-this.getRollingDirection()); - this.setRollingAmplitude(10); - this.markVelocityChanged(); - this.setDamage(this.getDamage() + amount * 10.0f); - boolean flag = source.getTrueSource() instanceof PlayerEntity && ((PlayerEntity) source.getTrueSource()).abilities.isCreativeMode; - if (flag || this.getDamage() > 40.0f) { - VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger); - Bukkit.getPluginManager().callEvent(destroyEvent); - if (destroyEvent.isCancelled()) { - this.setDamage(40.0f); - return true; - } - this.removePassengers(); - if (flag && !this.hasCustomName()) { - this.remove(); - } else { - this.killMinecart(source); - } - } - return true; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void tick() { - double prevX = this.getPosX(); - double prevY = this.getPosY(); - double prevZ = this.getPosZ(); - float prevYaw = this.rotationYaw; - float prevPitch = this.rotationPitch; - if (this.getRollingAmplitude() > 0) { - this.setRollingAmplitude(this.getRollingAmplitude() - 1); - } - if (this.getDamage() > 0.0f) { - this.setDamage(this.getDamage() - 1.0f); - } - if (this.getPosY() < -64.0) { - this.outOfWorld(); - } - if (this.world.isRemote) { - if (this.turnProgress > 0) { - double d0 = this.getPosX() + (this.minecartX - this.getPosX()) / this.turnProgress; - double d2 = this.getPosY() + (this.minecartY - this.getPosY()) / this.turnProgress; - double d3 = this.getPosZ() + (this.minecartZ - this.getPosZ()) / this.turnProgress; - double d4 = MathHelper.wrapDegrees(this.minecartYaw - this.rotationYaw); - this.rotationYaw += (float) (d4 / this.turnProgress); - this.rotationPitch += (float) ((this.minecartPitch - this.rotationPitch) / this.turnProgress); - --this.turnProgress; - this.setPosition(d0, d2, d3); - this.setRotation(this.rotationYaw, this.rotationPitch); - } else { - this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ()); - this.setRotation(this.rotationYaw, this.rotationPitch); - } - } else { - /* - this.prevPosX = this.getPosX(); - this.prevPosY = this.getPosY(); - this.prevPosZ = this.getPosZ(); - */ - if (!this.hasNoGravity()) { - this.setMotion(this.getMotion().add(0.0, -0.04, 0.0)); - } - int i = MathHelper.floor(this.getPosX()); - int j = MathHelper.floor(this.getPosY()); - int k = MathHelper.floor(this.getPosZ()); - if (this.world.getBlockState(new BlockPos(i, j - 1, k)).isIn(BlockTags.RAILS)) { - --j; - } - BlockPos blockposition = new BlockPos(i, j, k); - BlockState blockstate = this.world.getBlockState(blockposition); - if (this.canUseRail() && AbstractRailBlock.isRail(blockstate)) { - this.moveAlongTrack(blockposition, blockstate); - if (blockstate.getBlock() instanceof PoweredRailBlock && ((PoweredRailBlock) blockstate.getBlock()).isActivatorRail()) { - this.onActivatorRailPass(i, j, k, blockstate.get(PoweredRailBlock.POWERED)); - } - } else { - this.moveDerailedMinecart(); - } - this.doBlockCollisions(); - this.rotationPitch = 0.0f; - double d5 = this.prevPosX - this.getPosX(); - double d6 = this.prevPosZ - this.getPosZ(); - if (d5 * d5 + d6 * d6 > 0.001) { - this.rotationYaw = (float) (MathHelper.atan2(d6, d5) * 180.0 / 3.141592653589793); - if (this.isInReverse) { - this.rotationYaw += 180.0f; - } - } - double d7 = MathHelper.wrapDegrees(this.rotationYaw - this.prevRotationYaw); - if (d7 < -170.0 || d7 >= 170.0) { - this.rotationYaw += 180.0f; - this.isInReverse = !this.isInReverse; - } - this.setRotation(this.rotationYaw, this.rotationPitch); - org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld(); - Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); - Location to = new Location(bworld, this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, this.rotationPitch); - Vehicle vehicle = (Vehicle) this.getBukkitEntity(); - Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle)); - if (!from.equals(to)) { - Bukkit.getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to)); - } - if (this.getMinecartType() == AbstractMinecartEntity.Type.RIDEABLE && Entity.horizontalMag(this.getMotion()) > 0.01) { - List list = this.world.getEntitiesInAABBexcluding((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224), EntityPredicates.pushableBy((AbstractMinecartEntity) (Object) this)); - if (!list.isEmpty()) { - for (Entity entity : list) { - if (!(entity instanceof PlayerEntity) && !(entity instanceof IronGolemEntity) && !(entity instanceof AbstractMinecartEntity) && !this.isBeingRidden() && !entity.isPassenger()) { - VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity()); - Bukkit.getPluginManager().callEvent(collisionEvent); - if (!collisionEvent.isCancelled()) { - entity.startRiding((AbstractMinecartEntity) (Object) this); - } - } else { - if (!isRidingSameEntity(entity)) { - VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity()); - Bukkit.getPluginManager().callEvent(collisionEvent); - if (collisionEvent.isCancelled()) { - continue; - } - } - entity.applyEntityCollision((AbstractMinecartEntity) (Object) this); - } - } - } - } else { - for (Entity entity2 : this.world.getEntitiesWithinAABBExcludingEntity((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224))) { - if (!this.isPassenger(entity2) && entity2.canBePushed() && entity2 instanceof AbstractMinecartEntity) { - VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity2).bridge$getBukkitEntity()); - Bukkit.getPluginManager().callEvent(collisionEvent2); - if (collisionEvent2.isCancelled()) { - continue; - } - entity2.applyEntityCollision((AbstractMinecartEntity) (Object) this); - } - } - } - this.func_233566_aG_(); - if (this.isInLava()) { - this.setOnFireFromLava(); - this.fallDistance *= 0.5F; - } - this.firstUpdate = false; - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected double getMaximumSpeed() { - return maxSpeed; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void moveDerailedMinecart() { - final double d0 = this.getMaximumSpeed(); - final Vector3d vec3d = this.getMotion(); - this.setMotion(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0)); - if (this.onGround) { - this.setMotion(new Vector3d(this.getMotion().x * this.derailedX, this.getMotion().y * this.derailedY, this.getMotion().z * this.derailedZ)); - } - this.move(MoverType.SELF, this.getMotion()); - if (!this.onGround) { - this.setMotion(new Vector3d(this.getMotion().x * this.flyingX, this.getMotion().y * this.flyingY, this.getMotion().z * this.flyingZ)); - } - } - - @Redirect(method = "applyDrag", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/minecart/AbstractMinecartEntity;isBeingRidden()Z")) - private boolean arclight$slowWhenEmpty(AbstractMinecartEntity abstractMinecartEntity) { - return this.isBeingRidden() || !this.slowWhenEmpty; - } - - @Inject(method = "applyEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/minecart/AbstractMinecartEntity;isPassenger(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$vehicleCollide(Entity entityIn, CallbackInfo ci) { - if (!this.isPassenger(entityIn)) { - VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity()); - Bukkit.getPluginManager().callEvent(collisionEvent); - if (collisionEvent.isCancelled()) { - ci.cancel(); - } - } - } - - public Vector getFlyingVelocityMod() { - return new Vector(flyingX, flyingY, flyingZ); - } - - public void setFlyingVelocityMod(Vector flying) { - flyingX = flying.getX(); - flyingY = flying.getY(); - flyingZ = flying.getZ(); - } - - public Vector getDerailedVelocityMod() { - return new Vector(derailedX, derailedY, derailedZ); - } - - public void setDerailedVelocityMod(Vector derailed) { - derailedX = derailed.getX(); - derailedY = derailed.getY(); - derailedZ = derailed.getZ(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/CommandBlockMinecartEntity_MinecartCommandLogicMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/CommandBlockMinecartEntity_MinecartCommandLogicMixin.java deleted file mode 100644 index 66095a45..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/CommandBlockMinecartEntity_MinecartCommandLogicMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.item.minecart; - -import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.entity.item.minecart.CommandBlockMinecartEntity; -import org.bukkit.command.CommandSender; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(CommandBlockMinecartEntity.MinecartCommandLogic.class) -public abstract class CommandBlockMinecartEntity_MinecartCommandLogicMixin implements ICommandSourceBridge { - - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_210168_a"}, remap = false) - private CommandBlockMinecartEntity outerThis; - - public CommandSender getBukkitSender(CommandSource wrapper) { - return ((EntityBridge) outerThis).bridge$getBukkitEntity(); - } - - @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { - return getBukkitSender(wrapper); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntityMixin.java deleted file mode 100644 index 3fa5de26..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntityMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.AbstractRaiderEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.DamageSource; -import net.minecraft.world.raid.Raid; -import org.bukkit.event.entity.EntityPotionEffectEvent; -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; - -@Mixin(AbstractRaiderEntity.class) -public abstract class AbstractRaiderEntityMixin extends CreatureEntityMixin { - - @Inject(method = "onDeath", locals = LocalCapture.CAPTURE_FAILHARD, require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$raid(DamageSource cause, CallbackInfo ci, Entity entity, Raid raid, ItemStack itemStack, PlayerEntity playerEntity) { - ((PlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntity_FindTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntity_FindTargetGoalMixin.java deleted file mode 100644 index c7d6d8c3..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractRaiderEntity_FindTargetGoalMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.monster.AbstractRaiderEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(AbstractRaiderEntity.FindTargetGoal.class) -public abstract class AbstractRaiderEntity_FindTargetGoalMixin { - - @Redirect(method = "startExecuting", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/AbstractRaiderEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$reason(AbstractRaiderEntity abstractRaiderEntity, LivingEntity entitylivingbaseIn) { - ((MobEntityBridge) abstractRaiderEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); - abstractRaiderEntity.setAttackTarget(entitylivingbaseIn); - } - - @Redirect(method = "resetTask", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/AbstractRaiderEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$reason2(AbstractRaiderEntity abstractRaiderEntity, LivingEntity entitylivingbaseIn) { - ((MobEntityBridge) abstractRaiderEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); - abstractRaiderEntity.setAttackTarget(entitylivingbaseIn); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractSkeletonEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractSkeletonEntityMixin.java deleted file mode 100644 index 1b2eb525..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/AbstractSkeletonEntityMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.monster.AbstractSkeletonEntity; -import net.minecraft.entity.projectile.AbstractArrowEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundEvents; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityShootBowEvent; -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; - -@Mixin(AbstractSkeletonEntity.class) -public abstract class AbstractSkeletonEntityMixin extends CreatureEntityMixin { - - @Inject(method = "attackEntityWithRangedAttack", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/AbstractSkeletonEntity;playSound(Lnet/minecraft/util/SoundEvent;FF)V")) - private void arclight$shootBow(LivingEntity target, float distanceFactor, CallbackInfo ci, ItemStack itemStack, AbstractArrowEntity arrowEntity) { - EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent((AbstractSkeletonEntity) (Object) this, this.getHeldItemMainhand(), null, arrowEntity, Hand.MAIN_HAND, 0.8F, true); - if (event.isCancelled()) { - event.getProjectile().remove(); - ci.cancel(); - return; - } - if (event.getProjectile() != ((EntityBridge) arrowEntity).bridge$getBukkitEntity()) { - this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CreeperEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CreeperEntityMixin.java deleted file mode 100644 index 424f339e..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CreeperEntityMixin.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.monster.CreeperEntityBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.AreaEffectCloudEntity; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.monster.CreeperEntity; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.potion.EffectInstance; -import net.minecraft.world.Explosion; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.ForgeEventFactory; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.CreeperPowerEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import 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.Collection; - -@Mixin(CreeperEntity.class) -public abstract class CreeperEntityMixin extends CreatureEntityMixin implements CreeperEntityBridge { - - // @formatter:off - @Shadow @Final private static DataParameter POWERED; - @Shadow public int explosionRadius; - @Shadow protected abstract void spawnLingeringCloud(); - @Shadow private int timeSinceIgnited; - // @formatter:on - - @Inject(method = "causeLightningStrike", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/monster/CreeperEntity;dataManager:Lnet/minecraft/network/datasync/EntityDataManager;")) - private void arclight$lightningBolt(ServerWorld world, LightningBoltEntity lightningBolt, CallbackInfo ci) { - if (CraftEventFactory.callCreeperPowerEvent((CreeperEntity) (Object) this, lightningBolt, CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) { - ci.cancel(); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void explode() { - if (!this.world.isRemote) { - Explosion.Mode explosion_effect = ForgeEventFactory.getMobGriefingEvent(this.world, (CreeperEntity) (Object) this) ? Explosion.Mode.DESTROY : Explosion.Mode.NONE; - final float f = this.dataManager.get(POWERED) ? 2.0f : 1.0f; - final ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), this.explosionRadius * f, false); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.dead = true; - this.world.createExplosion((CreeperEntity) (Object) this, this.getPosX(), this.getPosY(), this.getPosZ(), event.getRadius(), event.getFire(), explosion_effect); - this.remove(); - this.spawnLingeringCloud(); - } else { - this.timeSinceIgnited = 0; - } - } - } - - @Inject(method = "spawnLingeringCloud", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$creeperCloud(CallbackInfo ci, Collection collection, AreaEffectCloudEntity areaeffectcloudentity) { - areaeffectcloudentity.setOwner((CreeperEntity) (Object) this); - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EXPLOSION); - } - - public void setPowered(boolean power) { - this.dataManager.set(POWERED, power); - } - - @Override - public void bridge$setPowered(boolean power) { - setPowered(power); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ElderGuardianEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ElderGuardianEntityMixin.java deleted file mode 100644 index 6b01a639..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ElderGuardianEntityMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.monster.ElderGuardianEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.potion.EffectInstance; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ElderGuardianEntity.class) -public abstract class ElderGuardianEntityMixin extends CreatureEntityMixin { - - @Redirect(method = "updateAITasks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private boolean arclight$potionReason(ServerPlayerEntity playerEntity, EffectInstance effectInstanceIn) { - ((ServerPlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - return playerEntity.addPotionEffect(effectInstanceIn); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntityMixin.java deleted file mode 100644 index e7976802..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntityMixin.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.monster.EndermanEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.attributes.AttributeModifier; -import net.minecraft.entity.ai.attributes.Attributes; -import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance; -import net.minecraft.entity.monster.EndermanEntity; -import net.minecraft.network.datasync.DataParameter; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import javax.annotation.Nullable; - -@Mixin(EndermanEntity.class) -public abstract class EndermanEntityMixin extends CreatureEntityMixin implements EndermanEntityBridge { - - // @formatter:off - @Shadow private int targetChangeTime; - @Shadow @Final private static DataParameter SCREAMING; - @Shadow @Final private static DataParameter field_226535_bx_; - @Shadow @Final private static AttributeModifier ATTACKING_SPEED_BOOST; - // @formatter:on - - @Override - public void bridge$updateTarget(LivingEntity livingEntity) { - ModifiableAttributeInstance modifiableattributeinstance = this.getAttribute(Attributes.MOVEMENT_SPEED); - if (livingEntity == null) { - this.targetChangeTime = 0; - this.dataManager.set(SCREAMING, false); - this.dataManager.set(field_226535_bx_, false); - modifiableattributeinstance.removeModifier(ATTACKING_SPEED_BOOST); - } else { - this.targetChangeTime = this.ticksExisted; - this.dataManager.set(SCREAMING, true); - if (!modifiableattributeinstance.hasModifier(ATTACKING_SPEED_BOOST)) { - modifiableattributeinstance.applyNonPersistentModifier(ATTACKING_SPEED_BOOST); - } - } - } - - @Override - public boolean setGoalTarget(LivingEntity livingEntity, EntityTargetEvent.TargetReason reason, boolean fireEvent) { - if (!super.setGoalTarget(livingEntity, reason, fireEvent)) { - return false; - } - bridge$updateTarget(getAttackTarget()); - return true; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void setAttackTarget(@Nullable LivingEntity entity) { - this.bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); - super.setAttackTarget(entity); - if (arclight$targetSuccess) { - bridge$updateTarget(getAttackTarget()); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/GhastEntity_FireballAttackGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/GhastEntity_FireballAttackGoalMixin.java deleted file mode 100644 index 4e74c261..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/GhastEntity_FireballAttackGoalMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.GhastEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import io.izzel.arclight.common.bridge.entity.projectile.DamagingProjectileEntityBridge; - -@Mixin(targets = "net.minecraft.entity.monster.GhastEntity.FireballAttackGoal") -public abstract class GhastEntity_FireballAttackGoalMixin { - - @Shadow @Final private GhastEntity parentEntity; - - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$setYaw(World world, Entity entityIn) { - ((DamagingProjectileEntityBridge) entityIn).bridge$setBukkitYield(this.parentEntity.getFireballStrength()); - return world.addEntity(entityIn); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/PhantomEntity_AttackPlayerGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/PhantomEntity_AttackPlayerGoalMixin.java deleted file mode 100644 index e3703f3b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/PhantomEntity_AttackPlayerGoalMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.monster.PhantomEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(targets = "net.minecraft.entity.monster.PhantomEntity.AttackPlayerGoal") -public abstract class PhantomEntity_AttackPlayerGoalMixin { - - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_203141_a"}, remap = false) - private PhantomEntity outerThis; - - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = "shouldExecute", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/monster/PhantomEntity;func_70624_b(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$reason(CallbackInfoReturnable cir) { - ((MobEntityBridge) outerThis).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/RavagerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/RavagerEntityMixin.java deleted file mode 100644 index c4c390db..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/RavagerEntityMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.RavagerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(RavagerEntity.class) -public abstract class RavagerEntityMixin extends CreatureEntityMixin { - - @Redirect(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;destroyBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) - private boolean arclight$entityChangeBlock(World world, BlockPos pos, boolean dropBlock, Entity entityIn) { - return !CraftEventFactory.callEntityChangeBlockEvent((RavagerEntity) (Object) this, pos, Blocks.AIR.getDefaultState()).isCancelled() - && world.destroyBlock(pos, dropBlock, entityIn); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ShulkerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ShulkerEntityMixin.java deleted file mode 100644 index da107075..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ShulkerEntityMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.monster.ShulkerEntity; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.world.server.ServerWorld; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ShulkerEntity.class) -public abstract class ShulkerEntityMixin extends CreatureEntityMixin { - - @Inject(method = "notifyDataManagerChange", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/monster/ShulkerEntity;forceSetPosition(DDD)V")) - private void arclight$chunkCheck(DataParameter key, CallbackInfo ci) { - if (valid) ((ServerWorld) this.world).chunkCheck((ShulkerEntity) (Object) this); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_HideInStoneGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_HideInStoneGoalMixin.java deleted file mode 100644 index d71fe8e9..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_HideInStoneGoalMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import net.minecraft.block.BlockState; -import net.minecraft.block.SilverfishBlock; -import net.minecraft.entity.CreatureEntity; -import net.minecraft.entity.ai.goal.RandomWalkingGoal; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(targets = "net.minecraft.entity.monster.SilverfishEntity.HideInStoneGoal") -public abstract class SilverfishEntity_HideInStoneGoalMixin extends RandomWalkingGoal { - - public SilverfishEntity_HideInStoneGoalMixin(CreatureEntity creatureIn, double speedIn) { - super(creatureIn, speedIn); - } - - @Inject(method = "startExecuting", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$entityChangeBlock(CallbackInfo ci, IWorld world, BlockPos blockPos, BlockState blockState) { - if (CraftEventFactory.callEntityChangeBlockEvent(this.creature, blockPos, SilverfishBlock.infest(blockState.getBlock())).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpellcastingIllagerEntity_UseSpellGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpellcastingIllagerEntity_UseSpellGoalMixin.java deleted file mode 100644 index 61055ae0..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpellcastingIllagerEntity_UseSpellGoalMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import net.minecraft.entity.monster.SpellcastingIllagerEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(SpellcastingIllagerEntity.UseSpellGoal.class) -public abstract class SpellcastingIllagerEntity_UseSpellGoalMixin { - - // @formatter:off - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_193323_e"}, remap = false) private SpellcastingIllagerEntity outerThis; - @Shadow protected abstract SpellcastingIllagerEntity.SpellType getSpellType(); - // @formatter:on - - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/SpellcastingIllagerEntity$UseSpellGoal;castSpell()V")) - private void arclight$castSpell(CallbackInfo ci) { - if (!CraftEventFactory.handleEntitySpellCastEvent(outerThis, this.getSpellType())) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpiderEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpiderEntityMixin.java deleted file mode 100644 index 5354d223..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SpiderEntityMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.ILivingEntityData; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.monster.SpiderEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.DifficultyInstance; -import net.minecraft.world.IServerWorld; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(SpiderEntity.class) -public abstract class SpiderEntityMixin extends CreatureEntityMixin { - - @Inject(method = "onInitialSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/SpiderEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$potionReason(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, ILivingEntityData spawnDataIn, CompoundNBT dataTag, CallbackInfoReturnable cir) { - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.SPIDER_SPAWN); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitchEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitchEntityMixin.java deleted file mode 100644 index e54edb13..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitchEntityMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import net.minecraft.entity.monster.WitchEntity; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(WitchEntity.class) -public abstract class WitchEntityMixin extends AbstractRaiderEntityMixin { - - @Inject(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/WitchEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$reason(CallbackInfo ci) { - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieEntityMixin.java deleted file mode 100644 index d45ee0c0..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieEntityMixin.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.ILivingEntityData; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.entity.monster.ZombieEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.DamageSource; -import net.minecraft.world.DifficultyInstance; -import net.minecraft.world.IServerWorld; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.event.entity.living.ZombieEvent; -import org.bukkit.Bukkit; -import org.bukkit.entity.Zombie; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.event.entity.EntityTransformEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(ZombieEntity.class) -public abstract class ZombieEntityMixin extends CreatureEntityMixin { - - @Inject(method = "func_234341_c_", at = @At("HEAD")) - private void arclight$transformReason(EntityType entityType, CallbackInfo ci) { - this.bridge$pushTransformReason(EntityTransformEvent.TransformReason.DROWNED); - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.DROWNED); - } - - @Inject(method = "func_234341_c_", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) - private void arclight$stopConversion(EntityType entityType, CallbackInfo ci, ZombieEntity zombieEntity) { - if (zombieEntity == null) { - ((Zombie) this.bridge$getBukkitEntity()).setConversionTime(-1); - } - } - - @Inject(method = "attackEntityFrom", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieEntity;onInitialSpawn(Lnet/minecraft/world/IServerWorld;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/ILivingEntityData;Lnet/minecraft/nbt/CompoundNBT;)Lnet/minecraft/entity/ILivingEntityData;")) - private void arclight$spawnWithReason(DamageSource source, float amount, CallbackInfoReturnable cir, ServerWorld world, LivingEntity livingEntity, int i, int j, int k, ZombieEvent.SummonAidEvent event, ZombieEntity zombieEntity) { - ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); - if (livingEntity != null) { - ((MobEntityBridge) zombieEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); - } - } - - @Redirect(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) - private void arclight$entityCombust(Entity entity, int seconds) { - EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false); - } - } - - @Eject(method = "onKillEntity", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;func_233656_b_(Lnet/minecraft/entity/EntityType;Z)Lnet/minecraft/entity/MobEntity;")) - private T arclight$transform(VillagerEntity villagerEntity, EntityType entityType, boolean flag, CallbackInfo ci) { - ((WorldBridge) villagerEntity.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.INFECTION); - ((MobEntityBridge) villagerEntity).bridge$pushTransformReason(EntityTransformEvent.TransformReason.INFECTION); - T t = villagerEntity.func_233656_b_(entityType, flag); - if (t == null) { - ci.cancel(); - } - return t; - } - - @Inject(method = "onInitialSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$mount(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, ILivingEntityData spawnDataIn, CompoundNBT dataTag, CallbackInfoReturnable cir) { - ((WorldBridge) worldIn.getWorld()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.MOUNT); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/piglin/PiglinTasksMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/piglin/PiglinTasksMixin.java deleted file mode 100644 index 6e39cc75..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/piglin/PiglinTasksMixin.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.monster.piglin; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.brain.memory.MemoryModuleType; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.monster.piglin.PiglinEntity; -import net.minecraft.entity.monster.piglin.PiglinTasks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(PiglinTasks.class) -public abstract class PiglinTasksMixin { - - // @formatter:off - @Shadow private static void func_234531_r_(PiglinEntity p_234531_0_) { } - @Shadow private static ItemStack func_234465_a_(ItemEntity p_234465_0_) { return null; } - @Shadow protected static boolean func_234480_a_(Item p_234480_0_) { return false; } - @Shadow private static void func_241427_c_(PiglinEntity p_241427_0_, ItemStack p_241427_1_) { } - @Shadow private static void func_234501_d_(LivingEntity p_234501_0_) { } - @Shadow private static boolean func_234499_c_(Item p_234499_0_) { return false; } - @Shadow private static boolean func_234538_z_(PiglinEntity p_234538_0_) { return false; } - @Shadow private static void func_234536_x_(PiglinEntity p_234536_0_) { } - @Shadow private static void func_234498_c_(PiglinEntity p_234498_0_, ItemStack p_234498_1_) { } - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected static void func_234470_a_(PiglinEntity piglinEntity, ItemEntity itemEntity) { - ItemStack itemstack; - func_234531_r_(piglinEntity); - if (itemEntity.getItem().getItem() == Items.GOLD_NUGGET && !CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, 0, false).isCancelled()) { - piglinEntity.onItemPickup(itemEntity, itemEntity.getItem().getCount()); - itemstack = itemEntity.getItem(); - itemEntity.remove(); - } else if (!CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, itemEntity.getItem().getCount() - 1, false).isCancelled()) { - piglinEntity.onItemPickup(itemEntity, 1); - itemstack = func_234465_a_(itemEntity); - } else { - return; - } - Item item = itemstack.getItem(); - if (func_234480_a_(item)) { - piglinEntity.getBrain().removeMemory(MemoryModuleType.TIME_TRYING_TO_REACH_ADMIRE_ITEM); - func_241427_c_(piglinEntity, itemstack); - func_234501_d_(piglinEntity); - } else if (func_234499_c_(item) && !func_234538_z_(piglinEntity)) { - func_234536_x_(piglinEntity); - } else { - ((MobEntityBridge) piglinEntity).bridge$captureItemDrop(itemEntity); - boolean flag = piglinEntity.func_233665_g_(itemstack); - if (!flag) { - func_234498_c_(piglinEntity, itemstack); - } - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/AnimalEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/AnimalEntityMixin.java deleted file mode 100644 index 5a84e829..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/AnimalEntityMixin.java +++ /dev/null @@ -1,134 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.passive.AnimalEntityBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.AgeableEntityMixin; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.entity.AgeableEntity; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.stats.Stats; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Hand; -import net.minecraft.world.GameRules; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityEnterLoveModeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; - -@Mixin(AnimalEntity.class) -public abstract class AnimalEntityMixin extends AgeableEntityMixin implements AnimalEntityBridge { - - // @formatter:off - @Shadow public ActionResultType getEntityInteractionResult(PlayerEntity playerIn, Hand hand) { return null; } - @Shadow public int inLove; - @Shadow public abstract void resetInLove(); - @Shadow @Nullable public abstract ServerPlayerEntity getLoveCause(); - // @formatter:on - - public ItemStack breedItem; - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean attackEntityFrom(DamageSource source, float amount) { - return super.attackEntityFrom(source, amount); - } - - @Inject(method = "setInLove(Lnet/minecraft/entity/player/PlayerEntity;)V", cancellable = true, at = @At("HEAD")) - private void arclight$enterLove(PlayerEntity player, CallbackInfo ci) { - EntityEnterLoveModeEvent event = CraftEventFactory.callEntityEnterLoveModeEvent(player, (AnimalEntity) (Object) this, 600); - if (event.isCancelled()) { - ci.cancel(); - } else { - arclight$loveTime = event.getTicksInLove(); - } - } - - private transient int arclight$loveTime; - - @Inject(method = "setInLove(Lnet/minecraft/entity/player/PlayerEntity;)V", at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/passive/AnimalEntity;inLove:I")) - private void arclight$inLove(PlayerEntity player, CallbackInfo ci) { - this.inLove = arclight$loveTime; - if (player != null) { - this.breedItem = player.inventory.getCurrentItem(); - } - } - - @Override - public ItemStack bridge$getBreedItem() { - return breedItem; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void spawnBabyAnimal(ServerWorld world, AnimalEntity animalEntity) { - AgeableEntity child = this.createChild(world, animalEntity); - final BabyEntitySpawnEvent event = new BabyEntitySpawnEvent((AnimalEntity) (Object) this, animalEntity, child); - final boolean cancelled = MinecraftForge.EVENT_BUS.post(event); - child = event.getChild(); - if (cancelled) { - //Reset the "inLove" state for the animals - this.setGrowingAge(6000); - animalEntity.setGrowingAge(6000); - this.resetInLove(); - animalEntity.resetInLove(); - return; - } - if (child != null) { - if (child instanceof TameableEntity && ((TameableEntity) child).isTamed()) { - child.persistenceRequired = true; - } - ServerPlayerEntity serverplayerentity = this.getLoveCause(); - if (serverplayerentity == null && animalEntity.getLoveCause() != null) { - serverplayerentity = animalEntity.getLoveCause(); - } - - int experience = this.getRNG().nextInt(7) + 1; - org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(child, (AnimalEntity) (Object) this, animalEntity, serverplayerentity, this.breedItem, experience); - if (entityBreedEvent.isCancelled()) { - return; - } - experience = entityBreedEvent.getExperience(); - - if (serverplayerentity != null) { - serverplayerentity.addStat(Stats.ANIMALS_BRED); - CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity, (AnimalEntity) (Object) this, animalEntity, child); - } - - this.setGrowingAge(6000); - animalEntity.setGrowingAge(6000); - this.resetInLove(); - animalEntity.resetInLove(); - child.setChild(true); - child.setLocationAndAngles(this.getPosX(), this.getPosY(), this.getPosZ(), 0.0F, 0.0F); - ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); - world.func_242417_l(child); - world.setEntityState((AnimalEntity) (Object) this, (byte) 18); - if (world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { - world.addEntity(new ExperienceOrbEntity(world, this.getPosX(), this.getPosY(), this.getPosZ(), experience)); - } - - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BatEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BatEntityMixin.java deleted file mode 100644 index 207c2770..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BatEntityMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.mixin.core.entity.MobEntityMixin; -import net.minecraft.entity.passive.BatEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(BatEntity.class) -public abstract class BatEntityMixin extends MobEntityMixin { - - // @formatter:off - @Shadow public abstract boolean getIsBatHanging(); - // @formatter:on - - @Inject(method = "updateAITasks", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/BatEntity;setIsBatHanging(Z)V")) - private void arclight$toggleSleep(CallbackInfo ci) { - if (!CraftEventFactory.handleBatToggleSleepEvent((BatEntity) (Object) this, !this.getIsBatHanging())) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_AngerGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_AngerGoalMixin.java deleted file mode 100644 index 0267a55a..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_AngerGoalMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.entity.passive.BeeEntity.AngerGoal") -public class BeeEntity_AngerGoalMixin { - - @Inject(method = "setAttackTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$reason(MobEntity mobIn, LivingEntity targetIn, CallbackInfo ci) { - ((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ChickenEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ChickenEntityMixin.java deleted file mode 100644 index fb57558c..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ChickenEntityMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.ChickenEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ChickenEntity.class) -public abstract class ChickenEntityMixin extends AnimalEntityMixin { - - // @formatter:off - @Shadow public abstract boolean isChickenJockey(); - // @formatter:on - - @Inject(method = "livingTick", at = @At("HEAD")) - private void arclight$persist(CallbackInfo ci) { - if (this.isChickenJockey()) { - this.persistenceRequired = !this.canDespawn(0.0); - } - } - - @Inject(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/ChickenEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$forceDropOn(CallbackInfo ci) { - this.forceDrops = true; - } - - @Inject(method = "livingTick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/passive/ChickenEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$forceDropOff(CallbackInfo ci) { - this.forceDrops = false; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/CowEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/CowEntityMixin.java deleted file mode 100644 index b0148219..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/CowEntityMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.CowEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.DrinkHelper; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.inventory.CraftItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(CowEntity.class) -public abstract class CowEntityMixin extends AnimalEntityMixin { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public ActionResultType getEntityInteractionResult(PlayerEntity playerEntity, Hand hand) { - ItemStack itemstack = playerEntity.getHeldItem(hand); - if (itemstack.getItem() == Items.BUCKET && !this.isChild()) { - playerEntity.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F); - org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerWorld) playerEntity.world, playerEntity, this.getPosition(), this.getPosition(), null, itemstack, Items.MILK_BUCKET); - - if (event.isCancelled()) { - return ActionResultType.PASS; - } - ItemStack itemstack1 = DrinkHelper.fill(itemstack, playerEntity, CraftItemStack.asNMSCopy(event.getItemStack())); - playerEntity.setHeldItem(hand, itemstack1); - return ActionResultType.func_233537_a_(this.world.isRemote); - } else { - return super.getEntityInteractionResult(playerEntity, hand); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntityMixin.java deleted file mode 100644 index a5cb6b40..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntityMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.DolphinEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; - -@Mixin(DolphinEntity.class) -public abstract class DolphinEntityMixin extends CreatureEntityMixin { - - @Inject(method = "updateEquipmentIfNeeded", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/DolphinEntity;setItemStackToSlot(Lnet/minecraft/inventory/EquipmentSlotType;Lnet/minecraft/item/ItemStack;)V")) - private void arclight$entityPick(ItemEntity itemEntity, CallbackInfo ci) { - if (CraftEventFactory.callEntityPickupItemEvent((DolphinEntity) (Object) this, itemEntity, 0, false).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntityMixin.java deleted file mode 100644 index 5613f322..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.FoxEntity; -import net.minecraft.item.ItemStack; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge; - -import java.util.UUID; - -@Mixin(FoxEntity.class) -public abstract class FoxEntityMixin extends AnimalEntityMixin implements FoxEntityBridge { - - // @formatter:off - @Invoker("addTrustedUUID") @Override public abstract void bridge$addTrustedUUID(UUID uuidIn); - // @formatter:on - - @Redirect(method = "updateEquipmentIfNeeded", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/FoxEntity;canEquipItem(Lnet/minecraft/item/ItemStack;)Z")) - private boolean arclight$pickupEvent(FoxEntity foxEntity, ItemStack stack, ItemEntity itemEntity) { - return CraftEventFactory.callEntityPickupItemEvent((FoxEntity) (Object) this, itemEntity, stack.getCount() - 1, !this.canEquipItem(stack)).isCancelled(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_EatBerriesGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_EatBerriesGoalMixin.java deleted file mode 100644 index 6ca977f2..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_EatBerriesGoalMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.block.BlockState; -import net.minecraft.block.SweetBerryBushBlock; -import net.minecraft.entity.CreatureEntity; -import net.minecraft.entity.ai.goal.MoveToBlockGoal; -import net.minecraft.entity.passive.FoxEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(FoxEntity.EatBerriesGoal.class) -public abstract class FoxEntity_EatBerriesGoalMixin extends MoveToBlockGoal { - - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_220732_h"}, remap = false) - private FoxEntity outerThis; - - public FoxEntity_EatBerriesGoalMixin(CreatureEntity creature, double speedIn, int length) { - super(creature, speedIn, length); - } - - @Inject(method = "eatBerry", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Random;nextInt(I)I")) - private void arclight$eatBerry(CallbackInfo ci, BlockState state) { - if (CraftEventFactory.callEntityChangeBlockEvent(outerThis, this.destinationBlock, state.with(SweetBerryBushBlock.AGE, 1)).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_MateGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_MateGoalMixin.java deleted file mode 100644 index 4b0d81ee..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_MateGoalMixin.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.passive.AnimalEntityBridge; -import io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.entity.ai.goal.BreedGoal; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.FoxEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.stats.Stats; -import net.minecraft.world.GameRules; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityBreedEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(targets = "net.minecraft.entity.passive.FoxEntity.MateGoal") -public abstract class FoxEntity_MateGoalMixin extends BreedGoal { - - public FoxEntity_MateGoalMixin(AnimalEntity animal, double speedIn) { - super(animal, speedIn); - } - - /** - * @author IzzekAkuz - * @reason - */ - @Overwrite - protected void spawnBaby() { - ServerWorld serverworld = (ServerWorld) this.world; - FoxEntity foxentity = (FoxEntity) this.animal.createChild(serverworld, this.targetMate); - final BabyEntitySpawnEvent event = new BabyEntitySpawnEvent(animal, targetMate, foxentity); - final boolean cancelled = MinecraftForge.EVENT_BUS.post(event); - foxentity = (FoxEntity) event.getChild(); - if (cancelled) { - //Reset the "inLove" state for the animals - this.animal.setGrowingAge(6000); - this.targetMate.setGrowingAge(6000); - this.animal.resetInLove(); - this.targetMate.resetInLove(); - return; - } - if (foxentity != null) { - ServerPlayerEntity serverplayerentity = this.animal.getLoveCause(); - ServerPlayerEntity serverplayerentity1 = this.targetMate.getLoveCause(); - ServerPlayerEntity serverplayerentity2 = serverplayerentity; - if (serverplayerentity != null) { - ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUniqueID()); - } else { - serverplayerentity2 = serverplayerentity1; - } - - if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) { - ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUniqueID()); - } - int experience = this.animal.getRNG().nextInt(7) + 1; - final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.targetMate, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience); - if (entityBreedEvent.isCancelled()) { - return; - } - experience = entityBreedEvent.getExperience(); - if (serverplayerentity2 != null) { - serverplayerentity2.addStat(Stats.ANIMALS_BRED); - CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.targetMate, foxentity); - } - - this.animal.setGrowingAge(6000); - this.targetMate.setGrowingAge(6000); - this.animal.resetInLove(); - this.targetMate.resetInLove(); - foxentity.setGrowingAge(-24000); - foxentity.setLocationAndAngles(this.animal.getPosX(), this.animal.getPosY(), this.animal.getPosZ(), 0.0F, 0.0F); - serverworld.func_242417_l(foxentity); - this.world.setEntityState(this.animal, (byte) 18); - if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { - if (experience > 0) { - this.world.addEntity(new ExperienceOrbEntity(this.world, this.animal.getPosX(), this.animal.getPosY(), this.animal.getPosZ(), experience)); - } - } - - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_RevengeGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_RevengeGoalMixin.java deleted file mode 100644 index ad3dacd6..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/FoxEntity_RevengeGoalMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.passive.FoxEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.entity.passive.FoxEntity.RevengeGoal") -public class FoxEntity_RevengeGoalMixin { - - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_220785_i"}, remap = false) - private FoxEntity outerThis; - - @Inject(method = "startExecuting", at = @At("HEAD")) - private void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) outerThis).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/IronGolemEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/IronGolemEntityMixin.java deleted file mode 100644 index ade22a86..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/IronGolemEntityMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.passive.IronGolemEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(IronGolemEntity.class) -public abstract class IronGolemEntityMixin extends CreatureEntityMixin { - - @Inject(method = "collideWithEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/IronGolemEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$targetReason(Entity entityIn, CallbackInfo ci) { - bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.COLLISION, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/MooshroomEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/MooshroomEntityMixin.java deleted file mode 100644 index ea175280..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/MooshroomEntityMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.passive.CowEntity; -import net.minecraft.entity.passive.MooshroomEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityTransformEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.Collections; -import java.util.List; - -@Mixin(MooshroomEntity.class) -public abstract class MooshroomEntityMixin extends AnimalEntityMixin { - - @SuppressWarnings("UnresolvedMixinReference") - @Redirect(method = "onSheared", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/MooshroomEntity;func_70106_y()V")) - private void arclight$animalTransformPre(MooshroomEntity mooshroomEntity) { - } - - @SuppressWarnings("UnresolvedMixinReference") - @Inject(method = "onSheared", remap = false, cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;func_217376_c(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$animalTransform(PlayerEntity player, ItemStack item, World world, BlockPos pos, int fortune, CallbackInfoReturnable> cir, CowEntity cowEntity) { - if (CraftEventFactory.callEntityTransformEvent((MooshroomEntity) (Object) this, cowEntity, EntityTransformEvent.TransformReason.SHEARED).isCancelled()) { - cir.setReturnValue(Collections.emptyList()); - } else { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SHEARED); - this.remove(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/OcelotEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/OcelotEntityMixin.java deleted file mode 100644 index 4ba16c24..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/OcelotEntityMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.OcelotEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(OcelotEntity.class) -public abstract class OcelotEntityMixin extends AnimalEntityMixin { - - // @formatter:off - @Shadow protected abstract boolean isTrusting(); - // @formatter:on - - public boolean spawnBonus = true; - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean canDespawn(double distanceToClosestPlayer) { - return !this.isTrusting() /*&& this.ticksExisted > 2400*/; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntityMixin.java deleted file mode 100644 index bacc0219..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntityMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.PandaEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.function.Predicate; - -@Mixin(PandaEntity.class) -public abstract class PandaEntityMixin extends AnimalEntityMixin { - - @Shadow @Final private static Predicate PANDA_ITEMS; - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void updateEquipmentIfNeeded(ItemEntity itemEntity) { - boolean cancel = this.getItemStackFromSlot(EquipmentSlotType.MAINHAND).isEmpty() && PANDA_ITEMS.test(itemEntity); - if (!CraftEventFactory.callEntityPickupItemEvent((PandaEntity) (Object) this, itemEntity, 0, cancel).isCancelled()) { - ItemStack itemstack = itemEntity.getItem(); - this.setItemStackToSlot(EquipmentSlotType.MAINHAND, itemstack); - this.inventoryHandsDropChances[EquipmentSlotType.MAINHAND.getIndex()] = 2.0F; - this.onItemPickup(itemEntity, itemstack.getCount()); - itemEntity.remove(); - } - - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntity_RevengeGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntity_RevengeGoalMixin.java deleted file mode 100644 index 514def20..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PandaEntity_RevengeGoalMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(targets = "net.minecraft.entity.passive.PandaEntity.RevengeGoal") -public class PandaEntity_RevengeGoalMixin { - - @Inject(method = "setAttackTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$reason(MobEntity mobIn, LivingEntity targetIn, CallbackInfo ci) { - ((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ParrotEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ParrotEntityMixin.java deleted file mode 100644 index 79762c30..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/ParrotEntityMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.ParrotEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import org.bukkit.event.entity.EntityPotionEffectEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ParrotEntity.class) -public abstract class ParrotEntityMixin extends AnimalEntityMixin { - - @Inject(method = "getEntityInteractionResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/ParrotEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$feed(PlayerEntity playerIn, Hand hand, CallbackInfoReturnable cir) { - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.FOOD); - } - - @Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/passive/ParrotEntity;func_233687_w_(Z)V")) - private void arclight$handledInSuper(ParrotEntity parrotEntity, boolean p_233687_1_) { - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PigEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PigEntityMixin.java deleted file mode 100644 index b83dac0d..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/PigEntityMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.monster.ZombifiedPiglinEntity; -import net.minecraft.entity.passive.PigEntity; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.CreatureSpawnEvent; -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; - -@Mixin(PigEntity.class) -public abstract class PigEntityMixin extends AnimalEntityMixin { - - @Inject(method = "causeLightningStrike", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$pigZap(ServerWorld world, LightningBoltEntity lightningBolt, CallbackInfo ci, ZombifiedPiglinEntity piglin) { - if (CraftEventFactory.callPigZapEvent((PigEntity) (Object) this, lightningBolt, piglin).isCancelled()) { - ci.cancel(); - } else { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntityMixin.java deleted file mode 100644 index e82d167a..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntityMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.RabbitEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(RabbitEntity.class) -public abstract class RabbitEntityMixin extends AnimalEntityMixin { - - // @formatter:off - @Shadow public abstract void setMovementSpeed(double newSpeed); - // @formatter:on - - public void initializePathFinderGoals() { - this.setMovementSpeed(0.0D); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SnowGolemEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SnowGolemEntityMixin.java deleted file mode 100644 index caa68f22..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SnowGolemEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.block.BlockState; -import net.minecraft.entity.passive.SnowGolemEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; - -@Mixin(SnowGolemEntity.class) -public abstract class SnowGolemEntityMixin extends CreatureEntityMixin { - - @Redirect(method = "livingTick", at = @At(value = "FIELD", target = "Lnet/minecraft/util/DamageSource;ON_FIRE:Lnet/minecraft/util/DamageSource;")) - private DamageSource arclight$useMelting() { - return CraftEventFactory.MELTING; - } - - @Redirect(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private boolean arclight$blockForm(World world, BlockPos pos, BlockState state) { - return CraftEventFactory.handleBlockFormEvent(world, pos, state, (SnowGolemEntity) (Object) this); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TameableEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TameableEntityMixin.java deleted file mode 100644 index e7ae9ee7..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TameableEntityMixin.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.TameableEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(TameableEntity.class) -public abstract class TameableEntityMixin extends AnimalEntityMixin { - - // @formatter:off - @Shadow public abstract boolean isTamed(); - // @formatter:on -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntityMixin.java deleted file mode 100644 index f75aa6a1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntityMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.passive.TurtleEntityBridge; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.passive.TurtleEntity; -import net.minecraft.world.server.ServerWorld; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.gen.Invoker; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TurtleEntity.class) -public abstract class TurtleEntityMixin extends AnimalEntityMixin implements TurtleEntityBridge { - - // @formatter:off - @Accessor("isDigging") public abstract int bridge$getDigging(); - @Invoker("setDigging") public abstract void bridge$setDigging(boolean digging); - @Accessor("isDigging") public abstract void bridge$setDigging(int i); - @Invoker("setHasEgg") public abstract void bridge$setHasEgg(boolean b); - // @formatter:on - - @Inject(method = "onGrowingAdult", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TurtleEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;I)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$forceDrop(CallbackInfo ci) { - forceDrops = true; - } - - @Inject(method = "onGrowingAdult", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/passive/TurtleEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;I)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$forceDropReset(CallbackInfo ci) { - forceDrops = false; - } - - @Inject(method = "causeLightningStrike", at = @At("HEAD")) - private void arclight$lightning(ServerWorld world, LightningBoltEntity lightningBolt, CallbackInfo ci) { - CraftEventFactory.entityDamage = lightningBolt; - } - - @Inject(method = "causeLightningStrike", at = @At("RETURN")) - private void arclight$lightningReset(ServerWorld world, LightningBoltEntity lightningBolt, CallbackInfo ci) { - CraftEventFactory.entityDamage = null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntity_LayEggGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntity_LayEggGoalMixin.java deleted file mode 100644 index 4a1e3b55..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/TurtleEntity_LayEggGoalMixin.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import io.izzel.arclight.common.bridge.entity.passive.TurtleEntityBridge; -import net.minecraft.block.Blocks; -import net.minecraft.block.TurtleEggBlock; -import net.minecraft.entity.CreatureEntity; -import net.minecraft.entity.ai.goal.MoveToBlockGoal; -import net.minecraft.entity.passive.TurtleEntity; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(targets = "net.minecraft.entity.passive.TurtleEntity.LayEggGoal") -public abstract class TurtleEntity_LayEggGoalMixin extends MoveToBlockGoal { - - @Shadow @Final private TurtleEntity turtle; - - public TurtleEntity_LayEggGoalMixin(CreatureEntity creature, double speedIn, int length) { - super(creature, speedIn, length); - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void tick() { - super.tick(); - BlockPos blockpos = this.turtle.getPosition(); - if (!this.turtle.isInWater() && this.getIsAboveDestination()) { - if (((TurtleEntityBridge) this.turtle).bridge$getDigging() < 1) { - ((TurtleEntityBridge) this.turtle).bridge$setDigging(true); - } else if (((TurtleEntityBridge) this.turtle).bridge$getDigging() > 200) { - World world = this.turtle.world; - if (!CraftEventFactory.callEntityChangeBlockEvent(this.turtle, this.destinationBlock.up(), (Blocks.TURTLE_EGG.getDefaultState()).with(TurtleEggBlock.EGGS, this.turtle.getRNG().nextInt(4) + 1)).isCancelled()) { - world.playSound(null, blockpos, SoundEvents.ENTITY_TURTLE_LAY_EGG, SoundCategory.BLOCKS, 0.3f, 0.9f + world.rand.nextFloat() * 0.2f); - world.setBlockState(this.destinationBlock.up(), (Blocks.TURTLE_EGG.getDefaultState()).with(TurtleEggBlock.EGGS, this.turtle.getRNG().nextInt(4) + 1), 3); - } - ((TurtleEntityBridge) this.turtle).bridge$setHasEgg(false); - ((TurtleEntityBridge) this.turtle).bridge$setDigging(false); - this.turtle.setInLove(600); - } - - if (this.turtle.isDigging()) { - ((TurtleEntityBridge) this.turtle).bridge$setDigging(((TurtleEntityBridge) this.turtle).bridge$getDigging() + 1); - } - } - - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/WolfEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/WolfEntityMixin.java deleted file mode 100644 index c7979ebf..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/WolfEntityMixin.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; - -import net.minecraft.entity.passive.WolfEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityTargetEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(WolfEntity.class) -public abstract class WolfEntityMixin extends TameableEntityMixin { - - @Redirect(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setSitting(Z)V")) - private void arclight$handledBy(WolfEntity wolfEntity, boolean p_233687_1_) { - } - - @Inject(method = "setTamed", at = @At("RETURN")) - private void arclight$healToMax(boolean tamed, CallbackInfo ci) { - if (tamed) { - this.setHealth(this.getMaxHealth()); - } - } - - @Inject(method = "getEntityInteractionResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;heal(F)V")) - private void arclight$healReason(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.EATING); - } - - @Inject(method = "getEntityInteractionResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$attackReason(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/AbstractFishEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/AbstractFishEntityMixin.java deleted file mode 100644 index 4ecde461..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/AbstractFishEntityMixin.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive.fish; - -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.passive.fish.AbstractFishEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.play.server.SEntityMetadataPacket; -import net.minecraft.network.play.server.SSpawnMobPacket; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.inventory.CraftItemStack; -import org.bukkit.event.player.PlayerBucketFishEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(AbstractFishEntity.class) -public abstract class AbstractFishEntityMixin extends CreatureEntityMixin { - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean canDespawn(double distanceToClosestPlayer) { - return true; - } - - @Inject(method = "setFromBucket", at = @At("RETURN")) - private void arclight$updatePersist(boolean p_203706_1_, CallbackInfo ci) { - this.persistenceRequired = this.isNoDespawnRequired(); - } - - @Inject(method = "getEntityInteractionResult", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "FIELD", ordinal = 0, target = "Lnet/minecraft/world/World;isRemote:Z")) - private void arclight$fireFishEvent(PlayerEntity playerIn, Hand hand, CallbackInfoReturnable cir, ItemStack itemStack, ItemStack itemStack1) { - PlayerBucketFishEvent event = CraftEventFactory.callPlayerFishBucketEvent((AbstractFishEntity) (Object) this, playerIn, itemStack, itemStack1); - if (event.isCancelled()) { - ((ServerPlayerEntity) playerIn).sendContainerToPlayer(playerIn.openContainer); - ((ServerPlayerEntity) playerIn).connection.sendPacket(new SSpawnMobPacket((AbstractFishEntity) (Object) this)); - ((ServerPlayerEntity) playerIn).connection.sendPacket(new SEntityMetadataPacket(this.getEntityId(), this.dataManager, true)); - itemStack.grow(1); - cir.setReturnValue(ActionResultType.FAIL); - } else { - arclight$bucketItem = CraftItemStack.asNMSCopy(event.getFishBucket()); - } - } - - private transient ItemStack arclight$bucketItem; - - @ModifyVariable(method = "getEntityInteractionResult", index = 4, at = @At(value = "FIELD", ordinal = 0, target = "Lnet/minecraft/world/World;isRemote:Z")) - private ItemStack arclight$updateBucketItem(ItemStack itemStack) { - return arclight$bucketItem; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/PufferfishEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/PufferfishEntityMixin.java deleted file mode 100644 index 52d98cf1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/fish/PufferfishEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.passive.fish; - -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.passive.fish.PufferfishEntity; -import net.minecraft.entity.player.PlayerEntity; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(PufferfishEntity.class) -public abstract class PufferfishEntityMixin extends AbstractFishEntityMixin { - - @Inject(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$attack(MobEntity mobEntity, CallbackInfo ci) { - ((MobEntityBridge) mobEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - } - - @Inject(method = "onCollideWithPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$collide(PlayerEntity entityIn, CallbackInfo ci) { - ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerEntityMixin.java deleted file mode 100644 index bc25d7aa..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerEntityMixin.java +++ /dev/null @@ -1,512 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.player; - -import com.mojang.authlib.GameProfile; -import com.mojang.datafixers.util.Either; -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.entity.InternalEntityBridge; -import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import io.izzel.arclight.common.bridge.util.DamageSourceBridge; -import io.izzel.arclight.common.bridge.util.FoodStatsBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.CreatureAttribute; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.attributes.Attributes; -import net.minecraft.entity.boss.dragon.EnderDragonPartEntity; -import net.minecraft.entity.item.ArmorStandEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerAbilities; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.EnderChestInventory; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.PlayerContainer; -import net.minecraft.item.ItemStack; -import net.minecraft.item.SwordItem; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.play.server.SEntityVelocityPacket; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.potion.Effects; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.stats.Stat; -import net.minecraft.stats.Stats; -import net.minecraft.util.DamageSource; -import net.minecraft.util.FoodStats; -import net.minecraft.util.Hand; -import net.minecraft.util.HandSide; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.Unit; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.Difficulty; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.common.ForgeHooks; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v.block.CraftBlock; -import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.util.CraftVector; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.player.PlayerBedLeaveEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerVelocityEvent; -import org.bukkit.scoreboard.Team; -import org.bukkit.util.Vector; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.List; - -@Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntityMixin implements PlayerEntityBridge { - - // @formatter:off - @Shadow public abstract String getScoreboardName(); - @Shadow @Final public PlayerAbilities abilities; - @Shadow public abstract float getCooledAttackStrength(float adjustTicks); - @Shadow public abstract void resetCooldown(); - @Shadow public abstract SoundCategory getSoundCategory(); - @Shadow public abstract float getAIMoveSpeed(); - @Shadow public abstract void spawnSweepParticles(); - @Shadow public abstract void onCriticalHit(Entity entityHit); - @Shadow public abstract void onEnchantmentCritical(Entity entityHit); - @Shadow public abstract void addStat(ResourceLocation p_195067_1_, int p_195067_2_); - @Shadow public abstract void addExhaustion(float exhaustion); - @Shadow private long timeEntitySatOnShoulder; - @Shadow public abstract void setRightShoulderEntity(CompoundNBT tag); - @Shadow public abstract void setLeftShoulderEntity(CompoundNBT tag); - @Shadow public abstract CompoundNBT getRightShoulderEntity(); - @Shadow public abstract CompoundNBT getLeftShoulderEntity(); - @Shadow public int experienceLevel; - @Shadow @Final public PlayerInventory inventory; - @Shadow public Container openContainer; - @Shadow @Final public PlayerContainer container; - @Shadow public abstract void addStat(Stat stat); - @Shadow public abstract void addStat(ResourceLocation stat); - @Shadow public abstract ITextComponent getDisplayName(); - @Shadow public abstract HandSide getPrimaryHand(); - @Shadow public float experience; - @Shadow public int experienceTotal; - @Shadow protected FoodStats foodStats; - @Shadow protected boolean isMovementBlocked() { return false; } - @Shadow public abstract Scoreboard getWorldScoreboard(); - @Shadow protected EnderChestInventory enterChestInventory; - @Shadow public abstract Either trySleep(BlockPos at); - @Shadow public int sleepTimer; - @Shadow public abstract GameProfile getGameProfile(); - // @formatter:on - - public boolean fauxSleeping; - public int oldLevel; - - @Inject(method = "", at = @At("RETURN")) - private void arclight$init(World p_i241920_1_, BlockPos p_i241920_2_, float p_i241920_3_, GameProfile p_i241920_4_, CallbackInfo ci) { - oldLevel = -1; - ((FoodStatsBridge) this.foodStats).bridge$setEntityHuman((PlayerEntity) (Object) this); - ((IInventoryBridge) this.enterChestInventory).setOwner(this.getBukkitEntity()); - } - - @Override - public boolean bridge$isFauxSleeping() { - return fauxSleeping; - } - - @Inject(method = "updateTurtleHelmet", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$turtleHelmet(CallbackInfo ci) { - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TURTLE_HELMET); - } - - @Inject(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;heal(F)V")) - private void arclight$healByRegen(CallbackInfo ci) { - bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.REGEN); - } - - @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/item/ItemEntity;", - cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "RETURN", ordinal = 1)) - private void arclight$playerDropItem(ItemStack droppedItem, boolean dropAround, boolean traceItem, CallbackInfoReturnable cir, double d0, ItemEntity itemEntity) { - Player player = (Player) this.getBukkitEntity(); - Item drop = (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity(); - - PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); - if (traceItem && (cur == null || cur.getAmount() == 0)) { - // The complete stack was dropped - player.getInventory().setItemInHand(drop.getItemStack()); - } else if (traceItem && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { - // Only one item is dropped - cur.setAmount(cur.getAmount() + 1); - player.getInventory().setItemInHand(cur); - } else { - // Fallback - player.getInventory().addItem(drop.getItemStack()); - } - cir.setReturnValue(null); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean attackEntityFrom(DamageSource source, float amount) { - if (!ForgeHooks.onPlayerAttack((PlayerEntity) (Object) this, source, amount)) return false; - if (this.isInvulnerableTo(source)) { - return false; - } else if (this.abilities.disableDamage && !source.canHarmInCreative()) { - this.forceExplosionKnockback = true; - return false; - } else { - this.idleTime = 0; - if (this.getHealth() <= 0.0F) { - return false; - } else { - if (source.isDifficultyScaled()) { - if (this.world.getDifficulty() == Difficulty.PEACEFUL) { - // amount = 0.0F; - return false; - } - - if (this.world.getDifficulty() == Difficulty.EASY) { - amount = Math.min(amount / 2.0F + 1.0F, amount); - } - - if (this.world.getDifficulty() == Difficulty.HARD) { - amount = amount * 3.0F / 2.0F; - } - } - - boolean damaged = super.attackEntityFrom(source, amount); - if (damaged) { - this.spawnShoulderEntities(); - } - return damaged; - //return amount == 0.0F ? false : super.attackEntityFrom(source, amount); - } - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public boolean canAttackPlayer(final PlayerEntity entityhuman) { - Team team; - if (entityhuman instanceof ServerPlayerEntity) { - final ServerPlayerEntity thatPlayer = (ServerPlayerEntity) entityhuman; - team = ((ServerPlayerEntityBridge) thatPlayer).bridge$getBukkitEntity().getScoreboard().getPlayerTeam(((ServerPlayerEntityBridge) thatPlayer).bridge$getBukkitEntity()); - if (team == null || team.allowFriendlyFire()) { - return true; - } - } else { - final OfflinePlayer thisPlayer = Bukkit.getOfflinePlayer(entityhuman.getScoreboardName()); - team = Bukkit.getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer); - if (team == null || team.allowFriendlyFire()) { - return true; - } - } - if ((Object) this instanceof ServerPlayerEntity) { - return !team.hasPlayer(((ServerPlayerEntityBridge) this).bridge$getBukkitEntity()); - } - return !team.hasPlayer(Bukkit.getOfflinePlayer(this.getScoreboardName())); - } - - @Inject(method = "damageEntity", cancellable = true, at = @At("HEAD")) - private void arclight$damageEntityCustom(DamageSource damageSrc, float damageAmount, CallbackInfo ci) { - damageEntity0(damageSrc, damageAmount); - ci.cancel(); - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void attackTargetEntityWithCurrentItem(final Entity entity) { - if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity)) return; - if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) { - float f = (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE); - float f2; - if (entity instanceof LivingEntity) { - f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute()); - } else { - f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED); - } - final float f3 = this.getCooledAttackStrength(0.5f); - f *= 0.2f + f3 * f3 * 0.8f; - f2 *= f3; - this.resetCooldown(); - if (f > 0.0f || f2 > 0.0f) { - final boolean flag = f3 > 0.9f; - boolean flag2 = false; - float i = (float)this.getAttributeValue(Attributes.ATTACK_KNOCKBACK); // Forge: Initialize this value to the attack knockback attribute of the player, which is by default 0 - i += EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this); - if (this.isSprinting() && flag) { - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f); - ++i; - flag2 = true; - } - boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity; - flag3 = flag3 && !this.isSprinting(); - net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F); - flag3 = hitResult != null; - if (flag3) { - f *= hitResult.getDamageModifier(); - } - f += f2; - boolean flag4 = false; - final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified; - if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) { - final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND); - if (itemstack.getItem() instanceof SwordItem) { - flag4 = true; - } - } - float f4 = 0.0f; - boolean flag5 = false; - final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this); - if (entity instanceof LivingEntity) { - f4 = ((LivingEntity) entity).getHealth(); - if (j > 0 && !entity.isBurning()) { - final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1); - Bukkit.getPluginManager().callEvent(combustEvent); - if (!combustEvent.isCancelled()) { - flag5 = true; - ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false); - } - } - } - final Vector3d vec3d = entity.getMotion(); - final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f); - if (flag6) { - if (i > 0) { - if (entity instanceof LivingEntity) { - ((LivingEntity) entity).applyKnockback(i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f)); - } else { - entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f); - } - this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6)); - this.setSprinting(false); - } - if (flag4) { - final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f; - final List list = this.world.getEntitiesWithinAABB(LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0)); - for (final LivingEntity entityliving : list) { - if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) { - entityliving.applyKnockback(0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f)); - } - } - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f); - this.spawnSweepParticles(); - } - if (entity instanceof ServerPlayerEntity && entity.velocityChanged) { - boolean cancelled = false; - final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(); - final Vector velocity = CraftVector.toBukkit(vec3d); - final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - cancelled = true; - } else if (!velocity.equals(event.getVelocity())) { - player.setVelocity(event.getVelocity()); - } - if (!cancelled) { - ((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity)); - entity.velocityChanged = false; - entity.setMotion(vec3d); - } - } - if (flag3) { - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f); - this.onCriticalHit(entity); - } - if (!flag3 && !flag4) { - if (flag) { - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f); - } else { - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f); - } - } - if (f2 > 0.0f) { - this.onEnchantmentCritical(entity); - } - this.setLastAttackedEntity(entity); - if (entity instanceof LivingEntity) { - EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this); - } - EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity); - final ItemStack itemstack2 = this.getHeldItemMainhand(); - Object object = entity; - if (entity instanceof EnderDragonPartEntity) { - object = ((EnderDragonPartEntity) entity).dragon; - } - if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) { - ItemStack copy = itemstack2.copy(); - itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this); - if (itemstack2.isEmpty()) { - net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND); - this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY); - } - } - if (entity instanceof LivingEntity) { - final float f6 = f4 - ((LivingEntity) entity).getHealth(); - this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f)); - if (j > 0) { - final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4); - Bukkit.getPluginManager().callEvent(combustEvent2); - if (!combustEvent2.isCancelled()) { - ((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false); - } - } - if (this.world instanceof ServerWorld && f6 > 2.0f) { - final int k = (int) (f6 * 0.5); - ((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.getPosX(), entity.getPosY() + entity.getHeight() * 0.5f, entity.getPosZ(), k, 0.1, 0.0, 0.1, 0.2); - } - } - this.addExhaustion(0.1f); - } else { - this.world.playSound(null, this.getPosX(), this.getPosY(), this.getPosZ(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f); - if (flag5) { - entity.extinguish(); - } - if (this instanceof ServerPlayerEntityBridge) { - ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory(); - } - } - } - } - } - - protected transient boolean arclight$forceSleep; - - public Either sleep(BlockPos at, boolean force) { - this.arclight$forceSleep = force; - return this.trySleep(at); - } - - @Override - public Either bridge$trySleep(BlockPos at, boolean force) { - return sleep(at, force); - } - - @Inject(method = "stopSleepInBed", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I")) - private void arclight$wakeup(boolean flag, boolean flag1, CallbackInfo ci) { - BlockPos blockPos = this.getBedPosition().orElse(null); - if (this.bridge$getBukkitEntity() instanceof Player) { - Player player = (Player) this.bridge$getBukkitEntity(); - Block bed; - if (blockPos != null) { - bed = CraftBlock.at(this.world, blockPos); - } else { - bed = ((WorldBridge) this.world).bridge$getWorld().getBlockAt(player.getLocation()); - } - PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true); - Bukkit.getPluginManager().callEvent(event); - } - } - - @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setFlag(IZ)V")) - private void arclight$toggleGlide(PlayerEntity playerEntity, int flag, boolean set) { - if (playerEntity.getFlag(flag) != set && !CraftEventFactory.callToggleGlideEvent((PlayerEntity) (Object) this, set).isCancelled()) { - playerEntity.setFlag(flag, set); - } - } - - @Inject(method = "startFallFlying", cancellable = true, at = @At("HEAD")) - private void arclight$startGlidingEvent(CallbackInfo ci) { - if (CraftEventFactory.callToggleGlideEvent((PlayerEntity) (Object) this, true).isCancelled()) { - this.setFlag(7, true); - this.setFlag(7, false); - ci.cancel(); - } - } - - @Inject(method = "stopFallFlying", cancellable = true, at = @At("HEAD")) - private void arclight$stopGlidingEvent(CallbackInfo ci) { - if (CraftEventFactory.callToggleGlideEvent((PlayerEntity) (Object) this, false).isCancelled()) { - ci.cancel(); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - protected void spawnShoulderEntities() { - if (this.timeEntitySatOnShoulder + 20L < this.world.getGameTime()) { - if (this.spawnEntityFromShoulder(this.getLeftShoulderEntity())) { - this.setLeftShoulderEntity(new CompoundNBT()); - } - if (this.spawnEntityFromShoulder(this.getRightShoulderEntity())) { - this.setRightShoulderEntity(new CompoundNBT()); - } - } - } - - private boolean spawnEntityFromShoulder(final CompoundNBT nbttagcompound) { - return this.world.isRemote || nbttagcompound.isEmpty() || EntityType.loadEntityUnchecked(nbttagcompound, this.world).map(entity -> { - if (entity instanceof TameableEntity) { - ((TameableEntity) entity).setOwnerId(this.entityUniqueID); - } - entity.setPosition(this.getPosX(), this.getPosY() + 0.699999988079071, this.getPosZ()); - return ((ServerWorldBridge) this.world).bridge$addEntitySerialized(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); - }).orElse(true); - } - - public CraftHumanEntity getBukkitEntity() { - return (CraftHumanEntity) ((InternalEntityBridge) this).internal$getBukkitEntity(); - } - - @Override - public CraftHumanEntity bridge$getBukkitEntity() { - return (CraftHumanEntity) ((InternalEntityBridge) this).internal$getBukkitEntity(); - } - - @Override - public void setSlot(EquipmentSlotType slotIn, ItemStack stack, boolean silent) { - if (slotIn == EquipmentSlotType.MAINHAND) { - this.bridge$playEquipSound(stack, silent); - this.inventory.mainInventory.set(this.inventory.currentItem, stack); - } else if (slotIn == EquipmentSlotType.OFFHAND) { - this.bridge$playEquipSound(stack, silent); - this.inventory.offHandInventory.set(0, stack); - } else if (slotIn.getSlotType() == EquipmentSlotType.Group.ARMOR) { - this.bridge$playEquipSound(stack, silent); - this.inventory.armorInventory.set(slotIn.getIndex(), stack); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerInventoryMixin.java deleted file mode 100644 index 467498bc..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/PlayerInventoryMixin.java +++ /dev/null @@ -1,132 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.player; - -import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge; -import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; -import org.bukkit.Location; -import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.InventoryHolder; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.ArrayList; -import java.util.List; - -@Mixin(PlayerInventory.class) -public abstract class PlayerInventoryMixin implements IInventory, IInventoryBridge, PlayerInventoryBridge { - - // @formatter:off - @Shadow @Final public NonNullList mainInventory; - @Shadow @Final public NonNullList offHandInventory; - @Shadow @Final public NonNullList armorInventory; - @Shadow @Final private List> allInventories; - @Shadow @Final public PlayerEntity player; - @Shadow private ItemStack itemStack; - @Shadow protected abstract boolean canMergeStacks(ItemStack stack1, ItemStack stack2); - @Shadow public abstract void setItemStack(ItemStack itemStackIn); - // @formatter:on - - private List transactions = new ArrayList<>(); - private int maxStack = MAX_STACK; - - @Inject(method = "getItemStack", at = @At("HEAD")) - public void arclight$carried(CallbackInfoReturnable cir) { - if (this.itemStack.isEmpty()) { - this.setItemStack(ItemStack.EMPTY); - } - } - - public int canHold(ItemStack stack) { - int remains = stack.getCount(); - for (int i = 0; i < this.mainInventory.size(); ++i) { - ItemStack slot = this.getStackInSlot(i); - if (slot.isEmpty()) return stack.getCount(); - - if (this.canMergeStacks(slot, stack)) { - remains -= (slot.getMaxStackSize() < this.getInventoryStackLimit() ? slot.getMaxStackSize() : this.getInventoryStackLimit()) - slot.getCount(); - } - if (remains <= 0) return stack.getCount(); - } - ItemStack offhandItemStack = this.getStackInSlot(this.mainInventory.size() + this.armorInventory.size()); - if (this.canMergeStacks(offhandItemStack, stack)) { - remains -= (offhandItemStack.getMaxStackSize() < this.getInventoryStackLimit() ? offhandItemStack.getMaxStackSize() : this.getInventoryStackLimit()) - offhandItemStack.getCount(); - } - if (remains <= 0) return stack.getCount(); - - return stack.getCount() - remains; - } - - @Override - public int bridge$canHold(ItemStack stack) { - return canHold(stack); - } - - public List getArmorContents() { - return this.armorInventory; - } - - @Override - public List getContents() { - List combined = new ArrayList<>(mainInventory.size() + offHandInventory.size() + armorInventory.size()); - for (List sub : this.allInventories) { - combined.addAll(sub); - } - return combined; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transactions.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transactions.remove(who); - } - - @Override - public List getViewers() { - return transactions; - } - - @Override - public InventoryHolder getOwner() { - return ((PlayerEntityBridge) this.player).bridge$getBukkitEntity(); - } - - @Override - public void setOwner(InventoryHolder owner) { } - - @Override - public int getInventoryStackLimit() { - if (maxStack == 0) maxStack = MAX_STACK; - return maxStack; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public Location getLocation() { - return ((PlayerEntityBridge) this.player).bridge$getBukkitEntity().getLocation(); - } - - @Override - public IRecipe getCurrentRecipe() { return null; } - - @Override - public void setCurrentRecipe(IRecipe recipe) { } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java deleted file mode 100644 index 88a51c25..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/player/ServerPlayerEntityMixin.java +++ /dev/null @@ -1,964 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.player; - -import com.mojang.datafixers.util.Either; -import io.izzel.arclight.common.bridge.block.PortalInfoBridge; -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.entity.InternalEntityBridge; -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; -import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; -import io.izzel.arclight.common.bridge.util.FoodStatsBridge; -import io.izzel.arclight.common.bridge.world.TeleporterBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mod.util.ArclightCaptures; -import io.izzel.arclight.common.mod.util.BlackholeNetHandler; -import io.izzel.arclight.common.mod.util.ChestBlockDoubleInventoryHacks; -import net.minecraft.block.NetherPortalBlock; -import net.minecraft.block.PortalInfo; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.monster.MonsterEntity; -import net.minecraft.entity.passive.horse.AbstractHorseEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.player.SpawnLocationHelper; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.HorseInventoryContainer; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.play.ServerPlayNetHandler; -import net.minecraft.network.play.client.CClientSettingsPacket; -import net.minecraft.network.play.server.SChangeGameStatePacket; -import net.minecraft.network.play.server.SCombatPacket; -import net.minecraft.network.play.server.SOpenHorseWindowPacket; -import net.minecraft.network.play.server.SPlayEntityEffectPacket; -import net.minecraft.network.play.server.SPlaySoundEventPacket; -import net.minecraft.network.play.server.SPlayerAbilitiesPacket; -import net.minecraft.network.play.server.SRespawnPacket; -import net.minecraft.network.play.server.SServerDifficultyPacket; -import net.minecraft.network.play.server.SSetSlotPacket; -import net.minecraft.network.play.server.SUpdateHealthPacket; -import net.minecraft.potion.EffectInstance; -import net.minecraft.scoreboard.Score; -import net.minecraft.scoreboard.ScoreCriteria; -import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.scoreboard.Team; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.PlayerInteractionManager; -import net.minecraft.server.management.PlayerList; -import net.minecraft.stats.Stat; -import net.minecraft.stats.Stats; -import net.minecraft.util.CombatTracker; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; -import net.minecraft.util.FoodStats; -import net.minecraft.util.HandSide; -import net.minecraft.util.NonNullList; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.TeleportationRepositioner; -import net.minecraft.util.Unit; -import net.minecraft.util.Util; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ChatType; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.util.text.event.HoverEvent; -import net.minecraft.world.DimensionType; -import net.minecraft.world.GameRules; -import net.minecraft.world.GameType; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeManager; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.IWorldInfo; -import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.util.FakePlayer; -import net.minecraftforge.common.util.ITeleporter; -import net.minecraftforge.fml.hooks.BasicEventHooks; -import net.minecraftforge.fml.server.ServerLifecycleHooks; -import org.apache.logging.log4j.Logger; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.WeatherType; -import org.bukkit.craftbukkit.v.CraftServer; -import org.bukkit.craftbukkit.v.CraftWorld; -import org.bukkit.craftbukkit.v.entity.CraftPlayer; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.craftbukkit.v.event.CraftPortalEvent; -import org.bukkit.craftbukkit.v.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v.scoreboard.CraftScoreboardManager; -import org.bukkit.craftbukkit.v.util.CraftChatMessage; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerChangedMainHandEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerGameModeChangeEvent; -import org.bukkit.event.player.PlayerLocaleChangeEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.MainHand; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.List; -import java.util.Optional; -import java.util.OptionalInt; -import java.util.Random; -import java.util.UUID; -import java.util.function.Consumer; - -@Mixin(ServerPlayerEntity.class) -public abstract class ServerPlayerEntityMixin extends PlayerEntityMixin implements ServerPlayerEntityBridge { - - // @formatter:off - @Shadow @Final public MinecraftServer server; - @Shadow protected abstract int func_205735_q(int p_205735_1_); - @Shadow @Final public PlayerInteractionManager interactionManager; - @Shadow public ServerPlayNetHandler connection; - @Shadow public abstract boolean isSpectator(); - @Shadow public abstract void takeStat(Stat stat); - @Shadow public abstract void closeScreen(); - @Shadow public abstract void setSpectatingEntity(Entity entityToSpectate); - @Shadow public boolean invulnerableDimensionChange; - @Shadow public abstract ServerWorld getServerWorld(); - @Shadow public boolean queuedEndExit; - @Shadow private boolean seenCredits; - @Shadow @Nullable private Vector3d enteredNetherPosition; - @Shadow public abstract void func_213846_b(ServerWorld p_213846_1_); - @Shadow public int lastExperience; - @Shadow private float lastHealth; - @Shadow private int lastFoodLevel; - @Shadow public int currentWindowId; - @Shadow public abstract void getNextWindowId(); - @Shadow(remap = false) private String language; - @Shadow public abstract void teleport(ServerWorld newWorld, double x, double y, double z, float yaw, float pitch); - @Shadow public abstract void giveExperiencePoints(int p_195068_1_); - @Shadow private RegistryKey field_241137_cq_; - @Shadow @Nullable public abstract BlockPos func_241140_K_(); - @Shadow public abstract float func_242109_L(); - @Shadow protected abstract void func_241157_eT_(); - @Shadow protected abstract void func_242110_a(ServerWorld p_242110_1_, BlockPos p_242110_2_); - @Shadow @Final private static Logger LOGGER; - @Shadow public abstract boolean isCreative(); - @Shadow public abstract void func_242111_a(RegistryKey p_242111_1_, @org.jetbrains.annotations.Nullable BlockPos p_242111_2_, float p_242111_3_, boolean p_242111_4_, boolean p_242111_5_); - @Shadow protected abstract boolean func_241156_b_(BlockPos p_241156_1_, Direction p_241156_2_); - @Shadow protected abstract boolean func_241147_a_(BlockPos p_241147_1_, Direction p_241147_2_); - @Shadow public abstract void sendMessage(ITextComponent component, UUID senderUUID); - // @formatter:on - - public String displayName; - public ITextComponent listName; - public org.bukkit.Location compassTarget; - public int newExp = 0; - public int newLevel = 0; - public int newTotalExp = 0; - public boolean keepLevel = false; - public double maxHealthCache; - public boolean joining = true; - public boolean sentListPacket = false; - public Integer clientViewDistance; - public long timeOffset = 0; - public boolean relativeTime = true; - public WeatherType weather = null; - private float pluginRainPosition; - private float pluginRainPositionPrevious; - public String locale = "en_us"; - private boolean arclight$initialized = false; - - @Inject(method = "", at = @At("RETURN")) - public void arclight$init(CallbackInfo ci) { - this.displayName = this.getGameProfile() != null ? getScoreboardName() : "~FakePlayer~"; - this.canPickUpLoot = true; - this.maxHealthCache = this.getMaxHealth(); - this.arclight$initialized = true; - if ((Object) this instanceof FakePlayer) { - this.connection = new BlackholeNetHandler(this.getServer(), (ServerPlayerEntity) (Object) this); - } - } - - @Override - public boolean bridge$initialized() { - return this.arclight$initialized; - } - - public final BlockPos getSpawnPoint(ServerWorld worldserver) { - BlockPos blockposition = worldserver.getSpawnPoint(); - if (worldserver.getDimensionType().hasSkyLight() && worldserver.serverWorldInfo.getGameType() != GameType.ADVENTURE) { - long k; - long l; - int i = Math.max(0, this.server.getSpawnRadius(worldserver)); - int j = MathHelper.floor(worldserver.getWorldBorder().getClosestDistance(blockposition.getX(), blockposition.getZ())); - if (j < i) { - i = j; - } - if (j <= 1) { - i = 1; - } - int i1 = (l = (k = (long) (i * 2 + 1)) * k) > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l; - int j1 = this.func_205735_q(i1); - int k1 = new Random().nextInt(i1); - for (int l1 = 0; l1 < i1; ++l1) { - int i2 = (k1 + j1 * l1) % i1; - int j2 = i2 % (i * 2 + 1); - int k2 = i2 / (i * 2 + 1); - BlockPos blockposition1 = SpawnLocationHelper.func_241092_a_(worldserver, blockposition.getX() + j2 - i, blockposition.getZ() + k2 - i, false); - if (blockposition1 == null) continue; - return blockposition1; - } - } - return blockposition; - } - - @Override - public BlockPos bridge$getSpawnPoint(ServerWorld world) { - return getSpawnPoint(world); - } - - @Inject(method = "readAdditional", at = @At("RETURN")) - private void arclight$readExtra(CompoundNBT compound, CallbackInfo ci) { - this.getBukkitEntity().readExtraData(compound); - String spawnWorld = compound.getString("SpawnWorld"); - CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld); - if (oldWorld != null) { - this.field_241137_cq_ = oldWorld.getHandle().getDimensionKey(); - } - } - - @Redirect(method = "writeAdditional", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isOnePlayerRiding()Z")) - private boolean arclight$nonPersistVehicle(Entity entity) { - Entity entity1 = this.getRidingEntity(); - boolean persistVehicle = true; - if (entity1 != null) { - Entity vehicle; - for (vehicle = entity1; vehicle != null; vehicle = vehicle.getRidingEntity()) { - if (!((EntityBridge) vehicle).bridge$isPersist()) { - persistVehicle = false; - break; - } - } - } - return persistVehicle && entity.isOnePlayerRiding(); - } - - @Inject(method = "writeAdditional", at = @At("RETURN")) - private void arclight$writeExtra(CompoundNBT compound, CallbackInfo ci) { - this.getBukkitEntity().setExtraData(compound); - } - - @Override - public void setWorld(World world) { - super.setWorld(world); - if (world == null) { - this.revive(); - Vector3d position = null; - if (this.field_241137_cq_ != null && (world = ServerLifecycleHooks.getCurrentServer().getWorld(this.field_241137_cq_)) != null && this.func_241140_K_() != null) { - position = PlayerEntity.func_242374_a((ServerWorld) world, this.func_241140_K_(), this.func_242109_L(), false, false).orElse(null); - } - if (world == null || position == null) { - world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle(); - position = Vector3d.copyCentered(((ServerWorld) world).getSpawnPoint()); - } - this.world = world; - this.setPosition(position.getX(), position.getY(), position.getZ()); - } - this.interactionManager.setWorld((ServerWorld) world); - } - - @Inject(method = "tick", at = @At("HEAD")) - private void arclight$joining(CallbackInfo ci) { - if (this.joining) { - this.joining = false; - } - } - - @Redirect(method = "playerTick", at = @At(value = "NEW", target = "net/minecraft/network/play/server/SUpdateHealthPacket")) - private SUpdateHealthPacket arclight$useScaledHealth(float healthIn, int foodLevelIn, float saturationLevelIn) { - return new SUpdateHealthPacket(this.getBukkitEntity().getScaledHealth(), foodLevelIn, saturationLevelIn); - } - - @Inject(method = "playerTick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;ticksExisted:I")) - private void arclight$updateHealthAndExp(CallbackInfo ci) { - if (this.maxHealthCache != this.getMaxHealth()) { - this.getBukkitEntity().updateScaledHealth(); - } - if (this.oldLevel == -1) { - this.oldLevel = this.experienceLevel; - } - if (this.oldLevel != this.experienceLevel) { - CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); - this.oldLevel = this.experienceLevel; - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void onDeath(DamageSource damagesource) { - if (net.minecraftforge.common.ForgeHooks.onLivingDeath((ServerPlayerEntity) (Object) this, damagesource)) - return; - boolean flag = this.world.getGameRules().getBoolean(GameRules.SHOW_DEATH_MESSAGES); - if (this.removed) { - return; - } - boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY) || this.isSpectator(); - PlayerInventory copyInv; - if (keepInventory) { - copyInv = this.inventory; - } else { - copyInv = new PlayerInventory((ServerPlayerEntity) (Object) this); - copyInv.copyInventory(this.inventory); - } - this.spawnDrops(damagesource); - - ITextComponent defaultMessage = this.getCombatTracker().getDeathMessage(); - String deathmessage = defaultMessage.getString(); - List loot = new ArrayList<>(); - Collection drops = this.captureDrops(null); - if (drops != null) { - for (ItemEntity entity : drops) { - CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); - loot.add(craftItemStack); - } - } - if (!keepInventory) { - this.inventory.copyInventory(copyInv); - } - PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayerEntity) (Object) this, loot, deathmessage, keepInventory); - if (this.openContainer != this.container) { - this.closeScreen(); - } - String deathMessage = event.getDeathMessage(); - if (deathMessage != null && deathMessage.length() > 0 && flag) { - ITextComponent itextcomponent; - if (deathMessage.equals(deathmessage)) { - itextcomponent = this.getCombatTracker().getDeathMessage(); - } else { - itextcomponent = CraftChatMessage.fromStringOrNull(deathMessage); - } - this.connection.sendPacket(new SCombatPacket(this.getCombatTracker(), SCombatPacket.Event.ENTITY_DIED, itextcomponent), (p_212356_2_) -> { - if (!p_212356_2_.isSuccess()) { - int i = 256; - String s = itextcomponent.getStringTruncated(256); - ITextComponent itextcomponent1 = new TranslationTextComponent("death.attack.message_too_long", (new StringTextComponent(s)).mergeStyle(TextFormatting.YELLOW)); - ITextComponent itextcomponent2 = (new TranslationTextComponent("death.attack.even_more_magic", this.getDisplayName())).modifyStyle((p_212357_1_) -> { - return p_212357_1_.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent1)); - }); - this.connection.sendPacket(new SCombatPacket(this.getCombatTracker(), SCombatPacket.Event.ENTITY_DIED, itextcomponent2)); - } - - }); - Team scoreboardteambase = this.getTeam(); - if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != Team.Visible.ALWAYS) { - if (scoreboardteambase.getDeathMessageVisibility() == Team.Visible.HIDE_FOR_OTHER_TEAMS) { - this.server.getPlayerList().sendMessageToAllTeamMembers((ServerPlayerEntity) (Object) this, itextcomponent); - } else if (scoreboardteambase.getDeathMessageVisibility() == Team.Visible.HIDE_FOR_OWN_TEAM) { - this.server.getPlayerList().sendMessageToTeamOrAllPlayers((ServerPlayerEntity) (Object) this, itextcomponent); - } - } else { - this.server.getPlayerList().func_232641_a_(itextcomponent, ChatType.SYSTEM, Util.DUMMY_UUID); - } - } else { - this.connection.sendPacket(new SCombatPacket(this.getCombatTracker(), SCombatPacket.Event.ENTITY_DIED)); - } - this.spawnShoulderEntities(); - - if (this.world.getGameRules().getBoolean(GameRules.FORGIVE_DEAD_PLAYERS)) { - this.func_241157_eT_(); - } - - this.dropExperience(); - - if (!event.getKeepInventory()) { - this.inventory.clear(); - } - this.setSpectatingEntity((ServerPlayerEntity) (Object) this); - ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(ScoreCriteria.DEATH_COUNT, this.getScoreboardName(), Score::incrementScore); - - LivingEntity entityliving = this.getAttackingEntity(); - if (entityliving != null) { - this.addStat(Stats.ENTITY_KILLED_BY.get(entityliving.getType())); - entityliving.awardKillScore((ServerPlayerEntity) (Object) this, this.scoreValue, damagesource); - this.createWitherRose(entityliving); - } - - this.world.setEntityState((ServerPlayerEntity) (Object) this, (byte) 3); - this.addStat(Stats.DEATHS); - this.takeStat(Stats.CUSTOM.get(Stats.TIME_SINCE_DEATH)); - this.takeStat(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)); - this.extinguish(); - this.setFlag(0, false); - this.getCombatTracker().reset(); - } - - @Redirect(method = "awardKillScore", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) - private void arclight$useCustomScoreboard(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { - ((CraftServer) Bukkit.getServer()).getScoreboardManager().getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); - } - - @Redirect(method = "handleTeamKill", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) - private void arclight$teamKill(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { - ((CraftServer) Bukkit.getServer()).getScoreboardManager().getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); - } - - @Inject(method = "canPlayersAttack", cancellable = true, at = @At("HEAD")) - private void arclight$pvpMode(CallbackInfoReturnable cir) { - cir.setReturnValue(((WorldBridge) this.world).bridge$isPvpMode()); - } - - /** - * @author IzzelAliz - * @reason - */ - @Nullable - @Overwrite - protected PortalInfo func_241829_a(ServerWorld p_241829_1_) { - PortalInfo portalinfo = super.func_241829_a(p_241829_1_); - if (portalinfo != null && ((WorldBridge) this.world).bridge$getTypeKey() == DimensionType.OVERWORLD && ((WorldBridge) p_241829_1_).bridge$getTypeKey() == DimensionType.THE_END) { - Vector3d vector3d = portalinfo.pos.add(0.0D, -1.0D, 0.0D); - PortalInfo newInfo = new PortalInfo(vector3d, Vector3d.ZERO, 90.0F, 0.0F); - ((PortalInfoBridge) newInfo).bridge$setWorld(p_241829_1_); - ((PortalInfoBridge) newInfo).bridge$setPortalEventInfo(((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo()); - return newInfo; - } else { - return portalinfo; - } - } - - @Override - public Entity bridge$changeDimension(ServerWorld world, PlayerTeleportEvent.TeleportCause cause) { - this.arclight$cause = cause; - return changeDimension(world); - } - - private transient PlayerTeleportEvent.TeleportCause arclight$cause; - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite(remap = false) - @Nullable - public Entity changeDimension(ServerWorld server, ITeleporter teleporter) { - if (this.isSleeping()) { - return (ServerPlayerEntity) (Object) this; - } - if (!ForgeHooks.onTravelToDimension((ServerPlayerEntity) (Object) this, server.getDimensionKey())) return null; - - PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause; - arclight$cause = null; - - // this.invulnerableDimensionChange = true; - ServerWorld serverworld = this.getServerWorld(); - RegistryKey registrykey = ((WorldBridge) serverworld).bridge$getTypeKey(); - if (registrykey == DimensionType.THE_END && ((WorldBridge) server).bridge$getTypeKey() == DimensionType.OVERWORLD && teleporter.isVanilla()) { //Forge: Fix non-vanilla teleporters triggering end credits - this.invulnerableDimensionChange = true; - this.detach(); - this.getServerWorld().removePlayer((ServerPlayerEntity) (Object) this, true); //Forge: The player entity is cloned so keep the data until after cloning calls copyFrom - if (!this.queuedEndExit) { - this.queuedEndExit = true; - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.PERFORM_RESPAWN, this.seenCredits ? 0.0F : 1.0F)); - this.seenCredits = true; - } - - return (ServerPlayerEntity) (Object) this; - } else { - IWorldInfo iworldinfo = server.getWorldInfo(); - this.connection.sendPacket(new SRespawnPacket(server.getDimensionType(), server.getDimensionKey(), BiomeManager.getHashedSeed(server.getSeed()), this.interactionManager.getGameType(), this.interactionManager.func_241815_c_(), server.isDebug(), server.isFlatWorld(), true)); - this.connection.sendPacket(new SServerDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); - PlayerList playerlist = this.server.getPlayerList(); - playerlist.updatePermissionLevel((ServerPlayerEntity) (Object) this); - serverworld.removeEntity((ServerPlayerEntity) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call. - this.revive(); - PortalInfo portalinfo = teleporter.getPortalInfo((ServerPlayerEntity) (Object) this, server, this::func_241829_a); - ServerWorld[] exitWorld = new ServerWorld[]{server}; - if (portalinfo != null) { - Entity e = teleporter.placeEntity((ServerPlayerEntity) (Object) this, serverworld, exitWorld[0], this.rotationYaw, spawnPortal -> {//Forge: Start vanilla logic - serverworld.getProfiler().startSection("moving"); - - if (((PortalInfoBridge) portalinfo).bridge$getWorld() != null) { - exitWorld[0] = ((PortalInfoBridge) portalinfo).bridge$getWorld(); - } - if (exitWorld[0] != null) { - if (registrykey == DimensionType.OVERWORLD && ((WorldBridge) exitWorld[0]).bridge$getTypeKey() == DimensionType.THE_NETHER) { - this.enteredNetherPosition = this.getPositionVec(); - } else if (spawnPortal && ((WorldBridge) exitWorld[0]).bridge$getTypeKey() == DimensionType.THE_END - && (((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo() == null || ((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo().getCanCreatePortal())) { - this.func_242110_a(exitWorld[0], new BlockPos(portalinfo.pos)); - } - } - - Location enter = this.getBukkitEntity().getLocation(); - Location exit = (exitWorld[0] == null) ? null : new Location(((WorldBridge) exitWorld[0]).bridge$getWorld(), portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.rotationYaw, portalinfo.rotationPitch); - PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, cause); - Bukkit.getServer().getPluginManager().callEvent(tpEvent); - if (tpEvent.isCancelled() || tpEvent.getTo() == null) { - return null; - } - exit = tpEvent.getTo(); - - serverworld.getProfiler().endSection(); - serverworld.getProfiler().startSection("placing"); - - this.invulnerableDimensionChange = true; - ServerWorld newWorld = ((CraftWorld) exit.getWorld()).getHandle(); - if (newWorld != exitWorld[0]) { - exitWorld[0] = newWorld; - IWorldInfo newWorldInfo = exitWorld[0].getWorldInfo(); - this.connection.sendPacket(new SRespawnPacket(exitWorld[0].getDimensionType(), exitWorld[0].getDimensionKey(), BiomeManager.getHashedSeed(exitWorld[0].getSeed()), this.interactionManager.getGameType(), this.interactionManager.func_241815_c_(), exitWorld[0].isDebug(), exitWorld[0].isFlatWorld(), true)); - this.connection.sendPacket(new SServerDifficultyPacket(newWorldInfo.getDifficulty(), newWorldInfo.isDifficultyLocked())); - } - - this.setWorld(exitWorld[0]); - exitWorld[0].addDuringPortalTeleport((ServerPlayerEntity) (Object) this); - - ((ServerPlayNetHandlerBridge) this.connection).bridge$teleport(exit); - this.connection.captureCurrentPosition(); - - serverworld.getProfiler().endSection(); - this.func_213846_b(exitWorld[0]); - return (ServerPlayerEntity) (Object) this;//forge: this is part of the ITeleporter patch - });//Forge: End vanilla logic - if (e == null) { - serverworld.addDuringPortalTeleport((ServerPlayerEntity) (Object) this); - return (ServerPlayerEntity) (Object) this; - } else if (e != (Object) this) { - throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this)); - } - - this.interactionManager.setWorld(exitWorld[0]); - this.connection.sendPacket(new SPlayerAbilitiesPacket(this.abilities)); - playerlist.sendWorldInfo((ServerPlayerEntity) (Object) this, exitWorld[0]); - playerlist.sendInventory((ServerPlayerEntity) (Object) this); - - for (EffectInstance effectinstance : this.getActivePotionEffects()) { - this.connection.sendPacket(new SPlayEntityEffectPacket(this.getEntityId(), effectinstance)); - } - - if (teleporter.playTeleportSound((ServerPlayerEntity) (Object) this, serverworld, exitWorld[0])) { - this.connection.sendPacket(new SPlaySoundEventPacket(1032, BlockPos.ZERO, 0, false)); - } - this.lastExperience = -1; - this.lastHealth = -1.0F; - this.lastFoodLevel = -1; - BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayerEntity) (Object) this, serverworld.getDimensionKey(), exitWorld[0].getDimensionKey()); - PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld()); - Bukkit.getPluginManager().callEvent(changeEvent); - } - - return (ServerPlayerEntity) (Object) this; - } - } - - @Override - protected CraftPortalEvent callPortalEvent(Entity entity, ServerWorld exitWorldServer, BlockPos exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { - Location enter = this.getBukkitEntity().getLocation(); - Location exit = new Location(((WorldBridge) exitWorldServer).bridge$getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ(), this.rotationYaw, this.rotationPitch); - PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, 128, true, creationRadius); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null) { - return null; - } - return new CraftPortalEvent(event); - } - - @Override - protected Optional findOrCreatePortal(ServerWorld worldserver, BlockPos blockposition, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { - Optional optional = super.findOrCreatePortal(worldserver, blockposition, flag, searchRadius, canCreatePortal, createRadius); - if (optional.isPresent() || !canCreatePortal) { - return optional; - } - Direction.Axis enumdirection_enumaxis = this.world.getBlockState(this.entityBlockPosition).func_235903_d_(NetherPortalBlock.AXIS).orElse(Direction.Axis.X); - Optional optional1 = ((TeleporterBridge) worldserver.getDefaultTeleporter()).bridge$createPortal(blockposition, enumdirection_enumaxis, (ServerPlayerEntity) (Object) this, createRadius); - if (!optional1.isPresent()) { - LOGGER.error("Unable to create a portal, likely target out of worldborder"); - } - return optional1; - } - - private Either getBedResult(BlockPos blockposition, Direction enumdirection) { - if (!this.isSleeping() && this.isAlive()) { - if (!this.world.getDimensionType().isNatural()) { - return Either.left(PlayerEntity.SleepResult.NOT_POSSIBLE_HERE); - } - if (!this.func_241147_a_(blockposition, enumdirection)) { - return Either.left(PlayerEntity.SleepResult.TOO_FAR_AWAY); - } - if (this.func_241156_b_(blockposition, enumdirection)) { - return Either.left(PlayerEntity.SleepResult.OBSTRUCTED); - } - this.func_242111_a(this.world.getDimensionKey(), blockposition, this.rotationYaw, false, true); - if (this.world.isDaytime()) { - return Either.left(PlayerEntity.SleepResult.NOT_POSSIBLE_NOW); - } - if (!this.isCreative()) { - double d0 = 8.0; - double d1 = 5.0; - Vector3d vec3d = Vector3d.copyCenteredHorizontally(blockposition); - List list = this.world.getEntitiesWithinAABB(MonsterEntity.class, new AxisAlignedBB(vec3d.getX() - 8.0, vec3d.getY() - 5.0, vec3d.getZ() - 8.0, vec3d.getX() + 8.0, vec3d.getY() + 5.0, vec3d.getZ() + 8.0), entitymonster -> entitymonster.func_230292_f_((ServerPlayerEntity) (Object) this)); - if (!list.isEmpty()) { - return Either.left(PlayerEntity.SleepResult.NOT_SAFE); - } - } - return Either.right(Unit.INSTANCE); - } - return Either.left(PlayerEntity.SleepResult.OTHER_PROBLEM); - } - - @Redirect(method = "trySleep", at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/datafixers/util/Either;left(Ljava/lang/Object;)Lcom/mojang/datafixers/util/Either;")) - private Either arclight$failSleep(L value, BlockPos pos) { - Either either = Either.left(value); - return arclight$fireBedEvent(either, pos); - } - - @Redirect(method = "trySleep", at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/datafixers/util/Either;ifRight(Ljava/util/function/Consumer;)Lcom/mojang/datafixers/util/Either;")) - private Either arclight$successSleep(Either either, Consumer consumer, BlockPos pos) { - return arclight$fireBedEvent(either, pos).ifRight(consumer); - } - - @SuppressWarnings("unchecked") - private Either arclight$fireBedEvent(Either e, BlockPos pos) { - Either either = (Either) e; - if (either.left().orElse(null) == PlayerEntity.SleepResult.OTHER_PROBLEM) { - return (Either) either; - } else { - if (arclight$forceSleep) { - either = Either.right(Unit.INSTANCE); - } - return (Either) CraftEventFactory.callPlayerBedEnterEvent((ServerPlayerEntity) (Object) this, pos, either); - } - } - - @Inject(method = "stopSleepInBed", cancellable = true, at = @At(value = "HEAD")) - private void arclight$wakeupOutBed(boolean p_225652_1_, boolean p_225652_2_, CallbackInfo ci) { - if (!this.isSleeping()) ci.cancel(); - } - - public int nextContainerCounter() { - this.getNextWindowId(); - return this.currentWindowId; - } - - @Inject(method = "openContainer", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/inventory/container/INamedContainerProvider;createMenu(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/inventory/container/Container;")) - private void arclight$invOpen(INamedContainerProvider itileinventory, CallbackInfoReturnable cir, Container container) { - if (container != null) { - ((ContainerBridge) container).bridge$setTitle(itileinventory.getDisplayName()); - boolean cancelled = false; - ArclightCaptures.captureContainerOwner((ServerPlayerEntity) (Object) this); - container = CraftEventFactory.callInventoryOpenEvent((ServerPlayerEntity) (Object) this, container, cancelled); - ArclightCaptures.resetContainerOwner(); - if (container == null && !cancelled) { - if (itileinventory instanceof IInventory) { - ((IInventory) itileinventory).closeInventory((ServerPlayerEntity) (Object) this); - } else if (ChestBlockDoubleInventoryHacks.isInstance(itileinventory)) { - ChestBlockDoubleInventoryHacks.get(itileinventory).closeInventory((ServerPlayerEntity) (Object) this); - } - cir.setReturnValue(OptionalInt.empty()); - } - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void openHorseInventory(final AbstractHorseEntity entityhorseabstract, final IInventory iinventory) { - this.nextContainerCounter(); - Container container = new HorseInventoryContainer(this.currentWindowId, this.inventory, iinventory, entityhorseabstract); - ((ContainerBridge) container).bridge$setTitle(entityhorseabstract.getDisplayName()); - container = CraftEventFactory.callInventoryOpenEvent((ServerPlayerEntity) (Object) this, container); - if (container == null) { - iinventory.closeInventory((ServerPlayerEntity) (Object) this); - return; - } - if (this.openContainer != this.container) { - this.closeScreen(); - } - this.connection.sendPacket(new SOpenHorseWindowPacket(this.currentWindowId, iinventory.getSizeInventory(), entityhorseabstract.getEntityId())); - (this.openContainer = container).addListener((ServerPlayerEntity) (Object) this); - net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open((ServerPlayerEntity) (Object) this, this.openContainer)); - } - - @Inject(method = "sendAllContents", at = @At("RETURN")) - private void arclight$sendExtra(Container container, NonNullList itemsList, CallbackInfo ci) { - ArclightCaptures.captureContainerOwner((ServerPlayerEntity) (Object) this); - if (EnumSet.of(InventoryType.CRAFTING, InventoryType.WORKBENCH).contains(((ContainerBridge) container).bridge$getBukkitView().getType())) { - this.connection.sendPacket(new SSetSlotPacket(container.windowId, 0, container.getSlot(0).getStack())); - } - ArclightCaptures.resetContainerOwner(); - } - - @Inject(method = "closeContainer", at = @At("HEAD")) - private void arclight$invClose(CallbackInfo ci) { - if (this.openContainer != this.container) { - CraftEventFactory.handleInventoryCloseEvent((ServerPlayerEntity) (Object) this); - } - } - - @Redirect(method = "addStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) - private void arclight$addStats(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { - ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); - } - - @Redirect(method = "takeStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;forAllObjectives(Lnet/minecraft/scoreboard/ScoreCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) - private void arclight$takeStats(Scoreboard scoreboard, ScoreCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { - ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); - } - - @Inject(method = "setPlayerHealthUpdated", at = @At("HEAD")) - private void arclight$setExpUpdate(CallbackInfo ci) { - this.lastExperience = -1; - } - - public void sendMessage(UUID uuid, ITextComponent[] components) { - for (final ITextComponent component : components) { - this.sendMessage(component, uuid == null ? Util.DUMMY_UUID : uuid); - } - } - - @Override - public void bridge$sendMessage(ITextComponent[] components, UUID uuid) { - sendMessage(uuid, components); - } - - @Override - public void bridge$sendMessage(ITextComponent component, UUID uuid) { - this.sendMessage(component, uuid == null ? Util.DUMMY_UUID : uuid); - } - - @Inject(method = "setGameType", cancellable = true, at = @At("HEAD")) - private void arclight$gameModeChange(GameType gameType, CallbackInfo ci) { - if (gameType == this.interactionManager.getGameType()) { - ci.cancel(); - return; - } - - PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(gameType.getID())); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - ci.cancel(); - } - } - - @Inject(method = "handleClientSettings", at = @At("HEAD")) - private void arclight$settingChange(CClientSettingsPacket packetIn, CallbackInfo ci) { - if (this.getPrimaryHand() != packetIn.getMainHand()) { - PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), (this.getPrimaryHand() == HandSide.LEFT) ? MainHand.LEFT : MainHand.RIGHT); - Bukkit.getPluginManager().callEvent(event); - } - if (!this.language.equals(packetIn.getLang())) { - PlayerLocaleChangeEvent event2 = new PlayerLocaleChangeEvent(this.getBukkitEntity(), packetIn.getLang()); - Bukkit.getPluginManager().callEvent(event2); - } - this.locale = packetIn.getLang(); - this.clientViewDistance = packetIn.view; - } - - @Inject(method = "setSpectatingEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;setPositionAndUpdate(DDD)V")) - private void arclight$spectatorReason(Entity entityToSpectate, CallbackInfo ci) { - this.bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause.SPECTATE); - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - @Nullable - public ITextComponent getTabListDisplayName() { - return listName; - } - - @Inject(method = "teleport", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/player/ServerPlayerEntity;stopRiding()V")) - private void arclight$handleBy(ServerWorld world, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { - PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause; - arclight$cause = null; - this.getBukkitEntity().teleport(new Location(((WorldBridge) world).bridge$getWorld(), x, y, z, yaw, pitch), cause); - ci.cancel(); - } - - public void a(ServerWorld worldserver, double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { - bridge$pushChangeDimensionCause(cause); - teleport(worldserver, d0, d1, d2, f, f1); - } - - public CraftPlayer getBukkitEntity() { - return (CraftPlayer) ((InternalEntityBridge) this).internal$getBukkitEntity(); - } - - @Override - public CraftPlayer bridge$getBukkitEntity() { - return (CraftPlayer) ((InternalEntityBridge) this).internal$getBukkitEntity(); - } - - @Override - public void bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause cause) { - arclight$cause = cause; - } - - @Override - public Optional bridge$getTeleportCause() { - try { - return Optional.ofNullable(arclight$cause); - } finally { - arclight$cause = null; - } - } - - public long getPlayerTime() { - if (this.relativeTime) { - return this.world.getDayTime() + this.timeOffset; - } - return this.world.getDayTime() - this.world.getDayTime() % 24000L + this.timeOffset; - } - - public WeatherType getPlayerWeather() { - return this.weather; - } - - public void setPlayerWeather(WeatherType type, boolean plugin) { - if (!plugin && this.weather != null) { - return; - } - if (plugin) { - this.weather = type; - } - if (type == WeatherType.DOWNFALL) { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.CLEAR, 0.0f)); - } else { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.RAINING, 0.0f)); - } - } - - public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) { - if (this.weather == null) { - if (oldRain != newRain) { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SET_RAIN_STRENGTH, newRain)); - } - } else if (this.pluginRainPositionPrevious != this.pluginRainPosition) { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SET_RAIN_STRENGTH, this.pluginRainPosition)); - } - if (oldThunder != newThunder) { - if (this.weather == WeatherType.DOWNFALL || this.weather == null) { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SET_THUNDER_STRENGTH, newThunder)); - } else { - this.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SET_THUNDER_STRENGTH, 0.0f)); - } - } - } - - public void tickWeather() { - if (this.weather == null) { - return; - } - this.pluginRainPositionPrevious = this.pluginRainPosition; - if (this.weather == WeatherType.DOWNFALL) { - this.pluginRainPosition += (float) 0.01; - } else { - this.pluginRainPosition -= (float) 0.01; - } - this.pluginRainPosition = MathHelper.clamp(this.pluginRainPosition, 0.0f, 1.0f); - } - - public void resetPlayerWeather() { - this.weather = null; - this.setPlayerWeather(this.world.getWorldInfo().isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false); - } - - @Override - public String toString() { - return super.toString() + "(" + this.getScoreboardName() + " at " + this.getPosX() + "," + this.getPosY() + "," + this.getPosZ() + ")"; - } - - public void forceSetPositionRotation(double x, double y, double z, float yaw, float pitch) { - this.setLocationAndAngles(x, y, z, yaw, pitch); - this.connection.captureCurrentPosition(); - } - - @Override - protected boolean isMovementBlocked() { - return super.isMovementBlocked() || !this.getBukkitEntity().isOnline(); - } - - @Override - public Scoreboard getWorldScoreboard() { - return this.getBukkitEntity().getScoreboard().getHandle(); - } - - public void reset() { - float exp = 0.0f; - boolean keepInventory = this.world.getGameRules().getBoolean(GameRules.KEEP_INVENTORY); - if (this.keepLevel || keepInventory) { - exp = this.experience; - this.newTotalExp = this.experienceTotal; - this.newLevel = this.experienceLevel; - } - this.setHealth(this.getMaxHealth()); - this.fire = 0; - this.fallDistance = 0.0f; - this.foodStats = new FoodStats(); - ((FoodStatsBridge) this.foodStats).bridge$setEntityHuman((ServerPlayerEntity) (Object) this); - this.experienceLevel = this.newLevel; - this.experienceTotal = this.newTotalExp; - this.experience = 0.0f; - this.deathTime = 0; - this.setArrowCount(0, true); - this.removeAllEffects(EntityPotionEffectEvent.Cause.DEATH); - this.potionsNeedUpdate = true; - this.openContainer = this.container; - this.attackingPlayer = null; - this.revengeTarget = null; - this.combatTracker = new CombatTracker((ServerPlayerEntity) (Object) this); - this.lastExperience = -1; - if (this.keepLevel || keepInventory) { - this.experience = exp; - } else { - this.giveExperiencePoints(this.newExp); - } - this.keepLevel = false; - } - - @Override - public boolean bridge$isMovementBlocked() { - return isMovementBlocked(); - } - - @Override - public void bridge$setCompassTarget(Location location) { - this.compassTarget = location; - } - - @Override - public boolean bridge$isJoining() { - return joining; - } - - @Override - public void bridge$reset() { - reset(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractArrowEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractArrowEntityMixin.java deleted file mode 100644 index 2ca3617e..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractArrowEntityMixin.java +++ /dev/null @@ -1,79 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge; -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.AbstractArrowEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.EntityRayTraceResult; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.CraftServer; -import org.bukkit.craftbukkit.v.entity.CraftItem; -import org.bukkit.entity.AbstractArrow; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -import org.bukkit.event.player.PlayerPickupArrowEvent; -import org.bukkit.projectiles.ProjectileSource; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(AbstractArrowEntity.class) -public abstract class AbstractArrowEntityMixin extends ProjectileEntityMixin { - - // @formatter:off - @Shadow public boolean inGround; - @Shadow public abstract boolean getNoClip(); - @Shadow public int arrowShake; - @Shadow public AbstractArrowEntity.PickupStatus pickupStatus; - @Shadow protected abstract ItemStack getArrowStack(); - // @formatter:on - - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) - private void arclight$fireShot(Entity entity, int seconds, EntityRayTraceResult result) { - EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); - Bukkit.getPluginManager().callEvent(combustEvent); - if (!combustEvent.isCancelled()) { - ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void onCollideWithPlayer(PlayerEntity playerEntity) { - if (!this.world.isRemote && (this.inGround || this.getNoClip()) && this.arrowShake <= 0) { - ItemStack itemstack = this.getArrowStack(); - if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) playerEntity.inventory).bridge$canHold(itemstack) > 0) { - ItemEntity item = new ItemEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), itemstack); - PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (AbstractArrowEntity) (Object) this, item), (AbstractArrow) this.getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - return; - } - itemstack = item.getItem(); - } - boolean flag = this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED || (this.pickupStatus == AbstractArrowEntity.PickupStatus.CREATIVE_ONLY && playerEntity.abilities.isCreativeMode) || (this.getNoClip() && this.getShooter().getUniqueID() == playerEntity.getUniqueID()); - if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !playerEntity.inventory.addItemStackToInventory(itemstack)) { - flag = false; - } - if (flag) { - playerEntity.onItemPickup((AbstractArrowEntity) (Object) this, 1); - this.remove(); - } - } - } - - @Inject(method = "setShooter", at = @At("HEAD")) - private void arclight$setShooter(Entity entityIn, CallbackInfo ci) { - this.projectileSource = entityIn == null ? null : (ProjectileSource) ((EntityBridge) entityIn).bridge$getBukkitEntity(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractFireballEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractFireballEntityMixin.java deleted file mode 100644 index f425889d..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/AbstractFireballEntityMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import net.minecraft.entity.projectile.AbstractFireballEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -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; - -@Mixin(AbstractFireballEntity.class) -public abstract class AbstractFireballEntityMixin extends DamagingProjectileEntityMixin { - - @Inject(method = "readAdditional", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/AbstractFireballEntity;setStack(Lnet/minecraft/item/ItemStack;)V")) - private void arclight$nonNullItem(CompoundNBT compound, CallbackInfo ci, ItemStack stack) { - if (stack.isEmpty()) ci.cancel(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/DamagingProjectileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/DamagingProjectileEntityMixin.java deleted file mode 100644 index c02a2583..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/DamagingProjectileEntityMixin.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.projectile.DamagingProjectileEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.projectile.DamagingProjectileEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(DamagingProjectileEntity.class) -public abstract class DamagingProjectileEntityMixin extends ProjectileEntityMixin implements DamagingProjectileEntityBridge { - - // @formatter:off - @Shadow public double accelerationX; - @Shadow public double accelerationY; - @Shadow public double accelerationZ; - // @formatter:on - - public float bukkitYield; - public boolean isIncendiary; - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType p_i50173_1_, World p_i50173_2_, CallbackInfo ci) { - this.bukkitYield = 1; - this.isIncendiary = true; - } - - public void setDirection(double d0, double d1, double d2) { - double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - - this.accelerationX = d0 / d3 * 0.1D; - this.accelerationY = d1 / d3 * 0.1D; - this.accelerationZ = d2 / d3 * 0.1D; - } - - @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/projectile/DamagingProjectileEntity;onImpact(Lnet/minecraft/util/math/RayTraceResult;)V")) - private void arclight$projectileHit(CallbackInfo ci, Entity entity, RayTraceResult rayTraceResult) { - if (this.removed) { - CraftEventFactory.callProjectileHitEvent((DamagingProjectileEntity) (Object) this, rayTraceResult); - } - } - - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getLookVec()Lnet/minecraft/util/math/vector/Vector3d;")) - private void arclight$nonLivingAttack(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((DamagingProjectileEntity) (Object) this, source, amount, false)) { - cir.setReturnValue(false); - } - } - - @Override - public void bridge$setBukkitYield(float yield) { - this.bukkitYield = yield; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EvokerFangsEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EvokerFangsEntityMixin.java deleted file mode 100644 index c89cbd8b..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EvokerFangsEntityMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.EvokerFangsEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(EvokerFangsEntity.class) -public abstract class EvokerFangsEntityMixin extends EntityMixin { - - @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - private void arclight$entityDamage(LivingEntity p_190551_1_, CallbackInfo ci) { - CraftEventFactory.entityDamage = (EvokerFangsEntity) (Object) this; - } - - @Inject(method = "damage", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - private void arclight$entityDamageReset(LivingEntity p_190551_1_, CallbackInfo ci) { - CraftEventFactory.entityDamage = null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireballEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireballEntityMixin.java deleted file mode 100644 index ae1c7d09..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireballEntityMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.FireballEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.Explosion; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.event.entity.ExplosionPrimeEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(FireballEntity.class) -public abstract class FireballEntityMixin extends DamagingProjectileEntityMixin { - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType p_i50163_1_, World worldIn, CallbackInfo ci) { - this.isIncendiary = worldIn.getGameRules().getBoolean(GameRules.MOB_GRIEFING); - } - - @Inject(method = "(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;DDD)V", at = @At("RETURN")) - private void arclight$init(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ, CallbackInfo ci) { - this.isIncendiary = worldIn.getGameRules().getBoolean(GameRules.MOB_GRIEFING); - } - - @Redirect(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/Explosion$Mode;)Lnet/minecraft/world/Explosion;")) - private Explosion arclight$explodePrime(World world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, boolean causesFire, Explosion.Mode modeIn) { - ExplosionPrimeEvent event = new ExplosionPrimeEvent((org.bukkit.entity.Explosive) this.getBukkitEntity()); - event.setRadius(explosionRadius); - event.setFire(causesFire); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - return this.world.createExplosion((FireballEntity) (Object) this, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); - } else { - return null; - } - } - - @Inject(method = "readAdditional", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;getInt(Ljava/lang/String;)I")) - private void arclight$setYield(CompoundNBT compound, CallbackInfo ci) { - this.bukkitYield = compound.getInt("ExplosionPower"); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FishingBobberEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FishingBobberEntityMixin.java deleted file mode 100644 index 6a07f315..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FishingBobberEntityMixin.java +++ /dev/null @@ -1,147 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.FishingBobberEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameterSets; -import net.minecraft.loot.LootParameters; -import net.minecraft.loot.LootTable; -import net.minecraft.loot.LootTables; -import net.minecraft.stats.Stats; -import net.minecraft.tags.ItemTags; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.entity.player.ItemFishedEvent; -import org.bukkit.Bukkit; -import org.bukkit.entity.FishHook; -import org.bukkit.event.player.PlayerFishEvent; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Collections; -import java.util.List; - -@Mixin(FishingBobberEntity.class) -public abstract class FishingBobberEntityMixin extends ProjectileEntityMixin { - - // @formatter:off - @Shadow private Entity caughtEntity; - @Shadow protected abstract void bringInHookedEntity(); - @Shadow private int ticksCatchable; - @Shadow @Final private int luck; - @Shadow public abstract PlayerEntity func_234606_i_(); - // @formatter:on - - @Inject(method = "catchingFish", at = @At(value = "FIELD", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/entity/projectile/FishingBobberEntity;ticksCatchableDelay:I")) - private void arclight$attemptFail(BlockPos blockPos, CallbackInfo ci) { - PlayerFishEvent event = new PlayerFishEvent(((ServerPlayerEntityBridge) this.func_234606_i_()).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT); - Bukkit.getPluginManager().callEvent(event); - } - - @Inject(method = "catchingFish", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/FishingBobberEntity;playSound(Lnet/minecraft/util/SoundEvent;FF)V")) - private void arclight$fishBite(BlockPos blockPos, CallbackInfo ci) { - PlayerFishEvent event = new PlayerFishEvent(((ServerPlayerEntityBridge) this.func_234606_i_()).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) { - ci.cancel(); - } - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public int handleHookRetraction(ItemStack p_146034_1_) { - PlayerEntity playerentity = this.func_234606_i_(); - if (!this.world.isRemote && playerentity != null) { - int i = 0; - ItemFishedEvent event = null; - if (this.caughtEntity != null) { - PlayerFishEvent fishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), ((EntityBridge) this.caughtEntity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY); - Bukkit.getPluginManager().callEvent(fishEvent); - if (fishEvent.isCancelled()) { - return 0; - } - this.bringInHookedEntity(); - CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, (FishingBobberEntity) (Object) this, Collections.emptyList()); - this.world.setEntityState((FishingBobberEntity) (Object)this, (byte) 31); - i = this.caughtEntity instanceof ItemEntity ? 3 : 5; - } else if (this.ticksCatchable > 0) { - LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.ORIGIN, this.getPositionVec()).withParameter(LootParameters.TOOL, p_146034_1_).withParameter(LootParameters.THIS_ENTITY, (FishingBobberEntity) (Object) this).withRandom(this.rand).withLuck((float) this.luck + playerentity.getLuck()); - lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.getShooter()).withParameter(LootParameters.THIS_ENTITY, (FishingBobberEntity) (Object) this); - LootTable loottable = this.world.getServer().getLootTableManager().getLootTableFromLocation(LootTables.GAMEPLAY_FISHING); - List list = loottable.generate(lootcontext$builder.build(LootParameterSets.FISHING)); - event = new ItemFishedEvent(list, this.onGround ? 2 : 1, (FishingBobberEntity) (Object) this); - MinecraftForge.EVENT_BUS.post(event); - if (event.isCanceled()) { - this.remove(); - return event.getRodDamage(); - } - CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, (FishingBobberEntity) (Object) this, list); - - for (ItemStack itemstack : list) { - ItemEntity itementity = new ItemEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), itemstack); - PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), ((EntityBridge) itementity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); - playerFishEvent.setExpToDrop(this.rand.nextInt(6) + 1); - Bukkit.getPluginManager().callEvent(playerFishEvent); - - if (playerFishEvent.isCancelled()) { - return 0; - } - double d0 = playerentity.getPosX() - this.getPosX(); - double d1 = playerentity.getPosY() - this.getPosY(); - double d2 = playerentity.getPosZ() - this.getPosZ(); - double d3 = 0.1D; - itementity.setMotion(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); - this.world.addEntity(itementity); - if (playerFishEvent.getExpToDrop() > 0) { - playerentity.world.addEntity(new ExperienceOrbEntity(playerentity.world, playerentity.getPosX(), playerentity.getPosY() + 0.5D, playerentity.getPosZ() + 0.5D, playerFishEvent.getExpToDrop())); - } - if (itemstack.getItem().isIn(ItemTags.FISHES)) { - playerentity.addStat(Stats.FISH_CAUGHT, 1); - } - } - - i = 1; - } - - if (this.onGround) { - PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND); - Bukkit.getPluginManager().callEvent(playerFishEvent); - - if (playerFishEvent.isCancelled()) { - return 0; - } - i = 2; - } - - if (i == 0) { - PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN); - Bukkit.getPluginManager().callEvent(playerFishEvent); - if (playerFishEvent.isCancelled()) { - return 0; - } - } - - this.remove(); - return event == null ? i : event.getRodDamage(); - } else { - return 0; - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/PotionEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/PotionEntityMixin.java deleted file mode 100644 index 4661ee57..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/PotionEntityMixin.java +++ /dev/null @@ -1,126 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.CampfireBlock; -import net.minecraft.entity.AreaEffectCloudEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.PotionEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Effect; -import net.minecraft.potion.EffectInstance; -import net.minecraft.potion.Potion; -import net.minecraft.util.Direction; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.bukkit.event.entity.LingeringPotionSplashEvent; -import org.bukkit.event.entity.PotionSplashEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Mixin(PotionEntity.class) -public abstract class PotionEntityMixin extends ProjectileItemEntityMixin { - - @Redirect(method = "onImpact", at = @At(value = "INVOKE", remap = false, ordinal = 1, target = "Ljava/util/List;isEmpty()Z")) - private boolean arclight$callEvent(List list) { - return false; - } - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - private void func_213888_a(List list, @Nullable Entity entity) { - AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0, 2.0, 4.0); - List list2 = this.world.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb); - Map affected = new HashMap<>(); - if (!list2.isEmpty()) { - for (LivingEntity entityliving : list2) { - if (entityliving.canBeHitWithPotion()) { - double d0 = this.getDistanceSq(entityliving); - if (d0 >= 16.0) { - continue; - } - double d2 = 1.0 - Math.sqrt(d0) / 4.0; - if (entityliving == entity) { - d2 = 1.0; - } - affected.put(((LivingEntityBridge) entityliving).bridge$getBukkitEntity(), d2); - } - } - } - PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((PotionEntity) (Object) this, affected); - if (!event.isCancelled() && list != null && !list.isEmpty()) { - for (org.bukkit.entity.LivingEntity victim : event.getAffectedEntities()) { - if (!(victim instanceof CraftLivingEntity)) { - continue; - } - LivingEntity entityliving2 = ((CraftLivingEntity) victim).getHandle(); - double d2 = event.getIntensity(victim); - for (EffectInstance mobeffect : list) { - Effect mobeffectlist = mobeffect.getPotion(); - if (!((WorldBridge) this.world).bridge$isPvpMode() && this.getShooter() instanceof ServerPlayerEntity && entityliving2 instanceof ServerPlayerEntity && entityliving2 != this.getShooter()) { - int i = Effect.getId(mobeffectlist); - if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18) { - continue; - } - if (i == 19) { - continue; - } - } - if (mobeffectlist.isInstant()) { - mobeffectlist.affectEntity((PotionEntity) (Object) this, this.getShooter(), entityliving2, mobeffect.getAmplifier(), d2); - } else { - int i = (int) (d2 * mobeffect.getDuration() + 0.5); - if (i <= 20) { - continue; - } - ((LivingEntityBridge) entityliving2).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.POTION_SPLASH); - entityliving2.addPotionEffect(new EffectInstance(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.doesShowParticles())); - } - } - } - } - } - - @Inject(method = "makeAreaOfEffectCloud", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private void arclight$makeCloud(ItemStack p_190542_1_, Potion p_190542_2_, CallbackInfo ci, AreaEffectCloudEntity entity) { - LingeringPotionSplashEvent event = CraftEventFactory.callLingeringPotionSplashEvent((PotionEntity) (Object) this, entity); - if (event.isCancelled() || entity.removed) { - ci.cancel(); - entity.remove(); - } - } - - @Inject(method = "extinguishFires", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - private void arclight$entityChangeBlock(BlockPos pos, Direction direction, CallbackInfo ci) { - if (CraftEventFactory.callEntityChangeBlockEvent((PotionEntity) (Object) this, pos.offset(direction), Blocks.AIR.getDefaultState()).isCancelled()) { - ci.cancel(); - } - } - - @Inject(method = "extinguishFires", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playEvent(Lnet/minecraft/entity/player/PlayerEntity;ILnet/minecraft/util/math/BlockPos;I)V")) - private void arclight$entityChangeBlock2(BlockPos pos, Direction p_184542_2_, CallbackInfo ci, BlockState state) { - if (CraftEventFactory.callEntityChangeBlockEvent((PotionEntity) (Object) this, pos, state.with(CampfireBlock.LIT, false)).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileEntityMixin.java deleted file mode 100644 index e956e920..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileEntityMixin.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceResult; -import org.bukkit.craftbukkit.v.entity.CraftEntity; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.projectiles.ProjectileSource; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import javax.annotation.Nullable; - -@Mixin(ProjectileEntity.class) -public abstract class ProjectileEntityMixin extends EntityMixin { - - // @formatter:off - @Shadow @Nullable public abstract Entity getShooter(); - @Shadow protected void onImpact(RayTraceResult result) { } - // @formatter:on - - @Inject(method = "setShooter", at = @At("RETURN")) - private void arclight$updateSource(Entity entityIn, CallbackInfo ci) { - if (entityIn != null) { - CraftEntity entity = ((EntityBridge) entityIn).bridge$getBukkitEntity(); - if (entity instanceof ProjectileSource) { - this.projectileSource = ((ProjectileSource) entity); - } - } - } - - private boolean hitCancelled = false; - - @Inject(method = "onImpact", cancellable = true, at = @At("HEAD")) - private void arclight$onHit(RayTraceResult result, CallbackInfo ci) { - ProjectileHitEvent event = CraftEventFactory.callProjectileHitEvent((ProjectileEntity) (Object) this, result); - hitCancelled = event != null && event.isCancelled(); - if (!(result.getType() == RayTraceResult.Type.BLOCK || !hitCancelled)) { - ci.cancel(); - } - } - - @Inject(method = "func_230299_a_", cancellable = true, at = @At("HEAD")) - private void arclight$cancelBlockHit(BlockRayTraceResult result, CallbackInfo ci) { - if (hitCancelled) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileItemEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileItemEntityMixin.java deleted file mode 100644 index 6f3f2d2f..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ProjectileItemEntityMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.projectile.ProjectileItemEntityBridge; -import net.minecraft.entity.projectile.ProjectileItemEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.util.Util; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(ProjectileItemEntity.class) -@Implements(@Interface(iface = ProjectileItemEntityBridge.Hack.class, prefix = "hack$")) -public abstract class ProjectileItemEntityMixin extends ThrowableEntityMixin { - - // @formatter:off - @Shadow protected abstract Item shadow$getDefaultItem(); - @Shadow @Final private static DataParameter ITEMSTACK_DATA; - // @formatter:on - - /** - * @author IzzelAliz - * @reason - */ - @Overwrite - public void setItem(ItemStack stack) { - if (stack.getItem() != this.shadow$getDefaultItem() || stack.hasTag()) { - this.getDataManager().set(ITEMSTACK_DATA, Util.make(stack.copy(), (itemStack) -> { - if (!itemStack.isEmpty()) { - itemStack.setCount(1); - } - })); - } - - } - - public Item hack$getDefaultItem() { - return this.shadow$getDefaultItem(); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ShulkerBulletEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ShulkerBulletEntityMixin.java deleted file mode 100644 index 5bafceb7..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ShulkerBulletEntityMixin.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.ShulkerBulletEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; -import net.minecraft.util.math.EntityRayTraceResult; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import javax.annotation.Nullable; - -@Mixin(ShulkerBulletEntity.class) -public abstract class ShulkerBulletEntityMixin extends EntityMixin { - - // @formatter:off - @Shadow private Entity target; - @Shadow @Nullable private Direction direction; - @Shadow protected abstract void selectNextMoveDirection(@Nullable Direction.Axis p_184569_1_); - // @formatter:on - - @Inject(method = "(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Direction$Axis;)V", at = @At("RETURN")) - private void arclight$init(World worldIn, LivingEntity ownerIn, Entity targetIn, Direction.Axis p_i46772_4_, CallbackInfo ci) { - this.projectileSource = ((LivingEntityBridge) ownerIn).bridge$getBukkitEntity(); - } - - @Inject(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$reason(EntityRayTraceResult result, CallbackInfo ci) { - ((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - } - - @Inject(method = "attackEntityFrom", cancellable = true, at = @At("HEAD")) - private void arclight$damageBullet(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((ShulkerBulletEntity) (Object) this, source, amount, false)) { - cir.setReturnValue(false); - } - } - - public Entity getTarget() { - return this.target; - } - - public void setTarget(final Entity e) { - this.target = e; - this.direction = Direction.UP; - this.selectNextMoveDirection(Direction.Axis.X); - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SmallFireballEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SmallFireballEntityMixin.java deleted file mode 100644 index abbeae68..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SmallFireballEntityMixin.java +++ /dev/null @@ -1,51 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.projectile.SmallFireballEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.bukkit.event.entity.EntityCombustByEntityEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(SmallFireballEntity.class) -public abstract class SmallFireballEntityMixin extends AbstractFireballEntityMixin { - - @Inject(method = "(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;DDD)V", at = @At("RETURN")) - private void arclight$init(World worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ, CallbackInfo ci) { - if (this.getShooter() != null && this.getShooter() instanceof MobEntity) { - this.isIncendiary = this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING); - } - } - - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) - private void arclight$entityCombust(Entity entity, int seconds) { - if (this.isIncendiary) { - EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); - Bukkit.getPluginManager().callEvent(event); - - if (!event.isCancelled()) { - ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false); - } - } - } - - @Inject(method = "func_230299_a_", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private void arclight$burnBlock(BlockRayTraceResult result, CallbackInfo ci, Entity entity, BlockPos pos) { - if (!this.isIncendiary || CraftEventFactory.callBlockIgniteEvent(this.world, pos, (SmallFireballEntity) (Object) this).isCancelled()) { - ci.cancel(); - } - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ThrowableEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ThrowableEntityMixin.java deleted file mode 100644 index 163af216..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ThrowableEntityMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.ThrowableEntity; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(ThrowableEntity.class) -public abstract class ThrowableEntityMixin extends ProjectileEntityMixin { - - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, LivingEntity livingEntityIn, World worldIn, CallbackInfo ci) { - this.projectileSource = ((LivingEntityBridge) livingEntityIn).bridge$getBukkitEntity(); - } - - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/ThrowableEntity;onImpact(Lnet/minecraft/util/math/RayTraceResult;)V")) - private void arclight$projectileHit(ThrowableEntity entity, RayTraceResult result) { - this.onImpact(result); - if (this.removed) { - CraftEventFactory.callProjectileHitEvent((ThrowableEntity) (Object) this, result); - } - } - -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/TridentEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/TridentEntityMixin.java deleted file mode 100644 index cb0c4c05..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/TridentEntityMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.projectile.TridentEntityBridge; -import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.projectile.TridentEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import org.bukkit.event.weather.LightningStrikeEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(TridentEntity.class) -public abstract class TridentEntityMixin extends AbstractArrowEntityMixin implements TridentEntityBridge { - - @Shadow public ItemStack thrownStack; - - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$lightning(World world, Entity entityIn) { - ((ServerWorldBridge) this.world).bridge$strikeLightning((LightningBoltEntity) entityIn, LightningStrikeEvent.Cause.TRIDENT); - return true; - } - - @Override - public void bridge$setThrownStack(ItemStack itemStack) { - this.thrownStack = itemStack; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/WitherSkullEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/WitherSkullEntityMixin.java deleted file mode 100644 index 4482ffe1..00000000 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/WitherSkullEntityMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; - -import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.projectile.WitherSkullEntity; -import net.minecraft.util.math.EntityRayTraceResult; -import net.minecraft.world.Explosion; -import net.minecraft.world.World; -import org.bukkit.Bukkit; -import org.bukkit.event.entity.EntityPotionEffectEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -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.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(WitherSkullEntity.class) -public abstract class WitherSkullEntityMixin extends DamagingProjectileEntityMixin { - - @Inject(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;heal(F)V")) - private void arclight$heal(EntityRayTraceResult result, CallbackInfo ci) { - ((LivingEntityBridge) this.getShooter()).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER); - } - - @Inject(method = "onEntityHit", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$effect(EntityRayTraceResult result, CallbackInfo ci) { - ((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); - } - - @Redirect(method = "onImpact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/Explosion$Mode;)Lnet/minecraft/world/Explosion;")) - private Explosion arclight$explode(World world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, boolean causesFire, Explosion.Mode modeIn) { - ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), explosionRadius, causesFire); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - return this.world.createExplosion((WitherSkullEntity) (Object) this, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); - } - return null; - } -} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/FlowingFluidMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/FlowingFluidMixin.java index eebce2c0..19d4dbf8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/FlowingFluidMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/FlowingFluidMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.fluid; -import net.minecraft.block.BlockState; -import net.minecraft.fluid.FlowingFluid; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidState; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -28,11 +28,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public abstract class FlowingFluidMixin { // @formatter:off - @Shadow protected abstract boolean canFlow(IBlockReader worldIn, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, Fluid fluidIn); + @Shadow protected abstract boolean canSpreadTo(BlockGetter worldIn, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, Fluid fluidIn); // @formatter:on - @Inject(method = "flowAround", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/FlowingFluid;flowInto(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/Direction;Lnet/minecraft/fluid/FluidState;)V")) - public void arclight$flowInto(IWorld worldIn, BlockPos pos, FluidState stateIn, CallbackInfo ci) { + @Inject(method = "spread", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FlowingFluid;spreadTo(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;Lnet/minecraft/world/level/material/FluidState;)V")) + public void arclight$flowInto(LevelAccessor worldIn, BlockPos pos, FluidState stateIn, CallbackInfo ci) { Block source = CraftBlock.at(worldIn, pos); BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN); Bukkit.getPluginManager().callEvent(event); @@ -41,10 +41,10 @@ public abstract class FlowingFluidMixin { } } - @Redirect(method = "func_207937_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/FlowingFluid;canFlow(Lnet/minecraft/world/IBlockReader;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/Direction;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/fluid/FluidState;Lnet/minecraft/fluid/Fluid;)Z")) - public boolean arclight$flowInto(FlowingFluid flowingFluid, IBlockReader worldIn, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, Fluid fluidIn) { - if (this.canFlow(worldIn, fromPos, fromBlockState, direction, toPos, toBlockState, toFluidState, fluidIn)) { - Block source = CraftBlock.at(((World) worldIn), fromPos); + @Redirect(method = "spreadToSides", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FlowingFluid;canSpreadTo(Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/material/FluidState;Lnet/minecraft/world/level/material/Fluid;)Z")) + public boolean arclight$flowInto(FlowingFluid flowingFluid, BlockGetter worldIn, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState, Fluid fluidIn) { + if (this.canSpreadTo(worldIn, fromPos, fromBlockState, direction, toPos, toBlockState, toFluidState, fluidIn)) { + Block source = CraftBlock.at(((Level) worldIn), fromPos); BlockFromToEvent event = new BlockFromToEvent(source, CraftBlock.notchToBlockFace(direction)); Bukkit.getPluginManager().callEvent(event); return !event.isCancelled(); @@ -53,13 +53,13 @@ public abstract class FlowingFluidMixin { } } - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private boolean arclight$fluidLevelChange(World world, BlockPos pos, BlockState newState, int flags) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private boolean arclight$fluidLevelChange(Level world, BlockPos pos, BlockState newState, int flags) { FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(world, pos, newState); if (event.isCancelled()) { return false; } else { - return world.setBlockState(pos, ((CraftBlockData) event.getNewData()).getState(), flags); + return world.setBlock(pos, ((CraftBlockData) event.getNewData()).getState(), flags); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/LavaFluidMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/LavaFluidMixin.java index f88e5c26..443b31f2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/LavaFluidMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/fluid/LavaFluidMixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.fluid; import io.izzel.arclight.common.bridge.world.IWorldBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.LavaFluid; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.GameRules; -import net.minecraft.world.IWorld; -import net.minecraft.world.IWorldReader; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.LavaFluid; import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; @@ -25,8 +25,8 @@ import java.util.Random; public abstract class LavaFluidMixin { // @formatter:off - @Shadow protected abstract boolean isSurroundingBlockFlammable(IWorldReader worldIn, BlockPos pos); - @Shadow protected abstract boolean getCanBlockBurn(IWorldReader worldIn, BlockPos pos); + @Shadow protected abstract boolean hasFlammableNeighbours(LevelReader worldIn, BlockPos pos); + @Shadow protected abstract boolean isFlammable(LevelReader worldIn, BlockPos pos); // @formatter:on /** @@ -34,48 +34,48 @@ public abstract class LavaFluidMixin { * @reason */ @Overwrite - public void randomTick(World world, BlockPos pos, FluidState state, Random random) { - if (world.getGameRules().getBoolean(GameRules.DO_FIRE_TICK)) { + public void randomTick(Level world, BlockPos pos, FluidState state, Random random) { + if (world.getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) { int i = random.nextInt(3); if (i > 0) { BlockPos blockpos = pos; for (int j = 0; j < i; ++j) { - blockpos = blockpos.add(random.nextInt(3) - 1, 1, random.nextInt(3) - 1); - if (!world.isBlockPresent(blockpos)) { + blockpos = blockpos.offset(random.nextInt(3) - 1, 1, random.nextInt(3) - 1); + if (!world.isLoaded(blockpos)) { return; } BlockState blockstate = world.getBlockState(blockpos); if (blockstate.isAir()) { - if (this.isSurroundingBlockFlammable(world, blockpos)) { + if (this.hasFlammableNeighbours(world, blockpos)) { if (world.getBlockState(blockpos).getBlock() != Blocks.FIRE) { if (CraftEventFactory.callBlockIgniteEvent(world, blockpos, pos).isCancelled()) { continue; } } - world.setBlockState(blockpos, ForgeEventFactory.fireFluidPlaceBlockEvent(world, blockpos, pos, Blocks.FIRE.getDefaultState())); + world.setBlockAndUpdate(blockpos, ForgeEventFactory.fireFluidPlaceBlockEvent(world, blockpos, pos, Blocks.FIRE.defaultBlockState())); return; } - } else if (blockstate.getMaterial().blocksMovement()) { + } else if (blockstate.getMaterial().blocksMotion()) { return; } } } else { for (int k = 0; k < 3; ++k) { - BlockPos blockpos1 = pos.add(random.nextInt(3) - 1, 0, random.nextInt(3) - 1); - if (!world.isBlockPresent(blockpos1)) { + BlockPos blockpos1 = pos.offset(random.nextInt(3) - 1, 0, random.nextInt(3) - 1); + if (!world.isLoaded(blockpos1)) { return; } - if (world.isAirBlock(blockpos1.up()) && this.getCanBlockBurn(world, blockpos1)) { - BlockPos up = blockpos1.up(); + if (world.isEmptyBlock(blockpos1.above()) && this.isFlammable(world, blockpos1)) { + BlockPos up = blockpos1.above(); if (world.getBlockState(up).getBlock() != Blocks.FIRE) { if (CraftEventFactory.callBlockIgniteEvent(world, up, pos).isCancelled()) { continue; } } - world.setBlockState(blockpos1.up(), ForgeEventFactory.fireFluidPlaceBlockEvent(world, blockpos1.up(), pos, Blocks.FIRE.getDefaultState())); + world.setBlockAndUpdate(blockpos1.above(), ForgeEventFactory.fireFluidPlaceBlockEvent(world, blockpos1.above(), pos, Blocks.FIRE.defaultBlockState())); } } } @@ -84,7 +84,7 @@ public abstract class LavaFluidMixin { } @Eject(method = "flowInto", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private boolean arclight$blockFromTo(IWorld world, BlockPos pos, BlockState newState, int flags, CallbackInfo ci) { + private boolean arclight$blockFromTo(LevelAccessor world, BlockPos pos, BlockState newState, int flags, CallbackInfo ci) { if (!CraftEventFactory.handleBlockFormEvent(((IWorldBridge) world).bridge$getMinecraftWorld(), pos, newState, flags)) { ci.cancel(); return false; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftResultInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftResultInventoryMixin.java index 6eec3c5d..2e67a63c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftResultInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftResultInventoryMixin.java @@ -1,11 +1,6 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -16,19 +11,24 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; -@Mixin(CraftResultInventory.class) -public abstract class CraftResultInventoryMixin implements IInventoryBridge, IInventory { +@Mixin(ResultContainer.class) +public abstract class CraftResultInventoryMixin implements IInventoryBridge, Container { // @formatter:off - @Shadow @Final private NonNullList stackResult; + @Shadow @Final private NonNullList itemStacks; // @formatter:on private int maxStack = MAX_STACK; @Override public List getContents() { - return this.stackResult; + return this.itemStacks; } @Override @@ -49,7 +49,7 @@ public abstract class CraftResultInventoryMixin implements IInventoryBridge, IIn public void setOwner(InventoryHolder owner) { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return this.maxStack; } @@ -63,8 +63,8 @@ public abstract class CraftResultInventoryMixin implements IInventoryBridge, IIn public Location getLocation() { return null; } @Override - public IRecipe getCurrentRecipe() { return null; } + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { } + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftingInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftingInventoryMixin.java index f20fd868..aa5eff46 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftingInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/CraftingInventoryMixin.java @@ -4,13 +4,6 @@ import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -22,48 +15,55 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; -@Mixin(CraftingInventory.class) -public abstract class CraftingInventoryMixin implements CraftingInventoryBridge, IInventory { +@Mixin(CraftingContainer.class) +public abstract class CraftingInventoryMixin implements CraftingInventoryBridge, Container { // @formatter:off - @Shadow @Final private NonNullList stackList; - @Shadow @Final public Container eventHandler; + @Shadow @Final private NonNullList items; + @Shadow @Final public AbstractContainerMenu menu; // @formatter:on public List transaction = new ArrayList<>(); - private IRecipe currentRecipe; - public IInventory resultInventory; - private PlayerEntity owner; + private Recipe currentRecipe; + public Container resultInventory; + private Player owner; private InventoryHolder bukkitOwner; private int maxStack = MAX_STACK; - public void arclight$constructor(Container eventHandlerIn, int width, int height) { + public void arclight$constructor(AbstractContainerMenu eventHandlerIn, int width, int height) { throw new RuntimeException(); } - public void arclight$constructor(Container eventHandlerIn, int width, int height, PlayerEntity owner) { + public void arclight$constructor(AbstractContainerMenu eventHandlerIn, int width, int height, Player owner) { arclight$constructor(eventHandlerIn, width, height); this.owner = owner; } public InventoryType getInvType() { - return this.stackList.size() == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH; + return this.items.size() == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH; } @Override - public void bridge$setResultInventory(IInventory resultInventory) { + public void bridge$setResultInventory(Container resultInventory) { this.resultInventory = resultInventory; } @Override - public void bridge$setOwner(PlayerEntity owner) { + public void bridge$setOwner(Player owner) { this.owner = owner; } @Override public List getContents() { - return this.stackList; + return this.items; } @Override @@ -95,7 +95,7 @@ public abstract class CraftingInventoryMixin implements CraftingInventoryBridge, } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return this.maxStack; } @@ -108,18 +108,18 @@ public abstract class CraftingInventoryMixin implements CraftingInventoryBridge, @Override public Location getLocation() { - return this.eventHandler instanceof PosContainerBridge - ? ((PosContainerBridge) eventHandler).bridge$getWorldLocation() + return this.menu instanceof PosContainerBridge + ? ((PosContainerBridge) menu).bridge$getWorldLocation() : ((PlayerEntityBridge) owner).bridge$getBukkitEntity().getLocation(); } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return this.currentRecipe; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { this.currentRecipe = recipe; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/DoubleSidedInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/DoubleSidedInventoryMixin.java index 82ed5a73..288743cf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/DoubleSidedInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/DoubleSidedInventoryMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -15,35 +11,39 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; -@Mixin(DoubleSidedInventory.class) -public abstract class DoubleSidedInventoryMixin implements IInventoryBridge, IInventory { +@Mixin(CompoundContainer.class) +public abstract class DoubleSidedInventoryMixin implements IInventoryBridge, Container { - @Shadow @Final public IInventory upperChest; - @Shadow @Final public IInventory lowerChest; + @Shadow @Final public Container container1; + @Shadow @Final public Container container2; private List transactions = new ArrayList<>(); @Override public List getContents() { - int size = this.getSizeInventory(); + int size = this.getContainerSize(); List ret = new ArrayList<>(size); for (int i = 0; i < size; i++) { - ret.add(this.getStackInSlot(i)); + ret.add(this.getItem(i)); } return ret; } @Override public void onOpen(CraftHumanEntity who) { - ((IInventoryBridge) this.upperChest).onOpen(who); - ((IInventoryBridge) this.lowerChest).onOpen(who); + ((IInventoryBridge) this.container1).onOpen(who); + ((IInventoryBridge) this.container2).onOpen(who); this.transactions.add(who); } @Override public void onClose(CraftHumanEntity who) { - ((IInventoryBridge) this.upperChest).onClose(who); - ((IInventoryBridge) this.lowerChest).onClose(who); + ((IInventoryBridge) this.container1).onClose(who); + ((IInventoryBridge) this.container2).onClose(who); this.transactions.remove(who); } @@ -59,24 +59,24 @@ public abstract class DoubleSidedInventoryMixin implements IInventoryBridge, IIn public void setOwner(InventoryHolder owner) { } @Override - public int getInventoryStackLimit() { - return Math.min(this.upperChest.getInventoryStackLimit(), this.lowerChest.getInventoryStackLimit()); + public int getMaxStackSize() { + return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); } @Override public void setMaxStackSize(int size) { - ((IInventoryBridge) this.upperChest).setMaxStackSize(size); - ((IInventoryBridge) this.lowerChest).setMaxStackSize(size); + ((IInventoryBridge) this.container1).setMaxStackSize(size); + ((IInventoryBridge) this.container2).setMaxStackSize(size); } @Override public Location getLocation() { - return ((IInventoryBridge) this.upperChest).getLocation(); + return ((IInventoryBridge) this.container1).getLocation(); } @Override - public IRecipe getCurrentRecipe() { return null; } + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { } + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/EnderChestInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/EnderChestInventoryMixin.java index 6b93d717..929688c9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/EnderChestInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/EnderChestInventoryMixin.java @@ -2,10 +2,10 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.EnderChestInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.tileentity.EnderChestTileEntity; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.PlayerEnderChestContainer; +import net.minecraft.world.level.block.entity.EnderChestBlockEntity; import org.bukkit.Location; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -14,20 +14,20 @@ import org.bukkit.inventory.InventoryHolder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(EnderChestInventory.class) -public abstract class EnderChestInventoryMixin extends InventoryMixin implements IInventoryBridge, IInventory { +@Mixin(PlayerEnderChestContainer.class) +public abstract class EnderChestInventoryMixin extends InventoryMixin implements IInventoryBridge, Container { // @formatter:off - @Shadow private EnderChestTileEntity associatedChest; + @Shadow private EnderChestBlockEntity activeChest; // @formatter:on - private PlayerEntity owner; + private Player owner; public void arclight$constructor$super(int numSlots, InventoryHolder owner) { throw new RuntimeException(); } - public void arclight$constructor(PlayerEntity owner) { + public void arclight$constructor(Player owner) { arclight$constructor$super(27, ((PlayerEntityBridge) owner).bridge$getBukkitEntity()); this.owner = owner; } @@ -50,6 +50,6 @@ public abstract class EnderChestInventoryMixin extends InventoryMixin implements @Override public Location getLocation() { - return CraftBlock.at(this.associatedChest.getWorld(), this.associatedChest.getPos()).getLocation(); + return CraftBlock.at(this.activeChest.getLevel(), this.activeChest.getBlockPos()).getLocation(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/IInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/IInventoryMixin.java index bba219dd..fed2ff4b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/IInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/IInventoryMixin.java @@ -1,9 +1,6 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -12,8 +9,11 @@ import org.spongepowered.asm.mixin.Mixin; import java.util.ArrayList; import java.util.List; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; -@Mixin(IInventory.class) +@Mixin(Container.class) public interface IInventoryMixin extends IInventoryBridge { @Override @@ -49,11 +49,11 @@ public interface IInventoryMixin extends IInventoryBridge { } @Override - default IRecipe getCurrentRecipe() { + default Recipe getCurrentRecipe() { return null; } @Override - default void setCurrentRecipe(IRecipe recipe) { + default void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/InventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/InventoryMixin.java index 15b2738e..0db7b96e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/InventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/InventoryMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -17,11 +17,11 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; -@Mixin(Inventory.class) -public abstract class InventoryMixin implements IInventory, IInventoryBridge { +@Mixin(SimpleContainer.class) +public abstract class InventoryMixin implements Container, IInventoryBridge { // @formatter:off - @Shadow @Final public NonNullList inventoryContents; + @Shadow @Final public NonNullList items; // @formatter:on private static final int MAX_STACK = 64; @@ -41,7 +41,7 @@ public abstract class InventoryMixin implements IInventory, IInventoryBridge { @Override public List getContents() { - return this.inventoryContents; + return this.items; } @Override @@ -70,7 +70,7 @@ public abstract class InventoryMixin implements IInventory, IInventoryBridge { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } @@ -86,12 +86,12 @@ public abstract class InventoryMixin implements IInventory, IInventoryBridge { } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/MerchantInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/MerchantInventoryMixin.java index 065b1905..d8889cb3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/MerchantInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/MerchantInventoryMixin.java @@ -2,13 +2,6 @@ package io.izzel.arclight.common.mixin.core.inventory; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.merchant.IMerchant; -import net.minecraft.entity.merchant.villager.AbstractVillagerEntity; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.MerchantInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftAbstractVillager; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -20,13 +13,20 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.entity.npc.AbstractVillager; +import net.minecraft.world.inventory.MerchantContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.trading.Merchant; -@Mixin(MerchantInventory.class) -public abstract class MerchantInventoryMixin implements IInventoryBridge, IInventory { +@Mixin(MerchantContainer.class) +public abstract class MerchantInventoryMixin implements IInventoryBridge, Container { // @formatter:off - @Shadow @Final private NonNullList slots; - @Shadow @Final private IMerchant merchant; + @Shadow @Final private NonNullList itemStacks; + @Shadow @Final private Merchant merchant; // @formatter:on private List transactions = new ArrayList<>(); @@ -34,7 +34,7 @@ public abstract class MerchantInventoryMixin implements IInventoryBridge, IInven @Override public List getContents() { - return this.slots; + return this.itemStacks; } @Override @@ -45,7 +45,7 @@ public abstract class MerchantInventoryMixin implements IInventoryBridge, IInven @Override public void onClose(CraftHumanEntity who) { transactions.remove(who); - this.merchant.setCustomer(null); + this.merchant.setTradingPlayer(null); } @Override @@ -55,14 +55,14 @@ public abstract class MerchantInventoryMixin implements IInventoryBridge, IInven @Override public InventoryHolder getOwner() { - return this.merchant instanceof AbstractVillagerEntity ? ((CraftAbstractVillager) ((EntityBridge) this.merchant).bridge$getBukkitEntity()) : null; + return this.merchant instanceof AbstractVillager ? ((CraftAbstractVillager) ((EntityBridge) this.merchant).bridge$getBukkitEntity()) : null; } @Override public void setOwner(InventoryHolder owner) { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return this.maxStack; } @@ -74,13 +74,13 @@ public abstract class MerchantInventoryMixin implements IInventoryBridge, IInven @Override public Location getLocation() { - return this.merchant instanceof AbstractVillagerEntity ? ((EntityBridge) this.merchant).bridge$getBukkitEntity().getLocation() : null; + return this.merchant instanceof AbstractVillager ? ((EntityBridge) this.merchant).bridge$getBukkitEntity().getLocation() : null; } @Override - public IRecipe getCurrentRecipe() { return null; } + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractFurnaceContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractFurnaceContainerMixin.java index 532e7208..d917de25 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractFurnaceContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractFurnaceContainerMixin.java @@ -1,17 +1,17 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.AbstractFurnaceContainer; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.RecipeBookCategory; -import net.minecraft.tileentity.AbstractFurnaceTileEntity; -import net.minecraft.util.IIntArray; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.AbstractFurnaceMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.RecipeBookType; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; import org.bukkit.craftbukkit.v.inventory.CraftInventoryFurnace; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -22,23 +22,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(AbstractFurnaceContainer.class) +@Mixin(AbstractFurnaceMenu.class) public abstract class AbstractFurnaceContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory furnaceInventory; + @Shadow @Final private Container container; // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(Lnet/minecraft/inventory/container/ContainerType;Lnet/minecraft/item/crafting/IRecipeType;Lnet/minecraft/item/crafting/RecipeBookCategory;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/util/IIntArray;)V", at = @At("RETURN")) - public void arclight$init(ContainerType p_i241922_1_, IRecipeType p_i241922_2_, RecipeBookCategory p_i241922_3_, int p_i241922_4_, PlayerInventory playerInventoryIn, IInventory p_i241922_6_, IIntArray p_i241922_7_, CallbackInfo ci) { + @Inject(method = "(Lnet/minecraft/world/inventory/MenuType;Lnet/minecraft/world/item/crafting/RecipeType;Lnet/minecraft/world/inventory/RecipeBookType;ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;)V", at = @At("RETURN")) + public void arclight$init(MenuType p_i241922_1_, RecipeType p_i241922_2_, RecipeBookType p_i241922_3_, int p_i241922_4_, Inventory playerInventoryIn, Container p_i241922_6_, ContainerData p_i241922_7_, CallbackInfo ci) { this.playerInventory = playerInventoryIn; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -48,8 +48,8 @@ public abstract class AbstractFurnaceContainerMixin extends ContainerMixin { return bukkitEntity; } - CraftInventoryFurnace inventory = new CraftInventoryFurnace((AbstractFurnaceTileEntity) this.furnaceInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryFurnace inventory = new CraftInventoryFurnace((AbstractFurnaceBlockEntity) this.container); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractRepairContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractRepairContainerMixin.java index 22c1d1ba..38563023 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractRepairContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/AbstractRepairContainerMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.inventory.container; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.AbstractRepairContainer; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ItemCombinerMenu; +import net.minecraft.world.inventory.ResultContainer; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -13,18 +13,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(AbstractRepairContainer.class) +@Mixin(ItemCombinerMenu.class) public abstract class AbstractRepairContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final protected IWorldPosCallable field_234644_e_; - @Shadow @Final @Mutable protected IInventory field_234643_d_; - @Shadow @Final protected CraftResultInventory field_234642_c_; - @Shadow @Final protected PlayerEntity field_234645_f_; + @Shadow @Final protected ContainerLevelAccess access; + @Shadow @Final @Mutable protected Container inputSlots; + @Shadow @Final protected ResultContainer resultSlots; + @Shadow @Final protected Player player; // @formatter:on - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - private void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + private void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BeaconContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BeaconContainerMixin.java index 9da76275..4edaf0ab 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BeaconContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BeaconContainerMixin.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.BeaconContainer; -import net.minecraft.inventory.container.Container; -import net.minecraft.util.IIntArray; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.BeaconMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.ContainerLevelAccess; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryBeacon; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; @@ -19,23 +19,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(BeaconContainer.class) +@Mixin(BeaconMenu.class) public abstract class BeaconContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory tileBeacon; + @Shadow @Final private Container beacon; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/inventory/IInventory;Lnet/minecraft/util/IIntArray;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int id, IInventory inventory, IIntArray p_i50100_3_, IWorldPosCallable worldPosCallable, CallbackInfo ci) { - this.playerInventory = (PlayerInventory) inventory; + @Inject(method = "(ILnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int id, Container inventory, ContainerData p_i50100_3_, ContainerLevelAccess worldPosCallable, CallbackInfo ci) { + this.playerInventory = (Inventory) inventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -45,8 +45,8 @@ public abstract class BeaconContainerMixin extends ContainerMixin { return bukkitEntity; } - CraftInventory inventory = new CraftInventoryBeacon(this.tileBeacon); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventory inventory = new CraftInventoryBeacon(this.beacon); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BrewingStandContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BrewingStandContainerMixin.java index 9cf5e324..599c4213 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BrewingStandContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/BrewingStandContainerMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.BrewingStandContainer; -import net.minecraft.inventory.container.Container; -import net.minecraft.util.IIntArray; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.BrewingStandMenu; +import net.minecraft.world.inventory.ContainerData; import org.bukkit.craftbukkit.v.inventory.CraftInventoryBrewer; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -17,23 +17,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(BrewingStandContainer.class) +@Mixin(BrewingStandMenu.class) public abstract class BrewingStandContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory tileBrewingStand; + @Shadow @Final private Container brewingStand; // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/util/IIntArray;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IInventory inventory, IIntArray p_i50096_4_, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;Lnet/minecraft/world/inventory/ContainerData;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, Container inventory, ContainerData p_i50096_4_, CallbackInfo ci) { this.playerInventory = playerInventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -43,8 +43,8 @@ public abstract class BrewingStandContainerMixin extends ContainerMixin { return bukkitEntity; } - CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.tileBrewingStand); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.brewingStand); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer1Mixin.java index aa838760..bae2e7ed 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer1Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.inventory.container.CartographyContainer; +import net.minecraft.world.inventory.CartographyTableMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/CartographyContainer$1") +@Mixin(targets = "net/minecraft/world/inventory/CartographyTableMenu$1") public abstract class CartographyContainer1Mixin implements IInventoryBridge { - @Shadow(aliases = {"this$0", "field_213911_a"}, remap = false) private CartographyContainer outerThis; + @Shadow(aliases = {"this$0", "field_213911_a"}, remap = false) private CartographyTableMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer2Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer2Mixin.java index e470504c..736aad9a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer2Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainer2Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.inventory.container.CartographyContainer; +import net.minecraft.world.inventory.CartographyTableMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/CartographyContainer$2") +@Mixin(targets = "net/minecraft/world/inventory/CartographyTableMenu$2") public abstract class CartographyContainer2Mixin implements IInventoryBridge { - @Shadow(aliases = {"this$0", "field_213924_a"}, remap = false) private CartographyContainer outerThis; + @Shadow(aliases = {"this$0", "field_213924_a"}, remap = false) private CartographyTableMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainerMixin.java index 58f9e21a..13cf50cf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/CartographyContainerMixin.java @@ -2,13 +2,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.CartographyContainer; -import net.minecraft.inventory.container.Container; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.CartographyTableMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ResultContainer; import org.bukkit.craftbukkit.v.inventory.CraftInventoryCartography; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.bukkit.entity.Player; @@ -20,25 +19,25 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(CartographyContainer.class) +@Mixin(CartographyTableMenu.class) public abstract class CartographyContainerMixin extends ContainerMixin implements PosContainerBridge { // @formatter:off - @Shadow @Final private IWorldPosCallable worldPosCallable; - @Shadow @Final public IInventory tableInventory; - @Shadow @Final private CraftResultInventory field_217001_f; + @Shadow @Final private ContainerLevelAccess access; + @Shadow @Final public Container container; + @Shadow @Final private ResultContainer resultContainer; // @formatter:on private CraftInventoryView bukkitEntity = null; private Player player; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IWorldPosCallable worldPosCallable, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, ContainerLevelAccess worldPosCallable, CallbackInfo ci) { this.player = ((ServerPlayerEntityBridge) playerInventory.player).bridge$getBukkitEntity(); } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(net.minecraft.world.entity.player.Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -48,13 +47,13 @@ public abstract class CartographyContainerMixin extends ContainerMixin implement return bukkitEntity; } - CraftInventoryCartography inventory = new CraftInventoryCartography(this.tableInventory, this.field_217001_f); - bukkitEntity = new CraftInventoryView(this.player, inventory, (Container) (Object) this); + CraftInventoryCartography inventory = new CraftInventoryCartography(this.container, this.resultContainer); + bukkitEntity = new CraftInventoryView(this.player, inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public IWorldPosCallable bridge$getWorldPos() { - return this.worldPosCallable; + public ContainerLevelAccess bridge$getWorldPos() { + return this.access; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ChestContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ChestContainerMixin.java index 47fed1e8..74a2dab8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ChestContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ChestContainerMixin.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.ChestContainer; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ChestMenu; +import net.minecraft.world.inventory.MenuType; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest; import org.bukkit.craftbukkit.v.inventory.CraftInventoryPlayer; @@ -20,23 +20,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ChestContainer.class) +@Mixin(ChestMenu.class) public abstract class ChestContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory lowerChestInventory; + @Shadow @Final private Container container; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(Lnet/minecraft/inventory/container/ContainerType;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;I)V", at = @At("RETURN")) - public void arclight$init(ContainerType type, int id, PlayerInventory playerInventoryIn, IInventory p_i50092_4_, int rows, CallbackInfo ci) { + @Inject(method = "(Lnet/minecraft/world/inventory/MenuType;ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;I)V", at = @At("RETURN")) + public void arclight$init(MenuType type, int id, Inventory playerInventoryIn, Container p_i50092_4_, int rows, CallbackInfo ci) { this.playerInventory = playerInventoryIn; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -47,15 +47,15 @@ public abstract class ChestContainerMixin extends ContainerMixin { } CraftInventory inventory; - if (this.lowerChestInventory instanceof PlayerInventory) { - inventory = new CraftInventoryPlayer((PlayerInventory) this.lowerChestInventory); - } else if (this.lowerChestInventory instanceof DoubleSidedInventory) { - inventory = new CraftInventoryDoubleChest((DoubleSidedInventory) this.lowerChestInventory); + if (this.container instanceof Inventory) { + inventory = new CraftInventoryPlayer((Inventory) this.container); + } else if (this.container instanceof CompoundContainer) { + inventory = new CraftInventoryDoubleChest((CompoundContainer) this.container); } else { - inventory = new CraftInventory(this.lowerChestInventory); + inventory = new CraftInventory(this.container); } - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerMixin.java index 4122df4e..8065ec0c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerMixin.java @@ -4,18 +4,6 @@ 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.SlotBridge; import io.izzel.arclight.common.mod.server.ArclightContainer; -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.ContainerType; -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.StringTextComponent; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -37,30 +25,42 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; -@Mixin(Container.class) +@Mixin(AbstractContainerMenu.class) public abstract class ContainerMixin implements ContainerBridge { // @formatter:off - @Shadow public void detectAndSendChanges() {} - @Shadow private int dragEvent; - @Shadow protected abstract void resetDrag(); - @Shadow private int dragMode; - @Shadow @Final private Set dragSlots; - @Shadow public List 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 void broadcastChanges() {} + @Shadow private int quickcraftStatus; + @Shadow protected abstract void resetQuickCraft(); + @Shadow private int quickcraftType; + @Shadow @Final private Set quickcraftSlots; + @Shadow public List slots; + @Shadow public abstract boolean canDragTo(Slot slotIn); + @Shadow public abstract ItemStack quickMoveStack(Player playerIn, int index); + @Shadow public abstract boolean canTakeItemForPickAll(ItemStack stack, Slot slotIn); + @Shadow @Final public int containerId; @Shadow public abstract Slot getSlot(int slotId); - @Shadow public static int getDragEvent(int clickedButton) { return 0; } - @Shadow public static int extractDragMode(int eventButton) { return 0; } - @Shadow public static boolean isValidDragMode(int dragModeIn, PlayerEntity player) { return false; } - @Shadow public static boolean canAddItemToSlot(@Nullable Slot slotIn, ItemStack stack, boolean stackSizeMatters) { return false; } - @Shadow public static void computeStackSize(Set dragSlotsIn, int dragModeIn, ItemStack stack, int slotStackSize) { } - @Shadow public static boolean areItemsAndTagsEqual(ItemStack stack1, ItemStack stack2) { return false; } - @Shadow protected abstract boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection); - @Shadow @Final @javax.annotation.Nullable private ContainerType containerType; + @Shadow public static int getQuickcraftHeader(int clickedButton) { return 0; } + @Shadow public static int getQuickcraftType(int eventButton) { return 0; } + @Shadow public static boolean isValidQuickcraftType(int dragModeIn, Player player) { return false; } + @Shadow public static boolean canItemQuickReplace(@Nullable Slot slotIn, ItemStack stack, boolean stackSizeMatters) { return false; } + @Shadow public static void getQuickCraftSlotCount(Set dragSlotsIn, int dragModeIn, ItemStack stack, int slotStackSize) { } + @Shadow public static boolean consideredTheSameItem(ItemStack stack1, ItemStack stack2) { return false; } + @Shadow protected abstract boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection); + @Shadow @Final @javax.annotation.Nullable private MenuType menuType; // @formatter:on public boolean checkReachable = true; @@ -69,21 +69,21 @@ public abstract class ContainerMixin implements ContainerBridge { public InventoryView getBukkitView() { if (bukkitView != null && bukkitViewHash != bukkitViewHash()) { - ArclightContainer.updateView((Container) (Object) this, bukkitView); + ArclightContainer.updateView((AbstractContainerMenu) (Object) this, bukkitView); bukkitViewHash = bukkitViewHash(); } if (bukkitView == null) { - bukkitView = ArclightContainer.createInvView((Container) (Object) this); + bukkitView = ArclightContainer.createInvView((AbstractContainerMenu) (Object) this); bukkitViewHash = bukkitViewHash(); } return bukkitView; } private long bukkitViewHash() { - return (((long) this.inventorySlots.size()) << 32) | System.identityHashCode(this.inventorySlots); + return (((long) this.slots.size()) << 32) | System.identityHashCode(this.slots); } - public void transferTo(Container other, CraftHumanEntity player) { + public void transferTo(AbstractContainerMenu other, CraftHumanEntity player) { InventoryView source = this.getBukkitView(); InventoryView destination = ((ContainerBridge) other).bridge$getBukkitView(); ((IInventoryBridge) ((CraftInventory) source.getTopInventory()).getInventory()).onClose(player); @@ -92,20 +92,20 @@ public abstract class ContainerMixin implements ContainerBridge { ((IInventoryBridge) ((CraftInventory) destination.getBottomInventory()).getInventory()).onOpen(player); } - private ITextComponent title; + private Component title; - public final ITextComponent getTitle() { + public final Component getTitle() { if (this.title == null) { - if (this.containerType != null && this.containerType.getRegistryName() != null) { - return new StringTextComponent(this.containerType.getRegistryName().toString()); + if (this.menuType != null && this.menuType.getRegistryName() != null) { + return new TextComponent(this.menuType.getRegistryName().toString()); } else { - return new StringTextComponent(this.toString()); + return new TextComponent(this.toString()); } } return this.title; } - public final void setTitle(ITextComponent title) { + public final void setTitle(Component title) { if (this.title == null) { if (title == null) { this.title = getTitle(); @@ -115,10 +115,10 @@ public abstract class ContainerMixin implements ContainerBridge { } } - @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); + @Redirect(method = "removed", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;drop(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/world/entity/item/ItemEntity;")) + private ItemEntity arclight$cleanBeforeDrop(Player playerEntity, ItemStack itemStackIn, boolean unused) { + playerEntity.inventory.setCarried(ItemStack.EMPTY); + return playerEntity.drop(itemStackIn, unused); } /** @@ -126,51 +126,51 @@ public abstract class ContainerMixin implements ContainerBridge { * @reason */ @Overwrite - private ItemStack func_241440_b_(int slotId, int dragType, ClickType clickTypeIn, PlayerEntity player) { + private ItemStack doClick(int slotId, int dragType, ClickType clickTypeIn, Player player) { ItemStack itemstack = ItemStack.EMPTY; - PlayerInventory playerinventory = player.inventory; + Inventory playerinventory = player.inventory; if (clickTypeIn == ClickType.QUICK_CRAFT) { - int j1 = this.dragEvent; - this.dragEvent = getDragEvent(dragType); - if ((j1 != 1 || this.dragEvent != 2) && j1 != this.dragEvent) { - this.resetDrag(); - } else if (playerinventory.getItemStack().isEmpty()) { - this.resetDrag(); - } else if (this.dragEvent == 0) { - this.dragMode = extractDragMode(dragType); - if (isValidDragMode(this.dragMode, player)) { - this.dragEvent = 1; - this.dragSlots.clear(); + int j1 = this.quickcraftStatus; + this.quickcraftStatus = getQuickcraftHeader(dragType); + if ((j1 != 1 || this.quickcraftStatus != 2) && j1 != this.quickcraftStatus) { + this.resetQuickCraft(); + } else if (playerinventory.getCarried().isEmpty()) { + this.resetQuickCraft(); + } else if (this.quickcraftStatus == 0) { + this.quickcraftType = getQuickcraftType(dragType); + if (isValidQuickcraftType(this.quickcraftType, player)) { + this.quickcraftStatus = 1; + this.quickcraftSlots.clear(); } else { - this.resetDrag(); + this.resetQuickCraft(); } - } else if (this.dragEvent == 1) { - Slot slot7 = this.inventorySlots.get(slotId); - ItemStack itemstack12 = playerinventory.getItemStack(); - if (slot7 != null && canAddItemToSlot(slot7, itemstack12, true) && slot7.isItemValid(itemstack12) && (this.dragMode == 2 || itemstack12.getCount() > this.dragSlots.size()) && this.canDragIntoSlot(slot7)) { - this.dragSlots.add(slot7); + } else if (this.quickcraftStatus == 1) { + Slot slot7 = this.slots.get(slotId); + ItemStack itemstack12 = playerinventory.getCarried(); + if (slot7 != null && canItemQuickReplace(slot7, itemstack12, true) && slot7.mayPlace(itemstack12) && (this.quickcraftType == 2 || itemstack12.getCount() > this.quickcraftSlots.size()) && this.canDragTo(slot7)) { + this.quickcraftSlots.add(slot7); } - } else if (this.dragEvent == 2) { - if (!this.dragSlots.isEmpty()) { - ItemStack itemstack9 = playerinventory.getItemStack().copy(); - int k1 = playerinventory.getItemStack().getCount(); + } else if (this.quickcraftStatus == 2) { + if (!this.quickcraftSlots.isEmpty()) { + ItemStack itemstack9 = playerinventory.getCarried().copy(); + int k1 = playerinventory.getCarried().getCount(); Map draggedSlots = new HashMap<>(); - for (Slot slot8 : this.dragSlots) { - ItemStack itemstack13 = playerinventory.getItemStack(); - if (slot8 != null && canAddItemToSlot(slot8, itemstack13, true) && slot8.isItemValid(itemstack13) && (this.dragMode == 2 || itemstack13.getCount() >= this.dragSlots.size()) && this.canDragIntoSlot(slot8)) { + for (Slot slot8 : this.quickcraftSlots) { + ItemStack itemstack13 = playerinventory.getCarried(); + if (slot8 != null && canItemQuickReplace(slot8, itemstack13, true) && slot8.mayPlace(itemstack13) && (this.quickcraftType == 2 || itemstack13.getCount() >= this.quickcraftSlots.size()) && this.canDragTo(slot8)) { ItemStack itemstack14 = itemstack9.copy(); - int j3 = slot8.getHasStack() ? slot8.getStack().getCount() : 0; - computeStackSize(this.dragSlots, this.dragMode, itemstack14, j3); - int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getItemStackLimit(itemstack14)); + int j3 = slot8.hasItem() ? slot8.getItem().getCount() : 0; + getQuickCraftSlotCount(this.quickcraftSlots, this.quickcraftType, itemstack14, j3); + int k3 = Math.min(itemstack14.getMaxStackSize(), slot8.getMaxStackSize(itemstack14)); if (itemstack14.getCount() > k3) { itemstack14.setCount(k3); } k1 -= itemstack14.getCount() - j3; // slot8.putStack(itemstack14); - draggedSlots.put(slot8.slotNumber, itemstack14); + draggedSlots.put(slot8.index, itemstack14); } } @@ -181,43 +181,43 @@ public abstract class ContainerMixin implements ContainerBridge { for (Map.Entry 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); + ItemStack oldCursor = playerinventory.getCarried(); + playerinventory.setCarried(CraftItemStack.asNMSCopy(newcursor)); + InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != Material.AIR) ? newcursor : null, CraftItemStack.asBukkitCopy(oldCursor), this.quickcraftType == 1, eventmap); Bukkit.getPluginManager().callEvent(event); boolean needsUpdate = event.getResult() != Event.Result.DEFAULT; if (event.getResult() != Event.Result.DENY) { for (Map.Entry dslot : draggedSlots.entrySet()) { view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue())); } - if (playerinventory.getItemStack() != null) { - playerinventory.setItemStack(CraftItemStack.asNMSCopy(event.getCursor())); + if (playerinventory.getCarried() != null) { + playerinventory.setCarried(CraftItemStack.asNMSCopy(event.getCursor())); needsUpdate = true; } } else { - playerinventory.setItemStack(oldCursor); + playerinventory.setCarried(oldCursor); } - if (needsUpdate && player instanceof ServerPlayerEntity) { - ((ServerPlayerEntity) player).sendContainerToPlayer((Container) (Object) this); + if (needsUpdate && player instanceof ServerPlayer) { + ((ServerPlayer) player).refreshContainer((AbstractContainerMenu) (Object) this); } } - this.resetDrag(); + this.resetQuickCraft(); } else { - this.resetDrag(); + this.resetQuickCraft(); } - } else if (this.dragEvent != 0) { - this.resetDrag(); + } else if (this.quickcraftStatus != 0) { + this.resetQuickCraft(); } else if ((clickTypeIn == ClickType.PICKUP || clickTypeIn == ClickType.QUICK_MOVE) && (dragType == 0 || dragType == 1)) { if (slotId == -999) { - if (!playerinventory.getItemStack().isEmpty()) { + if (!playerinventory.getCarried().isEmpty()) { if (dragType == 0) { - ItemStack carried = playerinventory.getItemStack(); - playerinventory.setItemStack(ItemStack.EMPTY); - player.dropItem(carried, true); + ItemStack carried = playerinventory.getCarried(); + playerinventory.setCarried(ItemStack.EMPTY); + player.drop(carried, true); } if (dragType == 1) { - player.dropItem(playerinventory.getItemStack().split(1), true); + player.drop(playerinventory.getCarried().split(1), true); } } } else if (clickTypeIn == ClickType.QUICK_MOVE) { @@ -225,12 +225,12 @@ public abstract class ContainerMixin implements ContainerBridge { return ItemStack.EMPTY; } - Slot slot5 = this.inventorySlots.get(slotId); - if (slot5 == null || !slot5.canTakeStack(player)) { + Slot slot5 = this.slots.get(slotId); + if (slot5 == null || !slot5.mayPickup(player)) { return ItemStack.EMPTY; } - for (ItemStack itemstack7 = this.transferStackInSlot(player, slotId); !itemstack7.isEmpty() && ItemStack.areItemsEqual(slot5.getStack(), itemstack7); itemstack7 = this.transferStackInSlot(player, slotId)) { + for (ItemStack itemstack7 = this.quickMoveStack(player, slotId); !itemstack7.isEmpty() && ItemStack.isSame(slot5.getItem(), itemstack7); itemstack7 = this.quickMoveStack(player, slotId)) { itemstack = itemstack7.copy(); } } else { @@ -238,42 +238,42 @@ public abstract class ContainerMixin implements ContainerBridge { return ItemStack.EMPTY; } - Slot slot6 = this.inventorySlots.get(slotId); + Slot slot6 = this.slots.get(slotId); if (slot6 != null) { - ItemStack itemstack8 = slot6.getStack(); - ItemStack itemstack11 = playerinventory.getItemStack(); + ItemStack itemstack8 = slot6.getItem(); + ItemStack itemstack11 = playerinventory.getCarried(); if (!itemstack8.isEmpty()) { itemstack = itemstack8.copy(); } if (itemstack8.isEmpty()) { - if (!itemstack11.isEmpty() && slot6.isItemValid(itemstack11)) { + if (!itemstack11.isEmpty() && slot6.mayPlace(itemstack11)) { int j2 = dragType == 0 ? itemstack11.getCount() : 1; - if (j2 > slot6.getItemStackLimit(itemstack11)) { - j2 = slot6.getItemStackLimit(itemstack11); + if (j2 > slot6.getMaxStackSize(itemstack11)) { + j2 = slot6.getMaxStackSize(itemstack11); } - slot6.putStack(itemstack11.split(j2)); + slot6.set(itemstack11.split(j2)); } - } else if (slot6.canTakeStack(player)) { + } else if (slot6.mayPickup(player)) { if (itemstack11.isEmpty()) { if (itemstack8.isEmpty()) { - slot6.putStack(ItemStack.EMPTY); - playerinventory.setItemStack(ItemStack.EMPTY); + slot6.set(ItemStack.EMPTY); + playerinventory.setCarried(ItemStack.EMPTY); } else { int k2 = dragType == 0 ? itemstack8.getCount() : (itemstack8.getCount() + 1) / 2; - playerinventory.setItemStack(slot6.decrStackSize(k2)); + playerinventory.setCarried(slot6.remove(k2)); if (itemstack8.isEmpty()) { - slot6.putStack(ItemStack.EMPTY); + slot6.set(ItemStack.EMPTY); } - slot6.onTake(player, playerinventory.getItemStack()); + slot6.onTake(player, playerinventory.getCarried()); } - } else if (slot6.isItemValid(itemstack11)) { - if (areItemsAndTagsEqual(itemstack8, itemstack11)) { + } else if (slot6.mayPlace(itemstack11)) { + if (consideredTheSameItem(itemstack8, itemstack11)) { int l2 = dragType == 0 ? itemstack11.getCount() : 1; - if (l2 > slot6.getItemStackLimit(itemstack11) - itemstack8.getCount()) { - l2 = slot6.getItemStackLimit(itemstack11) - itemstack8.getCount(); + if (l2 > slot6.getMaxStackSize(itemstack11) - itemstack8.getCount()) { + l2 = slot6.getMaxStackSize(itemstack11) - itemstack8.getCount(); } if (l2 > itemstack11.getMaxStackSize() - itemstack8.getCount()) { @@ -282,103 +282,103 @@ public abstract class ContainerMixin implements ContainerBridge { itemstack11.shrink(l2); itemstack8.grow(l2); - } else if (itemstack11.getCount() <= slot6.getItemStackLimit(itemstack11)) { - slot6.putStack(itemstack11); - playerinventory.setItemStack(itemstack8); + } else if (itemstack11.getCount() <= slot6.getMaxStackSize(itemstack11)) { + slot6.set(itemstack11); + playerinventory.setCarried(itemstack8); } - } else if (itemstack11.getMaxStackSize() > 1 && areItemsAndTagsEqual(itemstack8, itemstack11) && !itemstack8.isEmpty()) { + } else if (itemstack11.getMaxStackSize() > 1 && consideredTheSameItem(itemstack8, itemstack11) && !itemstack8.isEmpty()) { int i3 = itemstack8.getCount(); if (i3 + itemstack11.getCount() <= itemstack11.getMaxStackSize()) { itemstack11.grow(i3); - itemstack8 = slot6.decrStackSize(i3); + itemstack8 = slot6.remove(i3); if (itemstack8.isEmpty()) { - slot6.putStack(ItemStack.EMPTY); + slot6.set(ItemStack.EMPTY); } - slot6.onTake(player, playerinventory.getItemStack()); + slot6.onTake(player, playerinventory.getCarried()); } } } - slot6.onSlotChanged(); + slot6.setChanged(); - if (player instanceof ServerPlayerEntity && slot6.getSlotStackLimit() != 64) { - ((ServerPlayerEntity) player).connection.sendPacket(new SSetSlotPacket(this.windowId, slot6.slotNumber, slot6.getStack())); + if (player instanceof ServerPlayer && slot6.getMaxStackSize() != 64) { + ((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, slot6.index, slot6.getItem())); if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) { - ((ServerPlayerEntity) player).connection.sendPacket(new SSetSlotPacket(this.windowId, 0, this.getSlot(0).getStack())); + ((ServerPlayer) player).connection.send(new ClientboundContainerSetSlotPacket(this.containerId, 0, this.getSlot(0).getItem())); } } } } } else if (clickTypeIn == ClickType.SWAP && dragType >= 0 && dragType < 9) { - Slot slot4 = this.inventorySlots.get(slotId); - ItemStack itemstack6 = playerinventory.getStackInSlot(dragType); - ItemStack itemstack10 = slot4.getStack(); + Slot slot4 = this.slots.get(slotId); + ItemStack itemstack6 = playerinventory.getItem(dragType); + ItemStack itemstack10 = slot4.getItem(); if (!itemstack6.isEmpty() || !itemstack10.isEmpty()) { if (itemstack6.isEmpty()) { - if (slot4.canTakeStack(player)) { - playerinventory.setInventorySlotContents(dragType, itemstack10); + if (slot4.mayPickup(player)) { + playerinventory.setItem(dragType, itemstack10); ((SlotBridge) slot4).bridge$onSwapCraft(itemstack10.getCount()); - slot4.putStack(ItemStack.EMPTY); + slot4.set(ItemStack.EMPTY); slot4.onTake(player, itemstack10); } } else if (itemstack10.isEmpty()) { - if (slot4.isItemValid(itemstack6)) { - int l1 = slot4.getItemStackLimit(itemstack6); + if (slot4.mayPlace(itemstack6)) { + int l1 = slot4.getMaxStackSize(itemstack6); if (itemstack6.getCount() > l1) { - slot4.putStack(itemstack6.split(l1)); + slot4.set(itemstack6.split(l1)); } else { - slot4.putStack(itemstack6); - playerinventory.setInventorySlotContents(dragType, ItemStack.EMPTY); + slot4.set(itemstack6); + playerinventory.setItem(dragType, ItemStack.EMPTY); } } - } else if (slot4.canTakeStack(player) && slot4.isItemValid(itemstack6)) { - int i2 = slot4.getItemStackLimit(itemstack6); + } else if (slot4.mayPickup(player) && slot4.mayPlace(itemstack6)) { + int i2 = slot4.getMaxStackSize(itemstack6); if (itemstack6.getCount() > i2) { - slot4.putStack(itemstack6.split(i2)); + slot4.set(itemstack6.split(i2)); slot4.onTake(player, itemstack10); - if (!playerinventory.addItemStackToInventory(itemstack10)) { - player.dropItem(itemstack10, true); + if (!playerinventory.add(itemstack10)) { + player.drop(itemstack10, true); } } else { - slot4.putStack(itemstack6); - playerinventory.setInventorySlotContents(dragType, itemstack10); + slot4.set(itemstack6); + playerinventory.setItem(dragType, itemstack10); slot4.onTake(player, itemstack10); } } } - } else if (clickTypeIn == ClickType.CLONE && player.abilities.isCreativeMode && playerinventory.getItemStack().isEmpty() && slotId >= 0) { - Slot slot3 = this.inventorySlots.get(slotId); - if (slot3 != null && slot3.getHasStack()) { - ItemStack itemstack5 = slot3.getStack().copy(); + } else if (clickTypeIn == ClickType.CLONE && player.abilities.instabuild && playerinventory.getCarried().isEmpty() && slotId >= 0) { + Slot slot3 = this.slots.get(slotId); + if (slot3 != null && slot3.hasItem()) { + ItemStack itemstack5 = slot3.getItem().copy(); itemstack5.setCount(itemstack5.getMaxStackSize()); - playerinventory.setItemStack(itemstack5); + playerinventory.setCarried(itemstack5); } - } else if (clickTypeIn == ClickType.THROW && playerinventory.getItemStack().isEmpty() && slotId >= 0) { - Slot slot2 = this.inventorySlots.get(slotId); - if (slot2 != null && slot2.getHasStack() && slot2.canTakeStack(player)) { - ItemStack itemstack4 = slot2.decrStackSize(dragType == 0 ? 1 : slot2.getStack().getCount()); + } else if (clickTypeIn == ClickType.THROW && playerinventory.getCarried().isEmpty() && slotId >= 0) { + Slot slot2 = this.slots.get(slotId); + if (slot2 != null && slot2.hasItem() && slot2.mayPickup(player)) { + ItemStack itemstack4 = slot2.remove(dragType == 0 ? 1 : slot2.getItem().getCount()); slot2.onTake(player, itemstack4); - player.dropItem(itemstack4, true); + player.drop(itemstack4, true); } } else if (clickTypeIn == ClickType.PICKUP_ALL && slotId >= 0) { - Slot slot = this.inventorySlots.get(slotId); - ItemStack itemstack1 = playerinventory.getItemStack(); - if (!itemstack1.isEmpty() && (slot == null || !slot.getHasStack() || !slot.canTakeStack(player))) { - int i = dragType == 0 ? 0 : this.inventorySlots.size() - 1; + Slot slot = this.slots.get(slotId); + ItemStack itemstack1 = playerinventory.getCarried(); + if (!itemstack1.isEmpty() && (slot == null || !slot.hasItem() || !slot.mayPickup(player))) { + int i = dragType == 0 ? 0 : this.slots.size() - 1; int j = dragType == 0 ? 1 : -1; for (int k = 0; k < 2; ++k) { - for (int l = i; l >= 0 && l < this.inventorySlots.size() && itemstack1.getCount() < itemstack1.getMaxStackSize(); l += j) { - Slot slot1 = this.inventorySlots.get(l); - if (slot1.getHasStack() && canAddItemToSlot(slot1, itemstack1, true) && slot1.canTakeStack(player) && this.canMergeSlot(itemstack1, slot1)) { - ItemStack itemstack2 = slot1.getStack(); + for (int l = i; l >= 0 && l < this.slots.size() && itemstack1.getCount() < itemstack1.getMaxStackSize(); l += j) { + Slot slot1 = this.slots.get(l); + if (slot1.hasItem() && canItemQuickReplace(slot1, itemstack1, true) && slot1.mayPickup(player) && this.canTakeItemForPickAll(itemstack1, slot1)) { + ItemStack itemstack2 = slot1.getItem(); if (k != 0 || itemstack2.getCount() != itemstack2.getMaxStackSize()) { int i1 = Math.min(itemstack1.getMaxStackSize() - itemstack1.getCount(), itemstack2.getCount()); - ItemStack itemstack3 = slot1.decrStackSize(i1); + ItemStack itemstack3 = slot1.remove(i1); itemstack1.grow(i1); if (itemstack3.isEmpty()) { - slot1.putStack(ItemStack.EMPTY); + slot1.set(ItemStack.EMPTY); } slot1.onTake(player, itemstack3); } @@ -386,7 +386,7 @@ public abstract class ContainerMixin implements ContainerBridge { } } } - this.detectAndSendChanges(); + this.broadcastChanges(); } return itemstack; } @@ -402,17 +402,17 @@ public abstract class ContainerMixin implements ContainerBridge { } @Override - public void bridge$transferTo(Container other, CraftHumanEntity player) { + public void bridge$transferTo(AbstractContainerMenu other, CraftHumanEntity player) { transferTo(other, player); } @Override - public ITextComponent bridge$getTitle() { + public Component bridge$getTitle() { return getTitle(); } @Override - public void bridge$setTitle(ITextComponent title) { + public void bridge$setTitle(Component title) { setTitle(title); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerTypeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerTypeMixin.java index 6c6151fe..9f0b2285 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerTypeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ContainerTypeMixin.java @@ -1,23 +1,23 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.container.LecternContainerBridge; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.LecternContainer; -import net.minecraft.util.registry.Registry; +import net.minecraft.core.Registry; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.LecternMenu; +import net.minecraft.world.inventory.MenuType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ContainerType.class) -public class ContainerTypeMixin { +@Mixin(MenuType.class) +public class ContainerTypeMixin { @Inject(method = "register", cancellable = true, at = @At("HEAD")) - private static void arclight$replaceLectern(String key, ContainerType.IFactory factory, CallbackInfoReturnable> cir) { + private static void arclight$replaceLectern(String key, MenuType.MenuSupplier factory, CallbackInfoReturnable> cir) { if (key.equals("lectern")) { - cir.setReturnValue(Registry.register(Registry.MENU, key, new ContainerType<>((i, inv) -> { - LecternContainer container = new LecternContainer(i); + cir.setReturnValue(Registry.register(Registry.MENU, key, new MenuType<>((i, inv) -> { + LecternMenu container = new LecternMenu(i); ((LecternContainerBridge) container).bridge$setPlayerInventory(inv); return (T) container; }))); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/DispenserContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/DispenserContainerMixin.java index 1f06b68d..5307c3ae 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/DispenserContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/DispenserContainerMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.DispenserContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.DispenserMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -16,23 +16,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(DispenserContainer.class) +@Mixin(DispenserMenu.class) public abstract class DispenserContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final public IInventory dispenserInventory; + @Shadow @Final public Container dispenser; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;)V", at = @At("RETURN")) - public void arclight$init(int p_i50088_1_, PlayerInventory playerInventory, IInventory p_i50088_3_, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;)V", at = @At("RETURN")) + public void arclight$init(int p_i50088_1_, Inventory playerInventory, Container p_i50088_3_, CallbackInfo ci) { this.playerInventory = playerInventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -42,8 +42,8 @@ public abstract class DispenserContainerMixin extends ContainerMixin { return bukkitEntity; } - CraftInventory inventory = new CraftInventory(this.dispenserInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventory inventory = new CraftInventory(this.dispenser); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainer1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainer1Mixin.java index fd7b22ea..7adc8122 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainer1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainer1Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.inventory.container.EnchantmentContainer; +import net.minecraft.world.inventory.EnchantmentMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/EnchantmentContainer$1") +@Mixin(targets = "net/minecraft/world/inventory/EnchantmentMenu$1") public abstract class EnchantmentContainer1Mixin extends InventoryMixin { - @Shadow(aliases = {"this$0", "field_70484_a"}, remap = false) private EnchantmentContainer outerThis; + @Shadow(aliases = {"this$0", "field_70484_a"}, remap = false) private EnchantmentMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainerMixin.java index 8e560034..c4db62ca 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/EnchantmentContainerMixin.java @@ -5,26 +5,25 @@ import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge; import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.enchantment.EnchantmentData; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.EnchantmentContainer; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.util.IWorldPosCallable; -import net.minecraft.util.IntReferenceHolder; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.World; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.DataSlot; +import net.minecraft.world.inventory.EnchantmentMenu; +import net.minecraft.world.item.EnchantedBookItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.EnchantmentInstance; +import net.minecraft.world.level.Level; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.Bukkit; @@ -51,31 +50,31 @@ import java.util.List; import java.util.Map; import java.util.Random; -@Mixin(EnchantmentContainer.class) +@Mixin(EnchantmentMenu.class) public abstract class EnchantmentContainerMixin extends ContainerMixin implements PosContainerBridge { // @formatter:off - @Shadow @Final private IInventory tableInventory; - @Shadow @Final private IWorldPosCallable worldPosCallable; - @Shadow(remap = false) protected abstract float getPower(World world, BlockPos pos); - @Shadow @Final private Random rand; - @Shadow @Final private IntReferenceHolder xpSeed; - @Shadow @Final public int[] enchantLevels; + @Shadow @Final private Container enchantSlots; + @Shadow @Final private ContainerLevelAccess access; + @Shadow(remap = false) protected abstract float getPower(Level world, BlockPos pos); + @Shadow @Final private Random random; + @Shadow @Final private DataSlot enchantmentSeed; + @Shadow @Final public int[] costs; @Shadow @Final public int[] enchantClue; - @Shadow @Final public int[] worldClue; - @Shadow protected abstract List getEnchantmentList(ItemStack stack, int enchantSlot, int level); + @Shadow @Final public int[] levelClue; + @Shadow protected abstract List getEnchantmentList(ItemStack stack, int enchantSlot, int level); // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IWorldPosCallable worldPosCallable, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, ContainerLevelAccess worldPosCallable, CallbackInfo ci) { this.playerInventory = playerInventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(net.minecraft.world.entity.player.Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -84,48 +83,48 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement * @reason */ @Overwrite - public void onCraftMatrixChanged(IInventory inventoryIn) { - if (inventoryIn == this.tableInventory) { - ItemStack itemstack = inventoryIn.getStackInSlot(0); + public void slotsChanged(Container inventoryIn) { + if (inventoryIn == this.enchantSlots) { + ItemStack itemstack = inventoryIn.getItem(0); if (!itemstack.isEmpty()) { - this.worldPosCallable.consume((p_217002_2_, p_217002_3_) -> { + this.access.execute((p_217002_2_, p_217002_3_) -> { float power = 0; for (int k = -1; k <= 1; ++k) { for (int l = -1; l <= 1; ++l) { - if ((k != 0 || l != 0) && p_217002_2_.isAirBlock(p_217002_3_.add(l, 0, k)) && p_217002_2_.isAirBlock(p_217002_3_.add(l, 1, k))) { - power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 0, k * 2)); - power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 1, k * 2)); + if ((k != 0 || l != 0) && p_217002_2_.isEmptyBlock(p_217002_3_.offset(l, 0, k)) && p_217002_2_.isEmptyBlock(p_217002_3_.offset(l, 1, k))) { + power += getPower(p_217002_2_, p_217002_3_.offset(l * 2, 0, k * 2)); + power += getPower(p_217002_2_, p_217002_3_.offset(l * 2, 1, k * 2)); if (l != 0 && k != 0) { - power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 0, k)); - power += getPower(p_217002_2_, p_217002_3_.add(l * 2, 1, k)); - power += getPower(p_217002_2_, p_217002_3_.add(l, 0, k * 2)); - power += getPower(p_217002_2_, p_217002_3_.add(l, 1, k * 2)); + power += getPower(p_217002_2_, p_217002_3_.offset(l * 2, 0, k)); + power += getPower(p_217002_2_, p_217002_3_.offset(l * 2, 1, k)); + power += getPower(p_217002_2_, p_217002_3_.offset(l, 0, k * 2)); + power += getPower(p_217002_2_, p_217002_3_.offset(l, 1, k * 2)); } } } } - this.rand.setSeed(this.xpSeed.get()); + this.random.setSeed(this.enchantmentSeed.get()); for (int i1 = 0; i1 < 3; ++i1) { - this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, (int) power, itemstack); + this.costs[i1] = EnchantmentHelper.getEnchantmentCost(this.random, i1, (int) power, itemstack); this.enchantClue[i1] = -1; - this.worldClue[i1] = -1; - if (this.enchantLevels[i1] < i1 + 1) { - this.enchantLevels[i1] = 0; + this.levelClue[i1] = -1; + if (this.costs[i1] < i1 + 1) { + this.costs[i1] = 0; } - this.enchantLevels[i1] = ForgeEventFactory.onEnchantmentLevelSet(p_217002_2_, p_217002_3_, i1, (int) power, itemstack, enchantLevels[i1]); + this.costs[i1] = ForgeEventFactory.onEnchantmentLevelSet(p_217002_2_, p_217002_3_, i1, (int) power, itemstack, costs[i1]); } for (int j1 = 0; j1 < 3; ++j1) { - if (this.enchantLevels[j1] > 0) { - List list = this.getEnchantmentList(itemstack, j1, this.enchantLevels[j1]); + if (this.costs[j1] > 0) { + List list = this.getEnchantmentList(itemstack, j1, this.costs[j1]); if (list != null && !list.isEmpty()) { - EnchantmentData enchantmentdata = list.get(this.rand.nextInt(list.size())); + EnchantmentInstance enchantmentdata = list.get(this.random.nextInt(list.size())); this.enchantClue[j1] = Registry.ENCHANTMENT.getId(enchantmentdata.enchantment); - this.worldClue[j1] = enchantmentdata.enchantmentLevel; + this.levelClue[j1] = enchantmentdata.level; } } } @@ -134,19 +133,19 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement CraftItemStack item = CraftItemStack.asCraftMirror(itemstack); org.bukkit.enchantments.EnchantmentOffer[] offers = new EnchantmentOffer[3]; for (int j = 0; j < 3; ++j) { - org.bukkit.enchantments.Enchantment enchantment = (this.enchantClue[j] >= 0) ? org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(Registry.ENCHANTMENT.getByValue(this.enchantClue[j])))) : null; - offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.worldClue[j], this.enchantLevels[j]) : null; + org.bukkit.enchantments.Enchantment enchantment = (this.enchantClue[j] >= 0) ? org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(Registry.ENCHANTMENT.byId(this.enchantClue[j])))) : null; + offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.levelClue[j], this.costs[j]) : null; } - PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, offers, (int) power); + PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), this.getBukkitView(), ((IWorldPosCallableBridge) this.access).bridge$getLocation().getBlock(), item, offers, (int) power); event.setCancelled(!itemstack.isEnchantable()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { for (int j = 0; j < 3; ++j) { - this.enchantLevels[j] = 0; + this.costs[j] = 0; this.enchantClue[j] = -1; - this.worldClue[j] = -1; + this.levelClue[j] = -1; } return; } @@ -154,23 +153,23 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement for (int j = 0; j < 3; j++) { EnchantmentOffer offer = event.getOffers()[j]; if (offer != null) { - this.enchantLevels[j] = offer.getCost(); + this.costs[j] = offer.getCost(); this.enchantClue[j] = Registry.ENCHANTMENT.getId(ForgeRegistries.ENCHANTMENTS.getValue(CraftNamespacedKey.toMinecraft(offer.getEnchantment().getKey()))); - this.worldClue[j] = offer.getEnchantmentLevel(); + this.levelClue[j] = offer.getEnchantmentLevel(); } else { - this.enchantLevels[j] = 0; + this.costs[j] = 0; this.enchantClue[j] = -1; - this.worldClue[j] = -1; + this.levelClue[j] = -1; } } - this.detectAndSendChanges(); + this.broadcastChanges(); }); } else { for (int i = 0; i < 3; ++i) { - this.enchantLevels[i] = 0; + this.costs[i] = 0; this.enchantClue[i] = -1; - this.worldClue[i] = -1; + this.levelClue[i] = -1; } } } @@ -182,57 +181,57 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement * @reason */ @Overwrite - public boolean enchantItem(PlayerEntity playerIn, int id) { - ItemStack itemstack = this.tableInventory.getStackInSlot(0); - ItemStack itemstack1 = this.tableInventory.getStackInSlot(1); + public boolean clickMenuButton(net.minecraft.world.entity.player.Player playerIn, int id) { + ItemStack itemstack = this.enchantSlots.getItem(0); + ItemStack itemstack1 = this.enchantSlots.getItem(1); int i = id + 1; - if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.abilities.isCreativeMode) { + if ((itemstack1.isEmpty() || itemstack1.getCount() < i) && !playerIn.abilities.instabuild) { return false; - } else if (this.enchantLevels[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.enchantLevels[id]) && !playerIn.abilities.isCreativeMode) { + } else if (this.costs[id] <= 0 || itemstack.isEmpty() || (playerIn.experienceLevel < i || playerIn.experienceLevel < this.costs[id]) && !playerIn.abilities.instabuild) { return false; } else { - this.worldPosCallable.consume((p_217003_6_, p_217003_7_) -> { + this.access.execute((p_217003_6_, p_217003_7_) -> { ItemStack itemstack2 = itemstack; - List list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]); + List list = this.getEnchantmentList(itemstack, id, this.costs[id]); if (true || !list.isEmpty()) { // playerIn.onEnchant(itemstack, i); boolean flag = itemstack.getItem() == Items.BOOK; Map enchants = new java.util.HashMap<>(); - for (EnchantmentData obj : list) { - enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(obj.enchantment))), obj.enchantmentLevel); + for (EnchantmentInstance obj : list) { + enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(ForgeRegistries.ENCHANTMENTS.getKey(obj.enchantment))), obj.level); } CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2); - EnchantItemEvent event = new EnchantItemEvent(((Player) ((PlayerEntityBridge) playerIn).bridge$getBukkitEntity()), this.getBukkitView(), ((IWorldPosCallableBridge) this.worldPosCallable).bridge$getLocation().getBlock(), item, this.enchantLevels[id], enchants, id); + EnchantItemEvent event = new EnchantItemEvent(((Player) ((PlayerEntityBridge) playerIn).bridge$getBukkitEntity()), this.getBukkitView(), ((IWorldPosCallableBridge) this.access).bridge$getLocation().getBlock(), item, this.costs[id], enchants, id); Bukkit.getPluginManager().callEvent(event); int level = event.getExpLevelCost(); - if (event.isCancelled() || (level > playerIn.experienceLevel && !playerIn.abilities.isCreativeMode) || event.getEnchantsToAdd().isEmpty()) { + if (event.isCancelled() || (level > playerIn.experienceLevel && !playerIn.abilities.instabuild) || event.getEnchantsToAdd().isEmpty()) { return; } if (flag) { itemstack2 = new ItemStack(Items.ENCHANTED_BOOK); - CompoundNBT tag = itemstack2.getTag(); + CompoundTag tag = itemstack2.getTag(); if (tag != null) { itemstack2.setTag(tag.copy()); } - this.tableInventory.setInventorySlotContents(0, itemstack2); + this.enchantSlots.setItem(0, itemstack2); } for (Map.Entry entry : event.getEnchantsToAdd().entrySet()) { try { if (flag) { NamespacedKey enchantId = entry.getKey().getKey(); - net.minecraft.enchantment.Enchantment nms = ForgeRegistries.ENCHANTMENTS.getValue(CraftNamespacedKey.toMinecraft(enchantId)); + net.minecraft.world.item.enchantment.Enchantment nms = ForgeRegistries.ENCHANTMENTS.getValue(CraftNamespacedKey.toMinecraft(enchantId)); if (nms == null) { continue; } - EnchantmentData weightedrandomenchant = new EnchantmentData(nms, entry.getValue()); + EnchantmentInstance weightedrandomenchant = new EnchantmentInstance(nms, entry.getValue()); EnchantedBookItem.addEnchantment(itemstack2, weightedrandomenchant); } else { item.addUnsafeEnchantment(entry.getKey(), entry.getValue()); @@ -241,24 +240,24 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement /* Just swallow invalid enchantments */ } } - playerIn.onEnchant(itemstack, i); + playerIn.onEnchantmentPerformed(itemstack, i); - if (!playerIn.abilities.isCreativeMode) { + if (!playerIn.abilities.instabuild) { itemstack1.shrink(i); if (itemstack1.isEmpty()) { - this.tableInventory.setInventorySlotContents(1, ItemStack.EMPTY); + this.enchantSlots.setItem(1, ItemStack.EMPTY); } } - playerIn.addStat(Stats.ENCHANT_ITEM); - if (playerIn instanceof ServerPlayerEntity) { - CriteriaTriggers.ENCHANTED_ITEM.trigger((ServerPlayerEntity) playerIn, itemstack2, i); + playerIn.awardStat(Stats.ENCHANT_ITEM); + if (playerIn instanceof ServerPlayer) { + CriteriaTriggers.ENCHANTED_ITEM.trigger((ServerPlayer) playerIn, itemstack2, i); } - this.tableInventory.markDirty(); - this.xpSeed.set(playerIn.getXPSeed()); - this.onCraftMatrixChanged(this.tableInventory); - p_217003_6_.playSound(null, p_217003_7_, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, p_217003_6_.rand.nextFloat() * 0.1F + 0.9F); + this.enchantSlots.setChanged(); + this.enchantmentSeed.set(playerIn.getEnchantmentSeed()); + this.slotsChanged(this.enchantSlots); + p_217003_6_.playSound(null, p_217003_7_, SoundEvents.ENCHANTMENT_TABLE_USE, SoundSource.BLOCKS, 1.0F, p_217003_6_.random.nextFloat() * 0.1F + 0.9F); } }); @@ -272,13 +271,13 @@ public abstract class EnchantmentContainerMixin extends ContainerMixin implement return bukkitEntity; } - CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.tableInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.enchantSlots); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public IWorldPosCallable bridge$getWorldPos() { - return this.worldPosCallable; + public ContainerLevelAccess bridge$getWorldPos() { + return this.access; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/FurnaceResultSlotMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/FurnaceResultSlotMixin.java index 6825e504..c87d37a3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/FurnaceResultSlotMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/FurnaceResultSlotMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.inventory.container; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.FurnaceResultSlot; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.AbstractFurnaceTileEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import io.izzel.arclight.common.bridge.tileentity.AbstractFurnaceTileEntityBridge; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.FurnaceResultSlot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; @Mixin(FurnaceResultSlot.class) public class FurnaceResultSlotMixin { @@ -17,8 +17,8 @@ public class FurnaceResultSlotMixin { @Shadow private int removeCount; // @formatter:on - @Redirect(method = "onCrafting(Lnet/minecraft/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/AbstractFurnaceTileEntity;unlockRecipes(Lnet/minecraft/entity/player/PlayerEntity;)V")) - public void arclight$furnaceDropExp(AbstractFurnaceTileEntity furnace, PlayerEntity playerEntity, ItemStack stack) { - ((AbstractFurnaceTileEntityBridge) furnace).bridge$dropExp(playerEntity.world, playerEntity.getPositionVec(), playerEntity, stack, this.removeCount); + @Redirect(method = "checkTakeAchievements(Lnet/minecraft/world/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;awardUsedRecipesAndPopExperience(Lnet/minecraft/world/entity/player/Player;)V")) + public void arclight$furnaceDropExp(AbstractFurnaceBlockEntity furnace, Player playerEntity, ItemStack stack) { + ((AbstractFurnaceTileEntityBridge) furnace).bridge$dropExp(playerEntity.level, playerEntity.position(), playerEntity, stack, this.removeCount); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainer1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainer1Mixin.java index c430dd0a..2b88f7b2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainer1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainer1Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.inventory.container.GrindstoneContainer; +import net.minecraft.world.inventory.GrindstoneMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/GrindstoneContainer$1") +@Mixin(targets = "net/minecraft/world/inventory/GrindstoneMenu$1") public abstract class GrindstoneContainer1Mixin extends InventoryMixin { - @Shadow(aliases = {"this$0", "field_213912_a"}, remap = false) private GrindstoneContainer outerThis; + @Shadow(aliases = {"this$0", "field_213912_a"}, remap = false) private GrindstoneMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainerMixin.java index 1aae0a79..10e53f2b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/GrindstoneContainerMixin.java @@ -2,11 +2,11 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.GrindstoneContainer; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.GrindstoneMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventoryGrindstone; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -16,17 +16,17 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(GrindstoneContainer.class) +@Mixin(GrindstoneMenu.class) public abstract class GrindstoneContainerMixin extends ContainerMixin implements PosContainerBridge { - @Shadow @Final private IInventory inputInventory; - @Shadow @Final private IInventory outputInventory; - @Shadow @Final private IWorldPosCallable worldPosCallable; + @Shadow @Final private Container repairSlots; + @Shadow @Final private Container resultSlots; + @Shadow @Final private ContainerLevelAccess access; private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int windowIdIn, PlayerInventory playerInventory, IWorldPosCallable worldPosCallableIn, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int windowIdIn, Inventory playerInventory, ContainerLevelAccess worldPosCallableIn, CallbackInfo ci) { this.playerInventory = playerInventory; } @@ -36,13 +36,13 @@ public abstract class GrindstoneContainerMixin extends ContainerMixin implements return bukkitEntity; } - CraftInventoryGrindstone inventory = new CraftInventoryGrindstone(this.inputInventory, this.outputInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryGrindstone inventory = new CraftInventoryGrindstone(this.repairSlots, this.resultSlots); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public IWorldPosCallable bridge$getWorldPos() { - return this.worldPosCallable; + public ContainerLevelAccess bridge$getWorldPos() { + return this.access; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HopperContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HopperContainerMixin.java index 5463fd73..4d4407dc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HopperContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HopperContainerMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.HopperContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.HopperMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -16,23 +16,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(HopperContainer.class) +@Mixin(HopperMenu.class) public abstract class HopperContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory hopperInventory; + @Shadow @Final private Container hopper; // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IInventory inventory, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, Container inventory, CallbackInfo ci) { this.playerInventory = playerInventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -41,8 +41,8 @@ public abstract class HopperContainerMixin extends ContainerMixin { if (bukkitEntity != null) { return bukkitEntity; } - CraftInventory inventory = new CraftInventory(this.hopperInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventory inventory = new CraftInventory(this.hopper); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HorseInventoryContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HorseInventoryContainerMixin.java index 1d5a48a3..4979acda 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HorseInventoryContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/HorseInventoryContainerMixin.java @@ -2,11 +2,11 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.passive.horse.AbstractHorseEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.HorseInventoryContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.animal.horse.AbstractHorse; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.HorseInventoryMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -15,18 +15,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(HorseInventoryContainer.class) +@Mixin(HorseInventoryMenu.class) public abstract class HorseInventoryContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory horseInventory; + @Shadow @Final private Container horseContainer; // @formatter:on CraftInventoryView bukkitEntity; - PlayerInventory playerInventory; + Inventory playerInventory; @Inject(method = "", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IInventory horseInventory, AbstractHorseEntity horse, CallbackInfo ci) { + public void arclight$init(int id, Inventory playerInventory, Container horseInventory, AbstractHorse horse, CallbackInfo ci) { this.playerInventory = playerInventory; } @@ -36,6 +36,6 @@ public abstract class HorseInventoryContainerMixin extends ContainerMixin { return bukkitEntity; } return bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) playerInventory.player).bridge$getBukkitEntity(), - ((IInventoryBridge) this.horseInventory).getOwner().getInventory(), (Container) (Object) this); + ((IInventoryBridge) this.horseContainer).getOwner().getInventory(), (AbstractContainerMenu) (Object) this); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LecternContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LecternContainerMixin.java index f930d3ae..bc3ab437 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LecternContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LecternContainerMixin.java @@ -2,12 +2,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.LecternContainerBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.LecternContainer; -import net.minecraft.util.IIntArray; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.LecternMenu; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftInventoryLectern; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; @@ -19,36 +19,36 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(LecternContainer.class) +@Mixin(LecternMenu.class) public abstract class LecternContainerMixin extends ContainerMixin implements LecternContainerBridge { // @formatter:off - @Shadow @Final private IInventory lecternInventory; + @Shadow @Final private Container lectern; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; public void arclight$constructor(int i) { throw new RuntimeException(); } - public void arclight$constructor(int i, IInventory inventory, IIntArray intArray) { + public void arclight$constructor(int i, Container inventory, ContainerData intArray) { throw new RuntimeException(); } - public void arclight$constructor(int i, PlayerInventory playerInventory) { + public void arclight$constructor(int i, Inventory playerInventory) { arclight$constructor(i); this.playerInventory = playerInventory; } - public void arclight$constructor(int i, IInventory inventory, IIntArray intArray, PlayerInventory playerInventory) { + public void arclight$constructor(int i, Container inventory, ContainerData intArray, Inventory playerInventory) { arclight$constructor(i, inventory, intArray); this.playerInventory = playerInventory; } - @Inject(method = "enchantItem", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/IInventory;removeStackFromSlot(I)Lnet/minecraft/item/ItemStack;")) - public void arclight$takeBook(PlayerEntity playerIn, int id, CallbackInfoReturnable cir) { + @Inject(method = "clickMenuButton", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;removeItemNoUpdate(I)Lnet/minecraft/world/item/ItemStack;")) + public void arclight$takeBook(Player playerIn, int id, CallbackInfoReturnable cir) { PlayerTakeLecternBookEvent event = new PlayerTakeLecternBookEvent(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), ((CraftInventoryLectern) getBukkitView().getTopInventory()).getHolder()); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -56,8 +56,8 @@ public abstract class LecternContainerMixin extends ContainerMixin implements Le } } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } @@ -66,13 +66,13 @@ public abstract class LecternContainerMixin extends ContainerMixin implements Le if (bukkitEntity != null) { return bukkitEntity; } - CraftInventoryLectern inventory = new CraftInventoryLectern(this.lecternInventory); - bukkitEntity = new CraftInventoryView(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryLectern inventory = new CraftInventoryLectern(this.lectern); + bukkitEntity = new CraftInventoryView(((ServerPlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public void bridge$setPlayerInventory(PlayerInventory playerInventory) { + public void bridge$setPlayerInventory(Inventory playerInventory) { this.playerInventory = playerInventory; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer1Mixin.java index 187781fd..2bca216d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer1Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.inventory.container.LoomContainer; +import net.minecraft.world.inventory.LoomMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/LoomContainer$1") +@Mixin(targets = "net/minecraft/world/inventory/LoomMenu$1") public abstract class LoomContainer1Mixin extends InventoryMixin { - @Shadow(aliases = {"this$0", "field_213913_a"}, remap = false) private LoomContainer outerThis; + @Shadow(aliases = {"this$0", "field_213913_a"}, remap = false) private LoomMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer2Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer2Mixin.java index 64d0dcb1..fa8b9e7f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer2Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainer2Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.inventory.container.LoomContainer; +import net.minecraft.world.inventory.LoomMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/LoomContainer$2") +@Mixin(targets = "net/minecraft/world/inventory/LoomMenu$2") public abstract class LoomContainer2Mixin extends InventoryMixin { - @Shadow(aliases = {"this$0", "field_213914_a"}, remap = false) private LoomContainer outerThis; + @Shadow(aliases = {"this$0", "field_213914_a"}, remap = false) private LoomMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainerMixin.java index 220000c8..d730f2ce 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/LoomContainerMixin.java @@ -2,12 +2,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.LoomContainer; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.LoomMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventoryLoom; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -18,25 +18,25 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(LoomContainer.class) +@Mixin(LoomMenu.class) public abstract class LoomContainerMixin extends ContainerMixin implements PosContainerBridge { // @formatter:off - @Shadow @Final private IInventory inputInventory; - @Shadow @Final private IInventory outputInventory; - @Shadow @Final private IWorldPosCallable worldPos; + @Shadow @Final private Container inputContainer; + @Shadow @Final private Container outputContainer; + @Shadow @Final private ContainerLevelAccess access; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IWorldPosCallable worldCallable, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, ContainerLevelAccess worldCallable, CallbackInfo ci) { this.playerInventory = playerInventory; } - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) { cir.setReturnValue(true); } @@ -48,13 +48,13 @@ public abstract class LoomContainerMixin extends ContainerMixin implements PosCo return bukkitEntity; } - CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputInventory, this.outputInventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryLoom inventory = new CraftInventoryLoom(this.inputContainer, this.outputContainer); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public IWorldPosCallable bridge$getWorldPos() { - return this.worldPos; + public ContainerLevelAccess bridge$getWorldPos() { + return this.access; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/MerchantContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/MerchantContainerMixin.java index b4f0453b..8c8f3ebb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/MerchantContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/MerchantContainerMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.merchant.IMerchant; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.MerchantInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.MerchantContainer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MerchantContainer; +import net.minecraft.world.inventory.MerchantMenu; +import net.minecraft.world.item.trading.Merchant; import org.bukkit.craftbukkit.v.inventory.CraftInventoryMerchant; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -16,25 +16,25 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(MerchantContainer.class) +@Mixin(MerchantMenu.class) public abstract class MerchantContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IMerchant merchant; - @Shadow @Final private MerchantInventory merchantInventory; + @Shadow @Final private Merchant trader; + @Shadow @Final private MerchantContainer tradeContainer; // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/entity/merchant/IMerchant;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventoryIn, IMerchant merchantIn, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/item/trading/Merchant;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventoryIn, Merchant merchantIn, CallbackInfo ci) { this.playerInventory = playerInventoryIn; } - @Inject(method = "playMerchantYesSound", cancellable = true, at = @At("HEAD")) + @Inject(method = "playTradeSound", cancellable = true, at = @At("HEAD")) public void arclight$returnIfFail(CallbackInfo ci) { - if (!(this.merchant instanceof Entity)) { + if (!(this.trader instanceof Entity)) { ci.cancel(); } } @@ -42,7 +42,7 @@ public abstract class MerchantContainerMixin extends ContainerMixin { @Override public CraftInventoryView getBukkitView() { if (bukkitEntity == null) { - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventoryMerchant(this.merchant, this.merchantInventory), (Container) (Object) this); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventoryMerchant(this.trader, this.tradeContainer), (AbstractContainerMenu) (Object) this); } return bukkitEntity; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/PlayerContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/PlayerContainerMixin.java index 69a7e3b2..a947bc72 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/PlayerContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/PlayerContainerMixin.java @@ -3,14 +3,14 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.PlayerContainer; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.ResultContainer; import org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -20,28 +20,28 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(PlayerContainer.class) +@Mixin(InventoryMenu.class) public abstract class PlayerContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private CraftingInventory craftMatrix; - @Shadow @Final private CraftResultInventory craftResult; + @Shadow @Final private CraftingContainer craftSlots; + @Shadow @Final private ResultContainer resultSlots; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; @Inject(method = "", at = @At("RETURN")) - public void arclight$init(PlayerInventory playerInventory, boolean localWorld, PlayerEntity playerIn, CallbackInfo ci) { + public void arclight$init(Inventory playerInventory, boolean localWorld, Player playerIn, CallbackInfo ci) { this.playerInventory = playerInventory; - ((CraftingInventoryBridge) this.craftMatrix).bridge$setOwner(playerInventory.player); - ((CraftingInventoryBridge) this.craftMatrix).bridge$setResultInventory(this.craftResult); - this.setTitle(new TranslationTextComponent("container.crafting")); + ((CraftingInventoryBridge) this.craftSlots).bridge$setOwner(playerInventory.player); + ((CraftingInventoryBridge) this.craftSlots).bridge$setResultInventory(this.resultSlots); + this.setTitle(new TranslatableComponent("container.crafting")); } - @Inject(method = "onCraftMatrixChanged", at = @At("HEAD")) - public void arclight$captureContainer(IInventory inventoryIn, CallbackInfo ci) { - ArclightCaptures.captureWorkbenchContainer((Container) (Object) this); + @Inject(method = "slotsChanged", at = @At("HEAD")) + public void arclight$captureContainer(Container inventoryIn, CallbackInfo ci) { + ArclightCaptures.captureWorkbenchContainer((AbstractContainerMenu) (Object) this); } @Override @@ -50,8 +50,8 @@ public abstract class PlayerContainerMixin extends ContainerMixin { return bukkitEntity; } - CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/RepairContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/RepairContainerMixin.java index 33bb602c..f0899a09 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/RepairContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/RepairContainerMixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.RepairContainer; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.IntReferenceHolder; -import net.minecraft.util.text.StringTextComponent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.world.inventory.DataSlot; +import net.minecraft.world.item.EnchantedBookItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraftforge.common.ForgeHooks; import org.apache.commons.lang3.StringUtils; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -24,14 +24,14 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.Map; -@Mixin(RepairContainer.class) +@Mixin(AnvilMenu.class) public abstract class RepairContainerMixin extends AbstractRepairContainerMixin { // @formatter:off - @Shadow @Final public IntReferenceHolder maximumCost; - @Shadow public int materialCost; - @Shadow public String repairedItemName; - @Shadow public static int getNewRepairCost(int oldRepairCost) { return 0; } + @Shadow @Final public DataSlot cost; + @Shadow public int repairItemCountCost; + @Shadow public String itemName; + @Shadow public static int calculateIncreasedRepairCost(int oldRepairCost) { return 0; } // @formatter:on public int maximumRepairCost = 40; @@ -42,57 +42,57 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin * @reason */ @Overwrite - public void updateRepairOutput() { - ItemStack itemstack = this.field_234643_d_.getStackInSlot(0); - this.maximumCost.set(1); + public void createResult() { + ItemStack itemstack = this.inputSlots.getItem(0); + this.cost.set(1); int i = 0; int j = 0; int k = 0; if (itemstack.isEmpty()) { // this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY); CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); - this.maximumCost.set(0); + this.cost.set(0); } else { ItemStack itemstack1 = itemstack.copy(); - ItemStack itemstack2 = this.field_234643_d_.getStackInSlot(1); + ItemStack itemstack2 = this.inputSlots.getItem(1); Map map = EnchantmentHelper.getEnchantments(itemstack1); - j = j + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost()); - this.materialCost = 0; + j = j + itemstack.getBaseRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getBaseRepairCost()); + this.repairItemCountCost = 0; boolean flag = false; if (!itemstack2.isEmpty()) { - if (!ForgeHooks.onAnvilChange((RepairContainer) (Object) this, itemstack, itemstack2, field_234642_c_, repairedItemName, j, this.field_234645_f_)) + if (!ForgeHooks.onAnvilChange((AnvilMenu) (Object) this, itemstack, itemstack2, resultSlots, itemName, j, this.player)) return; flag = itemstack2.getItem() == Items.ENCHANTED_BOOK && !EnchantedBookItem.getEnchantments(itemstack2).isEmpty(); - if (itemstack1.isDamageable() && itemstack1.getItem().getIsRepairable(itemstack, itemstack2)) { - int l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4); + if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) { + int l2 = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); if (l2 <= 0) { // this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY); CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); - this.maximumCost.set(0); + this.cost.set(0); return; } int i3; for (i3 = 0; l2 > 0 && i3 < itemstack2.getCount(); ++i3) { - int j3 = itemstack1.getDamage() - l2; - itemstack1.setDamage(j3); + int j3 = itemstack1.getDamageValue() - l2; + itemstack1.setDamageValue(j3); ++i; - l2 = Math.min(itemstack1.getDamage(), itemstack1.getMaxDamage() / 4); + l2 = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); } - this.materialCost = i3; + this.repairItemCountCost = i3; } else { - if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.isDamageable())) { + if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.isDamageableItem())) { // this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY); CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); - this.maximumCost.set(0); + this.cost.set(0); return; } - if (itemstack1.isDamageable() && !flag) { - int l = itemstack.getMaxDamage() - itemstack.getDamage(); - int i1 = itemstack2.getMaxDamage() - itemstack2.getDamage(); + if (itemstack1.isDamageableItem() && !flag) { + int l = itemstack.getMaxDamage() - itemstack.getDamageValue(); + int i1 = itemstack2.getMaxDamage() - itemstack2.getDamageValue(); int j1 = i1 + itemstack1.getMaxDamage() * 12 / 100; int k1 = l + j1; int l1 = itemstack1.getMaxDamage() - k1; @@ -100,8 +100,8 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin l1 = 0; } - if (l1 < itemstack1.getDamage()) { - itemstack1.setDamage(l1); + if (l1 < itemstack1.getDamageValue()) { + itemstack1.setDamageValue(l1); i += 2; } } @@ -115,8 +115,8 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin int i2 = map.getOrDefault(enchantment1, 0); int j2 = map1.get(enchantment1); j2 = i2 == j2 ? j2 + 1 : Math.max(j2, i2); - boolean flag1 = enchantment1.canApply(itemstack); - if (this.field_234645_f_.abilities.isCreativeMode || itemstack.getItem() == Items.ENCHANTED_BOOK) { + boolean flag1 = enchantment1.canEnchant(itemstack); + if (this.player.abilities.instabuild || itemstack.getItem() == Items.ENCHANTED_BOOK) { flag1 = true; } @@ -166,46 +166,46 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin if (flag3 && !flag2) { // this.outputSlot.setInventorySlotContents(0, ItemStack.EMPTY); CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); - this.maximumCost.set(0); + this.cost.set(0); return; } } } - if (StringUtils.isBlank(this.repairedItemName)) { - if (itemstack.hasDisplayName()) { + if (StringUtils.isBlank(this.itemName)) { + if (itemstack.hasCustomHoverName()) { k = 1; i += k; - itemstack1.clearCustomName(); + itemstack1.resetHoverName(); } - } else if (!this.repairedItemName.equals(itemstack.getDisplayName().getString())) { + } else if (!this.itemName.equals(itemstack.getHoverName().getString())) { k = 1; i += k; - itemstack1.setDisplayName(new StringTextComponent(this.repairedItemName)); + itemstack1.setHoverName(new TextComponent(this.itemName)); } if (flag && !itemstack1.isBookEnchantable(itemstack2)) itemstack1 = ItemStack.EMPTY; - this.maximumCost.set(j + i); + this.cost.set(j + i); if (i <= 0) { itemstack1 = ItemStack.EMPTY; } - if (k == i && k > 0 && this.maximumCost.get() >= maximumRepairCost) { - this.maximumCost.set(maximumRepairCost - 1); + if (k == i && k > 0 && this.cost.get() >= maximumRepairCost) { + this.cost.set(maximumRepairCost - 1); } - if (this.maximumCost.get() >= maximumRepairCost && !this.field_234645_f_.abilities.isCreativeMode) { + if (this.cost.get() >= maximumRepairCost && !this.player.abilities.instabuild) { itemstack1 = ItemStack.EMPTY; } if (!itemstack1.isEmpty()) { - int k2 = itemstack1.getRepairCost(); - if (!itemstack2.isEmpty() && k2 < itemstack2.getRepairCost()) { - k2 = itemstack2.getRepairCost(); + int k2 = itemstack1.getBaseRepairCost(); + if (!itemstack2.isEmpty() && k2 < itemstack2.getBaseRepairCost()) { + k2 = itemstack2.getBaseRepairCost(); } if (k != i || k == 0) { - k2 = getNewRepairCost(k2); + k2 = calculateIncreasedRepairCost(k2); } itemstack1.setRepairCost(k2); @@ -214,7 +214,7 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin // this.outputSlot.setInventorySlotContents(0, itemstack1); CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); - this.detectAndSendChanges(); + this.broadcastChanges(); } } @@ -225,8 +225,8 @@ public abstract class RepairContainerMixin extends AbstractRepairContainerMixin } CraftInventory inventory = new CraftInventoryAnvil( - ((IWorldPosCallableBridge) this.field_234644_e_).bridge$getLocation(), this.field_234643_d_, this.field_234642_c_, (RepairContainer) (Object) this); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.field_234645_f_).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + ((IWorldPosCallableBridge) this.access).bridge$getLocation(), this.inputSlots, this.resultSlots, (AnvilMenu) (Object) this); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ShulkerBoxContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ShulkerBoxContainerMixin.java index 84445f22..6f9f3a58 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ShulkerBoxContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/ShulkerBoxContainerMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ShulkerBoxContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ShulkerBoxMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -14,18 +14,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ShulkerBoxContainer.class) +@Mixin(ShulkerBoxMenu.class) public abstract class ShulkerBoxContainerMixin extends ContainerMixin { // @formatter:off - @Shadow @Final private IInventory inventory; + @Shadow @Final private Container container; // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/IInventory;)V", at = @At("RETURN")) - public void arclight$init(int id, PlayerInventory playerInventory, IInventory inventory, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;)V", at = @At("RETURN")) + public void arclight$init(int id, Inventory playerInventory, Container inventory, CallbackInfo ci) { this.playerInventory = playerInventory; } @@ -35,7 +35,7 @@ public abstract class ShulkerBoxContainerMixin extends ContainerMixin { return bukkitEntity; } - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventory(this.inventory), (Container) (Object) this); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), new CraftInventory(this.container), (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SlotMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SlotMixin.java index c532eb3f..4e893e82 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SlotMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SlotMixin.java @@ -1,7 +1,7 @@ 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 net.minecraft.world.inventory.Slot; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SmithingTableContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SmithingTableContainerMixin.java index 368de2bc..10cd39ab 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SmithingTableContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/SmithingTableContainerMixin.java @@ -2,9 +2,9 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.container.SmithingTableContainer; -import net.minecraft.item.ItemStack; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.inventory.SmithingMenu; +import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftInventory; import org.bukkit.craftbukkit.v.inventory.CraftInventorySmithing; @@ -13,13 +13,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(SmithingTableContainer.class) +@Mixin(SmithingMenu.class) public abstract class SmithingTableContainerMixin extends AbstractRepairContainerMixin { private CraftInventoryView bukkitEntity; - @Redirect(method = "updateRepairOutput", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/CraftResultInventory;setInventorySlotContents(ILnet/minecraft/item/ItemStack;)V")) - private void arclight$prepareSmithing(CraftResultInventory craftResultInventory, int index, ItemStack stack) { + @Redirect(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V")) + private void arclight$prepareSmithing(ResultContainer craftResultInventory, int index, ItemStack stack) { CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), stack); } @@ -28,7 +28,7 @@ public abstract class SmithingTableContainerMixin extends AbstractRepairContaine if (this.bukkitEntity != null) { return this.bukkitEntity; } - CraftInventory inventory = new CraftInventorySmithing(((IWorldPosCallableBridge) this.field_234644_e_).bridge$getLocation(), this.field_234643_d_, this.field_234642_c_); - return this.bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.field_234645_f_).bridge$getBukkitEntity(), inventory, (SmithingTableContainer) (Object) this); + CraftInventory inventory = new CraftInventorySmithing(((IWorldPosCallableBridge) this.access).bridge$getLocation(), this.inputSlots, this.resultSlots); + return this.bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.player).bridge$getBukkitEntity(), inventory, (SmithingMenu) (Object) this); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainer1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainer1Mixin.java index 1d3cac1a..31b5cb2e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainer1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainer1Mixin.java @@ -2,15 +2,15 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.inventory.container.StonecutterContainer; +import net.minecraft.world.inventory.StonecutterMenu; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/inventory/container/StonecutterContainer$1") +@Mixin(targets = "net/minecraft/world/inventory/StonecutterMenu$1") public abstract class StonecutterContainer1Mixin implements IInventoryBridge { - @Shadow(aliases = {"this$0", "field_213915_a"}, remap = false) private StonecutterContainer outerThis; + @Shadow(aliases = {"this$0", "field_213915_a"}, remap = false) private StonecutterMenu outerThis; @Override public Location getLocation() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainerMixin.java index 8ed07a2e..1e42cae2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/StonecutterContainerMixin.java @@ -2,12 +2,12 @@ package io.izzel.arclight.common.mixin.core.inventory.container; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.StonecutterContainer; -import net.minecraft.util.IWorldPosCallable; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.inventory.StonecutterMenu; import org.bukkit.craftbukkit.v.inventory.CraftInventoryStonecutter; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; import org.spongepowered.asm.mixin.Final; @@ -17,20 +17,20 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(StonecutterContainer.class) +@Mixin(StonecutterMenu.class) public abstract class StonecutterContainerMixin extends ContainerMixin implements PosContainerBridge { // @formatter:off - @Shadow @Final public IInventory inputInventory; - @Shadow @Final private CraftResultInventory inventory; - @Shadow @Final private IWorldPosCallable worldPosCallable; + @Shadow @Final public Container container; + @Shadow @Final private ResultContainer resultContainer; + @Shadow @Final private ContainerLevelAccess access; // @formatter:on private CraftInventoryView bukkitEntity = null; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/util/IWorldPosCallable;)V", at = @At("RETURN")) - public void arclight$init(int windowIdIn, PlayerInventory playerInventoryIn, IWorldPosCallable worldPosCallableIn, CallbackInfo ci) { + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int windowIdIn, Inventory playerInventoryIn, ContainerLevelAccess worldPosCallableIn, CallbackInfo ci) { this.playerInventory = playerInventoryIn; } @@ -40,13 +40,13 @@ public abstract class StonecutterContainerMixin extends ContainerMixin implement return bukkitEntity; } - CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.inputInventory, this.inventory); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.container, this.resultContainer); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } @Override - public IWorldPosCallable bridge$getWorldPos() { - return this.worldPosCallable; + public ContainerLevelAccess bridge$getWorldPos() { + return this.access; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/WorkbenchContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/WorkbenchContainerMixin.java index c9d6d77d..83c9295b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/WorkbenchContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/inventory/container/WorkbenchContainerMixin.java @@ -5,20 +5,6 @@ import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge; import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; import io.izzel.arclight.common.bridge.inventory.container.PosContainerBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.WorkbenchContainer; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.ICraftingRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.network.play.server.SSetSlotPacket; -import net.minecraft.util.IWorldPosCallable; -import net.minecraft.world.World; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.v.inventory.CraftInventoryView; @@ -34,33 +20,47 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.inventory.CraftingMenu; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.CraftingRecipe; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; // todo 实现 -@Mixin(WorkbenchContainer.class) +@Mixin(CraftingMenu.class) public abstract class WorkbenchContainerMixin extends ContainerMixin implements PosContainerBridge { // @formatter:off - @Mutable @Shadow @Final private CraftingInventory craftMatrix; - @Shadow @Final private CraftResultInventory craftResult; - @Accessor("worldPosCallable") public abstract IWorldPosCallable bridge$getWorldPos(); + @Mutable @Shadow @Final private CraftingContainer craftSlots; + @Shadow @Final private ResultContainer resultSlots; + @Accessor("access") public abstract ContainerLevelAccess bridge$getWorldPos(); // @formatter:on private CraftInventoryView bukkitEntity; - private PlayerInventory playerInventory; + private Inventory playerInventory; - @Inject(method = "canInteractWith", cancellable = true, at = @At("HEAD")) - public void arclight$unreachable(PlayerEntity playerIn, CallbackInfoReturnable cir) { + @Inject(method = "stillValid", cancellable = true, at = @At("HEAD")) + public void arclight$unreachable(Player playerIn, CallbackInfoReturnable cir) { if (!bridge$isCheckReachable()) cir.setReturnValue(true); } - private static void a(int id, World world, PlayerEntity player, CraftingInventory inventory, CraftResultInventory inventoryResult, Container container) { + private static void a(int id, Level world, Player player, CraftingContainer inventory, ResultContainer inventoryResult, AbstractContainerMenu container) { ArclightCaptures.captureWorkbenchContainer(container); - updateCraftingResult(id, world, player, inventory, inventoryResult); + slotChangedCraftingGrid(id, world, player, inventory, inventoryResult); } - @Inject(method = "onCraftMatrixChanged", at = @At("HEAD")) - public void arclight$capture(IInventory inventoryIn, CallbackInfo ci) { - ArclightCaptures.captureWorkbenchContainer((WorkbenchContainer) (Object) this); + @Inject(method = "slotsChanged", at = @At("HEAD")) + public void arclight$capture(Container inventoryIn, CallbackInfo ci) { + ArclightCaptures.captureWorkbenchContainer((CraftingMenu) (Object) this); } /** @@ -68,30 +68,30 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements * @reason */ @Overwrite - public static void updateCraftingResult(int i, World world, PlayerEntity playerEntity, CraftingInventory inventory, CraftResultInventory resultInventory) { - Container container = ArclightCaptures.getWorkbenchContainer(); - if (!world.isRemote) { - ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) playerEntity; + public static void slotChangedCraftingGrid(int i, Level world, Player playerEntity, CraftingContainer inventory, ResultContainer resultInventory) { + AbstractContainerMenu container = ArclightCaptures.getWorkbenchContainer(); + if (!world.isClientSide) { + ServerPlayer serverplayerentity = (ServerPlayer) playerEntity; ItemStack itemstack = ItemStack.EMPTY; - Optional optional = world.getServer().getRecipeManager().getRecipe(IRecipeType.CRAFTING, inventory, world); + Optional optional = world.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventory, world); if (optional.isPresent()) { - ICraftingRecipe icraftingrecipe = optional.get(); - if (resultInventory.canUseRecipe(world, serverplayerentity, icraftingrecipe)) { - itemstack = icraftingrecipe.getCraftingResult(inventory); + CraftingRecipe icraftingrecipe = optional.get(); + if (resultInventory.setRecipeUsed(world, serverplayerentity, icraftingrecipe)) { + itemstack = icraftingrecipe.assemble(inventory); } } itemstack = CraftEventFactory.callPreCraftEvent(inventory, resultInventory, itemstack, ((ContainerBridge) container).bridge$getBukkitView(), false); - resultInventory.setInventorySlotContents(0, itemstack); - serverplayerentity.connection.sendPacket(new SSetSlotPacket(i, 0, itemstack)); + resultInventory.setItem(0, itemstack); + serverplayerentity.connection.send(new ClientboundContainerSetSlotPacket(i, 0, itemstack)); } } - @Inject(method = "(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) { - ((CraftingInventoryBridge) this.craftMatrix).bridge$setOwner(playerInventory.player); - ((CraftingInventoryBridge) this.craftMatrix).bridge$setResultInventory(this.craftResult); + @Inject(method = "(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("RETURN")) + public void arclight$init(int i, Inventory playerInventory, ContainerLevelAccess callable, CallbackInfo ci) { + ((CraftingInventoryBridge) this.craftSlots).bridge$setOwner(playerInventory.player); + ((CraftingInventoryBridge) this.craftSlots).bridge$setResultInventory(this.resultSlots); this.playerInventory = playerInventory; } @@ -101,8 +101,8 @@ public abstract class WorkbenchContainerMixin extends ContainerMixin implements return bukkitEntity; } - CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult); - bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this); + CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); + bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (AbstractContainerMenu) (Object) this); return bukkitEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ArmorStandItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ArmorStandItemMixin.java index 1d7cff52..ba8c142d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ArmorStandItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ArmorStandItemMixin.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.entity.item.ArmorStandEntity; -import net.minecraft.item.ArmorStandItem; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.item.ArmorStandItem; +import net.minecraft.world.item.context.UseOnContext; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,18 +14,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ArmorStandItem.class) public class ArmorStandItemMixin { - private transient ArmorStandEntity arclight$entity; + private transient ArmorStand arclight$entity; - @Redirect(method = "onItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ArmorStandEntity;setLocationAndAngles(DDDFF)V")) - public void arclight$captureEntity(ArmorStandEntity armorStandEntity, double x, double y, double z, float yaw, float pitch) { - armorStandEntity.setLocationAndAngles(x, y, z, yaw, pitch); + @Redirect(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;moveTo(DDDFF)V")) + public void arclight$captureEntity(ArmorStand armorStandEntity, double x, double y, double z, float yaw, float pitch) { + armorStandEntity.moveTo(x, y, z, yaw, pitch); arclight$entity = armorStandEntity; } - @Inject(method = "onItemUse", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public void arclight$entityPlace(ItemUseContext context, CallbackInfoReturnable cir) { + @Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public void arclight$entityPlace(UseOnContext context, CallbackInfoReturnable cir) { if (CraftEventFactory.callEntityPlaceEvent(context, arclight$entity).isCancelled()) { - cir.setReturnValue(ActionResultType.FAIL); + cir.setReturnValue(InteractionResult.FAIL); } arclight$entity = null; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BlockItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BlockItemMixin.java index 3b905cbe..d9ead635 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BlockItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BlockItemMixin.java @@ -1,19 +1,18 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.LilyPadItem; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.state.Property; -import net.minecraft.state.StateContainer; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.WaterLilyBlockItem; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.phys.shapes.CollisionContext; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlockState; @@ -33,47 +32,47 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public abstract class BlockItemMixin { // @formatter:off - @Shadow protected abstract boolean checkPosition(); - @Shadow private static > BlockState func_219988_a(BlockState p_219988_0_, Property p_219988_1_, String p_219988_2_) { return null; } + @Shadow protected abstract boolean mustSurvive(); + @Shadow private static > BlockState updateState(BlockState p_219988_0_, Property p_219988_1_, String p_219988_2_) { return null; } // @formatter:on private transient org.bukkit.block.BlockState arclight$state; - @Inject(method = "tryPlace", locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/item/BlockItem;getStateForPlacement(Lnet/minecraft/item/BlockItemUseContext;)Lnet/minecraft/block/BlockState;")) - private void arclight$prePlaceLilypad(BlockItemUseContext context, CallbackInfoReturnable cir, BlockItemUseContext context1) { - if ((Object) this instanceof LilyPadItem) { - this.arclight$state = CraftBlockState.getBlockState(context1.getWorld(), context1.getPos()); + @Inject(method = "place", locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/item/BlockItem;getPlacementState(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/level/block/state/BlockState;")) + private void arclight$prePlaceLilypad(BlockPlaceContext context, CallbackInfoReturnable cir, BlockPlaceContext context1) { + if ((Object) this instanceof WaterLilyBlockItem) { + this.arclight$state = CraftBlockState.getBlockState(context1.getLevel(), context1.getClickedPos()); } } - @Inject(method = "tryPlace", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, - at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/block/Block;onBlockPlacedBy(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;)V")) - private void arclight$postPlaceLilypad(BlockItemUseContext context, CallbackInfoReturnable cir, BlockItemUseContext context1) { + @Inject(method = "place", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, + at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/block/Block;setPlacedBy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;)V")) + private void arclight$postPlaceLilypad(BlockPlaceContext context, CallbackInfoReturnable cir, BlockPlaceContext context1) { org.bukkit.block.BlockState state = arclight$state; arclight$state = null; - BlockPos pos = context1.getPos(); + BlockPos pos = context1.getClickedPos(); if (state != null) { - org.bukkit.event.block.BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent((ServerWorld) context1.getWorld(), context1.getPlayer(), context1.getHand(), state, pos.getX(), pos.getY(), pos.getZ()); + org.bukkit.event.block.BlockPlaceEvent placeEvent = CraftEventFactory.callBlockPlaceEvent((ServerLevel) context1.getLevel(), context1.getPlayer(), context1.getHand(), state, pos.getX(), pos.getY(), pos.getZ()); if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) { state.update(true, false); - cir.setReturnValue(ActionResultType.FAIL); + cir.setReturnValue(InteractionResult.FAIL); } } } - @Inject(method = "tryPlace", at = @At("RETURN")) - private void arclight$cleanup(BlockItemUseContext context, CallbackInfoReturnable cir) { + @Inject(method = "place", at = @At("RETURN")) + private void arclight$cleanup(BlockPlaceContext context, CallbackInfoReturnable cir) { this.arclight$state = null; } - private static BlockState getBlockState(BlockState blockState, CompoundNBT nbt) { - StateContainer statecontainer = blockState.getBlock().getStateContainer(); - for (String s : nbt.keySet()) { + private static BlockState getBlockState(BlockState blockState, CompoundTag nbt) { + StateDefinition statecontainer = blockState.getBlock().getStateDefinition(); + for (String s : nbt.getAllKeys()) { Property iproperty = statecontainer.getProperty(s); if (iproperty != null) { - String s1 = nbt.get(s).getString(); - blockState = func_219988_a(blockState, iproperty, s1); + String s1 = nbt.get(s).getAsString(); + blockState = updateState(blockState, iproperty, s1); } } return blockState; @@ -84,13 +83,13 @@ public abstract class BlockItemMixin { * @reason */ @Overwrite - protected boolean canPlace(BlockItemUseContext context, BlockState state) { - PlayerEntity playerentity = context.getPlayer(); - ISelectionContext iselectioncontext = playerentity == null ? ISelectionContext.dummy() : ISelectionContext.forEntity(playerentity); - boolean original = (!this.checkPosition() || state.isValidPosition(context.getWorld(), context.getPos())) && context.getWorld().placedBlockCollides(state, context.getPos(), iselectioncontext); + protected boolean canPlace(BlockPlaceContext context, BlockState state) { + net.minecraft.world.entity.player.Player playerentity = context.getPlayer(); + CollisionContext iselectioncontext = playerentity == null ? CollisionContext.empty() : CollisionContext.of(playerentity); + boolean original = (!this.mustSurvive() || state.canSurvive(context.getLevel(), context.getClickedPos())) && context.getLevel().isUnobstructed(state, context.getClickedPos(), iselectioncontext); Player player = (context.getPlayer() instanceof ServerPlayerEntityBridge) ? ((ServerPlayerEntityBridge) context.getPlayer()).bridge$getBukkitEntity() : null; - BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(context.getWorld(), context.getPos()), player, CraftBlockData.fromData(state), original); + BlockCanBuildEvent event = new BlockCanBuildEvent(CraftBlock.at(context.getLevel(), context.getClickedPos()), player, CraftBlockData.fromData(state), original); Bukkit.getPluginManager().callEvent(event); return event.isBuildable(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BoatItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BoatItemMixin.java index dab8e11d..e33d4b8d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BoatItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BoatItemMixin.java @@ -1,21 +1,21 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.BoatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BoatItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.stats.Stats; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceContext; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.vehicle.Boat; +import net.minecraft.world.item.BoatItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; @@ -32,8 +32,8 @@ import java.util.function.Predicate; public class BoatItemMixin extends Item { // @formatter:off - @Shadow @Final private static Predicate field_219989_a; - @Shadow @Final private BoatEntity.Type type; + @Shadow @Final private static Predicate ENTITY_PREDICATE; + @Shadow @Final private Boat.Type type; // @formatter:on public BoatItemMixin(Properties properties) { @@ -45,57 +45,57 @@ public class BoatItemMixin extends Item { * @reason */ @Overwrite - public @NotNull ActionResult onItemRightClick(@NotNull World worldIn, PlayerEntity playerIn, @NotNull Hand handIn) { - ItemStack itemstack = playerIn.getHeldItem(handIn); - BlockRayTraceResult result = rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.ANY); - if (result.getType() == RayTraceResult.Type.MISS) { - return new ActionResult<>(ActionResultType.PASS, itemstack); + public @NotNull InteractionResultHolder use(@NotNull Level worldIn, Player playerIn, @NotNull InteractionHand handIn) { + ItemStack itemstack = playerIn.getItemInHand(handIn); + BlockHitResult result = getPlayerPOVHitResult(worldIn, playerIn, ClipContext.Fluid.ANY); + if (result.getType() == HitResult.Type.MISS) { + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } else { - Vector3d vec3d = playerIn.getLook(1.0F); + Vec3 vec3d = playerIn.getViewVector(1.0F); double d0 = 5.0D; - List list = worldIn.getEntitiesInAABBexcluding(playerIn, playerIn.getBoundingBox().expand(vec3d.scale(5.0D)).grow(1.0D), field_219989_a); + List list = worldIn.getEntities(playerIn, playerIn.getBoundingBox().expandTowards(vec3d.scale(5.0D)).inflate(1.0D), ENTITY_PREDICATE); if (!list.isEmpty()) { - Vector3d vec3d1 = playerIn.getEyePosition(1.0F); + Vec3 vec3d1 = playerIn.getEyePosition(1.0F); for (Entity entity : list) { - AxisAlignedBB axisalignedbb = entity.getBoundingBox().grow(entity.getCollisionBorderSize()); + AABB axisalignedbb = entity.getBoundingBox().inflate(entity.getPickRadius()); if (axisalignedbb.contains(vec3d1)) { - return new ActionResult<>(ActionResultType.PASS, itemstack); + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } } } - if (result.getType() == RayTraceResult.Type.BLOCK) { - PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, result.getPos(), result.getFace(), itemstack, handIn); + if (result.getType() == HitResult.Type.BLOCK) { + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, result.getBlockPos(), result.getDirection(), itemstack, handIn); if (event.isCancelled()) { - return new ActionResult<>(ActionResultType.PASS, itemstack); + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } - BoatEntity boatentity = new BoatEntity(worldIn, result.getHitVec().x, result.getHitVec().y, result.getHitVec().z); - boatentity.setBoatType(this.type); - boatentity.rotationYaw = playerIn.rotationYaw; - if (!worldIn.hasNoCollisions(boatentity, boatentity.getBoundingBox().grow(-0.1D))) { - return new ActionResult<>(ActionResultType.FAIL, itemstack); + Boat boatentity = new Boat(worldIn, result.getLocation().x, result.getLocation().y, result.getLocation().z); + boatentity.setType(this.type); + boatentity.yRot = playerIn.yRot; + if (!worldIn.noCollision(boatentity, boatentity.getBoundingBox().inflate(-0.1D))) { + return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack); } else { - if (!worldIn.isRemote) { - if (CraftEventFactory.callEntityPlaceEvent(worldIn, result.getPos(), result.getFace(), playerIn, boatentity).isCancelled()) { - return new ActionResult<>(ActionResultType.FAIL, itemstack); + if (!worldIn.isClientSide) { + if (CraftEventFactory.callEntityPlaceEvent(worldIn, result.getBlockPos(), result.getDirection(), playerIn, boatentity).isCancelled()) { + return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack); } - if (!worldIn.addEntity(boatentity)) { - return new ActionResult<>(ActionResultType.PASS, itemstack); + if (!worldIn.addFreshEntity(boatentity)) { + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } - if (!playerIn.abilities.isCreativeMode) { + if (!playerIn.abilities.instabuild) { itemstack.shrink(1); } } - playerIn.addStat(Stats.ITEM_USED.get(this)); - return ActionResult.func_233538_a_(itemstack, worldIn.isRemote()); + playerIn.awardStat(Stats.ITEM_USED.get(this)); + return InteractionResultHolder.sidedSuccess(itemstack, worldIn.isClientSide()); } } else { - return new ActionResult<>(ActionResultType.PASS, itemstack); + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BowItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BowItemMixin.java index 330efe5f..f5d7e1f3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BowItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BowItemMixin.java @@ -2,20 +2,20 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.AbstractArrowEntity; -import net.minecraft.item.ArrowItem; -import net.minecraft.item.BowItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.ShootableItem; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.World; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.item.ArrowItem; +import net.minecraft.world.item.BowItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.ProjectileWeaponItem; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.Level; import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityShootBowEvent; @@ -24,7 +24,7 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @Mixin(BowItem.class) -public abstract class BowItemMixin extends ShootableItem { +public abstract class BowItemMixin extends ProjectileWeaponItem { public BowItemMixin(Properties builder) { super(builder); @@ -32,8 +32,8 @@ public abstract class BowItemMixin extends ShootableItem { // @formatter:off @Shadow public abstract int getUseDuration(ItemStack stack); - @Shadow public static float getArrowVelocity(int charge) { return 0; } - @Shadow(remap = false) public abstract AbstractArrowEntity customArrow(AbstractArrowEntity arrow); + @Shadow public static float getPowerForTime(int charge) { return 0; } + @Shadow(remap = false) public abstract AbstractArrow customArrow(AbstractArrow arrow); // @formatter:on /** @@ -41,11 +41,11 @@ public abstract class BowItemMixin extends ShootableItem { * @reason */ @Overwrite - public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) { - if (entityLiving instanceof PlayerEntity) { - PlayerEntity playerentity = (PlayerEntity) entityLiving; - boolean flag = playerentity.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0; - ItemStack itemstack = playerentity.findAmmo(stack); + public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) { + if (entityLiving instanceof Player) { + Player playerentity = (Player) entityLiving; + boolean flag = playerentity.abilities.instabuild || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0; + ItemStack itemstack = playerentity.getProjectile(stack); int i = this.getUseDuration(stack) - timeLeft; i = ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag); @@ -56,48 +56,48 @@ public abstract class BowItemMixin extends ShootableItem { itemstack = new ItemStack(Items.ARROW); } - float f = getArrowVelocity(i); + float f = getPowerForTime(i); if (!((double) f < 0.1D)) { - boolean flag1 = playerentity.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity)); - if (!worldIn.isRemote) { + boolean flag1 = playerentity.abilities.instabuild || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity)); + if (!worldIn.isClientSide) { ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW); - AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity); + AbstractArrow abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity); abstractarrowentity = customArrow(abstractarrowentity); - abstractarrowentity.setDirectionAndMovement(playerentity, playerentity.rotationPitch, playerentity.rotationYaw, 0.0F, f * 3.0F, 1.0F); + abstractarrowentity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, f * 3.0F, 1.0F); if (f == 1.0F) { - abstractarrowentity.setIsCritical(true); + abstractarrowentity.setCritArrow(true); } - int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); + int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack); if (j > 0) { - abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D); + abstractarrowentity.setBaseDamage(abstractarrowentity.getBaseDamage() + (double) j * 0.5D + 0.5D); } - int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); + int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack); if (k > 0) { - abstractarrowentity.setKnockbackStrength(k); + abstractarrowentity.setKnockback(k); } - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) { - abstractarrowentity.setFire(100); + if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) { + abstractarrowentity.setSecondsOnFire(100); } - EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(playerentity, stack, itemstack, abstractarrowentity, playerentity.getActiveHand(), f, !flag1); + EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(playerentity, stack, itemstack, abstractarrowentity, playerentity.getUsedItemHand(), f, !flag1); if (event.isCancelled()) { event.getProjectile().remove(); return; } flag1 = !event.shouldConsumeItem(); - stack.damageItem(1, playerentity, (player) -> { - player.sendBreakAnimation(playerentity.getActiveHand()); + stack.hurtAndBreak(1, playerentity, (player) -> { + player.broadcastBreakEvent(playerentity.getUsedItemHand()); }); - if (flag1 || playerentity.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) { - abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY; + if (flag1 || playerentity.abilities.instabuild && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) { + abstractarrowentity.pickup = AbstractArrow.Pickup.CREATIVE_ONLY; } if (event.getProjectile() == ((EntityBridge) abstractarrowentity).bridge$getBukkitEntity()) { - if (!worldIn.addEntity(abstractarrowentity)) { + if (!worldIn.addFreshEntity(abstractarrowentity)) { if (playerentity instanceof ServerPlayerEntityBridge) { ((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity().updateInventory(); } @@ -106,15 +106,15 @@ public abstract class BowItemMixin extends ShootableItem { } } - worldIn.playSound(null, playerentity.getPosX(), playerentity.getPosY(), playerentity.getPosZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F); - if (!flag1 && !playerentity.abilities.isCreativeMode) { + worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundSource.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F); + if (!flag1 && !playerentity.abilities.instabuild) { itemstack.shrink(1); if (itemstack.isEmpty()) { - playerentity.inventory.deleteStack(itemstack); + playerentity.inventory.removeItem(itemstack); } } - playerentity.addStat(Stats.ITEM_USED.get(this)); + playerentity.awardStat(Stats.ITEM_USED.get(this)); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BucketItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BucketItemMixin.java index d1902495..fd037238 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BucketItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/BucketItemMixin.java @@ -1,23 +1,23 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.IBucketPickupHandler; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.BucketItem; -import net.minecraft.item.ItemStack; -import net.minecraft.network.play.server.SChangeBlockPacket; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BucketItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess; @@ -36,34 +36,34 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public abstract class BucketItemMixin { // @formatter:off - @Shadow public abstract boolean tryPlaceContainedLiquid(@javax.annotation.Nullable PlayerEntity player, World worldIn, BlockPos posIn, @javax.annotation.Nullable BlockRayTraceResult rayTrace); + @Shadow public abstract boolean emptyBucket(@javax.annotation.Nullable Player player, Level worldIn, BlockPos posIn, @javax.annotation.Nullable BlockHitResult rayTrace); // @formatter:on - @Inject(method = "onItemRightClick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/IBucketPickupHandler;pickupFluid(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/Fluid;")) - private void arclight$bucketFill(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable> cir, ItemStack stack, RayTraceResult result) { - BlockPos pos = ((BlockRayTraceResult) result).getPos(); + @Inject(method = "use", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BucketPickup;takeLiquid(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/level/material/Fluid;")) + private void arclight$bucketFill(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable> cir, ItemStack stack, HitResult result) { + BlockPos pos = ((BlockHitResult) result).getBlockPos(); BlockState state = worldIn.getBlockState(pos); - Fluid dummyFluid = ((IBucketPickupHandler) state.getBlock()).pickupFluid(DummyGeneratorAccess.INSTANCE, pos, state); - PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerWorld) worldIn, playerIn, pos, pos, ((BlockRayTraceResult) result).getFace(), stack, dummyFluid.getFilledBucket()); + Fluid dummyFluid = ((BucketPickup) state.getBlock()).takeLiquid(DummyGeneratorAccess.INSTANCE, pos, state); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) worldIn, playerIn, pos, pos, ((BlockHitResult) result).getDirection(), stack, dummyFluid.getBucket()); if (event.isCancelled()) { - ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(worldIn, pos)); + ((ServerPlayer) playerIn).connection.send(new ClientboundBlockUpdatePacket(worldIn, pos)); ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory(); - cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, stack)); + cir.setReturnValue(new InteractionResultHolder<>(InteractionResult.FAIL, stack)); } else { arclight$captureItem = event.getItemStack(); } } - @Inject(method = "onItemRightClick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BucketItem;tryPlaceContainedLiquid(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockRayTraceResult;)Z")) - private void arclight$capture(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable> cir, ItemStack stack, RayTraceResult result) { - BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result; - arclight$direction = blockRayTraceResult.getFace(); - arclight$click = blockRayTraceResult.getPos(); + @Inject(method = "use", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BucketItem;emptyBucket(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;)Z")) + private void arclight$capture(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable> cir, ItemStack stack, HitResult result) { + BlockHitResult blockRayTraceResult = (BlockHitResult) result; + arclight$direction = blockRayTraceResult.getDirection(); + arclight$click = blockRayTraceResult.getBlockPos(); arclight$stack = stack; } - @Inject(method = "onItemRightClick", at = @At("RETURN")) - private void arclight$clean(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable> cir) { + @Inject(method = "use", at = @At("RETURN")) + private void arclight$clean(Level worldIn, Player playerIn, InteractionHand handIn, CallbackInfoReturnable> cir) { arclight$captureItem = null; arclight$direction = null; arclight$click = null; @@ -77,12 +77,12 @@ public abstract class BucketItemMixin { return arclight$captureItem == null ? itemStack : CraftItemStack.asNMSCopy(arclight$captureItem); } - public boolean a(PlayerEntity entity, World world, BlockPos pos, @Nullable BlockRayTraceResult result, Direction direction, BlockPos clicked, ItemStack itemstack) { + public boolean a(Player entity, Level world, BlockPos pos, @Nullable BlockHitResult result, Direction direction, BlockPos clicked, ItemStack itemstack) { arclight$direction = direction; arclight$click = clicked; arclight$stack = itemstack; try { - return this.tryPlaceContainedLiquid(entity, world, pos, result); + return this.emptyBucket(entity, world, pos, result); } finally { arclight$direction = null; arclight$click = null; @@ -94,12 +94,12 @@ public abstract class BucketItemMixin { private transient BlockPos arclight$click; private transient ItemStack arclight$stack; - @Inject(method = "tryPlaceContainedLiquid", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/DimensionType;isUltrawarm()Z")) - private void arclight$bucketEmpty(PlayerEntity player, World worldIn, BlockPos posIn, BlockRayTraceResult rayTrace, CallbackInfoReturnable cir) { + @Inject(method = "emptyBucket", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/dimension/DimensionType;ultraWarm()Z")) + private void arclight$bucketEmpty(Player player, Level worldIn, BlockPos posIn, BlockHitResult rayTrace, CallbackInfoReturnable cir) { if (player != null) { - PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerWorld) worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack); + PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent((ServerLevel) worldIn, player, posIn, arclight$click, arclight$direction, arclight$stack); if (event.isCancelled()) { - ((ServerPlayerEntity) player).connection.sendPacket(new SChangeBlockPacket(worldIn, posIn)); + ((ServerPlayer) player).connection.send(new ClientboundBlockUpdatePacket(worldIn, posIn)); ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().updateInventory(); cir.setReturnValue(false); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ChorusFruitItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ChorusFruitItemMixin.java index 18712c48..d7b23706 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ChorusFruitItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ChorusFruitItemMixin.java @@ -1,18 +1,17 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.FoxEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ChorusFruitItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.item.ChorusFruitItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -33,19 +32,19 @@ public class ChorusFruitItemMixin extends Item { * @reason */ @Overwrite - public @NotNull ItemStack onItemUseFinish(@NotNull ItemStack stack, @NotNull World worldIn, @NotNull LivingEntity entityLiving) { - ItemStack itemstack = super.onItemUseFinish(stack, worldIn, entityLiving); - if (!worldIn.isRemote) { - double d0 = entityLiving.getPosX(); - double d1 = entityLiving.getPosY(); - double d2 = entityLiving.getPosZ(); + public @NotNull ItemStack finishUsingItem(@NotNull ItemStack stack, @NotNull Level worldIn, @NotNull LivingEntity entityLiving) { + ItemStack itemstack = super.finishUsingItem(stack, worldIn, entityLiving); + if (!worldIn.isClientSide) { + double d0 = entityLiving.getX(); + double d1 = entityLiving.getY(); + double d2 = entityLiving.getZ(); for (int i = 0; i < 16; ++i) { - double d3 = entityLiving.getPosX() + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D; - double d4 = MathHelper.clamp(entityLiving.getPosY() + (double) (entityLiving.getRNG().nextInt(16) - 8), 0.0D, worldIn.func_234938_ad_() - 1); - double d5 = entityLiving.getPosZ() + (entityLiving.getRNG().nextDouble() - 0.5D) * 16.0D; + double d3 = entityLiving.getX() + (entityLiving.getRandom().nextDouble() - 0.5D) * 16.0D; + double d4 = Mth.clamp(entityLiving.getY() + (double) (entityLiving.getRandom().nextInt(16) - 8), 0.0D, worldIn.getHeight() - 1); + double d5 = entityLiving.getZ() + (entityLiving.getRandom().nextDouble() - 0.5D) * 16.0D; - if (entityLiving instanceof ServerPlayerEntity) { + if (entityLiving instanceof ServerPlayer) { Player player = ((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity(); PlayerTeleportEvent event = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), d3, d4, d5), PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); Bukkit.getPluginManager().callEvent(event); @@ -61,16 +60,16 @@ public class ChorusFruitItemMixin extends Item { entityLiving.stopRiding(); } - if (entityLiving.attemptTeleport(d3, d4, d5, true)) { - SoundEvent soundevent = entityLiving instanceof FoxEntity ? SoundEvents.ENTITY_FOX_TELEPORT : SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT; - worldIn.playSound(null, d0, d1, d2, soundevent, SoundCategory.PLAYERS, 1.0F, 1.0F); + if (entityLiving.randomTeleport(d3, d4, d5, true)) { + SoundEvent soundevent = entityLiving instanceof Fox ? SoundEvents.FOX_TELEPORT : SoundEvents.CHORUS_FRUIT_TELEPORT; + worldIn.playSound(null, d0, d1, d2, soundevent, SoundSource.PLAYERS, 1.0F, 1.0F); entityLiving.playSound(soundevent, 1.0F, 1.0F); break; } } - if (entityLiving instanceof PlayerEntity) { - ((PlayerEntity) entityLiving).getCooldownTracker().setCooldown(this, 20); + if (entityLiving instanceof net.minecraft.world.entity.player.Player) { + ((net.minecraft.world.entity.player.Player) entityLiving).getCooldowns().addCooldown(this, 20); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/CrossbowItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/CrossbowItemMixin.java index e6fb1211..36a08f8b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/CrossbowItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/CrossbowItemMixin.java @@ -3,14 +3,14 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.item.CrossbowItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.world.World; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.CrossbowItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityShootBowEvent; import org.spongepowered.asm.mixin.Mixin; @@ -22,10 +22,10 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(CrossbowItem.class) public class CrossbowItemMixin { - @Inject(method = "fireProjectile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damageItem(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V")) - private static void arclight$entityShoot(World worldIn, LivingEntity shooter, Hand handIn, ItemStack crossbow, ItemStack projectile, float soundPitch, boolean isCreativeMode, float velocity, float inaccuracy, float projectileAngle, CallbackInfo ci, - boolean flag, ProjectileEntity proj) { - EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(shooter, crossbow, projectile, proj, shooter.getActiveHand(), soundPitch, true); + @Inject(method = "shootProjectile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V")) + private static void arclight$entityShoot(Level worldIn, LivingEntity shooter, InteractionHand handIn, ItemStack crossbow, ItemStack projectile, float soundPitch, boolean isCreativeMode, float velocity, float inaccuracy, float projectileAngle, CallbackInfo ci, + boolean flag, Projectile proj) { + EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent(shooter, crossbow, projectile, proj, shooter.getUsedItemHand(), soundPitch, true); if (event.isCancelled()) { event.getProjectile().remove(); ci.cancel(); @@ -36,10 +36,10 @@ public class CrossbowItemMixin { private static transient boolean arclight$capturedBoolean; @Eject(method = "fireProjectile", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private static boolean arclight$addEntity(World world, Entity entityIn, CallbackInfo ci, World worldIn, LivingEntity shooter) { + private static boolean arclight$addEntity(Level world, Entity entityIn, CallbackInfo ci, Level worldIn, LivingEntity shooter) { if (arclight$capturedBoolean) { - if (!world.addEntity(entityIn)) { - if (shooter instanceof ServerPlayerEntity) { + if (!world.addFreshEntity(entityIn)) { + if (shooter instanceof ServerPlayer) { ((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity().updateInventory(); } ci.cancel(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/DyeItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/DyeItemMixin.java index 0290bf96..bdd39337 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/DyeItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/DyeItemMixin.java @@ -2,13 +2,12 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.SheepEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.DyeColor; -import net.minecraft.item.DyeItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.DyeItem; +import net.minecraft.world.item.ItemStack; import org.bukkit.Bukkit; import org.bukkit.entity.Sheep; import org.bukkit.event.entity.SheepDyeWoolEvent; @@ -26,14 +25,14 @@ public class DyeItemMixin { // @formatter:on @Eject(method = "itemInteractionForEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setFleeceColor(Lnet/minecraft/item/DyeColor;)V")) - private void arclight$sheepDyeWool(SheepEntity sheepEntity, DyeColor color, CallbackInfoReturnable cir, ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) { + private void arclight$sheepDyeWool(net.minecraft.world.entity.animal.Sheep sheepEntity, DyeColor color, CallbackInfoReturnable cir, ItemStack stack, Player playerIn, LivingEntity target, InteractionHand hand) { byte bColor = (byte) this.dyeColor.getId(); SheepDyeWoolEvent event = new SheepDyeWoolEvent((Sheep) ((LivingEntityBridge) target).bridge$getBukkitEntity(), org.bukkit.DyeColor.getByWoolData(bColor)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { cir.setReturnValue(false); } else { - sheepEntity.setFleeceColor(DyeColor.byId(event.getColor().getWoolData())); + sheepEntity.setColor(DyeColor.byId(event.getColor().getWoolData())); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EggItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EggItemMixin.java index 8964e140..85c1d34a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EggItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EggItemMixin.java @@ -2,17 +2,17 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.EggItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.World; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.EggItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -26,20 +26,20 @@ public abstract class EggItemMixin extends Item { super(properties); } - @Redirect(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) - private void arclight$muteSound(World world, PlayerEntity player, double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch) { + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + private void arclight$muteSound(Level world, Player player, double x, double y, double z, SoundEvent soundIn, SoundSource category, float volume, float pitch) { } @Eject(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$updateIfFail(World world, Entity entityIn, CallbackInfoReturnable> cir, World worldIn, PlayerEntity playerIn, @NotNull Hand handIn) { - if (!worldIn.addEntity(entityIn)) { + private boolean arclight$updateIfFail(Level world, Entity entityIn, CallbackInfoReturnable> cir, Level worldIn, Player playerIn, @NotNull InteractionHand handIn) { + if (!worldIn.addFreshEntity(entityIn)) { if (playerIn instanceof ServerPlayerEntityBridge) { ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory(); } - cir.setReturnValue(ActionResult.resultFail(playerIn.getHeldItem(handIn))); + cir.setReturnValue(InteractionResultHolder.fail(playerIn.getItemInHand(handIn))); return false; } else { - worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); + worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); return true; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderCrystalItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderCrystalItemMixin.java index 9d727f78..d9e2b950 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderCrystalItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderCrystalItemMixin.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.entity.item.EnderCrystalEntity; -import net.minecraft.item.EnderCrystalItem; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; +import net.minecraft.world.item.EndCrystalItem; +import net.minecraft.world.item.context.UseOnContext; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,21 +11,21 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(EnderCrystalItem.class) +@Mixin(EndCrystalItem.class) public class EnderCrystalItemMixin { - @Redirect(method = "onItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/EnderCrystalEntity;setShowBottom(Z)V")) - public void arclight$captureEntity(EnderCrystalEntity enderCrystalEntity, boolean showBottom) { + @Redirect(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EndCrystal;setShowBottom(Z)V")) + public void arclight$captureEntity(EndCrystal enderCrystalEntity, boolean showBottom) { arclight$enderCrystalEntity = enderCrystalEntity; enderCrystalEntity.setShowBottom(showBottom); } - private transient EnderCrystalEntity arclight$enderCrystalEntity; + private transient EndCrystal arclight$enderCrystalEntity; - @Inject(method = "onItemUse", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public void arclight$entityPlace(ItemUseContext context, CallbackInfoReturnable cir) { + @Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public void arclight$entityPlace(UseOnContext context, CallbackInfoReturnable cir) { if (CraftEventFactory.callEntityPlaceEvent(context, arclight$enderCrystalEntity).isCancelled()) { - cir.setReturnValue(ActionResultType.FAIL); + cir.setReturnValue(InteractionResult.FAIL); } arclight$enderCrystalEntity = null; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderEyeItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderEyeItemMixin.java index ac431c66..fed0f3d0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderEyeItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderEyeItemMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.EnderEyeItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.EnderEyeItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -17,9 +17,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class EnderEyeItemMixin { @Eject(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$returnIfFail(World world, Entity entityIn, CallbackInfoReturnable> cir, World worldIn, PlayerEntity playerIn, Hand handIn) { - if (!world.addEntity(entityIn)) { - cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, playerIn.getHeldItem(handIn))); + private boolean arclight$returnIfFail(Level world, Entity entityIn, CallbackInfoReturnable> cir, Level worldIn, Player playerIn, InteractionHand handIn) { + if (!world.addFreshEntity(entityIn)) { + cir.setReturnValue(new InteractionResultHolder<>(InteractionResult.FAIL, playerIn.getItemInHand(handIn))); return false; } else { return true; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderPearlItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderPearlItemMixin.java index a33f6131..97b7eb3b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderPearlItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/EnderPearlItemMixin.java @@ -1,23 +1,23 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.item.EnderPearlEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.EnderPearlItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.ThrownEnderpearl; +import net.minecraft.world.item.EnderpearlItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; -@Mixin(EnderPearlItem.class) +@Mixin(EnderpearlItem.class) public class EnderPearlItemMixin extends Item { public EnderPearlItemMixin(Properties properties) { @@ -29,28 +29,28 @@ public class EnderPearlItemMixin extends Item { * @reason */ @Overwrite - public @NotNull ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, @NotNull Hand handIn) { - ItemStack itemstack = playerIn.getHeldItem(handIn); - if (!worldIn.isRemote) { - EnderPearlEntity enderpearlentity = new EnderPearlEntity(worldIn, playerIn); + public @NotNull InteractionResultHolder use(Level worldIn, Player playerIn, @NotNull InteractionHand handIn) { + ItemStack itemstack = playerIn.getItemInHand(handIn); + if (!worldIn.isClientSide) { + ThrownEnderpearl enderpearlentity = new ThrownEnderpearl(worldIn, playerIn); enderpearlentity.setItem(itemstack); - enderpearlentity.setDirectionAndMovement(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); - if (!worldIn.addEntity(enderpearlentity)) { + enderpearlentity.shootFromRotation(playerIn, playerIn.xRot, playerIn.yRot, 0.0F, 1.5F, 1.0F); + if (!worldIn.addFreshEntity(enderpearlentity)) { if (playerIn instanceof ServerPlayerEntityBridge) { ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory(); } - return new ActionResult<>(ActionResultType.FAIL, itemstack); + return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack); } } - worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); - playerIn.getCooldownTracker().setCooldown(this, 20); + worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.ENDER_PEARL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); + playerIn.getCooldowns().addCooldown(this, 20); - playerIn.addStat(Stats.ITEM_USED.get(this)); - if (!playerIn.abilities.isCreativeMode) { + playerIn.awardStat(Stats.ITEM_USED.get(this)); + if (!playerIn.abilities.instabuild) { itemstack.shrink(1); } - return ActionResult.func_233538_a_(itemstack, worldIn.isRemote()); + return InteractionResultHolder.sidedSuccess(itemstack, worldIn.isClientSide()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FilledMapItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FilledMapItemMixin.java index 8fba5ed0..f30fb983 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FilledMapItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FilledMapItemMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.world.storage.MapDataBridge; -import net.minecraft.item.FilledMapItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.MapData; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.MapItem; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; import org.bukkit.Bukkit; import org.bukkit.event.server.MapInitializeEvent; import org.spongepowered.asm.mixin.Mixin; @@ -19,17 +19,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(FilledMapItem.class) +@Mixin(MapItem.class) public abstract class FilledMapItemMixin { // @formatter:off - @Shadow private static MapData createMapData(ItemStack stack, World worldIn, int x, int z, int scale, boolean trackingPosition, boolean unlimitedTracking, RegistryKey dimensionTypeIn) { return null; } + @Shadow private static MapItemSavedData createAndStoreSavedData(ItemStack stack, Level worldIn, int x, int z, int scale, boolean trackingPosition, boolean unlimitedTracking, ResourceKey dimensionTypeIn) { return null; } // @formatter:on - @Inject(method = "createMapData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) - private static void arclight$mapInit(ItemStack stack, World worldIn, int x, int z, int scale, boolean trackingPosition, - boolean unlimitedTracking, RegistryKey dimensionTypeIn, CallbackInfoReturnable cir, - int i, MapData mapData) { + @Inject(method = "createAndStoreSavedData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) + private static void arclight$mapInit(ItemStack stack, Level worldIn, int x, int z, int scale, boolean trackingPosition, + boolean unlimitedTracking, ResourceKey dimensionTypeIn, CallbackInfoReturnable cir, + int i, MapItemSavedData mapData) { MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapData).bridge$getMapView()); Bukkit.getPluginManager().callEvent(event); } @@ -40,16 +40,16 @@ public abstract class FilledMapItemMixin { */ @Overwrite public static int getMapId(ItemStack stack) { - CompoundNBT compoundnbt = stack.getTag(); + CompoundTag compoundnbt = stack.getTag(); return compoundnbt != null && compoundnbt.contains("map", 99) ? compoundnbt.getInt("map") : -1; } - @Inject(method = "getMapData", cancellable = true, at = @At("HEAD")) - private static void arclight$nonFilledMap(ItemStack stack, World worldIn, CallbackInfoReturnable cir) { - if (stack != null && worldIn instanceof ServerWorld && stack.getItem() == Items.MAP) { - MapData mapdata = FilledMapItem.getData(stack, worldIn); + @Inject(method = "getOrCreateSavedData", cancellable = true, at = @At("HEAD")) + private static void arclight$nonFilledMap(ItemStack stack, Level worldIn, CallbackInfoReturnable cir) { + if (stack != null && worldIn instanceof ServerLevel && stack.getItem() == Items.MAP) { + MapItemSavedData mapdata = MapItem.getSavedData(stack, worldIn); if (mapdata == null) { - mapdata = createMapData(stack, worldIn, worldIn.getWorldInfo().getSpawnX(), worldIn.getWorldInfo().getSpawnZ(), 3, false, false, worldIn.getDimensionKey()); + mapdata = createAndStoreSavedData(stack, worldIn, worldIn.getLevelData().getXSpawn(), worldIn.getLevelData().getZSpawn(), 3, false, false, worldIn.dimension()); } cir.setReturnValue(mapdata); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FireChargeItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FireChargeItemMixin.java index c6389457..6bead674 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FireChargeItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FireChargeItemMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.item.FireChargeItem; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.FireChargeItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.block.BlockIgniteEvent; import org.spongepowered.asm.mixin.Mixin; @@ -16,14 +16,14 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(FireChargeItem.class) public class FireChargeItemMixin { - @Inject(method = "onItemUse", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/item/FireChargeItem;playUseSound(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$blockIgnite(ItemUseContext context, CallbackInfoReturnable cir, World world, BlockPos blockPos) { + @Inject(method = "useOn", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/FireChargeItem;playSound(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$blockIgnite(UseOnContext context, CallbackInfoReturnable cir, Level world, BlockPos blockPos) { if (CraftEventFactory.callBlockIgniteEvent(world, blockPos, BlockIgniteEvent.IgniteCause.FIREBALL, context.getPlayer()).isCancelled()) { - if (!context.getPlayer().abilities.isCreativeMode) { - context.getItem().shrink(1); + if (!context.getPlayer().abilities.instabuild) { + context.getItemInHand().shrink(1); } - cir.setReturnValue(ActionResultType.PASS); + cir.setReturnValue(InteractionResult.PASS); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FishingRodItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FishingRodItemMixin.java index 0d5c920b..176f8d42 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FishingRodItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FishingRodItemMixin.java @@ -2,19 +2,19 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.FishingBobberEntity; -import net.minecraft.item.FishingRodItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.FishingRodItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.entity.FishHook; import org.bukkit.event.player.PlayerFishEvent; @@ -33,39 +33,39 @@ public class FishingRodItemMixin extends Item { * @reason */ @Overwrite - public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { - ItemStack itemstack = playerIn.getHeldItem(handIn); - if (playerIn.fishingBobber != null) { - if (!worldIn.isRemote) { - int i = playerIn.fishingBobber.handleHookRetraction(itemstack); - itemstack.damageItem(i, playerIn, (player) -> { - player.sendBreakAnimation(handIn); + public InteractionResultHolder use(Level worldIn, Player playerIn, InteractionHand handIn) { + ItemStack itemstack = playerIn.getItemInHand(handIn); + if (playerIn.fishing != null) { + if (!worldIn.isClientSide) { + int i = playerIn.fishing.retrieve(itemstack); + itemstack.hurtAndBreak(i, playerIn, (player) -> { + player.broadcastBreakEvent(handIn); }); } - playerIn.swingArm(handIn); - worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_FISHING_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); + playerIn.swing(handIn); + worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_RETRIEVE, SoundSource.NEUTRAL, 1.0F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); } else { - if (!worldIn.isRemote) { + if (!worldIn.isClientSide) { int k = EnchantmentHelper.getFishingSpeedBonus(itemstack); int j = EnchantmentHelper.getFishingLuckBonus(itemstack); - FishingBobberEntity hook = new FishingBobberEntity(playerIn, worldIn, j, k); + FishingHook hook = new FishingHook(playerIn, worldIn, j, k); PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), null, (FishHook) ((EntityBridge) hook).bridge$getBukkitEntity(), PlayerFishEvent.State.FISHING); Bukkit.getPluginManager().callEvent(playerFishEvent); if (playerFishEvent.isCancelled()) { - playerIn.fishingBobber = null; - return new ActionResult<>(ActionResultType.PASS, itemstack); + playerIn.fishing = null; + return new InteractionResultHolder<>(InteractionResult.PASS, itemstack); } - worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); - worldIn.addEntity(new FishingBobberEntity(playerIn, worldIn, j, k)); + worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); + worldIn.addFreshEntity(new FishingHook(playerIn, worldIn, j, k)); } // playerIn.swingArm(handIn); - playerIn.addStat(Stats.ITEM_USED.get(this)); + playerIn.awardStat(Stats.ITEM_USED.get(this)); } - return ActionResult.func_233538_a_(itemstack, worldIn.isRemote()); + return InteractionResultHolder.sidedSuccess(itemstack, worldIn.isClientSide()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FlintAndSteelItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FlintAndSteelItemMixin.java index 5b7a64bc..88794499 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FlintAndSteelItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/FlintAndSteelItemMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FlintAndSteelItem; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.FlintAndSteelItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.block.BlockIgniteEvent; import org.spongepowered.asm.mixin.Mixin; @@ -16,17 +16,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(FlintAndSteelItem.class) public class FlintAndSteelItemMixin { - @Inject(method = "onItemUse", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) - public void arclight$blockIgnite(ItemUseContext context, CallbackInfoReturnable cir) { - PlayerEntity playerentity = context.getPlayer(); - World world = context.getWorld(); - BlockPos blockpos = context.getPos(); - BlockPos blockpos1 = blockpos.offset(context.getFace()); + @Inject(method = "useOn", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + public void arclight$blockIgnite(UseOnContext context, CallbackInfoReturnable cir) { + Player playerentity = context.getPlayer(); + Level world = context.getLevel(); + BlockPos blockpos = context.getClickedPos(); + BlockPos blockpos1 = blockpos.relative(context.getClickedFace()); if (CraftEventFactory.callBlockIgniteEvent(world, blockpos1, BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, playerentity).isCancelled()) { - context.getItem().damageItem(1, playerentity, (entity) -> { - entity.sendBreakAnimation(context.getHand()); + context.getItemInHand().hurtAndBreak(1, playerentity, (entity) -> { + entity.broadcastBreakEvent(context.getHand()); }); - cir.setReturnValue(ActionResultType.PASS); + cir.setReturnValue(InteractionResult.PASS); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/HangingEntityItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/HangingEntityItemMixin.java index 36fac346..60d87bd2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/HangingEntityItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/HangingEntityItemMixin.java @@ -2,15 +2,14 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.item.HangingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.HangingEntityItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.decoration.HangingEntity; +import net.minecraft.world.item.HangingEntityItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -27,9 +26,9 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(HangingEntityItem.class) public class HangingEntityItemMixin { - @Inject(method = "onItemUse", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;playPlaceSound()V")) - public void arclight$hangingPlace(ItemUseContext context, CallbackInfoReturnable cir, BlockPos blockPos, Direction direction, BlockPos blockPos1, PlayerEntity playerEntity, ItemStack itemStack, World world, HangingEntity hangingEntity) { + @Inject(method = "useOn", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/HangingEntity;playPlacementSound()V")) + public void arclight$hangingPlace(UseOnContext context, CallbackInfoReturnable cir, BlockPos blockPos, Direction direction, BlockPos blockPos1, net.minecraft.world.entity.player.Player playerEntity, ItemStack itemStack, Level world, HangingEntity hangingEntity) { Player who = (context.getPlayer() == null) ? null : (Player) ((PlayerEntityBridge) context.getPlayer()).bridge$getBukkitEntity(); Block blockClicked = CraftBlock.at(world, blockPos); BlockFace blockFace = CraftBlock.notchToBlockFace(direction); @@ -38,7 +37,7 @@ public class HangingEntityItemMixin { Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - cir.setReturnValue(ActionResultType.FAIL); + cir.setReturnValue(InteractionResult.FAIL); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ItemStackMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ItemStackMixin.java index b32037a3..342a94b7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ItemStackMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ItemStackMixin.java @@ -2,12 +2,12 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.item.ItemStackBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.CapabilityProvider; import net.minecraftforge.registries.IRegistryDelegate; import org.apache.logging.log4j.LogManager; @@ -35,7 +35,7 @@ public abstract class ItemStackMixin extends CapabilityProvider imple // @formatter:off @Shadow @Deprecated private Item item; @Shadow private int count; - @Shadow(remap = false) private CompoundNBT capNBT; + @Shadow(remap = false) private CompoundTag capNBT; @Mutable @Shadow(remap = false) @Final private IRegistryDelegate delegate; // @formatter:on @@ -44,12 +44,12 @@ public abstract class ItemStackMixin extends CapabilityProvider imple } @Override - public CompoundNBT bridge$getForgeCaps() { + public CompoundTag bridge$getForgeCaps() { return this.serializeCaps(); } @Override - public void bridge$setForgeCaps(CompoundNBT caps) { + public void bridge$setForgeCaps(CompoundTag caps) { this.capNBT = caps; if (caps != null) { this.deserializeCaps(caps); @@ -69,8 +69,8 @@ public abstract class ItemStackMixin extends CapabilityProvider imple this.convertStack(version); } - @ModifyVariable(method = "attemptDamageItem", index = 1, name = "amount", at = @At(value = "JUMP", opcode = Opcodes.IFGT, ordinal = 0)) - private int arclight$itemDamage(int i, int amount, Random rand, ServerPlayerEntity damager) { + @ModifyVariable(method = "hurt", index = 1, name = "amount", at = @At(value = "JUMP", opcode = Opcodes.IFGT, ordinal = 0)) + private int arclight$itemDamage(int i, int amount, Random rand, ServerPlayer damager) { if (damager != null) { PlayerItemDamageEvent event = new PlayerItemDamageEvent(((ServerPlayerEntityBridge) damager).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror((ItemStack) (Object) this), i); event.getPlayer().getServer().getPluginManager().callEvent(event); @@ -86,10 +86,10 @@ public abstract class ItemStackMixin extends CapabilityProvider imple return i; } - @Inject(method = "damageItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;shrink(I)V")) + @Inject(method = "hurtAndBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V")) private void arclight$itemBreak(int amount, T entityIn, Consumer onBroken, CallbackInfo ci) { - if (this.count == 1 && entityIn instanceof PlayerEntity) { - CraftEventFactory.callPlayerItemBreakEvent(((PlayerEntity) entityIn), (ItemStack) (Object) this); + if (this.count == 1 && entityIn instanceof Player) { + CraftEventFactory.callPlayerItemBreakEvent(((Player) entityIn), (ItemStack) (Object) this); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/LeadItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/LeadItemMixin.java index 305430fd..e4de9e22 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/LeadItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/LeadItemMixin.java @@ -2,14 +2,13 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.item.LeashKnotEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.LeadItem; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.decoration.LeashFenceKnotEntity; +import net.minecraft.world.item.LeadItem; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -28,34 +27,34 @@ public class LeadItemMixin { * @reason */ @Overwrite - public static ActionResultType bindPlayerMobs(PlayerEntity player, World worldIn, BlockPos fence) { - LeashKnotEntity leashknotentity = null; + public static InteractionResult bindPlayerMobs(net.minecraft.world.entity.player.Player player, Level worldIn, BlockPos fence) { + LeashFenceKnotEntity leashknotentity = null; boolean flag = false; double d0 = 7.0D; int i = fence.getX(); int j = fence.getY(); int k = fence.getZ(); - for (MobEntity mobentity : worldIn.getEntitiesWithinAABB(MobEntity.class, new AxisAlignedBB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) { + for (Mob mobentity : worldIn.getEntitiesOfClass(Mob.class, new AABB((double) i - 7.0D, (double) j - 7.0D, (double) k - 7.0D, (double) i + 7.0D, (double) j + 7.0D, (double) k + 7.0D))) { if (mobentity.getLeashHolder() == player) { if (leashknotentity == null) { - leashknotentity = LeashKnotEntity.create(worldIn, fence); + leashknotentity = LeashFenceKnotEntity.getOrCreateKnot(worldIn, fence); HangingPlaceEvent event = new HangingPlaceEvent((Hanging) ((EntityBridge) leashknotentity).bridge$getBukkitEntity(), player != null ? (Player) ((PlayerEntityBridge) player).bridge$getBukkitEntity() : null, CraftBlock.at(worldIn, fence), BlockFace.SELF); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { leashknotentity.remove(); - return ActionResultType.PASS; + return InteractionResult.PASS; } } if (CraftEventFactory.callPlayerLeashEntityEvent(mobentity, leashknotentity, player).isCancelled()) { continue; } - mobentity.setLeashHolder(leashknotentity, true); + mobentity.setLeashedTo(leashknotentity, true); flag = true; } } - return flag ? ActionResultType.SUCCESS : ActionResultType.PASS; + return flag ? InteractionResult.SUCCESS : InteractionResult.PASS; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MerchantOfferMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MerchantOfferMixin.java index e9d75d97..d0aa804b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MerchantOfferMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MerchantOfferMixin.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.item.MerchantOfferBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.MerchantOffer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.trading.MerchantOffer; import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class MerchantOfferMixin implements MerchantOfferBridge { // @formatter:off - @Shadow public ItemStack buyingStackFirst; + @Shadow public ItemStack baseCostA; // @formatter:on private CraftMerchantRecipe bukkitHandle; @@ -37,9 +37,9 @@ public class MerchantOfferMixin implements MerchantOfferBridge { return asBukkit(); } - @Inject(method = "getDiscountedBuyingStackFirst", cancellable = true, at = @At("HEAD")) + @Inject(method = "getCostA", cancellable = true, at = @At("HEAD")) private void arclight$fix(CallbackInfoReturnable cir) { - if (this.buyingStackFirst.getCount() <= 0) { + if (this.baseCostA.getCount() <= 0) { cir.setReturnValue(ItemStack.EMPTY); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MilkBucketItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MilkBucketItemMixin.java index 2dca0643..71c57b88 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MilkBucketItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MilkBucketItemMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.MilkBucketItem; -import net.minecraft.world.World; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.MilkBucketItem; +import net.minecraft.world.level.Level; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,8 +14,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(MilkBucketItem.class) public class MilkBucketItemMixin { - @Inject(method = "onItemUseFinish", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/LivingEntity;curePotionEffects(Lnet/minecraft/item/ItemStack;)Z")) - public void arclight$cureReason(ItemStack stack, World worldIn, LivingEntity entityLiving, CallbackInfoReturnable cir) { + @Inject(method = "finishUsingItem", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/entity/LivingEntity;curePotionEffects(Lnet/minecraft/world/item/ItemStack;)Z")) + public void arclight$cureReason(ItemStack stack, Level worldIn, LivingEntity entityLiving, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityLiving).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.MILK); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MinecartItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MinecartItemMixin.java index b887d9e7..aaa71877 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MinecartItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/MinecartItemMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemUseContext; -import net.minecraft.item.MinecartItem; -import net.minecraft.util.ActionResultType; -import net.minecraft.world.World; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.MinecartItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,12 +15,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class MinecartItemMixin { @Eject(method = "onItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$entityPlace(World world, Entity entityIn, CallbackInfoReturnable cir, ItemUseContext context) { + private boolean arclight$entityPlace(Level world, Entity entityIn, CallbackInfoReturnable cir, UseOnContext context) { if (CraftEventFactory.callEntityPlaceEvent(context, entityIn).isCancelled()) { - cir.setReturnValue(ActionResultType.FAIL); + cir.setReturnValue(InteractionResult.FAIL); return false; - } else if (!world.addEntity(entityIn)) { - cir.setReturnValue(ActionResultType.PASS); + } else if (!world.addFreshEntity(entityIn)) { + cir.setReturnValue(InteractionResult.PASS); return false; } else { return true; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/PotionItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/PotionItemMixin.java index c53f9f23..0edecd02 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/PotionItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/PotionItemMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.PotionItem; -import net.minecraft.world.World; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.PotionItem; +import net.minecraft.world.level.Level; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,8 +14,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PotionItem.class) public class PotionItemMixin { - @Inject(method = "onItemUseFinish", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - public void arclight$drinkPotion(ItemStack stack, World worldIn, LivingEntity entityLiving, CallbackInfoReturnable cir) { + @Inject(method = "finishUsingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + public void arclight$drinkPotion(ItemStack stack, Level worldIn, LivingEntity entityLiving, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityLiving).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.POTION_DRINK); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ShearsItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ShearsItemMixin.java index bf9b6937..17e0be1e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ShearsItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/ShearsItemMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.item; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ShearsItem; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ShearsItem; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,10 +15,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ShearsItem.class) public class ShearsItemMixin { - @Inject(method = "itemInteractionForEntity", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/common/IForgeShearable;isShearable(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Z")) - private void arclight$onShear(ItemStack stack, PlayerEntity playerIn, LivingEntity entity, Hand hand, CallbackInfoReturnable cir) { + @Inject(method = "interactLivingEntity", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/common/IForgeShearable;isShearable(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Z")) + private void arclight$onShear(ItemStack stack, Player playerIn, LivingEntity entity, InteractionHand hand, CallbackInfoReturnable cir) { if (!CraftEventFactory.handlePlayerShearEntityEvent(playerIn, entity, stack, hand)) { - cir.setReturnValue(ActionResultType.PASS); + cir.setReturnValue(InteractionResult.PASS); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SnowballItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SnowballItemMixin.java index d16d932f..2cbe680e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SnowballItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SnowballItemMixin.java @@ -1,19 +1,19 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.SnowballEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.SnowballItem; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; -import net.minecraft.util.ActionResult; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.world.World; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Snowball; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SnowballItem; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -30,23 +30,23 @@ public class SnowballItemMixin extends Item { * @reason */ @Overwrite - public @NotNull ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, @NotNull Hand handIn) { - ItemStack itemstack = playerIn.getHeldItem(handIn); - if (!worldIn.isRemote) { - SnowballEntity snowballentity = new SnowballEntity(worldIn, playerIn); + public @NotNull InteractionResultHolder use(Level worldIn, Player playerIn, @NotNull InteractionHand handIn) { + ItemStack itemstack = playerIn.getItemInHand(handIn); + if (!worldIn.isClientSide) { + Snowball snowballentity = new Snowball(worldIn, playerIn); snowballentity.setItem(itemstack); - if (worldIn.addEntity(snowballentity)) { - if (!playerIn.abilities.isCreativeMode) { + if (worldIn.addFreshEntity(snowballentity)) { + if (!playerIn.abilities.instabuild) { itemstack.shrink(1); } - worldIn.playSound(null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); - snowballentity.setDirectionAndMovement(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); - } else if (playerIn instanceof ServerPlayerEntity) { + worldIn.playSound(null, playerIn.getX(), playerIn.getY(), playerIn.getZ(), SoundEvents.SNOWBALL_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F)); + snowballentity.shootFromRotation(playerIn, playerIn.xRot, playerIn.yRot, 0.0F, 1.5F, 1.0F); + } else if (playerIn instanceof ServerPlayer) { ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory(); } } - playerIn.addStat(Stats.ITEM_USED.get(this)); - return new ActionResult<>(ActionResultType.SUCCESS, itemstack); + playerIn.awardStat(Stats.ITEM_USED.get(this)); + return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SpawnEggItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SpawnEggItemMixin.java index 5bdad844..15653a56 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SpawnEggItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/SpawnEggItemMixin.java @@ -1,13 +1,6 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.SpawnEggItem; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.server.ServerWorld; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,12 +8,19 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SpawnEggItem; +import net.minecraft.world.phys.Vec3; @Mixin(SpawnEggItem.class) public class SpawnEggItemMixin { - @Inject(method = "getChildToSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$reason(PlayerEntity player, MobEntity mob, EntityType entityType, ServerWorld world, Vector3d pos, ItemStack stack, CallbackInfoReturnable> cir) { + @Inject(method = "spawnOffspringFromSpawnEgg", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$reason(Player player, Mob mob, EntityType entityType, ServerLevel world, Vec3 pos, ItemStack stack, CallbackInfoReturnable> cir) { ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/TridentItemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/TridentItemMixin.java index a9341a3f..3a996fd7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/TridentItemMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/TridentItemMixin.java @@ -3,13 +3,6 @@ package io.izzel.arclight.common.mixin.core.item; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.entity.projectile.TridentEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.TridentItem; -import net.minecraft.world.World; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.event.player.PlayerRiptideEvent; @@ -20,33 +13,40 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.function.Consumer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.TridentItem; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.level.Level; @Mixin(TridentItem.class) public class TridentItemMixin { - @Redirect(method = "onPlayerStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damageItem(ILnet/minecraft/entity/LivingEntity;Ljava/util/function/Consumer;)V")) + @Redirect(method = "releaseUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V")) public void arclight$muteDamage(ItemStack stack, int amount, LivingEntity entityIn, Consumer onBroken) { - int j = EnchantmentHelper.getRiptideModifier(stack); - if (j != 0) stack.damageItem(amount, entityIn, onBroken); + int j = EnchantmentHelper.getRiptide(stack); + if (j != 0) stack.hurtAndBreak(amount, entityIn, onBroken); } @Eject(method = "onPlayerStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public boolean arclight$addEntity(World world, Entity entityIn, CallbackInfo ci, ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) { - if (!world.addEntity(entityIn)) { - if (entityLiving instanceof ServerPlayerEntity) { + public boolean arclight$addEntity(Level world, Entity entityIn, CallbackInfo ci, ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) { + if (!world.addFreshEntity(entityIn)) { + if (entityLiving instanceof ServerPlayer) { ((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity().updateInventory(); } ci.cancel(); return false; } - stack.damageItem(1, entityLiving, (entity) -> - entity.sendBreakAnimation(entityLiving.getActiveHand())); + stack.hurtAndBreak(1, entityLiving, (entity) -> + entity.broadcastBreakEvent(entityLiving.getUsedItemHand())); ((TridentEntityBridge) entityIn).bridge$setThrownStack(stack.copy()); return true; } - @Inject(method = "onPlayerStoppedUsing", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/entity/player/PlayerEntity;rotationYaw:F")) - public void arclight$riptide(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft, CallbackInfo ci) { + @Inject(method = "releaseUsing", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/entity/player/Player;yRot:F")) + public void arclight$riptide(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft, CallbackInfo ci) { PlayerRiptideEvent event = new PlayerRiptideEvent(((ServerPlayerEntityBridge) entityLiving).bridge$getBukkitEntity(), CraftItemStack.asCraftMirror(stack)); Bukkit.getPluginManager().callEvent(event); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/BlastingRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/BlastingRecipeMixin.java index 64ab1ec3..01a78151 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/BlastingRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/BlastingRecipeMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.BlastingRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.BlastingRecipe; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeType; import org.bukkit.craftbukkit.v.inventory.CraftBlastingRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; @@ -17,14 +17,14 @@ import org.spongepowered.asm.mixin.Mixin; @Mixin(BlastingRecipe.class) public abstract class BlastingRecipeMixin extends AbstractCookingRecipe implements IRecipeBridge { - public BlastingRecipeMixin(IRecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { + public BlastingRecipeMixin(RecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { super(typeIn, idIn, groupIn, ingredientIn, resultIn, experienceIn, cookTimeIn); } @Override public Recipe bridge$toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - CraftBlastingRecipe recipe = new CraftBlastingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime); + CraftBlastingRecipe recipe = new CraftBlastingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); recipe.setGroup(this.group); return recipe; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/CampfireCookingRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/CampfireCookingRecipeMixin.java index 98670dbe..e6d8c7ec 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/CampfireCookingRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/CampfireCookingRecipeMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.CampfireCookingRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.CampfireCookingRecipe; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeType; import org.bukkit.craftbukkit.v.inventory.CraftCampfireRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; @@ -17,14 +17,14 @@ import org.spongepowered.asm.mixin.Mixin; @Mixin(CampfireCookingRecipe.class) public abstract class CampfireCookingRecipeMixin extends AbstractCookingRecipe implements IRecipeBridge { - public CampfireCookingRecipeMixin(IRecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { + public CampfireCookingRecipeMixin(RecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { super(typeIn, idIn, groupIn, ingredientIn, resultIn, experienceIn, cookTimeIn); } @Override public Recipe bridge$toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - CraftCampfireRecipe recipe = new CraftCampfireRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime); + CraftCampfireRecipe recipe = new CraftCampfireRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); recipe.setGroup(this.group); return recipe; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/FurnaceRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/FurnaceRecipeMixin.java index 5a99a51e..b5f60da2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/FurnaceRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/FurnaceRecipeMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.FurnaceRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.SmeltingRecipe; import org.bukkit.craftbukkit.v.inventory.CraftFurnaceRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; @@ -14,10 +14,10 @@ import org.bukkit.craftbukkit.v.util.CraftNamespacedKey; import org.bukkit.inventory.Recipe; import org.spongepowered.asm.mixin.Mixin; -@Mixin(FurnaceRecipe.class) +@Mixin(SmeltingRecipe.class) public abstract class FurnaceRecipeMixin extends AbstractCookingRecipe implements IRecipeBridge { - public FurnaceRecipeMixin(IRecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { + public FurnaceRecipeMixin(RecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { super(typeIn, idIn, groupIn, ingredientIn, resultIn, experienceIn, cookTimeIn); } @@ -25,7 +25,7 @@ public abstract class FurnaceRecipeMixin extends AbstractCookingRecipe implement public Recipe bridge$toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(CraftNamespacedKey.fromMinecraft(this.id), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime); + CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(CraftNamespacedKey.fromMinecraft(this.id), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); recipe.setGroup(this.group); return recipe; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IRecipeMixin.java index 41533942..8c321eef 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IRecipeMixin.java @@ -2,17 +2,16 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; import io.izzel.arclight.common.mod.util.ArclightSpecialRecipe; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.item.ItemStack; import org.bukkit.inventory.Recipe; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(IRecipe.class) +@Mixin(net.minecraft.world.item.crafting.Recipe.class) public interface IRecipeMixin extends IRecipeBridge { // @formatter:off - @Shadow ItemStack getRecipeOutput(); + @Shadow ItemStack getResultItem(); // @formatter:on default Recipe toBukkitRecipe() { @@ -21,6 +20,6 @@ public interface IRecipeMixin extends IRecipeBridge { @Override default Recipe bridge$toBukkitRecipe() { - return new ArclightSpecialRecipe((IRecipe) this); + return new ArclightSpecialRecipe((net.minecraft.world.item.crafting.Recipe) this); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IngredientMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IngredientMixin.java index 5f66827f..67e2547c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IngredientMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/IngredientMixin.java @@ -1,20 +1,20 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IngredientBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import javax.annotation.Nullable; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; @Mixin(Ingredient.class) public abstract class IngredientMixin implements IngredientBridge { // @formatter:off - @Shadow public abstract void determineMatchingStacks(); - @Shadow public ItemStack[] matchingStacks; + @Shadow public abstract void dissolve(); + @Shadow public ItemStack[] itemStacks; // @formatter:on public boolean exact; @@ -28,13 +28,13 @@ public abstract class IngredientMixin implements IngredientBridge { if (stack == null) { return false; } else { - this.determineMatchingStacks(); - if (this.matchingStacks.length == 0) { + this.dissolve(); + if (this.itemStacks.length == 0) { return stack.isEmpty(); } else { - for (ItemStack itemstack : this.matchingStacks) { + for (ItemStack itemstack : this.itemStacks) { if (exact) { - if (itemstack.getItem() == stack.getItem() && ItemStack.areItemsEqual(itemstack, stack)) { + if (itemstack.getItem() == stack.getItem() && ItemStack.isSame(itemstack, stack)) { return true; } continue; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/RecipeManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/RecipeManagerMixin.java index ca1c8d95..1bb408af 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/RecipeManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/RecipeManagerMixin.java @@ -8,17 +8,17 @@ import com.google.gson.JsonParseException; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.item.crafting.RecipeManagerBridge; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.RecipeManager; -import net.minecraft.profiler.IProfiler; -import net.minecraft.resources.IResourceManager; -import net.minecraft.util.JSONUtils; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Util; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.World; +import net.minecraft.Util; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.GsonHelper; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.Level; import net.minecraftforge.common.crafting.CraftingHelper; import org.apache.logging.log4j.Logger; import org.spongepowered.asm.mixin.Final; @@ -34,11 +34,11 @@ import java.util.Optional; public abstract class RecipeManagerMixin implements RecipeManagerBridge { // @formatter:off - @Shadow public Map, Map>> recipes; - @Shadow protected abstract > Map> getRecipes(IRecipeType recipeTypeIn); - @Shadow private boolean someRecipesErrored; + @Shadow public Map, Map>> recipes; + @Shadow protected abstract > Map> byType(RecipeType recipeTypeIn); + @Shadow private boolean hasErrors; @Shadow @Final private static Logger LOGGER; - @Shadow public static IRecipe deserializeRecipe(ResourceLocation recipeId, JsonObject json) { return null; } + @Shadow public static Recipe fromJson(ResourceLocation recipeId, JsonObject json) { return null; } // @formatter:on /** @@ -47,11 +47,11 @@ public abstract class RecipeManagerMixin implements RecipeManagerBridge { */ @Overwrite @SuppressWarnings("unchecked") - protected void apply(Map objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) { - this.someRecipesErrored = false; - Map, Object2ObjectLinkedOpenHashMap>> map = Maps.newHashMap(); + protected void apply(Map objectIn, ResourceManager resourceManagerIn, ProfilerFiller profilerIn) { + this.hasErrors = false; + Map, Object2ObjectLinkedOpenHashMap>> map = Maps.newHashMap(); - for (IRecipeType type : Registry.RECIPE_TYPE) { + for (RecipeType type : Registry.RECIPE_TYPE) { map.put(type, new Object2ObjectLinkedOpenHashMap<>()); } @@ -65,7 +65,7 @@ public abstract class RecipeManagerMixin implements RecipeManagerBridge { LOGGER.info("Skipping loading recipe {} as it's conditions were not met", resourcelocation); continue; } - IRecipe irecipe = deserializeRecipe(resourcelocation, JSONUtils.getJsonObject(entry.getValue(), "top element")); + Recipe irecipe = fromJson(resourcelocation, GsonHelper.convertToJsonObject(entry.getValue(), "top element")); if (irecipe == null) { LOGGER.info("Skipping loading recipe {} as it's serializer returned null", resourcelocation); continue; @@ -86,27 +86,27 @@ public abstract class RecipeManagerMixin implements RecipeManagerBridge { * @reason */ @Overwrite - public > Optional getRecipe(IRecipeType recipeTypeIn, C inventoryIn, World worldIn) { - Optional optional = this.getRecipes(recipeTypeIn).values().stream().flatMap((recipe) -> { - return Util.streamOptional(recipeTypeIn.matches(recipe, worldIn, inventoryIn)); + public > Optional getRecipeFor(RecipeType recipeTypeIn, C inventoryIn, Level worldIn) { + Optional optional = this.byType(recipeTypeIn).values().stream().flatMap((recipe) -> { + return Util.toStream(recipeTypeIn.tryMatch(recipe, worldIn, inventoryIn)); }).findFirst(); ((IInventoryBridge) inventoryIn).setCurrentRecipe(optional.orElse(null)); return optional; } - public void addRecipe(IRecipe recipe) { + public void addRecipe(Recipe recipe) { if (this.recipes instanceof ImmutableMap) { this.recipes = new HashMap<>(recipes); } - Map> original = this.recipes.get(recipe.getType()); - Object2ObjectLinkedOpenHashMap> map; + Map> original = this.recipes.get(recipe.getType()); + Object2ObjectLinkedOpenHashMap> map; if (!(original instanceof Object2ObjectLinkedOpenHashMap)) { - Object2ObjectLinkedOpenHashMap> hashMap = new Object2ObjectLinkedOpenHashMap<>(); + Object2ObjectLinkedOpenHashMap> hashMap = new Object2ObjectLinkedOpenHashMap<>(); hashMap.putAll(original); this.recipes.put(recipe.getType(), hashMap); map = hashMap; } else { - map = ((Object2ObjectLinkedOpenHashMap>) original); + map = ((Object2ObjectLinkedOpenHashMap>) original); } if (map.containsKey(recipe.getId())) { @@ -117,13 +117,13 @@ public abstract class RecipeManagerMixin implements RecipeManagerBridge { } @Override - public void bridge$addRecipe(IRecipe recipe) { + public void bridge$addRecipe(Recipe recipe) { addRecipe(recipe); } public void clearRecipes() { this.recipes = new HashMap<>(); - for (IRecipeType type : Registry.RECIPE_TYPE) { + for (RecipeType type : Registry.RECIPE_TYPE) { this.recipes.put(type, new Object2ObjectLinkedOpenHashMap<>()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ServerRecipeBookMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ServerRecipeBookMixin.java index 348a685e..0c86400d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ServerRecipeBookMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ServerRecipeBookMixin.java @@ -1,10 +1,5 @@ package io.izzel.arclight.common.mixin.core.item.crafting; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ServerRecipeBook; -import net.minecraft.network.play.server.SRecipeBookPacket; -import net.minecraft.util.ResourceLocation; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,17 +9,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Collection; import java.util.List; +import net.minecraft.network.protocol.game.ClientboundRecipePacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.ServerRecipeBook; +import net.minecraft.world.item.crafting.Recipe; @Mixin(ServerRecipeBook.class) public class ServerRecipeBookMixin { - @Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/crafting/IRecipe;isDynamic()Z")) - public boolean arclight$recipeUpdate(IRecipe recipe, Collection> collection, ServerPlayerEntity playerEntity) { - return recipe.isDynamic() || !CraftEventFactory.handlePlayerRecipeListUpdateEvent(playerEntity, recipe.getId()); + @Redirect(method = "addRecipes", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/crafting/Recipe;isSpecial()Z")) + public boolean arclight$recipeUpdate(Recipe recipe, Collection> collection, ServerPlayer playerEntity) { + return recipe.isSpecial() || !CraftEventFactory.handlePlayerRecipeListUpdateEvent(playerEntity, recipe.getId()); } - @Inject(method = "sendPacket", cancellable = true, at = @At("HEAD")) - public void arclight$returnIfFail(SRecipeBookPacket.State state, ServerPlayerEntity player, List recipesIn, CallbackInfo ci) { + @Inject(method = "sendRecipes", cancellable = true, at = @At("HEAD")) + public void arclight$returnIfFail(ClientboundRecipePacket.State state, ServerPlayer player, List recipesIn, CallbackInfo ci) { if (player.connection == null) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapedRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapedRecipeMixin.java index 023ac2d4..98142a6e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapedRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapedRecipeMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapedRecipe; -import net.minecraft.util.NonNullList; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.ShapedRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; import org.bukkit.craftbukkit.v.inventory.CraftShapedRecipe; @@ -18,7 +18,7 @@ import org.spongepowered.asm.mixin.Shadow; public abstract class ShapedRecipeMixin implements IRecipeBridge { // @formatter:off - @Shadow @Final private ItemStack recipeOutput; + @Shadow @Final private ItemStack result; @Shadow @Final private String group; @Shadow @Final private NonNullList recipeItems; @Shadow public abstract int getHeight(); @@ -27,7 +27,7 @@ public abstract class ShapedRecipeMixin implements IRecipeBridge { @Override public Recipe bridge$toBukkitRecipe() { - CraftItemStack result = CraftItemStack.asCraftMirror(this.recipeOutput); + CraftItemStack result = CraftItemStack.asCraftMirror(this.result); CraftShapedRecipe recipe = new CraftShapedRecipe(result, (ShapedRecipe) (Object) this); recipe.setGroup(this.group); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapelessRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapelessRecipeMixin.java index 304e4ab0..8e293b57 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapelessRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/ShapelessRecipeMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapelessRecipe; -import net.minecraft.util.NonNullList; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.ShapelessRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; import org.bukkit.craftbukkit.v.inventory.CraftShapelessRecipe; @@ -17,17 +17,17 @@ import org.spongepowered.asm.mixin.Shadow; public class ShapelessRecipeMixin implements IRecipeBridge { // @formatter:off - @Shadow @Final private ItemStack recipeOutput; + @Shadow @Final private ItemStack result; @Shadow @Final private String group; - @Shadow @Final private NonNullList recipeItems; + @Shadow @Final private NonNullList ingredients; // @formatter:off @Override public Recipe bridge$toBukkitRecipe() { - CraftItemStack result = CraftItemStack.asCraftMirror(this.recipeOutput); + CraftItemStack result = CraftItemStack.asCraftMirror(this.result); CraftShapelessRecipe recipe = new CraftShapelessRecipe(result, (ShapelessRecipe)(Object) this); recipe.setGroup(this.group); - for (Ingredient list : this.recipeItems) { + for (Ingredient list : this.ingredients) { recipe.addIngredient(CraftRecipe.toBukkit(list)); } return recipe; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmithingRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmithingRecipeMixin.java index 4add535a..8d57be52 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmithingRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmithingRecipeMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.SmithingRecipe; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.UpgradeRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; import org.bukkit.craftbukkit.v.inventory.CraftSmithingRecipe; @@ -14,12 +14,12 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(SmithingRecipe.class) +@Mixin(UpgradeRecipe.class) public class SmithingRecipeMixin implements IRecipeBridge { // @formatter:off @Shadow @Final private ItemStack result; - @Shadow @Final private ResourceLocation recipeId; + @Shadow @Final private ResourceLocation id; @Shadow @Final private Ingredient base; @Shadow @Final private Ingredient addition; // @formatter:on @@ -27,6 +27,6 @@ public class SmithingRecipeMixin implements IRecipeBridge { @Override public Recipe bridge$toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - return new CraftSmithingRecipe(CraftNamespacedKey.fromMinecraft(this.recipeId), result, CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition)); + return new CraftSmithingRecipe(CraftNamespacedKey.fromMinecraft(this.id), result, CraftRecipe.toBukkit(this.base), CraftRecipe.toBukkit(this.addition)); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmokingRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmokingRecipeMixin.java index cca3969b..3f3ef498 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmokingRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SmokingRecipeMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.SmokingRecipe; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.AbstractCookingRecipe; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.SmokingRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; import org.bukkit.craftbukkit.v.inventory.CraftSmokingRecipe; @@ -17,14 +17,14 @@ import org.spongepowered.asm.mixin.Mixin; @Mixin(SmokingRecipe.class) public abstract class SmokingRecipeMixin extends AbstractCookingRecipe implements IRecipeBridge { - public SmokingRecipeMixin(IRecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { + public SmokingRecipeMixin(RecipeType typeIn, ResourceLocation idIn, String groupIn, Ingredient ingredientIn, ItemStack resultIn, float experienceIn, int cookTimeIn) { super(typeIn, idIn, groupIn, ingredientIn, resultIn, experienceIn, cookTimeIn); } @Override public Recipe bridge$toBukkitRecipe() { CraftItemStack result = CraftItemStack.asCraftMirror(this.result); - CraftSmokingRecipe recipe = new CraftSmokingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime); + CraftSmokingRecipe recipe = new CraftSmokingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); recipe.setGroup(this.group); return recipe; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SpecialRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SpecialRecipeMixin.java index 5f019cfe..0ea80686 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SpecialRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/SpecialRecipeMixin.java @@ -1,15 +1,15 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.world.item.crafting.CustomRecipe; import org.bukkit.inventory.Recipe; import org.spongepowered.asm.mixin.Mixin; -@Mixin(SpecialRecipe.class) +@Mixin(CustomRecipe.class) public class SpecialRecipeMixin implements IRecipeBridge { @Override public Recipe bridge$toBukkitRecipe() { - return new org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe((SpecialRecipe) (Object) this); + return new org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe((CustomRecipe) (Object) this); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/StonecuttingRecipeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/StonecuttingRecipeMixin.java index daa53759..b274393e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/StonecuttingRecipeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/item/crafting/StonecuttingRecipeMixin.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mixin.core.item.crafting; import io.izzel.arclight.common.bridge.item.crafting.IRecipeBridge; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.SingleItemRecipe; -import net.minecraft.item.crafting.StonecuttingRecipe; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.item.crafting.SingleItemRecipe; +import net.minecraft.world.item.crafting.StonecutterRecipe; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.craftbukkit.v.inventory.CraftRecipe; import org.bukkit.craftbukkit.v.inventory.CraftStonecuttingRecipe; @@ -15,10 +15,10 @@ import org.bukkit.craftbukkit.v.util.CraftNamespacedKey; import org.bukkit.inventory.Recipe; import org.spongepowered.asm.mixin.Mixin; -@Mixin(StonecuttingRecipe.class) +@Mixin(StonecutterRecipe.class) public abstract class StonecuttingRecipeMixin extends SingleItemRecipe implements IRecipeBridge { - public StonecuttingRecipeMixin(IRecipeType type, IRecipeSerializer serializer, ResourceLocation id, String group, Ingredient ingredient, ItemStack result) { + public StonecuttingRecipeMixin(RecipeType type, RecipeSerializer serializer, ResourceLocation id, String group, Ingredient ingredient, ItemStack result) { super(type, serializer, id, group, ingredient, result); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootEntry_SerializerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootEntry_SerializerMixin.java index 07f8f05f..7da610e7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootEntry_SerializerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootEntry_SerializerMixin.java @@ -3,12 +3,12 @@ package io.izzel.arclight.common.mixin.core.loot; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; -import net.minecraft.loot.LootEntry; +import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(LootEntry.Serializer.class) -public abstract class LootEntry_SerializerMixin { +@Mixin(LootPoolEntryContainer.Serializer.class) +public abstract class LootEntry_SerializerMixin { // @formatter:off @Shadow public abstract void serialize(JsonObject p_230424_1_, T p_230424_2_, JsonSerializationContext p_230424_3_); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootParametersMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootParametersMixin.java index 7eb43089..96fb7834 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootParametersMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootParametersMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.loot; -import net.minecraft.loot.LootParameter; -import net.minecraft.loot.LootParameters; -import net.minecraft.util.ResourceLocation; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.storage.loot.parameters.LootContextParam; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import org.spongepowered.asm.mixin.Mixin; -@Mixin(LootParameters.class) +@Mixin(LootContextParams.class) public class LootParametersMixin { - private static final LootParameter LOOTING_MOD = new LootParameter<>(new ResourceLocation("bukkit:looting_mod")); + private static final LootContextParam LOOTING_MOD = new LootContextParam<>(new ResourceLocation("bukkit:looting_mod")); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableManagerMixin.java index 5dcdebf6..6ee96e1f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableManagerMixin.java @@ -2,11 +2,6 @@ package io.izzel.arclight.common.mixin.core.loot; import com.google.common.collect.ImmutableMap; import com.google.gson.JsonObject; -import net.minecraft.profiler.IProfiler; -import net.minecraft.resources.IResourceManager; -import net.minecraft.util.ResourceLocation; -import net.minecraft.loot.LootTable; -import net.minecraft.loot.LootTableManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -14,20 +9,25 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Map; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.LootTables; -@Mixin(LootTableManager.class) +@Mixin(LootTables.class) public class LootTableManagerMixin { // @formatter:off - @Shadow private Map registeredLootTables; + @Shadow private Map tables; // @formatter:on public Map lootTableToKey = ImmutableMap.of(); @Inject(method = "apply", at = @At("RETURN")) - private void arclight$buildRev(Map objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn, CallbackInfo ci) { + private void arclight$buildRev(Map objectIn, ResourceManager resourceManagerIn, ProfilerFiller profilerIn, CallbackInfo ci) { ImmutableMap.Builder lootTableToKeyBuilder = ImmutableMap.builder(); - this.registeredLootTables.forEach((lootTable, key) -> lootTableToKeyBuilder.put(key, lootTable)); + this.tables.forEach((lootTable, key) -> lootTableToKeyBuilder.put(key, lootTable)); this.lootTableToKey = lootTableToKeyBuilder.build(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableMixin.java index 5a821623..850c758c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/LootTableMixin.java @@ -2,11 +2,6 @@ package io.izzel.arclight.common.mixin.core.loot; import io.izzel.arclight.common.bridge.world.storage.loot.LootTableBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameters; -import net.minecraft.loot.LootTable; import org.apache.logging.log4j.Logger; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; @@ -20,21 +15,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.List; import java.util.Random; import java.util.stream.Collectors; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; @Mixin(LootTable.class) public abstract class LootTableMixin implements LootTableBridge { // @formatter:off @Shadow @Final private static Logger LOGGER; - @Shadow public abstract List generate(LootContext context); - @Shadow protected abstract List getEmptySlotsRandomized(IInventory inventory, Random rand); - @Shadow protected abstract void shuffleItems(List stacks, int emptySlotsCount, Random rand); + @Shadow public abstract List getRandomItems(LootContext context); + @Shadow protected abstract List getAvailableSlots(Container inventory, Random rand); + @Shadow protected abstract void shuffleAndSplitItems(List stacks, int emptySlotsCount, Random rand); // @formatter:on @Eject(method = "fillInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;generate(Lnet/minecraft/loot/LootContext;)Ljava/util/List;")) - private List arclight$nonPluginEvent(LootTable lootTable, LootContext context, CallbackInfo ci, IInventory inv) { - List list = lootTable.generate(context); - if (!context.has(LootParameters.ORIGIN) && !context.has(LootParameters.THIS_ENTITY)) { + private List arclight$nonPluginEvent(LootTable lootTable, LootContext context, CallbackInfo ci, Container inv) { + List list = lootTable.getRandomItems(context); + if (!context.hasParam(LootContextParams.ORIGIN) && !context.hasParam(LootContextParams.THIS_ENTITY)) { return list; } LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, false); @@ -46,16 +46,16 @@ public abstract class LootTableMixin implements LootTableBridge { } } - public void fillInventory(IInventory inv, LootContext context, boolean plugin) { - List list = this.generate(context); + public void fillInventory(Container inv, LootContext context, boolean plugin) { + List list = this.getRandomItems(context); Random random = context.getRandom(); LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, plugin); if (event.isCancelled()) { return; } list = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(Collectors.toList()); - List list1 = this.getEmptySlotsRandomized(inv, random); - this.shuffleItems(list, list1.size(), random); + List list1 = this.getAvailableSlots(inv, random); + this.shuffleAndSplitItems(list, list1.size(), random); for (ItemStack itemstack : list) { if (list1.isEmpty()) { @@ -64,15 +64,15 @@ public abstract class LootTableMixin implements LootTableBridge { } if (itemstack.isEmpty()) { - inv.setInventorySlotContents(list1.remove(list1.size() - 1), ItemStack.EMPTY); + inv.setItem(list1.remove(list1.size() - 1), ItemStack.EMPTY); } else { - inv.setInventorySlotContents(list1.remove(list1.size() - 1), itemstack); + inv.setItem(list1.remove(list1.size() - 1), itemstack); } } } @Override - public void bridge$fillInventory(IInventory inv, LootContext context, boolean plugin) { + public void bridge$fillInventory(Container inv, LootContext context, boolean plugin) { this.fillInventory(inv, context, plugin); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/RandomChanceWithLootingMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/RandomChanceWithLootingMixin.java index 9613bbc5..cc993fdf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/RandomChanceWithLootingMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/RandomChanceWithLootingMixin.java @@ -1,17 +1,17 @@ package io.izzel.arclight.common.mixin.core.loot.conditions; import io.izzel.arclight.common.mod.ArclightConstants; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.conditions.RandomChanceWithLooting; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceWithLootingCondition; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -@Mixin(RandomChanceWithLooting.class) +@Mixin(LootItemRandomChanceWithLootingCondition.class) public class RandomChanceWithLootingMixin { - @Shadow @Final private float chance; + @Shadow @Final private float percent; @Shadow @Final private float lootingMultiplier; /** @@ -22,9 +22,9 @@ public class RandomChanceWithLootingMixin { public boolean test(LootContext context) { int i = context.getLootingModifier(); - if (context.has(ArclightConstants.LOOTING_MOD)) { - i = context.get(ArclightConstants.LOOTING_MOD); + if (context.hasParam(ArclightConstants.LOOTING_MOD)) { + i = context.getParamOrNull(ArclightConstants.LOOTING_MOD); } - return context.getRandom().nextFloat() < this.chance + (float) i * this.lootingMultiplier; + return context.getRandom().nextFloat() < this.percent + (float) i * this.lootingMultiplier; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/SurvivesExplosionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/SurvivesExplosionMixin.java index 806e6f56..abb65c07 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/SurvivesExplosionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/conditions/SurvivesExplosionMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.loot.conditions; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameters; -import net.minecraft.loot.conditions.SurvivesExplosion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import java.util.Random; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; -@Mixin(SurvivesExplosion.class) +@Mixin(ExplosionCondition.class) public class SurvivesExplosionMixin { /** @@ -17,7 +17,7 @@ public class SurvivesExplosionMixin { */ @Overwrite public boolean test(LootContext context) { - Float f = context.get(LootParameters.EXPLOSION_RADIUS); + Float f = context.getParamOrNull(LootContextParams.EXPLOSION_RADIUS); if (f != null) { Random random = context.getRandom(); float f1 = 1.0F / f; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/functions/LootingEnchantBonusMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/functions/LootingEnchantBonusMixin.java index b26ea3e4..9d323c72 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/functions/LootingEnchantBonusMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/loot/functions/LootingEnchantBonusMixin.java @@ -1,25 +1,25 @@ package io.izzel.arclight.common.mixin.core.loot.functions; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameters; -import net.minecraft.loot.RandomValueRange; -import net.minecraft.loot.functions.LootingEnchantBonus; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import io.izzel.arclight.common.mod.ArclightConstants; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.RandomValueBounds; +import net.minecraft.world.level.storage.loot.functions.LootingEnchantFunction; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -@Mixin(LootingEnchantBonus.class) +@Mixin(LootingEnchantFunction.class) public abstract class LootingEnchantBonusMixin { // @formatter:off - @Shadow @Final private RandomValueRange count; + @Shadow @Final private RandomValueBounds value; @Shadow @Final private int limit; - @Shadow protected abstract boolean func_215917_b(); + @Shadow protected abstract boolean hasLimit(); // @formatter:on /** @@ -27,20 +27,20 @@ public abstract class LootingEnchantBonusMixin { * @reason */ @Overwrite - public ItemStack doApply(ItemStack stack, LootContext context) { - Entity entity = context.get(LootParameters.KILLER_ENTITY); + public ItemStack run(ItemStack stack, LootContext context) { + Entity entity = context.getParamOrNull(LootContextParams.KILLER_ENTITY); if (entity instanceof LivingEntity) { int i = context.getLootingModifier(); - if (context.has(ArclightConstants.LOOTING_MOD)) { - i = context.get(ArclightConstants.LOOTING_MOD); + if (context.hasParam(ArclightConstants.LOOTING_MOD)) { + i = context.getParamOrNull(ArclightConstants.LOOTING_MOD); } if (i <= 0) { return stack; } - float f = (float) i * this.count.generateFloat(context.getRandom()); + float f = (float) i * this.value.getFloat(context.getRandom()); stack.grow(Math.round(f)); - if (this.func_215917_b() && stack.getCount() > this.limit) { + if (this.hasLimit() && stack.getCount() > this.limit) { stack.setCount(this.limit); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/NetworkManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/NetworkManagerMixin.java index 25ed0a74..c753aff6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/NetworkManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/NetworkManagerMixin.java @@ -3,14 +3,14 @@ package io.izzel.arclight.common.mixin.core.network; import com.mojang.authlib.properties.Property; import io.izzel.arclight.common.bridge.network.NetworkManagerBridge; import io.netty.channel.Channel; -import net.minecraft.network.NetworkManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import java.net.SocketAddress; import java.util.UUID; +import net.minecraft.network.Connection; -@Mixin(NetworkManager.class) +@Mixin(Connection.class) public class NetworkManagerMixin implements NetworkManagerBridge { @Shadow public Channel channel; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/PacketThreadUtilMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/PacketThreadUtilMixin.java index af1e483f..96854234 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/PacketThreadUtilMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/PacketThreadUtilMixin.java @@ -2,12 +2,12 @@ package io.izzel.arclight.common.mixin.core.network; import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; -import net.minecraft.network.INetHandler; -import net.minecraft.network.IPacket; -import net.minecraft.network.PacketThreadUtil; -import net.minecraft.network.ThreadQuickExitException; -import net.minecraft.network.play.ServerPlayNetHandler; -import net.minecraft.util.concurrent.ThreadTaskExecutor; +import net.minecraft.network.PacketListener; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.PacketUtils; +import net.minecraft.server.RunningOnDifferentThreadException; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.util.thread.BlockableEventLoop; import org.apache.logging.log4j.Logger; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -@Mixin(PacketThreadUtil.class) +@Mixin(PacketUtils.class) public class PacketThreadUtilMixin { @Shadow @Final private static Logger LOGGER; @@ -26,22 +26,22 @@ public class PacketThreadUtilMixin { * @reason */ @Overwrite - public static void checkThreadAndEnqueue(IPacket packetIn, T processor, ThreadTaskExecutor executor) throws ThreadQuickExitException { - if (!executor.isOnExecutionThread()) { + public static void ensureRunningOnSameThread(Packet packetIn, T processor, BlockableEventLoop executor) throws RunningOnDifferentThreadException { + if (!executor.isSameThread()) { executor.execute(() -> { - if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerPlayNetHandler && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) { + if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerGamePacketListenerImpl && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) { return; } - if (processor.getNetworkManager().isChannelOpen()) { - packetIn.processPacket(processor); + if (processor.getConnection().isConnected()) { + packetIn.handle(processor); } else { LOGGER.debug("Ignoring packet due to disconnection: " + packetIn); } }); - throw ThreadQuickExitException.INSTANCE; - } else if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerPlayNetHandler && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) { - throw ThreadQuickExitException.INSTANCE; + throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD; + } else if (((MinecraftServerBridge) ((CraftServer) Bukkit.getServer()).getServer()).bridge$hasStopped() || (processor instanceof ServerGamePacketListenerImpl && ((ServerPlayNetHandlerBridge) processor).bridge$processedDisconnect())) { + throw RunningOnDifferentThreadException.RUNNING_ON_DIFFERENT_THREAD; } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/datasync/EntityDataManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/datasync/EntityDataManagerMixin.java index 2a359fc7..6b0b8d35 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/datasync/EntityDataManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/datasync/EntityDataManagerMixin.java @@ -2,10 +2,10 @@ package io.izzel.arclight.common.mixin.core.network.datasync; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.network.datasync.EntityDataManagerBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -14,32 +14,32 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(EntityDataManager.class) +@Mixin(SynchedEntityData.class) public abstract class EntityDataManagerMixin implements EntityDataManagerBridge { // @formatter:off - @Shadow protected abstract EntityDataManager.DataEntry getEntry(DataParameter key); - @Shadow private boolean dirty; + @Shadow protected abstract SynchedEntityData.DataItem getItem(EntityDataAccessor key); + @Shadow private boolean isDirty; @Shadow @Final private Entity entity; // @formatter:on @Inject(method = "set", at = @At("HEAD")) - private void arclight$syncHealth(DataParameter key, T value, CallbackInfo ci) { - if (key == LivingEntity.HEALTH && this.entity instanceof ServerPlayerEntityBridge + private void arclight$syncHealth(EntityDataAccessor key, T value, CallbackInfo ci) { + if (key == LivingEntity.DATA_HEALTH_ID && this.entity instanceof ServerPlayerEntityBridge && ((ServerPlayerEntityBridge) this.entity).bridge$initialized()) { CraftPlayer player = ((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity(); player.setRealHealth(((Float) value)); } } - public void markDirty(DataParameter key) { - EntityDataManager.DataEntry entry = this.getEntry(key); + public void markDirty(EntityDataAccessor key) { + SynchedEntityData.DataItem entry = this.getItem(key); entry.setDirty(true); - this.dirty = true; + this.isDirty = true; } @Override - public void bridge$markDirty(DataParameter key) { + public void bridge$markDirty(EntityDataAccessor key) { this.markDirty(key); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/ServerHandshakeNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/ServerHandshakeNetHandlerMixin.java index 67c8ab89..8732e2ac 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/ServerHandshakeNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/ServerHandshakeNetHandlerMixin.java @@ -5,17 +5,17 @@ import com.mojang.authlib.properties.Property; import com.mojang.util.UUIDTypeAdapter; import io.izzel.arclight.common.bridge.network.NetworkManagerBridge; import io.izzel.arclight.common.bridge.network.login.ServerLoginNetHandlerBridge; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.ProtocolType; -import net.minecraft.network.handshake.ServerHandshakeNetHandler; -import net.minecraft.network.handshake.client.CHandshakePacket; -import net.minecraft.network.login.ServerLoginNetHandler; -import net.minecraft.network.login.server.SDisconnectLoginPacket; -import net.minecraft.network.status.ServerStatusNetHandler; +import net.minecraft.SharedConstants; +import net.minecraft.network.Connection; +import net.minecraft.network.ConnectionProtocol; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.handshake.ClientIntentionPacket; +import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.SharedConstants; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.server.network.ServerHandshakePacketListenerImpl; +import net.minecraft.server.network.ServerLoginPacketListenerImpl; +import net.minecraft.server.network.ServerStatusPacketListenerImpl; import net.minecraftforge.fml.server.ServerLifecycleHooks; import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; @@ -30,7 +30,7 @@ import java.net.InetSocketAddress; import java.text.MessageFormat; import java.util.HashMap; -@Mixin(ServerHandshakeNetHandler.class) +@Mixin(ServerHandshakePacketListenerImpl.class) public class ServerHandshakeNetHandlerMixin { private static final Gson gson = new Gson(); @@ -38,9 +38,9 @@ public class ServerHandshakeNetHandlerMixin { private static int throttleCounter = 0; // @formatter:off - @Shadow @Final private NetworkManager networkManager; + @Shadow @Final private Connection connection; @Shadow @Final private MinecraftServer server; - @Shadow @Final private static ITextComponent field_241169_a_; + @Shadow @Final private static Component IGNORE_STATUS_REASON; // @formatter:on /** @@ -48,22 +48,22 @@ public class ServerHandshakeNetHandlerMixin { * @reason */ @Overwrite - public void processHandshake(CHandshakePacket packetIn) { - if (!ServerLifecycleHooks.handleServerLogin(packetIn, this.networkManager)) return; - switch (packetIn.getRequestedState()) { + public void handleIntention(ClientIntentionPacket packetIn) { + if (!ServerLifecycleHooks.handleServerLogin(packetIn, this.connection)) return; + switch (packetIn.getIntention()) { case LOGIN: { - this.networkManager.setConnectionState(ProtocolType.LOGIN); + this.connection.setProtocol(ConnectionProtocol.LOGIN); try { long currentTime = System.currentTimeMillis(); long connectionThrottle = Bukkit.getServer().getConnectionThrottle(); - InetAddress address = ((InetSocketAddress) this.networkManager.getRemoteAddress()).getAddress(); + InetAddress address = ((InetSocketAddress) this.connection.getRemoteAddress()).getAddress(); synchronized (throttleTracker) { if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) { throttleTracker.put(address, currentTime); - TranslationTextComponent component = new TranslationTextComponent("Connection throttled! Please wait before reconnecting."); - this.networkManager.sendPacket(new SDisconnectLoginPacket(component)); - this.networkManager.closeChannel(component); + TranslatableComponent component = new TranslatableComponent("Connection throttled! Please wait before reconnecting."); + this.connection.send(new ClientboundLoginDisconnectPacket(component)); + this.connection.disconnect(component); return; } throttleTracker.put(address, currentTime); @@ -78,53 +78,53 @@ public class ServerHandshakeNetHandlerMixin { } - if (packetIn.getProtocolVersion() > SharedConstants.getVersion().getProtocolVersion()) { - TranslationTextComponent component = new TranslationTextComponent(MessageFormat.format(SpigotConfig.outdatedServerMessage.replaceAll("'", "''"), SharedConstants.getVersion().getName())); - this.networkManager.sendPacket(new SDisconnectLoginPacket(component)); - this.networkManager.closeChannel(component); + if (packetIn.getProtocolVersion() > SharedConstants.getCurrentVersion().getProtocolVersion()) { + TranslatableComponent component = new TranslatableComponent(MessageFormat.format(SpigotConfig.outdatedServerMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName())); + this.connection.send(new ClientboundLoginDisconnectPacket(component)); + this.connection.disconnect(component); break; } - if (packetIn.getProtocolVersion() < SharedConstants.getVersion().getProtocolVersion()) { - TranslationTextComponent component = new TranslationTextComponent(MessageFormat.format(SpigotConfig.outdatedClientMessage.replaceAll("'", "''"), SharedConstants.getVersion().getName())); - this.networkManager.sendPacket(new SDisconnectLoginPacket(component)); - this.networkManager.closeChannel(component); + if (packetIn.getProtocolVersion() < SharedConstants.getCurrentVersion().getProtocolVersion()) { + TranslatableComponent component = new TranslatableComponent(MessageFormat.format(SpigotConfig.outdatedClientMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName())); + this.connection.send(new ClientboundLoginDisconnectPacket(component)); + this.connection.disconnect(component); break; } - this.networkManager.setNetHandler(new ServerLoginNetHandler(this.server, this.networkManager)); + this.connection.setListener(new ServerLoginPacketListenerImpl(this.server, this.connection)); if (SpigotConfig.bungee) { - String[] split = packetIn.ip.split("\00"); + String[] split = packetIn.hostName.split("\00"); if (split.length == 3 || split.length == 4) { - packetIn.ip = split[0]; - this.networkManager.socketAddress = new InetSocketAddress(split[1], ((InetSocketAddress) this.networkManager.getRemoteAddress()).getPort()); - ((NetworkManagerBridge) this.networkManager).bridge$setSpoofedUUID(UUIDTypeAdapter.fromString(split[2])); + packetIn.hostName = split[0]; + this.connection.address = new InetSocketAddress(split[1], ((InetSocketAddress) this.connection.getRemoteAddress()).getPort()); + ((NetworkManagerBridge) this.connection).bridge$setSpoofedUUID(UUIDTypeAdapter.fromString(split[2])); } else { - TranslationTextComponent component = new TranslationTextComponent("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!"); - this.networkManager.sendPacket(new SDisconnectLoginPacket(component)); - this.networkManager.closeChannel(component); + TranslatableComponent component = new TranslatableComponent("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!"); + this.connection.send(new ClientboundLoginDisconnectPacket(component)); + this.connection.disconnect(component); return; } if (split.length == 4) { - ((NetworkManagerBridge) this.networkManager).bridge$setSpoofedProfile(gson.fromJson(split[3], Property[].class)); + ((NetworkManagerBridge) this.connection).bridge$setSpoofedProfile(gson.fromJson(split[3], Property[].class)); } } - ((ServerLoginNetHandlerBridge) this.networkManager.getNetHandler()).bridge$setHostname(packetIn.ip + ":" + packetIn.port); + ((ServerLoginNetHandlerBridge) this.connection.getPacketListener()).bridge$setHostname(packetIn.hostName + ":" + packetIn.port); break; } case STATUS: { - if (this.server.func_230541_aj_()) { - this.networkManager.setConnectionState(ProtocolType.STATUS); - this.networkManager.setNetHandler(new ServerStatusNetHandler(this.server, this.networkManager)); + if (this.server.repliesToStatus()) { + this.connection.setProtocol(ConnectionProtocol.STATUS); + this.connection.setListener(new ServerStatusPacketListenerImpl(this.server, this.connection)); } else { - this.networkManager.closeChannel(field_241169_a_); + this.connection.disconnect(IGNORE_STATUS_REASON); } break; } default: { - throw new UnsupportedOperationException("Invalid intention " + packetIn.getRequestedState()); + throw new UnsupportedOperationException("Invalid intention " + packetIn.getIntention()); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/client/CHandshakePacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/client/CHandshakePacketMixin.java index 78751762..f9033b89 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/client/CHandshakePacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/handshake/client/CHandshakePacketMixin.java @@ -2,8 +2,8 @@ package io.izzel.arclight.common.mixin.core.network.handshake.client; import com.google.gson.Gson; import com.mojang.authlib.properties.Property; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.handshake.client.CHandshakePacket; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.handshake.ClientIntentionPacket; import net.minecraftforge.fml.network.FMLNetworkConstants; import net.minecraftforge.fml.network.NetworkHooks; import org.spigotmc.SpigotConfig; @@ -16,26 +16,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Objects; -@Mixin(CHandshakePacket.class) +@Mixin(ClientIntentionPacket.class) public class CHandshakePacketMixin { // @formatter:off @Shadow(remap = false) private String fmlVersion; - @Shadow public String ip; + @Shadow public String hostName; // @formatter:on private static final String EXTRA_DATA = "extraData"; private static final Gson GSON = new Gson(); - @Redirect(method = "readPacketData", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketBuffer;readString(I)Ljava/lang/String;")) - private String arclight$bungeeHostname(PacketBuffer packetBuffer, int maxLength) { - return packetBuffer.readString(Short.MAX_VALUE); + @Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readUtf(I)Ljava/lang/String;")) + private String arclight$bungeeHostname(FriendlyByteBuf packetBuffer, int maxLength) { + return packetBuffer.readUtf(Short.MAX_VALUE); } - @Inject(method = "readPacketData", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, remap = false, target = "Lnet/minecraft/network/handshake/client/CHandshakePacket;fmlVersion:Ljava/lang/String;")) - private void arclight$readFromProfile(PacketBuffer buf, CallbackInfo ci) { + @Inject(method = "read", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, remap = false, target = "Lnet/minecraft/network/protocol/handshake/ClientIntentionPacket;fmlVersion:Ljava/lang/String;")) + private void arclight$readFromProfile(FriendlyByteBuf buf, CallbackInfo ci) { if (SpigotConfig.bungee && !Objects.equals(this.fmlVersion, FMLNetworkConstants.NETVERSION)) { - String[] split = this.ip.split("\0"); + String[] split = this.hostName.split("\0"); if (split.length == 4) { Property[] properties = GSON.fromJson(split[3], Property[].class); for (Property property : properties) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/login/ServerLoginNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/login/ServerLoginNetHandlerMixin.java index 58917483..b148948a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/login/ServerLoginNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/login/ServerLoginNetHandlerMixin.java @@ -6,23 +6,23 @@ import io.izzel.arclight.common.bridge.network.NetworkManagerBridge; import io.izzel.arclight.common.bridge.network.login.ServerLoginNetHandlerBridge; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; import io.izzel.arclight.common.bridge.server.management.PlayerListBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.login.ServerLoginNetHandler; -import net.minecraft.network.login.client.CEncryptionResponsePacket; -import net.minecraft.network.login.client.CLoginStartPacket; -import net.minecraft.network.login.server.SDisconnectLoginPacket; -import net.minecraft.network.login.server.SEnableCompressionPacket; -import net.minecraft.network.login.server.SEncryptionRequestPacket; -import net.minecraft.network.login.server.SLoginSuccessPacket; +import net.minecraft.DefaultUncaughtExceptionHandler; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.login.ClientboundGameProfilePacket; +import net.minecraft.network.protocol.login.ClientboundHelloPacket; +import net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket; +import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket; +import net.minecraft.network.protocol.login.ServerboundHelloPacket; +import net.minecraft.network.protocol.login.ServerboundKeyPacket; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerLoginPacketListenerImpl; +import net.minecraft.util.Crypt; import net.minecraft.util.CryptException; -import net.minecraft.util.CryptManager; -import net.minecraft.util.DefaultUncaughtExceptionHandler; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.fml.common.thread.SidedThreadGroups; import org.apache.commons.lang3.Validate; import org.apache.logging.log4j.Logger; @@ -48,22 +48,22 @@ import java.util.Arrays; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; -@Mixin(ServerLoginNetHandler.class) +@Mixin(ServerLoginPacketListenerImpl.class) public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandlerBridge { // @formatter:off - @Shadow private ServerLoginNetHandler.State currentLoginState; + @Shadow private ServerLoginPacketListenerImpl.State state; @Shadow @Final private MinecraftServer server; - @Shadow @Final private byte[] verifyToken; + @Shadow @Final private byte[] nonce; @Shadow private SecretKey secretKey; - @Shadow @Final public NetworkManager networkManager; - @Shadow @Final private static AtomicInteger AUTHENTICATOR_THREAD_ID; - @Shadow private GameProfile loginGameProfile; + @Shadow @Final public Connection connection; + @Shadow @Final private static AtomicInteger UNIQUE_THREAD_ID; + @Shadow private GameProfile gameProfile; @Shadow @Final private static Logger LOGGER; - @Shadow protected abstract GameProfile getOfflineProfile(GameProfile original); - @Shadow public abstract void disconnect(ITextComponent reason); - @Shadow public abstract String getConnectionInfo(); - @Shadow private ServerPlayerEntity player; + @Shadow protected abstract GameProfile createFakeProfile(GameProfile original); + @Shadow public abstract void disconnect(Component reason); + @Shadow public abstract String getUserName(); + @Shadow private ServerPlayer delayedAcceptPlayer; // @formatter:on public String hostname; @@ -80,10 +80,10 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle public void disconnect(final String s) { try { - final ITextComponent ichatbasecomponent = new StringTextComponent(s); - LOGGER.info("Disconnecting {}: {}", this.getConnectionInfo(), s); - this.networkManager.sendPacket(new SDisconnectLoginPacket(ichatbasecomponent)); - this.networkManager.closeChannel(ichatbasecomponent); + final Component ichatbasecomponent = new TextComponent(s); + LOGGER.info("Disconnecting {}: {}", this.getUserName(), s); + this.connection.send(new ClientboundLoginDisconnectPacket(ichatbasecomponent)); + this.connection.disconnect(ichatbasecomponent); } catch (Exception exception) { LOGGER.error("Error whilst disconnecting player", exception); } @@ -94,31 +94,31 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle * @reason */ @Overwrite - public void tryAcceptPlayer() { + public void handleAcceptedLogin() { /* if (!this.loginGameProfile.isComplete()) { this.loginGameProfile = this.getOfflineProfile(this.loginGameProfile); } */ - ServerPlayerEntity entity = ((PlayerListBridge) this.server.getPlayerList()).bridge$canPlayerLogin(this.networkManager.getRemoteAddress(), this.loginGameProfile, (ServerLoginNetHandler) (Object) this); + ServerPlayer entity = ((PlayerListBridge) this.server.getPlayerList()).bridge$canPlayerLogin(this.connection.getRemoteAddress(), this.gameProfile, (ServerLoginPacketListenerImpl) (Object) this); if (entity == null) { // this.disconnect(itextcomponent); } else { - this.currentLoginState = ServerLoginNetHandler.State.ACCEPTED; - if (this.server.getNetworkCompressionThreshold() >= 0 && !this.networkManager.isLocalChannel()) { - this.networkManager.sendPacket(new SEnableCompressionPacket(this.server.getNetworkCompressionThreshold()), (p_210149_1_) -> { - this.networkManager.setCompressionThreshold(this.server.getNetworkCompressionThreshold()); + this.state = ServerLoginPacketListenerImpl.State.ACCEPTED; + if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) { + this.connection.send(new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()), (p_210149_1_) -> { + this.connection.setupCompression(this.server.getCompressionThreshold()); }); } - this.networkManager.sendPacket(new SLoginSuccessPacket(this.loginGameProfile)); - ServerPlayerEntity serverplayerentity = this.server.getPlayerList().getPlayerByUUID(this.loginGameProfile.getId()); + this.connection.send(new ClientboundGameProfilePacket(this.gameProfile)); + ServerPlayer serverplayerentity = this.server.getPlayerList().getPlayer(this.gameProfile.getId()); if (serverplayerentity != null) { - this.currentLoginState = ServerLoginNetHandler.State.DELAY_ACCEPT; - this.player = entity; + this.state = ServerLoginPacketListenerImpl.State.DELAY_ACCEPT; + this.delayedAcceptPlayer = entity; } else { - this.server.getPlayerList().initializeConnectionToPlayer(this.networkManager, entity); + this.server.getPlayerList().placeNewPlayer(this.connection, entity); } } } @@ -128,17 +128,17 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle * @reason */ @Overwrite - public void processLoginStart(CLoginStartPacket packetIn) { - Validate.validState(this.currentLoginState == ServerLoginNetHandler.State.HELLO, "Unexpected hello packet"); - this.loginGameProfile = packetIn.getProfile(); - if (this.server.isServerInOnlineMode() && !this.networkManager.isLocalChannel()) { - this.currentLoginState = ServerLoginNetHandler.State.KEY; - this.networkManager.sendPacket(new SEncryptionRequestPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.verifyToken)); + public void handleHello(ServerboundHelloPacket packetIn) { + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet"); + this.gameProfile = packetIn.getGameProfile(); + if (this.server.usesAuthentication() && !this.connection.isMemoryConnection()) { + this.state = ServerLoginPacketListenerImpl.State.KEY; + this.connection.send(new ClientboundHelloPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.nonce)); } else { class Handler extends Thread { Handler() { - super(SidedThreadGroups.SERVER, "User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet()); + super(SidedThreadGroups.SERVER, "User Authenticator #" + UNIQUE_THREAD_ID.incrementAndGet()); } @Override @@ -148,7 +148,7 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle arclight$preLogin(); } catch (Exception ex) { disconnect("Failed to verify username!"); - LOGGER.warn("Exception verifying {} ", loginGameProfile.getName(), ex); + LOGGER.warn("Exception verifying {} ", gameProfile.getName(), ex); } } } @@ -159,17 +159,17 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle public void initUUID() { UUID uuid; - if (((NetworkManagerBridge) this.networkManager).bridge$getSpoofedUUID() != null) { - uuid = ((NetworkManagerBridge) this.networkManager).bridge$getSpoofedUUID(); + if (((NetworkManagerBridge) this.connection).bridge$getSpoofedUUID() != null) { + uuid = ((NetworkManagerBridge) this.connection).bridge$getSpoofedUUID(); } else { - uuid = PlayerEntity.getOfflineUUID(this.loginGameProfile.getName()); + uuid = Player.createPlayerUUID(this.gameProfile.getName()); } - this.loginGameProfile = new GameProfile(uuid, this.loginGameProfile.getName()); - if (((NetworkManagerBridge) this.networkManager).bridge$getSpoofedProfile() != null) { + this.gameProfile = new GameProfile(uuid, this.gameProfile.getName()); + if (((NetworkManagerBridge) this.connection).bridge$getSpoofedProfile() != null) { Property[] spoofedProfile; - for (int length = (spoofedProfile = ((NetworkManagerBridge) this.networkManager).bridge$getSpoofedProfile()).length, i = 0; i < length; ++i) { + for (int length = (spoofedProfile = ((NetworkManagerBridge) this.connection).bridge$getSpoofedProfile()).length, i = 0; i < length; ++i) { final Property property = spoofedProfile[i]; - this.loginGameProfile.getProperties().put(property.getName(), property); + this.gameProfile.getProperties().put(property.getName(), property); } } } @@ -179,22 +179,22 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle * @reason */ @Overwrite - public void processEncryptionResponse(CEncryptionResponsePacket packetIn) { - Validate.validState(this.currentLoginState == ServerLoginNetHandler.State.KEY, "Unexpected key packet"); + public void handleKey(ServerboundKeyPacket packetIn) { + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.KEY, "Unexpected key packet"); PrivateKey privatekey = this.server.getKeyPair().getPrivate(); final String s; try { - if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey))) { + if (!Arrays.equals(this.nonce, packetIn.getNonce(privatekey))) { throw new IllegalStateException("Protocol error"); } this.secretKey = packetIn.getSecretKey(privatekey); - Cipher cipher = CryptManager.createNetCipherInstance(2, this.secretKey); - Cipher cipher1 = CryptManager.createNetCipherInstance(1, this.secretKey); - s = (new BigInteger(CryptManager.getServerIdHash("", this.server.getKeyPair().getPublic(), this.secretKey))).toString(16); - this.currentLoginState = ServerLoginNetHandler.State.AUTHENTICATING; - this.networkManager.func_244777_a(cipher, cipher1); + Cipher cipher = Crypt.getCipher(2, this.secretKey); + Cipher cipher1 = Crypt.getCipher(1, this.secretKey); + s = (new BigInteger(Crypt.digestData("", this.server.getKeyPair().getPublic(), this.secretKey))).toString(16); + this.state = ServerLoginPacketListenerImpl.State.AUTHENTICATING; + this.connection.setEncryptionKey(cipher, cipher1); } catch (CryptException cryptexception) { throw new IllegalStateException("Protocol error", cryptexception); } @@ -202,34 +202,34 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle class Handler extends Thread { Handler() { - super(SidedThreadGroups.SERVER, "User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet()); + super(SidedThreadGroups.SERVER, "User Authenticator #" + UNIQUE_THREAD_ID.incrementAndGet()); } public void run() { - GameProfile gameprofile = loginGameProfile; + GameProfile gameprofile = gameProfile; try { - loginGameProfile = server.getMinecraftSessionService().hasJoinedServer(new GameProfile(null, gameprofile.getName()), s, this.getAddress()); - if (loginGameProfile != null) { - if (!networkManager.isChannelOpen()) { + gameProfile = server.getSessionService().hasJoinedServer(new GameProfile(null, gameprofile.getName()), s, this.getAddress()); + if (gameProfile != null) { + if (!connection.isConnected()) { return; } arclight$preLogin(); - } else if (server.isSinglePlayer()) { + } else if (server.isSingleplayer()) { LOGGER.warn("Failed to verify username but will let them in anyway!"); - loginGameProfile = getOfflineProfile(gameprofile); - currentLoginState = ServerLoginNetHandler.State.NEGOTIATING; + gameProfile = createFakeProfile(gameprofile); + state = ServerLoginPacketListenerImpl.State.NEGOTIATING; } else { - disconnect(new TranslationTextComponent("multiplayer.disconnect.unverified_username")); + disconnect(new TranslatableComponent("multiplayer.disconnect.unverified_username")); LOGGER.error("Username '{}' tried to join with an invalid session", gameprofile.getName()); } } catch (Exception var3) { - if (server.isSinglePlayer()) { + if (server.isSingleplayer()) { LOGGER.warn("Authentication servers are down but will let them in anyway!"); - loginGameProfile = getOfflineProfile(gameprofile); - currentLoginState = ServerLoginNetHandler.State.NEGOTIATING; + gameProfile = createFakeProfile(gameprofile); + state = ServerLoginPacketListenerImpl.State.NEGOTIATING; } else { - disconnect(new TranslationTextComponent("multiplayer.disconnect.authservers_down")); + disconnect(new TranslatableComponent("multiplayer.disconnect.authservers_down")); LOGGER.error("Couldn't verify username because servers are unavailable"); } } @@ -238,7 +238,7 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle @Nullable private InetAddress getAddress() { - SocketAddress socketaddress = networkManager.getRemoteAddress(); + SocketAddress socketaddress = connection.getRemoteAddress(); return server.getPreventProxyConnections() && socketaddress instanceof InetSocketAddress ? ((InetSocketAddress) socketaddress).getAddress() : null; } } @@ -248,9 +248,9 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle } private void arclight$preLogin() throws Exception { - String playerName = loginGameProfile.getName(); - InetAddress address = ((InetSocketAddress) networkManager.getRemoteAddress()).getAddress(); - UUID uniqueId = loginGameProfile.getId(); + String playerName = gameProfile.getName(); + InetAddress address = ((InetSocketAddress) connection.getRemoteAddress()).getAddress(); + UUID uniqueId = gameProfile.getId(); CraftServer craftServer = (CraftServer) Bukkit.getServer(); AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId); craftServer.getPluginManager().callEvent(asyncEvent); @@ -277,7 +277,7 @@ public abstract class ServerLoginNetHandlerMixin implements ServerLoginNetHandle disconnect(asyncEvent.getKickMessage()); return; } - LOGGER.info("UUID of player {} is {}", loginGameProfile.getName(), loginGameProfile.getId()); - currentLoginState = ServerLoginNetHandler.State.NEGOTIATING; + LOGGER.info("UUID of player {} is {}", gameProfile.getName(), gameProfile.getId()); + state = ServerLoginPacketListenerImpl.State.NEGOTIATING; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java index b96a9253..8500f47a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/ServerPlayNetHandlerMixin.java @@ -16,73 +16,96 @@ import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import it.unimi.dsi.fastutil.ints.Int2ShortMap; +import net.minecraft.ChatFormatting; +import net.minecraft.SharedConstants; +import net.minecraft.Util; import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.block.Blocks; -import net.minecraft.command.CommandException; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.fish.AbstractFishEntity; -import net.minecraft.entity.player.ChatVisibility; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.AbstractArrowEntity; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.MerchantContainer; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.StringNBT; -import net.minecraft.network.IPacket; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.PacketThreadUtil; -import net.minecraft.network.play.ServerPlayNetHandler; +import net.minecraft.commands.CommandRuntimeException; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.network.play.client.*; -import net.minecraft.network.play.server.SChatPacket; -import net.minecraft.network.play.server.SConfirmTransactionPacket; -import net.minecraft.network.play.server.SDisconnectPacket; -import net.minecraft.network.play.server.SEntityMetadataPacket; -import net.minecraft.network.play.server.SHeldItemChangePacket; -import net.minecraft.network.play.server.SMountEntityPacket; -import net.minecraft.network.play.server.SMoveVehiclePacket; -import net.minecraft.network.play.server.SPlayerPositionLookPacket; -import net.minecraft.network.play.server.SSetSlotPacket; -import net.minecraft.network.play.server.SSpawnMobPacket; -import net.minecraft.network.play.server.SWorldSpawnChangedPacket; -import net.minecraft.potion.Effects; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.PacketUtils; +import net.minecraft.network.protocol.game.ClientboundAddMobPacket; +import net.minecraft.network.protocol.game.ClientboundChatPacket; +import net.minecraft.network.protocol.game.ClientboundContainerAckPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundDisconnectPacket; +import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket; +import net.minecraft.network.protocol.game.ServerboundChatPacket; +import net.minecraft.network.protocol.game.ServerboundContainerAckPacket; +import net.minecraft.network.protocol.game.ServerboundContainerButtonClickPacket; +import net.minecraft.network.protocol.game.ServerboundContainerClickPacket; +import net.minecraft.network.protocol.game.ServerboundContainerClosePacket; +import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.game.ServerboundEditBookPacket; +import net.minecraft.network.protocol.game.ServerboundInteractPacket; +import net.minecraft.network.protocol.game.ServerboundKeepAlivePacket; +import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket; +import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket; +import net.minecraft.network.protocol.game.ServerboundResourcePackPacket; +import net.minecraft.network.protocol.game.ServerboundSelectTradePacket; +import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket; +import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket; +import net.minecraft.network.protocol.game.ServerboundSignUpdatePacket; +import net.minecraft.network.protocol.game.ServerboundSwingPacket; +import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.network.protocol.game.ServerboundUseItemPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.PlayerList; -import net.minecraft.tileentity.SignTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SharedConstants; -import net.minecraft.util.StringUtils; -import net.minecraft.util.Util; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.RayTraceContext; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ChatType; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.GameRules; -import net.minecraft.world.GameType; -import net.minecraft.world.IWorldReader; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.players.PlayerList; +import net.minecraft.util.Mth; +import net.minecraft.util.StringUtil; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.animal.AbstractFish; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.ChatVisiblity; +import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MerchantMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ForgeHooks; import org.apache.logging.log4j.Logger; import org.bukkit.Bukkit; @@ -152,32 +175,32 @@ import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.logging.Level; -@Mixin(ServerPlayNetHandler.class) +@Mixin(ServerGamePacketListenerImpl.class) public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerBridge { // @formatter:off @Shadow(aliases = {"server", "field_147367_d"}, remap = false) @Final private MinecraftServer minecraftServer; - @Shadow public ServerPlayerEntity player; - @Shadow @Final public NetworkManager netManager; - @Shadow public abstract void onDisconnect(ITextComponent reason); - @Shadow private static boolean isMoveVehiclePacketInvalid(CMoveVehiclePacket packetIn) { return false; } - @Shadow private Entity lowestRiddenEnt; - @Shadow private double lowestRiddenX; - @Shadow private double lowestRiddenY; - @Shadow private double lowestRiddenZ; - @Shadow protected abstract boolean func_217264_d(); - @Shadow private double lowestRiddenX1; - @Shadow private double lowestRiddenY1; - @Shadow private double lowestRiddenZ1; - @Shadow private boolean vehicleFloating; - @Shadow private int movePacketCounter; - @Shadow private int lastMovePacketCounter; - @Shadow private Vector3d targetPos; - @Shadow private static boolean isMovePlayerPacketInvalid(CPlayerPacket packetIn) { return false; } - @Shadow private int networkTickCount; - @Shadow public abstract void captureCurrentPosition(); - @Shadow private int lastPositionUpdate; - @Shadow public abstract void setPlayerLocation(double x, double y, double z, float yaw, float pitch); + @Shadow public ServerPlayer player; + @Shadow @Final public Connection connection; + @Shadow public abstract void onDisconnect(Component reason); + @Shadow private static boolean containsInvalidValues(ServerboundMoveVehiclePacket packetIn) { return false; } + @Shadow private Entity lastVehicle; + @Shadow private double vehicleFirstGoodX; + @Shadow private double vehicleFirstGoodY; + @Shadow private double vehicleFirstGoodZ; + @Shadow protected abstract boolean isSingleplayerOwner(); + @Shadow private double vehicleLastGoodX; + @Shadow private double vehicleLastGoodY; + @Shadow private double vehicleLastGoodZ; + @Shadow private boolean clientVehicleIsFloating; + @Shadow private int receivedMovePacketCount; + @Shadow private int knownMovePacketCount; + @Shadow private Vec3 awaitingPositionFromClient; + @Shadow private static boolean containsInvalidValues(ServerboundMovePlayerPacket packetIn) { return false; } + @Shadow private int tickCount; + @Shadow public abstract void resetPosition(); + @Shadow private int awaitingTeleportTime; + @Shadow public abstract void teleport(double x, double y, double z, float yaw, float pitch); @Shadow private double firstGoodX; @Shadow private double firstGoodY; @Shadow private double firstGoodZ; @@ -185,14 +208,14 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB @Shadow private double lastGoodX; @Shadow private double lastGoodY; @Shadow private double lastGoodZ; - @Shadow private boolean floating; - @Shadow private int teleportId; - @Shadow public abstract void sendPacket(IPacket packetIn); - @Shadow private int chatSpamThresholdCount; - @Shadow @Final private Int2ShortMap pendingTransactions; - @Shadow private int itemDropThreshold; - @Shadow protected abstract boolean func_241162_a_(Entity p_241162_1_); - @Shadow protected abstract boolean func_241163_a_(IWorldReader p_241163_1_, AxisAlignedBB p_241163_2_); + @Shadow private boolean clientIsFloating; + @Shadow private int awaitingTeleport; + @Shadow public abstract void send(Packet packetIn); + @Shadow private int chatSpamTickCount; + @Shadow @Final private Int2ShortMap expectedAcks; + @Shadow private int dropSpamTickCount; + @Shadow protected abstract boolean noBlocksAround(Entity p_241162_1_); + @Shadow protected abstract boolean isPlayerCollidingWithAnythingNew(LevelReader p_241163_1_, AABB p_241163_2_); // @formatter:on private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6; @@ -223,7 +246,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } @Inject(method = "", at = @At("RETURN")) - private void arclight$init(MinecraftServer server, NetworkManager networkManagerIn, ServerPlayerEntity playerIn, CallbackInfo ci) { + private void arclight$init(MinecraftServer server, Connection networkManagerIn, ServerPlayer playerIn, CallbackInfo ci) { this.server = ((CraftServer) Bukkit.getServer()); allowedPlayerTicks = 1; dropCount = 0; @@ -240,7 +263,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void disconnect(ITextComponent textComponent) { + public void disconnect(Component textComponent) { this.disconnect(CraftChatMessage.fromComponent(textComponent)); } @@ -248,20 +271,20 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB if (this.processedDisconnect) { return; } - String leaveMessage = TextFormatting.YELLOW + this.player.getScoreboardName() + " left the game."; + String leaveMessage = ChatFormatting.YELLOW + this.player.getScoreboardName() + " left the game."; PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage); - if (this.server.getServer().isServerRunning()) { + if (this.server.getServer().isRunning()) { this.server.getPluginManager().callEvent(event); } if (event.isCancelled()) { return; } s = event.getReason(); - ITextComponent textComponent = CraftChatMessage.fromString(s, true)[0]; - this.netManager.sendPacket(new SDisconnectPacket(textComponent), future -> this.netManager.closeChannel(textComponent)); + Component textComponent = CraftChatMessage.fromString(s, true)[0]; + this.connection.send(new ClientboundDisconnectPacket(textComponent), future -> this.connection.disconnect(textComponent)); this.onDisconnect(textComponent); - this.netManager.disableAutoRead(); - this.minecraftServer.runImmediately(this.netManager::handleDisconnection); + this.connection.setReadOnly(); + this.minecraftServer.executeBlocking(this.connection::handleDisconnection); } @Override @@ -274,32 +297,32 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processVehicleMove(final CMoveVehiclePacket packetplayinvehiclemove) { - PacketThreadUtil.checkThreadAndEnqueue(packetplayinvehiclemove, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); - if (isMoveVehiclePacketInvalid(packetplayinvehiclemove)) { - this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_vehicle_movement")); + public void handleMoveVehicle(final ServerboundMoveVehiclePacket packetplayinvehiclemove) { + PacketUtils.ensureRunningOnSameThread(packetplayinvehiclemove, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); + if (containsInvalidValues(packetplayinvehiclemove)) { + this.disconnect(new TranslatableComponent("multiplayer.disconnect.invalid_vehicle_movement")); } else { - Entity entity = this.player.getLowestRidingEntity(); - if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lowestRiddenEnt) { - ServerWorld worldserver = this.player.getServerWorld(); - double d0 = entity.getPosX(); - double d2 = entity.getPosY(); - double d3 = entity.getPosZ(); + Entity entity = this.player.getRootVehicle(); + if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) { + ServerLevel worldserver = this.player.getLevel(); + double d0 = entity.getX(); + double d2 = entity.getY(); + double d3 = entity.getZ(); double d4 = packetplayinvehiclemove.getX(); double d5 = packetplayinvehiclemove.getY(); double d6 = packetplayinvehiclemove.getZ(); - float f = packetplayinvehiclemove.getYaw(); - float f2 = packetplayinvehiclemove.getPitch(); - double d7 = d4 - this.lowestRiddenX; - double d8 = d5 - this.lowestRiddenY; - double d9 = d6 - this.lowestRiddenZ; - double d10 = entity.getMotion().lengthSquared(); + float f = packetplayinvehiclemove.getYRot(); + float f2 = packetplayinvehiclemove.getXRot(); + double d7 = d4 - this.vehicleFirstGoodX; + double d8 = d5 - this.vehicleFirstGoodY; + double d9 = d6 - this.vehicleFirstGoodZ; + double d10 = entity.getDeltaMovement().lengthSqr(); double d11 = d7 * d7 + d8 * d8 + d9 * d9; this.allowedPlayerTicks += (int) (System.currentTimeMillis() / 50L - this.lastTick); this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1); this.lastTick = (int) (System.currentTimeMillis() / 50L); - ++this.movePacketCounter; - int i = this.movePacketCounter - this.lastMovePacketCounter; + ++this.receivedMovePacketCount; + int i = this.receivedMovePacketCount - this.knownMovePacketCount; if (i > Math.max(this.allowedPlayerTicks, 5)) { LOGGER.debug(this.player.getScoreboardName() + " is sending move packets too frequently (" + i + " packets since last tick)"); i = 1; @@ -310,42 +333,42 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB this.allowedPlayerTicks = 20; } double speed; - if (this.player.abilities.isFlying) { - speed = this.player.abilities.flySpeed * 20.0f; + if (this.player.abilities.flying) { + speed = this.player.abilities.flyingSpeed * 20.0f; } else { - speed = this.player.abilities.walkSpeed * 10.0f; + speed = this.player.abilities.walkingSpeed * 10.0f; } speed *= 2.0; - if (d11 - d10 > Math.max(100.0, Math.pow(10.0f * i * speed, 2.0)) && !this.func_217264_d()) { + if (d11 - d10 > Math.max(100.0, Math.pow(10.0f * i * speed, 2.0)) && !this.isSingleplayerOwner()) { LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName().getString(), this.player.getName().getString(), d7, d8, d9); - this.netManager.sendPacket(new SMoveVehiclePacket(entity)); + this.connection.send(new ClientboundMoveVehiclePacket(entity)); return; } - boolean flag = worldserver.hasNoCollisions(entity, entity.getBoundingBox().shrink(0.0625)); - d7 = d4 - this.lowestRiddenX1; - d8 = d5 - this.lowestRiddenY1 - 1.0E-6; - d9 = d6 - this.lowestRiddenZ1; - entity.move(MoverType.PLAYER, new Vector3d(d7, d8, d9)); + boolean flag = worldserver.noCollision(entity, entity.getBoundingBox().deflate(0.0625)); + d7 = d4 - this.vehicleLastGoodX; + d8 = d5 - this.vehicleLastGoodY - 1.0E-6; + d9 = d6 - this.vehicleLastGoodZ; + entity.move(MoverType.PLAYER, new Vec3(d7, d8, d9)); double d12 = d8; - d7 = d4 - entity.getPosX(); - d8 = d5 - entity.getPosY(); + d7 = d4 - entity.getX(); + d8 = d5 - entity.getY(); if (d8 > -0.5 || d8 < 0.5) { d8 = 0.0; } - d9 = d6 - entity.getPosZ(); + d9 = d6 - entity.getZ(); d11 = d7 * d7 + d8 * d8 + d9 * d9; boolean flag2 = false; if (d11 > SpigotConfig.movedWronglyThreshold) { flag2 = true; LOGGER.warn("{} (vehicle of {}) moved wrongly! {}", entity.getName().getString(), this.player.getName().getString(), Math.sqrt(d11)); } - entity.setPositionAndRotation(d4, d5, d6, f, f2); - this.player.setPositionAndRotation(d4, d5, d6, this.player.rotationYaw, this.player.rotationPitch); - boolean flag3 = worldserver.hasNoCollisions(entity, entity.getBoundingBox().shrink(0.0625)); + entity.absMoveTo(d4, d5, d6, f, f2); + this.player.absMoveTo(d4, d5, d6, this.player.yRot, this.player.xRot); + boolean flag3 = worldserver.noCollision(entity, entity.getBoundingBox().deflate(0.0625)); if (flag && (flag2 || !flag3)) { - entity.setPositionAndRotation(d0, d2, d3, f, f2); - this.player.setPositionAndRotation(d0, d2, d3, this.player.rotationYaw, this.player.rotationPitch); - this.netManager.sendPacket(new SMoveVehiclePacket(entity)); + entity.absMoveTo(d0, d2, d3, f, f2); + this.player.absMoveTo(d0, d2, d3, this.player.yRot, this.player.xRot); + this.connection.send(new ClientboundMoveVehiclePacket(entity)); return; } Player player = this.getPlayer(); @@ -354,8 +377,8 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB to.setX(packetplayinvehiclemove.getX()); to.setY(packetplayinvehiclemove.getY()); to.setZ(packetplayinvehiclemove.getZ()); - to.setYaw(packetplayinvehiclemove.getYaw()); - to.setPitch(packetplayinvehiclemove.getPitch()); + to.setYaw(packetplayinvehiclemove.getYRot()); + to.setPitch(packetplayinvehiclemove.getXRot()); double delta = Math.pow(this.lastPosX - to.getX(), 2.0) + Math.pow(this.lastPosY - to.getY(), 2.0) + Math.pow(this.lastPosZ - to.getZ(), 2.0); float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch()); if ((delta > 0.00390625 || deltaAngle > 10.0f) && !((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { @@ -382,44 +405,44 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } } - this.player.getServerWorld().getChunkProvider().updatePlayerPosition(this.player); - this.player.addMovementStat(this.player.getPosX() - d0, this.player.getPosY() - d2, this.player.getPosZ() - d3); - this.vehicleFloating = d12 >= -0.03125 && !this.minecraftServer.isFlightAllowed() && this.func_241162_a_(entity); - this.lowestRiddenX1 = entity.getPosX(); - this.lowestRiddenY1 = entity.getPosY(); - this.lowestRiddenZ1 = entity.getPosZ(); + this.player.getLevel().getChunkSource().move(this.player); + this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d2, this.player.getZ() - d3); + this.clientVehicleIsFloating = d12 >= -0.03125 && !this.minecraftServer.isFlightAllowed() && this.noBlocksAround(entity); + this.vehicleLastGoodX = entity.getX(); + this.vehicleLastGoodY = entity.getY(); + this.vehicleLastGoodZ = entity.getZ(); } } } - @Inject(method = "processConfirmTeleport", - at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/network/play/ServerPlayNetHandler;targetPos:Lnet/minecraft/util/math/vector/Vector3d;"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;isInvulnerableDimensionChange()Z"))) - private void arclight$updateLoc(CConfirmTeleportPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleAcceptTeleportPacket", + at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;awaitingPositionFromClient:Lnet/minecraft/world/phys/Vec3;"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;isChangingDimension()Z"))) + private void arclight$updateLoc(ServerboundAcceptTeleportationPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) this.player).bridge$isValid()) { - this.player.getServerWorld().getChunkProvider().updatePlayerPosition(this.player); + this.player.getLevel().getChunkSource().move(this.player); } } - @Inject(method = "processConfirmTeleport", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/network/play/ServerPlayNetHandler;teleportId:I")) - private void arclight$confirm(CConfirmTeleportPacket packetIn, CallbackInfo ci) { - if (this.targetPos == null) { + @Inject(method = "handleAcceptTeleportPacket", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;awaitingTeleport:I")) + private void arclight$confirm(ServerboundAcceptTeleportationPacket packetIn, CallbackInfo ci) { + if (this.awaitingPositionFromClient == null) { ci.cancel(); } } - @Inject(method = "processSelectTrade", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/container/MerchantContainer;setCurrentRecipeIndex(I)V")) - private void arclight$tradeSelect(CSelectTradePacket packetIn, CallbackInfo ci, int i, Container container) { - CraftEventFactory.callTradeSelectEvent(this.player, i, (MerchantContainer) container); + @Inject(method = "handleSelectTrade", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/MerchantMenu;setSelectionHint(I)V")) + private void arclight$tradeSelect(ServerboundSelectTradePacket packetIn, CallbackInfo ci, int i, AbstractContainerMenu container) { + CraftEventFactory.callTradeSelectEvent(this.player, i, (MerchantMenu) container); } - @Inject(method = "processEditBook", cancellable = true, at = @At("HEAD")) - private void arclight$editBookSpam(CEditBookPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleEditBook", cancellable = true, at = @At("HEAD")) + private void arclight$editBookSpam(ServerboundEditBookPacket packetIn, CallbackInfo ci) { if (this.lastBookTick == 0) { this.lastBookTick = ArclightConstants.currentTick - 20; } if (this.lastBookTick + 20 > ArclightConstants.currentTick) { - PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.minecraftServer); + PacketUtils.ensureRunningOnSameThread(packetIn, (ServerGamePacketListenerImpl) (Object) this, this.minecraftServer); this.disconnect("Book edited too quickly!"); return; } @@ -431,13 +454,13 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - private void func_244536_a(List p_244536_1_, int p_244536_2_) { - ItemStack itemstack = this.player.inventory.getStackInSlot(p_244536_2_); + private void updateBookContents(List p_244536_1_, int p_244536_2_) { + ItemStack itemstack = this.player.inventory.getItem(p_244536_2_); if (itemstack.getItem() == Items.WRITABLE_BOOK) { - ListNBT listnbt = new ListNBT(); - p_244536_1_.stream().map(StringNBT::valueOf).forEach(listnbt::add); + ListTag listnbt = new ListTag(); + p_244536_1_.stream().map(StringTag::valueOf).forEach(listnbt::add); ItemStack old = itemstack.copy(); - itemstack.setTagInfo("pages", listnbt); + itemstack.addTagElement("pages", listnbt); CraftEventFactory.handleEditBookEvent(player, p_244536_2_, old, itemstack); } } @@ -447,27 +470,27 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - private void func_244534_a(String p_244534_1_, List p_244534_2_, int p_244534_3_) { - ItemStack itemstack = this.player.inventory.getStackInSlot(p_244534_3_); + private void signBook(String p_244534_1_, List p_244534_2_, int p_244534_3_) { + ItemStack itemstack = this.player.inventory.getItem(p_244534_3_); if (itemstack.getItem() == Items.WRITABLE_BOOK) { ItemStack itemstack1 = new ItemStack(Items.WRITTEN_BOOK); - CompoundNBT compoundnbt = itemstack.getTag(); + CompoundTag compoundnbt = itemstack.getTag(); if (compoundnbt != null) { itemstack1.setTag(compoundnbt.copy()); } - itemstack1.setTagInfo("author", StringNBT.valueOf(this.player.getName().getString())); - itemstack1.setTagInfo("title", StringNBT.valueOf(p_244534_1_)); - ListNBT listnbt = new ListNBT(); + itemstack1.addTagElement("author", StringTag.valueOf(this.player.getName().getString())); + itemstack1.addTagElement("title", StringTag.valueOf(p_244534_1_)); + ListTag listnbt = new ListTag(); for (String s : p_244534_2_) { - ITextComponent itextcomponent = new StringTextComponent(s); - String s1 = ITextComponent.Serializer.toJson(itextcomponent); - listnbt.add(StringNBT.valueOf(s1)); + Component itextcomponent = new TextComponent(s); + String s1 = Component.Serializer.toJson(itextcomponent); + listnbt.add(StringTag.valueOf(s1)); } - itemstack1.setTagInfo("pages", listnbt); - this.player.inventory.setInventorySlotContents(p_244534_3_, CraftEventFactory.handleEditBookEvent(player, p_244534_3_, itemstack, itemstack1)); + itemstack1.addTagElement("pages", listnbt); + this.player.inventory.setItem(p_244534_3_, CraftEventFactory.handleEditBookEvent(player, p_244534_3_, itemstack, itemstack1)); } } @@ -476,56 +499,56 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processPlayer(CPlayerPacket packetplayinflying) { - PacketThreadUtil.checkThreadAndEnqueue(packetplayinflying, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); - if (isMovePlayerPacketInvalid(packetplayinflying)) { - this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_player_movement")); + public void handleMovePlayer(ServerboundMovePlayerPacket packetplayinflying) { + PacketUtils.ensureRunningOnSameThread(packetplayinflying, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); + if (containsInvalidValues(packetplayinflying)) { + this.disconnect(new TranslatableComponent("multiplayer.disconnect.invalid_player_movement")); } else { - ServerWorld worldserver = this.player.getServerWorld(); - if (!this.player.queuedEndExit && !((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { - if (this.networkTickCount == 0) { - this.captureCurrentPosition(); + ServerLevel worldserver = this.player.getLevel(); + if (!this.player.wonGame && !((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { + if (this.tickCount == 0) { + this.resetPosition(); } - if (this.targetPos != null) { - if (this.networkTickCount - this.lastPositionUpdate > 20) { - this.lastPositionUpdate = this.networkTickCount; - this.setPlayerLocation(this.targetPos.x, this.targetPos.y, this.targetPos.z, this.player.rotationYaw, this.player.rotationPitch); + if (this.awaitingPositionFromClient != null) { + if (this.tickCount - this.awaitingTeleportTime > 20) { + this.awaitingTeleportTime = this.tickCount; + this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.yRot, this.player.xRot); } this.allowedPlayerTicks = 20; } else { - this.lastPositionUpdate = this.networkTickCount; + this.awaitingTeleportTime = this.tickCount; if (this.player.isPassenger()) { - this.player.setPositionAndRotation(this.player.getPosX(), this.player.getPosY(), this.player.getPosZ(), packetplayinflying.getYaw(this.player.rotationYaw), packetplayinflying.getPitch(this.player.rotationPitch)); - this.player.getServerWorld().getChunkProvider().updatePlayerPosition(this.player); + this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), packetplayinflying.getYRot(this.player.yRot), packetplayinflying.getXRot(this.player.xRot)); + this.player.getLevel().getChunkSource().move(this.player); this.allowedPlayerTicks = 20; } else { - double prevX = this.player.getPosX(); - double prevY = this.player.getPosY(); - double prevZ = this.player.getPosZ(); - float prevYaw = this.player.rotationYaw; - float prevPitch = this.player.rotationPitch; - double d0 = this.player.getPosX(); - double d1 = this.player.getPosY(); - double d2 = this.player.getPosZ(); - double d3 = this.player.getPosY(); - double d4 = packetplayinflying.getX(this.player.getPosX()); - double d5 = packetplayinflying.getY(this.player.getPosY()); - double d6 = packetplayinflying.getZ(this.player.getPosZ()); - float f = packetplayinflying.getYaw(this.player.rotationYaw); - float f1 = packetplayinflying.getPitch(this.player.rotationPitch); + double prevX = this.player.getX(); + double prevY = this.player.getY(); + double prevZ = this.player.getZ(); + float prevYaw = this.player.yRot; + float prevPitch = this.player.xRot; + double d0 = this.player.getX(); + double d1 = this.player.getY(); + double d2 = this.player.getZ(); + double d3 = this.player.getY(); + double d4 = packetplayinflying.getX(this.player.getX()); + double d5 = packetplayinflying.getY(this.player.getY()); + double d6 = packetplayinflying.getZ(this.player.getZ()); + float f = packetplayinflying.getYRot(this.player.yRot); + float f1 = packetplayinflying.getXRot(this.player.xRot); double d7 = d4 - this.firstGoodX; double d8 = d5 - this.firstGoodY; double d9 = d6 - this.firstGoodZ; - double d10 = this.player.getMotion().lengthSquared(); + double d10 = this.player.getDeltaMovement().lengthSqr(); double d11 = d7 * d7 + d8 * d8 + d9 * d9; if (this.player.isSleeping()) { if (d11 > 1.0) { - this.setPlayerLocation(this.player.getPosX(), this.player.getPosY(), this.player.getPosZ(), packetplayinflying.getYaw(this.player.rotationYaw), packetplayinflying.getPitch(this.player.rotationPitch)); + this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), packetplayinflying.getYRot(this.player.yRot), packetplayinflying.getXRot(this.player.xRot)); } } else { boolean flag; - ++this.movePacketCounter; - int i = this.movePacketCounter - this.lastMovePacketCounter; + ++this.receivedMovePacketCount; + int i = this.receivedMovePacketCount - this.knownMovePacketCount; this.allowedPlayerTicks = (int) ((long) this.allowedPlayerTicks + (System.currentTimeMillis() / 50L - (long) this.lastTick)); this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1); this.lastTick = (int) (System.currentTimeMillis() / 50L); @@ -533,56 +556,56 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i); i = 1; } - this.allowedPlayerTicks = packetplayinflying.rotating || d11 > 0.0 ? --this.allowedPlayerTicks : 20; - double speed = this.player.abilities.isFlying ? (double) (this.player.abilities.flySpeed * 20.0f) : (double) (this.player.abilities.walkSpeed * 10.0f); - if (!(this.player.isInvulnerableDimensionChange() || this.player.getServerWorld().getGameRules().getBoolean(GameRules.DISABLE_ELYTRA_MOVEMENT_CHECK) && this.player.isElytraFlying())) { + this.allowedPlayerTicks = packetplayinflying.hasRot || d11 > 0.0 ? --this.allowedPlayerTicks : 20; + double speed = this.player.abilities.flying ? (double) (this.player.abilities.flyingSpeed * 20.0f) : (double) (this.player.abilities.walkingSpeed * 10.0f); + if (!(this.player.isChangingDimension() || this.player.getLevel().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) && this.player.isFallFlying())) { float f2; - float f3 = f2 = this.player.isElytraFlying() ? 300.0f : 100.0f; - if (d11 - d10 > Math.max(f2, Math.pow(SpigotConfig.movedTooQuicklyMultiplier * (double) i * speed, 2.0)) && !this.func_217264_d()) { + float f3 = f2 = this.player.isFallFlying() ? 300.0f : 100.0f; + if (d11 - d10 > Math.max(f2, Math.pow(SpigotConfig.movedTooQuicklyMultiplier * (double) i * speed, 2.0)) && !this.isSingleplayerOwner()) { LOGGER.warn("{} moved too quickly! {},{},{}", this.player.getName().getString(), d7, d8, d9); - this.setPlayerLocation(this.player.getPosX(), this.player.getPosY(), this.player.getPosZ(), this.player.rotationYaw, this.player.rotationPitch); + this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.yRot, this.player.xRot); return; } } - AxisAlignedBB axisalignedbb = this.player.getBoundingBox(); + AABB axisalignedbb = this.player.getBoundingBox(); d7 = d4 - this.lastGoodX; d8 = d5 - this.lastGoodY; d9 = d6 - this.lastGoodZ; boolean bl = flag = d8 > 0.0; if (this.player.isOnGround() && !packetplayinflying.isOnGround() && flag) { - this.player.jump(); + this.player.jumpFromGround(); } - this.player.move(MoverType.PLAYER, new Vector3d(d7, d8, d9)); + this.player.move(MoverType.PLAYER, new Vec3(d7, d8, d9)); this.player.setOnGround(packetplayinflying.isOnGround()); double d12 = d8; - d7 = d4 - this.player.getPosX(); - d8 = d5 - this.player.getPosY(); + d7 = d4 - this.player.getX(); + d8 = d5 - this.player.getY(); if (d8 > -0.5 || d8 < 0.5) { d8 = 0.0; } - d9 = d6 - this.player.getPosZ(); + d9 = d6 - this.player.getZ(); d11 = d7 * d7 + d8 * d8 + d9 * d9; boolean flag1 = false; - if (!this.player.isInvulnerableDimensionChange() && d11 > SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.interactionManager.isCreative() && this.player.interactionManager.getGameType() != GameType.SPECTATOR) { + if (!this.player.isChangingDimension() && d11 > SpigotConfig.movedWronglyThreshold && !this.player.isSleeping() && !this.player.gameMode.isCreative() && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR) { flag1 = true; LOGGER.warn("{} moved wrongly!", this.player.getName().getString()); } - this.player.setPositionAndRotation(d4, d5, d6, f, f1); - if (!this.player.noClip && !this.player.isSleeping() && (flag1 && worldserver.hasNoCollisions(this.player, axisalignedbb) || this.func_241163_a_(worldserver, axisalignedbb))) { - this.setPlayerLocation(d0, d1, d2, f, f1); + this.player.absMoveTo(d4, d5, d6, f, f1); + if (!this.player.noPhysics && !this.player.isSleeping() && (flag1 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) { + this.teleport(d0, d1, d2, f, f1); } else { - this.player.setPositionAndRotation(prevX, prevY, prevZ, prevYaw, prevPitch); + this.player.absMoveTo(prevX, prevY, prevZ, prevYaw, prevPitch); CraftPlayer player = this.getPlayer(); Location from = new Location(player.getWorld(), this.lastPosX, this.lastPosY, this.lastPosZ, this.lastYaw, this.lastPitch); Location to = player.getLocation().clone(); - if (packetplayinflying.moving) { + if (packetplayinflying.hasPos) { to.setX(packetplayinflying.x); to.setY(packetplayinflying.y); to.setZ(packetplayinflying.z); } - if (packetplayinflying.rotating) { - to.setYaw(packetplayinflying.yaw); - to.setPitch(packetplayinflying.pitch); + if (packetplayinflying.hasRot) { + to.setYaw(packetplayinflying.yRot); + to.setPitch(packetplayinflying.xRot); } double delta = Math.pow(this.lastPosX - to.getX(), 2.0) + Math.pow(this.lastPosY - to.getY(), 2.0) + Math.pow(this.lastPosZ - to.getZ(), 2.0); float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch()); @@ -610,17 +633,17 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } } - this.player.setPositionAndRotation(d4, d5, d6, f, f1); - this.floating = d12 >= -0.03125 && this.player.interactionManager.getGameType() != GameType.SPECTATOR && !this.minecraftServer.isFlightAllowed() && !this.player.abilities.allowFlying && !this.player.isPotionActive(Effects.LEVITATION) && !this.player.isElytraFlying() && this.func_241162_a_(this.player) && !this.player.isSpinAttacking(); - this.player.getServerWorld().getChunkProvider().updatePlayerPosition(this.player); - this.player.handleFalling(this.player.getPosY() - d3, packetplayinflying.isOnGround()); + this.player.absMoveTo(d4, d5, d6, f, f1); + this.clientIsFloating = d12 >= -0.03125 && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR && !this.minecraftServer.isFlightAllowed() && !this.player.abilities.mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && this.noBlocksAround(this.player) && !this.player.isAutoSpinAttack(); + this.player.getLevel().getChunkSource().move(this.player); + this.player.doCheckFallDamage(this.player.getY() - d3, packetplayinflying.isOnGround()); if (flag) { this.player.fallDistance = 0.0f; } - this.player.addMovementStat(this.player.getPosX() - d0, this.player.getPosY() - d1, this.player.getPosZ() - d2); - this.lastGoodX = this.player.getPosX(); - this.lastGoodY = this.player.getPosY(); - this.lastGoodZ = this.player.getPosZ(); + this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2); + this.lastGoodX = this.player.getX(); + this.lastGoodY = this.player.getY(); + this.lastGoodZ = this.player.getZ(); } } } @@ -634,36 +657,36 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processPlayerDigging(CPlayerDiggingPacket packetplayinblockdig) { - PacketThreadUtil.checkThreadAndEnqueue(packetplayinblockdig, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handlePlayerAction(ServerboundPlayerActionPacket packetplayinblockdig) { + PacketUtils.ensureRunningOnSameThread(packetplayinblockdig, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } - BlockPos blockposition = packetplayinblockdig.getPosition(); - this.player.markPlayerActive(); - CPlayerDiggingPacket.Action packetplayinblockdig_enumplayerdigtype = packetplayinblockdig.getAction(); + BlockPos blockposition = packetplayinblockdig.getPos(); + this.player.resetLastActionTime(); + ServerboundPlayerActionPacket.Action packetplayinblockdig_enumplayerdigtype = packetplayinblockdig.getAction(); switch (packetplayinblockdig_enumplayerdigtype) { case SWAP_ITEM_WITH_OFFHAND: { if (!this.player.isSpectator()) { - ItemStack itemstack = this.player.getHeldItem(Hand.OFF_HAND); + ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND); CraftItemStack mainHand = CraftItemStack.asCraftMirror(itemstack); - CraftItemStack offHand = CraftItemStack.asCraftMirror(this.player.getHeldItem(Hand.MAIN_HAND)); + CraftItemStack offHand = CraftItemStack.asCraftMirror(this.player.getItemInHand(InteractionHand.MAIN_HAND)); PlayerSwapHandItemsEvent swapItemsEvent = new PlayerSwapHandItemsEvent(this.getPlayer(), mainHand.clone(), offHand.clone()); this.server.getPluginManager().callEvent(swapItemsEvent); if (swapItemsEvent.isCancelled()) { return; } if (swapItemsEvent.getOffHandItem().equals(offHand)) { - this.player.setHeldItem(Hand.OFF_HAND, this.player.getHeldItem(Hand.MAIN_HAND)); + this.player.setItemInHand(InteractionHand.OFF_HAND, this.player.getItemInHand(InteractionHand.MAIN_HAND)); } else { - this.player.setHeldItem(Hand.OFF_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getOffHandItem())); + this.player.setItemInHand(InteractionHand.OFF_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getOffHandItem())); } if (swapItemsEvent.getMainHandItem().equals(mainHand)) { - this.player.setHeldItem(Hand.MAIN_HAND, itemstack); + this.player.setItemInHand(InteractionHand.MAIN_HAND, itemstack); } else { - this.player.setHeldItem(Hand.MAIN_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getMainHandItem())); + this.player.setItemInHand(InteractionHand.MAIN_HAND, CraftItemStack.asNMSCopy(swapItemsEvent.getMainHandItem())); } - this.player.resetActiveHand(); + this.player.stopUsingItem(); } return; } @@ -691,13 +714,13 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB return; } case RELEASE_USE_ITEM: { - this.player.stopActiveHand(); + this.player.releaseUsingItem(); return; } case START_DESTROY_BLOCK: case ABORT_DESTROY_BLOCK: case STOP_DESTROY_BLOCK: { - this.player.interactionManager.func_225416_a(blockposition, packetplayinblockdig_enumplayerdigtype, packetplayinblockdig.getFacing(), this.minecraftServer.getBuildLimit()); + this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packetplayinblockdig.getDirection(), this.minecraftServer.getMaxBuildHeight()); return; } default: { @@ -706,8 +729,8 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Inject(method = "processTryUseItemOnBlock", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/entity/player/ServerPlayerEntity;getServerWorld()Lnet/minecraft/world/server/ServerWorld;")) - private void arclight$frozenUseItem(CPlayerTryUseItemOnBlockPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleUseItemOn", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerPlayer;getLevel()Lnet/minecraft/server/level/ServerLevel;")) + private void arclight$frozenUseItem(ServerboundUseItemOnPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { ci.cancel(); } @@ -716,9 +739,9 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Inject(method = "processTryUseItemOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerInteractionManager;func_219441_a(Lnet/minecraft/entity/player/ServerPlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/math/BlockRayTraceResult;)Lnet/minecraft/util/ActionResultType;")) - private void arclight$checkDistance(CPlayerTryUseItemOnBlockPacket packetIn, CallbackInfo ci) { - this.player.stopActiveHand(); + @Inject(method = "handleUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;")) + private void arclight$checkDistance(ServerboundUseItemOnPacket packetIn, CallbackInfo ci) { + this.player.releaseUsingItem(); } private int limitedPackets; @@ -743,70 +766,70 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processTryUseItem(CPlayerTryUseItemPacket packet) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handleUseItem(ServerboundUseItemPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } if (!this.checkLimit(((TimestampedPacket) packet).bridge$timestamp())) { return; } - ServerWorld worldserver = this.player.getServerWorld(); - Hand enumhand = packet.getHand(); - ItemStack itemstack = this.player.getHeldItem(enumhand); - this.player.markPlayerActive(); + ServerLevel worldserver = this.player.getLevel(); + InteractionHand enumhand = packet.getHand(); + ItemStack itemstack = this.player.getItemInHand(enumhand); + this.player.resetLastActionTime(); if (!itemstack.isEmpty()) { - float f1 = this.player.rotationPitch; - float f2 = this.player.rotationYaw; - double d0 = this.player.getPosX(); - double d2 = this.player.getPosY() + this.player.getEyeHeight(); - double d3 = this.player.getPosZ(); - Vector3d vec3d = new Vector3d(d0, d2, d3); - float f3 = MathHelper.cos(-f2 * 0.017453292f - 3.1415927f); - float f4 = MathHelper.sin(-f2 * 0.017453292f - 3.1415927f); - float f5 = -MathHelper.cos(-f1 * 0.017453292f); - float f6 = MathHelper.sin(-f1 * 0.017453292f); + float f1 = this.player.xRot; + float f2 = this.player.yRot; + double d0 = this.player.getX(); + double d2 = this.player.getY() + this.player.getEyeHeight(); + double d3 = this.player.getZ(); + Vec3 vec3d = new Vec3(d0, d2, d3); + float f3 = Mth.cos(-f2 * 0.017453292f - 3.1415927f); + float f4 = Mth.sin(-f2 * 0.017453292f - 3.1415927f); + float f5 = -Mth.cos(-f1 * 0.017453292f); + float f6 = Mth.sin(-f1 * 0.017453292f); float f7 = f4 * f5; float f8 = f3 * f5; - double d4 = (this.player.interactionManager.getGameType() == GameType.CREATIVE) ? 5.0 : 4.5; - Vector3d vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4); - BlockRayTraceResult movingobjectposition = this.player.world.rayTraceBlocks(new RayTraceContext(vec3d, vec3d2, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, this.player)); + double d4 = (this.player.gameMode.getGameModeForPlayer() == GameType.CREATIVE) ? 5.0 : 4.5; + Vec3 vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4); + BlockHitResult movingobjectposition = this.player.level.clip(new ClipContext(vec3d, vec3d2, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, this.player)); boolean cancelled; - if (movingobjectposition == null || movingobjectposition.getType() != RayTraceResult.Type.BLOCK) { + if (movingobjectposition == null || movingobjectposition.getType() != HitResult.Type.BLOCK) { PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack, enumhand); cancelled = (event.useItemInHand() == Event.Result.DENY); - } else if (((PlayerInteractionManagerBridge) this.player.interactionManager).bridge$isFiredInteract()) { - ((PlayerInteractionManagerBridge) this.player.interactionManager).bridge$setFiredInteract(false); - cancelled = ((PlayerInteractionManagerBridge) this.player.interactionManager).bridge$getInteractResult(); + } else if (((PlayerInteractionManagerBridge) this.player.gameMode).bridge$isFiredInteract()) { + ((PlayerInteractionManagerBridge) this.player.gameMode).bridge$setFiredInteract(false); + cancelled = ((PlayerInteractionManagerBridge) this.player.gameMode).bridge$getInteractResult(); } else { - BlockRayTraceResult movingobjectpositionblock = movingobjectposition; - PlayerInteractEvent event2 = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getPos(), movingobjectpositionblock.getFace(), itemstack, true, enumhand); + BlockHitResult movingobjectpositionblock = movingobjectposition; + PlayerInteractEvent event2 = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand); cancelled = (event2.useItemInHand() == Event.Result.DENY); } if (cancelled) { ((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity().updateInventory(); return; } - ActionResultType actionresulttype = this.player.interactionManager.processRightClick(this.player, worldserver, itemstack, enumhand); - if (actionresulttype.isSuccess()) { + InteractionResult actionresulttype = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); + if (actionresulttype.shouldSwing()) { this.player.swing(enumhand, true); } } } - @Inject(method = "handleSpectate", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;teleport(Lnet/minecraft/world/server/ServerWorld;DDDFF)V")) - private void arclight$spectateTeleport(CSpectatePacket packetIn, CallbackInfo ci) { + @Inject(method = "handleTeleportToEntityPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;teleportTo(Lnet/minecraft/server/level/ServerLevel;DDDFF)V")) + private void arclight$spectateTeleport(ServerboundTeleportToEntityPacket packetIn, CallbackInfo ci) { ((ServerPlayerEntityBridge) this.player).bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause.SPECTATE); } - @Inject(method = "handleResourcePackStatus", at = @At("HEAD")) - private void arclight$handleResourcePackStatus(CResourcePackStatusPacket packetIn, CallbackInfo ci) { - PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + @Inject(method = "handleResourcePackResponse", at = @At("HEAD")) + private void arclight$handleResourcePackStatus(ServerboundResourcePackPacket packetIn, CallbackInfo ci) { + PacketUtils.ensureRunningOnSameThread(packetIn, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); this.server.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getPlayer(), PlayerResourcePackStatusEvent.Status.values()[packetIn.action.ordinal()])); } @Inject(method = "onDisconnect", cancellable = true, at = @At("HEAD")) - private void arclight$returnIfProcessed(ITextComponent reason, CallbackInfo ci) { + private void arclight$returnIfProcessed(Component reason, CallbackInfo ci) { if (processedDisconnect) { ci.cancel(); } else { @@ -814,28 +837,28 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Redirect(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;func_232641_a_(Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/util/text/ChatType;Ljava/util/UUID;)V")) - public void arclight$captureQuit(PlayerList playerList, ITextComponent p_232641_1_, ChatType p_232641_2_, UUID p_232641_3_) { + @Redirect(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/ChatType;Ljava/util/UUID;)V")) + public void arclight$captureQuit(PlayerList playerList, Component p_232641_1_, ChatType p_232641_2_, UUID p_232641_3_) { // do nothing } - @Inject(method = "onDisconnect", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/management/PlayerList;playerLoggedOut(Lnet/minecraft/entity/player/ServerPlayerEntity;)V")) - public void arclight$processQuit(ITextComponent reason, CallbackInfo ci) { + @Inject(method = "onDisconnect", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/players/PlayerList;remove(Lnet/minecraft/server/level/ServerPlayer;)V")) + public void arclight$processQuit(Component reason, CallbackInfo ci) { String quitMessage = ArclightCaptures.getQuitMessage(); if (quitMessage != null && quitMessage.length() > 0) { ((PlayerListBridge) this.minecraftServer.getPlayerList()).bridge$sendMessage(CraftChatMessage.fromString(quitMessage)); } } - @Inject(method = "sendPacket(Lnet/minecraft/network/IPacket;Lio/netty/util/concurrent/GenericFutureListener;)V", cancellable = true, at = @At("HEAD")) - private void arclight$updateCompassTarget(IPacket packetIn, GenericFutureListener> futureListeners, CallbackInfo ci) { + @Inject(method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", cancellable = true, at = @At("HEAD")) + private void arclight$updateCompassTarget(Packet packetIn, GenericFutureListener> futureListeners, CallbackInfo ci) { if (packetIn == null || processedDisconnect) { ci.cancel(); return; } - if (packetIn instanceof SWorldSpawnChangedPacket) { - SWorldSpawnChangedPacket packet6 = (SWorldSpawnChangedPacket) packetIn; - ((ServerPlayerEntityBridge) this.player).bridge$setCompassTarget(new Location(this.getPlayer().getWorld(), packet6.spawnPos.getX(), packet6.spawnPos.getY(), packet6.spawnPos.getZ())); + if (packetIn instanceof ClientboundSetDefaultSpawnPositionPacket) { + ClientboundSetDefaultSpawnPositionPacket packet6 = (ClientboundSetDefaultSpawnPositionPacket) packetIn; + ((ServerPlayerEntityBridge) this.player).bridge$setCompassTarget(new Location(this.getPlayer().getWorld(), packet6.pos.getX(), packet6.pos.getY(), packet6.pos.getZ())); } } @@ -844,24 +867,24 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processHeldItemChange(CHeldItemChangePacket packet) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } - if (packet.getSlotId() >= 0 && packet.getSlotId() < PlayerInventory.getHotbarSize()) { - PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.currentItem, packet.getSlotId()); + if (packet.getSlot() >= 0 && packet.getSlot() < net.minecraft.world.entity.player.Inventory.getSelectionSize()) { + PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.selected, packet.getSlot()); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { - this.sendPacket(new SHeldItemChangePacket(this.player.inventory.currentItem)); - this.player.markPlayerActive(); + this.send(new ClientboundSetCarriedItemPacket(this.player.inventory.selected)); + this.player.resetLastActionTime(); return; } - if (this.player.inventory.currentItem != packet.getSlotId() && this.player.getActiveHand() == Hand.MAIN_HAND) { - this.player.resetActiveHand(); + if (this.player.inventory.selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { + this.player.stopUsingItem(); } - this.player.inventory.currentItem = packet.getSlotId(); - this.player.markPlayerActive(); + this.player.inventory.selected = packet.getSlot(); + this.player.resetLastActionTime(); } else { LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); this.disconnect("Invalid hotbar selection (Hacking?)"); @@ -873,27 +896,27 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processChatMessage(CChatMessagePacket packet) { - if (this.minecraftServer.isServerStopped()) { + public void handleChat(ServerboundChatPacket packet) { + if (this.minecraftServer.isStopped()) { return; } boolean isSync = packet.getMessage().startsWith("/"); if (packet.getMessage().startsWith("/")) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); } - if (this.player.removed || this.player.getChatVisibility() == ChatVisibility.HIDDEN) { - this.sendPacket(new SChatPacket((new TranslationTextComponent("chat.cannotSend")).mergeStyle(TextFormatting.RED), ChatType.SYSTEM, Util.DUMMY_UUID)); + if (this.player.removed || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { + this.send(new ClientboundChatPacket((new TranslatableComponent("chat.cannotSend")).withStyle(ChatFormatting.RED), ChatType.SYSTEM, Util.NIL_UUID)); } else { - this.player.markPlayerActive(); + this.player.resetLastActionTime(); String s = org.apache.commons.lang3.StringUtils.normalizeSpace(packet.getMessage()); for (int i = 0; i < s.length(); ++i) { - if (!SharedConstants.isAllowedCharacter(s.charAt(i))) { + if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) { if (!isSync) { class Disconnect extends Waitable { @Override protected Object evaluate() { - disconnect(new TranslationTextComponent("multiplayer.disconnect.illegal_characters")); + disconnect(new TranslatableComponent("multiplayer.disconnect.illegal_characters")); return null; } } @@ -909,14 +932,14 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB throw new RuntimeException(e); } } - this.disconnect(new TranslationTextComponent("multiplayer.disconnect.illegal_characters")); + this.disconnect(new TranslatableComponent("multiplayer.disconnect.illegal_characters")); return; } } if (isSync) { try { this.server.playerCommandState = true; - this.handleSlashCommand(s); + this.handleCommand(s); } finally { this.server.playerCommandState = false; } @@ -926,19 +949,19 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } else if (this.getPlayer().isConversing()) { String conversationInput = s; ((MinecraftServerBridge) this.minecraftServer).bridge$queuedProcess(() -> this.getPlayer().acceptConversationInput(conversationInput)); - } else if (this.player.getChatVisibility() == ChatVisibility.SYSTEM) { - this.sendPacket(new SChatPacket((new TranslationTextComponent("chat.cannotSend")).mergeStyle(TextFormatting.RED), ChatType.SYSTEM, Util.DUMMY_UUID)); + } else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) { + this.send(new ClientboundChatPacket((new TranslatableComponent("chat.cannotSend")).withStyle(ChatFormatting.RED), ChatType.SYSTEM, Util.NIL_UUID)); } else { this.chat(s, true); } - this.chatSpamThresholdCount += 20; - if (this.chatSpamThresholdCount > 200 && !this.minecraftServer.getPlayerList().canSendCommands(this.player.getGameProfile())) { + this.chatSpamTickCount += 20; + if (this.chatSpamTickCount > 200 && !this.minecraftServer.getPlayerList().isOp(this.player.getGameProfile())) { if (!isSync) { class Disconnect2 extends Waitable { @Override protected Object evaluate() { - disconnect(new TranslationTextComponent("disconnect.spam")); + disconnect(new TranslatableComponent("disconnect.spam")); return null; } } @@ -954,19 +977,19 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB throw new RuntimeException(e2); } } - this.disconnect(new TranslationTextComponent("disconnect.spam")); + this.disconnect(new TranslatableComponent("disconnect.spam")); } } } public void chat(String s, boolean async) { - if (s.isEmpty() || this.player.getChatVisibility() == ChatVisibility.HIDDEN) { + if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { return; } - ServerPlayNetHandler handler = (ServerPlayNetHandler) (Object) this; + ServerGamePacketListenerImpl handler = (ServerGamePacketListenerImpl) (Object) this; if (!async && s.startsWith("/")) { - this.handleSlashCommand(s); - } else if (this.player.getChatVisibility() != ChatVisibility.SYSTEM) { + this.handleCommand(s); + } else if (this.player.getChatVisibility() != ChatVisiblity.SYSTEM) { Player thisPlayer = this.getPlayer(); AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, thisPlayer, s, new LazyPlayerSet(this.minecraftServer)); this.server.getPluginManager().callEvent(event); @@ -982,11 +1005,11 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB return null; } String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage()); - ITextComponent component = ForgeHooks.onServerChatEvent(handler, queueEvent.getMessage(), ForgeHooks.newChatWithLinks(message)); + Component component = ForgeHooks.onServerChatEvent(handler, queueEvent.getMessage(), ForgeHooks.newChatWithLinks(message)); if (component == null) return null; Bukkit.getConsoleSender().sendMessage(CraftChatMessage.fromComponent(component)); if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) { - for (ServerPlayerEntity player : minecraftServer.getPlayerList().players) { + for (ServerPlayer player : minecraftServer.getPlayerList().players) { ((ServerPlayerEntityBridge) player).bridge$sendMessage(component, thisPlayer.getUniqueId()); } } else { @@ -1017,17 +1040,17 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB return; } s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); - ITextComponent chatWithLinks = ForgeHooks.newChatWithLinks(s); + Component chatWithLinks = ForgeHooks.newChatWithLinks(s); class ForgeChat extends Waitable { @Override protected Void evaluate() { // this is called on main thread - ITextComponent component = ForgeHooks.onServerChatEvent(handler, event.getMessage(), chatWithLinks); + Component component = ForgeHooks.onServerChatEvent(handler, event.getMessage(), chatWithLinks); if (component == null) return null; Bukkit.getConsoleSender().sendMessage(CraftChatMessage.fromComponent(component)); if (((LazyPlayerSet) event.getRecipients()).isLazy()) { - for (ServerPlayerEntity recipient : minecraftServer.getPlayerList().players) { + for (ServerPlayer recipient : minecraftServer.getPlayerList().players) { ((ServerPlayerEntityBridge) recipient).bridge$sendMessage(component, thisPlayer.getUniqueId()); } } else { @@ -1052,7 +1075,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - private void handleSlashCommand(String s) { + private void handleCommand(String s) { if (SpigotConfig.logCommands) { LOGGER.info(this.player.getScoreboardName() + " issued server command: " + s); } @@ -1064,9 +1087,9 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } try { this.server.dispatchCommand(event.getPlayer(), event.getMessage().substring(1)); - } catch (CommandException ex) { + } catch (CommandRuntimeException ex) { player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to perform this command"); - java.util.logging.Logger.getLogger(ServerPlayNetHandler.class.getName()).log(Level.SEVERE, null, ex); + java.util.logging.Logger.getLogger(ServerGamePacketListenerImpl.class.getName()).log(Level.SEVERE, null, ex); } } @@ -1075,52 +1098,52 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void handleAnimation(CAnimateHandPacket packet) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handleAnimate(ServerboundSwingPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } - this.player.markPlayerActive(); - float f1 = this.player.rotationPitch; - float f2 = this.player.rotationYaw; - double d0 = this.player.getPosX(); - double d2 = this.player.getPosY() + this.player.getEyeHeight(); - double d3 = this.player.getPosZ(); - Vector3d vec3d = new Vector3d(d0, d2, d3); - float f3 = MathHelper.cos(-f2 * 0.017453292f - 3.1415927f); - float f4 = MathHelper.sin(-f2 * 0.017453292f - 3.1415927f); - float f5 = -MathHelper.cos(-f1 * 0.017453292f); - float f6 = MathHelper.sin(-f1 * 0.017453292f); + this.player.resetLastActionTime(); + float f1 = this.player.xRot; + float f2 = this.player.yRot; + double d0 = this.player.getX(); + double d2 = this.player.getY() + this.player.getEyeHeight(); + double d3 = this.player.getZ(); + Vec3 vec3d = new Vec3(d0, d2, d3); + float f3 = Mth.cos(-f2 * 0.017453292f - 3.1415927f); + float f4 = Mth.sin(-f2 * 0.017453292f - 3.1415927f); + float f5 = -Mth.cos(-f1 * 0.017453292f); + float f6 = Mth.sin(-f1 * 0.017453292f); float f7 = f4 * f5; float f8 = f3 * f5; - double d4 = (this.player.interactionManager.getGameType() == GameType.CREATIVE) ? 5.0 : 4.5; - Vector3d vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4); - RayTraceResult result = this.player.world.rayTraceBlocks(new RayTraceContext(vec3d, vec3d2, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, this.player)); - if (result == null || result.getType() != RayTraceResult.Type.BLOCK) { - CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getCurrentItem(), Hand.MAIN_HAND); + double d4 = (this.player.gameMode.getGameModeForPlayer() == GameType.CREATIVE) ? 5.0 : 4.5; + Vec3 vec3d2 = vec3d.add(f7 * d4, f6 * d4, f8 * d4); + HitResult result = this.player.level.clip(new ClipContext(vec3d, vec3d2, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, this.player)); + if (result == null || result.getType() != HitResult.Type.BLOCK) { + CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_AIR, this.player.inventory.getSelected(), InteractionHand.MAIN_HAND); } PlayerAnimationEvent event = new PlayerAnimationEvent(this.getPlayer()); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - this.player.swingArm(packet.getHand()); + this.player.swing(packet.getHand()); } - @Inject(method = "processEntityAction", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;markPlayerActive()V")) - private void arclight$toggleAction(CEntityActionPacket packetIn, CallbackInfo ci) { + @Inject(method = "handlePlayerCommand", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V")) + private void arclight$toggleAction(ServerboundPlayerCommandPacket packetIn, CallbackInfo ci) { if (this.player.removed) { ci.cancel(); return; } - if (packetIn.getAction() == CEntityActionPacket.Action.PRESS_SHIFT_KEY || packetIn.getAction() == CEntityActionPacket.Action.RELEASE_SHIFT_KEY) { - PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packetIn.getAction() == CEntityActionPacket.Action.PRESS_SHIFT_KEY); + if (packetIn.getAction() == ServerboundPlayerCommandPacket.Action.PRESS_SHIFT_KEY || packetIn.getAction() == ServerboundPlayerCommandPacket.Action.RELEASE_SHIFT_KEY) { + PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getPlayer(), packetIn.getAction() == ServerboundPlayerCommandPacket.Action.PRESS_SHIFT_KEY); this.server.getPluginManager().callEvent(event); if (event.isCancelled()) { ci.cancel(); } - } else if (packetIn.getAction() == CEntityActionPacket.Action.START_SPRINTING || packetIn.getAction() == CEntityActionPacket.Action.STOP_SPRINTING) { - PlayerToggleSprintEvent e2 = new PlayerToggleSprintEvent(this.getPlayer(), packetIn.getAction() == CEntityActionPacket.Action.START_SPRINTING); + } else if (packetIn.getAction() == ServerboundPlayerCommandPacket.Action.START_SPRINTING || packetIn.getAction() == ServerboundPlayerCommandPacket.Action.STOP_SPRINTING) { + PlayerToggleSprintEvent e2 = new PlayerToggleSprintEvent(this.getPlayer(), packetIn.getAction() == ServerboundPlayerCommandPacket.Action.START_SPRINTING); this.server.getPluginManager().callEvent(e2); if (e2.isCancelled()) { ci.cancel(); @@ -1133,78 +1156,78 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processUseEntity(final CUseEntityPacket packetIn) { - PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handleInteract(final ServerboundInteractPacket packetIn) { + PacketUtils.ensureRunningOnSameThread(packetIn, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } - final ServerWorld world = this.player.getServerWorld(); - final Entity entity = packetIn.getEntityFromWorld(world); + final ServerLevel world = this.player.getLevel(); + final Entity entity = packetIn.getTarget(world); if (entity == player && !player.isSpectator()) { disconnect("Cannot interact with self!"); return; } - this.player.markPlayerActive(); - this.player.setSneaking(packetIn.isSneaking()); + this.player.resetLastActionTime(); + this.player.setShiftKeyDown(packetIn.isUsingSecondaryAction()); if (entity != null) { double d0 = 36.0D; - if (this.player.getDistanceSq(entity) < 36.0D) { - Hand hand = packetIn.getHand(); - ItemStack itemstack = hand != null ? this.player.getHeldItem(hand).copy() : ItemStack.EMPTY; - Optional optional = Optional.empty(); + if (this.player.distanceToSqr(entity) < 36.0D) { + InteractionHand hand = packetIn.getHand(); + ItemStack itemstack = hand != null ? this.player.getItemInHand(hand).copy() : ItemStack.EMPTY; + Optional optional = Optional.empty(); - final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand()); - if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) { - final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity; - final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem(); + final ItemStack itemInHand = this.player.getItemInHand((packetIn.getHand() == null) ? InteractionHand.MAIN_HAND : packetIn.getHand()); + if (packetIn.getAction() == ServerboundInteractPacket.Action.INTERACT || packetIn.getAction() == ServerboundInteractPacket.Action.INTERACT_AT) { + final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob; + final Item origItem = (this.player.inventory.getSelected() == null) ? null : this.player.inventory.getSelected().getItem(); PlayerInteractEntityEvent event; - if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) { - event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); + if (packetIn.getAction() == ServerboundInteractPacket.Action.INTERACT) { + event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); } else { - final Vector3d target = packetIn.getHitVec(); - event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); + final Vec3 target = packetIn.getLocation(); + event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND); } this.server.getPluginManager().callEvent(event); - if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) { - this.sendPacket(new SSpawnMobPacket((LivingEntity) entity)); - this.player.sendContainerToPlayer(this.player.openContainer); + if (entity instanceof AbstractFish && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getSelected() == null || this.player.inventory.getSelected().getItem() != origItem)) { + this.send(new ClientboundAddMobPacket((LivingEntity) entity)); + this.player.refreshContainer(this.player.containerMenu); } - if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) { - this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder())); + if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getSelected() == null || this.player.inventory.getSelected().getItem() != origItem)) { + this.send(new ClientboundSetEntityLinkPacket(entity, ((Mob) entity).getLeashHolder())); } - if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) { - this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true)); + if (event.isCancelled() || this.player.inventory.getSelected() == null || this.player.inventory.getSelected().getItem() != origItem) { + this.send(new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true)); } if (event.isCancelled()) { return; } } - if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) { + if (packetIn.getAction() == ServerboundInteractPacket.Action.INTERACT) { optional = Optional.of(this.player.interactOn(entity, hand)); if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.sendContainerToPlayer(this.player.openContainer); + this.player.refreshContainer(this.player.containerMenu); } - } else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) { - if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null) + } else if (packetIn.getAction() == ServerboundInteractPacket.Action.INTERACT_AT) { + if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getLocation(), hand) != null) return; - optional = Optional.of(entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand)); + optional = Optional.of(entity.interactAt(this.player, packetIn.getLocation(), hand)); if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.sendContainerToPlayer(this.player.openContainer); + this.player.refreshContainer(this.player.containerMenu); } - } else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) { - if ((entity instanceof ItemEntity && AstralSorceryHooks.notInteractable(entity)) || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) { - this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked")); + } else if (packetIn.getAction() == ServerboundInteractPacket.Action.ATTACK) { + if ((entity instanceof ItemEntity && AstralSorceryHooks.notInteractable(entity)) || entity instanceof ExperienceOrb || entity instanceof AbstractArrow || (entity == this.player && !this.player.isSpectator())) { + this.disconnect(new TranslatableComponent("multiplayer.disconnect.invalid_entity_attacked")); LOGGER.warn("Player {} tried to attack an invalid entity", this.player.getName().getString()); return; } - this.player.attackTargetEntityWithCurrentItem(entity); + this.player.attack(entity); if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) { - this.player.sendContainerToPlayer(this.player.openContainer); + this.player.refreshContainer(this.player.containerMenu); } } - if (optional.isPresent() && optional.get().isSuccessOrConsume()) { - CriteriaTriggers.PLAYER_ENTITY_INTERACTION.test(this.player, itemstack, entity); - if (optional.get().isSuccess()) { + if (optional.isPresent() && optional.get().consumesAction()) { + CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(this.player, itemstack, entity); + if (optional.get().shouldSwing()) { this.player.swing(hand, true); } } @@ -1212,8 +1235,8 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Inject(method = "processCloseWindow", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;closeContainer()V")) - private void arclight$invClose(CCloseWindowPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleContainerClose", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;doCloseContainer()V")) + private void arclight$invClose(ServerboundContainerClosePacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { ci.cancel(); } @@ -1225,71 +1248,71 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processClickWindow(CClickWindowPacket packet) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + public void handleContainerClick(ServerboundContainerClickPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) { return; } - this.player.markPlayerActive(); - if (this.player.openContainer.windowId == packet.getWindowId() && this.player.openContainer.getCanCraft(this.player) && this.player.openContainer.canInteractWith(this.player)) { + this.player.resetLastActionTime(); + if (this.player.containerMenu.containerId == packet.getContainerId() && this.player.containerMenu.isSynched(this.player) && this.player.containerMenu.stillValid(this.player)) { boolean cancelled = this.player.isSpectator(); - if (packet.getSlotId() < -1 && packet.getSlotId() != -999) { + if (packet.getSlotNum() < -1 && packet.getSlotNum() != -999) { return; } ArclightCaptures.captureContainerOwner(this.player); - InventoryView inventory = ((ContainerBridge) this.player.openContainer).bridge$getBukkitView(); + InventoryView inventory = ((ContainerBridge) this.player.containerMenu).bridge$getBukkitView(); ArclightCaptures.resetContainerOwner(); - InventoryType.SlotType type = inventory.getSlotType(packet.getSlotId()); + InventoryType.SlotType type = inventory.getSlotType(packet.getSlotNum()); org.bukkit.event.inventory.ClickType click = org.bukkit.event.inventory.ClickType.UNKNOWN; InventoryAction action = InventoryAction.UNKNOWN; ItemStack itemstack = ItemStack.EMPTY; switch (packet.getClickType()) { case PICKUP: { - if (packet.getUsedButton() == 0) { + if (packet.getButtonNum() == 0) { click = org.bukkit.event.inventory.ClickType.LEFT; - } else if (packet.getUsedButton() == 1) { + } else if (packet.getButtonNum() == 1) { click = org.bukkit.event.inventory.ClickType.RIGHT; } - if (packet.getUsedButton() != 0 && packet.getUsedButton() != 1) { + if (packet.getButtonNum() != 0 && packet.getButtonNum() != 1) { break; } action = InventoryAction.NOTHING; - if (packet.getSlotId() == -999) { - if (!this.player.inventory.getItemStack().isEmpty()) { - action = ((packet.getUsedButton() == 0) ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR); + if (packet.getSlotNum() == -999) { + if (!this.player.inventory.getCarried().isEmpty()) { + action = ((packet.getButtonNum() == 0) ? InventoryAction.DROP_ALL_CURSOR : InventoryAction.DROP_ONE_CURSOR); break; } break; } else { - if (packet.getSlotId() < 0) { + if (packet.getSlotNum() < 0) { action = InventoryAction.NOTHING; break; } - Slot slot = this.player.openContainer.getSlot(packet.getSlotId()); + Slot slot = this.player.containerMenu.getSlot(packet.getSlotNum()); if (slot == null) { break; } - ItemStack clickedItem = slot.getStack(); - ItemStack cursor = this.player.inventory.getItemStack(); + ItemStack clickedItem = slot.getItem(); + ItemStack cursor = this.player.inventory.getCarried(); if (clickedItem.isEmpty()) { if (!cursor.isEmpty()) { - action = ((packet.getUsedButton() == 0) ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE); + action = ((packet.getButtonNum() == 0) ? InventoryAction.PLACE_ALL : InventoryAction.PLACE_ONE); break; } break; } else { - if (!slot.canTakeStack(this.player)) { + if (!slot.mayPickup(this.player)) { break; } if (cursor.isEmpty()) { - action = ((packet.getUsedButton() == 0) ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF); + action = ((packet.getButtonNum() == 0) ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF); break; } - if (slot.isItemValid(cursor)) { - if (clickedItem.isItemEqual(cursor) && ItemStack.areItemStackTagsEqual(clickedItem, cursor)) { - int toPlace = (packet.getUsedButton() == 0) ? cursor.getCount() : 1; + if (slot.mayPlace(cursor)) { + if (clickedItem.sameItem(cursor) && ItemStack.tagMatches(clickedItem, cursor)) { + int toPlace = (packet.getButtonNum() == 0) ? cursor.getCount() : 1; toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount()); - toPlace = Math.min(toPlace, slot.inventory.getInventoryStackLimit() - clickedItem.getCount()); + toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount()); if (toPlace == 1) { action = InventoryAction.PLACE_ONE; break; @@ -1308,14 +1331,14 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } break; } else { - if (cursor.getCount() <= slot.getSlotStackLimit()) { + if (cursor.getCount() <= slot.getMaxStackSize()) { action = InventoryAction.SWAP_WITH_CURSOR; break; } break; } } else { - if (cursor.getItem() == clickedItem.getItem() && ItemStack.areItemStackTagsEqual(cursor, clickedItem) && clickedItem.getCount() >= 0 && clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) { + if (cursor.getItem() == clickedItem.getItem() && ItemStack.tagMatches(cursor, clickedItem) && clickedItem.getCount() >= 0 && clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) { action = InventoryAction.PICKUP_ALL; break; } @@ -1325,20 +1348,20 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } case QUICK_MOVE: { - if (packet.getUsedButton() == 0) { + if (packet.getButtonNum() == 0) { click = org.bukkit.event.inventory.ClickType.SHIFT_LEFT; - } else if (packet.getUsedButton() == 1) { + } else if (packet.getButtonNum() == 1) { click = org.bukkit.event.inventory.ClickType.SHIFT_RIGHT; } - if (packet.getUsedButton() != 0 && packet.getUsedButton() != 1) { + if (packet.getButtonNum() != 0 && packet.getButtonNum() != 1) { break; } - if (packet.getSlotId() < 0) { + if (packet.getSlotNum() < 0) { action = InventoryAction.NOTHING; break; } - Slot slot = this.player.openContainer.getSlot(packet.getSlotId()); - if (slot != null && slot.canTakeStack(this.player) && slot.getHasStack()) { + Slot slot = this.player.containerMenu.getSlot(packet.getSlotNum()); + if (slot != null && slot.mayPickup(this.player) && slot.hasItem()) { action = InventoryAction.MOVE_TO_OTHER_INVENTORY; break; } @@ -1346,18 +1369,18 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB break; } case SWAP: { - if ((packet.getUsedButton() < 0 || packet.getUsedButton() >= 9) && packet.getUsedButton() != 40) { + if ((packet.getButtonNum() < 0 || packet.getButtonNum() >= 9) && packet.getButtonNum() != 40) { break; } - click = packet.getUsedButton() == 40 ? ClickType.SWAP_OFFHAND : ClickType.NUMBER_KEY; - Slot clickedSlot = this.player.openContainer.getSlot(packet.getSlotId()); - if (!clickedSlot.canTakeStack(this.player)) { + click = packet.getButtonNum() == 40 ? ClickType.SWAP_OFFHAND : ClickType.NUMBER_KEY; + Slot clickedSlot = this.player.containerMenu.getSlot(packet.getSlotNum()); + if (!clickedSlot.mayPickup(this.player)) { action = InventoryAction.NOTHING; break; } - ItemStack hotbar = this.player.inventory.getStackInSlot(packet.getUsedButton()); - boolean canCleanSwap = hotbar.isEmpty() || (clickedSlot.inventory == this.player.inventory && clickedSlot.isItemValid(hotbar)); - if (clickedSlot.getHasStack()) { + ItemStack hotbar = this.player.inventory.getItem(packet.getButtonNum()); + boolean canCleanSwap = hotbar.isEmpty() || (clickedSlot.container == this.player.inventory && clickedSlot.mayPlace(hotbar)); + if (clickedSlot.hasItem()) { if (canCleanSwap) { action = InventoryAction.HOTBAR_SWAP; break; @@ -1365,7 +1388,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB action = InventoryAction.HOTBAR_MOVE_AND_READD; break; } else { - if (!clickedSlot.getHasStack() && !hotbar.isEmpty() && clickedSlot.isItemValid(hotbar)) { + if (!clickedSlot.hasItem() && !hotbar.isEmpty() && clickedSlot.mayPlace(hotbar)) { action = InventoryAction.HOTBAR_SWAP; break; } @@ -1374,18 +1397,18 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } case CLONE: { - if (packet.getUsedButton() != 2) { + if (packet.getButtonNum() != 2) { click = org.bukkit.event.inventory.ClickType.UNKNOWN; action = InventoryAction.UNKNOWN; break; } click = org.bukkit.event.inventory.ClickType.MIDDLE; - if (packet.getSlotId() < 0) { + if (packet.getSlotNum() < 0) { action = InventoryAction.NOTHING; break; } - Slot slot = this.player.openContainer.getSlot(packet.getSlotId()); - if (slot != null && slot.getHasStack() && this.player.abilities.isCreativeMode && this.player.inventory.getItemStack().isEmpty()) { + Slot slot = this.player.containerMenu.getSlot(packet.getSlotNum()); + if (slot != null && slot.hasItem() && this.player.abilities.instabuild && this.player.inventory.getCarried().isEmpty()) { action = InventoryAction.CLONE_STACK; break; } @@ -1393,30 +1416,30 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB break; } case THROW: { - if (packet.getSlotId() < 0) { + if (packet.getSlotNum() < 0) { click = org.bukkit.event.inventory.ClickType.LEFT; - if (packet.getUsedButton() == 1) { + if (packet.getButtonNum() == 1) { click = org.bukkit.event.inventory.ClickType.RIGHT; } action = InventoryAction.NOTHING; break; } - if (packet.getUsedButton() == 0) { + if (packet.getButtonNum() == 0) { click = org.bukkit.event.inventory.ClickType.DROP; - Slot slot = this.player.openContainer.getSlot(packet.getSlotId()); - if (slot != null && slot.getHasStack() && slot.canTakeStack(this.player) && !slot.getStack().isEmpty() && slot.getStack().getItem() != Item.getItemFromBlock(Blocks.AIR)) { + Slot slot = this.player.containerMenu.getSlot(packet.getSlotNum()); + if (slot != null && slot.hasItem() && slot.mayPickup(this.player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.byBlock(Blocks.AIR)) { action = InventoryAction.DROP_ONE_SLOT; break; } action = InventoryAction.NOTHING; break; } else { - if (packet.getUsedButton() != 1) { + if (packet.getButtonNum() != 1) { break; } click = org.bukkit.event.inventory.ClickType.CONTROL_DROP; - Slot slot = this.player.openContainer.getSlot(packet.getSlotId()); - if (slot != null && slot.getHasStack() && slot.canTakeStack(this.player) && !slot.getStack().isEmpty() && slot.getStack().getItem() != Item.getItemFromBlock(Blocks.AIR)) { + Slot slot = this.player.containerMenu.getSlot(packet.getSlotNum()); + if (slot != null && slot.hasItem() && slot.mayPickup(this.player) && !slot.getItem().isEmpty() && slot.getItem().getItem() != Item.byBlock(Blocks.AIR)) { action = InventoryAction.DROP_ALL_SLOT; break; } @@ -1425,16 +1448,16 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } case QUICK_CRAFT: { - itemstack = this.player.openContainer.slotClick(packet.getSlotId(), packet.getUsedButton(), packet.getClickType(), this.player); + itemstack = this.player.containerMenu.clicked(packet.getSlotNum(), packet.getButtonNum(), packet.getClickType(), this.player); break; } case PICKUP_ALL: { click = org.bukkit.event.inventory.ClickType.DOUBLE_CLICK; action = InventoryAction.NOTHING; - if (packet.getSlotId() < 0 || this.player.inventory.getItemStack().isEmpty()) { + if (packet.getSlotNum() < 0 || this.player.inventory.getCarried().isEmpty()) { break; } - ItemStack cursor2 = this.player.inventory.getItemStack(); + ItemStack cursor2 = this.player.inventory.getCarried(); action = InventoryAction.NOTHING; if (inventory.getTopInventory().contains(CraftMagicNumbers.getMaterial(cursor2.getItem())) || inventory.getBottomInventory().contains(CraftMagicNumbers.getMaterial(cursor2.getItem()))) { action = InventoryAction.COLLECT_TO_CURSOR; @@ -1443,44 +1466,44 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB break; } } - if (packet.getClickType() != net.minecraft.inventory.container.ClickType.QUICK_CRAFT) { + if (packet.getClickType() != net.minecraft.world.inventory.ClickType.QUICK_CRAFT) { InventoryClickEvent event; if (click == org.bukkit.event.inventory.ClickType.NUMBER_KEY) { - event = new InventoryClickEvent(inventory, type, packet.getSlotId(), click, action, packet.getUsedButton()); + event = new InventoryClickEvent(inventory, type, packet.getSlotNum(), click, action, packet.getButtonNum()); } else { - event = new InventoryClickEvent(inventory, type, packet.getSlotId(), click, action); + event = new InventoryClickEvent(inventory, type, packet.getSlotNum(), click, action); } Inventory top = inventory.getTopInventory(); - if (packet.getSlotId() == 0 && top instanceof org.bukkit.inventory.CraftingInventory) { + if (packet.getSlotNum() == 0 && top instanceof org.bukkit.inventory.CraftingInventory) { Recipe recipe = ((org.bukkit.inventory.CraftingInventory) top).getRecipe(); if (recipe != null) { if (click == org.bukkit.event.inventory.ClickType.NUMBER_KEY) { - event = new CraftItemEvent(recipe, inventory, type, packet.getSlotId(), click, action, packet.getUsedButton()); + event = new CraftItemEvent(recipe, inventory, type, packet.getSlotNum(), click, action, packet.getButtonNum()); } else { - event = new CraftItemEvent(recipe, inventory, type, packet.getSlotId(), click, action); + event = new CraftItemEvent(recipe, inventory, type, packet.getSlotNum(), click, action); } } } - if (packet.getSlotId() == 2 && top instanceof SmithingInventory) { + if (packet.getSlotNum() == 2 && top instanceof SmithingInventory) { org.bukkit.inventory.ItemStack result = ((SmithingInventory) top).getResult(); if (result != null) { if (click == ClickType.NUMBER_KEY) { - event = new SmithItemEvent(inventory, type, packet.getSlotId(), click, action, packet.getUsedButton()); + event = new SmithItemEvent(inventory, type, packet.getSlotNum(), click, action, packet.getButtonNum()); } else { - event = new SmithItemEvent(inventory, type, packet.getSlotId(), click, action); + event = new SmithItemEvent(inventory, type, packet.getSlotNum(), click, action); } } } event.setCancelled(cancelled); - Container oldContainer = this.player.openContainer; + AbstractContainerMenu oldContainer = this.player.containerMenu; this.server.getPluginManager().callEvent(event); - if (this.player.openContainer != oldContainer) { + if (this.player.containerMenu != oldContainer) { return; } switch (event.getResult()) { case DEFAULT: case ALLOW: { - itemstack = this.player.openContainer.slotClick(packet.getSlotId(), packet.getUsedButton(), packet.getClickType(), this.player); + itemstack = this.player.containerMenu.clicked(packet.getSlotNum(), packet.getButtonNum(), packet.getClickType(), this.player); break; } case DENY: { @@ -1491,7 +1514,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB case HOTBAR_SWAP: case COLLECT_TO_CURSOR: case UNKNOWN: { - this.player.sendContainerToPlayer(this.player.openContainer); + this.player.refreshContainer(this.player.containerMenu); break; } case PICKUP_SOME: @@ -1501,19 +1524,19 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB case PLACE_SOME: case PLACE_ONE: case SWAP_WITH_CURSOR: { - this.player.connection.sendPacket(new SSetSlotPacket(-1, -1, this.player.inventory.getItemStack())); - this.player.connection.sendPacket(new SSetSlotPacket(this.player.openContainer.windowId, packet.getSlotId(), this.player.openContainer.getSlot(packet.getSlotId()).getStack())); + this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, -1, this.player.inventory.getCarried())); + this.player.connection.send(new ClientboundContainerSetSlotPacket(this.player.containerMenu.containerId, packet.getSlotNum(), this.player.containerMenu.getSlot(packet.getSlotNum()).getItem())); break; } case DROP_ALL_SLOT: case DROP_ONE_SLOT: { - this.player.connection.sendPacket(new SSetSlotPacket(this.player.openContainer.windowId, packet.getSlotId(), this.player.openContainer.getSlot(packet.getSlotId()).getStack())); + this.player.connection.send(new ClientboundContainerSetSlotPacket(this.player.containerMenu.containerId, packet.getSlotNum(), this.player.containerMenu.getSlot(packet.getSlotNum()).getItem())); break; } case DROP_ALL_CURSOR: case DROP_ONE_CURSOR: case CLONE_STACK: { - this.player.connection.sendPacket(new SSetSlotPacket(-1, -1, this.player.inventory.getItemStack())); + this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, -1, this.player.inventory.getCarried())); break; } } @@ -1521,31 +1544,31 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } if (event instanceof CraftItemEvent || event instanceof SmithItemEvent) { - this.player.sendContainerToPlayer(this.player.openContainer); + this.player.refreshContainer(this.player.containerMenu); } } - if (ItemStack.areItemStacksEqual(packet.getClickedItem(), itemstack)) { - this.player.connection.sendPacket(new SConfirmTransactionPacket(packet.getWindowId(), packet.getActionNumber(), true)); - this.player.isChangingQuantityOnly = true; - this.player.openContainer.detectAndSendChanges(); - this.player.updateHeldItem(); - this.player.isChangingQuantityOnly = false; + if (ItemStack.matches(packet.getItem(), itemstack)) { + this.player.connection.send(new ClientboundContainerAckPacket(packet.getContainerId(), packet.getUid(), true)); + this.player.ignoreSlotUpdateHack = true; + this.player.containerMenu.broadcastChanges(); + this.player.broadcastCarriedItem(); + this.player.ignoreSlotUpdateHack = false; } else { - this.pendingTransactions.put(this.player.openContainer.windowId, packet.getActionNumber()); - this.player.connection.sendPacket(new SConfirmTransactionPacket(packet.getWindowId(), packet.getActionNumber(), false)); - this.player.openContainer.setCanCraft(this.player, false); + this.expectedAcks.put(this.player.containerMenu.containerId, packet.getUid()); + this.player.connection.send(new ClientboundContainerAckPacket(packet.getContainerId(), packet.getUid(), false)); + this.player.containerMenu.setSynched(this.player, false); NonNullList nonnulllist1 = NonNullList.create(); - for (int j = 0; j < this.player.openContainer.inventorySlots.size(); ++j) { - ItemStack itemstack2 = this.player.openContainer.inventorySlots.get(j).getStack(); + for (int j = 0; j < this.player.containerMenu.slots.size(); ++j) { + ItemStack itemstack2 = this.player.containerMenu.slots.get(j).getItem(); nonnulllist1.add(itemstack2.isEmpty() ? ItemStack.EMPTY : itemstack2); } - this.player.sendAllContents(this.player.openContainer, nonnulllist1); + this.player.refreshContainer(this.player.containerMenu, nonnulllist1); } } } - @Inject(method = "processEnchantItem", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;markPlayerActive()V")) - private void arclight$noEnchant(CEnchantItemPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleContainerButtonClick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V")) + private void arclight$noEnchant(ServerboundContainerButtonClickPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) player).bridge$isMovementBlocked()) { ci.cancel(); } @@ -1556,39 +1579,39 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processCreativeInventoryAction(final CCreativeInventoryActionPacket packetplayinsetcreativeslot) { - PacketThreadUtil.checkThreadAndEnqueue(packetplayinsetcreativeslot, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); - if (this.player.interactionManager.isCreative()) { - final boolean flag = packetplayinsetcreativeslot.getSlotId() < 0; - ItemStack itemstack = packetplayinsetcreativeslot.getStack(); - final CompoundNBT nbttagcompound = itemstack.getChildTag("BlockEntityTag"); + public void handleSetCreativeModeSlot(final ServerboundSetCreativeModeSlotPacket packetplayinsetcreativeslot) { + PacketUtils.ensureRunningOnSameThread(packetplayinsetcreativeslot, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); + if (this.player.gameMode.isCreative()) { + final boolean flag = packetplayinsetcreativeslot.getSlotNum() < 0; + ItemStack itemstack = packetplayinsetcreativeslot.getItem(); + final CompoundTag nbttagcompound = itemstack.getTagElement("BlockEntityTag"); if (!itemstack.isEmpty() && nbttagcompound != null && nbttagcompound.contains("x") && nbttagcompound.contains("y") && nbttagcompound.contains("z")) { final BlockPos blockposition = new BlockPos(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z")); - final TileEntity tileentity = this.player.world.getTileEntity(blockposition); + final BlockEntity tileentity = this.player.level.getBlockEntity(blockposition); if (tileentity != null) { - final CompoundNBT nbttagcompound2 = tileentity.write(new CompoundNBT()); + final CompoundTag nbttagcompound2 = tileentity.save(new CompoundTag()); nbttagcompound2.remove("x"); nbttagcompound2.remove("y"); nbttagcompound2.remove("z"); - itemstack.setTagInfo("BlockEntityTag", nbttagcompound2); + itemstack.addTagElement("BlockEntityTag", nbttagcompound2); } } - final boolean flag2 = packetplayinsetcreativeslot.getSlotId() >= 1 && packetplayinsetcreativeslot.getSlotId() <= 45; - boolean flag3 = itemstack.isEmpty() || (itemstack.getDamage() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty()); - if (flag || (flag2 && !ItemStack.areItemStacksEqual(this.player.container.getSlot(packetplayinsetcreativeslot.getSlotId()).getStack(), packetplayinsetcreativeslot.getStack()))) { - final InventoryView inventory = ((ContainerBridge) this.player.container).bridge$getBukkitView(); - final org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getStack()); + final boolean flag2 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45; + boolean flag3 = itemstack.isEmpty() || (itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty()); + if (flag || (flag2 && !ItemStack.matches(this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).getItem(), packetplayinsetcreativeslot.getItem()))) { + final InventoryView inventory = ((ContainerBridge) this.player.inventoryMenu).bridge$getBukkitView(); + final org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItem()); InventoryType.SlotType type = InventoryType.SlotType.QUICKBAR; if (flag) { type = InventoryType.SlotType.OUTSIDE; - } else if (packetplayinsetcreativeslot.getSlotId() < 36) { - if (packetplayinsetcreativeslot.getSlotId() >= 5 && packetplayinsetcreativeslot.getSlotId() < 9) { + } else if (packetplayinsetcreativeslot.getSlotNum() < 36) { + if (packetplayinsetcreativeslot.getSlotNum() >= 5 && packetplayinsetcreativeslot.getSlotNum() < 9) { type = InventoryType.SlotType.ARMOR; } else { type = InventoryType.SlotType.CONTAINER; } } - final InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.getSlotId(), item); + final InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.getSlotNum(), item); this.server.getPluginManager().callEvent(event); itemstack = CraftItemStack.asNMSCopy(event.getCursor()); switch (event.getResult()) { @@ -1596,9 +1619,9 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB flag3 = true; } case DENY: { - if (packetplayinsetcreativeslot.getSlotId() >= 0) { - this.player.connection.sendPacket(new SSetSlotPacket(this.player.container.windowId, packetplayinsetcreativeslot.getSlotId(), this.player.container.getSlot(packetplayinsetcreativeslot.getSlotId()).getStack())); - this.player.connection.sendPacket(new SSetSlotPacket(-1, -1, ItemStack.EMPTY)); + if (packetplayinsetcreativeslot.getSlotNum() >= 0) { + this.player.connection.send(new ClientboundContainerSetSlotPacket(this.player.inventoryMenu.containerId, packetplayinsetcreativeslot.getSlotNum(), this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).getItem())); + this.player.connection.send(new ClientboundContainerSetSlotPacket(-1, -1, ItemStack.EMPTY)); } return; } @@ -1606,46 +1629,46 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } if (flag2 && flag3) { if (itemstack.isEmpty()) { - this.player.container.putStackInSlot(packetplayinsetcreativeslot.getSlotId(), ItemStack.EMPTY); + this.player.inventoryMenu.setItem(packetplayinsetcreativeslot.getSlotNum(), ItemStack.EMPTY); } else { - this.player.container.putStackInSlot(packetplayinsetcreativeslot.getSlotId(), itemstack); + this.player.inventoryMenu.setItem(packetplayinsetcreativeslot.getSlotNum(), itemstack); } - this.player.container.setCanCraft(this.player, true); - this.player.container.detectAndSendChanges(); - } else if (flag && flag3 && this.itemDropThreshold < 200) { - this.itemDropThreshold += 20; - this.player.dropItem(itemstack, true); + this.player.inventoryMenu.setSynched(this.player, true); + this.player.inventoryMenu.broadcastChanges(); + } else if (flag && flag3 && this.dropSpamTickCount < 200) { + this.dropSpamTickCount += 20; + this.player.drop(itemstack, true); } } } - @Inject(method = "processConfirmTransaction", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/IPacket;Lnet/minecraft/network/INetHandler;Lnet/minecraft/world/server/ServerWorld;)V")) - private void arclight$noTransaction(CConfirmTransactionPacket packetIn, CallbackInfo ci) { + @Inject(method = "handleContainerAck", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/server/level/ServerLevel;)V")) + private void arclight$noTransaction(ServerboundContainerAckPacket packetIn, CallbackInfo ci) { if (((ServerPlayerEntityBridge) player).bridge$isMovementBlocked()) { ci.cancel(); } } - @Inject(method = "func_244542_a", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;markPlayerActive()V")) - private void arclight$noSignEdit(CUpdateSignPacket p_244542_1_, List p_244542_2_, CallbackInfo ci) { + @Inject(method = "updateSignText", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V")) + private void arclight$noSignEdit(ServerboundSignUpdatePacket p_244542_1_, List p_244542_2_, CallbackInfo ci) { if (((ServerPlayerEntityBridge) player).bridge$isMovementBlocked()) { ci.cancel(); } } - private ITextComponent[] arclight$lines; + private Component[] arclight$lines; - @Inject(method = "func_244542_a", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/SignTileEntity;getIsEditable()Z")) - public void arclight$onSignChangePre(CUpdateSignPacket p_244542_1_, List p_244542_2_, CallbackInfo ci) { + @Inject(method = "updateSignText", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/SignBlockEntity;isEditable()Z")) + public void arclight$onSignChangePre(ServerboundSignUpdatePacket p_244542_1_, List p_244542_2_, CallbackInfo ci) { String[] lines = p_244542_2_.toArray(new String[0]); Player player = ((CraftServer) Bukkit.getServer()).getPlayer(this.player); - CraftBlock block = CraftBlock.at(this.player.world, p_244542_1_.getPosition()); + CraftBlock block = CraftBlock.at(this.player.level, p_244542_1_.getPos()); String[] bukkitLines = new String[lines.length]; for (int i = 0; i < lines.length; i++) { - bukkitLines[i] = TextFormatting.getTextWithoutFormattingCodes( - new StringTextComponent( + bukkitLines[i] = ChatFormatting.stripFormatting( + new TextComponent( Objects.requireNonNull( - TextFormatting.getTextWithoutFormattingCodes(lines[i]) + ChatFormatting.stripFormatting(lines[i]) ) ).getString() ); @@ -1659,10 +1682,10 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Redirect(method = "func_244542_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/SignTileEntity;setText(ILnet/minecraft/util/text/ITextComponent;)V")) - public void arclight$onSignChangePost(SignTileEntity signTileEntity, int line, ITextComponent signText) { + @Redirect(method = "updateSignText", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/SignBlockEntity;setMessage(ILnet/minecraft/network/chat/Component;)V")) + public void arclight$onSignChangePost(SignBlockEntity signTileEntity, int line, Component signText) { if (arclight$lines != null) { - signTileEntity.setText(line, arclight$lines[line]); + signTileEntity.setMessage(line, arclight$lines[line]); if (line == arclight$lines.length - 1) { arclight$lines = null; ((SignTileEntityBridge) signTileEntity).bridge$setEditable(false); @@ -1670,9 +1693,9 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } } - @Inject(method = "processKeepAlive", at = @At("HEAD")) - private void arclight$syncKeepAlive(CKeepAlivePacket packetIn, CallbackInfo ci) { - PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); + @Inject(method = "handleKeepAlive", at = @At("HEAD")) + private void arclight$syncKeepAlive(ServerboundKeepAlivePacket packetIn, CallbackInfo ci) { + PacketUtils.ensureRunningOnSameThread(packetIn, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); } /** @@ -1680,15 +1703,15 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void processPlayerAbilities(CPlayerAbilitiesPacket packet) { - PacketThreadUtil.checkThreadAndEnqueue(packet, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld()); - if (this.player.abilities.allowFlying && this.player.abilities.isFlying != packet.isFlying()) { + public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { + PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.getLevel()); + if (this.player.abilities.mayfly && this.player.abilities.flying != packet.isFlying()) { PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(this.server.getPlayer(this.player), packet.isFlying()); this.server.getPluginManager().callEvent(event); if (!event.isCancelled()) { - this.player.abilities.isFlying = packet.isFlying(); + this.player.abilities.flying = packet.isFlying(); } else { - this.player.sendPlayerAbilities(); + this.player.onUpdateAbilities(); } } } @@ -1696,13 +1719,13 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB private static final ResourceLocation CUSTOM_REGISTER = new ResourceLocation("register"); private static final ResourceLocation CUSTOM_UNREGISTER = new ResourceLocation("unregister"); - @Inject(method = "processCustomPayload", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/fml/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/fml/network/ICustomPacket;Lnet/minecraft/network/NetworkManager;)Z")) - private void arclight$customPayload(CCustomPayloadPacket packet, CallbackInfo ci) { - if (packet.channel.equals(CUSTOM_REGISTER)) { + @Inject(method = "handleCustomPayload", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/fml/network/NetworkHooks;onCustomPayload(Lnet/minecraftforge/fml/network/ICustomPacket;Lnet/minecraft/network/Connection;)Z")) + private void arclight$customPayload(ServerboundCustomPayloadPacket packet, CallbackInfo ci) { + if (packet.identifier.equals(CUSTOM_REGISTER)) { try { String channels = packet.data.toString(Charsets.UTF_8); for (String channel : channels.split("\0")) { - if (!StringUtils.isNullOrEmpty(channel)) { + if (!StringUtil.isNullOrEmpty(channel)) { this.getPlayer().addChannel(channel); } } @@ -1711,11 +1734,11 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB this.disconnect("Invalid payload REGISTER!"); ci.cancel(); } - } else if (packet.channel.equals(CUSTOM_UNREGISTER)) { + } else if (packet.identifier.equals(CUSTOM_UNREGISTER)) { try { final String channels = packet.data.toString(Charsets.UTF_8); for (String channel : channels.split("\0")) { - if (!StringUtils.isNullOrEmpty(channel)) { + if (!StringUtil.isNullOrEmpty(channel)) { this.getPlayer().removeChannel(channel); } } @@ -1729,7 +1752,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB int readerIndex = packet.data.readerIndex(); final byte[] data = new byte[packet.data.readableBytes()]; packet.data.readBytes(data); - this.server.getMessenger().dispatchIncomingMessage(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), packet.channel.toString(), data); + this.server.getMessenger().dispatchIncomingMessage(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity(), packet.identifier.toString(), data); packet.data.readerIndex(readerIndex); } catch (Exception ex) { LOGGER.error("Couldn't dispatch custom payload", ex); @@ -1740,7 +1763,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB } public final boolean isDisconnected() { - return !((ServerPlayerEntityBridge) this.player).bridge$isJoining() && !this.netManager.isChannelOpen(); + return !((ServerPlayerEntityBridge) this.player).bridge$isJoining() && !this.connection.isConnected(); } @Override @@ -1753,7 +1776,7 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB * @reason */ @Overwrite - public void setPlayerLocation(double x, double y, double z, float yaw, float pitch, Set relativeSet) { + public void teleport(double x, double y, double z, float yaw, float pitch, Set relativeSet) { PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause; arclight$cause = null; Player player = this.getPlayer(); @@ -1786,12 +1809,12 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB this.a(d0, d1, d2, f, f1, Collections.emptySet(), cause); } - public void a(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { + public void a(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { bridge$pushTeleportCause(cause); - this.setPlayerLocation(d0, d1, d2, f, f1, set); + this.teleport(d0, d1, d2, f, f1, set); } - private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set set) { + private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set set) { if (Float.isNaN(f)) { f = 0.0f; } @@ -1799,23 +1822,23 @@ public abstract class ServerPlayNetHandlerMixin implements ServerPlayNetHandlerB f1 = 0.0f; } this.justTeleported = true; - double d3 = set.contains(SPlayerPositionLookPacket.Flags.X) ? this.player.getPosX() : 0.0; - double d4 = set.contains(SPlayerPositionLookPacket.Flags.Y) ? this.player.getPosY() : 0.0; - double d5 = set.contains(SPlayerPositionLookPacket.Flags.Z) ? this.player.getPosZ() : 0.0; - float f2 = set.contains(SPlayerPositionLookPacket.Flags.Y_ROT) ? this.player.rotationYaw : 0.0f; - float f3 = set.contains(SPlayerPositionLookPacket.Flags.X_ROT) ? this.player.rotationPitch : 0.0f; - this.targetPos = new Vector3d(d0, d1, d2); - if (++this.teleportId == Integer.MAX_VALUE) { - this.teleportId = 0; + double d3 = set.contains(ClientboundPlayerPositionPacket.RelativeArgument.X) ? this.player.getX() : 0.0; + double d4 = set.contains(ClientboundPlayerPositionPacket.RelativeArgument.Y) ? this.player.getY() : 0.0; + double d5 = set.contains(ClientboundPlayerPositionPacket.RelativeArgument.Z) ? this.player.getZ() : 0.0; + float f2 = set.contains(ClientboundPlayerPositionPacket.RelativeArgument.Y_ROT) ? this.player.yRot : 0.0f; + float f3 = set.contains(ClientboundPlayerPositionPacket.RelativeArgument.X_ROT) ? this.player.xRot : 0.0f; + this.awaitingPositionFromClient = new Vec3(d0, d1, d2); + if (++this.awaitingTeleport == Integer.MAX_VALUE) { + this.awaitingTeleport = 0; } - this.lastPosX = this.targetPos.x; - this.lastPosY = this.targetPos.y; - this.lastPosZ = this.targetPos.z; + this.lastPosX = this.awaitingPositionFromClient.x; + this.lastPosY = this.awaitingPositionFromClient.y; + this.lastPosZ = this.awaitingPositionFromClient.z; this.lastYaw = f; this.lastPitch = f1; - this.lastPositionUpdate = this.networkTickCount; - this.player.setPositionAndRotation(d0, d1, d2, f, f1); - this.player.connection.sendPacket(new SPlayerPositionLookPacket(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.teleportId)); + this.awaitingTeleportTime = this.tickCount; + this.player.absMoveTo(d0, d1, d2, f, f1); + this.player.connection.send(new ClientboundPlayerPositionPacket(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport)); } public void teleport(Location dest) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CChatMessagePacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CChatMessagePacketMixin.java index 2938e5a3..641e03ac 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CChatMessagePacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CChatMessagePacketMixin.java @@ -1,8 +1,6 @@ package io.izzel.arclight.common.mixin.core.network.play.client; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import net.minecraft.network.play.IServerPlayNetHandler; -import net.minecraft.network.play.client.CChatMessagePacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -11,8 +9,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import net.minecraft.network.protocol.game.ServerGamePacketListener; +import net.minecraft.network.protocol.game.ServerboundChatPacket; -@Mixin(CChatMessagePacket.class) +@Mixin(ServerboundChatPacket.class) public class CChatMessagePacketMixin { @Shadow private String message; @@ -21,10 +21,10 @@ public class CChatMessagePacketMixin { new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").build() ); - @Inject(method = "processPacket", cancellable = true, at = @At("HEAD")) - private void arclight$asyncChat(IServerPlayNetHandler handler, CallbackInfo ci) { + @Inject(method = "handle", cancellable = true, at = @At("HEAD")) + private void arclight$asyncChat(ServerGamePacketListener handler, CallbackInfo ci) { if (!this.message.startsWith("/")) { - executors.submit(() -> handler.processChatMessage((CChatMessagePacket) (Object) this)); + executors.submit(() -> handler.handleChat((ServerboundChatPacket) (Object) this)); ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CCloseWindowPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CCloseWindowPacketMixin.java index 386991f1..1a2ab7fa 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CCloseWindowPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CCloseWindowPacketMixin.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mixin.core.network.play.client; -import net.minecraft.network.play.client.CCloseWindowPacket; +import net.minecraft.network.protocol.game.ServerboundContainerClosePacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(CCloseWindowPacket.class) +@Mixin(ServerboundContainerClosePacket.class) public class CCloseWindowPacketMixin { - @Shadow private int windowId; + @Shadow private int containerId; public void arclight$constructor() { throw new RuntimeException(); @@ -15,6 +15,6 @@ public class CCloseWindowPacketMixin { public void arclight$constructor(int id) { arclight$constructor(); - this.windowId = id; + this.containerId = id; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemOnBlockPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemOnBlockPacketMixin.java index f4d15e48..457fa0d7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemOnBlockPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemOnBlockPacketMixin.java @@ -1,20 +1,20 @@ package io.izzel.arclight.common.mixin.core.network.play.client; import io.izzel.arclight.common.bridge.network.play.TimestampedPacket; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.client.CPlayerTryUseItemOnBlockPacket; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(CPlayerTryUseItemOnBlockPacket.class) +@Mixin(ServerboundUseItemOnPacket.class) public class CPlayerTryUseItemOnBlockPacketMixin implements TimestampedPacket { public long timestamp; - @Inject(method = "readPacketData", at = @At("HEAD")) - private void arclight$read(PacketBuffer buf, CallbackInfo ci) { + @Inject(method = "read", at = @At("HEAD")) + private void arclight$read(FriendlyByteBuf buf, CallbackInfo ci) { this.timestamp = System.currentTimeMillis(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemPacketMixin.java index 4eb01df4..115b386d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/client/CPlayerTryUseItemPacketMixin.java @@ -1,20 +1,20 @@ package io.izzel.arclight.common.mixin.core.network.play.client; import io.izzel.arclight.common.bridge.network.play.TimestampedPacket; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.client.CPlayerTryUseItemPacket; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ServerboundUseItemPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(CPlayerTryUseItemPacket.class) +@Mixin(ServerboundUseItemPacket.class) public class CPlayerTryUseItemPacketMixin implements TimestampedPacket { public long timestamp; - @Inject(method = "readPacketData", at = @At("HEAD")) - private void arclight$read(PacketBuffer buf, CallbackInfo ci) { + @Inject(method = "read", at = @At("HEAD")) + private void arclight$read(FriendlyByteBuf buf, CallbackInfo ci) { this.timestamp = System.currentTimeMillis(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SChatPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SChatPacketMixin.java index d366a73d..0f710237 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SChatPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SChatPacketMixin.java @@ -2,10 +2,10 @@ package io.izzel.arclight.common.mixin.core.network.play.server; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.chat.ComponentSerializer; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.play.server.SChatPacket; -import net.minecraft.util.text.ChatType; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundChatPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @@ -13,11 +13,11 @@ import org.spongepowered.asm.mixin.Shadow; import java.io.IOException; import java.util.UUID; -@Mixin(SChatPacket.class) +@Mixin(ClientboundChatPacket.class) public class SChatPacketMixin { // @formatter:off - @Shadow private ITextComponent chatComponent; + @Shadow private Component message; @Shadow private ChatType type; @Shadow private UUID sender; // @formatter:on @@ -29,13 +29,13 @@ public class SChatPacketMixin { * @reason */ @Overwrite - public void writePacketData(PacketBuffer buf) throws IOException { + public void write(FriendlyByteBuf buf) throws IOException { if (components != null) { - buf.writeString(ComponentSerializer.toString(components)); + buf.writeUtf(ComponentSerializer.toString(components)); } else { - buf.writeTextComponent(this.chatComponent); + buf.writeComponent(this.message); } - buf.writeByte(this.type.getId()); - buf.writeUniqueId(this.sender); + buf.writeByte(this.type.getIndex()); + buf.writeUUID(this.sender); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SWorldBorderPacketMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SWorldBorderPacketMixin.java index 0809a4eb..5ef941a3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SWorldBorderPacketMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/play/server/SWorldBorderPacketMixin.java @@ -1,25 +1,25 @@ package io.izzel.arclight.common.mixin.core.network.play.server; import io.izzel.arclight.common.bridge.world.border.WorldBorderBridge; -import net.minecraft.network.play.server.SWorldBorderPacket; -import net.minecraft.world.border.WorldBorder; +import net.minecraft.network.protocol.game.ClientboundSetBorderPacket; +import net.minecraft.world.level.border.WorldBorder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(SWorldBorderPacket.class) +@Mixin(ClientboundSetBorderPacket.class) public class SWorldBorderPacketMixin { // @formatter:off - @Shadow private double centerX; - @Shadow private double centerZ; + @Shadow private double newCenterX; + @Shadow private double newCenterZ; // @formatter:on - @Inject(method = "(Lnet/minecraft/world/border/WorldBorder;Lnet/minecraft/network/play/server/SWorldBorderPacket$Action;)V", at = @At("RETURN")) - private void arclight$nether(WorldBorder border, SWorldBorderPacket.Action actionIn, CallbackInfo ci) { - this.centerX = border.getCenterX() * (((WorldBorderBridge) border).bridge$getWorld().getDimensionType().getCoordinateScale()); - this.centerZ = border.getCenterZ() * (((WorldBorderBridge) border).bridge$getWorld().getDimensionType().getCoordinateScale()); + @Inject(method = "(Lnet/minecraft/world/level/border/WorldBorder;Lnet/minecraft/network/protocol/game/ClientboundSetBorderPacket$Type;)V", at = @At("RETURN")) + private void arclight$nether(WorldBorder border, ClientboundSetBorderPacket.Type actionIn, CallbackInfo ci) { + this.newCenterX = border.getCenterX() * (((WorldBorderBridge) border).bridge$getWorld().dimensionType().coordinateScale()); + this.newCenterZ = border.getCenterZ() * (((WorldBorderBridge) border).bridge$getWorld().dimensionType().coordinateScale()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/rcon/RConConsoleSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/rcon/RConConsoleSourceMixin.java index 06054499..1e9a16bd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/rcon/RConConsoleSourceMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/rcon/RConConsoleSourceMixin.java @@ -3,15 +3,15 @@ package io.izzel.arclight.common.mixin.core.network.rcon; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; import io.izzel.arclight.common.bridge.network.rcon.RConConsoleSourceBridge; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.network.rcon.RConConsoleSource; +import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.rcon.RconConsoleSource; import org.bukkit.command.CommandSender; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(RConConsoleSource.class) +@Mixin(RconConsoleSource.class) public class RConConsoleSourceMixin implements ICommandSourceBridge, RConConsoleSourceBridge { // @formatter:off @@ -28,7 +28,7 @@ public class RConConsoleSourceMixin implements ICommandSourceBridge, RConConsole } @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { return getBukkitSender(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/status/ServerStatusNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/status/ServerStatusNetHandlerMixin.java index 01c3ca06..077a5e84 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/status/ServerStatusNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/status/ServerStatusNetHandlerMixin.java @@ -2,14 +2,14 @@ package io.izzel.arclight.common.mixin.core.network.status; import com.mojang.authlib.GameProfile; import io.izzel.arclight.common.mod.util.ArclightPingEvent; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.ServerStatusResponse; -import net.minecraft.network.status.ServerStatusNetHandler; -import net.minecraft.network.status.server.SServerInfoPacket; +import net.minecraft.SharedConstants; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; +import net.minecraft.network.protocol.status.ServerStatus; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.SharedConstants; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerStatusPacketListenerImpl; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.util.CraftChatMessage; import org.spigotmc.SpigotConfig; @@ -23,13 +23,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -@Mixin(ServerStatusNetHandler.class) +@Mixin(ServerStatusPacketListenerImpl.class) public class ServerStatusNetHandlerMixin { @Shadow @Final private MinecraftServer server; - @Redirect(method = "processServerQuery", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;sendPacket(Lnet/minecraft/network/IPacket;)V")) - private void arclight$handleServerPing(NetworkManager networkManager, IPacket packetIn) { + @Redirect(method = "handleStatusRequest", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V")) + private void arclight$handleServerPing(Connection networkManager, Packet packetIn) { Object[] players = this.server.getPlayerList().players.toArray(); ArclightPingEvent event = new ArclightPingEvent(networkManager, server); Bukkit.getPluginManager().callEvent(event); @@ -38,22 +38,22 @@ public class ServerStatusNetHandlerMixin { for (int length = (array = players).length, i = 0; i < length; ++i) { Object player = array[i]; if (player != null) { - profiles.add(((ServerPlayerEntity) player).getGameProfile()); + profiles.add(((ServerPlayer) player).getGameProfile()); } } - ServerStatusResponse.Players playerSample = new ServerStatusResponse.Players(event.getMaxPlayers(), profiles.size()); + ServerStatus.Players playerSample = new ServerStatus.Players(event.getMaxPlayers(), profiles.size()); if (!profiles.isEmpty()) { Collections.shuffle(profiles); profiles = profiles.subList(0, Math.min(profiles.size(), SpigotConfig.playerSample)); } - playerSample.setPlayers(profiles.toArray(new GameProfile[0])); - ServerStatusResponse ping = new ServerStatusResponse(); + playerSample.setSample(profiles.toArray(new GameProfile[0])); + ServerStatus ping = new ServerStatus(); ping.setFavicon(event.icon.value); - ping.setServerDescription(CraftChatMessage.fromString(event.getMotd(), true)[0]); + ping.setDescription(CraftChatMessage.fromString(event.getMotd(), true)[0]); ping.setPlayers(playerSample); - int version = SharedConstants.getVersion().getProtocolVersion(); - ping.setVersion(new ServerStatusResponse.Version(this.server.getServerModName() + " " + this.server.getMinecraftVersion(), version)); - ping.setForgeData(this.server.getServerStatusResponse().getForgeData()); - networkManager.sendPacket(new SServerInfoPacket(ping)); + int version = SharedConstants.getCurrentVersion().getProtocolVersion(); + ping.setVersion(new ServerStatus.Version(this.server.getServerModName() + " " + this.server.getServerVersion(), version)); + ping.setForgeData(this.server.getStatus().getForgeData()); + networkManager.send(new ClientboundStatusResponsePacket(ping)); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/potion/EffectMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/potion/EffectMixin.java index 1608ee56..5e3e3198 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/potion/EffectMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/potion/EffectMixin.java @@ -2,14 +2,14 @@ package io.izzel.arclight.common.mixin.core.potion; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.play.server.SUpdateHealthPacket; -import net.minecraft.potion.Effect; -import net.minecraft.util.DamageSource; -import net.minecraft.util.FoodStats; +import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodData; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -19,39 +19,39 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(Effect.class) +@Mixin(MobEffect.class) public class EffectMixin { - @Inject(method = "performEffect", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/LivingEntity;heal(F)V")) + @Inject(method = "applyEffectTick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V")) public void arclight$healReason1(LivingEntity livingEntity, int amplifier, CallbackInfo ci) { ((LivingEntityBridge) livingEntity).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.MAGIC_REGEN); } - @Inject(method = "performEffect", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/entity/LivingEntity;heal(F)V")) + @Inject(method = "applyEffectTick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V")) public void arclight$healReason2(LivingEntity livingEntity, int amplifier, CallbackInfo ci) { ((LivingEntityBridge) livingEntity).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.MAGIC); } - @Inject(method = "affectEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;heal(F)V")) + @Inject(method = "applyInstantenousEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V")) public void arclight$healReason3(Entity source, Entity indirectSource, LivingEntity livingEntity, int amplifier, double health, CallbackInfo ci) { ((LivingEntityBridge) livingEntity).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.MAGIC); } - @Redirect(method = "performEffect", at = @At(value = "FIELD", ordinal = 0, target = "Lnet/minecraft/util/DamageSource;MAGIC:Lnet/minecraft/util/DamageSource;")) + @Redirect(method = "applyEffectTick", at = @At(value = "FIELD", ordinal = 0, target = "Lnet/minecraft/world/damagesource/DamageSource;MAGIC:Lnet/minecraft/world/damagesource/DamageSource;")) private DamageSource arclight$redirectPoison() { return CraftEventFactory.POISON; } - @Redirect(method = "performEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/FoodStats;addStats(IF)V")) - public void arclight$foodLevelChange(FoodStats foodStats, int foodLevelIn, float foodSaturationModifier, LivingEntity livingEntity, int amplifier) { - PlayerEntity playerEntity = ((PlayerEntity) livingEntity); - int oldFoodLevel = playerEntity.getFoodStats().getFoodLevel(); + @Redirect(method = "applyEffectTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/food/FoodData;eat(IF)V")) + public void arclight$foodLevelChange(FoodData foodStats, int foodLevelIn, float foodSaturationModifier, LivingEntity livingEntity, int amplifier) { + Player playerEntity = ((Player) livingEntity); + int oldFoodLevel = playerEntity.getFoodData().getFoodLevel(); FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(playerEntity, foodLevelIn + oldFoodLevel); if (!event.isCancelled()) { - playerEntity.getFoodStats().addStats(event.getFoodLevel() - oldFoodLevel, foodSaturationModifier); + playerEntity.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, foodSaturationModifier); } - ((ServerPlayerEntity) playerEntity).connection.sendPacket(new SUpdateHealthPacket(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity().getScaledHealth(), - playerEntity.getFoodStats().getFoodLevel(), playerEntity.getFoodStats().getSaturationLevel())); + ((ServerPlayer) playerEntity).connection.send(new ClientboundSetHealthPacket(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity().getScaledHealth(), + playerEntity.getFoodData().getFoodLevel(), playerEntity.getFoodData().getSaturationLevel())); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/scoreboard/ServerScoreboardMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/scoreboard/ServerScoreboardMixin.java index 3d8445f2..e3c7dd3f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/scoreboard/ServerScoreboardMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/scoreboard/ServerScoreboardMixin.java @@ -1,38 +1,38 @@ package io.izzel.arclight.common.mixin.core.scoreboard; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; -import net.minecraft.scoreboard.ServerScoreboard; -import net.minecraft.server.management.PlayerList; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import java.util.List; import java.util.stream.Collectors; +import net.minecraft.network.protocol.Packet; +import net.minecraft.server.ServerScoreboard; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.players.PlayerList; @Mixin(ServerScoreboard.class) public class ServerScoreboardMixin { - @Redirect(method = "addObjective", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;getPlayers()Ljava/util/List;")) - private List arclight$filterAdd(PlayerList playerList) { + @Redirect(method = "addObjective", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;getPlayers()Ljava/util/List;")) + private List arclight$filterAdd(PlayerList playerList) { return filterPlayer(playerList.getPlayers()); } - @Redirect(method = "sendDisplaySlotRemovalPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;getPlayers()Ljava/util/List;")) - private List arclight$filterRemove(PlayerList playerList) { + @Redirect(method = "stopTrackingObjective", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;getPlayers()Ljava/util/List;")) + private List arclight$filterRemove(PlayerList playerList) { return filterPlayer(playerList.getPlayers()); } - @Redirect(method = "*", require = 11, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;sendPacketToAllPlayers(Lnet/minecraft/network/IPacket;)V")) - private void arclight$sendToOwner(PlayerList playerList, IPacket packetIn) { - for (ServerPlayerEntity entity : filterPlayer(playerList.getPlayers())) { - entity.connection.sendPacket(packetIn); + @Redirect(method = "*", require = 11, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastAll(Lnet/minecraft/network/protocol/Packet;)V")) + private void arclight$sendToOwner(PlayerList playerList, Packet packetIn) { + for (ServerPlayer entity : filterPlayer(playerList.getPlayers())) { + entity.connection.send(packetIn); } } - private List filterPlayer(List list) { + private List filterPlayer(List list) { return list.stream() .filter(it -> ((ServerPlayerEntityBridge) it).bridge$getBukkitEntity().getScoreboard().getHandle() == (Object) this) .collect(Collectors.toList()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/CustomServerBossInfoMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/CustomServerBossInfoMixin.java index a1c8b277..4ce56cb0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/CustomServerBossInfoMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/CustomServerBossInfoMixin.java @@ -1,19 +1,19 @@ package io.izzel.arclight.common.mixin.core.server; import io.izzel.arclight.common.bridge.server.CustomServerBossInfoBridge; -import net.minecraft.server.CustomServerBossInfo; +import net.minecraft.server.bossevents.CustomBossEvent; import org.bukkit.boss.KeyedBossBar; import org.bukkit.craftbukkit.v.boss.CraftKeyedBossbar; import org.spongepowered.asm.mixin.Mixin; -@Mixin(CustomServerBossInfo.class) +@Mixin(CustomBossEvent.class) public class CustomServerBossInfoMixin implements CustomServerBossInfoBridge { private KeyedBossBar bossBar; public KeyedBossBar getBukkitEntity() { if (bossBar == null) { - bossBar = new CraftKeyedBossbar((CustomServerBossInfo) (Object) this); + bossBar = new CraftKeyedBossbar((CustomBossEvent) (Object) this); } return bossBar; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MainMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MainMixin.java index 1037ea6b..d873b280 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MainMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MainMixin.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mixin.core.server; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.resources.ResourcePackList; import net.minecraft.server.Main; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.datafix.codec.DatapackCodec; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.DataPackConfig; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -12,9 +12,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(Main.class) public class MainMixin { - @Redirect(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;func_240772_a_(Lnet/minecraft/resources/ResourcePackList;Lnet/minecraft/util/datafix/codec/DatapackCodec;Z)Lnet/minecraft/util/datafix/codec/DatapackCodec;")) - private static DatapackCodec arclight$captureDatapackCodec(ResourcePackList p_240772_0_, DatapackCodec p_240772_1_, boolean p_240772_2_) { - DatapackCodec datapackCodec = MinecraftServer.func_240772_a_(p_240772_0_, p_240772_1_, p_240772_2_); + @Redirect(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;configurePackRepository(Lnet/minecraft/server/packs/repository/PackRepository;Lnet/minecraft/world/level/DataPackConfig;Z)Lnet/minecraft/world/level/DataPackConfig;")) + private static DataPackConfig arclight$captureDatapackCodec(PackRepository p_240772_0_, DataPackConfig p_240772_1_, boolean p_240772_2_) { + DataPackConfig datapackCodec = MinecraftServer.configurePackRepository(p_240772_0_, p_240772_1_, p_240772_2_); ArclightCaptures.captureDatapackConfig(datapackCodec); return datapackCodec; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java index 5918e7dc..d8ecc7a4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/MinecraftServerMixin.java @@ -13,40 +13,40 @@ import io.izzel.arclight.common.mod.util.BukkitOptionParser; import it.unimi.dsi.fastutil.longs.LongIterator; import joptsimple.OptionParser; import joptsimple.OptionSet; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.ReportedException; -import net.minecraft.network.ServerStatusResponse; -import net.minecraft.profiler.IProfiler; -import net.minecraft.profiler.LongTickDetector; -import net.minecraft.resources.DataPackRegistries; -import net.minecraft.resources.ResourcePackList; +import net.minecraft.CrashReport; +import net.minecraft.ReportedException; +import net.minecraft.SharedConstants; +import net.minecraft.Util; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.core.BlockPos; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.protocol.status.ServerStatus; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.management.PlayerProfileCache; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.SharedConstants; +import net.minecraft.server.ServerResources; +import net.minecraft.server.TickTask; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.TicketType; +import net.minecraft.server.level.progress.ChunkProgressListener; +import net.minecraft.server.level.progress.ChunkProgressListenerFactory; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.server.players.GameProfileCache; import net.minecraft.util.Unit; -import net.minecraft.util.Util; -import net.minecraft.util.concurrent.RecursiveEventLoop; -import net.minecraft.util.concurrent.TickDelayedTask; -import net.minecraft.util.datafix.codec.DatapackCodec; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.registry.DynamicRegistries; -import net.minecraft.util.text.StringTextComponent; -import net.minecraft.world.ForcedChunksSaveData; -import net.minecraft.world.World; -import net.minecraft.world.border.WorldBorder; -import net.minecraft.world.chunk.listener.IChunkStatusListener; -import net.minecraft.world.chunk.listener.IChunkStatusListenerFactory; -import net.minecraft.world.gen.settings.DimensionGeneratorSettings; -import net.minecraft.world.server.ServerChunkProvider; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.server.TicketType; -import net.minecraft.world.storage.IServerConfiguration; -import net.minecraft.world.storage.IServerWorldInfo; -import net.minecraft.world.storage.SaveFormat; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.util.profiling.SingleTickProfiler; +import net.minecraft.util.thread.ReentrantBlockableEventLoop; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.DataPackConfig; +import net.minecraft.world.level.ForcedChunksSavedData; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.border.WorldBorder; +import net.minecraft.world.level.levelgen.WorldGenSettings; +import net.minecraft.world.level.storage.LevelStorageSource; +import net.minecraft.world.level.storage.ServerLevelData; +import net.minecraft.world.level.storage.WorldData; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.world.StructureSpawnManager; import net.minecraftforge.fml.BrandingControl; @@ -86,41 +86,41 @@ import java.util.Map; import java.util.function.BooleanSupplier; @Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin extends RecursiveEventLoop implements MinecraftServerBridge, ICommandSourceBridge { +public abstract class MinecraftServerMixin extends ReentrantBlockableEventLoop implements MinecraftServerBridge, ICommandSourceBridge { // @formatter:off - @Shadow private int tickCounter; - @Shadow protected abstract boolean init() throws IOException; - @Shadow protected long serverTime; - @Shadow @Final private ServerStatusResponse statusResponse; + @Shadow private int tickCount; + @Shadow protected abstract boolean initServer() throws IOException; + @Shadow protected long nextTickTime; + @Shadow @Final private ServerStatus status; @Shadow @Nullable private String motd; - @Shadow protected abstract void applyServerIconToResponse(ServerStatusResponse response); - @Shadow private volatile boolean serverRunning; - @Shadow private long timeOfLastWarning; + @Shadow protected abstract void updateStatusIcon(ServerStatus response); + @Shadow private volatile boolean running; + @Shadow private long lastOverloadWarning; @Shadow @Final private static Logger LOGGER; - @Shadow private boolean startProfiling; - @Shadow protected abstract void tick(BooleanSupplier hasTimeLeft); - @Shadow protected abstract boolean isAheadOfTime(); - @Shadow private boolean isRunningScheduledTasks; - @Shadow private long runTasksUntil; - @Shadow protected abstract void runScheduledTasks(); - @Shadow private volatile boolean serverIsRunning; - @Shadow protected abstract void finalTick(CrashReport report); - @Shadow public abstract CrashReport addServerInfoToCrashReport(CrashReport report); - @Shadow public abstract File getDataDirectory(); - @Shadow private boolean serverStopped; + @Shadow private boolean delayProfilerStart; + @Shadow protected abstract void tickServer(BooleanSupplier hasTimeLeft); + @Shadow protected abstract boolean haveTime(); + @Shadow private boolean mayHaveDelayedTasks; + @Shadow private long delayedTasksMaxNextTickTime; + @Shadow protected abstract void waitUntilNextTick(); + @Shadow private volatile boolean isReady; + @Shadow protected abstract void onServerCrash(CrashReport report); + @Shadow public abstract CrashReport fillReport(CrashReport report); + @Shadow public abstract File getServerDirectory(); + @Shadow private boolean stopped; @Shadow protected abstract void stopServer(); - @Shadow protected abstract void systemExitNow(); - @Shadow public abstract Commands getCommandManager(); - @Shadow protected abstract void func_240773_a_(@org.jetbrains.annotations.Nullable LongTickDetector p_240773_1_); - @Shadow private IProfiler profiler; - @Shadow protected abstract void func_240795_b_(@org.jetbrains.annotations.Nullable LongTickDetector p_240795_1_); - @Shadow protected abstract void func_240794_aZ_(); - @Shadow public abstract ServerWorld func_241755_D_(); - @Shadow @Final public Map, ServerWorld> worlds; - @Shadow protected abstract void func_240778_a_(IServerConfiguration p_240778_1_); - @Shadow protected IServerConfiguration serverConfig; - @Shadow private static void func_240786_a_(ServerWorld p_240786_0_, IServerWorldInfo p_240786_1_, boolean hasBonusChest, boolean p_240786_3_, boolean p_240786_4_) { } + @Shadow protected abstract void onServerExit(); + @Shadow public abstract Commands getCommands(); + @Shadow protected abstract void startProfilerTick(@org.jetbrains.annotations.Nullable SingleTickProfiler p_240773_1_); + @Shadow private ProfilerFiller profiler; + @Shadow protected abstract void endProfilerTick(@org.jetbrains.annotations.Nullable SingleTickProfiler p_240795_1_); + @Shadow protected abstract void updateMobSpawningFlags(); + @Shadow public abstract ServerLevel overworld(); + @Shadow @Final public Map, ServerLevel> levels; + @Shadow protected abstract void setupDebugLevel(WorldData p_240778_1_); + @Shadow protected WorldData worldData; + @Shadow private static void setInitialSpawn(ServerLevel p_240786_0_, ServerLevelData p_240786_1_, boolean hasBonusChest, boolean p_240786_3_, boolean p_240786_4_) { } @Shadow(remap = false) @Deprecated public abstract void markWorldsDirty(); // @formatter:on @@ -128,7 +128,7 @@ public abstract class MinecraftServerMixin extends RecursiveEventLoop 2000L && this.serverTime - this.timeOfLastWarning >= 15000L) { + while (this.running) { + long i = (curTime = Util.getMillis()) - this.nextTickTime; + if (i > 2000L && this.nextTickTime - this.lastOverloadWarning >= 15000L) { long j = i / 50L; if (server.getWarnOnOverload()) { LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j); } - this.serverTime += j * 50L; - this.timeOfLastWarning = this.serverTime; + this.nextTickTime += j * 50L; + this.lastOverloadWarning = this.nextTickTime; } if (tickCount++ % SAMPLE_INTERVAL == 0) { @@ -210,26 +210,26 @@ public abstract class MinecraftServerMixin extends RecursiveEventLoop cir) { if (this.forceTicks) cir.setReturnValue(true); } - @Inject(method = "func_240787_a_", at = @At(value = "NEW", ordinal = 0, target = "net/minecraft/world/server/ServerWorld")) - private void arclight$registerEnv(IChunkStatusListener p_240787_1_, CallbackInfo ci) { + @Inject(method = "createLevels", at = @At(value = "NEW", ordinal = 0, target = "net/minecraft/server/level/ServerLevel")) + private void arclight$registerEnv(ChunkProgressListener p_240787_1_, CallbackInfo ci) { BukkitRegistry.registerEnvironments(); } - @Redirect(method = "func_240787_a_", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) + @Redirect(method = "createLevels", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) private Object arclight$worldInit(Map map, Object key, Object value) { Object ret = map.put(key, value); - ServerWorld serverWorld = (ServerWorld) value; + ServerLevel serverWorld = (ServerLevel) value; if (((CraftServer) Bukkit.getServer()).scoreboardManager == null) { ((CraftServer) Bukkit.getServer()).scoreboardManager = new CraftScoreboardManager((MinecraftServer) (Object) this, serverWorld.getScoreboard()); } @@ -342,34 +342,34 @@ public abstract class MinecraftServerMixin extends RecursiveEventLoop cir, boolean flag) { cir.setReturnValue(flag); } @@ -505,12 +505,12 @@ public abstract class MinecraftServerMixin extends RecursiveEventLoop cir) { Bukkit.getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent((Player) ((EntityBridge) this.player).bridge$getBukkitEntity(), ((AdvancementBridge) advancementIn).bridge$getBukkit())); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/advancements/FunctionManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/ServerFunctionManagerMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/advancements/FunctionManagerMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/ServerFunctionManagerMixin.java index 0c261f8d..bf3a68a1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/advancements/FunctionManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/ServerFunctionManagerMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.advancements; +package io.izzel.arclight.common.mixin.core.server; import com.mojang.brigadier.CommandDispatcher; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; -import net.minecraft.advancements.FunctionManager; -import net.minecraft.command.CommandSource; +import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ServerFunctionManager; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -12,13 +12,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(FunctionManager.class) -public class FunctionManagerMixin { +@Mixin(ServerFunctionManager.class) +public class ServerFunctionManagerMixin { - @Shadow @Final private MinecraftServer server; + @Shadow @Final MinecraftServer server; - @Inject(method = "getCommandDispatcher", cancellable = true, at = @At("HEAD")) - private void arclight$useVanillaDispatcher(CallbackInfoReturnable> cir) { + @Inject(method = "getDispatcher", cancellable = true, at = @At("HEAD")) + private void arclight$useVanillaDispatcher(CallbackInfoReturnable> cir) { cir.setReturnValue(((MinecraftServerBridge) this.server).bridge$getVanillaCommands().getDispatcher()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/EffectCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/EffectCommandMixin.java similarity index 54% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/EffectCommandMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/EffectCommandMixin.java index 4d83fd62..162c9b1d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/EffectCommandMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/EffectCommandMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.command.impl; +package io.izzel.arclight.common.mixin.core.server.commands; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.impl.EffectCommand; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.potion.Effect; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.commands.EffectCommands; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,11 +14,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Collection; -@Mixin(EffectCommand.class) +@Mixin(EffectCommands.class) public class EffectCommandMixin { - @Inject(method = "addEffect", at = @At("HEAD")) - private static void arclight$addReason(CommandSource source, Collection targets, Effect effect, Integer seconds, int amplifier, boolean showParticles, CallbackInfoReturnable cir) { + @Inject(method = "giveEffect", at = @At("HEAD")) + private static void arclight$addReason(CommandSourceStack source, Collection targets, MobEffect effect, Integer seconds, int amplifier, boolean showParticles, CallbackInfoReturnable cir) { for (Entity entity : targets) { if (entity instanceof LivingEntity) { ((LivingEntityBridge) entity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.COMMAND); @@ -26,8 +26,8 @@ public class EffectCommandMixin { } } - @Inject(method = "clearAllEffects", at = @At("HEAD")) - private static void arclight$removeAllReason(CommandSource source, Collection targets, CallbackInfoReturnable cir) { + @Inject(method = "clearEffects", at = @At("HEAD")) + private static void arclight$removeAllReason(CommandSourceStack source, Collection targets, CallbackInfoReturnable cir) { for (Entity entity : targets) { if (entity instanceof LivingEntity) { ((LivingEntityBridge) entity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.COMMAND); @@ -36,7 +36,7 @@ public class EffectCommandMixin { } @Inject(method = "clearEffect", at = @At("HEAD")) - private static void arclight$removeReason(CommandSource source, Collection targets, Effect effect, CallbackInfoReturnable cir) { + private static void arclight$removeReason(CommandSourceStack source, Collection targets, MobEffect effect, CallbackInfoReturnable cir) { for (Entity entity : targets) { if (entity instanceof LivingEntity) { ((LivingEntityBridge) entity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.COMMAND); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/GameRuleCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/GameRuleCommandMixin.java new file mode 100644 index 00000000..414912db --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/GameRuleCommandMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.server.commands; + +import com.mojang.brigadier.context.CommandContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.commands.GameRuleCommand; +import net.minecraft.world.level.GameRules; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(GameRuleCommand.class) +public class GameRuleCommandMixin { + + @Redirect(method = "setRule", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getGameRules()Lnet/minecraft/world/level/GameRules;")) + private static GameRules arclight$perWorldGameRule(MinecraftServer minecraftServer, CommandContext context) { + return context.getSource().getLevel().getGameRules(); + } + + @Redirect(method = "queryRule", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getGameRules()Lnet/minecraft/world/level/GameRules;")) + private static GameRules arclight$perWorldGameRule2(MinecraftServer minecraftServer, CommandSourceStack source) { + return source.getLevel().getGameRules(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/ReloadCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/ReloadCommandMixin.java new file mode 100644 index 00000000..48bad4fd --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/ReloadCommandMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.server.commands; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.commands.ReloadCommand; +import net.minecraft.server.packs.repository.PackRepository; +import net.minecraft.world.level.storage.WorldData; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Collection; + +@Mixin(ReloadCommand.class) +public abstract class ReloadCommandMixin { + + // @formatter:off + @Shadow private static Collection discoverNewPacks(PackRepository p_241058_0_, WorldData p_241058_1_, Collection p_241058_2_) { return null; } + // @formatter:on + + private static void reload(MinecraftServer minecraftserver) { + PackRepository resourcePackList = minecraftserver.getPackRepository(); + WorldData configuration = minecraftserver.getWorldData(); + Collection collection = resourcePackList.getSelectedIds(); + Collection collection2 = discoverNewPacks(resourcePackList, configuration, collection); + minecraftserver.reloadResources(collection2); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/SummonCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/SummonCommandMixin.java new file mode 100644 index 00000000..8292fee6 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/SummonCommandMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.server.commands; + +import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.commands.SummonCommand; +import net.minecraft.world.phys.Vec3; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SummonCommand.class) +public class SummonCommandMixin { + + @Inject(method = "spawnEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;tryAddFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)Z")) + private static void arclight$summonReason(CommandSourceStack source, ResourceLocation type, Vec3 pos, CompoundTag nbt, boolean randomizeProperties, CallbackInfoReturnable cir) { + ((ServerWorldBridge) source.getLevel()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.COMMAND); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TeleportCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TeleportCommandMixin.java new file mode 100644 index 00000000..46832c29 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TeleportCommandMixin.java @@ -0,0 +1,126 @@ +package io.izzel.arclight.common.mixin.core.server.commands; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; +import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.server.commands.TeleportCommand; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.TicketType; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.entity.EntityTeleportEvent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v.CraftWorld; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import javax.annotation.Nullable; +import java.util.Set; + +@Mixin(TeleportCommand.class) +public class TeleportCommandMixin { + + // @formatter:off + @Shadow @Final private static SimpleCommandExceptionType INVALID_POSITION; + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + private static void performTeleport(CommandSourceStack source, Entity teleport, ServerLevel level, double x, double y, double z, Set p_139021_, float p_139022_, float p_139023_, @Nullable TeleportCommand.LookAt p_139024_) throws CommandSyntaxException { + EntityTeleportEvent.TeleportCommand event = ForgeEventFactory.onEntityTeleportCommand(teleport, x, y, z); + if (event.isCanceled()) return; + x = event.getTargetX(); + y = event.getTargetY(); + z = event.getTargetZ(); + BlockPos blockpos = new BlockPos(x, y, z); + if (!Level.isInSpawnableBounds(blockpos)) { + throw INVALID_POSITION.create(); + } else { + float yaw = Mth.wrapDegrees(p_139022_); + float f1 = Mth.wrapDegrees(p_139023_); + if (teleport instanceof ServerPlayer) { + ChunkPos chunkpos = new ChunkPos(new BlockPos(x, y, z)); + level.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkpos, 1, teleport.getId()); + teleport.stopRiding(); + if (((ServerPlayer) teleport).isSleeping()) { + ((ServerPlayer) teleport).stopSleepInBed(true, true); + } + + if (level == teleport.level) { + ((ServerPlayNetHandlerBridge) ((ServerPlayer) teleport).connection).bridge$pushTeleportCause(PlayerTeleportEvent.TeleportCause.COMMAND); + ((ServerPlayer) teleport).connection.teleport(x, y, z, yaw, f1, p_139021_); + } else { + ((ServerPlayerEntityBridge) teleport).bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause.COMMAND); + ((ServerPlayer) teleport).teleportTo(level, x, y, z, yaw, f1); + } + + teleport.setYHeadRot(yaw); + } else { + float pitch = Mth.clamp(f1, -90.0F, 90.0F); + Location to = new Location(((ServerWorldBridge) level).bridge$getWorld(), x, y, z, pitch, yaw); + org.bukkit.event.entity.EntityTeleportEvent bukkitEvent = new org.bukkit.event.entity.EntityTeleportEvent(((EntityBridge) teleport).bridge$getBukkitEntity(), ((EntityBridge) teleport).bridge$getBukkitEntity().getLocation(), to); + Bukkit.getPluginManager().callEvent(bukkitEvent); + if (bukkitEvent.isCancelled()) { + return; + } + + x = to.getX(); + y = to.getY(); + z = to.getZ(); + yaw = to.getYaw(); + pitch = to.getPitch(); + level = ((CraftWorld) to.getWorld()).getHandle(); + if (level == teleport.level) { + teleport.moveTo(x, y, z, yaw, pitch); + teleport.setYHeadRot(yaw); + } else { + teleport.unRide(); + Entity entity = teleport; + teleport = teleport.getType().create(level); + if (teleport == null) { + return; + } + + teleport.restoreFrom(entity); + teleport.moveTo(x, y, z, yaw, pitch); + teleport.setYHeadRot(yaw); + entity.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); + level.addDuringTeleport(teleport); + } + } + + if (p_139024_ != null) { + p_139024_.perform(source, teleport); + } + + if (!(teleport instanceof LivingEntity) || !((LivingEntity) teleport).isFallFlying()) { + teleport.setDeltaMovement(teleport.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D)); + teleport.setOnGround(true); + } + + if (teleport instanceof PathfinderMob) { + ((PathfinderMob) teleport).getNavigation().stop(); + } + + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TimeCommandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java similarity index 74% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TimeCommandMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java index 7592421e..1f31445e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/command/impl/TimeCommandMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/commands/TimeCommandMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.command.impl; +package io.izzel.arclight.common.mixin.core.server.commands; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.command.impl.TimeCommand; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.commands.TimeCommand; +import net.minecraft.server.level.ServerLevel; import org.bukkit.Bukkit; import org.bukkit.event.world.TimeSkipEvent; import org.spongepowered.asm.mixin.Mixin; @@ -12,8 +12,8 @@ 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) { + @Redirect(method = "addTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setDayTime(J)V")) + private static void arclight$addTimeEvent(ServerLevel serverWorld, long time) { TimeSkipEvent event = new TimeSkipEvent(((ServerWorldBridge) serverWorld).bridge$getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - serverWorld.getDayTime()); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -21,8 +21,8 @@ public class TimeCommandMixin { } } - @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) { + @Redirect(method = "setTime", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setDayTime(J)V")) + private static void arclight$setTimeEvent(ServerLevel serverWorld, long time) { TimeSkipEvent event = new TimeSkipEvent(((ServerWorldBridge) serverWorld).bridge$getWorld(), TimeSkipEvent.SkipReason.COMMAND, time - serverWorld.getDayTime()); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/dedicated/DedicatedServerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/dedicated/DedicatedServerMixin.java index 26be07f8..1917e778 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/dedicated/DedicatedServerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/dedicated/DedicatedServerMixin.java @@ -2,11 +2,11 @@ package io.izzel.arclight.common.mixin.core.server.dedicated; import io.izzel.arclight.common.mixin.core.server.MinecraftServerMixin; 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.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.server.ConsoleInput; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.dedicated.PendingCommand; +import net.minecraft.server.rcon.RconConsoleSource; import net.minecrell.terminalconsole.TerminalConsoleAppender; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; @@ -30,14 +30,14 @@ import java.io.IOException; public abstract class DedicatedServerMixin extends MinecraftServerMixin { // @formatter:off - @Shadow @Final public RConConsoleSource rconConsoleSource; + @Shadow @Final public RconConsoleSource rconConsoleSource; // @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 = "initServer", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/dedicated/DedicatedServer;setPlayerList(Lnet/minecraft/server/players/PlayerList;)V")) public void arclight$loadPlugins(CallbackInfoReturnable cir) { BukkitRegistry.unlockRegistries(); ((CraftServer) Bukkit.getServer()).loadPlugins(); @@ -45,20 +45,20 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin { BukkitRegistry.lockRegistries(); } - @Inject(method = "init", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/network/rcon/MainThread;func_242130_a(Lnet/minecraft/network/rcon/IServer;)Lnet/minecraft/network/rcon/MainThread;")) + @Inject(method = "initServer", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/rcon/thread/RconThread;create(Lnet/minecraft/server/ServerInterface;)Lnet/minecraft/server/rcon/thread/RconThread;")) public void arclight$setRcon(CallbackInfoReturnable cir) { this.remoteConsole = new CraftRemoteConsoleCommandSender(this.rconConsoleSource); } - @Redirect(method = "executePendingCommands", at = @At(value = "INVOKE", target = "Lnet/minecraft/command/Commands;handleCommand(Lnet/minecraft/command/CommandSource;Ljava/lang/String;)I")) - private int arclight$serverCommandEvent(Commands commands, CommandSource source, String command) { + @Redirect(method = "handleConsoleInputs", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)I")) + private int arclight$serverCommandEvent(Commands commands, CommandSourceStack source, String command) { if (command.isEmpty()) { return 0; } ServerCommandEvent event = new ServerCommandEvent(console, command); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - server.dispatchServerCommand(console, new PendingCommand(event.getCommand(), source)); + server.dispatchServerCommand(console, new ConsoleInput(event.getCommand(), source)); } return 0; } @@ -68,20 +68,20 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin { * @reason */ @Overwrite - public String handleRConCommand(String command) { - this.rconConsoleSource.resetLog(); - this.runImmediately(() -> { + public String runCommand(String command) { + this.rconConsoleSource.prepareForCommand(); + this.executeBlocking(() -> { RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, command); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - this.server.dispatchServerCommand(remoteConsole, new PendingCommand(event.getCommand(), this.rconConsoleSource.getCommandSource())); + this.server.dispatchServerCommand(remoteConsole, new ConsoleInput(event.getCommand(), this.rconConsoleSource.createCommandSourceStack())); }); - return this.rconConsoleSource.getLogContents(); + return this.rconConsoleSource.getCommandResponse(); } - @Inject(method = "systemExitNow", at = @At("RETURN")) + @Inject(method = "onServerExit", at = @At("RETURN")) public void arclight$exitNow(CallbackInfo ci) { try { TerminalConsoleAppender.close(); @@ -96,7 +96,7 @@ public abstract class DedicatedServerMixin extends MinecraftServerMixin { * @reason */ @Overwrite - public String getPlugins() { + public String getPluginNames() { StringBuilder result = new StringBuilder(); org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/BanEntryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/BanEntryMixin.java index 6926dae0..e23bf612 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/BanEntryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/BanEntryMixin.java @@ -1,22 +1,22 @@ package io.izzel.arclight.common.mixin.core.server.management; import io.izzel.arclight.common.bridge.server.management.BanEntryBridge; -import net.minecraft.server.management.BanEntry; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import java.util.Date; +import net.minecraft.server.players.BanListEntry; -@Mixin(BanEntry.class) +@Mixin(BanListEntry.class) public class BanEntryMixin implements BanEntryBridge { // @formatter:off - @Shadow @Final protected Date banStartDate; + @Shadow @Final protected Date created; // @formatter:on public Date getCreated() { - return this.banStartDate; + return this.created; } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerInteractionManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerInteractionManagerMixin.java index ddf98fba..80590707 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerInteractionManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerInteractionManagerMixin.java @@ -5,30 +5,30 @@ import io.izzel.arclight.common.bridge.server.management.PlayerInteractionManage import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.util.ArclightCaptures; import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.block.BlockState; -import net.minecraft.block.CakeBlock; -import net.minecraft.block.DoorBlock; -import net.minecraft.block.TrapDoorBlock; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUseContext; -import net.minecraft.item.TallBlockItem; -import net.minecraft.network.play.client.CPlayerDiggingPacket; -import net.minecraft.network.play.server.SChangeBlockPacket; -import net.minecraft.network.play.server.SPlayerDiggingPacket; -import net.minecraft.server.management.PlayerInteractionManager; -import net.minecraft.state.properties.DoubleBlockHalf; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.GameType; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.protocol.game.ClientboundBlockBreakAckPacket; +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; +import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.DoubleHighBlockItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CakeBlock; +import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.common.ForgeHooks; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -47,23 +47,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.List; import java.util.Objects; -@Mixin(PlayerInteractionManager.class) +@Mixin(ServerPlayerGameMode.class) public abstract class PlayerInteractionManagerMixin implements PlayerInteractionManagerBridge { // @formatter:off - @Shadow public ServerWorld world; - @Shadow public ServerPlayerEntity player; + @Shadow public ServerLevel level; + @Shadow public ServerPlayer player; @Shadow public abstract boolean isCreative(); - @Shadow private GameType gameType; - @Shadow private int initialDamage; - @Shadow private int ticks; + @Shadow private GameType gameModeForPlayer; + @Shadow private int destroyProgressStart; + @Shadow private int gameTicks; @Shadow private boolean isDestroyingBlock; @Shadow private BlockPos destroyPos; - @Shadow private int durabilityRemainingOnBlock; - @Shadow private boolean receivedFinishDiggingPacket; + @Shadow private int lastSentState; + @Shadow private boolean hasDelayedDestroy; @Shadow private BlockPos delayedDestroyPos; - @Shadow private int initialBlockDamage; - @Shadow public abstract void func_229860_a_(BlockPos p_229860_1_, CPlayerDiggingPacket.Action p_229860_2_, String p_229860_3_); + @Shadow private int delayedTickStart; + @Shadow public abstract void destroyAndAck(BlockPos p_229860_1_, ServerboundPlayerActionPacket.Action p_229860_2_, String p_229860_3_); // @formatter:on public boolean interactResult = false; @@ -74,135 +74,135 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction * @reason */ @Overwrite - public void func_225416_a(BlockPos blockPos, CPlayerDiggingPacket.Action action, Direction direction, int i) { - double d0 = this.player.getPosX() - (blockPos.getX() + 0.5); - double d2 = this.player.getPosY() - (blockPos.getY() + 0.5) + 1.5; - double d3 = this.player.getPosZ() - (blockPos.getZ() + 0.5); + public void handleBlockBreakAction(BlockPos blockPos, ServerboundPlayerActionPacket.Action action, Direction direction, int i) { + double d0 = this.player.getX() - (blockPos.getX() + 0.5); + double d2 = this.player.getY() - (blockPos.getY() + 0.5) + 1.5; + double d3 = this.player.getZ() - (blockPos.getZ() + 0.5); double d4 = d0 * d0 + d2 * d2 + d3 * d3; double dist = player.getAttribute(net.minecraftforge.common.ForgeMod.REACH_DISTANCE.get()).getValue() + 1; dist *= dist; net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock forgeEvent = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(player, blockPos, direction); if (forgeEvent.isCanceled() || (!this.isCreative() && forgeEvent.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY)) { // Restore block and te data - player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, world.getBlockState(blockPos), action, false, "mod canceled")); - world.notifyBlockUpdate(blockPos, world.getBlockState(blockPos), world.getBlockState(blockPos), 3); + player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, level.getBlockState(blockPos), action, false, "mod canceled")); + level.sendBlockUpdated(blockPos, level.getBlockState(blockPos), level.getBlockState(blockPos), 3); return; } if (d4 > dist) { - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, false, "too far")); + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "too far")); } else if (blockPos.getY() >= i) { - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, false, "too high")); - } else if (action == CPlayerDiggingPacket.Action.START_DESTROY_BLOCK) { - if (!this.world.isBlockModifiable(this.player, blockPos)) { - CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getCurrentItem(), Hand.MAIN_HAND); - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, false, "may not interact")); - TileEntity tileentity = this.world.getTileEntity(blockPos); + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "too high")); + } else if (action == ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK) { + if (!this.level.mayInteract(this.player, blockPos)) { + CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getSelected(), InteractionHand.MAIN_HAND); + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "may not interact")); + BlockEntity tileentity = this.level.getBlockEntity(blockPos); if (tileentity != null) { - this.player.connection.sendPacket(tileentity.getUpdatePacket()); + this.player.connection.send(tileentity.getUpdatePacket()); } return; } - PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getCurrentItem(), Hand.MAIN_HAND); + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.LEFT_CLICK_BLOCK, blockPos, direction, this.player.inventory.getSelected(), InteractionHand.MAIN_HAND); if (event.isCancelled()) { - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, blockPos)); - TileEntity tileentity2 = this.world.getTileEntity(blockPos); + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); + BlockEntity tileentity2 = this.level.getBlockEntity(blockPos); if (tileentity2 != null) { - this.player.connection.sendPacket(tileentity2.getUpdatePacket()); + this.player.connection.send(tileentity2.getUpdatePacket()); } return; } if (this.isCreative()) { - this.func_229860_a_(blockPos, action, "creative destroy"); + this.destroyAndAck(blockPos, action, "creative destroy"); return; } - if (this.player.blockActionRestricted(this.world, blockPos, this.gameType)) { - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, false, "block action restricted")); + if (this.player.blockActionRestricted(this.level, blockPos, this.gameModeForPlayer)) { + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, false, "block action restricted")); return; } - this.initialDamage = this.ticks; + this.destroyProgressStart = this.gameTicks; float f = 1.0f; - BlockState iblockdata = this.world.getBlockState(blockPos); + BlockState iblockdata = this.level.getBlockState(blockPos); if (event.useInteractedBlock() == org.bukkit.event.Event.Result.DENY) { - BlockState data = this.world.getBlockState(blockPos); + BlockState data = this.level.getBlockState(blockPos); if (data.getBlock() instanceof DoorBlock) { - boolean bottom = data.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER; - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, blockPos)); - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockPos.up() : blockPos.down())); + boolean bottom = data.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER; + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, bottom ? blockPos.above() : blockPos.below())); } else if (data.getBlock() instanceof TrapDoorBlock) { - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, blockPos)); + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); } - } else if (!iblockdata.isAir(world, blockPos)) { + } else if (!iblockdata.isAir(level, blockPos)) { if (forgeEvent.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY) { - iblockdata.onBlockClicked(this.world, blockPos, this.player); + iblockdata.attack(this.level, blockPos, this.player); } - f = iblockdata.getPlayerRelativeBlockHardness(this.player, this.player.world, blockPos); + f = iblockdata.getDestroyProgress(this.player, this.player.level, blockPos); } if (event.useItemInHand() == Event.Result.DENY) { if (f > 1.0f) { - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, blockPos)); + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); } return; } - BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), this.player.inventory.getCurrentItem(), f >= 1.0f); + BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, blockPos.getX(), blockPos.getY(), blockPos.getZ(), this.player.inventory.getSelected(), f >= 1.0f); if (blockEvent.isCancelled()) { - this.player.connection.sendPacket(new SChangeBlockPacket(this.world, blockPos)); + this.player.connection.send(new ClientboundBlockUpdatePacket(this.level, blockPos)); return; } if (blockEvent.getInstaBreak()) { f = 2.0f; } - if (!iblockdata.isAir(world, blockPos) && f >= 1.0f) { - this.func_229860_a_(blockPos, action, "insta mine"); + if (!iblockdata.isAir(level, blockPos) && f >= 1.0f) { + this.destroyAndAck(blockPos, action, "insta mine"); } else { if (this.isDestroyingBlock) { - this.player.connection.sendPacket(new SPlayerDiggingPacket(this.destroyPos, this.world.getBlockState(this.destroyPos), CPlayerDiggingPacket.Action.START_DESTROY_BLOCK, false, "abort destroying since another started (client insta mine, server disagreed)")); + this.player.connection.send(new ClientboundBlockBreakAckPacket(this.destroyPos, this.level.getBlockState(this.destroyPos), ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, false, "abort destroying since another started (client insta mine, server disagreed)")); } this.isDestroyingBlock = true; this.destroyPos = blockPos; int j = (int) (f * 10.0f); - this.world.sendBlockBreakProgress(this.player.getEntityId(), blockPos, j); - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, true, "actual start of destroying")); - this.durabilityRemainingOnBlock = j; + this.level.destroyBlockProgress(this.player.getId(), blockPos, j); + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, true, "actual start of destroying")); + this.lastSentState = j; } - } else if (action == CPlayerDiggingPacket.Action.STOP_DESTROY_BLOCK) { + } else if (action == ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK) { if (blockPos.equals(this.destroyPos)) { - int k = this.ticks - this.initialDamage; - BlockState iblockdata = this.world.getBlockState(blockPos); + int k = this.gameTicks - this.destroyProgressStart; + BlockState iblockdata = this.level.getBlockState(blockPos); if (!iblockdata.isAir()) { - float f2 = iblockdata.getPlayerRelativeBlockHardness(this.player, this.player.world, blockPos) * (k + 1); + float f2 = iblockdata.getDestroyProgress(this.player, this.player.level, blockPos) * (k + 1); if (f2 >= 0.7f) { this.isDestroyingBlock = false; - this.world.sendBlockBreakProgress(this.player.getEntityId(), blockPos, -1); - this.func_229860_a_(blockPos, action, "destroyed"); + this.level.destroyBlockProgress(this.player.getId(), blockPos, -1); + this.destroyAndAck(blockPos, action, "destroyed"); return; } - if (!this.receivedFinishDiggingPacket) { + if (!this.hasDelayedDestroy) { this.isDestroyingBlock = false; - this.receivedFinishDiggingPacket = true; + this.hasDelayedDestroy = true; this.delayedDestroyPos = blockPos; - this.initialBlockDamage = this.initialDamage; + this.delayedTickStart = this.destroyProgressStart; } } } - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, true, "stopped destroying")); - } else if (action == CPlayerDiggingPacket.Action.ABORT_DESTROY_BLOCK) { + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, true, "stopped destroying")); + } else if (action == ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK) { this.isDestroyingBlock = false; if (!Objects.equals(this.destroyPos, blockPos)) { ArclightMod.LOGGER.debug("Mismatch in destroy block pos: " + this.destroyPos + " " + blockPos); - this.world.sendBlockBreakProgress(this.player.getEntityId(), this.destroyPos, -1); - this.player.connection.sendPacket(new SPlayerDiggingPacket(this.destroyPos, this.world.getBlockState(this.destroyPos), action, true, "aborted mismatched destroying")); + this.level.destroyBlockProgress(this.player.getId(), this.destroyPos, -1); + this.player.connection.send(new ClientboundBlockBreakAckPacket(this.destroyPos, this.level.getBlockState(this.destroyPos), action, true, "aborted mismatched destroying")); } - this.world.sendBlockBreakProgress(this.player.getEntityId(), blockPos, -1); - this.player.connection.sendPacket(new SPlayerDiggingPacket(blockPos, this.world.getBlockState(blockPos), action, true, "aborted destroying")); + this.level.destroyBlockProgress(this.player.getId(), blockPos, -1); + this.player.connection.send(new ClientboundBlockBreakAckPacket(blockPos, this.level.getBlockState(blockPos), action, true, "aborted destroying")); } } - @Inject(method = "tryHarvestBlock", at = @At("RETURN")) + @Inject(method = "destroyBlock", at = @At("RETURN")) public void arclight$resetBlockBreak(BlockPos pos, CallbackInfoReturnable cir) { List blockDrops = ArclightCaptures.getBlockDrops(); org.bukkit.block.BlockState state = ArclightCaptures.getBlockBreakPlayerState(); BlockBreakEvent breakEvent = ArclightCaptures.resetBlockBreakPlayer(); if (blockDrops != null && (breakEvent == null || breakEvent.isDropItems())) { - CraftBlock craftBlock = CraftBlock.at(this.world, pos); + CraftBlock craftBlock = CraftBlock.at(this.level, pos); CraftEventFactory.handleBlockDropItemEvent(craftBlock, state, this.player, blockDrops); } } @@ -232,76 +232,76 @@ public abstract class PlayerInteractionManagerMixin implements PlayerInteraction * @reason */ @Overwrite - public ActionResultType func_219441_a(ServerPlayerEntity playerIn, World worldIn, ItemStack stackIn, Hand handIn, BlockRayTraceResult blockRaytraceResultIn) { - BlockPos blockpos = blockRaytraceResultIn.getPos(); + public InteractionResult useItemOn(ServerPlayer playerIn, Level worldIn, ItemStack stackIn, InteractionHand handIn, BlockHitResult blockRaytraceResultIn) { + BlockPos blockpos = blockRaytraceResultIn.getBlockPos(); BlockState blockstate = worldIn.getBlockState(blockpos); - ActionResultType resultType = ActionResultType.PASS; + InteractionResult resultType = InteractionResult.PASS; boolean cancelledBlock = false; - if (this.gameType == GameType.SPECTATOR) { - INamedContainerProvider provider = blockstate.getContainer(worldIn, blockpos); - cancelledBlock = !(provider instanceof INamedContainerProvider); + if (this.gameModeForPlayer == GameType.SPECTATOR) { + MenuProvider provider = blockstate.getMenuProvider(worldIn, blockpos); + cancelledBlock = !(provider instanceof MenuProvider); } - if (playerIn.getCooldownTracker().hasCooldown(stackIn.getItem())) { + if (playerIn.getCooldowns().isOnCooldown(stackIn.getItem())) { cancelledBlock = true; } - PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getFace(), stackIn, cancelledBlock, handIn); + PlayerInteractEvent bukkitEvent = CraftEventFactory.callPlayerInteractEvent(playerIn, Action.RIGHT_CLICK_BLOCK, blockpos, blockRaytraceResultIn.getDirection(), stackIn, cancelledBlock, handIn); bridge$setFiredInteract(true); bridge$setInteractResult(bukkitEvent.useItemInHand() == Event.Result.DENY); if (bukkitEvent.useInteractedBlock() == Event.Result.DENY) { if (blockstate.getBlock() instanceof DoorBlock) { - boolean bottom = blockstate.get(DoorBlock.HALF) == DoubleBlockHalf.LOWER; - playerIn.connection.sendPacket(new SChangeBlockPacket(this.world, bottom ? blockpos.up() : blockpos.down())); + boolean bottom = blockstate.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER; + playerIn.connection.send(new ClientboundBlockUpdatePacket(this.level, bottom ? blockpos.above() : blockpos.below())); } else if (blockstate.getBlock() instanceof CakeBlock) { ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().sendHealthUpdate(); - } else if (stackIn.getItem() instanceof TallBlockItem) { + } else if (stackIn.getItem() instanceof DoubleHighBlockItem) { // send a correcting update to the client, as it already placed the upper half of the bisected item - playerIn.connection.sendPacket(new SChangeBlockPacket(world, blockpos.offset(blockRaytraceResultIn.getFace()).up())); + playerIn.connection.send(new ClientboundBlockUpdatePacket(level, blockpos.relative(blockRaytraceResultIn.getDirection()).above())); // send a correcting update to the client for the block above as well, this because of replaceable blocks (such as grass, sea grass etc) - playerIn.connection.sendPacket(new SChangeBlockPacket(world, blockpos.up())); + playerIn.connection.send(new ClientboundBlockUpdatePacket(level, blockpos.above())); } ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory(); - resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? ActionResultType.SUCCESS : ActionResultType.PASS); - } else if (this.gameType == GameType.SPECTATOR) { - INamedContainerProvider inamedcontainerprovider = blockstate.getContainer(worldIn, blockpos); + resultType = ((bukkitEvent.useItemInHand() != Event.Result.ALLOW) ? InteractionResult.SUCCESS : InteractionResult.PASS); + } else if (this.gameModeForPlayer == GameType.SPECTATOR) { + MenuProvider inamedcontainerprovider = blockstate.getMenuProvider(worldIn, blockpos); if (inamedcontainerprovider != null) { - playerIn.openContainer(inamedcontainerprovider); - return ActionResultType.SUCCESS; + playerIn.openMenu(inamedcontainerprovider); + return InteractionResult.SUCCESS; } else { - return ActionResultType.PASS; + return InteractionResult.PASS; } } else { net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(playerIn, handIn, blockpos, blockRaytraceResultIn); if (event.isCanceled()) return event.getCancellationResult(); - ItemUseContext itemusecontext = new ItemUseContext(playerIn, handIn, blockRaytraceResultIn); + UseOnContext itemusecontext = new UseOnContext(playerIn, handIn, blockRaytraceResultIn); if (event.getUseItem() != net.minecraftforge.eventbus.api.Event.Result.DENY) { - ActionResultType result = stackIn.onItemUseFirst(itemusecontext); - if (result != ActionResultType.PASS) return result; + InteractionResult result = stackIn.onItemUseFirst(itemusecontext); + if (result != InteractionResult.PASS) return result; } - boolean flag = !playerIn.getHeldItemMainhand().isEmpty() || !playerIn.getHeldItemOffhand().isEmpty(); - boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getHeldItemMainhand().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getHeldItemOffhand().doesSneakBypassUse(worldIn, blockpos, playerIn)); + boolean flag = !playerIn.getMainHandItem().isEmpty() || !playerIn.getOffhandItem().isEmpty(); + boolean flag1 = (playerIn.isSecondaryUseActive() && flag) && !(playerIn.getMainHandItem().doesSneakBypassUse(worldIn, blockpos, playerIn) && playerIn.getOffhandItem().doesSneakBypassUse(worldIn, blockpos, playerIn)); ItemStack itemstack = stackIn.copy(); if (event.getUseBlock() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && !flag1)) { - resultType = blockstate.onBlockActivated(worldIn, playerIn, handIn, blockRaytraceResultIn); - if (resultType.isSuccessOrConsume()) { - CriteriaTriggers.RIGHT_CLICK_BLOCK_WITH_ITEM.test(playerIn, blockpos, itemstack); + resultType = blockstate.use(worldIn, playerIn, handIn, blockRaytraceResultIn); + if (resultType.consumesAction()) { + CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(playerIn, blockpos, itemstack); return resultType; } } - if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || (!stackIn.isEmpty() && resultType != ActionResultType.SUCCESS && !bridge$getInteractResult())) { + if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || (!stackIn.isEmpty() && resultType != InteractionResult.SUCCESS && !bridge$getInteractResult())) { if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) { - return ActionResultType.PASS; + return InteractionResult.PASS; } if (this.isCreative()) { int i = stackIn.getCount(); - resultType = stackIn.onItemUse(itemusecontext); + resultType = stackIn.useOn(itemusecontext); stackIn.setCount(i); } else { - resultType = stackIn.onItemUse(itemusecontext); + resultType = stackIn.useOn(itemusecontext); } - if (resultType.isSuccessOrConsume()) { - CriteriaTriggers.RIGHT_CLICK_BLOCK_WITH_ITEM.test(playerIn, blockpos, itemstack); + if (resultType.consumesAction()) { + CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger(playerIn, blockpos, itemstack); } return resultType; } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java index 65d50d5a..a23b9d40 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java @@ -14,54 +14,53 @@ import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.mod.server.ArclightServer; import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.mixin.Eject; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.login.ServerLoginNetHandler; -import net.minecraft.network.play.server.SChangeGameStatePacket; -import net.minecraft.network.play.server.SChatPacket; -import net.minecraft.network.play.server.SEntityStatusPacket; -import net.minecraft.network.play.server.SPlayEntityEffectPacket; -import net.minecraft.network.play.server.SPlaySoundEffectPacket; -import net.minecraft.network.play.server.SRespawnPacket; -import net.minecraft.network.play.server.SServerDifficultyPacket; -import net.minecraft.network.play.server.SSetExperiencePacket; -import net.minecraft.network.play.server.SUpdateViewDistancePacket; -import net.minecraft.network.play.server.SWorldSpawnChangedPacket; -import net.minecraft.potion.EffectInstance; +import net.minecraft.Util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket; +import net.minecraft.network.protocol.game.ClientboundChatPacket; +import net.minecraft.network.protocol.game.ClientboundEntityEventPacket; +import net.minecraft.network.protocol.game.ClientboundGameEventPacket; +import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundSetChunkCacheRadiusPacket; +import net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSetExperiencePacket; +import net.minecraft.network.protocol.game.ClientboundSoundPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.management.BanList; -import net.minecraft.server.management.DemoPlayerInteractionManager; -import net.minecraft.server.management.IPBanEntry; -import net.minecraft.server.management.IPBanList; -import net.minecraft.server.management.PlayerInteractionManager; -import net.minecraft.server.management.PlayerList; -import net.minecraft.server.management.ProfileBanEntry; -import net.minecraft.stats.ServerStatisticsManager; +import net.minecraft.server.level.DemoMode; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.server.network.ServerLoginPacketListenerImpl; +import net.minecraft.server.players.IpBanList; +import net.minecraft.server.players.IpBanListEntry; +import net.minecraft.server.players.PlayerList; +import net.minecraft.server.players.UserBanList; +import net.minecraft.server.players.UserBanListEntry; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.stats.ServerStatsCounter; import net.minecraft.tags.BlockTags; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.Util; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.registry.DynamicRegistries; -import net.minecraft.util.text.ChatType; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeManager; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.FolderName; -import net.minecraft.world.storage.IWorldInfo; -import net.minecraft.world.storage.PlayerData; +import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.level.storage.LevelResource; +import net.minecraft.world.level.storage.PlayerDataStorage; +import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.CraftServer; @@ -102,29 +101,29 @@ import java.util.UUID; public abstract class PlayerListMixin implements PlayerListBridge { // @formatter:off - @Override @Accessor("players") @Mutable public abstract void bridge$setPlayers(List players); - @Override @Accessor("players") public abstract List bridge$getPlayers(); - @Shadow @Final public PlayerData playerDataManager; - @Shadow @Final private BanList bannedPlayers; - @Shadow @Final private static SimpleDateFormat DATE_FORMAT; - @Shadow public abstract boolean canJoin(GameProfile profile); - @Shadow @Final private IPBanList bannedIPs; - @Shadow @Final public List players; + @Override @Accessor("players") @Mutable public abstract void bridge$setPlayers(List players); + @Override @Accessor("players") public abstract List bridge$getPlayers(); + @Shadow @Final public PlayerDataStorage playerIo; + @Shadow @Final private UserBanList bans; + @Shadow @Final private static SimpleDateFormat BAN_DATE_FORMAT; + @Shadow public abstract boolean isWhiteListed(GameProfile profile); + @Shadow @Final private IpBanList ipBans; + @Shadow @Final public List players; @Shadow @Final protected int maxPlayers; - @Shadow public abstract boolean bypassesPlayerLimit(GameProfile profile); - @Shadow protected abstract void writePlayerData(ServerPlayerEntity playerIn); + @Shadow public abstract boolean canBypassPlayerLimit(GameProfile profile); + @Shadow protected abstract void save(ServerPlayer playerIn); @Shadow @Final private MinecraftServer server; - @Shadow public abstract BanList getBannedPlayers(); - @Shadow public abstract IPBanList getBannedIPs(); - @Shadow(remap = false) public abstract boolean removePlayer(ServerPlayerEntity player); - @Shadow public abstract void sendWorldInfo(ServerPlayerEntity playerIn, ServerWorld worldIn); - @Shadow public abstract void updatePermissionLevel(ServerPlayerEntity player); - @Shadow(remap = false) public abstract boolean addPlayer(ServerPlayerEntity player); - @Shadow @Final private Map uuidToPlayerMap; - @Shadow public abstract void sendInventory(ServerPlayerEntity playerIn); - @Shadow public abstract void func_232641_a_(ITextComponent p_232641_1_, ChatType p_232641_2_, UUID p_232641_3_); - @Shadow @Nullable public abstract ServerPlayerEntity getPlayerByUUID(UUID playerUUID); - @Shadow protected abstract void setPlayerGameTypeBasedOnOther(ServerPlayerEntity target, @org.jetbrains.annotations.Nullable ServerPlayerEntity source, ServerWorld worldIn); + @Shadow public abstract UserBanList getBans(); + @Shadow public abstract IpBanList getIpBans(); + @Shadow(remap = false) public abstract boolean removePlayer(ServerPlayer player); + @Shadow public abstract void sendLevelInfo(ServerPlayer playerIn, ServerLevel worldIn); + @Shadow public abstract void sendPlayerPermissionLevel(ServerPlayer player); + @Shadow(remap = false) public abstract boolean addPlayer(ServerPlayer player); + @Shadow @Final private Map playersByUUID; + @Shadow public abstract void sendAllPlayerInfo(ServerPlayer playerIn); + @Shadow public abstract void broadcastMessage(Component p_232641_1_, ChatType p_232641_2_, UUID p_232641_3_); + @Shadow @Nullable public abstract ServerPlayer getPlayer(UUID playerUUID); + @Shadow protected abstract void updatePlayerGameMode(ServerPlayer target, @org.jetbrains.annotations.Nullable ServerPlayer source, ServerLevel worldIn); // @formatter:on private CraftServer cserver; @@ -135,110 +134,110 @@ public abstract class PlayerListMixin implements PlayerListBridge { } @Inject(method = "", at = @At("RETURN")) - private void arclight$loadServer(MinecraftServer minecraftServer, DynamicRegistries.Impl p_i231425_2_, PlayerData p_i231425_3_, int p_i231425_4_, CallbackInfo ci) { + private void arclight$loadServer(MinecraftServer minecraftServer, RegistryAccess.RegistryHolder p_i231425_2_, PlayerDataStorage p_i231425_3_, int p_i231425_4_, CallbackInfo ci) { cserver = ArclightServer.createOrLoad((DedicatedServer) minecraftServer, (PlayerList) (Object) this); } - @Redirect(method = "initializeConnectionToPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getWorld(Lnet/minecraft/util/RegistryKey;)Lnet/minecraft/world/server/ServerWorld;")) - private ServerWorld arclight$spawnLocationEvent(MinecraftServer minecraftServer, RegistryKey dimension, NetworkManager netManager, ServerPlayerEntity playerIn) { + @Redirect(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getLevel(Lnet/minecraft/resources/ResourceKey;)Lnet/minecraft/server/level/ServerLevel;")) + private ServerLevel arclight$spawnLocationEvent(MinecraftServer minecraftServer, ResourceKey dimension, Connection netManager, ServerPlayer playerIn) { CraftPlayer player = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(); PlayerSpawnLocationEvent event = new PlayerSpawnLocationEvent(player, player.getLocation()); cserver.getPluginManager().callEvent(event); Location loc = event.getSpawnLocation(); - ServerWorld world = ((CraftWorld) loc.getWorld()).getHandle(); - playerIn.setWorld(world); - playerIn.setPositionAndRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); + ServerLevel world = ((CraftWorld) loc.getWorld()).getHandle(); + playerIn.setLevel(world); + playerIn.absMoveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); return world; } - @Redirect(method = "initializeConnectionToPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/server/management/PlayerList;viewDistance:I")) - private int arclight$spigotViewDistance(PlayerList playerList, NetworkManager netManager, ServerPlayerEntity playerIn) { - return ((WorldBridge) playerIn.getServerWorld()).bridge$spigotConfig().viewDistance; + @Redirect(method = "placeNewPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/server/players/PlayerList;viewDistance:I")) + private int arclight$spigotViewDistance(PlayerList playerList, Connection netManager, ServerPlayer playerIn) { + return ((WorldBridge) playerIn.getLevel()).bridge$spigotConfig().viewDistance; } @Eject(method = "initializeConnectionToPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;func_232641_a_(Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/util/text/ChatType;Ljava/util/UUID;)V")) - private void arclight$playerJoin(PlayerList playerList, ITextComponent component, ChatType chatType, UUID uuid, CallbackInfo ci, NetworkManager netManager, ServerPlayerEntity playerIn) { + private void arclight$playerJoin(PlayerList playerList, Component component, ChatType chatType, UUID uuid, CallbackInfo ci, Connection netManager, ServerPlayer playerIn) { PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(this.cserver.getPlayer(playerIn), CraftChatMessage.fromComponent(component)); this.players.add(playerIn); - this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn); + this.playersByUUID.put(playerIn.getUUID(), playerIn); this.cserver.getPluginManager().callEvent(playerJoinEvent); - if (!playerIn.connection.netManager.isChannelOpen()) { + if (!playerIn.connection.connection.isConnected()) { ci.cancel(); return; } this.players.remove(playerIn); String joinMessage = playerJoinEvent.getJoinMessage(); if (joinMessage != null && joinMessage.length() > 0) { - for (ITextComponent line : CraftChatMessage.fromString(joinMessage)) { - this.server.getPlayerList().sendPacketToAllPlayers(new SChatPacket(line, ChatType.SYSTEM, Util.DUMMY_UUID)); + for (Component line : CraftChatMessage.fromString(joinMessage)) { + this.server.getPlayerList().broadcastAll(new ClientboundChatPacket(line, ChatType.SYSTEM, Util.NIL_UUID)); } } } - @Inject(method = "func_212504_a", cancellable = true, at = @At("HEAD")) - private void arclight$returnIfSet(ServerWorld world, CallbackInfo ci) { - if (this.playerDataManager != null) { + @Inject(method = "setLevel", cancellable = true, at = @At("HEAD")) + private void arclight$returnIfSet(ServerLevel world, CallbackInfo ci) { + if (this.playerIo != null) { ci.cancel(); } } - @Inject(method = "writePlayerData", cancellable = true, at = @At("HEAD")) - private void arclight$returnIfNotPersist(ServerPlayerEntity playerIn, CallbackInfo ci) { + @Inject(method = "save", cancellable = true, at = @At("HEAD")) + private void arclight$returnIfNotPersist(ServerPlayer playerIn, CallbackInfo ci) { if (!((ServerPlayerEntityBridge) playerIn).bridge$isPersist()) { ci.cancel(); } } - @Inject(method = "playerLoggedOut", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;writePlayerData(Lnet/minecraft/entity/player/ServerPlayerEntity;)V")) - private void arclight$playerQuitPre(ServerPlayerEntity playerIn, CallbackInfo ci) { - if (playerIn.container != playerIn.openContainer) { + @Inject(method = "remove", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;save(Lnet/minecraft/server/level/ServerPlayer;)V")) + private void arclight$playerQuitPre(ServerPlayer playerIn, CallbackInfo ci) { + if (playerIn.inventoryMenu != playerIn.containerMenu) { ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().closeInventory(); } PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(playerIn), "\u00A7e" + playerIn.getScoreboardName() + " left the game"); cserver.getPluginManager().callEvent(playerQuitEvent); ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); - playerIn.playerTick(); + playerIn.doTick(); ArclightCaptures.captureQuitMessage(playerQuitEvent.getQuitMessage()); cserver.getScoreboardManager().removePlayer(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity()); } @Override - public ServerPlayerEntity bridge$canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile, ServerLoginNetHandler handler) { - UUID uuid = PlayerEntity.getUUID(gameProfile); - List list = Lists.newArrayList(); - for (ServerPlayerEntity entityplayer : this.players) { - if (entityplayer.getUniqueID().equals(uuid)) { + public ServerPlayer bridge$canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile, ServerLoginPacketListenerImpl handler) { + UUID uuid = net.minecraft.world.entity.player.Player.createPlayerUUID(gameProfile); + List list = Lists.newArrayList(); + for (ServerPlayer entityplayer : this.players) { + if (entityplayer.getUUID().equals(uuid)) { list.add(entityplayer); } } - for (ServerPlayerEntity entityplayer : list) { - this.writePlayerData(entityplayer); - entityplayer.connection.disconnect(new TranslationTextComponent("multiplayer.disconnect.duplicate_login")); + for (ServerPlayer entityplayer : list) { + this.save(entityplayer); + entityplayer.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.duplicate_login")); } - ServerPlayerEntity entity = new ServerPlayerEntity(this.server, this.server.getWorld(World.OVERWORLD), gameProfile, new PlayerInteractionManager(this.server.getWorld(World.OVERWORLD))); + ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameProfile, new ServerPlayerGameMode(this.server.getLevel(Level.OVERWORLD))); Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(); String hostname = handler == null ? "" : ((ServerLoginNetHandlerBridge) handler).bridge$getHostname(); - InetAddress realAddress = handler == null ? ((InetSocketAddress) socketAddress).getAddress() : ((InetSocketAddress) ((NetworkManagerBridge) handler.networkManager).bridge$getRawAddress()).getAddress(); + InetAddress realAddress = handler == null ? ((InetSocketAddress) socketAddress).getAddress() : ((InetSocketAddress) ((NetworkManagerBridge) handler.connection).bridge$getRawAddress()).getAddress(); PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((InetSocketAddress) socketAddress).getAddress(), realAddress); - if (this.getBannedPlayers().isBanned(gameProfile) && !this.getBannedPlayers().getEntry(gameProfile).hasBanExpired()) { - ProfileBanEntry gameprofilebanentry = this.bannedPlayers.getEntry(gameProfile); - TranslationTextComponent chatmessage = new TranslationTextComponent("multiplayer.disconnect.banned.reason", gameprofilebanentry.getBanReason()); - if (gameprofilebanentry.getBanEndDate() != null) { - chatmessage.append(new TranslationTextComponent("multiplayer.disconnect.banned.expiration", DATE_FORMAT.format(gameprofilebanentry.getBanEndDate()))); + if (this.getBans().isBanned(gameProfile) && !this.getBans().get(gameProfile).hasExpired()) { + UserBanListEntry gameprofilebanentry = this.bans.get(gameProfile); + TranslatableComponent chatmessage = new TranslatableComponent("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason()); + if (gameprofilebanentry.getExpires() != null) { + chatmessage.append(new TranslatableComponent("multiplayer.disconnect.banned.expiration", BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires()))); } event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); - } else if (!this.canJoin(gameProfile)) { + } else if (!this.isWhiteListed(gameProfile)) { event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, SpigotConfig.whitelistMessage); - } else if (this.getBannedIPs().isBanned(socketAddress) && !this.getBannedIPs().getBanEntry(socketAddress).hasBanExpired()) { - IPBanEntry ipbanentry = this.bannedIPs.getBanEntry(socketAddress); - TranslationTextComponent chatmessage = new TranslationTextComponent("multiplayer.disconnect.banned_ip.reason", ipbanentry.getBanReason()); - if (ipbanentry.getBanEndDate() != null) { - chatmessage.append(new TranslationTextComponent("multiplayer.disconnect.banned_ip.expiration", DATE_FORMAT.format(ipbanentry.getBanEndDate()))); + } else if (this.getIpBans().isBanned(socketAddress) && !this.getIpBans().get(socketAddress).hasExpired()) { + IpBanListEntry ipbanentry = this.ipBans.get(socketAddress); + TranslatableComponent chatmessage = new TranslatableComponent("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason()); + if (ipbanentry.getExpires() != null) { + chatmessage.append(new TranslatableComponent("multiplayer.disconnect.banned_ip.expiration", BAN_DATE_FORMAT.format(ipbanentry.getExpires()))); } event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); - } else if (this.players.size() >= this.maxPlayers && !this.bypassesPlayerLimit(gameProfile)) { + } else if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameProfile)) { event.disallow(PlayerLoginEvent.Result.KICK_FULL, SpigotConfig.serverFullMessage); } this.cserver.getPluginManager().callEvent(event); @@ -252,16 +251,16 @@ public abstract class PlayerListMixin implements PlayerListBridge { } // todo check these two - public ServerPlayerEntity moveToWorld(ServerPlayerEntity playerIn, ServerWorld worldIn, boolean flag, Location location, boolean avoidSuffocation) { + public ServerPlayer moveToWorld(ServerPlayer playerIn, ServerLevel worldIn, boolean flag, Location location, boolean avoidSuffocation) { playerIn.stopRiding(); this.removePlayer(playerIn); - playerIn.getServerWorld().removePlayer(playerIn, true); + playerIn.getLevel().removePlayer(playerIn, true); playerIn.revive(); - BlockPos pos = playerIn.func_241140_K_(); - float f = playerIn.func_242109_L(); - boolean flag2 = playerIn.func_241142_M_(); + BlockPos pos = playerIn.getRespawnPosition(); + float f = playerIn.getRespawnAngle(); + boolean flag2 = playerIn.isRespawnForced(); org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld(); - playerIn.queuedEndExit = false; + playerIn.wonGame = false; /* playerIn.copyFrom(playerIn, flag); playerIn.setEntityId(playerIn.getEntityId()); @@ -273,36 +272,36 @@ public abstract class PlayerListMixin implements PlayerListBridge { boolean flag3 = false; if (location == null) { boolean isBedSpawn = false; - ServerWorld spawnWorld = this.server.getWorld(playerIn.func_241141_L_()); + ServerLevel spawnWorld = this.server.getLevel(playerIn.getRespawnDimension()); if (spawnWorld != null) { - Optional optional; + Optional optional; if (pos != null) { - optional = PlayerEntity.func_242374_a(spawnWorld, pos, f, flag2, flag); + optional = net.minecraft.world.entity.player.Player.findRespawnPositionAndUseSpawnBlock(spawnWorld, pos, f, flag2, flag); } else { optional = Optional.empty(); } if (optional.isPresent()) { BlockState iblockdata = spawnWorld.getBlockState(pos); - boolean flag4 = iblockdata.isIn(Blocks.RESPAWN_ANCHOR); - Vector3d vec3d = optional.get(); + boolean flag4 = iblockdata.is(Blocks.RESPAWN_ANCHOR); + Vec3 vec3d = optional.get(); float f2; - if (!iblockdata.isIn(BlockTags.BEDS) && !flag4) { + if (!iblockdata.is(BlockTags.BEDS) && !flag4) { f2 = f; } else { - Vector3d vec3d2 = Vector3d.copyCenteredHorizontally(pos).subtract(vec3d).normalize(); - f2 = (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d2.z, vec3d2.x) * 57.2957763671875 - 90.0); + Vec3 vec3d2 = Vec3.atBottomCenterOf(pos).subtract(vec3d).normalize(); + f2 = (float) Mth.wrapDegrees(Mth.atan2(vec3d2.z, vec3d2.x) * 57.2957763671875 - 90.0); } // playerIn.setLocationAndAngles(vec3d.x, vec3d.y, vec3d.z, f2, 0.0f); - playerIn.func_242111_a(spawnWorld.getDimensionKey(), pos, f, flag2, false); + playerIn.setRespawnPosition(spawnWorld.dimension(), pos, f, flag2, false); flag3 = (!flag && flag4); isBedSpawn = true; location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), vec3d.x, vec3d.y, vec3d.z); } else if (pos != null) { - playerIn.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SPAWN_NOT_VALID, 0.0f)); + playerIn.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE, 0.0f)); } } if (location == null) { - spawnWorld = this.server.getWorld(World.OVERWORLD); + spawnWorld = this.server.getLevel(Level.OVERWORLD); pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(spawnWorld); location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f); } @@ -319,46 +318,46 @@ public abstract class PlayerListMixin implements PlayerListBridge { } else { location.setWorld(((WorldBridge) worldIn).bridge$getWorld()); } - ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle(); - playerIn.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - playerIn.connection.captureCurrentPosition(); - while (avoidSuffocation && !serverWorld.hasNoCollisions(playerIn) && playerIn.getPosY() < 256.0) { - playerIn.setPosition(playerIn.getPosX(), playerIn.getPosY() + 1.0, playerIn.getPosZ()); + ServerLevel serverWorld = ((CraftWorld) location.getWorld()).getHandle(); + playerIn.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + playerIn.connection.resetPosition(); + while (avoidSuffocation && !serverWorld.noCollision(playerIn) && playerIn.getY() < 256.0) { + playerIn.setPos(playerIn.getX(), playerIn.getY() + 1.0, playerIn.getZ()); } - IWorldInfo worlddata = serverWorld.getWorldInfo(); - playerIn.connection.sendPacket(new SRespawnPacket(serverWorld.getDimensionType(), serverWorld.getDimensionKey(), BiomeManager.getHashedSeed(serverWorld.getSeed()), playerIn.interactionManager.getGameType(), playerIn.interactionManager.func_241815_c_(), serverWorld.isDebug(), serverWorld.isFlatWorld(), flag)); - playerIn.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance)); - playerIn.setWorld(serverWorld); - ((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), playerIn.rotationYaw, playerIn.rotationPitch)); - playerIn.setSneaking(false); - playerIn.connection.sendPacket(new SWorldSpawnChangedPacket(serverWorld.getSpawnPoint(), serverWorld.getSpawnAngle())); - playerIn.connection.sendPacket(new SServerDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); - playerIn.connection.sendPacket(new SSetExperiencePacket(playerIn.experience, playerIn.experienceTotal, playerIn.experienceLevel)); - this.sendWorldInfo(playerIn, serverWorld); - this.updatePermissionLevel(playerIn); + LevelData worlddata = serverWorld.getLevelData(); + playerIn.connection.send(new ClientboundRespawnPacket(serverWorld.dimensionType(), serverWorld.dimension(), BiomeManager.obfuscateSeed(serverWorld.getSeed()), playerIn.gameMode.getGameModeForPlayer(), playerIn.gameMode.getPreviousGameModeForPlayer(), serverWorld.isDebug(), serverWorld.isFlat(), flag)); + playerIn.connection.send(new ClientboundSetChunkCacheRadiusPacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance)); + playerIn.setLevel(serverWorld); + ((ServerPlayNetHandlerBridge) playerIn.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), playerIn.getX(), playerIn.getY(), playerIn.getZ(), playerIn.yRot, playerIn.xRot)); + playerIn.setShiftKeyDown(false); + playerIn.connection.send(new ClientboundSetDefaultSpawnPositionPacket(serverWorld.getSharedSpawnPos(), serverWorld.getSharedSpawnAngle())); + playerIn.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); + playerIn.connection.send(new ClientboundSetExperiencePacket(playerIn.experienceProgress, playerIn.totalExperience, playerIn.experienceLevel)); + this.sendLevelInfo(playerIn, serverWorld); + this.sendPlayerPermissionLevel(playerIn); if (!((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) { serverWorld.addDuringCommandTeleport(playerIn); this.addPlayer(playerIn); - this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn); + this.playersByUUID.put(playerIn.getUUID(), playerIn); } playerIn.setHealth(playerIn.getHealth()); net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerChangedDimensionEvent(playerIn, ((CraftWorld) fromWorld).getHandle().dimension, serverWorld.dimension); if (flag3) { - playerIn.connection.sendPacket(new SPlaySoundEffectPacket(SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f)); + playerIn.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f)); } - this.sendInventory(playerIn); - playerIn.sendPlayerAbilities(); - for (Object o1 : playerIn.getActivePotionEffects()) { - EffectInstance mobEffect = (EffectInstance) o1; - playerIn.connection.sendPacket(new SPlayEntityEffectPacket(playerIn.getEntityId(), mobEffect)); + this.sendAllPlayerInfo(playerIn); + playerIn.onUpdateAbilities(); + for (Object o1 : playerIn.getActiveEffects()) { + MobEffectInstance mobEffect = (MobEffectInstance) o1; + playerIn.connection.send(new ClientboundUpdateMobEffectPacket(playerIn.getId(), mobEffect)); } - playerIn.func_213846_b(((CraftWorld) fromWorld).getHandle()); + playerIn.triggerDimensionChangeTriggers(((CraftWorld) fromWorld).getHandle()); if (fromWorld != location.getWorld()) { PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity(), fromWorld); Bukkit.getPluginManager().callEvent(event); } if (((ServerPlayNetHandlerBridge) playerIn.connection).bridge$isDisconnected()) { - this.writePlayerData(playerIn); + this.save(playerIn); } return playerIn; } @@ -371,54 +370,54 @@ public abstract class PlayerListMixin implements PlayerListBridge { * @reason */ @Overwrite - public ServerPlayerEntity func_232644_a_(ServerPlayerEntity playerIn, boolean conqueredEnd) { + public ServerPlayer respawn(ServerPlayer playerIn, boolean conqueredEnd) { Location location = arclight$loc; arclight$loc = null; boolean avoidSuffocation = arclight$suffo == null || arclight$suffo; arclight$suffo = null; playerIn.stopRiding(); this.removePlayer(playerIn); - playerIn.getServerWorld().removePlayer(playerIn, true); // Forge: keep data until copyFrom called - BlockPos pos = playerIn.func_241140_K_(); - float f = playerIn.func_242109_L(); - boolean flag2 = playerIn.func_241142_M_(); + playerIn.getLevel().removePlayer(playerIn, true); // Forge: keep data until copyFrom called + BlockPos pos = playerIn.getRespawnPosition(); + float f = playerIn.getRespawnAngle(); + boolean flag2 = playerIn.isRespawnForced(); org.bukkit.World fromWorld = ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().getWorld(); - playerIn.queuedEndExit = false; + playerIn.wonGame = false; boolean flag3 = false; - ServerWorld spawnWorld = this.server.getWorld(playerIn.func_241141_L_()); + ServerLevel spawnWorld = this.server.getLevel(playerIn.getRespawnDimension()); if (location == null) { boolean isBedSpawn = false; if (spawnWorld != null) { - Optional optional; + Optional optional; if (pos != null) { - optional = PlayerEntity.func_242374_a(spawnWorld, pos, f, flag2, conqueredEnd); + optional = net.minecraft.world.entity.player.Player.findRespawnPositionAndUseSpawnBlock(spawnWorld, pos, f, flag2, conqueredEnd); } else { optional = Optional.empty(); } if (optional.isPresent()) { BlockState iblockdata = spawnWorld.getBlockState(pos); - boolean flag4 = iblockdata.isIn(Blocks.RESPAWN_ANCHOR); - Vector3d vec3d = optional.get(); + boolean flag4 = iblockdata.is(Blocks.RESPAWN_ANCHOR); + Vec3 vec3d = optional.get(); float f2; - if (!iblockdata.isIn(BlockTags.BEDS) && !flag4) { + if (!iblockdata.is(BlockTags.BEDS) && !flag4) { f2 = f; } else { - Vector3d vec3d2 = Vector3d.copyCenteredHorizontally(pos).subtract(vec3d).normalize(); - f2 = (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d2.z, vec3d2.x) * 57.2957763671875 - 90.0); + Vec3 vec3d2 = Vec3.atBottomCenterOf(pos).subtract(vec3d).normalize(); + f2 = (float) Mth.wrapDegrees(Mth.atan2(vec3d2.z, vec3d2.x) * 57.2957763671875 - 90.0); } // playerIn.setLocationAndAngles(vec3d.x, vec3d.y, vec3d.z, f2, 0.0f); - playerIn.func_242111_a(spawnWorld.getDimensionKey(), pos, f, flag2, false); + playerIn.setRespawnPosition(spawnWorld.dimension(), pos, f, flag2, false); flag3 = (!flag2 && flag4); isBedSpawn = true; location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), vec3d.x, vec3d.y, vec3d.z); } else if (pos != null) { - playerIn.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SPAWN_NOT_VALID, 0.0f)); + playerIn.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE, 0.0f)); } } if (location == null) { - spawnWorld = this.server.getWorld(World.OVERWORLD); + spawnWorld = this.server.getLevel(Level.OVERWORLD); pos = ((ServerPlayerEntityBridge) playerIn).bridge$getSpawnPoint(spawnWorld); location = new Location(((WorldBridge) spawnWorld).bridge$getWorld(), pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f); } @@ -436,146 +435,146 @@ public abstract class PlayerListMixin implements PlayerListBridge { location.setWorld(((WorldBridge) spawnWorld).bridge$getWorld()); } - ServerWorld serverWorld = ((CraftWorld) location.getWorld()).getHandle(); - PlayerInteractionManager playerinteractionmanager; + ServerLevel serverWorld = ((CraftWorld) location.getWorld()).getHandle(); + ServerPlayerGameMode playerinteractionmanager; if (this.server.isDemo()) { - playerinteractionmanager = new DemoPlayerInteractionManager(serverWorld); + playerinteractionmanager = new DemoMode(serverWorld); } else { - playerinteractionmanager = new PlayerInteractionManager(serverWorld); + playerinteractionmanager = new ServerPlayerGameMode(serverWorld); } - ServerPlayerEntity serverplayerentity = new ServerPlayerEntity(this.server, serverWorld, playerIn.getGameProfile(), playerinteractionmanager); + ServerPlayer serverplayerentity = new ServerPlayer(this.server, serverWorld, playerIn.getGameProfile(), playerinteractionmanager); // Forward to new player instance ((InternalEntityBridge) playerIn).internal$getBukkitEntity().setHandle(serverplayerentity); ((EntityBridge) serverplayerentity).bridge$setBukkitEntity(((InternalEntityBridge) playerIn).internal$getBukkitEntity()); - if ((Object) playerIn instanceof MobEntity) { - ((MobEntity) (Object) playerIn).clearLeashed(true, false); + if ((Object) playerIn instanceof Mob) { + ((Mob) (Object) playerIn).dropLeash(true, false); } serverplayerentity.connection = playerIn.connection; - serverplayerentity.copyFrom(playerIn, conqueredEnd); + serverplayerentity.restoreFrom(playerIn, conqueredEnd); if (!conqueredEnd) { // keep inventory here since inventory dropped at ServerPlayerEntity#onDeath - serverplayerentity.inventory.copyInventory(playerIn.inventory); + serverplayerentity.inventory.replaceWith(playerIn.inventory); } playerIn.remove(false); // Forge: clone event had a chance to see old data, now discard it - serverplayerentity.setEntityId(playerIn.getEntityId()); - serverplayerentity.setPrimaryHand(playerIn.getPrimaryHand()); + serverplayerentity.setId(playerIn.getId()); + serverplayerentity.setMainArm(playerIn.getMainArm()); for (String s : playerIn.getTags()) { serverplayerentity.addTag(s); } - serverplayerentity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - serverplayerentity.connection.captureCurrentPosition(); + serverplayerentity.absMoveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + serverplayerentity.connection.resetPosition(); - this.setPlayerGameTypeBasedOnOther(serverplayerentity, playerIn, serverWorld); - while (avoidSuffocation && !serverWorld.hasNoCollisions(serverplayerentity) && serverplayerentity.getPosY() < 256.0D) { - serverplayerentity.setPosition(serverplayerentity.getPosX(), serverplayerentity.getPosY() + 1.0D, serverplayerentity.getPosZ()); + this.updatePlayerGameMode(serverplayerentity, playerIn, serverWorld); + while (avoidSuffocation && !serverWorld.noCollision(serverplayerentity) && serverplayerentity.getY() < 256.0D) { + serverplayerentity.setPos(serverplayerentity.getX(), serverplayerentity.getY() + 1.0D, serverplayerentity.getZ()); } - IWorldInfo iworldinfo = serverplayerentity.world.getWorldInfo(); - serverplayerentity.connection.sendPacket(new SRespawnPacket(serverplayerentity.world.getDimensionType(), serverplayerentity.world.getDimensionKey(), BiomeManager.getHashedSeed(serverplayerentity.getServerWorld().getSeed()), serverplayerentity.interactionManager.getGameType(), serverplayerentity.interactionManager.func_241815_c_(), serverplayerentity.getServerWorld().isDebug(), serverplayerentity.getServerWorld().isFlatWorld(), conqueredEnd)); - serverplayerentity.connection.sendPacket(new SUpdateViewDistancePacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance)); - serverplayerentity.setWorld(serverWorld); - ((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), serverplayerentity.getPosX(), serverplayerentity.getPosY(), serverplayerentity.getPosZ(), serverplayerentity.rotationYaw, serverplayerentity.rotationPitch)); - serverplayerentity.setSneaking(false); - serverplayerentity.connection.sendPacket(new SWorldSpawnChangedPacket(serverWorld.getSpawnPoint(), serverWorld.getSpawnAngle())); - serverplayerentity.connection.sendPacket(new SServerDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); - serverplayerentity.connection.sendPacket(new SSetExperiencePacket(serverplayerentity.experience, serverplayerentity.experienceTotal, serverplayerentity.experienceLevel)); - this.sendWorldInfo(serverplayerentity, serverWorld); - this.updatePermissionLevel(serverplayerentity); + LevelData iworldinfo = serverplayerentity.level.getLevelData(); + serverplayerentity.connection.send(new ClientboundRespawnPacket(serverplayerentity.level.dimensionType(), serverplayerentity.level.dimension(), BiomeManager.obfuscateSeed(serverplayerentity.getLevel().getSeed()), serverplayerentity.gameMode.getGameModeForPlayer(), serverplayerentity.gameMode.getPreviousGameModeForPlayer(), serverplayerentity.getLevel().isDebug(), serverplayerentity.getLevel().isFlat(), conqueredEnd)); + serverplayerentity.connection.send(new ClientboundSetChunkCacheRadiusPacket(((WorldBridge) serverWorld).bridge$spigotConfig().viewDistance)); + serverplayerentity.setLevel(serverWorld); + ((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$teleport(new Location(((WorldBridge) serverWorld).bridge$getWorld(), serverplayerentity.getX(), serverplayerentity.getY(), serverplayerentity.getZ(), serverplayerentity.yRot, serverplayerentity.xRot)); + serverplayerentity.setShiftKeyDown(false); + serverplayerentity.connection.send(new ClientboundSetDefaultSpawnPositionPacket(serverWorld.getSharedSpawnPos(), serverWorld.getSharedSpawnAngle())); + serverplayerentity.connection.send(new ClientboundChangeDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); + serverplayerentity.connection.send(new ClientboundSetExperiencePacket(serverplayerentity.experienceProgress, serverplayerentity.totalExperience, serverplayerentity.experienceLevel)); + this.sendLevelInfo(serverplayerentity, serverWorld); + this.sendPlayerPermissionLevel(serverplayerentity); if (!((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) { serverWorld.addRespawnedPlayer(serverplayerentity); this.addPlayer(serverplayerentity); - this.uuidToPlayerMap.put(serverplayerentity.getUniqueID(), serverplayerentity); + this.playersByUUID.put(serverplayerentity.getUUID(), serverplayerentity); } - serverplayerentity.addSelfToInternalCraftingInventory(); + serverplayerentity.initMenu(); serverplayerentity.setHealth(serverplayerentity.getHealth()); net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerRespawnEvent(serverplayerentity, conqueredEnd); if (flag2) { - serverplayerentity.connection.sendPacket(new SPlaySoundEffectPacket(SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 1.0F, 1.0F)); + serverplayerentity.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 1.0F, 1.0F)); } - this.sendInventory(serverplayerentity); - serverplayerentity.sendPlayerAbilities(); - for (Object o1 : serverplayerentity.getActivePotionEffects()) { - EffectInstance mobEffect = (EffectInstance) o1; - serverplayerentity.connection.sendPacket(new SPlayEntityEffectPacket(serverplayerentity.getEntityId(), mobEffect)); + this.sendAllPlayerInfo(serverplayerentity); + serverplayerentity.onUpdateAbilities(); + for (Object o1 : serverplayerentity.getActiveEffects()) { + MobEffectInstance mobEffect = (MobEffectInstance) o1; + serverplayerentity.connection.send(new ClientboundUpdateMobEffectPacket(serverplayerentity.getId(), mobEffect)); } - serverplayerentity.func_213846_b(((CraftWorld) fromWorld).getHandle()); + serverplayerentity.triggerDimensionChangeTriggers(((CraftWorld) fromWorld).getHandle()); if (fromWorld != location.getWorld()) { PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(((ServerPlayerEntityBridge) serverplayerentity).bridge$getBukkitEntity(), fromWorld); Bukkit.getPluginManager().callEvent(event); } if (((ServerPlayNetHandlerBridge) serverplayerentity.connection).bridge$isDisconnected()) { - this.writePlayerData(serverplayerentity); + this.save(serverplayerentity); } return serverplayerentity; } - public void sendAll(IPacket packet, PlayerEntity entityhuman) { - for (ServerPlayerEntity entityplayer : this.players) { - if (!(entityhuman instanceof ServerPlayerEntity) || ((ServerPlayerEntityBridge) entityplayer).bridge$getBukkitEntity().canSee(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity())) { - entityplayer.connection.sendPacket(packet); + public void sendAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) { + for (ServerPlayer entityplayer : this.players) { + if (!(entityhuman instanceof ServerPlayer) || ((ServerPlayerEntityBridge) entityplayer).bridge$getBukkitEntity().canSee(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity())) { + entityplayer.connection.send(packet); } } } - public void sendAll(IPacket packet, World world) { - for (int i = 0; i < world.getPlayers().size(); ++i) { - ((ServerPlayerEntity) world.getPlayers().get(i)).connection.sendPacket(packet); + public void sendAll(Packet packet, Level world) { + for (int i = 0; i < world.players().size(); ++i) { + ((ServerPlayer) world.players().get(i)).connection.send(packet); } } - @Inject(method = "sendPlayerPermissionLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getCommandManager()Lnet/minecraft/command/Commands;")) - private void arclight$calculatePerms(ServerPlayerEntity player, int permLevel, CallbackInfo ci) { + @Inject(method = "sendPlayerPermissionLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getCommands()Lnet/minecraft/commands/Commands;")) + private void arclight$calculatePerms(ServerPlayer player, int permLevel, CallbackInfo ci) { ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().recalculatePermissions(); } - @Redirect(method = "sendInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/ServerPlayerEntity;setPlayerHealthUpdated()V")) - private void arclight$useScaledHealth(ServerPlayerEntity playerEntity) { + @Redirect(method = "sendAllPlayerInfo", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetSentInfo()V")) + private void arclight$useScaledHealth(ServerPlayer playerEntity) { ((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity().updateScaledHealth(); - int i = playerEntity.world.getGameRules().getBoolean(GameRules.REDUCED_DEBUG_INFO) ? 22 : 23; - playerEntity.connection.sendPacket(new SEntityStatusPacket(playerEntity, (byte) i)); + int i = playerEntity.level.getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23; + playerEntity.connection.send(new ClientboundEntityEventPacket(playerEntity, (byte) i)); if (ArclightVersion.atLeast(ArclightVersion.v1_15)) { - float immediateRespawn = playerEntity.world.getGameRules().getBoolean(GameRules.DO_IMMEDIATE_RESPAWN) ? 1.0f : 0.0f; - playerEntity.connection.sendPacket(new SChangeGameStatePacket(SChangeGameStatePacket.SHOW_DEATH_SCREEN, immediateRespawn)); + float immediateRespawn = playerEntity.level.getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0f : 0.0f; + playerEntity.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.IMMEDIATE_RESPAWN, immediateRespawn)); } } - public void sendMessage(ITextComponent[] components) { - for (ITextComponent component : components) { - this.func_232641_a_(component, ChatType.SYSTEM, Util.DUMMY_UUID); + public void sendMessage(Component[] components) { + for (Component component : components) { + this.broadcastMessage(component, ChatType.SYSTEM, Util.NIL_UUID); } } @Override - public void bridge$sendMessage(ITextComponent[] components) { + public void bridge$sendMessage(Component[] components) { this.sendMessage(components); } - @Redirect(method = "func_232641_a_", at = @At(value = "NEW", target = "net/minecraft/network/play/server/SChatPacket")) - private SChatPacket arclight$addWebLinks(ITextComponent message, ChatType type, UUID uuid) { - return new SChatPacket(CraftChatMessage.fixComponent(message), type, uuid); + @Redirect(method = "broadcastMessage", at = @At(value = "NEW", target = "net/minecraft/network/protocol/game/ClientboundChatPacket")) + private ClientboundChatPacket arclight$addWebLinks(Component message, ChatType type, UUID uuid) { + return new ClientboundChatPacket(CraftChatMessage.fixComponent(message), type, uuid); } - public ServerStatisticsManager getStatisticManager(ServerPlayerEntity entityhuman) { - ServerStatisticsManager serverstatisticmanager = entityhuman.getStats(); - return serverstatisticmanager == null ? this.getStatisticManager(entityhuman.getUniqueID(), entityhuman.getName().getString()) : serverstatisticmanager; + public ServerStatsCounter getStatisticManager(ServerPlayer entityhuman) { + ServerStatsCounter serverstatisticmanager = entityhuman.getStats(); + return serverstatisticmanager == null ? this.getStatisticManager(entityhuman.getUUID(), entityhuman.getName().getString()) : serverstatisticmanager; } - public ServerStatisticsManager getStatisticManager(UUID uuid, String displayName) { - ServerStatisticsManager serverstatisticmanager; - ServerPlayerEntity entityhuman = this.getPlayerByUUID(uuid); - ServerStatisticsManager serverStatisticsManager = serverstatisticmanager = entityhuman == null ? null : entityhuman.getStats(); + public ServerStatsCounter getStatisticManager(UUID uuid, String displayName) { + ServerStatsCounter serverstatisticmanager; + ServerPlayer entityhuman = this.getPlayer(uuid); + ServerStatsCounter serverStatisticsManager = serverstatisticmanager = entityhuman == null ? null : entityhuman.getStats(); if (serverstatisticmanager == null) { File file2; - File file = this.server.func_240776_a_(FolderName.STATS).toFile(); + File file = this.server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile(); File file1 = new File(file, uuid + ".json"); if (!file1.exists() && (file2 = new File(file, String.valueOf(displayName) + ".json")).exists() && file2.isFile()) { file2.renameTo(file1); } - serverstatisticmanager = new ServerStatisticsManager(this.server, file1); + serverstatisticmanager = new ServerStatsCounter(this.server, file1); } return serverstatisticmanager; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/UserListMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/UserListMixin.java index d0dd99d5..48635301 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/UserListMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/UserListMixin.java @@ -1,7 +1,5 @@ package io.izzel.arclight.common.mixin.core.server.management; -import net.minecraft.server.management.UserList; -import net.minecraft.server.management.UserListEntry; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,16 +7,18 @@ import io.izzel.arclight.common.bridge.server.management.UserListBridge; import java.util.Collection; import java.util.Map; +import net.minecraft.server.players.StoredUserEntry; +import net.minecraft.server.players.StoredUserList; -@Mixin(UserList.class) -public class UserListMixin> implements UserListBridge { +@Mixin(StoredUserList.class) +public class UserListMixin> implements UserListBridge { // @formatter:off - @Shadow @Final private Map values; + @Shadow @Final private Map map; // @formatter:on public Collection getValues() { - return this.values.values(); + return this.map.values(); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/state/IntegerPropertyMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/state/IntegerPropertyMixin.java index 7455f3f0..0d2d619e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/state/IntegerPropertyMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/state/IntegerPropertyMixin.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mixin.core.state; -import net.minecraft.state.IntegerProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/stats/StatisticsManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/stats/StatisticsManagerMixin.java index 63a8190e..89fa8f16 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/stats/StatisticsManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/stats/StatisticsManagerMixin.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mixin.core.stats; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.stats.Stat; -import net.minecraft.stats.StatisticsManager; +import net.minecraft.stats.StatsCounter; +import net.minecraft.world.entity.player.Player; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.Cancellable; import org.spongepowered.asm.mixin.Mixin; @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(StatisticsManager.class) +@Mixin(StatsCounter.class) public abstract class StatisticsManagerMixin { // @formatter:off @@ -20,8 +20,8 @@ public abstract class StatisticsManagerMixin { // @formatter:on @Inject(method = "increment", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/stats/StatisticsManager;setValue(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/stats/Stat;I)V")) - public void arclight$statsIncl(PlayerEntity player, Stat stat, int amount, CallbackInfo ci, int i) { + at = @At(value = "INVOKE", target = "Lnet/minecraft/stats/StatsCounter;setValue(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/stats/Stat;I)V")) + public void arclight$statsIncl(Player player, Stat stat, int amount, CallbackInfo ci, int i) { Cancellable cancellable = CraftEventFactory.handleStatisticsIncrease(player, stat, this.getValue(stat), i); if (cancellable != null && cancellable.isCancelled()) { ci.cancel(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/AbstractFurnaceTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/AbstractFurnaceTileEntityMixin.java index 5c819998..4dafcfed 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/AbstractFurnaceTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/AbstractFurnaceTileEntityMixin.java @@ -3,19 +3,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.tileentity.AbstractFurnaceTileEntityBridge; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.minecraft.block.Blocks; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.tileentity.AbstractFurnaceTileEntity; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.World; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -36,21 +23,34 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; +import net.minecraft.core.NonNullList; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.WorldlyContainer; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; +import net.minecraft.world.phys.Vec3; import java.util.ArrayList; import java.util.List; -@Mixin(AbstractFurnaceTileEntity.class) +@Mixin(AbstractFurnaceBlockEntity.class) public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityMixin implements AbstractFurnaceTileEntityBridge { // @formatter:off @Shadow protected NonNullList items; - @Shadow protected abstract int getBurnTime(ItemStack stack); - @Shadow public int burnTime; - @Shadow protected abstract boolean isBurning(); - @Shadow protected abstract boolean canSmelt(@Nullable IRecipe recipeIn); - @Shadow public abstract void setRecipeUsed(@Nullable IRecipe recipe); - @Shadow public abstract List> grantStoredRecipeExperience(World world, Vector3d pos); - @Shadow @Final private Object2IntOpenHashMap recipes; + @Shadow protected abstract int getBurnDuration(ItemStack stack); + @Shadow public int litTime; + @Shadow protected abstract boolean isLit(); + @Shadow protected abstract boolean canBurn(@Nullable Recipe recipeIn); + @Shadow public abstract void setRecipeUsed(@Nullable Recipe recipe); + @Shadow public abstract List> getRecipesToAwardAndPopExperience(Level world, Vec3 pos); + @Shadow @Final private Object2IntOpenHashMap recipesUsed; // @formatter:on public List transaction = new ArrayList<>(); @@ -58,12 +58,12 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM private transient FurnaceBurnEvent arclight$burnEvent; - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/AbstractFurnaceTileEntity;getBurnTime(Lnet/minecraft/item/ItemStack;)I")) + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;getBurnDuration(Lnet/minecraft/world/item/ItemStack;)I")) public void arclight$furnaceBurn(CallbackInfo ci) { ItemStack itemStack = this.items.get(1); CraftItemStack fuel = CraftItemStack.asCraftMirror(itemStack); - arclight$burnEvent = new FurnaceBurnEvent(CraftBlock.at(this.world, this.pos), fuel, getBurnTime(itemStack)); + arclight$burnEvent = new FurnaceBurnEvent(CraftBlock.at(this.level, this.worldPosition), fuel, getBurnDuration(itemStack)); Bukkit.getPluginManager().callEvent(arclight$burnEvent); if (arclight$burnEvent.isCancelled()) { @@ -72,11 +72,11 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM } } - @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 4, target = "Lnet/minecraft/tileentity/AbstractFurnaceTileEntity;isBurning()Z")) - public boolean arclight$setBurnTime(AbstractFurnaceTileEntity furnace) { - this.burnTime = arclight$burnEvent.getBurnTime(); + @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 4, target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;isLit()Z")) + public boolean arclight$setBurnTime(AbstractFurnaceBlockEntity furnace) { + this.litTime = arclight$burnEvent.getBurnTime(); try { - return this.isBurning() && arclight$burnEvent.isBurning(); + return this.isLit() && arclight$burnEvent.isBurning(); } finally { arclight$burnEvent = null; } @@ -88,16 +88,16 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM */ @Overwrite @SuppressWarnings("unchecked") - private void smelt(@Nullable IRecipe recipe) { - if (recipe != null && this.canSmelt(recipe)) { + private void burn(@Nullable Recipe recipe) { + if (recipe != null && this.canBurn(recipe)) { ItemStack itemstack = this.items.get(0); - ItemStack itemstack1 = ((IRecipe) recipe).getCraftingResult((AbstractFurnaceTileEntity)(Object)this); + ItemStack itemstack1 = ((Recipe) recipe).assemble((AbstractFurnaceBlockEntity)(Object)this); ItemStack itemstack2 = this.items.get(2); CraftItemStack source = CraftItemStack.asCraftMirror(itemstack); org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1); - FurnaceSmeltEvent event = new FurnaceSmeltEvent(CraftBlock.at(world, pos), source, result); + FurnaceSmeltEvent event = new FurnaceSmeltEvent(CraftBlock.at(level, worldPosition), source, result); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -117,7 +117,7 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM } } - if (!this.world.isRemote) { + if (!this.level.isClientSide) { this.setRecipeUsed(recipe); } @@ -129,20 +129,20 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM } } - private static AbstractFurnaceTileEntity arclight$captureFurnace; - private static PlayerEntity arclight$capturePlayer; + private static AbstractFurnaceBlockEntity arclight$captureFurnace; + private static Player arclight$capturePlayer; private static ItemStack arclight$item; private static int arclight$captureAmount; - public List> a(World world, Vector3d pos, PlayerEntity entity, ItemStack itemStack, int amount) { + public List> a(Level world, Vec3 pos, Player entity, ItemStack itemStack, int amount) { try { arclight$item = itemStack; arclight$captureAmount = amount; - arclight$captureFurnace = (AbstractFurnaceTileEntity) (Object) this; + arclight$captureFurnace = (AbstractFurnaceBlockEntity) (Object) this; arclight$capturePlayer = entity; - List> list = this.grantStoredRecipeExperience(world, pos); - entity.unlockRecipes(list); - this.recipes.clear(); + List> list = this.getRecipesToAwardAndPopExperience(world, pos); + entity.awardRecipes(list); + this.recipesUsed.clear(); return list; } finally { arclight$item = null; @@ -153,7 +153,7 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM } @Override - public List> bridge$dropExp(World world, Vector3d pos, PlayerEntity entity, ItemStack itemStack, int amount) { + public List> bridge$dropExp(Level world, Vec3 pos, Player entity, ItemStack itemStack, int amount) { return a(world, pos, entity, itemStack, amount); } @@ -162,24 +162,24 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM * @reason */ @Overwrite - private static void splitAndSpawnExperience(World world, Vector3d pos, int craftedAmount, float experience) { - int i = MathHelper.floor((float) craftedAmount * experience); - float f = MathHelper.frac((float) craftedAmount * experience); + private static void createExperience(Level world, Vec3 pos, int craftedAmount, float experience) { + int i = Mth.floor((float) craftedAmount * experience); + float f = Mth.frac((float) craftedAmount * experience); if (f != 0.0F && Math.random() < (double) f) { ++i; } if (arclight$capturePlayer != null && arclight$captureAmount != 0) { FurnaceExtractEvent event = new FurnaceExtractEvent(((ServerPlayerEntityBridge) arclight$capturePlayer).bridge$getBukkitEntity(), - CraftBlock.at(world, arclight$captureFurnace.getPos()), CraftMagicNumbers.getMaterial(arclight$item.getItem()), arclight$captureAmount, i); + CraftBlock.at(world, arclight$captureFurnace.getBlockPos()), CraftMagicNumbers.getMaterial(arclight$item.getItem()), arclight$captureAmount, i); Bukkit.getPluginManager().callEvent(event); i = event.getExpToDrop(); } while (i > 0) { - int j = ExperienceOrbEntity.getXPSplit(i); + int j = ExperienceOrb.getExperienceValue(i); i -= j; - world.addEntity(new ExperienceOrbEntity(world, pos.x, pos.y, pos.z, j)); + world.addFreshEntity(new ExperienceOrb(world, pos.x, pos.y, pos.z, j)); } } @@ -208,7 +208,7 @@ public abstract class AbstractFurnaceTileEntityMixin extends LockableTileEntityM } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BarrelTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BarrelTileEntityMixin.java index 4c65c684..0130e466 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BarrelTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BarrelTileEntityMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.BarrelTileEntity; -import net.minecraft.util.NonNullList; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; @@ -13,12 +9,16 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BarrelBlockEntity; -@Mixin(BarrelTileEntity.class) -public abstract class BarrelTileEntityMixin extends LockableTileEntityMixin implements IInventoryBridge, IInventory { +@Mixin(BarrelBlockEntity.class) +public abstract class BarrelTileEntityMixin extends LockableTileEntityMixin implements IInventoryBridge, Container { // @formatter:off - @Shadow private NonNullList barrelContents; + @Shadow private NonNullList items; // @formatter:on public List transaction = new ArrayList<>(); @@ -26,7 +26,7 @@ public abstract class BarrelTileEntityMixin extends LockableTileEntityMixin impl @Override public List getContents() { - return this.barrelContents; + return this.items; } @Override @@ -45,7 +45,7 @@ public abstract class BarrelTileEntityMixin extends LockableTileEntityMixin impl } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeaconTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeaconTileEntityMixin.java index b190f874..660928b8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeaconTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeaconTileEntityMixin.java @@ -1,10 +1,5 @@ package io.izzel.arclight.common.mixin.core.tileentity; -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.potion.Effect; -import net.minecraft.potion.EffectInstance; -import net.minecraft.tileentity.BeaconTileEntity; import org.bukkit.craftbukkit.v.potion.CraftPotionUtil; import org.bukkit.potion.PotionEffect; import org.spongepowered.asm.mixin.Mixin; @@ -15,32 +10,37 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import io.izzel.arclight.common.bridge.tileentity.BeaconTileEntityBridge; import javax.annotation.Nullable; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.level.block.entity.BeaconBlockEntity; +import net.minecraft.world.level.block.state.BlockState; -@Mixin(BeaconTileEntity.class) +@Mixin(BeaconBlockEntity.class) public abstract class BeaconTileEntityMixin implements BeaconTileEntityBridge { // @formatter:off - @Shadow @Nullable public Effect primaryEffect; + @Shadow @Nullable public MobEffect primaryPower; @Shadow public int levels; - @Shadow @Nullable public Effect secondaryEffect; + @Shadow @Nullable public MobEffect secondaryPower; // @formatter:on - @Inject(method = "read", at = @At("RETURN")) - public void arclight$level(BlockState state, CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "load", at = @At("RETURN")) + public void arclight$level(BlockState state, CompoundTag compound, CallbackInfo ci) { this.levels = compound.getInt("Levels"); } public PotionEffect getPrimaryEffect() { - return (this.primaryEffect != null) ? CraftPotionUtil.toBukkit(new EffectInstance(this.primaryEffect, this.getLevel(), this.getAmplification(), true, true)) : null; + return (this.primaryPower != null) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.primaryPower, this.getLevel(), this.getAmplification(), true, true)) : null; } public PotionEffect getSecondaryEffect() { - return (this.hasSecondaryEffect()) ? CraftPotionUtil.toBukkit(new EffectInstance(this.secondaryEffect, getLevel(), getAmplification(), true, true)) : null; + return (this.hasSecondaryEffect()) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.secondaryPower, getLevel(), getAmplification(), true, true)) : null; } private byte getAmplification() { byte b0 = 0; - if (this.levels >= 4 && this.primaryEffect == this.secondaryEffect) { + if (this.levels >= 4 && this.primaryPower == this.secondaryPower) { b0 = 1; } return b0; @@ -52,7 +52,7 @@ public abstract class BeaconTileEntityMixin implements BeaconTileEntityBridge { } private boolean hasSecondaryEffect() { - if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect != null) { + if (this.levels >= 4 && this.primaryPower != this.secondaryPower && this.secondaryPower != null) { return true; } return false; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeehiveTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeehiveTileEntityMixin.java index 29a774d9..c500299f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeehiveTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BeehiveTileEntityMixin.java @@ -4,15 +4,15 @@ import com.google.common.collect.Lists; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.BeeEntity; -import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.CompoundTag; import net.minecraft.tags.EntityTypeTags; -import net.minecraft.tileentity.BeehiveTileEntity; -import net.minecraft.world.World; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Bee; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BeehiveBlockEntity; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -31,12 +31,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.annotation.Nullable; import java.util.List; -@Mixin(BeehiveTileEntity.class) +@Mixin(BeehiveBlockEntity.class) public abstract class BeehiveTileEntityMixin extends TileEntityMixin { // @formatter:off - @Shadow @Final private List bees; - @Shadow protected abstract boolean func_235651_a_(BlockState p_235651_1_, BeehiveTileEntity.Bee p_235651_2_, @org.jetbrains.annotations.Nullable List p_235651_3_, BeehiveTileEntity.State p_235651_4_); + @Shadow @Final private List stored; + @Shadow protected abstract boolean releaseOccupant(BlockState p_235651_1_, BeehiveBlockEntity.BeeData p_235651_2_, @org.jetbrains.annotations.Nullable List p_235651_3_, BeehiveBlockEntity.BeeReleaseStatus p_235651_4_); // @formatter:on public int maxBees = 3; @@ -46,40 +46,40 @@ public abstract class BeehiveTileEntityMixin extends TileEntityMixin { * @reason */ @Overwrite - public boolean isFullOfBees() { - return this.bees.size() >= maxBees; + public boolean isFull() { + return this.stored.size() >= maxBees; } - @Redirect(method = "angerBees", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/BeeEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$angryReason(BeeEntity beeEntity, LivingEntity livingEntity) { + @Redirect(method = "emptyAllLivingFromHive", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Bee;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$angryReason(Bee beeEntity, LivingEntity livingEntity) { ((MobEntityBridge) beeEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); - beeEntity.setAttackTarget(livingEntity); + beeEntity.setTarget(livingEntity); } - public List tryReleaseBee(BlockState blockState, BeehiveTileEntity.State state, boolean force) { + public List tryReleaseBee(BlockState blockState, BeehiveBlockEntity.BeeReleaseStatus state, boolean force) { List list = Lists.newArrayList(); - this.bees.removeIf(bee -> this.releaseBee(blockState, bee, list, state, force)); + this.stored.removeIf(bee -> this.releaseBee(blockState, bee, list, state, force)); return list; } - @Inject(method = "tryEnterHive(Lnet/minecraft/entity/Entity;ZI)V", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;stopRiding()V")) + @Inject(method = "addOccupantWithPresetTicks(Lnet/minecraft/world/entity/Entity;ZI)V", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;stopRiding()V")) private void arclight$beeEnterBlock(Entity entity, boolean p_226962_2_, int p_226962_3_, CallbackInfo ci) { - if (this.world != null) { - EntityEnterBlockEvent event = new EntityEnterBlockEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(this.world, this.getPos())); + if (this.level != null) { + EntityEnterBlockEvent event = new EntityEnterBlockEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(this.level, this.getPos())); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - if (entity instanceof BeeEntity) { - ((BeeEntity) entity).setStayOutOfHiveCountdown(400); + if (entity instanceof Bee) { + ((Bee) entity).setStayOutOfHiveCountdown(400); } ci.cancel(); } } } - private boolean releaseBee(BlockState blockState, BeehiveTileEntity.Bee bee, @Nullable List list, BeehiveTileEntity.State state, boolean force) { + private boolean releaseBee(BlockState blockState, BeehiveBlockEntity.BeeData bee, @Nullable List list, BeehiveBlockEntity.BeeReleaseStatus state, boolean force) { arclight$force = force; try { - return this.func_235651_a_(blockState, bee, list, state); + return this.releaseOccupant(blockState, bee, list, state); } finally { arclight$force = false; } @@ -87,17 +87,17 @@ public abstract class BeehiveTileEntityMixin extends TileEntityMixin { private transient boolean arclight$force; - @Redirect(method = "func_235651_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isNightTime()Z")) - private boolean arclight$bypassNightCheck(World world) { - return !arclight$force && world.isNightTime(); + @Redirect(method = "releaseOccupant", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;isNight()Z")) + private boolean arclight$bypassNightCheck(Level world) { + return !arclight$force && world.isNight(); } - @Redirect(method = "func_235651_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getType()Lnet/minecraft/entity/EntityType;")) + @Redirect(method = "releaseOccupant", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getType()Lnet/minecraft/world/entity/EntityType;")) private EntityType arclight$spawnFirst(Entity entity) { EntityType type = entity.getType(); - if (type.isContained(EntityTypeTags.BEEHIVE_INHABITORS)) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BEEHIVE); - if (!this.world.addEntity(entity)) { + if (type.is(EntityTypeTags.BEEHIVE_INHABITORS)) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BEEHIVE); + if (!this.level.addFreshEntity(entity)) { return EntityType.ITEM_FRAME; } else { return type; @@ -106,20 +106,20 @@ public abstract class BeehiveTileEntityMixin extends TileEntityMixin { return type; } - @Redirect(method = "func_235651_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$addedBefore(World world, Entity entityIn) { + @Redirect(method = "releaseOccupant", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$addedBefore(Level world, Entity entityIn) { return true; } - @Inject(method = "read", at = @At("RETURN")) - private void arclight$readMax(BlockState state, CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "load", at = @At("RETURN")) + private void arclight$readMax(BlockState state, CompoundTag compound, CallbackInfo ci) { if (compound.contains("Bukkit.MaxEntities")) { this.maxBees = compound.getInt("Bukkit.MaxEntities"); } } - @Inject(method = "write", at = @At("RETURN")) - private void arclight$writeMax(CompoundNBT compound, CallbackInfoReturnable cir) { + @Inject(method = "save", at = @At("RETURN")) + private void arclight$writeMax(CompoundTag compound, CallbackInfoReturnable cir) { compound.putInt("Bukkit.MaxEntities", this.maxBees); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BrewingStandTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BrewingStandTileEntityMixin.java index faf7a0df..d4a25a19 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BrewingStandTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/BrewingStandTileEntityMixin.java @@ -1,8 +1,5 @@ package io.izzel.arclight.common.mixin.core.tileentity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.BrewingStandTileEntity; -import net.minecraft.util.NonNullList; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -22,12 +19,15 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BrewingStandBlockEntity; -@Mixin(BrewingStandTileEntity.class) +@Mixin(BrewingStandBlockEntity.class) public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixin { // @formatter:off - @Shadow private NonNullList brewingItemStacks; + @Shadow private NonNullList items; @Shadow public int fuel; // @formatter:on @@ -38,9 +38,9 @@ public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixi private transient boolean arclight$consume; @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/tileentity/BrewingStandTileEntity;fuel:I")) + at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/level/block/entity/BrewingStandBlockEntity;fuel:I")) public void arclight$brewFuel(CallbackInfo ci, ItemStack itemStack) { - BrewingStandFuelEvent event = new BrewingStandFuelEvent(CraftBlock.at(this.world, this.pos), CraftItemStack.asCraftMirror(itemStack), 20); + BrewingStandFuelEvent event = new BrewingStandFuelEvent(CraftBlock.at(this.level, this.worldPosition), CraftItemStack.asCraftMirror(itemStack), 20); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -52,7 +52,7 @@ public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixi } } - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;shrink(I)V")) + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V")) public void arclight$brewFuel(ItemStack itemStack, int count) { if (arclight$fuel != null) { this.fuel = arclight$fuel; @@ -64,11 +64,11 @@ public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixi arclight$consume = false; } - @Inject(method = "brewPotions", cancellable = true, at = @At("HEAD")) + @Inject(method = "doBrew", cancellable = true, at = @At("HEAD")) public void arclight$brewPotion(CallbackInfo ci) { InventoryHolder owner = this.getOwner(); if (owner != null) { - BrewEvent event = new BrewEvent(CraftBlock.at(world, pos), (BrewerInventory) owner.getInventory(), this.fuel); + BrewEvent event = new BrewEvent(CraftBlock.at(level, worldPosition), (BrewerInventory) owner.getInventory(), this.fuel); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { ci.cancel(); @@ -78,7 +78,7 @@ public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixi @Override public List getContents() { - return this.brewingItemStacks; + return this.items; } @Override @@ -101,7 +101,7 @@ public abstract class BrewingStandTileEntityMixin extends LockableTileEntityMixi } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CampfireTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CampfireTileEntityMixin.java index 27aa751b..63c5cbb3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CampfireTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CampfireTileEntityMixin.java @@ -1,15 +1,15 @@ package io.izzel.arclight.common.mixin.core.tileentity; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.tileentity.CampfireTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.Containers; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeType; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.CampfireBlockEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; @@ -19,17 +19,17 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -@Mixin(CampfireTileEntity.class) -public abstract class CampfireTileEntityMixin extends TileEntity { +@Mixin(CampfireBlockEntity.class) +public abstract class CampfireTileEntityMixin extends BlockEntity { // @formatter:off - @Shadow @Final private NonNullList inventory; - @Shadow @Final public int[] cookingTimes; - @Shadow @Final public int[] cookingTotalTimes; - @Shadow protected abstract void inventoryChanged(); + @Shadow @Final private NonNullList items; + @Shadow @Final public int[] cookingProgress; + @Shadow @Final public int[] cookingTime; + @Shadow protected abstract void markUpdated(); // @formatter:on - public CampfireTileEntityMixin(TileEntityType tileEntityTypeIn) { + public CampfireTileEntityMixin(BlockEntityType tileEntityTypeIn) { super(tileEntityTypeIn); } @@ -38,29 +38,29 @@ public abstract class CampfireTileEntityMixin extends TileEntity { * @reason */ @Overwrite - private void cookAndDrop() { - for (int i = 0; i < this.inventory.size(); ++i) { - ItemStack before = this.inventory.get(i); + private void cook() { + for (int i = 0; i < this.items.size(); ++i) { + ItemStack before = this.items.get(i); if (!before.isEmpty()) { - ++this.cookingTimes[i]; - if (this.cookingTimes[i] >= this.cookingTotalTimes[i]) { - IInventory iinventory = new Inventory(before); - ItemStack after = this.world.getRecipeManager().getRecipe(IRecipeType.CAMPFIRE_COOKING, iinventory, - this.world).map((cookingRecipe) -> cookingRecipe.getCraftingResult(iinventory)).orElse(before); - BlockPos blockpos = this.getPos(); + ++this.cookingProgress[i]; + if (this.cookingProgress[i] >= this.cookingTime[i]) { + Container iinventory = new SimpleContainer(before); + ItemStack after = this.level.getRecipeManager().getRecipeFor(RecipeType.CAMPFIRE_COOKING, iinventory, + this.level).map((cookingRecipe) -> cookingRecipe.assemble(iinventory)).orElse(before); + BlockPos blockpos = this.getBlockPos(); CraftItemStack craftBefore = CraftItemStack.asCraftMirror(before); org.bukkit.inventory.ItemStack bukkitAfter = CraftItemStack.asBukkitCopy(after); - BlockCookEvent event = new BlockCookEvent(CraftBlock.at(this.world, this.pos), craftBefore, bukkitAfter); + BlockCookEvent event = new BlockCookEvent(CraftBlock.at(this.level, this.worldPosition), craftBefore, bukkitAfter); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { continue; } ItemStack cookFinal = CraftItemStack.asNMSCopy(event.getResult()); - InventoryHelper.spawnItemStack(this.world, blockpos.getX(), blockpos.getY(), blockpos.getZ(), cookFinal); - this.inventory.set(i, ItemStack.EMPTY); - this.inventoryChanged(); + Containers.dropItemStack(this.level, blockpos.getX(), blockpos.getY(), blockpos.getZ(), cookFinal); + this.items.set(i, ItemStack.EMPTY); + this.markUpdated(); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ChestTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ChestTileEntityMixin.java index 0c46311e..4df3680e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ChestTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ChestTileEntityMixin.java @@ -1,15 +1,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.ChestTileEntity; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.HumanEntity; @@ -23,63 +14,72 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.ChestBlockEntity; -@Mixin(ChestTileEntity.class) +@Mixin(ChestBlockEntity.class) public abstract class ChestTileEntityMixin extends LockableTileEntityMixin { // @formatter:off - @Shadow private NonNullList chestContents; - @Shadow public int numPlayersUsing; + @Shadow private NonNullList items; + @Shadow public int openCount; // @formatter:on public List transaction = new ArrayList<>(); private int maxStack = IInventoryBridge.MAX_STACK; public boolean opened; - @Inject(method = "openInventory", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/ChestTileEntity;onOpenOrClose()V")) - public void arclight$openRedstone(PlayerEntity player, CallbackInfo ci) { - if (this.world == null) { + @Inject(method = "startOpen", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/ChestBlockEntity;signalOpenCount()V")) + public void arclight$openRedstone(Player player, CallbackInfo ci) { + if (this.level == null) { ci.cancel(); return; } - int oldPower = MathHelper.clamp(this.numPlayersUsing - 1, 0, 15); + int oldPower = Mth.clamp(this.openCount - 1, 0, 15); if (this.getBlockState().getBlock() == Blocks.TRAPPED_CHEST) { - int newPower = MathHelper.clamp(this.numPlayersUsing, 0, 15); + int newPower = Mth.clamp(this.openCount, 0, 15); if (oldPower != newPower) { - CraftEventFactory.callRedstoneChange(world, pos, oldPower, newPower); + CraftEventFactory.callRedstoneChange(level, worldPosition, oldPower, newPower); } } } - @Inject(method = "closeInventory", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/ChestTileEntity;onOpenOrClose()V")) - public void arclight$closeRedstone(PlayerEntity player, CallbackInfo ci) { - int oldPower = MathHelper.clamp(this.numPlayersUsing + 1, 0, 15); + @Inject(method = "stopOpen", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/ChestBlockEntity;signalOpenCount()V")) + public void arclight$closeRedstone(Player player, CallbackInfo ci) { + int oldPower = Mth.clamp(this.openCount + 1, 0, 15); if (this.getBlockState().getBlock() == Blocks.TRAPPED_CHEST) { - int newPower = MathHelper.clamp(this.numPlayersUsing, 0, 15); + int newPower = Mth.clamp(this.openCount, 0, 15); if (oldPower != newPower) { - CraftEventFactory.callRedstoneChange(world, pos, oldPower, newPower); + CraftEventFactory.callRedstoneChange(level, worldPosition, oldPower, newPower); } } } - @Inject(method = "tick", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/tileentity/ChestTileEntity;prevLidAngle:F")) + @Inject(method = "tick", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/block/entity/ChestBlockEntity;oOpenness:F")) private void arclight$openByApi(CallbackInfo ci) { if (opened) { - this.numPlayersUsing--; + this.openCount--; ci.cancel(); } } - @Redirect(method = "onOpenOrClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addBlockEvent(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;II)V")) - private void arclight$soundIfByPlayer(World world, BlockPos pos, Block blockIn, int eventID, int eventParam) { - if (!opened) world.addBlockEvent(pos, blockIn, eventID, eventParam); + @Redirect(method = "signalOpenCount", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;blockEvent(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;II)V")) + private void arclight$soundIfByPlayer(Level world, BlockPos pos, Block blockIn, int eventID, int eventParam) { + if (!opened) world.blockEvent(pos, blockIn, eventID, eventParam); } @Override public List getContents() { - return this.chestContents; + return this.items; } @Override @@ -102,7 +102,7 @@ public abstract class ChestTileEntityMixin extends LockableTileEntityMixin { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = IInventoryBridge.MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockLogicMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockLogicMixin.java index c182c6d0..3de75e29 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockLogicMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockLogicMixin.java @@ -2,11 +2,11 @@ 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.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.world.level.BaseCommandBlock; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.event.server.ServerCommandEvent; @@ -17,15 +17,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(CommandBlockLogic.class) +@Mixin(BaseCommandBlock.class) public class CommandBlockLogicMixin { // @formatter:off - @Shadow private ITextComponent customName; + @Shadow private Component name; // @formatter:on - @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) { + @Redirect(method = "performCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;performCommand(Lnet/minecraft/commands/CommandSourceStack;Ljava/lang/String;)I")) + private int arclight$serverCommand(Commands commands, CommandSourceStack sender, String command) { Joiner joiner = Joiner.on(" "); if (command.startsWith("/")) { command = command.substring(1); @@ -54,13 +54,13 @@ public class CommandBlockLogicMixin { args[0] = "minecraft:" + args[0]; } - return commands.handleCommand(sender, joiner.join(args)); + return commands.performCommand(sender, joiner.join(args)); } @Inject(method = "setName", at = @At("RETURN")) - public void arclight$setName(ITextComponent nameIn, CallbackInfo ci) { - if (this.customName == null) { - this.customName = new StringTextComponent("@"); + public void arclight$setName(Component nameIn, CallbackInfo ci) { + if (this.name == null) { + this.name = new TextComponent("@"); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockTileEntity1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockTileEntity1Mixin.java index 7b231369..7441f41b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockTileEntity1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/CommandBlockTileEntity1Mixin.java @@ -1,24 +1,24 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.tileentity.CommandBlockTileEntity; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.world.level.block.entity.CommandBlockEntity; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v.command.CraftBlockCommandSender; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net/minecraft/tileentity/CommandBlockTileEntity$1") +@Mixin(targets = "net/minecraft/world/level/block/entity/CommandBlockEntity$1") 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 CommandBlockEntity outerThis; - public CommandSender getBukkitSender(CommandSource wrapper) { + public CommandSender getBukkitSender(CommandSourceStack wrapper) { return new CraftBlockCommandSender(wrapper, outerThis); } @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { return getBukkitSender(wrapper); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ConduitTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ConduitTileEntityMixin.java index ce06244e..4214e4ca 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ConduitTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ConduitTileEntityMixin.java @@ -1,9 +1,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.tileentity.ConduitTileEntity; -import net.minecraft.util.math.AxisAlignedBB; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityPotionEffectEvent; @@ -15,22 +12,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Iterator; import java.util.List; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.ConduitBlockEntity; +import net.minecraft.world.phys.AABB; -@Mixin(ConduitTileEntity.class) +@Mixin(ConduitBlockEntity.class) public abstract class ConduitTileEntityMixin extends TileEntityMixin { - @Inject(method = "addEffectsToPlayers", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - public void arclight$addEntity(CallbackInfo ci, int i, int j, int k, int l, int i1, AxisAlignedBB bb, List list, - Iterator iterator, PlayerEntity playerEntity) { + @Inject(method = "applyEffects", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + public void arclight$addEntity(CallbackInfo ci, int i, int j, int k, int l, int i1, AABB bb, List list, + Iterator iterator, Player playerEntity) { ((PlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONDUIT); } - @Inject(method = "attackMobs", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) + @Inject(method = "updateDestroyTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) public void arclight$attackReason(CallbackInfo ci) { - CraftEventFactory.blockDamage = CraftBlock.at(this.world, this.pos); + CraftEventFactory.blockDamage = CraftBlock.at(this.level, this.worldPosition); } - @Inject(method = "attackMobs", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) + @Inject(method = "updateDestroyTarget", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) public void arclight$attackReasonReset(CallbackInfo ci) { CraftEventFactory.blockDamage = null; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/DispenserTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/DispenserTileEntityMixin.java index 31481b8d..3c33575f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/DispenserTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/DispenserTileEntityMixin.java @@ -1,8 +1,5 @@ package io.izzel.arclight.common.mixin.core.tileentity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.DispenserTileEntity; -import net.minecraft.util.NonNullList; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; @@ -11,12 +8,15 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.DispenserBlockEntity; -@Mixin(DispenserTileEntity.class) +@Mixin(DispenserBlockEntity.class) public abstract class DispenserTileEntityMixin extends LockableTileEntityMixin { // @formatter:off - @Shadow private NonNullList stacks; + @Shadow private NonNullList items; // @formatter:on public List transaction = new ArrayList<>(); @@ -24,7 +24,7 @@ public abstract class DispenserTileEntityMixin extends LockableTileEntityMixin { @Override public List getContents() { - return this.stacks; + return this.items; } @Override @@ -47,7 +47,7 @@ public abstract class DispenserTileEntityMixin extends LockableTileEntityMixin { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/EndGatewayTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/EndGatewayTileEntityMixin.java index 351b040c..f42146d3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/EndGatewayTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/EndGatewayTileEntityMixin.java @@ -3,10 +3,10 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.tileentity.EndGatewayTileEntity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftPlayer; @@ -18,18 +18,18 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(EndGatewayTileEntity.class) +@Mixin(TheEndGatewayBlockEntity.class) public abstract class EndGatewayTileEntityMixin extends TileEntityMixin { // @formatter:off @Shadow public abstract void triggerCooldown(); // @formatter:on - @Inject(method = "teleportEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;teleportKeepLoaded(DDD)V")) + @Inject(method = "teleportEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;teleportToWithTicket(DDD)V")) public void arclight$portal(Entity entityIn, CallbackInfo ci, BlockPos pos) { - if (entityIn instanceof ServerPlayerEntity) { + if (entityIn instanceof ServerPlayer) { CraftPlayer player = ((ServerPlayerEntityBridge) entityIn).bridge$getBukkitEntity(); - Location location = new Location(((WorldBridge) world).bridge$getWorld(), pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); + Location location = new Location(((WorldBridge) level).bridge$getWorld(), pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); location.setPitch(player.getLocation().getPitch()); location.setYaw(player.getLocation().getYaw()); @@ -40,7 +40,7 @@ public abstract class EndGatewayTileEntityMixin extends TileEntityMixin { return; } - ((ServerPlayNetHandlerBridge) (((ServerPlayerEntity) entityIn)).connection).bridge$teleport(event.getTo()); + ((ServerPlayNetHandlerBridge) (((ServerPlayer) entityIn)).connection).bridge$teleport(event.getTo()); this.triggerCooldown(); // CraftBukkit - call at end of method ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/HopperTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/HopperTileEntityMixin.java index e379fdd7..993f814a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/HopperTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/HopperTileEntityMixin.java @@ -2,15 +2,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.item.minecart.HopperMinecartEntity; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.HopperTileEntity; -import net.minecraft.tileentity.IHopper; -import net.minecraft.util.Direction; -import net.minecraft.util.NonNullList; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest; @@ -31,14 +22,23 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.Container; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.vehicle.MinecartHopper; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.Hopper; +import net.minecraft.world.level.block.entity.HopperBlockEntity; -@Mixin(HopperTileEntity.class) +@Mixin(HopperBlockEntity.class) public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { // @formatter:off - @Shadow private NonNullList inventory; - @Shadow public abstract void setTransferCooldown(int ticks); - @Shadow public abstract void setInventorySlotContents(int index, ItemStack stack); + @Shadow private NonNullList items; + @Shadow public abstract void setCooldown(int ticks); + @Shadow public abstract void setItem(int index, ItemStack stack); // @formatter:on public List transaction = new ArrayList<>(); @@ -46,23 +46,23 @@ public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { private static transient boolean arclight$moveItem; - @Inject(method = "transferItemsOut", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;")) - public void arclight$returnIfMoveFail(CallbackInfoReturnable cir, IInventory inv, Direction direction, int i, ItemStack itemStack) { + @Inject(method = "ejectItems", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/Container;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/core/Direction;)Lnet/minecraft/world/item/ItemStack;")) + public void arclight$returnIfMoveFail(CallbackInfoReturnable cir, Container inv, Direction direction, int i, ItemStack itemStack) { if (arclight$moveItem) { - this.setInventorySlotContents(i, itemStack); + this.setItem(i, itemStack); cir.setReturnValue(false); } arclight$moveItem = false; } - @Redirect(method = "transferItemsOut", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;")) - public ItemStack arclight$moveItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) { + @Redirect(method = "ejectItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/Container;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/core/Direction;)Lnet/minecraft/world/item/ItemStack;")) + public ItemStack arclight$moveItem(Container source, Container destination, ItemStack stack, Direction direction) { CraftItemStack original = CraftItemStack.asCraftMirror(stack); Inventory destinationInventory; // Have to special case large chests as they work oddly - if (destination instanceof DoubleSidedInventory) { - destinationInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) destination)); + if (destination instanceof CompoundContainer) { + destinationInventory = new CraftInventoryDoubleChest(((CompoundContainer) destination)); } else { destinationInventory = ((IInventoryBridge) destination).getOwnerInventory(); } @@ -70,29 +70,29 @@ public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), original.clone(), destinationInventory, true); Bukkit.getPluginManager().callEvent(event); if (arclight$moveItem = event.isCancelled()) { - this.setTransferCooldown(8); // Delay hopper checks + this.setCooldown(8); // Delay hopper checks return null; } - return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction); + return HopperBlockEntity.addItem(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction); } - @Inject(method = "pullItemFromSlot", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;")) - private static void arclight$returnIfPullFail(IHopper hopper, IInventory inventoryIn, int index, Direction direction, CallbackInfoReturnable cir, ItemStack item, ItemStack item1) { + @Inject(method = "tryTakeInItemFromSlot", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/Container;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/core/Direction;)Lnet/minecraft/world/item/ItemStack;")) + private static void arclight$returnIfPullFail(Hopper hopper, Container inventoryIn, int index, Direction direction, CallbackInfoReturnable cir, ItemStack item, ItemStack item1) { if (arclight$moveItem) { - inventoryIn.setInventorySlotContents(index, item1); + inventoryIn.setItem(index, item1); cir.setReturnValue(false); } arclight$moveItem = false; } - @Redirect(method = "pullItemFromSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;")) - private static ItemStack arclight$pullItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) { + @Redirect(method = "tryTakeInItemFromSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/Container;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/core/Direction;)Lnet/minecraft/world/item/ItemStack;")) + private static ItemStack arclight$pullItem(Container source, Container destination, ItemStack stack, Direction direction) { CraftItemStack original = CraftItemStack.asCraftMirror(stack); Inventory sourceInventory; // Have to special case large chests as they work oddly - if (source instanceof DoubleSidedInventory) { - sourceInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) source)); + if (source instanceof CompoundContainer) { + sourceInventory = new CraftInventoryDoubleChest(((CompoundContainer) source)); } else { sourceInventory = ((IInventoryBridge) source).getOwnerInventory(); } @@ -100,18 +100,18 @@ public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, original.clone(), ((IInventoryBridge) destination).getOwnerInventory(), false); Bukkit.getPluginManager().callEvent(event); if (arclight$moveItem = event.isCancelled()) { - if (destination instanceof HopperTileEntity) { - ((HopperTileEntity) destination).setTransferCooldown(8); // Delay hopper checks - } else if (destination instanceof HopperMinecartEntity) { - ((HopperMinecartEntity) destination).setTransferTicker(4); // Delay hopper minecart checks + if (destination instanceof HopperBlockEntity) { + ((HopperBlockEntity) destination).setCooldown(8); // Delay hopper checks + } else if (destination instanceof MinecartHopper) { + ((MinecartHopper) destination).setCooldown(4); // Delay hopper minecart checks } return null; } - return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction); + return HopperBlockEntity.addItem(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction); } - @Inject(method = "captureItem", cancellable = true, at = @At("HEAD")) - private static void arclight$pickupItem(IInventory inventory, ItemEntity itemEntity, CallbackInfoReturnable cir) { + @Inject(method = "addItem", cancellable = true, at = @At("HEAD")) + private static void arclight$pickupItem(Container inventory, ItemEntity itemEntity, CallbackInfoReturnable cir) { InventoryPickupItemEvent event = new InventoryPickupItemEvent(((IInventoryBridge) inventory).getOwnerInventory(), (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -121,7 +121,7 @@ public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { @Override public List getContents() { - return this.inventory; + return this.items; } @Override @@ -144,7 +144,7 @@ public abstract class HopperTileEntityMixin extends LockableTileEntityMixin { } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntity1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntity1Mixin.java index a656eef5..4620e6d5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntity1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntity1Mixin.java @@ -2,11 +2,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.LecternBlock; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.tileentity.LecternTileEntity; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -18,21 +13,26 @@ import io.izzel.arclight.common.bridge.tileentity.TileEntityBridge; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.block.LecternBlock; +import net.minecraft.world.level.block.entity.LecternBlockEntity; -@Mixin(targets = "net/minecraft/tileentity/LecternTileEntity$1") -public abstract class LecternTileEntity1Mixin implements IInventoryBridge, IInventory { +@Mixin(targets = "net/minecraft/world/level/block/entity/LecternBlockEntity$1") +public abstract class LecternTileEntity1Mixin implements IInventoryBridge, Container { - @Shadow(aliases = {"this$0", "field_214028_a"}, remap = false) private LecternTileEntity outerThis; + @Shadow(aliases = {"this$0", "field_214028_a"}, remap = false) private LecternBlockEntity outerThis; public List transaction = new ArrayList<>(); private int maxStack = 1; @Override - public void setInventorySlotContents(int index, ItemStack stack) { + public void setItem(int index, ItemStack stack) { if (index == 0) { outerThis.setBook(stack); - if (outerThis.getWorld() != null) { - LecternBlock.setHasBook(outerThis.getWorld(), outerThis.getPos(), outerThis.getBlockState(), outerThis.hasBook()); + if (outerThis.getLevel() != null) { + LecternBlock.resetBookState(outerThis.getLevel(), outerThis.getBlockPos(), outerThis.getBlockState(), outerThis.hasBook()); } } } @@ -67,7 +67,7 @@ public abstract class LecternTileEntity1Mixin implements IInventoryBridge, IInve } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = 1; return maxStack; } @@ -79,15 +79,15 @@ public abstract class LecternTileEntity1Mixin implements IInventoryBridge, IInve @Override public Location getLocation() { - return new Location(((WorldBridge) outerThis.getWorld()).bridge$getWorld(), outerThis.getPos().getX(), outerThis.getPos().getY(), outerThis.getPos().getZ()); + return new Location(((WorldBridge) outerThis.getLevel()).bridge$getWorld(), outerThis.getBlockPos().getX(), outerThis.getBlockPos().getY(), outerThis.getBlockPos().getZ()); } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntityMixin.java index bf2d834e..a0046224 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LecternTileEntityMixin.java @@ -3,22 +3,22 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.inventory.container.LecternContainerBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.ICommandSource; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.LecternContainer; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.LecternTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIntArray; -import net.minecraft.util.math.vector.Vector2f; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Container; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ContainerData; +import net.minecraft.world.inventory.LecternMenu; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.LecternBlockEntity; +import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v.command.CraftBlockCommandSender; import org.jetbrains.annotations.NotNull; @@ -32,17 +32,17 @@ import org.spongepowered.asm.mixin.injection.Redirect; import javax.annotation.Nullable; import java.util.UUID; -@Mixin(LecternTileEntity.class) -public abstract class LecternTileEntityMixin extends TileEntityMixin implements ICommandSource, ICommandSourceBridge { +@Mixin(LecternBlockEntity.class) +public abstract class LecternTileEntityMixin extends TileEntityMixin implements CommandSource, ICommandSourceBridge { // @formatter:off - @Shadow @Final public IInventory inventory; - @Shadow @Final private IIntArray field_214049_b; + @Shadow @Final public Container bookAccess; + @Shadow @Final private ContainerData dataAccess; // @formatter:on - @Redirect(method = "createCommandSource", at = @At(value = "NEW", target = "net/minecraft/command/CommandSource")) - private CommandSource arclight$source(ICommandSource source, Vector3d vec3d, Vector2f vec2f, ServerWorld world, int i, String s, ITextComponent component, MinecraftServer server, @Nullable Entity entity) { - return new CommandSource(this, vec3d, vec2f, world, i, s, component, server, entity); + @Redirect(method = "createCommandSourceStack", at = @At(value = "NEW", target = "net/minecraft/commands/CommandSourceStack")) + private CommandSourceStack arclight$source(CommandSource source, Vec3 vec3d, Vec2 vec2f, ServerLevel world, int i, String s, Component component, MinecraftServer server, @Nullable Entity entity) { + return new CommandSourceStack(this, vec3d, vec2f, world, i, s, component, server, entity); } /** @@ -50,37 +50,37 @@ public abstract class LecternTileEntityMixin extends TileEntityMixin implements * @reason */ @Overwrite - public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity entity) { - LecternContainer container = new LecternContainer(i, this.inventory, this.field_214049_b); + public AbstractContainerMenu createMenu(int i, Inventory playerInventory, Player entity) { + LecternMenu container = new LecternMenu(i, this.bookAccess, this.dataAccess); ((LecternContainerBridge) container).bridge$setPlayerInventory(playerInventory); return container; } @Override - public void sendMessage(@NotNull ITextComponent component, @NotNull UUID uuid) { + public void sendMessage(@NotNull Component component, @NotNull UUID uuid) { } @Override - public boolean shouldReceiveFeedback() { + public boolean acceptsSuccess() { return false; } @Override - public boolean shouldReceiveErrors() { + public boolean acceptsFailure() { return false; } @Override - public boolean allowLogging() { + public boolean shouldInformAdmins() { return false; } - public CommandSender getBukkitSender(CommandSource wrapper) { - return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this); + public CommandSender getBukkitSender(CommandSourceStack wrapper) { + return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (BlockEntity) (Object) this); } @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { return getBukkitSender(wrapper); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LockableTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LockableTileEntityMixin.java index 664f9476..4dbf1a1c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LockableTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/LockableTileEntityMixin.java @@ -1,27 +1,27 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.tileentity.LockableTileEntity; +import net.minecraft.world.Container; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import org.bukkit.Location; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.spongepowered.asm.mixin.Mixin; -@Mixin(LockableTileEntity.class) -public abstract class LockableTileEntityMixin extends TileEntityMixin implements IInventoryBridge, IInventory { +@Mixin(BaseContainerBlockEntity.class) +public abstract class LockableTileEntityMixin extends TileEntityMixin implements IInventoryBridge, Container { @Override public Location getLocation() { - return CraftBlock.at(this.world, this.pos).getLocation(); + return CraftBlock.at(this.level, this.worldPosition).getLocation(); } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ShulkerBoxTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ShulkerBoxTileEntityMixin.java index a752ffe3..35916af0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ShulkerBoxTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/ShulkerBoxTileEntityMixin.java @@ -1,9 +1,5 @@ package io.izzel.arclight.common.mixin.core.tileentity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.ShulkerBoxTileEntity; -import net.minecraft.util.NonNullList; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; @@ -15,31 +11,35 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.NonNullList; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; -@Mixin(ShulkerBoxTileEntity.class) +@Mixin(ShulkerBoxBlockEntity.class) public abstract class ShulkerBoxTileEntityMixin extends LockableTileEntityMixin { // @formatter:off - @Shadow private NonNullList items; + @Shadow private NonNullList itemStacks; // @formatter:on public List transaction = new ArrayList<>(); private int maxStack = MAX_STACK; public boolean opened; - @Inject(method = "openInventory", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addBlockEvent(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;II)V")) - private void arclight$sound1(PlayerEntity player, CallbackInfo ci) { + @Inject(method = "startOpen", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;blockEvent(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;II)V")) + private void arclight$sound1(Player player, CallbackInfo ci) { if (opened) ci.cancel(); } - @Inject(method = "closeInventory", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addBlockEvent(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;II)V")) - private void arclight$sound2(PlayerEntity player, CallbackInfo ci) { + @Inject(method = "stopOpen", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;blockEvent(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;II)V")) + private void arclight$sound2(Player player, CallbackInfo ci) { if (opened) ci.cancel(); } @Override public List getContents() { - return this.items; + return this.itemStacks; } @Override @@ -62,7 +62,7 @@ public abstract class ShulkerBoxTileEntityMixin extends LockableTileEntityMixin } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = MAX_STACK; return maxStack; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SignTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SignTileEntityMixin.java index 2c6af823..b651fefe 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SignTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SignTileEntityMixin.java @@ -3,17 +3,17 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.tileentity.SignTileEntityBridge; -import net.minecraft.command.CommandSource; -import net.minecraft.command.ICommandSource; -import net.minecraft.entity.Entity; -import net.minecraft.item.DyeColor; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.SignTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.vector.Vector2f; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v.command.CraftBlockCommandSender; import org.jetbrains.annotations.NotNull; @@ -27,50 +27,50 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.annotation.Nullable; import java.util.UUID; -@Mixin(SignTileEntity.class) -public abstract class SignTileEntityMixin extends TileEntityMixin implements SignTileEntityBridge, ICommandSource, ICommandSourceBridge { +@Mixin(SignBlockEntity.class) +public abstract class SignTileEntityMixin extends TileEntityMixin implements SignTileEntityBridge, CommandSource, ICommandSourceBridge { // @formatter:off @Override @Accessor("isEditable") public abstract void bridge$setEditable(boolean editable); // @formatter:on - @Redirect(method = "getCommandSource", at = @At(value = "NEW", target = "net/minecraft/command/CommandSource")) - private CommandSource arclight$source(ICommandSource source, Vector3d vec3d, Vector2f vec2f, ServerWorld world, int i, String s, ITextComponent component, MinecraftServer server, @Nullable Entity entity) { - return new CommandSource(this, vec3d, vec2f, world, i, s, component, server, entity); + @Redirect(method = "createCommandSourceStack", at = @At(value = "NEW", target = "net/minecraft/commands/CommandSourceStack")) + private CommandSourceStack arclight$source(CommandSource source, Vec3 vec3d, Vec2 vec2f, ServerLevel world, int i, String s, Component component, MinecraftServer server, @Nullable Entity entity) { + return new CommandSourceStack(this, vec3d, vec2f, world, i, s, component, server, entity); } - @Inject(method = "setTextColor", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;notifyBlockUpdate(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;I)V")) + @Inject(method = "setColor", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;sendBlockUpdated(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;I)V")) public void arclight$setColor(DyeColor newColor, CallbackInfoReturnable cir) { - if (this.world == null) { + if (this.level == null) { cir.setReturnValue(true); } } @Override - public void sendMessage(@NotNull ITextComponent component, @NotNull UUID uuid) { + public void sendMessage(@NotNull Component component, @NotNull UUID uuid) { } @Override - public boolean shouldReceiveFeedback() { + public boolean acceptsSuccess() { return false; } @Override - public boolean shouldReceiveErrors() { + public boolean acceptsFailure() { return false; } @Override - public boolean allowLogging() { + public boolean shouldInformAdmins() { return false; } - public CommandSender getBukkitSender(CommandSource wrapper) { - return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (TileEntity) (Object) this); + public CommandSender getBukkitSender(CommandSourceStack wrapper) { + return wrapper.getEntity() != null ? ((EntityBridge) wrapper.getEntity()).bridge$getBukkitSender(wrapper) : new CraftBlockCommandSender(wrapper, (BlockEntity) (Object) this); } @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { return getBukkitSender(wrapper); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SkullTileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SkullTileEntityMixin.java index e2379d9e..41c63c91 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SkullTileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/SkullTileEntityMixin.java @@ -11,7 +11,6 @@ import com.mojang.authlib.GameProfile; import com.mysql.jdbc.StringUtils; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; import io.izzel.arclight.common.mod.util.ArclightHeadLoader; -import net.minecraft.tileentity.SkullTileEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.spongepowered.asm.mixin.Mixin; @@ -24,12 +23,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import net.minecraft.world.level.block.entity.SkullBlockEntity; -@Mixin(SkullTileEntity.class) +@Mixin(SkullBlockEntity.class) public abstract class SkullTileEntityMixin extends TileEntityMixin { // @formatter:off - @Shadow public GameProfile playerProfile; + @Shadow public GameProfile owner; // @formatter:on private static ExecutorService executor = Executors.newFixedThreadPool(3, @@ -45,10 +45,10 @@ public abstract class SkullTileEntityMixin extends TileEntityMixin { * @reason */ @Overwrite - private void updatePlayerProfile() { - GameProfile profile = this.playerProfile; + private void updateOwnerProfile() { + GameProfile profile = this.owner; b(profile, input -> { - playerProfile = input; + owner = input; markDirty(); return false; }, false); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/TileEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/TileEntityMixin.java index 2e47c313..6e9d4234 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/TileEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/tileentity/TileEntityMixin.java @@ -2,11 +2,6 @@ package io.izzel.arclight.common.mixin.core.tileentity; import io.izzel.arclight.common.bridge.tileentity.TileEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataTypeRegistry; @@ -19,44 +14,49 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.annotation.Nullable; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; -@Mixin(TileEntity.class) +@Mixin(BlockEntity.class) public abstract class TileEntityMixin implements TileEntityBridge { private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); public CraftPersistentDataContainer persistentDataContainer; // @formatter:off - @Shadow @Nullable public World world; - @Shadow protected BlockPos pos; + @Shadow @Nullable public Level level; + @Shadow protected BlockPos worldPosition; @Shadow public abstract BlockState getBlockState(); - @Shadow public abstract void markDirty(); - @Shadow public BlockPos getPos() { return null; } - @Shadow public abstract boolean onlyOpsCanSetNbt(); + @Shadow public abstract void setChanged(); + @Shadow public BlockPos getBlockPos() { return null; } + @Shadow public abstract boolean onlyOpCanSetNbt(); // @formatter:on - @Inject(method = "read", at = @At("RETURN")) - public void arclight$loadPersistent(BlockState state, CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "load", at = @At("RETURN")) + public void arclight$loadPersistent(BlockState state, CompoundTag compound, CallbackInfo ci) { this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); - CompoundNBT persistentDataTag = compound.getCompound("PublicBukkitValues"); + CompoundTag persistentDataTag = compound.getCompound("PublicBukkitValues"); if (persistentDataTag != null) { this.persistentDataContainer.putAll(persistentDataTag); } } - @Inject(method = "writeInternal", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;putString(Ljava/lang/String;Ljava/lang/String;)V")) - public void arclight$savePersistent(CompoundNBT compound, CallbackInfoReturnable cir) { + @Inject(method = "saveMetadata", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;putString(Ljava/lang/String;Ljava/lang/String;)V")) + public void arclight$savePersistent(CompoundTag compound, CallbackInfoReturnable cir) { if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) { compound.put("PublicBukkitValues", this.persistentDataContainer.toTagCompound()); } } public InventoryHolder getOwner() { - if (this.world == null) return null; - org.bukkit.block.Block block = CraftBlock.at(this.world, this.pos); + if (this.level == null) return null; + org.bukkit.block.Block block = CraftBlock.at(this.level, this.worldPosition); if (block == null) { - org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.WARNING, "No block for owner at %s %d %d %d", new Object[]{((WorldBridge) world).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ()}); + org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.WARNING, "No block for owner at %s %d %d %d", new Object[]{((WorldBridge) level).bridge$getWorld(), worldPosition.getX(), worldPosition.getY(), worldPosition.getZ()}); return null; } org.bukkit.block.BlockState state = block.getState(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/BootstrapMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/BootstrapMixin.java index 0fe8f3cf..3142fd75 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/BootstrapMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/BootstrapMixin.java @@ -1,6 +1,5 @@ package io.izzel.arclight.common.mixin.core.util; -import net.minecraft.util.registry.Bootstrap; import org.bukkit.craftbukkit.v.util.CraftLegacy; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,11 +10,12 @@ import io.izzel.arclight.api.Unsafe; import java.lang.reflect.Field; import java.util.HashSet; import java.util.Set; +import net.minecraft.server.Bootstrap; @Mixin(Bootstrap.class) public class BootstrapMixin { - @Inject(method = "register", at = @At("HEAD")) + @Inject(method = "bootStrap", at = @At("HEAD")) private static void arclight$replaceWhitelist(CallbackInfo ci) { // 噢,天哪,看着肮脏的 hack,我i了 // 我简直是 fucking genius diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/DamageSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/DamageSourceMixin.java index 8c8a722d..4482641f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/DamageSourceMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/DamageSourceMixin.java @@ -1,18 +1,18 @@ package io.izzel.arclight.common.mixin.core.util; -import net.minecraft.entity.Entity; -import net.minecraft.util.DamageSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import io.izzel.arclight.common.bridge.util.DamageSourceBridge; import javax.annotation.Nullable; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; @Mixin(DamageSource.class) public abstract class DamageSourceMixin implements DamageSourceBridge { // @formatter:off - @Shadow @Nullable public Entity getTrueSource() { return null; } + @Shadow @Nullable public Entity getEntity() { return null; } // @formatter:on private boolean sweep; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/FoodStatsMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/FoodStatsMixin.java index f13140d9..07e04cdc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/FoodStatsMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/FoodStatsMixin.java @@ -3,13 +3,13 @@ package io.izzel.arclight.common.mixin.core.util; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.util.FoodStatsBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.Food; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.network.play.server.SUpdateHealthPacket; -import net.minecraft.util.FoodStats; +import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodData; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -20,55 +20,55 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(FoodStats.class) +@Mixin(FoodData.class) public abstract class FoodStatsMixin implements FoodStatsBridge { // @formatter:off @Shadow public int foodLevel; - @Shadow public abstract void addStats(int foodLevelIn, float foodSaturationModifier); - @Shadow public float foodSaturationLevel; + @Shadow public abstract void eat(int foodLevelIn, float foodSaturationModifier); + @Shadow public float saturationLevel; // @formatter:on - private PlayerEntity entityhuman; + private Player entityhuman; public void arclight$constructor() { throw new RuntimeException(); } - public void arclight$constructor(PlayerEntity playerEntity) { + public void arclight$constructor(Player playerEntity) { arclight$constructor(); this.entityhuman = playerEntity; } - @Redirect(method = "consume", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/FoodStats;addStats(IF)V")) - public void arclight$foodLevelChange(FoodStats foodStats, int foodLevelIn, float foodSaturationModifier, Item maybeFood, ItemStack stack) { - Food food = maybeFood.getFood(); + @Redirect(method = "eat", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/food/FoodData;eat(IF)V")) + public void arclight$foodLevelChange(FoodData foodStats, int foodLevelIn, float foodSaturationModifier, Item maybeFood, ItemStack stack) { + FoodProperties food = maybeFood.getFoodProperties(); int oldFoodLevel = this.foodLevel; - FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, food.getHealing() + oldFoodLevel, stack); + FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, food.getNutrition() + oldFoodLevel, stack); if (!event.isCancelled()) { - this.addStats(event.getFoodLevel() - oldFoodLevel, food.getSaturation()); + this.eat(event.getFoodLevel() - oldFoodLevel, food.getSaturationModifier()); } ((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity().sendHealthUpdate(); } @Inject(method = "tick", at = @At(value = "INVOKE_ASSIGN", remap = false, target = "Ljava/lang/Math;max(II)I")) - public void arclight$foodLevelChange2(PlayerEntity player, CallbackInfo ci) { + public void arclight$foodLevelChange2(Player player, CallbackInfo ci) { FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, Math.max(this.foodLevel - 1, 0)); if (!event.isCancelled()) { this.foodLevel = event.getFoodLevel(); } - ((ServerPlayerEntity) entityhuman).connection.sendPacket(new SUpdateHealthPacket(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity().getScaledHealth(), this.foodLevel, this.foodSaturationLevel)); + ((ServerPlayer) entityhuman).connection.send(new ClientboundSetHealthPacket(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;heal(F)V")) - public void arclight$heal(PlayerEntity player, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;heal(F)V")) + public void arclight$heal(Player player, CallbackInfo ci) { ((LivingEntityBridge) player).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.SATIATED); } @Override - public void bridge$setEntityHuman(PlayerEntity playerEntity) { + public void bridge$setEntityHuman(Player playerEntity) { this.entityhuman = playerEntity; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IWorldPosCallableMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IWorldPosCallableMixin.java index 5de938a8..4de77f59 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IWorldPosCallableMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IWorldPosCallableMixin.java @@ -1,20 +1,20 @@ package io.izzel.arclight.common.mixin.core.util; import io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge; -import net.minecraft.util.IWorldPosCallable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import org.bukkit.Location; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import java.util.Optional; import java.util.function.BiFunction; +import net.minecraft.core.BlockPos; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.level.Level; -@Mixin(IWorldPosCallable.class) +@Mixin(ContainerLevelAccess.class) public interface IWorldPosCallableMixin extends IWorldPosCallableBridge { - default World getWorld() { + default Level getWorld() { return bridge$getWorld(); } @@ -31,16 +31,16 @@ public interface IWorldPosCallableMixin extends IWorldPosCallableBridge { * @reason */ @Overwrite - static IWorldPosCallable of(final World world, final BlockPos pos) { - class Anonymous implements IWorldPosCallable, IWorldPosCallableBridge { + static ContainerLevelAccess create(final Level world, final BlockPos pos) { + class Anonymous implements ContainerLevelAccess, IWorldPosCallableBridge { @Override - public Optional apply(BiFunction worldPosConsumer) { + public Optional evaluate(BiFunction worldPosConsumer) { return Optional.of(worldPosConsumer.apply(world, pos)); } @Override - public World bridge$getWorld() { + public Level bridge$getWorld() { return world; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IndirectEntityDamageSourceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IndirectEntityDamageSourceMixin.java index d5cf250b..34b9ca1b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IndirectEntityDamageSourceMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/IndirectEntityDamageSourceMixin.java @@ -1,22 +1,22 @@ package io.izzel.arclight.common.mixin.core.util; -import net.minecraft.entity.Entity; -import net.minecraft.util.IndirectEntityDamageSource; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import io.izzel.arclight.common.bridge.util.IndirectEntityDamageSourceBridge; +import net.minecraft.world.damagesource.IndirectEntityDamageSource; +import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Shadow; @Mixin(IndirectEntityDamageSource.class) public class IndirectEntityDamageSourceMixin extends DamageSourceMixin implements IndirectEntityDamageSourceBridge { // @formatter:off - @Shadow @Final private Entity indirectEntity; + @Shadow @Final private Entity owner; // @formatter:on public Entity getProximateDamageSource() { - Entity trueSource = super.getTrueSource(); - return trueSource == null ? this.indirectEntity : trueSource; + Entity trueSource = super.getEntity(); + return trueSource == null ? this.owner : trueSource; } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ColorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ColorMixin.java index ca63154b..dde6e2be 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ColorMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ColorMixin.java @@ -1,7 +1,5 @@ package io.izzel.arclight.common.mixin.core.util.text; -import net.minecraft.util.text.Color; -import net.minecraft.util.text.TextFormatting; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -11,21 +9,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.TextColor; -@Mixin(Color.class) +@Mixin(TextColor.class) public class ColorMixin { // @formatter:off @Shadow @Final @Mutable @Nullable public String name; // @formatter:on - public TextFormatting format; + public ChatFormatting format; public void arclight$constructor(int color) { throw new RuntimeException(); } - public void arclight$constructor(int color, String name, TextFormatting textFormatting) { + public void arclight$constructor(int color, String name, ChatFormatting textFormatting) { arclight$constructor(color); this.name = name; this.format = textFormatting; @@ -33,6 +33,6 @@ public class ColorMixin { @Inject(method = "(ILjava/lang/String;)V", at = @At("RETURN")) private void arclight$withFormat(int color, String name, CallbackInfo ci) { - this.format = TextFormatting.getValueByName(name); + this.format = ChatFormatting.getByName(name); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ITextComponentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ITextComponentMixin.java index 2f00f042..69f0ba93 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ITextComponentMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/ITextComponentMixin.java @@ -2,7 +2,6 @@ package io.izzel.arclight.common.mixin.core.util.text; import com.google.common.collect.Streams; import io.izzel.arclight.common.bridge.util.text.ITextComponentBridge; -import net.minecraft.util.text.ITextComponent; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -11,37 +10,38 @@ import java.util.Iterator; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; +import net.minecraft.network.chat.Component; -@Mixin(ITextComponent.class) -public interface ITextComponentMixin extends ITextComponentBridge, Iterable { +@Mixin(Component.class) +public interface ITextComponentMixin extends ITextComponentBridge, Iterable { // @formatter:off - @Shadow List getSiblings(); + @Shadow List getSiblings(); // @formatter:on - default Stream stream() { - class Func implements Function> { + default Stream stream() { + class Func implements Function> { @Override - public Stream apply(ITextComponent component) { + public Stream apply(Component component) { return ((ITextComponentBridge) component).bridge$stream(); } } - return Streams.concat(Stream.of((ITextComponent) this), this.getSiblings().stream().flatMap(new Func())); + return Streams.concat(Stream.of((Component) this), this.getSiblings().stream().flatMap(new Func())); } @Override - default @NotNull Iterator iterator() { + default @NotNull Iterator iterator() { return this.stream().iterator(); } @Override - default Stream bridge$stream() { + default Stream bridge$stream() { return stream(); } @Override - default Iterator bridge$iterator() { + default Iterator bridge$iterator() { return iterator(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/StyleMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/StyleMixin.java index b9e51156..79b7eec0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/StyleMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/util/text/StyleMixin.java @@ -1,21 +1,21 @@ package io.izzel.arclight.common.mixin.core.util.text; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.Color; -import net.minecraft.util.text.Style; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.HoverEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import javax.annotation.Nullable; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; +import net.minecraft.resources.ResourceLocation; @Mixin(Style.class) public class StyleMixin { // @formatter:off - @Shadow @Final @Nullable private Color color; + @Shadow @Final @Nullable private TextColor color; @Shadow @Final @Nullable private Boolean bold; @Shadow @Final @Nullable private Boolean italic; @Shadow @Final @Nullable private Boolean underlined; @@ -24,18 +24,18 @@ public class StyleMixin { @Shadow @Final @Nullable private ClickEvent clickEvent; @Shadow @Final @Nullable private HoverEvent hoverEvent; @Shadow @Final @Nullable private String insertion; - @Shadow @Final @Nullable private ResourceLocation fontId; + @Shadow @Final @Nullable private ResourceLocation font; // @formatter:on public Style setStrikethrough(final Boolean b) { - return new Style(this.color, this.bold, this.italic, this.underlined, b, this.obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.fontId); + return new Style(this.color, this.bold, this.italic, this.underlined, b, this.obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.font); } public Style setUnderline(final Boolean b) { - return new Style(this.color, this.bold, this.italic, b, this.strikethrough, this.obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.fontId); + return new Style(this.color, this.bold, this.italic, b, this.strikethrough, this.obfuscated, this.clickEvent, this.hoverEvent, this.insertion, this.font); } public Style setRandom(final Boolean b) { - return new Style(this.color, this.bold, this.italic, this.underlined, this.strikethrough, b, this.clickEvent, this.hoverEvent, this.insertion, this.fontId); + return new Style(this.color, this.bold, this.italic, this.underlined, this.strikethrough, b, this.clickEvent, this.hoverEvent, this.insertion, this.font); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/village/VillageSiegeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/village/VillageSiegeMixin.java index 067e9d51..8761ceb2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/village/VillageSiegeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/village/VillageSiegeMixin.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mixin.core.village; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.village.VillageSiege; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ai.village.VillageSiege; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,8 +12,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(VillageSiege.class) public class VillageSiegeMixin { - @Inject(method = "spawnZombie", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - public void arclight$addEntityReason(ServerWorld world, CallbackInfo ci) { + @Inject(method = "trySpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + public void arclight$addEntityReason(ServerLevel world, CallbackInfo ci) { ((ServerWorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.VILLAGE_INVASION); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java index f937d5f3..c7aacd6d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/ExplosionMixin.java @@ -7,32 +7,6 @@ import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.world.ExplosionBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.block.AbstractFireBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.enchantment.ProtectionEnchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.FallingBlockEntity; -import net.minecraft.entity.item.TNTEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.FluidState; -import net.minecraft.item.ItemStack; -import net.minecraft.loot.LootContext; -import net.minecraft.loot.LootParameters; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.Explosion; -import net.minecraft.world.ExplosionContext; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -55,36 +29,62 @@ import java.util.Map; import java.util.Optional; import java.util.Random; import java.util.Set; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.world.entity.item.PrimedTnt; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.ProtectionEnchantment; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.ExplosionDamageCalculator; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseFireBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; @Mixin(Explosion.class) public abstract class ExplosionMixin implements ExplosionBridge { // @formatter:off - @Shadow @Final private World world; - @Shadow @Final private Explosion.Mode mode; - @Shadow @Mutable @Final private float size; - @Shadow @Final private List affectedBlockPositions; + @Shadow @Final private Level level; + @Shadow @Final private Explosion.BlockInteraction blockInteraction; + @Shadow @Mutable @Final private float radius; + @Shadow @Final private List toBlow; @Shadow @Final private double x; @Shadow @Final private double y; @Shadow @Final private double z; - @Shadow @Final public Entity exploder; + @Shadow @Final public Entity source; @Shadow public abstract DamageSource getDamageSource(); - @Shadow @Final private Map playerKnockbackMap; - @Accessor("exploder") public abstract Entity bridge$getExploder(); - @Accessor("size") public abstract float bridge$getSize(); - @Accessor("size") public abstract void bridge$setSize(float size); - @Accessor("mode") public abstract Explosion.Mode bridge$getMode(); - @Shadow @Final private boolean causesFire; + @Shadow @Final private Map hitPlayers; + @Accessor("source") public abstract Entity bridge$getExploder(); + @Accessor("radius") public abstract float bridge$getSize(); + @Accessor("radius") public abstract void bridge$setSize(float size); + @Accessor("blockInteraction") public abstract Explosion.BlockInteraction bridge$getMode(); + @Shadow @Final private boolean fire; @Shadow @Final private Random random; - @Shadow private static void handleExplosionDrops(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos) { } + @Shadow private static void addBlockDrops(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos) { } // @formatter:on - @Shadow @Final private ExplosionContext context; + @Shadow @Final private ExplosionDamageCalculator damageCalculator; - @Inject(method = "(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/Explosion$Mode;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)V", at = @At("RETURN")) - public void arclight$adjustSize(World worldIn, Entity exploderIn, double xIn, double yIn, double zIn, float sizeIn, boolean causesFireIn, Explosion.Mode modeIn, CallbackInfo ci) { - this.size = Math.max(sizeIn, 0F); + public void arclight$adjustSize(Level worldIn, Entity exploderIn, double xIn, double yIn, double zIn, float sizeIn, boolean causesFireIn, Explosion.BlockInteraction modeIn, CallbackInfo ci) { + this.radius = Math.max(sizeIn, 0F); } /** @@ -92,8 +92,8 @@ public abstract class ExplosionMixin implements ExplosionBridge { * @reason */ @Overwrite - public void doExplosionA() { - if (this.size < 0.1F) { + public void explode() { + if (this.radius < 0.1F) { return; } Set set = Sets.newHashSet(); @@ -110,21 +110,21 @@ public abstract class ExplosionMixin implements ExplosionBridge { d0 = d0 / d3; d1 = d1 / d3; d2 = d2 / d3; - float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F); + float f = this.radius * (0.7F + this.level.random.nextFloat() * 0.6F); double d4 = this.x; double d6 = this.y; double d8 = this.z; for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) { BlockPos blockpos = new BlockPos(d4, d6, d8); - BlockState blockstate = this.world.getBlockState(blockpos); - FluidState fluidstate = this.world.getFluidState(blockpos); - Optional optional = this.context.getExplosionResistance((Explosion) (Object) this, this.world, blockpos, blockstate, fluidstate); + BlockState blockstate = this.level.getBlockState(blockpos); + FluidState fluidstate = this.level.getFluidState(blockpos); + Optional optional = this.damageCalculator.getBlockExplosionResistance((Explosion) (Object) this, this.level, blockpos, blockstate, fluidstate); if (optional.isPresent()) { f -= (optional.get() + 0.3F) * 0.3F; } - if (f > 0.0F && this.context.canExplosionDestroyBlock((Explosion) (Object) this, this.world, blockpos, blockstate, f)) { + if (f > 0.0F && this.damageCalculator.shouldBlockExplode((Explosion) (Object) this, this.level, blockpos, blockstate, f)) { set.add(blockpos); } @@ -137,51 +137,51 @@ public abstract class ExplosionMixin implements ExplosionBridge { } } - this.affectedBlockPositions.addAll(set); - float f3 = this.size * 2.0F; - int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D); - int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D); - int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D); - int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D); - int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D); - int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D); - List list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1)); - net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, (Explosion) (Object) this, list, f3); - Vector3d vec3d = new Vector3d(this.x, this.y, this.z); + this.toBlow.addAll(set); + float f3 = this.radius * 2.0F; + int k1 = Mth.floor(this.x - (double) f3 - 1.0D); + int l1 = Mth.floor(this.x + (double) f3 + 1.0D); + int i2 = Mth.floor(this.y - (double) f3 - 1.0D); + int i1 = Mth.floor(this.y + (double) f3 + 1.0D); + int j2 = Mth.floor(this.z - (double) f3 - 1.0D); + int j1 = Mth.floor(this.z + (double) f3 + 1.0D); + List list = this.level.getEntities(this.source, new AABB(k1, i2, j2, l1, i1, j1)); + net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.level, (Explosion) (Object) this, list, f3); + Vec3 vec3d = new Vec3(this.x, this.y, this.z); for (Entity entity : list) { - if (!entity.isImmuneToExplosions()) { - double d12 = MathHelper.sqrt(entity.getDistanceSq(vec3d)) / f3; + if (!entity.ignoreExplosion()) { + double d12 = Mth.sqrt(entity.distanceToSqr(vec3d)) / f3; if (d12 <= 1.0D) { - double d5 = entity.getPosX() - this.x; - double d7 = entity.getPosYEye() - this.y; - double d9 = entity.getPosZ() - this.z; - double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9); + double d5 = entity.getX() - this.x; + double d7 = entity.getEyeY() - this.y; + double d9 = entity.getZ() - this.z; + double d13 = Mth.sqrt(d5 * d5 + d7 * d7 + d9 * d9); if (d13 != 0.0D) { d5 = d5 / d13; d7 = d7 / d13; d9 = d9 / d13; - double d14 = Explosion.getBlockDensity(vec3d, entity); + double d14 = Explosion.getSeenPercent(vec3d, entity); double d10 = (1.0D - d12) * d14; - CraftEventFactory.entityDamage = this.exploder; + CraftEventFactory.entityDamage = this.source; ((EntityBridge) entity).bridge$setForceExplosionKnockback(false); - boolean wasDamaged = entity.attackEntityFrom(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); + boolean wasDamaged = entity.hurt(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D))); CraftEventFactory.entityDamage = null; - if (!wasDamaged && !(entity instanceof TNTEntity || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) { + if (!wasDamaged && !(entity instanceof PrimedTnt || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) { continue; } double d11 = d10; if (entity instanceof LivingEntity) { - d11 = ProtectionEnchantment.getBlastDamageReduction((LivingEntity) entity, d10); + d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10); } - entity.setMotion(entity.getMotion().add(d5 * d11, d7 * d11, d9 * d11)); - if (entity instanceof PlayerEntity) { - PlayerEntity playerentity = (PlayerEntity) entity; - if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.isFlying)) { - this.playerKnockbackMap.put(playerentity, new Vector3d(d5 * d10, d7 * d10, d9 * d10)); + entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11)); + if (entity instanceof Player) { + Player playerentity = (Player) entity; + if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.flying)) { + this.hitPlayers.put(playerentity, new Vec3(d5 * d10, d7 * d10, d9 * d10)); } } } @@ -203,23 +203,23 @@ public abstract class ExplosionMixin implements ExplosionBridge { * @reason */ @Overwrite - public void doExplosionB(boolean spawnParticles) { - if (this.world.isRemote) { - this.world.playSound(this.x, this.y, this.z, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F, false); + public void finalizeExplosion(boolean spawnParticles) { + if (this.level.isClientSide) { + this.level.playLocalSound(this.x, this.y, this.z, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F, (1.0F + (this.level.random.nextFloat() - this.level.random.nextFloat()) * 0.2F) * 0.7F, false); } - boolean flag = this.mode != Explosion.Mode.NONE; + boolean flag = this.blockInteraction != Explosion.BlockInteraction.NONE; if (spawnParticles) { - if (!(this.size < 2.0F) && flag) { - this.world.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D); + if (!(this.radius < 2.0F) && flag) { + this.level.addParticle(ParticleTypes.EXPLOSION_EMITTER, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D); } else { - this.world.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D); + this.level.addParticle(ParticleTypes.EXPLOSION, this.x, this.y, this.z, 1.0D, 0.0D, 0.0D); } } if (flag) { ObjectArrayList> objectarraylist = new ObjectArrayList<>(); - Collections.shuffle(this.affectedBlockPositions, this.world.rand); + Collections.shuffle(this.toBlow, this.level.random); float yield = this.callBlockExplodeEvent(); @@ -228,58 +228,58 @@ public abstract class ExplosionMixin implements ExplosionBridge { return; } - for (BlockPos blockpos : this.affectedBlockPositions) { - BlockState blockstate = this.world.getBlockState(blockpos); + for (BlockPos blockpos : this.toBlow) { + BlockState blockstate = this.level.getBlockState(blockpos); Block block = blockstate.getBlock(); - if (!blockstate.isAir(this.world, blockpos)) { - BlockPos blockpos1 = blockpos.toImmutable(); - this.world.getProfiler().startSection("explosion_blocks"); - if (blockstate.canDropFromExplosion(this.world, blockpos, (Explosion) (Object) this) && this.world instanceof ServerWorld) { - TileEntity tileentity = blockstate.hasTileEntity() ? this.world.getTileEntity(blockpos) : null; - LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld)this.world)).withRandom(this.world.rand).withParameter(LootParameters.ORIGIN, Vector3d.copyCentered(blockpos)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, tileentity).withNullableParameter(LootParameters.THIS_ENTITY, this.exploder); - if (this.mode == Explosion.Mode.DESTROY || yield < 1.0F) { - lootcontext$builder.withParameter(LootParameters.EXPLOSION_RADIUS, 1.0F / yield); + if (!blockstate.isAir(this.level, blockpos)) { + BlockPos blockpos1 = blockpos.immutable(); + this.level.getProfiler().push("explosion_blocks"); + if (blockstate.canDropFromExplosion(this.level, blockpos, (Explosion) (Object) this) && this.level instanceof ServerLevel) { + BlockEntity tileentity = blockstate.hasTileEntity() ? this.level.getBlockEntity(blockpos) : null; + LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel)this.level)).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, this.source); + if (this.blockInteraction == Explosion.BlockInteraction.DESTROY || yield < 1.0F) { + lootcontext$builder.withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0F / yield); } blockstate.getDrops(lootcontext$builder).forEach((stack) -> { - handleExplosionDrops(objectarraylist, stack, blockpos1); + addBlockDrops(objectarraylist, stack, blockpos1); }); } - blockstate.onBlockExploded(this.world, blockpos, (Explosion) (Object) this); - this.world.getProfiler().endSection(); + blockstate.onBlockExploded(this.level, blockpos, (Explosion) (Object) this); + this.level.getProfiler().pop(); } } for (Pair pair : objectarraylist) { - Block.spawnAsEntity(this.world, pair.getSecond(), pair.getFirst()); + Block.popResource(this.level, pair.getSecond(), pair.getFirst()); } } - if (this.causesFire) { - for (BlockPos blockpos2 : this.affectedBlockPositions) { - if (this.random.nextInt(3) == 0 && this.world.getBlockState(blockpos2).isAir() && this.world.getBlockState(blockpos2.down()).isOpaqueCube(this.world, blockpos2.down())) { - BlockIgniteEvent event = CraftEventFactory.callBlockIgniteEvent(this.world, blockpos2.getX(), blockpos2.getY(), blockpos2.getZ(), (Explosion) (Object) this); + if (this.fire) { + for (BlockPos blockpos2 : this.toBlow) { + if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockpos2).isAir() && this.level.getBlockState(blockpos2.below()).isSolidRender(this.level, blockpos2.below())) { + BlockIgniteEvent event = CraftEventFactory.callBlockIgniteEvent(this.level, blockpos2.getX(), blockpos2.getY(), blockpos2.getZ(), (Explosion) (Object) this); if (!event.isCancelled()) { - this.world.setBlockState(blockpos2, AbstractFireBlock.getFireForPlacement(this.world, blockpos2)); + this.level.setBlockAndUpdate(blockpos2, BaseFireBlock.getState(this.level, blockpos2)); } } } } } - @Inject(method = "handleExplosionDrops", cancellable = true, at = @At("HEAD")) + @Inject(method = "addBlockDrops", cancellable = true, at = @At("HEAD")) private static void arclight$fix(ObjectArrayList> dropPositionArray, ItemStack stack, BlockPos pos, CallbackInfo ci) { if (stack.isEmpty()) ci.cancel(); } private float callBlockExplodeEvent() { - org.bukkit.World world = ((WorldBridge) this.world).bridge$getWorld(); - org.bukkit.entity.Entity exploder = this.exploder == null ? null : ((EntityBridge) this.exploder).bridge$getBukkitEntity(); + org.bukkit.World world = ((WorldBridge) this.level).bridge$getWorld(); + org.bukkit.entity.Entity exploder = this.source == null ? null : ((EntityBridge) this.source).bridge$getBukkitEntity(); Location location = new Location(world, this.x, this.y, this.z); List blockList = Lists.newArrayList(); - for (int i = this.affectedBlockPositions.size() - 1; i >= 0; i--) { - BlockPos blockPos = this.affectedBlockPositions.get(i); + for (int i = this.toBlow.size() - 1; i >= 0; i--) { + BlockPos blockPos = this.toBlow.get(i); org.bukkit.block.Block block = world.getBlockAt(blockPos.getX(), blockPos.getY(), blockPos.getZ()); if (!block.getType().isAir()) { blockList.add(block); @@ -291,24 +291,24 @@ public abstract class ExplosionMixin implements ExplosionBridge { float yield; if (exploder != null) { - EntityExplodeEvent event = new EntityExplodeEvent(exploder, location, blockList, this.mode == Explosion.Mode.DESTROY ? 1.0F / this.size : 1.0F); + EntityExplodeEvent event = new EntityExplodeEvent(exploder, location, blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY ? 1.0F / this.radius : 1.0F); Bukkit.getPluginManager().callEvent(event); cancelled = event.isCancelled(); bukkitBlocks = event.blockList(); yield = event.getYield(); } else { - BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.mode == Explosion.Mode.DESTROY ? 1.0F / this.size : 1.0F); + BlockExplodeEvent event = new BlockExplodeEvent(location.getBlock(), blockList, this.blockInteraction == Explosion.BlockInteraction.DESTROY ? 1.0F / this.radius : 1.0F); Bukkit.getPluginManager().callEvent(event); cancelled = event.isCancelled(); bukkitBlocks = event.blockList(); yield = event.getYield(); } - this.affectedBlockPositions.clear(); + this.toBlow.clear(); for (org.bukkit.block.Block block : bukkitBlocks) { BlockPos blockPos = new BlockPos(block.getX(), block.getY(), block.getZ()); - this.affectedBlockPositions.add(blockPos); + this.toBlow.add(blockPos); } return cancelled ? Float.NaN : yield; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IBlockReaderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IBlockReaderMixin.java index 8aefb7c2..142c5d5b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IBlockReaderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IBlockReaderMixin.java @@ -1,44 +1,44 @@ package io.izzel.arclight.common.mixin.core.world; import io.izzel.arclight.common.bridge.world.IBlockReaderBridge; -import net.minecraft.block.BlockState; -import net.minecraft.fluid.FluidState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.RayTraceContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.IBlockReader; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import javax.annotation.Nullable; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.VoxelShape; -@Mixin(IBlockReader.class) +@Mixin(BlockGetter.class) public interface IBlockReaderMixin extends IBlockReaderBridge { // @formatter:off @Shadow BlockState getBlockState(BlockPos pos); @Shadow FluidState getFluidState(BlockPos pos); - @Shadow @Nullable BlockRayTraceResult rayTraceBlocks(Vector3d startVec, Vector3d endVec, BlockPos pos, VoxelShape shape, BlockState state); + @Shadow @Nullable BlockHitResult clipWithInteractionOverride(Vec3 startVec, Vec3 endVec, BlockPos pos, VoxelShape shape, BlockState state); // @formatter:on - default BlockRayTraceResult rayTraceBlock(RayTraceContext context, BlockPos pos) { + default BlockHitResult rayTraceBlock(ClipContext context, BlockPos pos) { BlockState blockstate = this.getBlockState(pos); FluidState ifluidstate = this.getFluidState(pos); - Vector3d vec3d = context.getStartVec(); - Vector3d vec3d1 = context.getStartVec(); - VoxelShape voxelshape = context.getBlockShape(blockstate, (IBlockReader) this, pos); - BlockRayTraceResult blockraytraceresult = this.rayTraceBlocks(vec3d, vec3d1, pos, voxelshape, blockstate); - VoxelShape voxelshape1 = context.getFluidShape(ifluidstate, (IBlockReader) this, pos); - BlockRayTraceResult blockraytraceresult1 = voxelshape1.rayTrace(vec3d, vec3d1, pos); - double d0 = blockraytraceresult == null ? Double.MAX_VALUE : context.getStartVec().squareDistanceTo(blockraytraceresult.getHitVec()); - double d1 = blockraytraceresult1 == null ? Double.MAX_VALUE : context.getStartVec().squareDistanceTo(blockraytraceresult1.getHitVec()); + Vec3 vec3d = context.getFrom(); + Vec3 vec3d1 = context.getFrom(); + VoxelShape voxelshape = context.getBlockShape(blockstate, (BlockGetter) this, pos); + BlockHitResult blockraytraceresult = this.clipWithInteractionOverride(vec3d, vec3d1, pos, voxelshape, blockstate); + VoxelShape voxelshape1 = context.getFluidShape(ifluidstate, (BlockGetter) this, pos); + BlockHitResult blockraytraceresult1 = voxelshape1.clip(vec3d, vec3d1, pos); + double d0 = blockraytraceresult == null ? Double.MAX_VALUE : context.getFrom().distanceToSqr(blockraytraceresult.getLocation()); + double d1 = blockraytraceresult1 == null ? Double.MAX_VALUE : context.getFrom().distanceToSqr(blockraytraceresult1.getLocation()); return d0 <= d1 ? blockraytraceresult : blockraytraceresult1; } @Override - default BlockRayTraceResult bridge$rayTraceBlock(RayTraceContext context, BlockPos pos) { + default BlockHitResult bridge$rayTraceBlock(ClipContext context, BlockPos pos) { return rayTraceBlock(context, pos); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IServerWorldMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IServerWorldMixin.java index 67e1c191..11cd54c8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IServerWorldMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IServerWorldMixin.java @@ -1,27 +1,27 @@ package io.izzel.arclight.common.mixin.core.world; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.world.IServerWorld; -import net.minecraft.world.IWorld; -import net.minecraft.world.server.ServerWorld; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import java.util.Iterator; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.ServerLevelAccessor; -@Mixin(IServerWorld.class) -public interface IServerWorldMixin extends IWorld, ServerWorldBridge { +@Mixin(ServerLevelAccessor.class) +public interface IServerWorldMixin extends LevelAccessor, ServerWorldBridge { // @formatter:off - @Shadow ServerWorld getWorld(); + @Shadow ServerLevel getLevel(); // @formatter:on @Override - default ServerWorld bridge$getMinecraftWorld() { - return this.getWorld(); + default ServerLevel bridge$getMinecraftWorld() { + return this.getLevel(); } /** @@ -29,13 +29,13 @@ public interface IServerWorldMixin extends IWorld, ServerWorldBridge { * @reason */ @Overwrite - default void func_242417_l(Entity entity) { + default void addFreshEntityWithPassengers(Entity entity) { CreatureSpawnEvent.SpawnReason spawnReason = bridge$getAddEntityReason(); Iterator iterator = entity.getSelfAndPassengers().iterator(); while (iterator.hasNext()) { Entity next = iterator.next(); bridge$pushAddEntityReason(spawnReason); - this.addEntity(next); + this.addFreshEntity(next); } } @@ -44,7 +44,7 @@ public interface IServerWorldMixin extends IWorld, ServerWorldBridge { while (iterator.hasNext()) { Entity next = iterator.next(); bridge$pushAddEntityReason(reason); - this.addEntity(next); + this.addFreshEntity(next); } return !entity.removed; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldMixin.java index 69299ea0..03380696 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldMixin.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mixin.core.world; import io.izzel.arclight.common.bridge.world.IWorldBridge; -import net.minecraft.world.IWorld; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Mixin; -@Mixin(IWorld.class) +@Mixin(LevelAccessor.class) public interface IWorldMixin extends IWorldBridge { - default ServerWorld getMinecraftWorld() { + default ServerLevel getMinecraftWorld() { return this.bridge$getMinecraftWorld(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldWriterMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldWriterMixin.java index 8aed3353..7e1408e7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldWriterMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/IWorldWriterMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.core.world; import io.izzel.arclight.common.bridge.world.IWorldWriterBridge; -import net.minecraft.entity.Entity; -import net.minecraft.world.IWorldWriter; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.LevelWriter; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; -@Mixin(IWorldWriter.class) +@Mixin(LevelWriter.class) public interface IWorldWriterMixin extends IWorldWriterBridge { default boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TeleporterMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TeleporterMixin.java index 730c18de..fdf6188a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TeleporterMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TeleporterMixin.java @@ -3,13 +3,6 @@ package io.izzel.arclight.common.mixin.core.world; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.world.TeleporterBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.util.Direction; -import net.minecraft.util.TeleportationRepositioner; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.Teleporter; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.craftbukkit.v.util.BlockStateListPopulator; @@ -27,34 +20,41 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import net.minecraft.BlockUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.portal.PortalForcer; -@Mixin(Teleporter.class) +@Mixin(PortalForcer.class) public abstract class TeleporterMixin implements TeleporterBridge { // @formatter:off - @Shadow public abstract Optional makePortal(BlockPos pos, Direction.Axis axis); - @Shadow @Final protected ServerWorld world; - @Shadow public abstract Optional getExistingPortal(BlockPos pos, boolean isNether); + @Shadow public abstract Optional createPortal(BlockPos pos, Direction.Axis axis); + @Shadow @Final protected ServerLevel level; + @Shadow public abstract Optional findPortalAround(BlockPos pos, boolean isNether); // @formatter:on - @ModifyVariable(method = "getExistingPortal", index = 4, at = @At(value = "INVOKE", target = "Lnet/minecraft/village/PointOfInterestManager;ensureLoadedAndValid(Lnet/minecraft/world/IWorldReader;Lnet/minecraft/util/math/BlockPos;I)V")) + @ModifyVariable(method = "findPortalAround", index = 4, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/village/poi/PoiManager;ensureLoadedAndValid(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;I)V")) private int arclight$useSearchRadius(int i) { return this.arclight$searchRadius == -1 ? i : this.arclight$searchRadius; } private transient int arclight$searchRadius = -1; - public Optional findPortal(BlockPos pos, int searchRadius) { + public Optional findPortal(BlockPos pos, int searchRadius) { this.arclight$searchRadius = searchRadius; try { - return this.getExistingPortal(pos, false); + return this.findPortalAround(pos, false); } finally { this.arclight$searchRadius = -1; } } @Override - public Optional bridge$findPortal(BlockPos pos, int searchRadius) { + public Optional bridge$findPortal(BlockPos pos, int searchRadius) { return findPortal(pos, searchRadius); } @@ -63,26 +63,26 @@ public abstract class TeleporterMixin implements TeleporterBridge { return this.arclight$createRadius == -1 ? i : this.arclight$createRadius; } - @Redirect(method = "makePortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private boolean arclight$captureBlocks1(ServerWorld serverWorld, BlockPos pos, BlockState state) { + @Redirect(method = "createPortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$captureBlocks1(ServerLevel serverWorld, BlockPos pos, BlockState state) { if (this.arclight$populator == null) { this.arclight$populator = new BlockStateListPopulator(serverWorld); } - return this.arclight$populator.setBlockState(pos, state, 3); + return this.arclight$populator.setBlock(pos, state, 3); } - @Redirect(method = "makePortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private boolean arclight$captureBlocks2(ServerWorld serverWorld, BlockPos pos, BlockState state, int flags) { + @Redirect(method = "createPortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private boolean arclight$captureBlocks2(ServerLevel serverWorld, BlockPos pos, BlockState state, int flags) { if (this.arclight$populator == null) { this.arclight$populator = new BlockStateListPopulator(serverWorld); } - return this.arclight$populator.setBlockState(pos, state, flags); + return this.arclight$populator.setBlock(pos, state, flags); } @SuppressWarnings({"unchecked", "rawtypes"}) - @Inject(method = "makePortal", cancellable = true, at = @At("RETURN")) - private void arclight$portalCreate(BlockPos pos, Direction.Axis axis, CallbackInfoReturnable> cir) { - CraftWorld craftWorld = ((WorldBridge) this.world).bridge$getWorld(); + @Inject(method = "createPortal", cancellable = true, at = @At("RETURN")) + private void arclight$portalCreate(BlockPos pos, Direction.Axis axis, CallbackInfoReturnable> cir) { + CraftWorld craftWorld = ((WorldBridge) this.level).bridge$getWorld(); List blockStates; if (this.arclight$populator == null) { blockStates = new ArrayList<>(); @@ -105,11 +105,11 @@ public abstract class TeleporterMixin implements TeleporterBridge { private transient Entity arclight$entity; private transient int arclight$createRadius = -1; - public Optional createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius) { + public Optional createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius) { this.arclight$entity = entity; this.arclight$createRadius = createRadius; try { - return this.makePortal(pos, axis); + return this.createPortal(pos, axis); } finally { this.arclight$entity = null; this.arclight$createRadius = -1; @@ -117,7 +117,7 @@ public abstract class TeleporterMixin implements TeleporterBridge { } @Override - public Optional bridge$createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius) { + public Optional bridge$createPortal(BlockPos pos, Direction.Axis axis, Entity entity, int createRadius) { return createPortal(pos, axis, entity, createRadius); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TrackedEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TrackedEntityMixin.java index 5ea2d952..05102fe1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TrackedEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/TrackedEntityMixin.java @@ -4,35 +4,6 @@ import com.google.common.collect.Lists; import com.mojang.datafixers.util.Pair; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.TrackedEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance; -import net.minecraft.entity.item.ItemFrameEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.AbstractArrowEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.FilledMapItem; -import net.minecraft.item.ItemStack; -import net.minecraft.network.IPacket; -import net.minecraft.network.datasync.EntityDataManager; -import net.minecraft.network.play.server.SEntityEquipmentPacket; -import net.minecraft.network.play.server.SEntityHeadLookPacket; -import net.minecraft.network.play.server.SEntityMetadataPacket; -import net.minecraft.network.play.server.SEntityPacket; -import net.minecraft.network.play.server.SEntityPropertiesPacket; -import net.minecraft.network.play.server.SEntityTeleportPacket; -import net.minecraft.network.play.server.SEntityVelocityPacket; -import net.minecraft.network.play.server.SMountEntityPacket; -import net.minecraft.network.play.server.SPlayEntityEffectPacket; -import net.minecraft.network.play.server.SSetPassengersPacket; -import net.minecraft.network.play.server.SSpawnMobPacket; -import net.minecraft.potion.EffectInstance; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.world.TrackedEntity; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.MapData; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerVelocityEvent; @@ -52,51 +23,80 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.function.Consumer; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundAddMobPacket; +import net.minecraft.network.protocol.game.ClientboundMoveEntityPacket; +import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; +import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; +import net.minecraft.network.protocol.game.ClientboundSetPassengersPacket; +import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.server.level.ServerEntity; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.decoration.ItemFrame; +import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.MapItem; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; +import net.minecraft.world.phys.Vec3; -@Mixin(TrackedEntity.class) +@Mixin(ServerEntity.class) public abstract class TrackedEntityMixin implements TrackedEntityBridge { // @formatter:off - @Shadow @Final private Entity trackedEntity; - @Shadow private List passengers; - @Shadow @Final private Consumer> packetConsumer; - @Shadow private int updateCounter; - @Shadow @Final private ServerWorld world; - @Shadow protected abstract void sendMetadata(); - @Shadow @Final private int updateFrequency; - @Shadow private int encodedRotationYaw; - @Shadow private int encodedRotationPitch; - @Shadow protected abstract void updateEncodedPosition(); - @Shadow private boolean riding; - @Shadow private int ticksSinceAbsoluteTeleport; - @Shadow private long encodedPosX; - @Shadow private long encodedPosY; - @Shadow private long encodedPosZ; - @Shadow private boolean onGround; - @Shadow @Final private boolean sendVelocityUpdates; - @Shadow private Vector3d velocity; - @Shadow private int encodedRotationYawHead; - @Shadow protected abstract void sendPacket(IPacket packet); + @Shadow @Final private Entity entity; + @Shadow private List lastPassengers; + @Shadow @Final private Consumer> broadcast; + @Shadow private int tickCount; + @Shadow @Final private ServerLevel level; + @Shadow protected abstract void sendDirtyEntityData(); + @Shadow @Final private int updateInterval; + @Shadow private int yRotp; + @Shadow private int xRotp; + @Shadow protected abstract void updateSentPos(); + @Shadow private boolean wasRiding; + @Shadow private int teleportDelay; + @Shadow private long xp; + @Shadow private long yp; + @Shadow private long zp; + @Shadow private boolean wasOnGround; + @Shadow @Final private boolean trackDelta; + @Shadow private Vec3 ap; + @Shadow private int yHeadRotp; + @Shadow protected abstract void broadcastAndSend(Packet packet); // @formatter:on - private Set trackedPlayers; + private Set trackedPlayers; @Inject(method = "", at = @At("RETURN")) - private void arclight$init(ServerWorld serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer, CallbackInfo ci) { + private void arclight$init(ServerLevel serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer, CallbackInfo ci) { trackedPlayers = new HashSet<>(); } - public void arclight$constructor(ServerWorld serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer) { + public void arclight$constructor(ServerLevel serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer) { throw new NullPointerException(); } - public void arclight$constructor(ServerWorld serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer, Set set) { + public void arclight$constructor(ServerLevel serverWorld, Entity entity, int updateFrequency, boolean sendVelocityUpdates, Consumer> packetConsumer, Set set) { arclight$constructor(serverWorld, entity, updateFrequency, sendVelocityUpdates, packetConsumer); this.trackedPlayers = set; } @Override - public void bridge$setTrackedPlayers(Set trackedPlayers) { + public void bridge$setTrackedPlayers(Set trackedPlayers) { this.trackedPlayers = trackedPlayers; } @@ -105,103 +105,103 @@ public abstract class TrackedEntityMixin implements TrackedEntityBridge { * @reason */ @Overwrite - public void tick() { - List list = this.trackedEntity.getPassengers(); - if (!list.equals(this.passengers)) { - this.passengers = list; - this.sendPacket(new SSetPassengersPacket(this.trackedEntity)); + public void sendChanges() { + List list = this.entity.getPassengers(); + if (!list.equals(this.lastPassengers)) { + this.lastPassengers = list; + this.broadcastAndSend(new ClientboundSetPassengersPacket(this.entity)); } - if (this.trackedEntity instanceof ItemFrameEntity) { - ItemFrameEntity itemframeentity = (ItemFrameEntity) this.trackedEntity; - ItemStack itemstack = itemframeentity.getDisplayedItem(); - MapData mapdata = FilledMapItem.getMapData(itemstack, this.world); - if (this.updateCounter % 10 == 0 && mapdata != null && itemstack.getItem() instanceof FilledMapItem) { - for (ServerPlayerEntity serverplayerentity : this.trackedPlayers) { - mapdata.updateVisiblePlayers(serverplayerentity, itemstack); - IPacket ipacket = ((FilledMapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.world, serverplayerentity); + if (this.entity instanceof ItemFrame) { + ItemFrame itemframeentity = (ItemFrame) this.entity; + ItemStack itemstack = itemframeentity.getItem(); + MapItemSavedData mapdata = MapItem.getOrCreateSavedData(itemstack, this.level); + if (this.tickCount % 10 == 0 && mapdata != null && itemstack.getItem() instanceof MapItem) { + for (ServerPlayer serverplayerentity : this.trackedPlayers) { + mapdata.tickCarriedBy(serverplayerentity, itemstack); + Packet ipacket = ((MapItem) itemstack.getItem()).getUpdatePacket(itemstack, this.level, serverplayerentity); if (ipacket != null) { - serverplayerentity.connection.sendPacket(ipacket); + serverplayerentity.connection.send(ipacket); } } } - this.sendMetadata(); + this.sendDirtyEntityData(); } - if (this.updateCounter % this.updateFrequency == 0 || this.trackedEntity.isAirBorne || this.trackedEntity.getDataManager().isDirty()) { - if (this.trackedEntity.isPassenger()) { - int i1 = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0F / 360.0F); - int l1 = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0F / 360.0F); - boolean flag2 = Math.abs(i1 - this.encodedRotationYaw) >= 1 || Math.abs(l1 - this.encodedRotationPitch) >= 1; + if (this.tickCount % this.updateInterval == 0 || this.entity.hasImpulse || this.entity.getEntityData().isDirty()) { + if (this.entity.isPassenger()) { + int i1 = Mth.floor(this.entity.yRot * 256.0F / 360.0F); + int l1 = Mth.floor(this.entity.xRot * 256.0F / 360.0F); + boolean flag2 = Math.abs(i1 - this.yRotp) >= 1 || Math.abs(l1 - this.xRotp) >= 1; if (flag2) { - this.packetConsumer.accept(new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) i1, (byte) l1, this.trackedEntity.isOnGround())); - this.encodedRotationYaw = i1; - this.encodedRotationPitch = l1; + this.broadcast.accept(new ClientboundMoveEntityPacket.Rot(this.entity.getId(), (byte) i1, (byte) l1, this.entity.isOnGround())); + this.yRotp = i1; + this.xRotp = l1; } - this.updateEncodedPosition(); - this.sendMetadata(); - this.riding = true; + this.updateSentPos(); + this.sendDirtyEntityData(); + this.wasRiding = true; } else { - ++this.ticksSinceAbsoluteTeleport; - int l = MathHelper.floor(this.trackedEntity.rotationYaw * 256.0F / 360.0F); - int k1 = MathHelper.floor(this.trackedEntity.rotationPitch * 256.0F / 360.0F); - Vector3d vector3d = this.trackedEntity.getPositionVec().subtract(SEntityPacket.decodePosition(this.encodedPosX, this.encodedPosY, this.encodedPosZ)); - boolean flag3 = vector3d.lengthSquared() >= (double) 7.6293945E-6F; - IPacket ipacket1 = null; - boolean flag4 = flag3 || this.updateCounter % 60 == 0; - boolean flag = Math.abs(l - this.encodedRotationYaw) >= 1 || Math.abs(k1 - this.encodedRotationPitch) >= 1; + ++this.teleportDelay; + int l = Mth.floor(this.entity.yRot * 256.0F / 360.0F); + int k1 = Mth.floor(this.entity.xRot * 256.0F / 360.0F); + Vec3 vector3d = this.entity.position().subtract(ClientboundMoveEntityPacket.packetToEntity(this.xp, this.yp, this.zp)); + boolean flag3 = vector3d.lengthSqr() >= (double) 7.6293945E-6F; + Packet ipacket1 = null; + boolean flag4 = flag3 || this.tickCount % 60 == 0; + boolean flag = Math.abs(l - this.yRotp) >= 1 || Math.abs(k1 - this.xRotp) >= 1; if (flag4) { - this.updateEncodedPosition(); + this.updateSentPos(); } if (flag) { - this.encodedRotationYaw = l; - this.encodedRotationPitch = k1; + this.yRotp = l; + this.xRotp = k1; } - if (this.updateCounter > 0 || this.trackedEntity instanceof AbstractArrowEntity) { - long i = SEntityPacket.func_218743_a(vector3d.x); - long j = SEntityPacket.func_218743_a(vector3d.y); - long k = SEntityPacket.func_218743_a(vector3d.z); + if (this.tickCount > 0 || this.entity instanceof AbstractArrow) { + long i = ClientboundMoveEntityPacket.entityToPacket(vector3d.x); + long j = ClientboundMoveEntityPacket.entityToPacket(vector3d.y); + long k = ClientboundMoveEntityPacket.entityToPacket(vector3d.z); boolean flag1 = i < -32768L || i > 32767L || j < -32768L || j > 32767L || k < -32768L || k > 32767L; - if (!flag1 && this.ticksSinceAbsoluteTeleport <= 400 && !this.riding && this.onGround == this.trackedEntity.isOnGround()) { - if ((!flag4 || !flag) && !(this.trackedEntity instanceof AbstractArrowEntity)) { + if (!flag1 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.isOnGround()) { + if ((!flag4 || !flag) && !(this.entity instanceof AbstractArrow)) { if (flag4) { - ipacket1 = new SEntityPacket.RelativeMovePacket(this.trackedEntity.getEntityId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), this.trackedEntity.isOnGround()); + ipacket1 = new ClientboundMoveEntityPacket.Pos(this.entity.getId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), this.entity.isOnGround()); } else if (flag) { - ipacket1 = new SEntityPacket.LookPacket(this.trackedEntity.getEntityId(), (byte) l, (byte) k1, this.trackedEntity.isOnGround()); + ipacket1 = new ClientboundMoveEntityPacket.Rot(this.entity.getId(), (byte) l, (byte) k1, this.entity.isOnGround()); } } else { - ipacket1 = new SEntityPacket.MovePacket(this.trackedEntity.getEntityId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), (byte) l, (byte) k1, this.trackedEntity.isOnGround()); + ipacket1 = new ClientboundMoveEntityPacket.PosRot(this.entity.getId(), (short) ((int) i), (short) ((int) j), (short) ((int) k), (byte) l, (byte) k1, this.entity.isOnGround()); } } else { - this.onGround = this.trackedEntity.isOnGround(); - this.ticksSinceAbsoluteTeleport = 0; - ipacket1 = new SEntityTeleportPacket(this.trackedEntity); + this.wasOnGround = this.entity.isOnGround(); + this.teleportDelay = 0; + ipacket1 = new ClientboundTeleportEntityPacket(this.entity); } } - if ((this.sendVelocityUpdates || this.trackedEntity.isAirBorne || this.trackedEntity instanceof LivingEntity && ((LivingEntity) this.trackedEntity).isElytraFlying()) && this.updateCounter > 0) { - Vector3d vector3d1 = this.trackedEntity.getMotion(); - double d0 = vector3d1.squareDistanceTo(this.velocity); - if (d0 > 1.0E-7D || d0 > 0.0D && vector3d1.lengthSquared() == 0.0D) { - this.velocity = vector3d1; - this.packetConsumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity)); + if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) { + Vec3 vector3d1 = this.entity.getDeltaMovement(); + double d0 = vector3d1.distanceToSqr(this.ap); + if (d0 > 1.0E-7D || d0 > 0.0D && vector3d1.lengthSqr() == 0.0D) { + this.ap = vector3d1; + this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap)); } } if (ipacket1 != null) { - this.packetConsumer.accept(ipacket1); + this.broadcast.accept(ipacket1); } - this.sendMetadata(); - this.riding = false; + this.sendDirtyEntityData(); + this.wasRiding = false; } - int j1 = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F); - if (Math.abs(j1 - this.encodedRotationYawHead) >= 1) { - this.packetConsumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) j1)); - this.encodedRotationYawHead = j1; + int j1 = Mth.floor(this.entity.getYHeadRot() * 256.0F / 360.0F); + if (Math.abs(j1 - this.yHeadRotp) >= 1) { + this.broadcast.accept(new ClientboundRotateHeadPacket(this.entity, (byte) j1)); + this.yHeadRotp = j1; } - this.trackedEntity.isAirBorne = false; + this.entity.hasImpulse = false; } - ++this.updateCounter; - if (this.trackedEntity.velocityChanged) { + ++this.tickCount; + if (this.entity.hurtMarked) { boolean cancelled = false; - if (this.trackedEntity instanceof ServerPlayerEntity) { - Player player = ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity(); + if (this.entity instanceof ServerPlayer) { + Player player = ((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity(); Vector velocity = player.getVelocity(); PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); Bukkit.getPluginManager().callEvent(event); @@ -212,22 +212,22 @@ public abstract class TrackedEntityMixin implements TrackedEntityBridge { } } if (!cancelled) { - this.sendPacket(new SEntityVelocityPacket(this.trackedEntity)); + this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity)); } - this.trackedEntity.velocityChanged = false; + this.entity.hurtMarked = false; } } - @Inject(method = "track", at = @At("HEAD")) - private void arclight$addPlayer(ServerPlayerEntity player, CallbackInfo ci) { + @Inject(method = "addPairing", at = @At("HEAD")) + private void arclight$addPlayer(ServerPlayer player, CallbackInfo ci) { this.arclight$player = player; } - private transient ServerPlayerEntity arclight$player; + private transient ServerPlayer arclight$player; - public void a(final Consumer> consumer, ServerPlayerEntity playerEntity) { + public void a(final Consumer> consumer, ServerPlayer playerEntity) { this.arclight$player = playerEntity; - this.sendSpawnPackets(consumer); + this.sendPairingData(consumer); } /** @@ -235,70 +235,70 @@ public abstract class TrackedEntityMixin implements TrackedEntityBridge { * @reason */ @Overwrite - public void sendSpawnPackets(final Consumer> consumer) { - ServerPlayerEntity player = arclight$player; + public void sendPairingData(final Consumer> consumer) { + ServerPlayer player = arclight$player; arclight$player = null; - MobEntity entityinsentient; - if (this.trackedEntity.removed) { + Mob entityinsentient; + if (this.entity.removed) { return; } - IPacket packet = this.trackedEntity.createSpawnPacket(); - this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f); + Packet packet = this.entity.getAddEntityPacket(); + this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0f / 360.0f); consumer.accept(packet); - if (!this.trackedEntity.getDataManager().isEmpty()) { - consumer.accept(new SEntityMetadataPacket(this.trackedEntity.getEntityId(), this.trackedEntity.getDataManager(), true)); + if (!this.entity.getEntityData().isEmpty()) { + consumer.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), this.entity.getEntityData(), true)); } - boolean flag = this.sendVelocityUpdates; - if (this.trackedEntity instanceof LivingEntity) { - Collection collection = ((LivingEntity) this.trackedEntity).getAttributeManager().getWatchedInstances(); - if (this.trackedEntity.getEntityId() == player.getEntityId()) { - ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false); + boolean flag = this.trackDelta; + if (this.entity instanceof LivingEntity) { + Collection collection = ((LivingEntity) this.entity).getAttributes().getSyncableAttributes(); + if (this.entity.getId() == player.getId()) { + ((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity().injectScaledMaxHealth(collection, false); } if (!collection.isEmpty()) { - consumer.accept(new SEntityPropertiesPacket(this.trackedEntity.getEntityId(), collection)); + consumer.accept(new ClientboundUpdateAttributesPacket(this.entity.getId(), collection)); } - if (((LivingEntity) this.trackedEntity).isElytraFlying()) { + if (((LivingEntity) this.entity).isFallFlying()) { flag = true; } } - this.velocity = this.trackedEntity.getMotion(); - if (flag && !(packet instanceof SSpawnMobPacket)) { - consumer.accept(new SEntityVelocityPacket(this.trackedEntity.getEntityId(), this.velocity)); + this.ap = this.entity.getDeltaMovement(); + if (flag && !(packet instanceof ClientboundAddMobPacket)) { + consumer.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap)); } - if (this.trackedEntity instanceof LivingEntity) { - ArrayList> list = Lists.newArrayList(); - for (EquipmentSlotType enumitemslot : EquipmentSlotType.values()) { - ItemStack itemstack = ((LivingEntity) this.trackedEntity).getItemStackFromSlot(enumitemslot); + if (this.entity instanceof LivingEntity) { + ArrayList> list = Lists.newArrayList(); + for (EquipmentSlot enumitemslot : EquipmentSlot.values()) { + ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot); if (itemstack.isEmpty()) continue; list.add(Pair.of(enumitemslot, itemstack.copy())); } if (!list.isEmpty()) { - consumer.accept(new SEntityEquipmentPacket(this.trackedEntity.getEntityId(), list)); + consumer.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list)); } } - this.encodedRotationYawHead = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0f / 360.0f); - consumer.accept(new SEntityHeadLookPacket(this.trackedEntity, (byte) this.encodedRotationYawHead)); - if (this.trackedEntity instanceof LivingEntity) { - LivingEntity entityliving = (LivingEntity) this.trackedEntity; - for (EffectInstance mobeffect : entityliving.getActivePotionEffects()) { - consumer.accept(new SPlayEntityEffectPacket(this.trackedEntity.getEntityId(), mobeffect)); + this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0f / 360.0f); + consumer.accept(new ClientboundRotateHeadPacket(this.entity, (byte) this.yHeadRotp)); + if (this.entity instanceof LivingEntity) { + LivingEntity entityliving = (LivingEntity) this.entity; + for (MobEffectInstance mobeffect : entityliving.getActiveEffects()) { + consumer.accept(new ClientboundUpdateMobEffectPacket(this.entity.getId(), mobeffect)); } } - if (!this.trackedEntity.getPassengers().isEmpty()) { - consumer.accept(new SSetPassengersPacket(this.trackedEntity)); + if (!this.entity.getPassengers().isEmpty()) { + consumer.accept(new ClientboundSetPassengersPacket(this.entity)); } - if (this.trackedEntity.isPassenger()) { - consumer.accept(new SSetPassengersPacket(this.trackedEntity.getRidingEntity())); + if (this.entity.isPassenger()) { + consumer.accept(new ClientboundSetPassengersPacket(this.entity.getVehicle())); } - if (this.trackedEntity instanceof MobEntity && (entityinsentient = (MobEntity) this.trackedEntity).getLeashed()) { - consumer.accept(new SMountEntityPacket(entityinsentient, entityinsentient.getLeashHolder())); + if (this.entity instanceof Mob && (entityinsentient = (Mob) this.entity).isLeashed()) { + consumer.accept(new ClientboundSetEntityLinkPacket(entityinsentient, entityinsentient.getLeashHolder())); } } - @Inject(method = "sendMetadata", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/TrackedEntity;sendPacket(Lnet/minecraft/network/IPacket;)V")) - private void arclight$sendScaledHealth(CallbackInfo ci, EntityDataManager entitydatamanager, Set set) { - if (this.trackedEntity instanceof ServerPlayerEntity) { - ((ServerPlayerEntityBridge) this.trackedEntity).bridge$getBukkitEntity().injectScaledMaxHealth(set, false); + @Inject(method = "sendDirtyEntityData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerEntity;broadcastAndSend(Lnet/minecraft/network/protocol/Packet;)V")) + private void arclight$sendScaledHealth(CallbackInfo ci, SynchedEntityData entitydatamanager, Set set) { + if (this.entity instanceof ServerPlayer) { + ((ServerPlayerEntityBridge) this.entity).bridge$getBukkitEntity().injectScaledMaxHealth(set, false); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/WorldMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/WorldMixin.java index 804f58d7..115fc245 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/WorldMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/WorldMixin.java @@ -7,25 +7,25 @@ import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.server.ArclightServer; import io.izzel.arclight.common.mod.server.world.WrappedWorlds; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.profiler.IProfiler; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.DimensionType; -import net.minecraft.world.IWorld; -import net.minecraft.world.IWorldWriter; -import net.minecraft.world.World; -import net.minecraft.world.border.WorldBorder; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.IServerWorldInfo; -import net.minecraft.world.storage.ISpawnWorldInfo; -import net.minecraft.world.storage.IWorldInfo; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelWriter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.border.WorldBorder; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.level.storage.ServerLevelData; +import net.minecraft.world.level.storage.WritableLevelData; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.CraftWorld; @@ -52,24 +52,24 @@ import java.lang.reflect.Field; import java.util.Optional; import java.util.function.Supplier; -@Mixin(World.class) -public abstract class WorldMixin implements WorldBridge, IWorldWriter { +@Mixin(Level.class) +public abstract class WorldMixin implements WorldBridge, LevelWriter { // @formatter:off - @Shadow @Nullable public TileEntity getTileEntity(BlockPos pos) { return null; } + @Shadow @Nullable public BlockEntity getBlockEntity(BlockPos pos) { return null; } @Shadow public abstract BlockState getBlockState(BlockPos pos); - @Shadow public abstract void setTileEntity(BlockPos pos, @Nullable TileEntity tileEntityIn); + @Shadow public abstract void setBlockEntity(BlockPos pos, @Nullable BlockEntity tileEntityIn); @Shadow public abstract WorldBorder getWorldBorder(); @Shadow @Final private WorldBorder worldBorder; @Shadow public abstract long getDayTime(); @Shadow public abstract MinecraftServer shadow$getServer(); @Shadow @Final private DimensionType dimensionType; - @Shadow public abstract IWorldInfo getWorldInfo(); - @Shadow public abstract RegistryKey getDimensionKey(); - @Accessor("mainThread") public abstract Thread arclight$getMainThread(); + @Shadow public abstract LevelData getLevelData(); + @Shadow public abstract ResourceKey dimension(); + @Accessor("thread") public abstract Thread arclight$getMainThread(); // @formatter:on - private RegistryKey typeKey; + private ResourceKey typeKey; protected CraftWorld world; public boolean pvpMode; public boolean keepSpawnInMemory = true; @@ -85,30 +85,30 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { @SuppressWarnings("unused") // Access transformed to public by ArclightMixinPlugin private static BlockPos lastPhysicsProblem; // Spigot - public void arclight$constructor(ISpawnWorldInfo worldInfo, RegistryKey dimension, final DimensionType dimensionType, Supplier profiler, boolean isRemote, boolean isDebug, long seed) { + public void arclight$constructor(WritableLevelData worldInfo, ResourceKey dimension, final DimensionType dimensionType, Supplier profiler, boolean isRemote, boolean isDebug, long seed) { throw new RuntimeException(); } - public void arclight$constructor(ISpawnWorldInfo worldInfo, RegistryKey dimension, final DimensionType dimensionType, Supplier profiler, boolean isRemote, boolean isDebug, long seed, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) { + public void arclight$constructor(WritableLevelData worldInfo, ResourceKey dimension, final DimensionType dimensionType, Supplier profiler, boolean isRemote, boolean isDebug, long seed, org.bukkit.generator.ChunkGenerator gen, org.bukkit.World.Environment env) { arclight$constructor(worldInfo, dimension, dimensionType, profiler, isRemote, isDebug, seed); this.generator = gen; this.environment = env; bridge$getWorld(); } - @Inject(method = "(Lnet/minecraft/world/storage/ISpawnWorldInfo;Lnet/minecraft/util/RegistryKey;Lnet/minecraft/world/DimensionType;Ljava/util/function/Supplier;ZZJ)V", at = @At("RETURN")) - private void arclight$init(ISpawnWorldInfo info, RegistryKey dimension, DimensionType dimType, Supplier profiler, boolean isRemote, boolean isDebug, long seed, CallbackInfo ci) { - this.spigotConfig = new SpigotWorldConfig(((IServerWorldInfo) info).getWorldName()); - ((WorldBorderBridge) this.worldBorder).bridge$setWorld((World) (Object) this); + @Inject(method = "(Lnet/minecraft/world/level/storage/WritableLevelData;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/DimensionType;Ljava/util/function/Supplier;ZZJ)V", at = @At("RETURN")) + private void arclight$init(WritableLevelData info, ResourceKey dimension, DimensionType dimType, Supplier profiler, boolean isRemote, boolean isDebug, long seed, CallbackInfo ci) { + this.spigotConfig = new SpigotWorldConfig(((ServerLevelData) info).getLevelName()); + ((WorldBorderBridge) this.worldBorder).bridge$setWorld((Level) (Object) this); this.ticksPerAnimalSpawns = this.getServer().getTicksPerAnimalSpawns(); this.ticksPerMonsterSpawns = this.getServer().getTicksPerMonsterSpawns(); this.ticksPerWaterSpawns = this.getServer().getTicksPerWaterSpawns(); this.ticksPerWaterAmbientSpawns = this.getServer().getTicksPerWaterAmbientSpawns(); this.ticksPerAmbientSpawns = this.getServer().getTicksPerAmbientSpawns(); - this.typeKey = this.getServer().getHandle().getServer().getDynamicRegistries().func_230520_a_().getOptionalKey(dimensionType) + this.typeKey = this.getServer().getHandle().getServer().registryAccess().dimensionTypes().getResourceKey(dimensionType) .orElseGet(() -> { - Registry registry = this.getServer().getHandle().getServer().getDynamicRegistries().func_230520_a_(); - RegistryKey typeRegistryKey = RegistryKey.getOrCreateKey(registry.getRegistryKey(), dimension.getLocation()); + Registry registry = this.getServer().getHandle().getServer().registryAccess().dimensionTypes(); + ResourceKey typeRegistryKey = ResourceKey.create(registry.key(), dimension.location()); ArclightMod.LOGGER.warn("Assign {} to unknown dimension type {} as {}", typeRegistryKey, dimType); return typeRegistryKey; }); @@ -139,12 +139,12 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { return ticksPerWaterAmbientSpawns; } - public RegistryKey getTypeKey() { + public ResourceKey getTypeKey() { return this.typeKey; } @Override - public RegistryKey bridge$getTypeKey() { + public ResourceKey bridge$getTypeKey() { return getTypeKey(); } @@ -153,7 +153,7 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { return this.spigotConfig; } - @Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", + @Inject(method = "setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z", at = @At("HEAD"), cancellable = true) private void arclight$hooks(BlockPos pos, BlockState newState, int flags, CallbackInfoReturnable cir) { if (!processCaptures(pos, newState, flags)) { @@ -171,11 +171,11 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { return true; } - @Inject(method = "markAndNotifyBlock", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;updateNeighbours(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;II)V")) - private void arclight$callBlockPhysics(BlockPos pos, Chunk chunk, BlockState blockstate, BlockState state, int flags, int recursionLeft, CallbackInfo ci) { + @Inject(method = "markAndNotifyBlock", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;updateNeighbours(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;II)V")) + private void arclight$callBlockPhysics(BlockPos pos, LevelChunk chunk, BlockState blockstate, BlockState state, int flags, int recursionLeft, CallbackInfo ci) { try { if (this.world != null) { - BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at((IWorld) this, pos), CraftBlockData.fromData(state)); + BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at((LevelAccessor) this, pos), CraftBlockData.fromData(state)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { ci.cancel(); @@ -187,12 +187,12 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { } @Inject(method = "neighborChanged", cancellable = true, - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;neighborChanged(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;Lnet/minecraft/util/math/BlockPos;Z)V"), + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;neighborChanged(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;Lnet/minecraft/core/BlockPos;Z)V"), locals = LocalCapture.CAPTURE_FAILHARD) private void arclight$callBlockPhysics2(BlockPos pos, Block blockIn, BlockPos fromPos, CallbackInfo ci, BlockState blockState) { try { if (this.world != null) { - IWorld iWorld = (IWorld) this; + LevelAccessor iWorld = (LevelAccessor) this; BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(iWorld, pos), CraftBlockData.fromData(blockState), CraftBlock.at(iWorld, fromPos)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -219,28 +219,28 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { } } if (generator == null) { - generator = getServer().getGenerator(((IServerWorldInfo) this.getWorldInfo()).getWorldName()); - if (generator != null && (Object) this instanceof ServerWorld) { - ServerWorld serverWorld = (ServerWorld) (Object) this; - CustomChunkGenerator gen = new CustomChunkGenerator(serverWorld, serverWorld.getChunkProvider().getChunkGenerator(), generator); - ((ServerChunkProviderBridge) serverWorld.getChunkProvider()).bridge$setChunkGenerator(gen); + generator = getServer().getGenerator(((ServerLevelData) this.getLevelData()).getLevelName()); + if (generator != null && (Object) this instanceof ServerLevel) { + ServerLevel serverWorld = (ServerLevel) (Object) this; + CustomChunkGenerator gen = new CustomChunkGenerator(serverWorld, serverWorld.getChunkSource().getGenerator(), generator); + ((ServerChunkProviderBridge) serverWorld.getChunkSource()).bridge$setChunkGenerator(gen); } } if (environment == null) { environment = ArclightServer.getEnvironment(this.typeKey); } - this.world = new CraftWorld((ServerWorld) (Object) this, generator, environment); + this.world = new CraftWorld((ServerLevel) (Object) this, generator, environment); getServer().addWorld(this.world); } return this.world; } - public TileEntity getTileEntity(BlockPos pos, boolean validate) { - return getTileEntity(pos); + public BlockEntity getTileEntity(BlockPos pos, boolean validate) { + return getBlockEntity(pos); } @Override - public TileEntity bridge$getTileEntity(BlockPos pos, boolean validate) { + public BlockEntity bridge$getTileEntity(BlockPos pos, boolean validate) { return getTileEntity(pos, validate); } @@ -280,7 +280,7 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { } @Override - public ServerWorld bridge$getMinecraftWorld() { + public ServerLevel bridge$getMinecraftWorld() { return getWorld().getHandle(); } @@ -290,7 +290,7 @@ public abstract class WorldMixin implements WorldBridge, IWorldWriter { return ((WorldBridge) getWorld().getHandle()).bridge$addEntity(entity, reason); } else { this.bridge$pushAddEntityReason(reason); - return this.addEntity(entity); + return this.addFreshEntity(entity); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/biome/BiomeContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/biome/BiomeContainerMixin.java index 3b1170cf..178a1a15 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/biome/BiomeContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/biome/BiomeContainerMixin.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mixin.core.world.biome; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.BiomeContainer; +import net.minecraft.util.Mth; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.chunk.ChunkBiomeContainer; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(BiomeContainer.class) +@Mixin(ChunkBiomeContainer.class) public class BiomeContainerMixin { // @formatter:off @@ -16,9 +16,9 @@ public class BiomeContainerMixin { // @formatter:on public void setBiome(int i, int j, int k, Biome biome) { - int l = i & BiomeContainer.HORIZONTAL_MASK; - int i2 = MathHelper.clamp(j, 0, BiomeContainer.VERTICAL_MASK); - int j2 = k & BiomeContainer.HORIZONTAL_MASK; + int l = i & ChunkBiomeContainer.HORIZONTAL_MASK; + int i2 = Mth.clamp(j, 0, ChunkBiomeContainer.VERTICAL_MASK); + int j2 = k & ChunkBiomeContainer.HORIZONTAL_MASK; this.biomes[i2 << WIDTH_BITS + WIDTH_BITS | j2 << WIDTH_BITS | l] = biome; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/border/WorldBorderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/border/WorldBorderMixin.java index 6e0bfa71..c5e29a3c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/border/WorldBorderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/border/WorldBorderMixin.java @@ -1,22 +1,22 @@ package io.izzel.arclight.common.mixin.core.world.border; import io.izzel.arclight.common.bridge.world.border.WorldBorderBridge; -import net.minecraft.world.border.WorldBorder; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.border.WorldBorder; import org.spongepowered.asm.mixin.Mixin; @Mixin(WorldBorder.class) public class WorldBorderMixin implements WorldBorderBridge { - public World world; + public Level world; @Override - public World bridge$getWorld() { + public Level bridge$getWorld() { return this.world; } @Override - public void bridge$setWorld(World world) { + public void bridge$setWorld(Level world) { this.world = world; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/ChunkMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/ChunkMixin.java index ac394632..fcab3bf1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/ChunkMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/ChunkMixin.java @@ -2,21 +2,6 @@ package io.izzel.arclight.common.mixin.core.world.chunk; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.fluid.Fluid; -import net.minecraft.util.ClassInheritanceMultiMap; -import net.minecraft.util.math.BlockPos; -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.ChunkPrimer; -import net.minecraft.world.chunk.ChunkSection; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftChunk; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; @@ -32,41 +17,56 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.ClassInstanceMultiMap; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.TickList; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkBiomeContainer; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.chunk.ProtoChunk; +import net.minecraft.world.level.chunk.UpgradeData; +import net.minecraft.world.level.material.Fluid; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; -@Mixin(Chunk.class) +@Mixin(LevelChunk.class) public abstract class ChunkMixin implements ChunkBridge { // @formatter:off @Shadow @Nullable public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean isMoving); - @Shadow @Final public World world; - @Shadow @Final private ChunkPos pos; - @Shadow private volatile boolean dirty; - @Shadow private boolean hasEntities; + @Shadow @Final public Level level; + @Shadow @Final private ChunkPos chunkPos; + @Shadow private volatile boolean unsaved; + @Shadow private boolean lastSaveHadEntities; @Shadow private long lastSaveTime; - @Shadow @Final public ClassInheritanceMultiMap[] entityLists; + @Shadow @Final public ClassInstanceMultiMap[] entitySections; // @formatter:on public org.bukkit.Chunk bukkitChunk; public boolean mustNotSave; public boolean needsDecoration; private transient boolean arclight$doPlace; - public ServerWorld $$world; + public ServerLevel $$world; private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); public final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); - @Inject(method = "(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 tickBlocksIn, ITickList tickFluidsIn, long inhabitedTimeIn, ChunkSection[] sectionsIn, Consumer postLoadConsumerIn, CallbackInfo ci) { - this.$$world = ((ServerWorld) worldIn); - bridge$setBukkitChunk(new CraftChunk((Chunk) (Object) this)); + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/chunk/ChunkBiomeContainer;Lnet/minecraft/world/level/chunk/UpgradeData;Lnet/minecraft/world/level/TickList;Lnet/minecraft/world/level/TickList;J[Lnet/minecraft/world/level/chunk/LevelChunkSection;Ljava/util/function/Consumer;)V", at = @At("RETURN")) + private void arclight$init(Level worldIn, ChunkPos chunkPosIn, ChunkBiomeContainer biomeContainerIn, UpgradeData upgradeDataIn, TickList tickBlocksIn, TickList tickFluidsIn, long inhabitedTimeIn, LevelChunkSection[] sectionsIn, Consumer postLoadConsumerIn, CallbackInfo ci) { + this.$$world = ((ServerLevel) worldIn); + bridge$setBukkitChunk(new CraftChunk((LevelChunk) (Object) this)); } @SuppressWarnings("unchecked") public List[] getEntitySlices() { - return Arrays.stream(this.entityLists).map(ClassInheritanceMultiMap::func_241289_a_).toArray(List[]::new); + return Arrays.stream(this.entitySections).map(ClassInstanceMultiMap::getAllInstances).toArray(List[]::new); } public org.bukkit.Chunk getBukkitChunk() { @@ -140,20 +140,20 @@ public abstract class ChunkMixin implements ChunkBridge { if (this.needsDecoration) { this.needsDecoration = false; java.util.Random random = new java.util.Random(); - random.setSeed(((ServerWorld) world).getSeed()); + random.setSeed(((ServerLevel) level).getSeed()); long xRand = random.nextLong() / 2L * 2L + 1L; long zRand = random.nextLong() / 2L * 2L + 1L; - random.setSeed((long) this.pos.x * xRand + (long) this.pos.z * zRand ^ ((ServerWorld) world).getSeed()); + random.setSeed((long) this.chunkPos.x * xRand + (long) this.chunkPos.z * zRand ^ ((ServerLevel) level).getSeed()); - org.bukkit.World world = ((WorldBridge) this.world).bridge$getWorld(); + org.bukkit.World world = ((WorldBridge) this.level).bridge$getWorld(); if (world != null) { - ((WorldBridge) this.world).bridge$setPopulating(true); + ((WorldBridge) this.level).bridge$setPopulating(true); try { for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) { populator.populate(world, random, bukkitChunk); } } finally { - ((WorldBridge) this.world).bridge$setPopulating(false); + ((WorldBridge) this.level).bridge$setPopulating(false); } } server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk)); @@ -163,21 +163,21 @@ public abstract class ChunkMixin implements ChunkBridge { public void unloadCallback() { org.bukkit.Server server = Bukkit.getServer(); - org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(this.bukkitChunk, this.isModified()); + org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(this.bukkitChunk, this.isUnsaved()); server.getPluginManager().callEvent(unloadEvent); // note: saving can be prevented, but not forced if no saving is actually required this.mustNotSave = !unloadEvent.isSaveChunk(); } - @Inject(method = "(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/ChunkPrimer;)V", + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/chunk/ProtoChunk;)V", at = @At("RETURN")) - public void arclight$setNeedsDecoration(World worldIn, ChunkPrimer primer, CallbackInfo ci) { + public void arclight$setNeedsDecoration(Level worldIn, ProtoChunk primer, CallbackInfo ci) { this.needsDecoration = true; } - @Redirect(method = "setBlockState", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/World;isRemote:Z")) - public boolean arclight$redirectIsRemote(World world) { - return world.isRemote && this.arclight$doPlace; + @Redirect(method = "setBlockState", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/level/Level;isClientSide:Z")) + public boolean arclight$redirectIsRemote(Level world) { + return world.isClientSide && this.arclight$doPlace; } /** @@ -185,7 +185,7 @@ public abstract class ChunkMixin implements ChunkBridge { * @reason */ @Overwrite - public boolean isModified() { - return !this.mustNotSave && (this.dirty || this.hasEntities && this.world.getGameTime() != this.lastSaveTime); + public boolean isUnsaved() { + return !this.mustNotSave && (this.unsaved || this.lastSaveHadEntities && this.level.getGameTime() != this.lastSaveTime); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/ChunkLoaderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/ChunkLoaderMixin.java index 9d8c5ab6..8638f6d3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/ChunkLoaderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/ChunkLoaderMixin.java @@ -1,39 +1,39 @@ package io.izzel.arclight.common.mixin.core.world.chunk.storage; import com.google.common.collect.ImmutableList; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.DimensionType; -import net.minecraft.world.World; -import net.minecraft.world.chunk.storage.ChunkLoader; -import net.minecraft.world.gen.feature.structure.LegacyStructureDataUtil; -import net.minecraft.world.storage.DimensionSavedDataManager; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import javax.annotation.Nullable; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.chunk.storage.ChunkStorage; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.levelgen.structure.LegacyStructureDataHandler; +import net.minecraft.world.level.storage.DimensionDataStorage; import java.util.List; -@Mixin(ChunkLoader.class) +@Mixin(ChunkStorage.class) public abstract class ChunkLoaderMixin { - @Redirect(method = "func_235968_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/feature/structure/LegacyStructureDataUtil;func_236992_a_(Lnet/minecraft/util/RegistryKey;Lnet/minecraft/world/storage/DimensionSavedDataManager;)Lnet/minecraft/world/gen/feature/structure/LegacyStructureDataUtil;")) - private LegacyStructureDataUtil arclight$legacyData(RegistryKey p_236992_0_, DimensionSavedDataManager p_236992_1_) { + @Redirect(method = "upgradeChunkTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/LegacyStructureDataHandler;getLegacyStructureHandler(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/storage/DimensionDataStorage;)Lnet/minecraft/world/level/levelgen/structure/LegacyStructureDataHandler;")) + private LegacyStructureDataHandler arclight$legacyData(ResourceKey p_236992_0_, DimensionDataStorage p_236992_1_) { return legacyDataOf(p_236992_0_, p_236992_1_); } /** - * From {@link LegacyStructureDataUtil#func_236992_a_(RegistryKey, DimensionSavedDataManager)} + * From {@link LegacyStructureDataHandler#getLegacyStructureHandler(ResourceKey, DimensionDataStorage)} */ - private static LegacyStructureDataUtil legacyDataOf(RegistryKey typeKey, @Nullable DimensionSavedDataManager dataManager) { - if (typeKey == DimensionType.OVERWORLD || typeKey == World.OVERWORLD) { - return new LegacyStructureDataUtil(dataManager, ImmutableList.of("Monument", "Stronghold", "Village", "Mineshaft", "Temple", "Mansion"), ImmutableList.of("Village", "Mineshaft", "Mansion", "Igloo", "Desert_Pyramid", "Jungle_Pyramid", "Swamp_Hut", "Stronghold", "Monument")); - } else if (typeKey == DimensionType.THE_NETHER || typeKey == World.THE_NETHER) { + private static LegacyStructureDataHandler legacyDataOf(ResourceKey typeKey, @Nullable DimensionDataStorage dataManager) { + if (typeKey == DimensionType.OVERWORLD_LOCATION || typeKey == Level.OVERWORLD) { + return new LegacyStructureDataHandler(dataManager, ImmutableList.of("Monument", "Stronghold", "Village", "Mineshaft", "Temple", "Mansion"), ImmutableList.of("Village", "Mineshaft", "Mansion", "Igloo", "Desert_Pyramid", "Jungle_Pyramid", "Swamp_Hut", "Stronghold", "Monument")); + } else if (typeKey == DimensionType.NETHER_LOCATION || typeKey == Level.NETHER) { List list1 = ImmutableList.of("Fortress"); - return new LegacyStructureDataUtil(dataManager, list1, list1); - } else if (typeKey == DimensionType.THE_END || typeKey == World.THE_END) { + return new LegacyStructureDataHandler(dataManager, list1, list1); + } else if (typeKey == DimensionType.END_LOCATION || typeKey == Level.END) { List list = ImmutableList.of("EndCity"); - return new LegacyStructureDataUtil(dataManager, list, list); + return new LegacyStructureDataHandler(dataManager, list, list); } else { throw new RuntimeException(String.format("Unknown dimension type : %s", typeKey)); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/RegionFileCacheMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/RegionFileCacheMixin.java index 31c169a3..c27d2927 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/RegionFileCacheMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/chunk/storage/RegionFileCacheMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.chunk.storage; import io.izzel.arclight.common.bridge.world.chunk.storage.RegionFileCacheBridge; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.chunk.storage.RegionFile; -import net.minecraft.world.chunk.storage.RegionFileCache; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -15,47 +11,51 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.io.File; import java.io.IOException; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.storage.RegionFile; +import net.minecraft.world.level.chunk.storage.RegionFileStorage; -@Mixin(RegionFileCache.class) +@Mixin(RegionFileStorage.class) public abstract class RegionFileCacheMixin implements RegionFileCacheBridge { // @formatter:off - @Shadow protected abstract RegionFile loadFile(ChunkPos pos) throws IOException; + @Shadow protected abstract RegionFile getRegionFile(ChunkPos pos) throws IOException; // @formatter:on private RegionFile loadFile(ChunkPos pos, boolean existsOnly) throws IOException { this.arclight$existOnly = existsOnly; - return loadFile(pos); + return getRegionFile(pos); } private transient boolean arclight$existOnly; - @Inject(method = "loadFile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "NEW", target = "net/minecraft/world/chunk/storage/RegionFile")) + @Inject(method = "getRegionFile", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "NEW", target = "net/minecraft/world/level/chunk/storage/RegionFile")) private void arclight$retIfSearch(ChunkPos pos, CallbackInfoReturnable cir, long l, File file) { if (arclight$existOnly && !file.exists()) cir.setReturnValue(null); } - @Inject(method = "readChunk", at = @At("HEAD")) - private void arclight$read(ChunkPos pos, CallbackInfoReturnable cir) { + @Inject(method = "read", at = @At("HEAD")) + private void arclight$read(ChunkPos pos, CallbackInfoReturnable cir) { this.arclight$existOnly = true; } - @Inject(method = "readChunk", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/storage/RegionFile;func_222666_a(Lnet/minecraft/util/math/ChunkPos;)Ljava/io/DataInputStream;")) - private void arclight$retIfNotFound(ChunkPos pos, CallbackInfoReturnable cir, RegionFile rf) { + @Inject(method = "read", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/storage/RegionFile;getChunkDataInputStream(Lnet/minecraft/world/level/ChunkPos;)Ljava/io/DataInputStream;")) + private void arclight$retIfNotFound(ChunkPos pos, CallbackInfoReturnable cir, RegionFile rf) { if (rf == null) { cir.setReturnValue(null); } } - @Inject(method = "writeChunk", at = @At("HEAD")) - private void arclight$write(ChunkPos pos, CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "write", at = @At("HEAD")) + private void arclight$write(ChunkPos pos, CompoundTag compound, CallbackInfo ci) { this.arclight$existOnly = false; } public boolean chunkExists(ChunkPos pos) throws IOException { RegionFile regionFile = loadFile(pos, true); - return regionFile != null && regionFile.contains(pos); + return regionFile != null && regionFile.hasChunk(pos); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AgeableMobMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AgeableMobMixin.java new file mode 100644 index 00000000..b6b85556 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AgeableMobMixin.java @@ -0,0 +1,47 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import io.izzel.arclight.common.bridge.entity.AgeableEntityBridge; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.AgeableMob; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; + +@Mixin(AgeableMob.class) +public abstract class AgeableMobMixin extends PathfinderMobMixin implements AgeableEntityBridge { + + // @formatter:off + @Shadow public abstract boolean isBaby(); + @Shadow @Nullable public abstract AgeableMob getBreedOffspring(ServerLevel world, AgeableMob mate); + @Shadow public abstract void setAge(int age); + // @formatter:on + + public boolean ageLocked; + + @Inject(method = "addAdditionalSaveData", at = @At("RETURN")) + private void arclight$writeAgeLocked(CompoundTag compound, CallbackInfo ci) { + compound.putBoolean("AgeLocked", ageLocked); + } + + @Inject(method = "readAdditionalSaveData", at = @At("RETURN")) + private void arclight$readAgeLocked(CompoundTag compound, CallbackInfo ci) { + ageLocked = compound.getBoolean("AgeLocked"); + } + + @Redirect(method = "aiStep", at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/Level;isClientSide:Z")) + private boolean arclight$tickIfNotLocked(Level world) { + return world.isClientSide || ageLocked; + } + + @Override + public boolean bridge$isAgeLocked() { + return this.ageLocked; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java new file mode 100644 index 00000000..3c8028bf --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java @@ -0,0 +1,225 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import com.google.common.collect.Lists; +import io.izzel.arclight.common.bridge.entity.AreaEffectCloudEntityBridge; +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import net.minecraft.core.Registry; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.AreaEffectCloud; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; +import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.AreaEffectCloudApplyEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Map; + +@Mixin(AreaEffectCloud.class) +@Implements(@Interface(iface = AreaEffectCloudEntityBridge.Hack.class, prefix = "hack$")) +public abstract class AreaEffectCloudEntityMixin extends EntityMixin implements AreaEffectCloudEntityBridge { + + // @formatter:off + @Shadow private boolean fixedColor; + @Shadow @Final private static EntityDataAccessor DATA_COLOR; + @Shadow public List effects; + @Shadow private Potion potion; + @Shadow public abstract void setPotion(Potion potionIn); + @Shadow public abstract boolean isWaiting(); + @Shadow public abstract float getRadius(); + @Shadow public abstract ParticleOptions getParticle(); + @Shadow public abstract int getColor(); + @Shadow public int waitTime; + @Shadow private int duration; + @Shadow protected abstract void setWaiting(boolean ignoreRadius); + @Shadow public float radiusPerTick; + @Shadow public abstract void setRadius(float radiusIn); + @Shadow @Final private Map victims; + @Shadow public int reapplicationDelay; + @Shadow @Nullable public abstract LivingEntity getOwner(); + @Shadow public float radiusOnUse; + @Shadow public int durationOnUse; + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void tick() { + super.tick(); + boolean flag = this.isWaiting(); + float f = this.getRadius(); + if (this.level.isClientSide) { + if (flag && this.random.nextBoolean()) { + return; + } + + ParticleOptions particleoptions = this.getParticle(); + int i; + float f1; + if (flag) { + i = 2; + f1 = 0.2F; + } else { + i = Mth.ceil((float) Math.PI * f * f); + f1 = f; + } + + for (int j = 0; j < i; ++j) { + float f2 = this.random.nextFloat() * ((float) Math.PI * 2F); + float f3 = Mth.sqrt(this.random.nextFloat()) * f1; + double d0 = this.getX() + (double) (Mth.cos(f2) * f3); + double d2 = this.getY(); + double d4 = this.getZ() + (double) (Mth.sin(f2) * f3); + double d5; + double d6; + double d7; + if (particleoptions.getType() != ParticleTypes.ENTITY_EFFECT) { + if (flag) { + d5 = 0.0D; + d6 = 0.0D; + d7 = 0.0D; + } else { + d5 = (0.5D - this.random.nextDouble()) * 0.15D; + d6 = 0.01F; + d7 = (0.5D - this.random.nextDouble()) * 0.15D; + } + } else { + int k = flag && this.random.nextBoolean() ? 16777215 : this.getColor(); + d5 = (float) (k >> 16 & 255) / 255.0F; + d6 = (float) (k >> 8 & 255) / 255.0F; + d7 = (float) (k & 255) / 255.0F; + } + + this.level.addAlwaysVisibleParticle(particleoptions, d0, d2, d4, d5, d6, d7); + } + } else { + if (this.tickCount >= this.waitTime + this.duration) { + this.discard(); + return; + } + + boolean flag1 = this.tickCount < this.waitTime; + if (flag != flag1) { + this.setWaiting(flag1); + } + + if (flag1) { + return; + } + + if (this.radiusPerTick != 0.0F) { + f += this.radiusPerTick; + if (f < 0.5F) { + this.discard(); + return; + } + + this.setRadius(f); + } + + if (this.tickCount % 5 == 0) { + this.victims.entrySet().removeIf((p_146784_) -> { + return this.tickCount >= p_146784_.getValue(); + }); + List list = Lists.newArrayList(); + + for (MobEffectInstance mobeffectinstance : this.potion.getEffects()) { + list.add(new MobEffectInstance(mobeffectinstance.getEffect(), mobeffectinstance.getDuration() / 4, mobeffectinstance.getAmplifier(), mobeffectinstance.isAmbient(), mobeffectinstance.isVisible())); + } + + list.addAll(this.effects); + if (list.isEmpty()) { + this.victims.clear(); + } else { + List list1 = this.level.getEntitiesOfClass(LivingEntity.class, this.getBoundingBox()); + if (!list1.isEmpty()) { + List entities = new java.util.ArrayList(); // CraftBukkit + for (LivingEntity livingentity : list1) { + if (!this.victims.containsKey(livingentity) && livingentity.isAffectedByPotions()) { + double d8 = livingentity.getX() - this.getX(); + double d1 = livingentity.getZ() - this.getZ(); + double d3 = d8 * d8 + d1 * d1; + if (d3 <= (double) (f * f)) { + entities.add(((LivingEntityBridge) livingentity).bridge$getBukkitEntity()); + } + } + } + AreaEffectCloudApplyEvent event = CraftEventFactory.callAreaEffectCloudApplyEvent((AreaEffectCloud) (Object) this, entities); + if (!event.isCancelled()) { + for (org.bukkit.entity.LivingEntity entity : event.getAffectedEntities()) { + if (entity instanceof CraftLivingEntity) { + net.minecraft.world.entity.LivingEntity livingentity = ((CraftLivingEntity) entity).getHandle(); + + this.victims.put(livingentity, this.tickCount + this.reapplicationDelay); + + for (MobEffectInstance mobeffectinstance1 : list) { + if (mobeffectinstance1.getEffect().isInstantenous()) { + mobeffectinstance1.getEffect().applyInstantenousEffect((AreaEffectCloud) (Object) this, this.getOwner(), livingentity, mobeffectinstance1.getAmplifier(), 0.5D); + } else { + livingentity.addEffect(new MobEffectInstance(mobeffectinstance1), (AreaEffectCloud) (Object) this); + } + } + + if (this.radiusOnUse != 0.0F) { + f += this.radiusOnUse; + if (f < 0.5F) { + this.discard(); + return; + } + + this.setRadius(f); + } + + if (this.durationOnUse != 0) { + this.duration += this.durationOnUse; + if (this.duration <= 0) { + this.discard(); + return; + } + } + } + } + } + } + } + } + } + + } + + + public void refreshEffects() { + if (!this.fixedColor) { + this.getEntityData().set(DATA_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects))); + } + } + + public String hack$getType() { + return Registry.POTION.getKey(this.potion).toString(); + } + + public void hack$setType(final String string) { + this.setPotion(Registry.POTION.get(new ResourceLocation(string))); + } + + @Override + public void bridge$refreshEffects() { + refreshEffects(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java similarity index 59% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java index 3de4efd5..82957819 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/EntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java @@ -1,5 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity; +package io.izzel.arclight.common.mixin.core.world.entity; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; import io.izzel.arclight.common.bridge.block.PortalInfoBridge; import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; import io.izzel.arclight.common.bridge.entity.EntityBridge; @@ -10,42 +12,43 @@ import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.TeleporterBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.BlockState; -import net.minecraft.block.PortalInfo; -import net.minecraft.block.PortalSize; -import net.minecraft.command.CommandSource; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntitySize; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.Pose; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.network.datasync.EntityDataManager; -import net.minecraft.scoreboard.Team; +import net.minecraft.BlockUtil; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.TeleportationRepositioner; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.DimensionType; -import net.minecraft.world.World; -import net.minecraft.world.border.WorldBorder; -import net.minecraft.world.gen.Heightmap; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.util.Mth; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.Pose; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.border.WorldBorder; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.portal.PortalInfo; +import net.minecraft.world.level.portal.PortalShape; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.scores.Team; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -97,106 +100,109 @@ import java.util.UUID; public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, ICommandSourceBridge { // @formatter:off - @Shadow public float rotationYaw; - @Shadow public World world; - @Shadow protected int rideCooldown; - @Shadow public float rotationPitch; - @Shadow public int fire; + @Shadow public float yRot; + @Shadow public Level level; + @Shadow protected int boardingCooldown; + @Shadow public float xRot; + @Shadow public int remainingFireTicks; @Shadow public abstract Pose getPose(); @Shadow public abstract String getScoreboardName(); - @Shadow protected abstract void updatePortal(); - @Shadow public abstract boolean isImmuneToFire(); - @Shadow public abstract boolean attackEntityFrom(DamageSource source, float amount); - @Shadow public abstract void setFire(int seconds); - @Shadow public boolean collidedHorizontally; - @Shadow protected abstract Vector3d getAllowedMovement(Vector3d vec); - @Shadow public abstract void remove(); - @Shadow public int ticksExisted; - @Shadow public void setWorld(World worldIn) { } - @Shadow private Entity ridingEntity; - @Shadow @Final public List passengers; + @Shadow protected abstract void handleNetherPortal(); + @Shadow public abstract boolean fireImmune(); + @Shadow public abstract boolean hurt(DamageSource source, float amount); + @Shadow public abstract void setSecondsOnFire(int seconds); + @Shadow public boolean horizontalCollision; + @Shadow protected abstract Vec3 collide(Vec3 vec); + @Shadow public int tickCount; + @Shadow private Entity vehicle; @Shadow @Nullable public abstract Entity getControllingPassenger(); @Shadow public abstract boolean isSwimming(); @Shadow public abstract boolean isAlive(); - @Shadow public abstract void detach(); - @Shadow @Final protected EntityDataManager dataManager; - @Shadow @Final private static DataParameter AIR; - @Shadow @Deprecated public boolean removed; + @Shadow public abstract void unRide(); + @Shadow @Final protected SynchedEntityData entityData; + @Shadow @Final private static EntityDataAccessor DATA_AIR_SUPPLY_ID; @Shadow @Nullable public abstract MinecraftServer getServer(); - @Shadow public abstract Vector3d getMotion(); + @Shadow public abstract Vec3 getDeltaMovement(); @Shadow public abstract EntityType getType(); @Shadow(remap = false) public void remove(boolean keepData) { } - @Shadow @Final protected Random rand; - @Shadow public abstract float getWidth(); - @Shadow public abstract float getHeight(); + @Shadow @Final protected Random random; + @Shadow public abstract float getBbWidth(); + @Shadow public abstract float getBbHeight(); @Shadow public abstract boolean isInvisible(); @Shadow public abstract boolean isInvulnerableTo(DamageSource source); - @Shadow public int hurtResistantTime; + @Shadow public int invulnerableTime; @Shadow public abstract void playSound(SoundEvent soundIn, float volume, float pitch); - @Shadow public abstract void setPositionAndUpdate(double x, double y, double z); - @Shadow @Nullable public abstract ItemEntity entityDropItem(ItemStack stack); - @Shadow public abstract EntityDataManager getDataManager(); + @Shadow public abstract void teleportTo(double x, double y, double z); + @Shadow @Nullable public abstract ItemEntity spawnAtLocation(ItemStack stack); + @Shadow public abstract SynchedEntityData getEntityData(); @Shadow public void tick() {} - @Shadow public abstract AxisAlignedBB getBoundingBox(); + @Shadow public abstract AABB getBoundingBox(); @Shadow(remap = false) public abstract Collection captureDrops(); @Shadow(remap = false) public abstract Collection captureDrops(Collection value); - @Shadow public abstract BlockPos getPosition(); + @Shadow public abstract BlockPos blockPosition(); @Shadow protected boolean onGround; @Shadow public abstract boolean isInWater(); @Shadow public abstract boolean isPassenger(); @Shadow public float fallDistance; @Shadow public abstract boolean isSprinting(); - @Shadow public float distanceWalkedModified; - @Shadow public float prevDistanceWalkedModified; - @Shadow public abstract boolean isOnSameTeam(Entity entityIn); - @Shadow public abstract void setMotion(Vector3d motionIn); - @Shadow public abstract double getDistanceSq(Entity entityIn); - @Shadow protected UUID entityUniqueID; - @Shadow protected abstract void markVelocityChanged(); - @Shadow public abstract void removePassengers(); + @Shadow public float walkDist; + @Shadow public float walkDistO; + @Shadow public abstract boolean isAlliedTo(Entity entityIn); + @Shadow public abstract void setDeltaMovement(Vec3 motionIn); + @Shadow public abstract double distanceToSqr(Entity entityIn); + @Shadow protected UUID uuid; + @Shadow protected abstract void markHurt(); + @Shadow public abstract void ejectPassengers(); @Shadow public abstract boolean hasCustomName(); @Shadow protected abstract void outOfWorld(); - @Shadow public abstract void setPosition(double x, double y, double z); - @Shadow protected abstract void setRotation(float yaw, float pitch); - @Shadow public double prevPosX; - @Shadow public double prevPosY; - @Shadow public double prevPosZ; - @Shadow public abstract boolean hasNoGravity(); - @Shadow protected abstract void doBlockCollisions(); - @Shadow public float prevRotationYaw; - @Shadow public abstract boolean isBeingRidden(); - @Shadow public abstract boolean isPassenger(Entity entityIn); - @Shadow public abstract void setMotion(double x, double y, double z); - @Shadow public abstract void move(MoverType typeIn, Vector3d pos); - @Shadow @Nullable public abstract Entity getRidingEntity(); + @Shadow public abstract void setPos(double x, double y, double z); + @Shadow protected abstract void setRot(float yaw, float pitch); + @Shadow public double xo; + @Shadow public double yo; + @Shadow public double zo; + @Shadow public abstract boolean isNoGravity(); + @Shadow protected abstract void checkInsideBlocks(); + @Shadow public float yRotO; + @Shadow public abstract boolean isVehicle(); + @Shadow public abstract boolean hasPassenger(Entity entityIn); + @Shadow public abstract void setDeltaMovement(double x, double y, double z); + @Shadow public abstract void move(MoverType typeIn, Vec3 pos); + @Shadow @Nullable public abstract Entity getVehicle(); @Shadow @Nullable public abstract Team getTeam(); - @Shadow public abstract void extinguish(); - @Shadow public abstract void setFlag(int flag, boolean set); - @Shadow public abstract void setLocationAndAngles(double x, double y, double z, float yaw, float pitch); - @Shadow public abstract int getEntityId(); - @Shadow @Nullable public abstract ITextComponent getCustomName(); - @Shadow public abstract void applyEnchantments(LivingEntity entityLivingBaseIn, Entity entityIn); - @Shadow @Nullable public abstract Entity changeDimension(ServerWorld world); - @Shadow public abstract boolean isRidingSameEntity(Entity entityIn); + @Shadow public abstract void clearFire(); + @Shadow public abstract void setSharedFlag(int flag, boolean set); + @Shadow public abstract void moveTo(double x, double y, double z, float yaw, float pitch); + @Shadow public abstract int getId(); + @Shadow @Nullable public abstract Component getCustomName(); + @Shadow public abstract void doEnchantDamageEffects(LivingEntity entityLivingBaseIn, Entity entityIn); + @Shadow @Nullable public abstract Entity changeDimension(ServerLevel world); + @Shadow public abstract boolean isPassengerOfSameVehicle(Entity entityIn); @Shadow public abstract boolean isInvulnerable(); - @Shadow public abstract double getPosX(); - @Shadow public abstract double getPosZ(); - @Shadow public abstract double getPosY(); - @Shadow public abstract double getPosYEye(); - @Shadow public abstract Vector3d getPositionVec(); + @Shadow public abstract double getX(); + @Shadow public abstract double getZ(); + @Shadow public abstract double getY(); + @Shadow public abstract double getEyeY(); + @Shadow public abstract Vec3 position(); @Shadow(remap = false) public abstract void revive(); - @Shadow public abstract boolean canBePushed(); - @Shadow protected abstract void setDead(); - @Shadow protected abstract Optional func_241830_a(ServerWorld p_241830_1_, BlockPos p_241830_2_, boolean p_241830_3_); - @Shadow protected BlockPos entityBlockPosition; - @Shadow protected abstract Vector3d func_241839_a(Direction.Axis axis, TeleportationRepositioner.Result result); - @Shadow public abstract EntitySize getSize(Pose poseIn); - @Shadow protected abstract boolean func_233566_aG_(); + @Shadow public abstract boolean isPushable(); + @Shadow protected abstract void removeAfterChangingDimensions(); + @Shadow protected abstract Optional getExitPortal(ServerLevel p_241830_1_, BlockPos p_241830_2_, boolean p_241830_3_); + @Shadow protected BlockPos portalEntrancePos; + @Shadow protected abstract Vec3 getRelativePortalPosition(Direction.Axis axis, BlockUtil.FoundRectangle result); + @Shadow public abstract EntityDimensions getDimensions(Pose poseIn); + @Shadow protected abstract boolean updateInWaterStateAndDoFluidPushing(); @Shadow public abstract boolean isInLava(); - @Shadow protected abstract void setOnFireFromLava(); - @Shadow protected boolean firstUpdate; + @Shadow public abstract void lavaHurt(); + @Shadow protected boolean firstTick; @Shadow public abstract boolean isSilent(); @Shadow public abstract void setInvisible(boolean invisible); + @Shadow public ImmutableList passengers; + @Shadow public abstract boolean isRemoved(); + @Shadow public abstract void remove(Entity.RemovalReason p_146834_); + @Shadow public abstract void discard(); + @Shadow protected abstract void unsetRemoved(); + @Shadow public abstract double getY(double p_20228_); + @Shadow public abstract void gameEvent(GameEvent p_146853_, @org.jetbrains.annotations.Nullable Entity p_146854_); // @formatter:on private static final int CURRENT_LEVEL = 2; @@ -213,7 +219,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } @Override - public CommandSender bridge$getBukkitSender(CommandSource wrapper) { + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { return internal$getBukkitEntity(); } @@ -236,7 +242,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } public float getBukkitYaw() { - return rotationYaw; + return yRot; } @Override @@ -245,7 +251,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } public boolean isChunkLoaded() { - return world.chunkExists((int) Math.floor(getPosX()) >> 4, (int) Math.floor(getPosZ()) >> 4); + return level.hasChunk((int) Math.floor(getX()) >> 4, (int) Math.floor(getZ()) >> 4); } @Override @@ -253,7 +259,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return isChunkLoaded(); } - @Inject(method = "setPose", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/datasync/EntityDataManager;set(Lnet/minecraft/network/datasync/DataParameter;Ljava/lang/Object;)V")) + @Inject(method = "setPose", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/syncher/SynchedEntityData;set(Lnet/minecraft/network/syncher/EntityDataAccessor;Ljava/lang/Object;)V")) public void arclight$setPose$EntityPoseChangeEvent(Pose poseIn, CallbackInfo callbackInfo) { if (poseIn == this.getPose()) { callbackInfo.cancel(); @@ -263,36 +269,36 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, Bukkit.getPluginManager().callEvent(event); } - @Inject(method = "setRotation", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;rotationYaw:F")) - public void arclight$setRotation$InfiniteValueCheck(float yaw, float pitch, CallbackInfo callbackInfo) { + @Inject(method = "setRot", cancellable = true, at = @At(value = "HEAD")) + public void arclight$infCheck(float yaw, float pitch, CallbackInfo ci) { // CraftBukkit start - yaw was sometimes set to NaN, so we need to set it back to 0 if (Float.isNaN(yaw)) { - this.rotationYaw = 0; - callbackInfo.cancel(); + this.yRot = 0; + ci.cancel(); } if (yaw == Float.POSITIVE_INFINITY || yaw == Float.NEGATIVE_INFINITY) { - if (((Object) this) instanceof PlayerEntity) { + if (((Object) this) instanceof Player) { Bukkit.getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid yaw"); ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite yaw (Are you hacking?)"); } - this.rotationYaw = 0; - callbackInfo.cancel(); + this.yRot = 0; + ci.cancel(); } // pitch was sometimes set to NaN, so we need to set it back to 0 if (Float.isNaN(pitch)) { - this.rotationPitch = 0; - callbackInfo.cancel(); + this.xRot = 0; + ci.cancel(); } if (pitch == Float.POSITIVE_INFINITY || pitch == Float.NEGATIVE_INFINITY) { - if (((Object) this) instanceof PlayerEntity) { + if (((Object) this) instanceof Player) { Bukkit.getLogger().warning(this.getScoreboardName() + " was caught trying to crash the server with an invalid pitch"); ((CraftPlayer) this.getBukkitEntity()).kickPlayer("Infinite pitch (Are you hacking?)"); } - this.rotationPitch = 0; - callbackInfo.cancel(); + this.xRot = 0; + ci.cancel(); } // CraftBukkit end } @@ -341,15 +347,10 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, this.forceExplosionKnockback = forceExplosionKnockback; } - @Inject(method = "setPosition", at = @At(value = "RETURN")) - public void arclight$setPosition$CraftBukkitChunkCheck(double x, double y, double z, CallbackInfo callbackInfo) { - if (valid) ((ServerWorld) world).chunkCheck((Entity) (Object) this); // CraftBukkit - } - public void postTick() { // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle - if (!((Object) this instanceof PlayerEntity)) { - this.updatePortal(); + if (!((Object) this instanceof ServerPlayer)) { + this.handleNetherPortal(); } } @@ -358,25 +359,25 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, postTick(); } - @Redirect(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;updatePortal()V")) + @Redirect(method = "baseTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;handleNetherPortal()V")) public void arclight$baseTick$moveToPostTick(Entity entity) { - if ((Object) this instanceof PlayerEntity) this.updatePortal();// CraftBukkit - // Moved up to postTick + if ((Object) this instanceof ServerPlayer) this.handleNetherPortal();// CraftBukkit - // Moved up to postTick } - @Redirect(method = "setOnFireFromLava", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) + @Redirect(method = "lavaHurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) public void arclight$setOnFireFromLava$bukkitEvent(Entity entity, int seconds) { - if ((Object) this instanceof LivingEntity && fire <= 0) { + if ((Object) this instanceof LivingEntity && remainingFireTicks <= 0) { org.bukkit.block.Block damager = null; // ((WorldServer) this.l).getWorld().getBlockAt(i, j, k); org.bukkit.entity.Entity damagee = this.getBukkitEntity(); EntityCombustEvent combustEvent = new EntityCombustByBlockEvent(damager, damagee, 15); Bukkit.getPluginManager().callEvent(combustEvent); if (!combustEvent.isCancelled()) { - this.setFire(combustEvent.getDuration()); + this.setSecondsOnFire(combustEvent.getDuration()); } } else { // This will be called every single tick the entity is in lava, so don't throw an event - this.setFire(15); + this.setSecondsOnFire(15); } } @@ -389,7 +390,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } seconds = event.getDuration(); } - this.setFire(seconds); + this.setSecondsOnFire(seconds); } @Override @@ -397,23 +398,23 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, setOnFire(tick, callEvent); } - @ModifyArg(method = "move", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onEntityWalk(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V")) + @ModifyArg(method = "move", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;stepOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/Entity;)V")) private BlockPos arclight$captureBlockWalk(BlockPos pos) { ArclightCaptures.captureDamageEventBlock(pos); return pos; } - @Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/block/Block;onEntityWalk(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V")) - private void arclight$resetBlockWalk(MoverType typeIn, Vector3d pos, CallbackInfo ci) { + @Inject(method = "move", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/block/Block;stepOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$resetBlockWalk(MoverType typeIn, Vec3 pos, CallbackInfo ci) { ArclightCaptures.captureDamageEventBlock(null); } - @Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;canTriggerWalking()Z")) - private void arclight$move$blockCollide(MoverType typeIn, Vector3d pos, CallbackInfo ci) { - if (collidedHorizontally && this.bridge$getBukkitEntity() instanceof Vehicle) { + @Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity$MovementEmission;emitsAnything()Z")) + private void arclight$move$blockCollide(MoverType typeIn, Vec3 pos, CallbackInfo ci) { + if (horizontalCollision && this.bridge$getBukkitEntity() instanceof Vehicle) { Vehicle vehicle = (Vehicle) this.bridge$getBukkitEntity(); - org.bukkit.block.Block block = ((WorldBridge) this.world).bridge$getWorld().getBlockAt(MathHelper.floor(this.getPosX()), MathHelper.floor(this.getPosY()), MathHelper.floor(this.getPosZ())); - Vector3d vec3d = this.getAllowedMovement(pos); + org.bukkit.block.Block block = ((WorldBridge) this.level).bridge$getWorld().getBlockAt(Mth.floor(this.getX()), Mth.floor(this.getY()), Mth.floor(this.getZ())); + Vec3 vec3d = this.collide(pos); if (pos.x > vec3d.x) { block = block.getRelative(BlockFace.EAST); } else if (vec3d.x < vec3d.x) { @@ -431,14 +432,9 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - @Inject(method = "resetPositionToBB", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;chunkCheck(Lnet/minecraft/entity/Entity;)V")) - private void arclight$checkIfValid(CallbackInfo ci) { - if (!valid) ci.cancel(); - } - public void burn(float amount) { - if (!this.isImmuneToFire()) { - this.attackEntityFrom(DamageSource.IN_FIRE, amount); + if (!this.fireImmune()) { + this.hurt(DamageSource.IN_FIRE, amount); } } @@ -447,23 +443,14 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, burn(amount); } - @Inject(method = "setWorld", at = @At(value = "HEAD"), cancellable = true) - public void arclight$setWorld(World world, CallbackInfo ci) { - if (world == null) { - remove(); - this.world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle(); - ci.cancel(); - } - } - - @Inject(method = "setPositionAndRotation", at = @At("RETURN")) + @Inject(method = "absMoveTo(DDDFF)V", at = @At("RETURN")) private void arclight$loadChunk(double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { if (this.valid) - this.world.getChunk((int) Math.floor(this.getPosX()) >> 4, (int) Math.floor(this.getPosZ()) >> 4); + this.level.getChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4); } public boolean canCollideWith(Entity entity) { - return this.canBePushed(); + return this.isPushable(); } @Override @@ -471,30 +458,30 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return canCollideWith(entity); } - @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 cir) { + @Inject(method = "saveAsPassenger", cancellable = true, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/entity/Entity;getEncodeId()Ljava/lang/String;")) + public void arclight$writeUnlessRemoved$persistCheck(CompoundTag compound, CallbackInfoReturnable cir) { if (!this.persist) cir.setReturnValue(false); } - @Inject(method = "writeWithoutTypeId", at = @At(value = "INVOKE_ASSIGN", ordinal = 1, target = "Lnet/minecraft/nbt/CompoundNBT;put(Ljava/lang/String;Lnet/minecraft/nbt/INBT;)Lnet/minecraft/nbt/INBT;")) - public void arclight$writeWithoutTypeId$InfiniteValueCheck(CompoundNBT compound, CallbackInfoReturnable cir) { - if (Float.isNaN(this.rotationYaw)) { - this.rotationYaw = 0; + @Inject(method = "saveWithoutId", at = @At(value = "INVOKE_ASSIGN", ordinal = 1, target = "Lnet/minecraft/nbt/CompoundTag;put(Ljava/lang/String;Lnet/minecraft/nbt/Tag;)Lnet/minecraft/nbt/Tag;")) + public void arclight$writeWithoutTypeId$InfiniteValueCheck(CompoundTag compound, CallbackInfoReturnable cir) { + if (Float.isNaN(this.yRot)) { + this.yRot = 0; } - if (Float.isNaN(this.rotationPitch)) { - this.rotationPitch = 0; + if (Float.isNaN(this.xRot)) { + this.xRot = 0; } } - @Inject(method = "writeWithoutTypeId", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/nbt/CompoundNBT;putUniqueId(Ljava/lang/String;Ljava/util/UUID;)V")) - public void arclight$writeWithoutTypeId$CraftBukkitNBT(CompoundNBT compound, CallbackInfoReturnable cir) { - compound.putLong("WorldUUIDLeast", ((WorldBridge) this.world).bridge$getWorld().getUID().getLeastSignificantBits()); - compound.putLong("WorldUUIDMost", ((WorldBridge) this.world).bridge$getWorld().getUID().getMostSignificantBits()); + @Inject(method = "saveWithoutId", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/nbt/CompoundTag;putUUID(Ljava/lang/String;Ljava/util/UUID;)V")) + public void arclight$writeWithoutTypeId$CraftBukkitNBT(CompoundTag compound, CallbackInfoReturnable cir) { + compound.putLong("WorldUUIDLeast", ((WorldBridge) this.level).bridge$getWorld().getUID().getLeastSignificantBits()); + compound.putLong("WorldUUIDMost", ((WorldBridge) this.level).bridge$getWorld().getUID().getMostSignificantBits()); compound.putInt("Bukkit.updateLevel", CURRENT_LEVEL); - compound.putInt("Spigot.ticksLived", this.ticksExisted); + compound.putInt("Spigot.ticksLived", this.tickCount); if (!this.persist) { compound.putBoolean("Bukkit.persist", this.persist); } @@ -503,35 +490,36 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - @Inject(method = "writeWithoutTypeId", at = @At(value = "RETURN")) - public void arclight$writeWithoutTypeId$StoreBukkitValues(CompoundNBT compound, CallbackInfoReturnable cir) { + @Inject(method = "saveWithoutId", at = @At(value = "RETURN")) + public void arclight$writeWithoutTypeId$StoreBukkitValues(CompoundTag compound, CallbackInfoReturnable cir) { if (this.bukkitEntity != null) { this.bukkitEntity.storeBukkitValues(compound); } } - private static boolean isLevelAtLeast(CompoundNBT tag, int level) { + private static boolean isLevelAtLeast(CompoundTag tag, int level) { return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level; } - @Inject(method = "read", at = @At(value = "RETURN")) - public void arclight$read$ReadBukkitValues(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "load", at = @At(value = "RETURN")) + public void arclight$read$ReadBukkitValues(CompoundTag compound, CallbackInfo ci) { // CraftBukkit start if ((Object) this instanceof LivingEntity) { LivingEntity entity = (LivingEntity) (Object) this; - this.ticksExisted = compound.getInt("Spigot.ticksLived"); + this.tickCount = compound.getInt("Spigot.ticksLived"); // Reset the persistence for tamed animals - if (entity instanceof TameableEntity && !isLevelAtLeast(compound, 2) && !compound.getBoolean("PersistenceRequired")) { - MobEntity entityInsentient = (MobEntity) entity; - ((MobEntityBridge) entityInsentient).bridge$setPersistenceRequired(!entityInsentient.canDespawn(0)); + if (entity instanceof TamableAnimal && !isLevelAtLeast(compound, 2) && !compound.getBoolean("PersistenceRequired")) { + Mob entityInsentient = (Mob) entity; + ((MobEntityBridge) entityInsentient).bridge$setPersistenceRequired(!entityInsentient.removeWhenFarAway(0)); } } + this.persist = !compound.contains("Bukkit.persist") || compound.getBoolean("Bukkit.persist"); // CraftBukkit end // CraftBukkit start - Reset world - if ((Object) this instanceof ServerPlayerEntity) { + if ((Object) this instanceof ServerPlayer) { Server server = Bukkit.getServer(); org.bukkit.World bworld = null; @@ -545,10 +533,10 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } if (bworld == null) { - bworld = ((WorldBridge) ((CraftServer) server).getServer().getWorld(World.OVERWORLD)).bridge$getWorld(); + bworld = ((WorldBridge) ((CraftServer) server).getServer().getLevel(Level.OVERWORLD)).bridge$getWorld(); } - setWorld(bworld == null ? null : ((CraftWorld) bworld).getHandle()); + ((ServerPlayer) (Object) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle()); } this.getBukkitEntity().readBukkitValues(compound); if (compound.contains("Bukkit.invisible")) { @@ -566,7 +554,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - @Redirect(method = "entityDropItem(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/item/ItemEntity;", at = @At(value = "INVOKE", remap = false, ordinal = 0, target = "Lnet/minecraft/entity/Entity;captureDrops()Ljava/util/Collection;")) + @Redirect(method = "spawnAtLocation(Lnet/minecraft/world/item/ItemStack;F)Lnet/minecraft/world/entity/item/ItemEntity;", at = @At(value = "INVOKE", remap = false, ordinal = 0, target = "Lnet/minecraft/world/entity/Entity;captureDrops()Ljava/util/Collection;")) public Collection arclight$forceDrops(Entity entity) { Collection drops = entity.captureDrops(); if (this instanceof LivingEntityBridge && ((LivingEntityBridge) this).bridge$isForceDrops()) { @@ -575,9 +563,9 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return drops; } - @Inject(method = "entityDropItem(Lnet/minecraft/item/ItemStack;F)Lnet/minecraft/entity/item/ItemEntity;", + @Inject(method = "spawnAtLocation(Lnet/minecraft/world/item/ItemStack;F)Lnet/minecraft/world/entity/item/ItemEntity;", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) public void arclight$entityDropItem(ItemStack stack, float offsetY, CallbackInfoReturnable cir, ItemEntity itementity) { EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) ((EntityBridge) itementity).bridge$getBukkitEntity()); Bukkit.getPluginManager().callEvent(event); @@ -586,18 +574,17 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - @Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;addPassenger(Lnet/minecraft/entity/Entity;)V")) + @Inject(method = "startRiding(Lnet/minecraft/world/entity/Entity;Z)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;addPassenger(Lnet/minecraft/world/entity/Entity;)V")) public void arclight$startRide(Entity entityIn, boolean force, CallbackInfoReturnable cir) { - if (!((EntityBridge) this.ridingEntity).bridge$addPassenger((Entity) (Object) this)) { - this.ridingEntity = null; + if (!((EntityBridge) this.vehicle).bridge$addPassenger((Entity) (Object) this)) { + this.vehicle = null; } - cir.setReturnValue(true); } - @Redirect(method = "dismount", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;removePassenger(Lnet/minecraft/entity/Entity;)V")) + @Redirect(method = "removeVehicle", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;removePassenger(Lnet/minecraft/world/entity/Entity;)V")) public void arclight$stopRiding$CraftBukkitPatch(Entity entity, Entity passenger) { if (!((EntityBridge) entity).bridge$removePassenger(passenger)) { - this.ridingEntity = entity; + this.vehicle = entity; } } @@ -612,7 +599,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } public boolean addPassenger(Entity entity) { - if (entity.getRidingEntity() != (Object) this) { + if (entity.getVehicle() != (Object) this) { throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)"); } else { // CraftBukkit start @@ -646,10 +633,18 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return false; } // Spigot end - if (!this.world.isRemote && entity instanceof PlayerEntity && !(this.getControllingPassenger() instanceof PlayerEntity)) { - this.passengers.add(0, entity); + if (this.passengers.isEmpty()) { + this.passengers = ImmutableList.of(entity); } else { - this.passengers.add(entity); + List list = Lists.newArrayList(this.passengers); + + if (!this.level.isClientSide && entity instanceof Player && !(this.getControllingPassenger() instanceof Player)) { + list.add(0, entity); + } else { + list.add(entity); + } + + this.passengers = ImmutableList.copyOf(list); } } @@ -662,7 +657,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } public boolean removePassenger(Entity entity) { // CraftBukkit - if (entity.getRidingEntity() == (Object) this) { + if (entity.getVehicle() == (Object) this) { throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)"); } else { // CraftBukkit start @@ -673,7 +668,10 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, (Vehicle) getBukkitEntity(), (org.bukkit.entity.LivingEntity) ((EntityBridge) entity).bridge$getBukkitEntity() ); - Bukkit.getPluginManager().callEvent(event); + // Suppress during worldgen + if (this.valid) { + Bukkit.getPluginManager().callEvent(event); + } CraftEntity craftn = (CraftEntity) ((EntityBridge) entity).bridge$getBukkitEntity().getVehicle(); Entity n = craftn == null ? null : craftn.getHandle(); if (event.isCancelled() || n != orig) { @@ -683,18 +681,27 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, // CraftBukkit end // Spigot start org.spigotmc.event.entity.EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(((EntityBridge) entity).bridge$getBukkitEntity(), this.getBukkitEntity()); - Bukkit.getPluginManager().callEvent(event); + // Suppress during worldgen + if (this.valid) { + Bukkit.getPluginManager().callEvent(event); + } if (event.isCancelled()) { return false; } // Spigot end - this.passengers.remove(entity); - ((EntityBridge) entity).bridge$setRideCooldown(60); + if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { + this.passengers = ImmutableList.of(); + } else { + this.passengers = this.passengers.stream().filter((entity1) -> entity1 != entity) + .collect(ImmutableList.toImmutableList()); + } + + entity.boardingCooldown = 60; } return true; // CraftBukkit } - @Inject(method = "updatePortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;changeDimension(Lnet/minecraft/world/server/ServerWorld;)Lnet/minecraft/entity/Entity;")) + @Inject(method = "handleNetherPortal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;changeDimension(Lnet/minecraft/server/level/ServerLevel;)Lnet/minecraft/world/entity/Entity;")) public void arclight$changeDimension(CallbackInfo ci) { if (this instanceof ServerPlayerEntityBridge) { ((ServerPlayerEntityBridge) this).bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); @@ -712,7 +719,7 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, // CraftBukkit end } - @Inject(method = "setAir", cancellable = true, at = @At(value = "HEAD")) + @Inject(method = "setAirSupply", cancellable = true, at = @At(value = "HEAD")) public void arclight$setAir$EntityAirChangeEvent(int air, CallbackInfo ci) { // CraftBukkit start EntityAirChangeEvent event = new EntityAirChangeEvent(this.getBukkitEntity(), air); @@ -721,13 +728,13 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, event.getEntity().getServer().getPluginManager().callEvent(event); } if (!event.isCancelled()) { - this.dataManager.set(AIR, event.getAmount()); + this.entityData.set(DATA_AIR_SUPPLY_ID, event.getAmount()); } ci.cancel(); // CraftBukkit end } - @Redirect(method = "causeLightningStrike", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) + @Redirect(method = "thunderHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) public void arclight$onStruckByLightning$EntityCombustByEntityEvent0(Entity entity, int seconds) { final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); final org.bukkit.entity.Entity stormBukkitEntity = ((EntityBridge) entity).bridge$getBukkitEntity(); @@ -736,12 +743,12 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8); pluginManager.callEvent(entityCombustEvent); if (!entityCombustEvent.isCancelled()) { - this.setFire(entityCombustEvent.getDuration()); + this.setSecondsOnFire(entityCombustEvent.getDuration()); } // CraftBukkit end } - @Redirect(method = "causeLightningStrike", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) + @Redirect(method = "thunderHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) public boolean arclight$onStruckByLightning$EntityCombustByEntityEvent1(Entity entity, DamageSource source, float amount) { final org.bukkit.entity.Entity thisBukkitEntity = this.getBukkitEntity(); final org.bukkit.entity.Entity stormBukkitEntity = ((EntityBridge) entity).bridge$getBukkitEntity(); @@ -755,11 +762,11 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - if (this.isImmuneToFire()) { + if (this.fireImmune()) { return false; } CraftEventFactory.entityDamage = entity; - if (!this.attackEntityFrom(DamageSource.LIGHTNING_BOLT, amount)) { + if (!this.hurt(DamageSource.LIGHTNING_BOLT, amount)) { CraftEventFactory.entityDamage = null; return false; } @@ -768,12 +775,12 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, @Override public void bridge$setRideCooldown(int rideCooldown) { - this.rideCooldown = rideCooldown; + this.boardingCooldown = rideCooldown; } @Override public int bridge$getRideCooldown() { - return this.rideCooldown; + return this.boardingCooldown; } private transient BlockPos arclight$tpPos; @@ -787,13 +794,13 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - public Entity teleportTo(ServerWorld world, BlockPos blockPos) { + public Entity teleportTo(ServerLevel world, BlockPos blockPos) { arclight$tpPos = blockPos; return changeDimension(world); } @Override - public Entity bridge$teleportTo(ServerWorld world, BlockPos blockPos) { + public Entity bridge$teleportTo(ServerLevel world, BlockPos blockPos) { return teleportTo(world, blockPos); } @@ -803,40 +810,40 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, */ @Overwrite(remap = false) @Nullable - public Entity changeDimension(ServerWorld server, net.minecraftforge.common.util.ITeleporter teleporter) { - if (this.world instanceof ServerWorld && !this.removed) { - this.world.getProfiler().startSection("changeDimension"); + public Entity changeDimension(ServerLevel server, net.minecraftforge.common.util.ITeleporter teleporter) { + if (this.level instanceof ServerLevel && !this.isRemoved()) { + this.level.getProfiler().push("changeDimension"); if (server == null) { return null; } - this.world.getProfiler().startSection("reposition"); - PortalInfo portalinfo = teleporter.getPortalInfo((Entity) (Object) this, server, this::func_241829_a); + this.level.getProfiler().push("reposition"); + PortalInfo portalinfo = teleporter.getPortalInfo((Entity) (Object) this, server, this::findDimensionEntryPoint); if (portalinfo == null) { return null; } else { - ServerWorld world = ((PortalInfoBridge) portalinfo).bridge$getWorld() == null ? server : ((PortalInfoBridge) portalinfo).bridge$getWorld(); - this.detach(); - Entity transportedEntity = teleporter.placeEntity((Entity) (Object) this, (ServerWorld) this.world, server, this.rotationYaw, spawnPortal -> { //Forge: Start vanilla logic - this.world.getProfiler().endStartSection("reloading"); + ServerLevel world = ((PortalInfoBridge) portalinfo).bridge$getWorld() == null ? server : ((PortalInfoBridge) portalinfo).bridge$getWorld(); + this.unRide(); + Entity transportedEntity = teleporter.placeEntity((Entity) (Object) this, (ServerLevel) this.level, server, this.yRot, spawnPortal -> { //Forge: Start vanilla logic + this.level.getProfiler().popPush("reloading"); Entity entity = this.getType().create(world); if (entity != null) { - entity.copyDataFromOld((Entity) (Object) this); - entity.setLocationAndAngles(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.rotationYaw, entity.rotationPitch); - entity.setMotion(portalinfo.motion); - world.addFromAnotherDimension(entity); - if (((WorldBridge) world).bridge$getTypeKey() == DimensionType.THE_END) { + entity.restoreFrom((Entity) (Object) this); + entity.moveTo(portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, entity.getXRot()); + entity.setDeltaMovement(portalinfo.speed); + world.addDuringTeleport(entity); + if (((WorldBridge) world).bridge$getTypeKey() == DimensionType.END_LOCATION) { ArclightCaptures.captureEndPortalEntity((Entity) (Object) this, spawnPortal); - ServerWorld.setupEndSpawnPlatform(world); + ServerLevel.makeObsidianPlatform(world); } } return entity; }); //Forge: End vanilla logic - this.setDead(); - this.world.getProfiler().endSection(); - ((ServerWorld) this.world).resetUpdateEntityTick(); - world.resetUpdateEntityTick(); - this.world.getProfiler().endSection(); + this.removeAfterChangingDimensions(); + this.level.getProfiler().pop(); + ((ServerLevel) this.level).resetEmptyTime(); + world.resetEmptyTime(); + this.level.getProfiler().pop(); return transportedEntity; } } else { @@ -844,12 +851,12 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } } - @Inject(method = "copyDataFromOld", at = @At("HEAD")) + @Inject(method = "restoreFrom", at = @At("HEAD")) private void arclight$forwardHandle(Entity entityIn, CallbackInfo ci) { ((InternalEntityBridge) entityIn).internal$getBukkitEntity().setHandle((Entity) (Object) this); ((EntityBridge) this).bridge$setBukkitEntity(((InternalEntityBridge) entityIn).internal$getBukkitEntity()); - if (entityIn instanceof MobEntity) { - ((MobEntity) entityIn).clearLeashed(true, false); + if (entityIn instanceof Mob) { + ((Mob) entityIn).dropLeash(true, false); } } @@ -859,57 +866,57 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, */ @Nullable @Overwrite - protected PortalInfo func_241829_a(ServerWorld world) { + protected PortalInfo findDimensionEntryPoint(ServerLevel world) { if (world == null) { return null; } - boolean flag = ((WorldBridge) this.world).bridge$getTypeKey() == DimensionType.THE_END && ((WorldBridge) world).bridge$getTypeKey() == DimensionType.OVERWORLD; - boolean flag1 = ((WorldBridge) world).bridge$getTypeKey() == DimensionType.THE_END; + boolean flag = ((WorldBridge) this.level).bridge$getTypeKey() == DimensionType.END_LOCATION && ((WorldBridge) world).bridge$getTypeKey() == DimensionType.OVERWORLD_LOCATION; + boolean flag1 = ((WorldBridge) world).bridge$getTypeKey() == DimensionType.END_LOCATION; if (!flag && !flag1) { - boolean flag2 = ((WorldBridge) world).bridge$getTypeKey() == DimensionType.THE_NETHER; - if (this.world.getDimensionKey() != World.THE_NETHER && !flag2) { + boolean flag2 = ((WorldBridge) world).bridge$getTypeKey() == DimensionType.NETHER_LOCATION; + if (this.level.dimension() != Level.NETHER && !flag2) { return null; } else { WorldBorder worldborder = world.getWorldBorder(); - double d0 = Math.max(-2.9999872E7D, worldborder.minX() + 16.0D); - double d1 = Math.max(-2.9999872E7D, worldborder.minZ() + 16.0D); - double d2 = Math.min(2.9999872E7D, worldborder.maxX() - 16.0D); - double d3 = Math.min(2.9999872E7D, worldborder.maxZ() - 16.0D); - double d4 = DimensionType.getCoordinateDifference(this.world.getDimensionType(), world.getDimensionType()); - BlockPos blockpos1 = new BlockPos(MathHelper.clamp(this.getPosX() * d4, d0, d2), this.getPosY(), MathHelper.clamp(this.getPosZ() * d4, d1, d3)); + double d0 = Math.max(-2.9999872E7D, worldborder.getMinX() + 16.0D); + double d1 = Math.max(-2.9999872E7D, worldborder.getMinZ() + 16.0D); + double d2 = Math.min(2.9999872E7D, worldborder.getMaxX() - 16.0D); + double d3 = Math.min(2.9999872E7D, worldborder.getMaxZ() - 16.0D); + double d4 = DimensionType.getTeleportationScale(this.level.dimensionType(), world.dimensionType()); + BlockPos blockpos1 = new BlockPos(Mth.clamp(this.getX() * d4, d0, d2), this.getY(), Mth.clamp(this.getZ() * d4, d1, d3)); CraftPortalEvent event = this.callPortalEvent((Entity) (Object) this, world, blockpos1, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL, flag2 ? 16 : 128, 16); if (event == null) { return null; } - ServerWorld worldFinal = world = ((CraftWorld) event.getTo().getWorld()).getHandle(); + ServerLevel worldFinal = world = ((CraftWorld) event.getTo().getWorld()).getHandle(); blockpos1 = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); return this.findOrCreatePortal(world, blockpos1, flag2, event.getSearchRadius(), event.getCanCreatePortal(), event.getCreationRadius()).map((result) -> { - BlockState blockstate = this.world.getBlockState(this.entityBlockPosition); + BlockState blockstate = this.level.getBlockState(this.portalEntrancePos); Direction.Axis direction$axis; - Vector3d vector3d; + Vec3 vector3d; if (blockstate.hasProperty(BlockStateProperties.HORIZONTAL_AXIS)) { - direction$axis = blockstate.get(BlockStateProperties.HORIZONTAL_AXIS); - TeleportationRepositioner.Result teleportationrepositioner$result = TeleportationRepositioner.findLargestRectangle(this.entityBlockPosition, direction$axis, 21, Direction.Axis.Y, 21, (pos) -> { - return this.world.getBlockState(pos) == blockstate; + direction$axis = blockstate.getValue(BlockStateProperties.HORIZONTAL_AXIS); + BlockUtil.FoundRectangle teleportationrepositioner$result = BlockUtil.getLargestRectangleAround(this.portalEntrancePos, direction$axis, 21, Direction.Axis.Y, 21, (pos) -> { + return this.level.getBlockState(pos) == blockstate; }); - vector3d = this.func_241839_a(direction$axis, teleportationrepositioner$result); + vector3d = this.getRelativePortalPosition(direction$axis, teleportationrepositioner$result); } else { direction$axis = Direction.Axis.X; - vector3d = new Vector3d(0.5D, 0.0D, 0.0D); + vector3d = new Vec3(0.5D, 0.0D, 0.0D); } ArclightCaptures.captureCraftPortalEvent(event); - return PortalSize.func_242963_a(worldFinal, result, direction$axis, vector3d, this.getSize(this.getPose()), this.getMotion(), this.rotationYaw, this.rotationPitch); + return PortalShape.createPortalInfo(worldFinal, result, direction$axis, vector3d, this.getDimensions(this.getPose()), this.getDeltaMovement(), this.yRot, this.xRot); }).orElse(null); } } else { BlockPos blockpos; if (flag1) { - blockpos = ServerWorld.END_SPAWN_AREA; + blockpos = ServerLevel.END_SPAWN_POINT; } else { - blockpos = world.getHeight(Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, world.getSpawnPoint()); + blockpos = world.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, world.getSharedSpawnPos()); } CraftPortalEvent event = this.callPortalEvent((Entity) (Object) this, world, blockpos, PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); @@ -918,14 +925,14 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, } blockpos = new BlockPos(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); - PortalInfo portalInfo = new PortalInfo(new Vector3d((double) blockpos.getX() + 0.5D, blockpos.getY(), (double) blockpos.getZ() + 0.5D), this.getMotion(), this.rotationYaw, this.rotationPitch); + PortalInfo portalInfo = new PortalInfo(new Vec3((double) blockpos.getX() + 0.5D, blockpos.getY(), (double) blockpos.getZ() + 0.5D), this.getDeltaMovement(), this.yRot, this.xRot); ((PortalInfoBridge) portalInfo).bridge$setWorld(((CraftWorld) event.getTo().getWorld()).getHandle()); ((PortalInfoBridge) portalInfo).bridge$setPortalEventInfo(event); return portalInfo; } } - protected CraftPortalEvent callPortalEvent(Entity entity, ServerWorld exitWorldServer, BlockPos exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { + protected CraftPortalEvent callPortalEvent(Entity entity, ServerLevel exitWorldServer, BlockPos exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { CraftEntity bukkitEntity = ((EntityBridge) entity).bridge$getBukkitEntity(); Location enter = bukkitEntity.getLocation(); Location exit = new Location(((WorldBridge) exitWorldServer).bridge$getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()); @@ -937,11 +944,11 @@ public abstract class EntityMixin implements InternalEntityBridge, EntityBridge, return new CraftPortalEvent(event); } - protected Optional a(ServerWorld serverWorld, BlockPos pos, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { + protected Optional a(ServerLevel serverWorld, BlockPos pos, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { return findOrCreatePortal(serverWorld, pos, flag, searchRadius, canCreatePortal, createRadius); } - protected Optional findOrCreatePortal(ServerWorld serverWorld, BlockPos pos, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { - return ((TeleporterBridge) serverWorld.getDefaultTeleporter()).bridge$findPortal(pos, searchRadius); + protected Optional findOrCreatePortal(ServerLevel serverWorld, BlockPos pos, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { + return ((TeleporterBridge) serverWorld.getPortalForcer()).bridge$findPortal(pos, searchRadius); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityTypeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityTypeMixin.java new file mode 100644 index 00000000..0849acd3 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityTypeMixin.java @@ -0,0 +1,65 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import io.izzel.arclight.common.bridge.entity.EntityTypeBridge; +import io.izzel.arclight.common.bridge.world.IWorldWriterBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.player.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import javax.annotation.Nullable; + +@Mixin(EntityType.class) +public abstract class EntityTypeMixin implements EntityTypeBridge { + + // @formatter:off + @Shadow @Nullable public abstract T create(ServerLevel worldIn, @Nullable CompoundTag compound, @Nullable Component customName, @Nullable Player playerIn, BlockPos pos, MobSpawnType reason, boolean p_220349_7_, boolean p_220349_8_); + // @formatter:on + + @Inject(method = "spawn(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/network/chat/Component;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/MobSpawnType;ZZ)Lnet/minecraft/world/entity/Entity;", + at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$spawnReason(ServerLevel worldIn, CompoundTag compound, Component customName, Player playerIn, BlockPos pos, MobSpawnType reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable cir) { + CreatureSpawnEvent.SpawnReason spawnReason = ((IWorldWriterBridge) worldIn).bridge$getAddEntityReason(); + if (spawnReason == null) { + ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); + } + } + + @Inject(method = "spawn(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/network/chat/Component;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/MobSpawnType;ZZ)Lnet/minecraft/world/entity/Entity;", + cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;func_242417_l(Lnet/minecraft/world/entity/Entity;)V"))) + private void arclight$returnIfSuccess(ServerLevel worldIn, CompoundTag compound, Component customName, Player playerIn, BlockPos pos, MobSpawnType reason, boolean p_220342_7_, boolean p_220342_8_, CallbackInfoReturnable cir, T t) { + if (t != null) { + cir.setReturnValue(t.isRemoved() ? null : t); + } + } + + public T spawnCreature(ServerLevel worldIn, @Nullable CompoundTag compound, @Nullable Component customName, @Nullable Player playerIn, BlockPos pos, MobSpawnType reason, boolean p_220342_7_, boolean p_220342_8_, CreatureSpawnEvent.SpawnReason spawnReason) { + T t = this.create(worldIn, compound, customName, playerIn, pos, reason, p_220342_7_, p_220342_8_); + if (t != null) { + if (t instanceof net.minecraft.world.entity.Mob && net.minecraftforge.event.ForgeEventFactory.doSpecialSpawn((net.minecraft.world.entity.Mob) t, worldIn, pos.getX(), pos.getY(), pos.getZ(), null, reason)) + return null; + ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(spawnReason); + worldIn.addFreshEntityWithPassengers(t); + return t.isRemoved() ? null : t; + } + return null; + } + + @Override + public T bridge$spawnCreature(ServerLevel worldIn, @Nullable CompoundTag compound, @Nullable Component customName, @Nullable Player playerIn, BlockPos pos, MobSpawnType reason, boolean flag, boolean flag1, CreatureSpawnEvent.SpawnReason spawnReason) { + return spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, spawnReason); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java new file mode 100644 index 00000000..e19bf132 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java @@ -0,0 +1,125 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Map; + +@Mixin(ExperienceOrb.class) +public abstract class ExperienceOrbMixin extends EntityMixin { + + // @formatter:off + @Shadow private Player followingPlayer; + @Shadow public abstract boolean hurt(DamageSource source, float amount); + @Shadow public int value; + @Shadow protected abstract int durabilityToXp(int durability); + @Shadow protected abstract int xpToDurability(int p_20799_); + // @formatter:on + + private transient Player arclight$lastPlayer; + + @Inject(method = "tick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;tick()V")) + private void arclight$captureLast(CallbackInfo ci) { + arclight$lastPlayer = this.followingPlayer; + } + + @Inject(method = "tick", at = @At("RETURN")) + private void arclight$captureReset(CallbackInfo ci) { + arclight$lastPlayer = null; + } + + @Redirect(method = "tick", at = @At(value = "FIELD", ordinal = 6, target = "Lnet/minecraft/world/entity/ExperienceOrb;followingPlayer:Lnet/minecraft/world/entity/player/Player;")) + private Player arclight$targetPlayer(ExperienceOrb entity) { + if (this.followingPlayer != arclight$lastPlayer) { + EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent((ExperienceOrb) (Object) this, this.followingPlayer, (this.followingPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET); + LivingEntity target = (event.getTarget() == null) ? null : ((CraftLivingEntity) event.getTarget()).getHandle(); + + if (event.isCancelled()) { + this.followingPlayer = arclight$lastPlayer; + return null; + } else { + this.followingPlayer = (target instanceof Player) ? (Player) target : null; + } + } + return this.followingPlayer; + } + + @Redirect(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;giveExperiencePoints(I)V")) + private void arclight$expChange(Player player, int amount) { + player.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(player, amount).getAmount()); + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + private int repairPlayerItems(Player player, int i) { + Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, player, ItemStack::isDamaged); + + if (entry != null) { + ItemStack itemstack = entry.getValue(); + int j = Math.min(this.xpToDurability(this.value), itemstack.getDamageValue()); + // CraftBukkit start + org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(player, (ExperienceOrb) (Object) this, itemstack, j); + j = event.getRepairAmount(); + if (event.isCancelled()) { + return i; + } + // CraftBukkit end + + itemstack.setDamageValue(itemstack.getDamageValue() - j); + int k = i - this.durabilityToXp(j); + + return k > 0 ? this.repairPlayerItems(player, k) : 0; + } else { + return i; + } + } + + + @Inject(method = "getExperienceValue", cancellable = true, at = @At("HEAD")) + private static void arclight$higherLevelSplit(int expValue, CallbackInfoReturnable cir) { + // @formatter:off + if (expValue > 162670129) { cir.setReturnValue(expValue - 100000); return; } + if (expValue > 81335063) { cir.setReturnValue(81335063); return; } + if (expValue > 40667527) { cir.setReturnValue(40667527); return; } + if (expValue > 20333759) { cir.setReturnValue(20333759); return; } + if (expValue > 10166857) { cir.setReturnValue(10166857); return; } + if (expValue > 5083423) { cir.setReturnValue(5083423); return; } + if (expValue > 2541701) { cir.setReturnValue(2541701); return; } + if (expValue > 1270849) { cir.setReturnValue(1270849); return; } + if (expValue > 635413) { cir.setReturnValue(635413); return; } + if (expValue > 317701) { cir.setReturnValue(317701); return; } + if (expValue > 158849) { cir.setReturnValue(158849); return; } + if (expValue > 79423) { cir.setReturnValue(79423); return; } + if (expValue > 39709) { cir.setReturnValue(39709); return; } + if (expValue > 19853) { cir.setReturnValue(19853); return; } + if (expValue > 9923) { cir.setReturnValue(9923); return; } + if (expValue > 4957) { cir.setReturnValue(4957); } + // @formatter:on + } + + @Override + public void burn(float amount) { + this.hurt(DamageSource.IN_FIRE, amount); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/IAngerableMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/IAngerableMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/IAngerableMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/IAngerableMixin.java index 2e09367a..b8d26b1a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/IAngerableMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/IAngerableMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.entity; +package io.izzel.arclight.common.mixin.core.world.entity; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.IAngerable; -import net.minecraft.entity.LivingEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.NeutralMob; import org.bukkit.event.entity.EntityTargetEvent; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -11,14 +11,14 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.UUID; -@Mixin(IAngerable.class) +@Mixin(NeutralMob.class) public interface IAngerableMixin extends MobEntityBridge { // @formatter:off - @Shadow void setRevengeTarget(@Nullable LivingEntity livingBase); - @Shadow void setAngerTarget(@Nullable UUID target); - @Shadow void setAttackTarget(@Nullable LivingEntity entitylivingbaseIn); - @Shadow void setAngerTime(int time); + @Shadow void setLastHurtByMob(@Nullable LivingEntity livingBase); + @Shadow void setPersistentAngerTarget(@Nullable UUID target); + @Shadow void setTarget(@Nullable LivingEntity entitylivingbaseIn); + @Shadow void setRemainingPersistentAngerTime(int time); // @formatter:on /** @@ -26,17 +26,17 @@ public interface IAngerableMixin extends MobEntityBridge { * @reason */ @Overwrite - default void resetTargets() { - this.setRevengeTarget(null); - this.setAngerTarget(null); + default void stopBeingAngry() { + this.setLastHurtByMob(null); + this.setPersistentAngerTarget(null); this.bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true); - this.setAttackTarget(null); - this.setAngerTime(0); + this.setTarget(null); + this.setRemainingPersistentAngerTime(0); } default boolean setGoalTarget(LivingEntity livingEntity, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fireEvent) { this.bridge$pushGoalTargetReason(reason, fireEvent); - this.setAttackTarget(livingEntity); + this.setTarget(livingEntity); return this.bridge$lastGoalTargetResult(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ItemBaseSteeringMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ItemBaseSteeringMixin.java new file mode 100644 index 00000000..ed79b7ab --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ItemBaseSteeringMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.SynchedEntityData; +import net.minecraft.world.entity.ItemBasedSteering; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ItemBasedSteering.class) +public class ItemBaseSteeringMixin { + + // @formatter:off + @Shadow public boolean boosting; + @Shadow public int boostTime; + @Shadow public int boostTimeTotal; + @Shadow @Final private SynchedEntityData entityData; + @Shadow @Final private EntityDataAccessor boostTimeAccessor; + // @formatter:on + + public void setBoostTicks(int ticks) { + this.boosting = true; + this.boostTime = 0; + this.boostTimeTotal = ticks; + this.entityData.set(this.boostTimeAccessor, this.boostTimeTotal); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java new file mode 100644 index 00000000..e459553a --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java @@ -0,0 +1,48 @@ +package io.izzel.arclight.common.mixin.core.world.entity; + +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LightningBolt.class) +public abstract class LightningBoltMixin extends EntityMixin { + + @Shadow private int life; + + public boolean isSilent = false; + + @Redirect(method = "tick", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, ordinal = 0, target = "Lnet/minecraft/world/entity/LightningBolt;life:I")) + private int arclight$silent(LightningBolt lightningBolt) { + return isSilent ? 0 : this.life; + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;thunderHit(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LightningBolt;)V")) + private void arclight$captureEntity(CallbackInfo ci) { + ArclightCaptures.captureDamageEventEntity((Entity) (Object) this); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;thunderHit(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LightningBolt;)V")) + private void arclight$resetEntity(CallbackInfo ci) { + ArclightCaptures.captureDamageEventEntity(null); + } + + @Redirect(method = "spawnFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$blockIgnite(Level world, BlockPos pos, BlockState state) { + if (!CraftEventFactory.callBlockIgniteEvent(world, pos, (LightningBolt) (Object) this).isCancelled()) { + return world.setBlockAndUpdate(pos, state); + } else { + return false; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java index 9159e7ee..7bcb2651 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/LivingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java @@ -1,49 +1,52 @@ -package io.izzel.arclight.common.mixin.core.entity; +package io.izzel.arclight.common.mixin.core.world.entity; import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.datafixers.util.Either; +import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.mixin.Eject; import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.attributes.Attribute; -import net.minecraft.entity.ai.attributes.AttributeModifierManager; -import net.minecraft.entity.ai.attributes.Attributes; -import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance; -import net.minecraft.entity.item.ExperienceOrbEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.FloatNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.nbt.IntNBT; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.potion.Effect; -import net.minecraft.potion.EffectInstance; -import net.minecraft.potion.Effects; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.FloatTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.Tag; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvent; import net.minecraft.stats.Stats; -import net.minecraft.util.CombatTracker; -import net.minecraft.util.DamageSource; -import net.minecraft.util.EntityDamageSource; -import net.minecraft.util.Hand; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.damagesource.CombatTracker; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.damagesource.EntityDamageSource; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeMap; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.gameevent.GameEvent; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeEventFactory; @@ -57,6 +60,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExhaustionEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityResurrectEvent; @@ -71,6 +75,7 @@ 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.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import javax.annotation.Nullable; import java.util.Collection; @@ -94,85 +99,87 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt @Shadow public abstract void heal(float healAmount); @Shadow public abstract float getHealth(); @Shadow public abstract void setHealth(float health); - @Shadow public abstract float getRotationYawHead(); - @Shadow protected abstract int getExperiencePoints(PlayerEntity player); - @Shadow protected int recentlyHit; - @Shadow protected abstract boolean canDropLoot(); - @Shadow protected abstract boolean isPlayer(); - @Shadow public PlayerEntity attackingPlayer; + @Shadow public abstract float getYHeadRot(); + @Shadow protected abstract int getExperienceReward(net.minecraft.world.entity.player.Player player); + @Shadow protected int lastHurtByPlayerTime; + @Shadow protected abstract boolean shouldDropExperience(); + @Shadow protected abstract boolean isAlwaysExperienceDropper(); + @Shadow public net.minecraft.world.entity.player.Player lastHurtByPlayer; @Shadow public int deathTime; @Shadow protected boolean dead; - @Shadow public abstract ModifiableAttributeInstance getAttribute(Attribute attribute); - @Shadow public boolean potionsNeedUpdate; - @Shadow public abstract boolean removePotionEffect(Effect effectIn); - @Shadow public abstract boolean clearActivePotions(); - @Shadow @Final public static DataParameter HEALTH; - @Shadow public abstract boolean isPotionActive(Effect potionIn); + @Shadow public abstract AttributeInstance getAttribute(Attribute attribute); + @Shadow public boolean effectsDirty; + @Shadow public abstract boolean removeEffect(MobEffect effectIn); + @Shadow public abstract boolean removeAllEffects(); + @Shadow @Final public static EntityDataAccessor DATA_HEALTH_ID; + @Shadow public abstract boolean hasEffect(MobEffect potionIn); @Shadow public abstract boolean isSleeping(); - @Shadow public abstract void wakeUp(); - @Shadow protected int idleTime; - @Shadow public abstract net.minecraft.item.ItemStack getItemStackFromSlot(EquipmentSlotType slotIn); - @Shadow protected abstract boolean canBlockDamageSource(DamageSource damageSourceIn); - @Shadow protected abstract void damageShield(float damage); + @Shadow public abstract void stopSleeping(); + @Shadow protected int noActionTime; + @Shadow public abstract net.minecraft.world.item.ItemStack getItemBySlot(EquipmentSlot slotIn); + @Shadow public abstract boolean isDamageSourceBlocked(DamageSource damageSourceIn); + @Shadow protected abstract void hurtCurrentlyUsedShield(float damage); @Shadow protected abstract void blockUsingShield(LivingEntity entityIn); - @Shadow public float limbSwingAmount; - @Shadow public float lastDamage; - @Shadow public int maxHurtTime; + @Shadow public float animationSpeed; + @Shadow public float lastHurt; + @Shadow public int hurtDuration; @Shadow public int hurtTime; - @Shadow public float attackedAtYaw; - @Shadow public abstract void setRevengeTarget(@Nullable LivingEntity livingBase); - @Shadow protected abstract void markVelocityChanged(); + @Shadow public float hurtDir; + @Shadow public abstract void setLastHurtByMob(@Nullable LivingEntity livingBase); + @Shadow protected abstract void markHurt(); @Shadow @Nullable protected abstract SoundEvent getDeathSound(); @Shadow protected abstract float getSoundVolume(); - @Shadow protected abstract float getSoundPitch(); - @Shadow public abstract void onDeath(DamageSource cause); + @Shadow public abstract float getVoicePitch(); + @Shadow public abstract void die(DamageSource cause); @Shadow protected abstract void playHurtSound(DamageSource source); @Shadow private DamageSource lastDamageSource; @Shadow private long lastDamageStamp; - @Shadow protected abstract float applyArmorCalculations(DamageSource source, float damage); - @Shadow public abstract net.minecraft.item.ItemStack getHeldItem(Hand hand); - @Shadow @Nullable public abstract EffectInstance getActivePotionEffect(Effect potionIn); - @Shadow protected abstract float applyPotionDamageCalculations(DamageSource source, float damage); + @Shadow protected abstract float getDamageAfterArmorAbsorb(DamageSource source, float damage); + @Shadow public abstract net.minecraft.world.item.ItemStack getItemInHand(InteractionHand hand); + @Shadow @Nullable public abstract MobEffectInstance getEffect(MobEffect potionIn); + @Shadow protected abstract float getDamageAfterMagicAbsorb(DamageSource source, float damage); @Shadow public abstract float getAbsorptionAmount(); @Shadow public abstract void setAbsorptionAmount(float amount); @Shadow public abstract CombatTracker getCombatTracker(); - @Shadow @Final private AttributeModifierManager attributes; - @Shadow public abstract boolean isOnLadder(); - @Shadow protected ItemStack activeItemStack; - @Shadow public abstract void onItemPickup(Entity entityIn, int quantity); - @Shadow protected abstract void spawnDrops(DamageSource damageSourceIn); - @Shadow public abstract ItemStack getHeldItemMainhand(); + @Shadow @Final private AttributeMap attributes; + @Shadow public abstract boolean onClimbable(); + @Shadow protected ItemStack useItem; + @Shadow public abstract void take(Entity entityIn, int quantity); + @Shadow protected abstract void dropAllDeathLoot(DamageSource damageSourceIn); + @Shadow public abstract ItemStack getMainHandItem(); @Shadow public abstract void setSprinting(boolean sprinting); - @Shadow public abstract void setLastAttackedEntity(Entity entityIn); - @Shadow public abstract void setHeldItem(Hand hand, ItemStack stack); - @Shadow public abstract boolean canEntityBeSeen(Entity entityIn); - @Shadow @Nullable public abstract LivingEntity getAttackingEntity(); - @Shadow protected int scoreValue; - @Shadow public abstract Collection getActivePotionEffects(); - @Shadow public abstract void setArrowCountInEntity(int count); - @Shadow @Nullable public LivingEntity revengeTarget; + @Shadow public abstract void setLastHurtMob(Entity entityIn); + @Shadow public abstract void setItemInHand(InteractionHand hand, ItemStack stack); + @Shadow @Nullable public abstract LivingEntity getKillCredit(); + @Shadow protected int deathScore; + @Shadow public abstract Collection getActiveEffects(); + @Shadow public abstract void setArrowCount(int count); + @Shadow @Nullable public LivingEntity lastHurtByMob; @Shadow public CombatTracker combatTracker; - @Shadow public abstract ItemStack getHeldItemOffhand(); - @Shadow public abstract Random getRNG(); - @Shadow public abstract Optional getBedPosition(); - @Shadow @Final private static DataParameter POTION_EFFECTS; - @Shadow @Final private static DataParameter HIDE_PARTICLES; - @Shadow @Final public Map activePotionsMap; - @Shadow protected abstract void onFinishedPotionEffect(EffectInstance effect); - @Shadow protected abstract void onChangedPotionEffect(EffectInstance id, boolean reapply); - @Shadow protected abstract void updatePotionMetadata(); - @Shadow public abstract boolean isPotionApplicable(EffectInstance potioneffectIn); - @Shadow protected abstract void onNewPotionEffect(EffectInstance id); - @Shadow @Nullable public abstract EffectInstance removeActivePotionEffect(@Nullable Effect potioneffectin); + @Shadow public abstract ItemStack getOffhandItem(); + @Shadow public abstract Random getRandom(); + @Shadow public abstract Optional getSleepingPos(); + @Shadow @Final private static EntityDataAccessor DATA_EFFECT_COLOR_ID; + @Shadow @Final private static EntityDataAccessor DATA_EFFECT_AMBIENCE_ID; + @Shadow @Final public Map activeEffects; + @Shadow protected abstract void onEffectRemoved(MobEffectInstance effect); + @Shadow protected abstract void updateInvisibilityStatus(); + @Shadow public abstract boolean canBeAffected(MobEffectInstance potioneffectIn); + @Shadow @Nullable public abstract MobEffectInstance removeEffectNoUpdate(@Nullable MobEffect potioneffectin); @Shadow protected abstract void createWitherRose(@Nullable LivingEntity entitySource); @Shadow public abstract double getAttributeValue(Attribute attribute); - @Shadow public abstract void applyKnockback(float strength, double ratioX, double ratioZ); - @Shadow protected abstract void damageArmor(DamageSource damageSource, float damage); - @Shadow protected abstract void playEquipSound(ItemStack stack); - @Shadow public abstract boolean getShouldBeDead(); - @Shadow public abstract int getArrowCountInEntity(); - @Shadow @Final private static DataParameter ARROW_COUNT_IN_ENTITY; - @Shadow public abstract void setItemStackToSlot(EquipmentSlotType slotIn, ItemStack stack); + @Shadow protected abstract void hurtArmor(DamageSource damageSource, float damage); + @Shadow public abstract boolean isDeadOrDying(); + @Shadow public abstract int getArrowCount(); + @Shadow @Final public static EntityDataAccessor DATA_ARROW_COUNT_ID; + @Shadow public abstract void setItemSlot(EquipmentSlot slotIn, ItemStack stack); + @Shadow protected abstract void onEffectUpdated(MobEffectInstance p_147192_, boolean p_147193_, @org.jetbrains.annotations.Nullable Entity p_147194_); + @Shadow protected abstract void onEffectAdded(MobEffectInstance p_147190_, @org.jetbrains.annotations.Nullable Entity p_147191_); + @Shadow public abstract void knockback(double p_147241_, double p_147242_, double p_147243_); + @Shadow protected abstract void equipEventAndSound(ItemStack p_147219_); + @Shadow public abstract boolean canAttack(LivingEntity p_21171_); + @Shadow public abstract boolean hasLineOfSight(Entity p_147185_); + @Shadow protected abstract void hurtHelmet(DamageSource p_147213_, float p_147214_); // @formatter:on public int expToDrop; @@ -183,17 +190,17 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt public boolean canPickUpLoot; public Set collidableExemptions = new HashSet<>(); - @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setHealth(F)V")) + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setHealth(F)V")) private void arclight$muteHealth(LivingEntity entity, float health) { // do nothing } @Inject(method = "", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { this.maxAirTicks = 300; this.collides = true; this.craftAttributes = new CraftAttributeMap(this.attributes); - this.dataManager.set(HEALTH, (float) this.getAttributeValue(Attributes.MAX_HEALTH)); + this.entityData.set(DATA_HEALTH_ID, (float) this.getAttributeValue(Attributes.MAX_HEALTH)); } /** @@ -201,26 +208,19 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt * @reason */ @Overwrite - protected void onDeathUpdate() { + protected void tickDeath() { ++this.deathTime; - if (this.deathTime >= 20 && !this.removed) { - - this.remove((Object) this instanceof ServerPlayerEntity); //Forge keep data until we revive player - - for (int k = 0; k < 20; ++k) { - double d2 = this.rand.nextGaussian() * 0.02D; - double d0 = this.rand.nextGaussian() * 0.02D; - double d1 = this.rand.nextGaussian() * 0.02D; - this.world.addParticle(ParticleTypes.POOF, this.getPosX() + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), this.getPosY() + (double) (this.rand.nextFloat() * this.getHeight()), this.getPosZ() + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), d2, d0, d1); - } + if (this.deathTime >= 20 && !this.isRemoved() && !this.level.isClientSide()) { + this.level.broadcastEntityEvent((LivingEntity) (Object) this, (byte) 60); + this.remove(Entity.RemovalReason.KILLED); } } - @Redirect(method = "spawnDrops", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;dropExperience()V")) + @Redirect(method = "dropAllDeathLoot", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;dropExperience()V")) private void arclight$dropLater(LivingEntity livingEntity) { } - @Inject(method = "spawnDrops", at = @At("RETURN")) + @Inject(method = "dropAllDeathLoot", at = @At("RETURN")) private void arclight$dropLast(DamageSource damageSourceIn, CallbackInfo ci) { this.dropExperience(); } @@ -233,36 +233,31 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt protected void dropExperience() { // if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) { if (true) { - int i = bridge$getExpToDrop(); - while (i > 0) { - int j = ExperienceOrbEntity.getXPSplit(i); - i -= j; - this.world.addEntity(new ExperienceOrbEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), j)); - } + ExperienceOrb.award((ServerLevel) this.level, this.position(), this.expToDrop); bridge$setExpToDrop(0); } } private boolean isTickingEffects = false; - private List, EntityPotionEffectEvent.Cause>> effectsToProcess = Lists.newArrayList(); + private List, EntityPotionEffectEvent.Cause>> effectsToProcess = Lists.newArrayList(); /** * @author IzzelAliz * @reason */ @Overwrite - protected void updatePotionEffects() { + protected void tickEffects() { this.isTickingEffects = true; - Iterator iterator = this.activePotionsMap.keySet().iterator(); + Iterator iterator = this.activeEffects.keySet().iterator(); try { while (iterator.hasNext()) { - Effect effect = iterator.next(); - EffectInstance effectinstance = this.activePotionsMap.get(effect); + MobEffect effect = iterator.next(); + MobEffectInstance effectinstance = this.activeEffects.get(effect); if (!effectinstance.tick((LivingEntity) (Object) this, () -> { - onChangedPotionEffect(effectinstance, true); + onEffectUpdated(effectinstance, true, null); })) { - if (!this.world.isRemote && !MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionExpiryEvent((LivingEntity) (Object) this, effectinstance))) { + if (!this.level.isClientSide && !MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionExpiryEvent((LivingEntity) (Object) this, effectinstance))) { EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, null, EntityPotionEffectEvent.Cause.EXPIRATION); if (event.isCancelled()) { @@ -270,55 +265,55 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt } iterator.remove(); - this.onFinishedPotionEffect(effectinstance); + this.onEffectRemoved(effectinstance); } } else if (effectinstance.getDuration() % 600 == 0) { - this.onChangedPotionEffect(effectinstance, false); + this.onEffectUpdated(effectinstance, false, null); } } } catch (ConcurrentModificationException ignored) { } isTickingEffects = false; - for (Map.Entry, EntityPotionEffectEvent.Cause> e : effectsToProcess) { - Either either = e.getKey(); + for (Map.Entry, EntityPotionEffectEvent.Cause> e : effectsToProcess) { + Either either = e.getKey(); EntityPotionEffectEvent.Cause cause = e.getValue(); bridge$pushEffectCause(cause); if (either.left().isPresent()) { - addPotionEffect(either.left().get()); + addEffect(either.left().get(), cause); } else { - removePotionEffect(either.right().get()); + removeEffect(either.right().get(), cause); } } effectsToProcess.clear(); - if (this.potionsNeedUpdate) { - if (!this.world.isRemote) { - this.updatePotionMetadata(); + if (this.effectsDirty) { + if (!this.level.isClientSide) { + this.updateInvisibilityStatus(); } - this.potionsNeedUpdate = false; + this.effectsDirty = false; } - int i = this.dataManager.get(POTION_EFFECTS); - boolean flag1 = this.dataManager.get(HIDE_PARTICLES); + int i = this.entityData.get(DATA_EFFECT_COLOR_ID); + boolean flag1 = this.entityData.get(DATA_EFFECT_AMBIENCE_ID); if (i > 0) { boolean flag; if (this.isInvisible()) { - flag = this.rand.nextInt(15) == 0; + flag = this.random.nextInt(15) == 0; } else { - flag = this.rand.nextBoolean(); + flag = this.random.nextBoolean(); } if (flag1) { - flag &= this.rand.nextInt(5) == 0; + flag &= this.random.nextInt(5) == 0; } if (flag && i > 0) { double d0 = (double) (i >> 16 & 255) / 255.0D; double d1 = (double) (i >> 8 & 255) / 255.0D; double d2 = (double) (i >> 0 & 255) / 255.0D; - this.world.addParticle(flag1 ? ParticleTypes.AMBIENT_ENTITY_EFFECT : ParticleTypes.ENTITY_EFFECT, this.getPosX() + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), this.getPosY() + this.rand.nextDouble() * (double) this.getHeight(), this.getPosZ() + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), d0, d1, d2); + this.level.addParticle(flag1 ? ParticleTypes.AMBIENT_ENTITY_EFFECT : ParticleTypes.ENTITY_EFFECT, this.getX() + (this.random.nextDouble() - 0.5D) * (double) this.getBbWidth(), this.getY() + this.random.nextDouble() * (double) this.getBbHeight(), this.getZ() + (this.random.nextDouble() - 0.5D) * (double) this.getBbWidth(), d0, d1, d2); } } } @@ -328,21 +323,21 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt * @reason */ @Overwrite - public boolean addPotionEffect(EffectInstance effectInstanceIn) { + public boolean addEffect(MobEffectInstance effectInstanceIn, Entity entity) { EntityPotionEffectEvent.Cause cause = bridge$getEffectCause().orElse(EntityPotionEffectEvent.Cause.UNKNOWN); if (isTickingEffects) { effectsToProcess.add(Maps.immutableEntry(Either.left(effectInstanceIn), cause)); return true; } - if (!this.isPotionApplicable(effectInstanceIn)) { + if (!this.canBeAffected(effectInstanceIn)) { return false; } else { - EffectInstance effectinstance = this.activePotionsMap.get(effectInstanceIn.getPotion()); + MobEffectInstance effectinstance = this.activeEffects.get(effectInstanceIn.getEffect()); boolean override = false; if (effectinstance != null) { - override = new EffectInstance(effectinstance).combine(effectInstanceIn); + override = new MobEffectInstance(effectinstance).update(effectInstanceIn); } EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn, cause, override); @@ -352,12 +347,12 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionAddedEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn)); if (effectinstance == null) { - this.activePotionsMap.put(effectInstanceIn.getPotion(), effectInstanceIn); - this.onNewPotionEffect(effectInstanceIn); + this.activeEffects.put(effectInstanceIn.getEffect(), effectInstanceIn); + this.onEffectAdded(effectInstanceIn, entity); return true; } else if (event.isOverride()) { - effectinstance.combine(effectInstanceIn); - this.onChangedPotionEffect(effectinstance, true); + effectinstance.update(effectInstanceIn); + this.onEffectUpdated(effectinstance, true, entity); return true; } else { return false; @@ -366,13 +361,13 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt } @SuppressWarnings("unused") // mock - public EffectInstance c(@Nullable Effect potioneffectin, EntityPotionEffectEvent.Cause cause) { + public MobEffectInstance c(@Nullable MobEffect potioneffectin, EntityPotionEffectEvent.Cause cause) { bridge$pushEffectCause(cause); - return removeActivePotionEffect(potioneffectin); + return removeEffectNoUpdate(potioneffectin); } - @Inject(method = "removeActivePotionEffect", cancellable = true, at = @At("HEAD")) - public void arclight$clearActive(Effect effect, CallbackInfoReturnable cir) { + @Inject(method = "removeEffectNoUpdate", cancellable = true, at = @At("HEAD")) + public void arclight$clearActive(MobEffect effect, CallbackInfoReturnable cir) { EntityPotionEffectEvent.Cause cause = bridge$getEffectCause().orElse(EntityPotionEffectEvent.Cause.UNKNOWN); if (isTickingEffects) { effectsToProcess.add(Maps.immutableEntry(Either.right(effect), cause)); @@ -380,7 +375,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt return; } - EffectInstance effectInstance = this.activePotionsMap.get(effect); + MobEffectInstance effectInstance = this.activeEffects.get(effect); if (effectInstance == null) { cir.setReturnValue(null); return; @@ -394,7 +389,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt @Eject(method = "onLivingFall", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) private boolean arclight$fall(LivingEntity livingEntity, DamageSource source, float amount, CallbackInfoReturnable cir) { - boolean ret = livingEntity.attackEntityFrom(source, amount); + boolean ret = livingEntity.hurt(source, amount); cir.setReturnValue(ret); return ret; } @@ -406,13 +401,13 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt @Override public float getBukkitYaw() { - return getRotationYawHead(); + return getYHeadRot(); } public int getExpReward() { - if (!this.world.isRemote && (this.recentlyHit > 0 || this.isPlayer()) && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { - int exp = this.getExperiencePoints(this.attackingPlayer); - return ForgeEventFactory.getExperienceDrop((LivingEntity) (Object) this, this.attackingPlayer, exp); + if (!this.level.isClientSide && (this.lastHurtByPlayerTime > 0 || this.isAlwaysExperienceDropper()) && this.shouldDropExperience() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { + int exp = this.getExperienceReward(this.lastHurtByPlayer); + return ForgeEventFactory.getExperienceDrop((LivingEntity) (Object) this, this.lastHurtByPlayer, exp); } else { return 0; } @@ -438,19 +433,19 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt return forceDrops; } - @Inject(method = "readAdditional", at = @At("HEAD")) - public void arclight$readMaxHealth(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "readAdditionalSaveData", at = @At("HEAD")) + public void arclight$readMaxHealth(CompoundTag compound, CallbackInfo ci) { if (compound.contains("Bukkit.MaxHealth")) { - INBT nbtbase = compound.get("Bukkit.MaxHealth"); + Tag nbtbase = compound.get("Bukkit.MaxHealth"); if (nbtbase.getId() == 5) { - this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((FloatNBT) nbtbase).getDouble()); + this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((FloatTag) nbtbase).getAsDouble()); } else if (nbtbase.getId() == 3) { - this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((IntNBT) nbtbase).getDouble()); + this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((IntTag) nbtbase).getAsDouble()); } } } - @Inject(method = "clearActivePotions", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z")) + @Inject(method = "removeAllEffects", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z")) public void arclight$clearReason(CallbackInfoReturnable cir) { arclight$action = EntityPotionEffectEvent.Action.CLEARED; } @@ -472,7 +467,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt */ @Overwrite public boolean isAlive() { - return !this.removed && this.dataManager.get(HEALTH) > 0.0F; + return !this.isRemoved() && this.entityData.get(DATA_HEALTH_ID) > 0.0F; } @Inject(method = "getHealth", cancellable = true, at = @At("HEAD")) @@ -487,7 +482,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (this instanceof ServerPlayerEntityBridge && ((ServerPlayerEntityBridge) this).bridge$initialized()) { CraftPlayer player = ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity(); - double realHealth = MathHelper.clamp(health, 0.0F, player.getMaxHealth()); + double realHealth = Mth.clamp(health, 0.0F, player.getMaxHealth()); player.setRealHealth(realHealth); player.updateScaledHealth(false); @@ -501,39 +496,39 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt * @reason */ @Overwrite - public boolean attackEntityFrom(DamageSource source, float amount) { + public boolean hurt(DamageSource source, float amount) { if (!ForgeHooks.onLivingAttack((LivingEntity) (Object) this, source, amount)) return false; if (this.isInvulnerableTo(source)) { return false; - } else if (this.world.isRemote) { + } else if (this.level.isClientSide) { return false; - } else if (this.dead || this.removed || this.getHealth() <= 0.0F) { + } else if (this.dead || this.isRemoved() || this.getHealth() <= 0.0F) { return false; - } else if (source.isFireDamage() && this.isPotionActive(Effects.FIRE_RESISTANCE)) { + } else if (source.isFire() && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; } else { - if (this.isSleeping() && !this.world.isRemote) { - this.wakeUp(); + if (this.isSleeping() && !this.level.isClientSide) { + this.stopSleeping(); } - this.idleTime = 0; + this.noActionTime = 0; float f = amount; - if (false && (source == DamageSource.ANVIL || source == DamageSource.FALLING_BLOCK) && !this.getItemStackFromSlot(EquipmentSlotType.HEAD).isEmpty()) { - this.getItemStackFromSlot(EquipmentSlotType.HEAD).damageItem((int) (amount * 4.0F + this.rand.nextFloat() * amount * 2.0F), (LivingEntity) (Object) this, (p_213341_0_) -> { - p_213341_0_.sendBreakAnimation(EquipmentSlotType.HEAD); + if (false && (source == DamageSource.ANVIL || source == DamageSource.FALLING_BLOCK) && !this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) { + this.getItemBySlot(EquipmentSlot.HEAD).hurtAndBreak((int) (amount * 4.0F + this.random.nextFloat() * amount * 2.0F), (LivingEntity) (Object) this, (p_213341_0_) -> { + p_213341_0_.broadcastBreakEvent(EquipmentSlot.HEAD); }); amount *= 0.75F; } - boolean flag = false; + boolean flag = f > 0.0F && this.isDamageSourceBlocked(source); // Copied from below float f1 = 0.0F; - if (false && amount > 0.0F && this.canBlockDamageSource(source)) { - this.damageShield(amount); + if (false && amount > 0.0F && this.isDamageSourceBlocked(source)) { + this.hurtCurrentlyUsedShield(amount); f1 = amount; amount = 0.0F; if (!source.isProjectile()) { - Entity entity = source.getImmediateSource(); + Entity entity = source.getDirectEntity(); if (entity instanceof LivingEntity) { this.blockUsingShield((LivingEntity) entity); } @@ -542,55 +537,55 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt flag = true; } - this.limbSwingAmount = 1.5F; + this.animationSpeed = 1.5F; boolean flag1 = true; - if ((float) this.hurtResistantTime > 10.0F) { - if (amount <= this.lastDamage) { + if ((float) this.invulnerableTime > 10.0F) { + if (amount <= this.lastHurt) { this.forceExplosionKnockback = true; return false; } - if (!this.damageEntity0(source, amount - this.lastDamage)) { + if (!this.damageEntity0(source, amount - this.lastHurt)) { return false; } - this.lastDamage = amount; + this.lastHurt = amount; flag1 = false; } else { if (!this.damageEntity0(source, amount)) { return false; } - this.lastDamage = amount; - this.hurtResistantTime = 20; - this.maxHurtTime = 10; - this.hurtTime = this.maxHurtTime; + this.lastHurt = amount; + this.invulnerableTime = 20; + this.hurtDuration = 10; + this.hurtTime = this.hurtDuration; } - if ((Object) this instanceof AnimalEntity) { - ((AnimalEntity) (Object) this).resetInLove(); - if ((Object) this instanceof TameableEntity) { - ((TameableEntity) (Object) this).setSitting(false); + if ((Object) this instanceof Animal) { + ((Animal) (Object) this).resetLove(); + if ((Object) this instanceof TamableAnimal) { + ((TamableAnimal) (Object) this).setOrderedToSit(false); } } - this.attackedAtYaw = 0.0F; - Entity entity1 = source.getTrueSource(); + this.hurtDir = 0.0F; + Entity entity1 = source.getEntity(); if (entity1 != null) { if (entity1 instanceof LivingEntity) { - this.setRevengeTarget((LivingEntity) entity1); + this.setLastHurtByMob((LivingEntity) entity1); } - if (entity1 instanceof PlayerEntity) { - this.recentlyHit = 100; - this.attackingPlayer = (PlayerEntity) entity1; - } else if (entity1 instanceof TameableEntity) { - TameableEntity wolfentity = (TameableEntity) entity1; - if (wolfentity.isTamed()) { - this.recentlyHit = 100; + if (entity1 instanceof net.minecraft.world.entity.player.Player) { + this.lastHurtByPlayerTime = 100; + this.lastHurtByPlayer = (net.minecraft.world.entity.player.Player) entity1; + } else if (entity1 instanceof TamableAnimal) { + TamableAnimal wolfentity = (TamableAnimal) entity1; + if (wolfentity.isTame()) { + this.lastHurtByPlayerTime = 100; LivingEntity livingentity = wolfentity.getOwner(); if (livingentity != null && livingentity.getType() == EntityType.PLAYER) { - this.attackingPlayer = (PlayerEntity) livingentity; + this.lastHurtByPlayer = (net.minecraft.world.entity.player.Player) livingentity; } else { - this.attackingPlayer = null; + this.lastHurtByPlayer = null; } } } @@ -598,14 +593,14 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (flag1) { if (flag) { - this.world.setEntityState((LivingEntity) (Object) this, (byte) 29); - } else if (source instanceof EntityDamageSource && ((EntityDamageSource) source).getIsThornsDamage()) { - this.world.setEntityState((LivingEntity) (Object) this, (byte) 33); + this.level.broadcastEntityEvent((LivingEntity) (Object) this, (byte) 29); + } else if (source instanceof EntityDamageSource && ((EntityDamageSource) source).isThorns()) { + this.level.broadcastEntityEvent((LivingEntity) (Object) this, (byte) 33); } else { byte b0; if (source == DamageSource.DROWN) { b0 = 36; - } else if (source.isFireDamage()) { + } else if (source.isFire()) { b0 = 37; } else if (source == DamageSource.SWEET_BERRY_BUSH) { b0 = 44; @@ -613,25 +608,25 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt b0 = 2; } - this.world.setEntityState((LivingEntity) (Object) this, b0); + this.level.broadcastEntityEvent((LivingEntity) (Object) this, b0); } if (source != DamageSource.DROWN && (!flag || amount > 0.0F)) { - this.markVelocityChanged(); + this.markHurt(); } if (entity1 != null) { - double d1 = entity1.getPosX() - this.getPosX(); + double d1 = entity1.getX() - this.getX(); double d0; - for (d0 = entity1.getPosZ() - this.getPosZ(); d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D) { + for (d0 = entity1.getZ() - this.getZ(); d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D) { d1 = (Math.random() - Math.random()) * 0.01D; } - this.attackedAtYaw = (float) (MathHelper.atan2(d0, d1) * (double) (180F / (float) Math.PI) - (double) this.rotationYaw); - this.applyKnockback(0.4F, d1, d0); + this.hurtDir = (float) (Mth.atan2(d0, d1) * (double) (180F / (float) Math.PI) - (double) this.yRot); + this.knockback(0.4F, d1, d0); } else { - this.attackedAtYaw = (float) ((int) (Math.random() * 2.0D) * 180); + this.hurtDir = (float) ((int) (Math.random() * 2.0D) * 180); } } @@ -639,10 +634,10 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (!this.checkTotemDeathProtection(source)) { SoundEvent soundevent = this.getDeathSound(); if (flag1 && soundevent != null) { - this.playSound(soundevent, this.getSoundVolume(), this.getSoundPitch()); + this.playSound(soundevent, this.getSoundVolume(), this.getVoicePitch()); } - this.onDeath(source); + this.die(source); } } else if (flag1) { this.playHurtSound(source); @@ -651,25 +646,25 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt boolean flag2 = !flag || amount > 0.0F; if (flag2) { this.lastDamageSource = source; - this.lastDamageStamp = this.world.getGameTime(); + this.lastDamageStamp = this.level.getGameTime(); } - if ((Object) this instanceof ServerPlayerEntity) { - CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayerEntity) (Object) this, source, f, amount, flag); + if ((Object) this instanceof ServerPlayer) { + CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) (Object) this, source, f, amount, flag); if (f1 > 0.0F && f1 < 3.4028235E37F) { - ((ServerPlayerEntity) (Object) this).addStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f1 * 10.0F)); + ((ServerPlayer) (Object) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(f1 * 10.0F)); } } - if (entity1 instanceof ServerPlayerEntity) { - CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayerEntity) entity1, (LivingEntity) (Object) this, source, f, amount, flag); + if (entity1 instanceof ServerPlayer) { + CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayer) entity1, (LivingEntity) (Object) this, source, f, amount, flag); } return flag2; } } - @Inject(method = "damageEntity", cancellable = true, at = @At("HEAD")) + @Inject(method = "actuallyHurt", cancellable = true, at = @At("HEAD")) public void arclight$redirectDamageEntity(DamageSource damageSrc, float damageAmount, CallbackInfo ci) { damageEntity0(damageSrc, damageAmount); ci.cancel(); @@ -677,14 +672,14 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt protected boolean damageEntity0(DamageSource damagesource, float f) { if (!this.isInvulnerableTo(damagesource)) { - final boolean human = (Object) this instanceof PlayerEntity; + final boolean human = (Object) this instanceof net.minecraft.world.entity.player.Player; f = net.minecraftforge.common.ForgeHooks.onLivingHurt((LivingEntity) (Object) this, damagesource, f); if (f <= 0) return true; float originalDamage = f; Function hardHat = f12 -> { - if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getItemStackFromSlot(EquipmentSlotType.HEAD).isEmpty()) { + if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && !this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) { return -(f12 - (f12 * 0.75F)); } return -0.0; @@ -692,17 +687,17 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt float hardHatModifier = hardHat.apply((double) f).floatValue(); f += hardHatModifier; - Function blocking = f13 -> -((this.canBlockDamageSource(damagesource)) ? f13 : 0.0); + Function blocking = f13 -> -((this.isDamageSourceBlocked(damagesource)) ? f13 : 0.0); float blockingModifier = blocking.apply((double) f).floatValue(); f += blockingModifier; - Function armor = f14 -> -(f14 - this.applyArmorCalculations(damagesource, f14.floatValue())); + Function armor = f14 -> -(f14 - this.getDamageAfterArmorAbsorb(damagesource, f14.floatValue())); float armorModifier = armor.apply((double) f).floatValue(); f += armorModifier; Function resistance = f15 -> { - if (!damagesource.isDamageAbsolute() && this.isPotionActive(Effects.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) { - int i = (this.getActivePotionEffect(Effects.RESISTANCE).getAmplifier() + 1) * 5; + if (!damagesource.isBypassMagic() && this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) { + int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = f15.floatValue() * (float) j; return -(f15 - (f1 / 25.0F)); @@ -712,7 +707,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt float resistanceModifier = resistance.apply((double) f).floatValue(); f += resistanceModifier; - Function magic = f16 -> -(f16 - this.applyPotionDamageCalculations(damagesource, f16.floatValue())); + Function magic = f16 -> -(f16 - this.getDamageAfterMagicAbsorb(damagesource, f16.floatValue())); float magicModifier = magic.apply((double) f).floatValue(); f += magicModifier; @@ -720,9 +715,8 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt float absorptionModifier = absorption.apply((double) f).floatValue(); EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent((LivingEntity) (Object) this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption); - - if (damagesource.getTrueSource() instanceof PlayerEntity) { - ((PlayerEntity) damagesource.getTrueSource()).resetCooldown(); + if (damagesource.getEntity() instanceof net.minecraft.world.entity.player.Player) { + ((net.minecraft.world.entity.player.Player) damagesource.getEntity()).resetAttackStrengthTicker(); } if (event.isCancelled()) { @@ -735,32 +729,30 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (event.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE) < 0) { float f3 = (float) -event.getDamage(EntityDamageEvent.DamageModifier.RESISTANCE); if (f3 > 0.0F && f3 < 3.4028235E37F) { - if ((Object) this instanceof ServerPlayerEntity) { - ((ServerPlayerEntity) (Object) this).addStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F)); - } else if (damagesource.getTrueSource() instanceof ServerPlayerEntity) { - ((ServerPlayerEntity) damagesource.getTrueSource()).addStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F)); + if ((Object) this instanceof ServerPlayer) { + ((ServerPlayer) (Object) this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f3 * 10.0F)); + } else if (damagesource.getEntity() instanceof ServerPlayer) { + ((ServerPlayer) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F)); } } } // Apply damage to helmet - if ((damagesource == DamageSource.ANVIL || damagesource == DamageSource.FALLING_BLOCK) && this.getItemStackFromSlot(EquipmentSlotType.HEAD) != null) { - this.getItemStackFromSlot(EquipmentSlotType.HEAD).damageItem((int) (event.getDamage() * 4.0F + this.rand.nextFloat() * event.getDamage() * 2.0F), (LivingEntity) (Object) this, (entityliving) -> { - entityliving.sendBreakAnimation(EquipmentSlotType.HEAD); - }); + if (damagesource.isDamageHelmet() && !this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) { + this.hurtHelmet(damagesource, f); } // Apply damage to armor - if (!damagesource.isUnblockable()) { + if (!damagesource.isBypassArmor()) { float armorDamage = (float) (event.getDamage() + event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) + event.getDamage(EntityDamageEvent.DamageModifier.HARD_HAT)); - this.damageArmor(damagesource, armorDamage); + this.hurtArmor(damagesource, armorDamage); } // Apply blocking code // PAIL: steal from above if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0) { - this.world.setEntityState((Entity) (Object) this, (byte) 29); // SPIGOT-4635 - shield damage sound - this.damageShield((float) -event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING)); - Entity entity = damagesource.getImmediateSource(); + this.level.broadcastEntityEvent((Entity) (Object) this, (byte) 29); // SPIGOT-4635 - shield damage sound + this.hurtCurrentlyUsedShield((float) -event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING)); + Entity entity = damagesource.getDirectEntity(); if (entity instanceof LivingEntity) { this.blockUsingShield(((LivingEntity) entity)); @@ -771,11 +763,11 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt this.setAbsorptionAmount(Math.max(this.getAbsorptionAmount() - absorptionModifier, 0.0F)); float f2 = absorptionModifier; - if (f2 > 0.0F && f2 < 3.4028235E37F && (Object) this instanceof PlayerEntity) { - ((PlayerEntity) (Object) this).addStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F)); + if (f2 > 0.0F && f2 < 3.4028235E37F && (Object) this instanceof net.minecraft.world.entity.player.Player) { + ((net.minecraft.world.entity.player.Player) (Object) this).awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F)); } - if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getTrueSource() instanceof PlayerEntity) { - ((PlayerEntity) damagesource.getTrueSource()).addStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F)); + if (f2 > 0.0F && f2 < 3.4028235E37F && damagesource.getEntity() instanceof net.minecraft.world.entity.player.Player) { + ((net.minecraft.world.entity.player.Player) damagesource.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f2 * 10.0F)); } f = net.minecraftforge.common.ForgeHooks.onLivingDamage((LivingEntity) (Object) this, damagesource, f); @@ -783,34 +775,36 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (f > 0 || !human) { if (human) { // PAIL: Be sure to drag all this code from the EntityHuman subclass each update. - ((PlayerEntity) (Object) this).addExhaustion(damagesource.getHungerDamage()); + ((PlayerEntityBridge) this).bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.DAMAGED); + ((net.minecraft.world.entity.player.Player) (Object) this).causeFoodExhaustion(damagesource.getFoodExhaustion()); if (f < 3.4028235E37F) { - ((PlayerEntity) (Object) this).addStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F)); + ((net.minecraft.world.entity.player.Player) (Object) this).awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F)); } } // CraftBukkit end float f3 = this.getHealth(); - this.getCombatTracker().trackDamage(damagesource, f3, f); + this.getCombatTracker().recordDamage(damagesource, f3, f); this.setHealth(f3 - f); // Forge: moved to fix MC-121048 // CraftBukkit start if (!human) { this.setAbsorptionAmount(this.getAbsorptionAmount() - f); } + this.gameEvent(GameEvent.ENTITY_DAMAGED, damagesource.getEntity()); return true; } else { // Duplicate triggers if blocking if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0) { - if ((Object) this instanceof ServerPlayerEntity) { - CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayerEntity) (Object) this, damagesource, f, originalDamage, true); + if ((Object) this instanceof ServerPlayer) { + CriteriaTriggers.ENTITY_HURT_PLAYER.trigger((ServerPlayer) (Object) this, damagesource, f, originalDamage, true); f2 = (float) (-event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING)); if (f2 > 0.0f && f2 < 3.4028235E37f) { - ((ServerPlayerEntity) (Object) this).addStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0f)); + ((ServerPlayer) (Object) this).awardStat(Stats.DAMAGE_BLOCKED_BY_SHIELD, Math.round(originalDamage * 10.0f)); } } - if (damagesource.getTrueSource() instanceof ServerPlayerEntity) { - CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayerEntity) damagesource.getTrueSource(), (Entity) (Object) this, damagesource, f, originalDamage, true); + if (damagesource.getEntity() instanceof ServerPlayer) { + CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayer) damagesource.getEntity(), (Entity) (Object) this, damagesource, f, originalDamage, true); } return false; @@ -830,7 +824,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt this.heal(healAmount); } - @Redirect(method = "heal", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setHealth(F)V")) + @Redirect(method = "heal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setHealth(F)V")) public void arclight$healEvent(LivingEntity livingEntity, float health) { EntityRegainHealthEvent.RegainReason regainReason = arclight$regainReason == null ? EntityRegainHealthEvent.RegainReason.CUSTOM : arclight$regainReason; arclight$regainReason = null; @@ -853,24 +847,24 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt private transient EntityPotionEffectEvent.Cause arclight$cause; - public boolean removeEffect(Effect effect, EntityPotionEffectEvent.Cause cause) { + public boolean removeEffect(MobEffect effect, EntityPotionEffectEvent.Cause cause) { bridge$pushEffectCause(cause); - return removePotionEffect(effect); + return removeEffect(effect); } @Override - public boolean bridge$removeEffect(Effect effect, EntityPotionEffectEvent.Cause cause) { + public boolean bridge$removeEffect(MobEffect effect, EntityPotionEffectEvent.Cause cause) { return removeEffect(effect, cause); } - public boolean addEffect(EffectInstance effect, EntityPotionEffectEvent.Cause cause) { + public boolean addEffect(MobEffectInstance effect, EntityPotionEffectEvent.Cause cause) { bridge$pushEffectCause(cause); - return this.addPotionEffect(effect); + return this.addEffect(effect, (Entity) null); } public boolean removeAllEffects(EntityPotionEffectEvent.Cause cause) { bridge$pushEffectCause(cause); - return this.clearActivePotions(); + return this.removeAllEffects(); } @Override @@ -893,17 +887,17 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt */ @Overwrite private boolean checkTotemDeathProtection(DamageSource damageSourceIn) { - if (damageSourceIn.canHarmInCreative()) { + if (damageSourceIn.isBypassInvul()) { return false; } else { - net.minecraft.item.ItemStack itemstack = null; + net.minecraft.world.item.ItemStack itemstack = null; - net.minecraft.item.ItemStack itemstack1 = null; - for (Hand hand : Hand.values()) { - itemstack1 = this.getHeldItem(hand); + net.minecraft.world.item.ItemStack itemstack1 = ItemStack.EMPTY; + for (InteractionHand hand : InteractionHand.values()) { + itemstack1 = this.getItemInHand(hand); if (itemstack1.getItem() == Items.TOTEM_OF_UNDYING) { itemstack = itemstack1.copy(); - itemstack1.shrink(1); + // itemstack1.shrink(1); break; } } @@ -916,47 +910,52 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (!itemstack1.isEmpty()) { itemstack1.shrink(1); } - if (itemstack != null && (Object) this instanceof ServerPlayerEntity) { - ServerPlayerEntity serverplayerentity = (ServerPlayerEntity) (Object) this; - serverplayerentity.addStat(Stats.ITEM_USED.get(Items.TOTEM_OF_UNDYING)); + if (itemstack != null && (Object) this instanceof ServerPlayer) { + ServerPlayer serverplayerentity = (ServerPlayer) (Object) this; + serverplayerentity.awardStat(Stats.ITEM_USED.get(Items.TOTEM_OF_UNDYING)); CriteriaTriggers.USED_TOTEM.trigger(serverplayerentity, itemstack); } this.setHealth(1.0F); - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TOTEM); - this.clearActivePotions(); - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TOTEM); - this.addPotionEffect(new EffectInstance(Effects.REGENERATION, 900, 1)); - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TOTEM); - this.addPotionEffect(new EffectInstance(Effects.ABSORPTION, 100, 1)); - bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TOTEM); - this.addPotionEffect(new EffectInstance(Effects.FIRE_RESISTANCE, 800, 1)); - this.world.setEntityState((Entity) (Object) this, (byte) 35); + this.removeAllEffects(EntityPotionEffectEvent.Cause.TOTEM); + this.addEffect(new MobEffectInstance(MobEffects.REGENERATION, 900, 1), EntityPotionEffectEvent.Cause.TOTEM);bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TOTEM); + this.addEffect(new MobEffectInstance(MobEffects.ABSORPTION, 100, 1), EntityPotionEffectEvent.Cause.TOTEM); + this.addEffect(new MobEffectInstance(MobEffects.FIRE_RESISTANCE, 800, 1), EntityPotionEffectEvent.Cause.TOTEM); + this.level.broadcastEntityEvent((Entity) (Object) this, (byte) 35); } return !event.isCancelled(); } } - @Redirect(method = "applyArmorCalculations", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;damageArmor(Lnet/minecraft/util/DamageSource;F)V")) - public void arclight$muteDamageArmor(LivingEntity entity, DamageSource damageSource, float damage) { - } - - @Redirect(method = "applyPotionDamageCalculations", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isPotionActive(Lnet/minecraft/potion/Effect;)Z")) - public boolean arclight$mutePotion(LivingEntity livingEntity, Effect potionIn) { - return false; - } - - @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setFlag(IZ)V")) - public void arclight$stopGlide(LivingEntity livingEntity, int flag, boolean set) { - if (set != livingEntity.getFlag(flag) && !CraftEventFactory.callToggleGlideEvent(livingEntity, set).isCancelled()) { - livingEntity.setFlag(flag, set); + @Inject(method = "createWitherRose", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$witherRoseDrop(LivingEntity livingEntity, CallbackInfo ci, ItemEntity itemEntity) { + org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) (((EntityBridge) itemEntity).bridge$getBukkitEntity())); + CraftEventFactory.callEvent(event); + if (event.isCancelled()) { + ci.cancel(); } } - @Redirect(method = "updateElytra", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setFlag(IZ)V")) + @Redirect(method = "getDamageAfterArmorAbsorb", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurtArmor(Lnet/minecraft/world/damagesource/DamageSource;F)V")) + public void arclight$muteDamageArmor(LivingEntity entity, DamageSource damageSource, float damage) { + } + + @Redirect(method = "getDamageAfterMagicAbsorb", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hasEffect(Lnet/minecraft/world/effect/MobEffect;)Z")) + public boolean arclight$mutePotion(LivingEntity livingEntity, MobEffect potionIn) { + return false; + } + + @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V")) + public void arclight$stopGlide(LivingEntity livingEntity, int flag, boolean set) { + if (set != livingEntity.getSharedFlag(flag) && !CraftEventFactory.callToggleGlideEvent(livingEntity, set).isCancelled()) { + livingEntity.setSharedFlag(flag, set); + } + } + + @Redirect(method = "updateFallFlying", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setSharedFlag(IZ)V")) public void arclight$toggleGlide(LivingEntity livingEntity, int flag, boolean set) { - if (set != livingEntity.getFlag(flag) && !CraftEventFactory.callToggleGlideEvent(livingEntity, set).isCancelled()) { - livingEntity.setFlag(flag, set); + if (set != livingEntity.getSharedFlag(flag) && !CraftEventFactory.callToggleGlideEvent(livingEntity, set).isCancelled()) { + livingEntity.setSharedFlag(flag, set); } } @@ -965,8 +964,8 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt * @reason */ @Overwrite - public boolean canBeCollidedWith() { - return !this.removed && this.collides; + public boolean isPickable() { + return !this.isRemoved() && this.collides; } /** @@ -974,17 +973,17 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt * @reason */ @Overwrite - public boolean canBePushed() { - return this.isAlive() && !this.isOnLadder() && this.collides; + public boolean isPushable() { + return this.isAlive() && !this.onClimbable() && this.collides; } @Override public boolean canCollideWith(Entity entity) { - return this.canBePushed() && this.collides != this.collidableExemptions.contains(entity.getUniqueID()); + return this.isPushable() && this.collides != this.collidableExemptions.contains(entity.getUUID()); } - @Eject(method = "onItemUseFinish", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;onItemUseFinish(Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;")) - private ItemStack arclight$itemConsume(ItemStack itemStack, World worldIn, LivingEntity entityLiving, CallbackInfo ci) { + @Eject(method = "completeUsingItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;finishUsingItem(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;)Lnet/minecraft/world/item/ItemStack;")) + private ItemStack arclight$itemConsume(ItemStack itemStack, Level worldIn, LivingEntity entityLiving, CallbackInfo ci) { if (this instanceof ServerPlayerEntityBridge) { final org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(itemStack); final PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem); @@ -995,33 +994,33 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt ci.cancel(); return null; } else if (!craftItem.equals(event.getItem())) { - return CraftItemStack.asNMSCopy(event.getItem()).onItemUseFinish(worldIn, entityLiving); + return CraftItemStack.asNMSCopy(event.getItem()).finishUsingItem(worldIn, entityLiving); } } - return itemStack.onItemUseFinish(worldIn, entityLiving); + return itemStack.finishUsingItem(worldIn, entityLiving); } - @Eject(method = "attemptTeleport", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/LivingEntity;setPositionAndUpdate(DDD)V")) + @Eject(method = "randomTeleport", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/LivingEntity;teleportTo(DDD)V")) private void arclight$entityTeleport(LivingEntity entity, double x, double y, double z, CallbackInfoReturnable cir) { - EntityTeleportEvent event = new EntityTeleportEvent(getBukkitEntity(), new Location(((WorldBridge) this.world).bridge$getWorld(), this.getPosX(), this.getPosY(), this.getPosZ()), - new Location(((WorldBridge) this.world).bridge$getWorld(), x, y, z)); + EntityTeleportEvent event = new EntityTeleportEvent(getBukkitEntity(), new Location(((WorldBridge) this.level).bridge$getWorld(), this.getX(), this.getY(), this.getZ()), + new Location(((WorldBridge) this.level).bridge$getWorld(), x, y, z)); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - this.setPositionAndUpdate(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); + this.teleportTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()); } else { - this.setPositionAndUpdate(this.getPosX(), this.getPosY(), this.getPosZ()); + this.teleportTo(this.getX(), this.getY(), this.getZ()); cir.setReturnValue(false); } } - @Redirect(method = "spawnDrops", at = @At(value = "INVOKE", ordinal = 0, remap = false, target = "Lnet/minecraft/entity/LivingEntity;captureDrops(Ljava/util/Collection;)Ljava/util/Collection;")) + @Redirect(method = "dropAllDeathLoot", at = @At(value = "INVOKE", ordinal = 0, remap = false, target = "Lnet/minecraft/world/entity/LivingEntity;captureDrops(Ljava/util/Collection;)Ljava/util/Collection;")) private Collection arclight$captureIfNeed(LivingEntity livingEntity, Collection value) { Collection drops = livingEntity.captureDrops(); // todo this instanceof ArmorStandEntity return drops == null ? livingEntity.captureDrops(value) : drops; } - @Redirect(method = "spawnDrops", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Collection;forEach(Ljava/util/function/Consumer;)V")) + @Redirect(method = "dropAllDeathLoot", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Collection;forEach(Ljava/util/function/Consumer;)V")) private void arclight$cancelEvent(Collection collection, Consumer action) { if (this instanceof ServerPlayerEntityBridge) { // recapture for ServerPlayerEntityMixin#onDeath @@ -1031,15 +1030,8 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt } } - @Inject(method = "canEntityBeSeen", cancellable = true, at = @At("HEAD")) - private void arclight$seeNoEvil(Entity entityIn, CallbackInfoReturnable cir) { - if (this.world != entityIn.world) { - cir.setReturnValue(false); - } - } - - @Inject(method = "applyFoodEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - public void arclight$foodEffectCause(ItemStack p_213349_1_, World p_213349_2_, LivingEntity livingEntity, CallbackInfo ci) { + @Inject(method = "addEatEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + public void arclight$foodEffectCause(ItemStack p_213349_1_, Level p_213349_2_, LivingEntity livingEntity, CallbackInfo ci) { ((LivingEntityBridge) livingEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.FOOD); } @@ -1059,7 +1051,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt } @Override - public boolean bridge$addEffect(EffectInstance effect, EntityPotionEffectEvent.Cause cause) { + public boolean bridge$addEffect(MobEffectInstance effect, EntityPotionEffectEvent.Cause cause) { return addEffect(effect, cause); } @@ -1072,7 +1064,7 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt } } - @Inject(method = "setArrowCountInEntity", cancellable = true, at = @At("HEAD")) + @Inject(method = "setArrowCount", cancellable = true, at = @At("HEAD")) private void arclight$onArrowChange(int count, CallbackInfo ci) { if (arclight$callArrowCountChange(count, false)) { ci.cancel(); @@ -1083,25 +1075,25 @@ public abstract class LivingEntityMixin extends EntityMixin implements LivingEnt if (arclight$callArrowCountChange(count, reset)) { return; } - this.dataManager.set(ARROW_COUNT_IN_ENTITY, count); + this.entityData.set(DATA_ARROW_COUNT_ID, count); } private boolean arclight$callArrowCountChange(int newCount, boolean reset) { - return CraftEventFactory.callArrowBodyCountChangeEvent((LivingEntity) (Object) this, this.getArrowCountInEntity(), newCount, reset).isCancelled(); + return CraftEventFactory.callArrowBodyCountChangeEvent((LivingEntity) (Object) this, this.getArrowCount(), newCount, reset).isCancelled(); } - public void setSlot(EquipmentSlotType slotIn, ItemStack stack, boolean silent) { - this.setItemStackToSlot(slotIn, stack); + public void setSlot(EquipmentSlot slotIn, ItemStack stack, boolean silent) { + this.setItemSlot(slotIn, stack); } @Override - public void bridge$setSlot(EquipmentSlotType slotIn, ItemStack stack, boolean silent) { + public void bridge$setSlot(EquipmentSlot slotIn, ItemStack stack, boolean silent) { this.setSlot(slotIn, stack, silent); } protected void playEquipSound(ItemStack stack, boolean silent) { if (!silent) { - this.playEquipSound(stack); + this.equipEventAndSound(stack); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/MobEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/MobEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java index 719c8f87..45ec2227 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/MobEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java @@ -1,4 +1,4 @@ -package io.izzel.arclight.common.mixin.core.entity; +package io.izzel.arclight.common.mixin.core.world.entity; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; @@ -6,21 +6,20 @@ import io.izzel.arclight.common.bridge.entity.MobEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.network.play.server.SMountEntityPacket; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.ForgeHooks; import org.apache.logging.log4j.Level; import org.bukkit.Bukkit; @@ -33,8 +32,6 @@ import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.bukkit.event.entity.EntityUnleashEvent; import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Implements; -import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @@ -46,30 +43,30 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import javax.annotation.Nullable; -@Mixin(MobEntity.class) -@Implements(@Interface(iface = MobEntityBridge.Hack.class, prefix = "hack$")) -public abstract class MobEntityMixin extends LivingEntityMixin implements MobEntityBridge { +import static net.minecraft.world.entity.LivingEntity.getEquipmentSlotForItem; + +@Mixin(Mob.class) +public abstract class MobMixin extends LivingEntityMixin implements MobEntityBridge { // @formatter:off @Shadow public boolean persistenceRequired; - @Shadow public abstract boolean canDespawn(double distanceToClosestPlayer); - @Shadow @Nullable public abstract LivingEntity getAttackTarget(); - @Shadow private LivingEntity attackTarget; - @Shadow protected abstract ResourceLocation shadow$getLootTable(); - @Shadow public static EquipmentSlotType getSlotForItemStack(ItemStack stack) { return null; } - @Shadow public abstract ItemStack getItemStackFromSlot(EquipmentSlotType slotIn); - @Shadow public abstract boolean canEquipItem(ItemStack stack); - @Shadow protected abstract float getDropChance(EquipmentSlotType slotIn); - @Shadow public abstract void setItemStackToSlot(EquipmentSlotType slotIn, ItemStack stack); - @Shadow @Final public float[] inventoryHandsDropChances; - @Shadow @Final public float[] inventoryArmorDropChances; + @Shadow public abstract boolean removeWhenFarAway(double distanceToClosestPlayer); + @Shadow @Nullable public abstract LivingEntity getTarget(); + @Shadow private LivingEntity target; + @Shadow protected abstract ResourceLocation getDefaultLootTable(); + @Shadow public abstract ItemStack getItemBySlot(EquipmentSlot slotIn); + @Shadow public abstract boolean canHoldItem(ItemStack stack); + @Shadow protected abstract float getEquipmentDropChance(EquipmentSlot slotIn); + @Shadow public abstract void setItemSlot(EquipmentSlot slotIn, ItemStack stack); + @Shadow @Final public float[] handDropChances; + @Shadow @Final public float[] armorDropChances; @Shadow @Nullable public abstract Entity getLeashHolder(); - @Shadow public abstract boolean isNoDespawnRequired(); - @Shadow protected void updateAITasks() { } - @Shadow public abstract boolean isAIDisabled(); - @Shadow protected abstract boolean shouldExchangeEquipment(ItemStack candidate, ItemStack existing); - @Shadow protected abstract void func_233657_b_(EquipmentSlotType p_233657_1_, ItemStack p_233657_2_); - @Shadow @Nullable public abstract T func_233656_b_(EntityType p_233656_1_, boolean p_233656_2_); + @Shadow public abstract boolean isPersistenceRequired(); + @Shadow protected void customServerAiStep() { } + @Shadow public abstract boolean isNoAi(); + @Shadow protected abstract boolean canReplaceCurrentItem(ItemStack candidate, ItemStack existing); + @Shadow protected abstract void setItemSlotAndDropWhenKilled(EquipmentSlot p_233657_1_, ItemStack p_233657_2_); + @Shadow @Nullable public abstract T convertTo(EntityType p_233656_1_, boolean p_233656_2_); // @formatter:on public boolean aware; @@ -94,8 +91,8 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt } @Inject(method = "", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { - this.persistenceRequired = !this.canDespawn(0.0); + private void arclight$init(EntityType type, net.minecraft.world.level.Level worldIn, CallbackInfo ci) { + this.persistenceRequired = !this.removeWhenFarAway(0.0); this.aware = true; } @@ -108,18 +105,18 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt * @reason */ @Overwrite - public void setAttackTarget(@Nullable LivingEntity livingEntity) { + public void setTarget(@Nullable LivingEntity livingEntity) { boolean fireEvent = arclight$fireEvent; arclight$fireEvent = false; EntityTargetEvent.TargetReason reason = arclight$reason == null ? EntityTargetEvent.TargetReason.UNKNOWN : arclight$reason; arclight$reason = null; - if (getAttackTarget() == livingEntity) { + if (getTarget() == livingEntity) { arclight$targetSuccess = false; return; } if (fireEvent) { - if (reason == EntityTargetEvent.TargetReason.UNKNOWN && this.getAttackTarget() != null && livingEntity == null) { - reason = (this.getAttackTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED); + if (reason == EntityTargetEvent.TargetReason.UNKNOWN && this.getTarget() != null && livingEntity == null) { + reason = (this.getTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED); } if (reason == EntityTargetEvent.TargetReason.UNKNOWN) { ArclightMod.LOGGER.log(Level.WARN, "Unknown target reason setting {} target to {}", this, livingEntity); @@ -140,14 +137,14 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt livingEntity = null; } } - this.attackTarget = livingEntity; - ForgeHooks.onLivingSetAttackTarget((MobEntity) (Object) this, this.attackTarget); + this.target = livingEntity; + ForgeHooks.onLivingSetAttackTarget((Mob) (Object) this, this.target); arclight$targetSuccess = true; } public boolean setGoalTarget(LivingEntity livingEntity, EntityTargetEvent.TargetReason reason, boolean fireEvent) { bridge$pushGoalTargetReason(reason, fireEvent); - setAttackTarget(livingEntity); + setTarget(livingEntity); return arclight$targetSuccess; } @@ -171,37 +168,37 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt arclight$fireEvent = fireEvent; } - @Inject(method = "writeAdditional", at = @At("HEAD")) - private void arclight$setAware(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "addAdditionalSaveData", at = @At("HEAD")) + private void arclight$setAware(CompoundTag compound, CallbackInfo ci) { compound.putBoolean("Bukkit.Aware", this.aware); } - @Inject(method = "readAdditional", at = @At("HEAD")) - private void arclight$readAware(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "readAdditionalSaveData", at = @At("HEAD")) + private void arclight$readAware(CompoundTag compound, CallbackInfo ci) { if (compound.contains("Bukkit.Aware")) { this.aware = compound.getBoolean("Bukkit.Aware"); } } - @Redirect(method = "readAdditional", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setCanPickUpLoot(Z)V")) - public void arclight$setIfTrue(MobEntity mobEntity, boolean canPickup) { + @Redirect(method = "readAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;setCanPickUpLoot(Z)V")) + public void arclight$setIfTrue(Mob mobEntity, boolean canPickup) { if (canPickup) mobEntity.setCanPickUpLoot(true); } - @Redirect(method = "readAdditional", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/nbt/CompoundNBT;getBoolean(Ljava/lang/String;)Z")) - public boolean arclight$setIfTrue(CompoundNBT nbt, String key) { + @Redirect(method = "readAdditionalSaveData", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/nbt/CompoundTag;getBoolean(Ljava/lang/String;)Z")) + public boolean arclight$setIfTrue(CompoundTag nbt, String key) { return nbt.getBoolean(key) || this.persistenceRequired; } - @Inject(method = "updateEntityActionState", cancellable = true, at = @At("HEAD")) + @Inject(method = "serverAiStep", cancellable = true, at = @At("HEAD")) private void arclight$unaware(CallbackInfo ci) { if (!this.aware) { - ++this.idleTime; + ++this.noActionTime; ci.cancel(); } } - @Inject(method = "updateEquipmentIfNeeded", at = @At("HEAD")) + @Inject(method = "pickUpItem", at = @At("HEAD")) private void arclight$captureItemEntity(ItemEntity itemEntity, CallbackInfo ci) { arclight$item = itemEntity; } @@ -218,101 +215,101 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt * @reason */ @Overwrite - public boolean func_233665_g_(ItemStack p_233665_1_) { + public boolean equipItemIfPossible(ItemStack stack) { ItemEntity itemEntity = arclight$item; arclight$item = null; - EquipmentSlotType equipmentslottype = getSlotForItemStack(p_233665_1_); - ItemStack itemstack = this.getItemStackFromSlot(equipmentslottype); - boolean flag = this.shouldExchangeEquipment(p_233665_1_, itemstack); - boolean canPickup = flag && this.canEquipItem(p_233665_1_); + EquipmentSlot equipmentslottype = getEquipmentSlotForItem(stack); + ItemStack itemstack = this.getItemBySlot(equipmentslottype); + boolean flag = this.canReplaceCurrentItem(stack, itemstack); + boolean canPickup = flag && this.canHoldItem(stack); if (itemEntity != null) { - canPickup = !CraftEventFactory.callEntityPickupItemEvent((MobEntity) (Object) this, itemEntity, 0, !canPickup).isCancelled(); + canPickup = !CraftEventFactory.callEntityPickupItemEvent((Mob) (Object) this, itemEntity, 0, !canPickup).isCancelled(); } if (canPickup) { - double d0 = this.getDropChance(equipmentslottype); - if (!itemstack.isEmpty() && (double) Math.max(this.rand.nextFloat() - 0.1F, 0.0F) < d0) { + double d0 = this.getEquipmentDropChance(equipmentslottype); + if (!itemstack.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) { forceDrops = true; - this.entityDropItem(itemstack); + this.spawnAtLocation(itemstack); forceDrops = false; } - this.func_233657_b_(equipmentslottype, p_233665_1_); - this.playEquipSound(p_233665_1_); + this.setItemSlotAndDropWhenKilled(equipmentslottype, stack); + this.equipEventAndSound(stack); return true; } else { return false; } } - @Redirect(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;canDespawn(D)Z")) - public boolean arclight$checkDespawn(MobEntity mobEntity, double distanceToClosestPlayer) { + @Redirect(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;removeWhenFarAway(D)Z")) + public boolean arclight$checkDespawn(Mob mobEntity, double distanceToClosestPlayer) { return true; } - @Inject(method = "processInitialInteract", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;clearLeashed(ZZ)V")) - private void arclight$unleash(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (CraftEventFactory.callPlayerUnleashEntityEvent((MobEntity) (Object) this, player).isCancelled()) { - ((ServerPlayerEntity) player).connection.sendPacket(new SMountEntityPacket((MobEntity) (Object) this, this.getLeashHolder())); - cir.setReturnValue(ActionResultType.PASS); + @Inject(method = "interact", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;dropLeash(ZZ)V")) + private void arclight$unleash(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + if (CraftEventFactory.callPlayerUnleashEntityEvent((Mob) (Object) this, player).isCancelled()) { + ((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket((Mob) (Object) this, this.getLeashHolder())); + cir.setReturnValue(InteractionResult.PASS); } } - @Inject(method = "processInteract", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setLeashHolder(Lnet/minecraft/entity/Entity;Z)V")) - private void arclight$leash(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (CraftEventFactory.callPlayerLeashEntityEvent((MobEntity) (Object) this, player, player).isCancelled()) { - ((ServerPlayerEntity) player).connection.sendPacket(new SMountEntityPacket((MobEntity) (Object) this, this.getLeashHolder())); - cir.setReturnValue(ActionResultType.PASS); + @Inject(method = "checkAndHandleImportantInteractions", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;setLeashedTo(Lnet/minecraft/world/entity/Entity;Z)V")) + private void arclight$leash(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + if (CraftEventFactory.callPlayerLeashEntityEvent((Mob) (Object) this, player, player).isCancelled()) { + ((ServerPlayer) player).connection.send(new ClientboundSetEntityLinkPacket((Mob) (Object) this, this.getLeashHolder())); + cir.setReturnValue(InteractionResult.PASS); } } - @Inject(method = "updateLeashedState", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;clearLeashed(ZZ)V")) + @Inject(method = "tickLeash", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;dropLeash(ZZ)V")) public void arclight$unleash2(CallbackInfo ci) { Bukkit.getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), this.isAlive() ? EntityUnleashEvent.UnleashReason.HOLDER_GONE : EntityUnleashEvent.UnleashReason.PLAYER_UNLEASH)); } - @Inject(method = "clearLeashed", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/MobEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;)Lnet/minecraft/entity/item/ItemEntity;")) + @Inject(method = "dropLeash", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;")) public void arclight$leashDropPost(boolean sendPacket, boolean dropLead, CallbackInfo ci) { this.forceDrops = false; } - @Inject(method = "clearLeashed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;)Lnet/minecraft/entity/item/ItemEntity;")) + @Inject(method = "dropLeash", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;")) public void arclight$leashDropPre(boolean sendPacket, boolean dropLead, CallbackInfo ci) { this.forceDrops = true; } - @Inject(method = "startRiding", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;clearLeashed(ZZ)V")) + @Inject(method = "startRiding", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;dropLeash(ZZ)V")) private void arclight$unleashRide(Entity entityIn, boolean force, CallbackInfoReturnable cir) { Bukkit.getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN)); } - @Inject(method = "setDead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;clearLeashed(ZZ)V")) + @Inject(method = "removeAfterChangingDimensions", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;dropLeash(ZZ)V")) private void arclight$unleashDead(CallbackInfo ci) { Bukkit.getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN)); } - @Eject(method = "func_233656_b_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$copySpawn(World world, Entity entityIn, CallbackInfoReturnable cir) { + @Eject(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$copySpawn(net.minecraft.world.level.Level world, Entity entityIn, CallbackInfoReturnable cir) { EntityTransformEvent.TransformReason transformReason = arclight$transform == null ? EntityTransformEvent.TransformReason.UNKNOWN : arclight$transform; arclight$transform = null; - if (CraftEventFactory.callEntityTransformEvent((MobEntity) (Object) this, (LivingEntity) entityIn, transformReason).isCancelled()) { + if (CraftEventFactory.callEntityTransformEvent((Mob) (Object) this, (LivingEntity) entityIn, transformReason).isCancelled()) { cir.setReturnValue(null); return false; } else { - return world.addEntity(entityIn); + return world.addFreshEntity(entityIn); } } - @Inject(method = "func_233656_b_", at = @At("RETURN")) - private void arclight$cleanReason(EntityType p_233656_1_, boolean p_233656_2_, CallbackInfoReturnable cir) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(null); + @Inject(method = "convertTo", at = @At("RETURN")) + private void arclight$cleanReason(EntityType p_233656_1_, boolean p_233656_2_, CallbackInfoReturnable cir) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(null); this.arclight$transform = null; } - public T a(EntityType entityType, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(spawnReason); + public T a(EntityType entityType, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(spawnReason); bridge$pushTransformReason(transformReason); - return this.func_233656_b_(entityType, flag); + return this.convertTo(entityType, flag); } private transient EntityTransformEvent.TransformReason arclight$transform; @@ -322,7 +319,7 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt this.arclight$transform = transformReason; } - @Redirect(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setFire(I)V")) + @Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) public void arclight$attackCombust(Entity entity, int seconds) { EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); @@ -331,13 +328,9 @@ public abstract class MobEntityMixin extends LivingEntityMixin implements MobEnt } } - public ResourceLocation hack$getLootTable() { - return this.shadow$getLootTable(); - } - @Override public ResourceLocation bridge$getLootTable() { - return this.hack$getLootTable(); + return this.getDefaultLootTable(); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/CreatureEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/PathfinderMobMixin.java similarity index 60% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/CreatureEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/PathfinderMobMixin.java index 807500cd..f22c61d3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/CreatureEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/PathfinderMobMixin.java @@ -1,6 +1,6 @@ -package io.izzel.arclight.common.mixin.core.entity; +package io.izzel.arclight.common.mixin.core.world.entity; -import net.minecraft.entity.CreatureEntity; +import net.minecraft.world.entity.PathfinderMob; import org.bukkit.Bukkit; import org.bukkit.event.entity.EntityUnleashEvent; import org.spongepowered.asm.mixin.Mixin; @@ -8,10 +8,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(CreatureEntity.class) -public abstract class CreatureEntityMixin extends MobEntityMixin { +@Mixin(PathfinderMob.class) +public abstract class PathfinderMobMixin extends MobMixin { - @Inject(method = "updateLeashedState", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/CreatureEntity;clearLeashed(ZZ)V")) + @Inject(method = "tickLeash", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/PathfinderMob;dropLeash(ZZ)V")) private void arclight$unleashDistance(CallbackInfo ci) { Bukkit.getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.DISTANCE)); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/attributes/RangedAttributeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/attributes/RangedAttributeMixin.java similarity index 69% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/attributes/RangedAttributeMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/attributes/RangedAttributeMixin.java index d74ad09a..0d089028 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/attributes/RangedAttributeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/attributes/RangedAttributeMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.attributes; +package io.izzel.arclight.common.mixin.core.world.entity.ai.attributes; import io.izzel.arclight.common.bridge.entity.ai.attributes.RangedAttributeBridge; -import net.minecraft.entity.ai.attributes.Attribute; -import net.minecraft.entity.ai.attributes.RangedAttribute; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.RangedAttribute; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; @@ -13,14 +13,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public abstract class RangedAttributeMixin extends Attribute implements RangedAttributeBridge { // @formatter:off - @Override @Accessor("maximumValue") public abstract void bridge$setMaximumValue(double maximumValue); + @Override @Accessor("maxValue") public abstract void bridge$setMaximumValue(double maximumValue); // @formatter:on protected RangedAttributeMixin(String attributeName, double defaultValue) { super(attributeName, defaultValue); } - @Inject(method = "clampValue", cancellable = true, at = @At("HEAD")) + @Inject(method = "sanitizeValue", cancellable = true, at = @At("HEAD")) private void arclight$notNan(double value, CallbackInfoReturnable cir) { if (Double.isNaN(value)) { cir.setReturnValue(this.getDefaultValue()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/AssignProfessionTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/AssignProfessionFromJobSiteMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/AssignProfessionTaskMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/AssignProfessionFromJobSiteMixin.java index 7c469c70..56be5e85 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/AssignProfessionTaskMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/AssignProfessionFromJobSiteMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; -import net.minecraft.entity.ai.brain.memory.MemoryModuleType; -import net.minecraft.entity.ai.brain.task.AssignProfessionTask; -import net.minecraft.entity.merchant.villager.VillagerData; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.entity.merchant.villager.VillagerProfession; +import net.minecraft.core.GlobalPos; +import net.minecraft.core.Registry; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.GlobalPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ai.behavior.AssignProfessionFromJobSite; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.entity.npc.VillagerData; +import net.minecraft.world.entity.npc.VillagerProfession; import org.bukkit.craftbukkit.v.entity.CraftVillager; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.VillagerCareerChangeEvent; @@ -17,33 +17,33 @@ import org.spongepowered.asm.mixin.Overwrite; import java.util.Optional; -@Mixin(AssignProfessionTask.class) -public class AssignProfessionTaskMixin { +@Mixin(AssignProfessionFromJobSite.class) +public class AssignProfessionFromJobSiteMixin { /** * @author IzzelAliz * @reason */ @Overwrite - protected void startExecuting(ServerWorld worldIn, VillagerEntity entityIn, long gameTimeIn) { + protected void start(ServerLevel worldIn, Villager entityIn, long gameTimeIn) { GlobalPos globalpos = entityIn.getBrain().getMemory(MemoryModuleType.POTENTIAL_JOB_SITE).get(); - entityIn.getBrain().removeMemory(MemoryModuleType.POTENTIAL_JOB_SITE); + entityIn.getBrain().eraseMemory(MemoryModuleType.POTENTIAL_JOB_SITE); entityIn.getBrain().setMemory(MemoryModuleType.JOB_SITE, globalpos); - worldIn.setEntityState(entityIn, (byte) 14); + worldIn.broadcastEntityEvent(entityIn, (byte) 14); if (entityIn.getVillagerData().getProfession() == VillagerProfession.NONE) { MinecraftServer minecraftserver = worldIn.getServer(); - Optional.ofNullable(minecraftserver.getWorld(globalpos.getDimension())).flatMap((world) -> { - return world.getPointOfInterestManager().getType(globalpos.getPos()); + Optional.ofNullable(minecraftserver.getLevel(globalpos.dimension())).flatMap((world) -> { + return world.getPoiManager().getType(globalpos.pos()); }).flatMap((poiType) -> { return Registry.VILLAGER_PROFESSION.stream().filter((profession) -> { - return profession.getPointOfInterest() == poiType; + return profession.getJobPoiType() == poiType; }).findFirst(); }).ifPresent((profession) -> { VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(entityIn, CraftVillager.nmsToBukkitProfession(profession), VillagerCareerChangeEvent.ChangeReason.EMPLOYED); if (!event.isCancelled()) { - VillagerData newData = entityIn.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())); + VillagerData newData = entityIn.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())); entityIn.setVillagerData(newData); - entityIn.resetBrain(worldIn); + entityIn.refreshBrain(worldIn); } }); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/HarvestFarmlandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/HarvestFarmlandMixin.java new file mode 100644 index 00000000..18cb591a --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/HarvestFarmlandMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; + +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 io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ai.behavior.HarvestFarmland; +import net.minecraft.world.entity.npc.Villager; + +@Mixin(HarvestFarmland.class) +public abstract class HarvestFarmlandMixin { + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void on(ServerLevel worldIn, Villager owner, long gameTime, CallbackInfo ci) { + ArclightCaptures.captureEntityChangeBlock(owner); + } + +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/InteractWithDoorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/InteractWithDoorMixin.java new file mode 100644 index 00000000..9aada110 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/InteractWithDoorMixin.java @@ -0,0 +1,75 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.BlockTags; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.behavior.InteractWithDoor; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.pathfinder.Node; +import net.minecraft.world.level.pathfinder.Path; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.event.entity.EntityInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import javax.annotation.Nullable; + +@Mixin(InteractWithDoor.class) +public abstract class InteractWithDoorMixin { + + // @formatter:off + @Shadow @Nullable private Node lastCheckedNode; + @Shadow protected abstract void rememberDoorToClose(ServerLevel p_242301_1_, LivingEntity p_242301_2_, BlockPos p_242301_3_); + @Shadow public static void closeDoorsThatIHaveOpenedOrPassedThrough(ServerLevel p_242294_0_, LivingEntity p_242294_1_, @org.jetbrains.annotations.Nullable Node p_242294_2_, @org.jetbrains.annotations.Nullable Node p_242294_3_) { } + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void start(ServerLevel worldIn, LivingEntity entityIn, long gameTimeIn) { + Path path = entityIn.getBrain().getMemory(MemoryModuleType.PATH).get(); + this.lastCheckedNode = path.getNextNode(); + Node pathpoint = path.getPreviousNode(); + Node pathpoint1 = path.getNextNode(); + BlockPos blockpos = pathpoint.asBlockPos(); + BlockState blockstate = worldIn.getBlockState(blockpos); + if (blockstate.is(BlockTags.WOODEN_DOORS)) { + DoorBlock doorblock = (DoorBlock) blockstate.getBlock(); + if (!doorblock.isOpen(blockstate)) { + EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.level, blockpos)); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + doorblock.setOpen(entityIn, worldIn, blockstate, blockpos, true); + } + + this.rememberDoorToClose(worldIn, entityIn, blockpos); + } + + BlockPos blockpos1 = pathpoint1.asBlockPos(); + BlockState blockstate1 = worldIn.getBlockState(blockpos1); + if (blockstate1.is(BlockTags.WOODEN_DOORS)) { + DoorBlock doorblock1 = (DoorBlock) blockstate1.getBlock(); + if (!doorblock1.isOpen(blockstate1)) { + EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(entityIn.level, blockpos)); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + doorblock1.setOpen(entityIn, worldIn, blockstate1, blockpos1, true); + this.rememberDoorToClose(worldIn, entityIn, blockpos1); + } + } + + closeDoorsThatIHaveOpenedOrPassedThrough(worldIn, entityIn, pathpoint, pathpoint1); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ChangeJobTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/ResetProfessionMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ChangeJobTaskMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/ResetProfessionMixin.java index 17dbd68e..52ad0d79 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ChangeJobTaskMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/ResetProfessionMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; -import net.minecraft.entity.ai.brain.task.ChangeJobTask; -import net.minecraft.entity.merchant.villager.VillagerData; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.entity.merchant.villager.VillagerProfession; +import net.minecraft.world.entity.ai.behavior.ResetProfession; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.entity.npc.VillagerData; +import net.minecraft.world.entity.npc.VillagerProfession; import org.bukkit.craftbukkit.v.entity.CraftVillager; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.VillagerCareerChangeEvent; @@ -11,16 +11,16 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(ChangeJobTask.class) -public class ChangeJobTaskMixin { +@Mixin(ResetProfession.class) +public class ResetProfessionMixin { - @Redirect(method = "startExecuting", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;setVillagerData(Lnet/minecraft/entity/merchant/villager/VillagerData;)V")) - private void arclight$careerChangeHook(VillagerEntity villagerEntity, VillagerData villagerData) { + @Redirect(method = "start", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/npc/Villager;setVillagerData(Lnet/minecraft/world/entity/npc/VillagerData;)V")) + private void arclight$careerChangeHook(Villager villagerEntity, VillagerData villagerData) { VillagerCareerChangeEvent event = CraftEventFactory.callVillagerCareerChangeEvent(villagerEntity, CraftVillager.nmsToBukkitProfession(VillagerProfession.NONE), VillagerCareerChangeEvent.ChangeReason.LOSING_JOB); // 这里本来是 EMPLOYED 但是我怀疑他打错了 if (!event.isCancelled()) { - VillagerData newData = villagerEntity.getVillagerData().withProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())); + VillagerData newData = villagerEntity.getVillagerData().setProfession(CraftVillager.bukkitToNmsProfession(event.getProfession())); villagerEntity.setVillagerData(newData); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ForgetAttackTargetTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StartAttackingMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ForgetAttackTargetTaskMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StartAttackingMixin.java index 24878fee..9c879011 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/ForgetAttackTargetTaskMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StartAttackingMixin.java @@ -1,31 +1,31 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.brain.memory.MemoryModuleType; -import net.minecraft.entity.ai.brain.task.ForgetAttackTargetTask; -import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.behavior.StartAttacking; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; -@Mixin(ForgetAttackTargetTask.class) -public class ForgetAttackTargetTaskMixin { +@Mixin(StartAttacking.class) +public class StartAttackingMixin { /** * @author IzzelAliz * @reason */ @Overwrite - private void func_233976_a_(E mob, LivingEntity livingEntity) { - EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(mob, livingEntity, (livingEntity instanceof ServerPlayerEntity) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY); + private void setAttackTarget(E mob, LivingEntity livingEntity) { + EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(mob, livingEntity, (livingEntity instanceof ServerPlayer) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY); if (event.isCancelled()) { return; } livingEntity = ((event.getTarget() != null) ? ((CraftLivingEntity) event.getTarget()).getHandle() : null); mob.getBrain().setMemory(MemoryModuleType.ATTACK_TARGET, livingEntity); - mob.getBrain().removeMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); + mob.getBrain().eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FindNewAttackTargetTaskMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StopAttackingIfTargetInvalidMixin.java similarity index 68% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FindNewAttackTargetTaskMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StopAttackingIfTargetInvalidMixin.java index d862f1b0..4a837d57 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/task/FindNewAttackTargetTaskMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/StopAttackingIfTargetInvalidMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain.task; +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.brain.memory.MemoryModuleType; -import net.minecraft.entity.ai.brain.task.FindNewAttackTargetTask; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.behavior.StopAttackingIfTargetInvalid; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityTargetEvent; @@ -12,10 +12,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(FindNewAttackTargetTask.class) -public class FindNewAttackTargetTaskMixin { +@Mixin(StopAttackingIfTargetInvalid.class) +public class StopAttackingIfTargetInvalidMixin { - @Inject(method = "func_233987_d_", cancellable = true, at = @At("HEAD")) + @Inject(method = "clearAttackTarget", cancellable = true, at = @At("HEAD")) private void arclight$attackEvent(E mob, CallbackInfo ci) { LivingEntity old = mob.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); EntityTargetEvent event = CraftEventFactory.callEntityTargetLivingEvent(mob, old, (old != null && !old.isAlive()) ? EntityTargetEvent.TargetReason.TARGET_DIED : EntityTargetEvent.TargetReason.FORGOT_TARGET); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/VillagerMakeLoveMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/VillagerMakeLoveMixin.java new file mode 100644 index 00000000..8056290d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/VillagerMakeLoveMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.AgeableMob; +import net.minecraft.world.entity.ai.behavior.VillagerMakeLove; +import net.minecraft.world.entity.npc.Villager; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(VillagerMakeLove.class) +public class VillagerMakeLoveMixin { + + @Redirect(method = "breed", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/npc/Villager;getBreedOffspring(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/AgeableMob;)Lnet/minecraft/world/entity/npc/Villager;")) + private Villager arclight$entityBreed(Villager lona, ServerLevel world, AgeableMob anonymous) { + Villager child = lona.getBreedOffspring(world, anonymous); + if (child != null && !CraftEventFactory.callEntityBreedEvent(child, lona, anonymous, null, null, 0).isCancelled()) { + ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); + return child; + } else { + return null; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/WorkAtComposterMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/WorkAtComposterMixin.java new file mode 100644 index 00000000..c958f8ad --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/WorkAtComposterMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior; + +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.core.GlobalPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ai.behavior.WorkAtComposter; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WorkAtComposter.class) +public class WorkAtComposterMixin { + + @Inject(method = "compostItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/ComposterBlock;extractProduce(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;")) + private void arclight$captureVillager1(ServerLevel world, Villager villager, GlobalPos p_234016_3_, BlockState state, CallbackInfo ci) { + ArclightCaptures.captureEntityChangeBlock(villager); + } + + @Inject(method = "compostItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/ComposterBlock;insertItem(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;")) + private void arclight$captureVillager2(ServerLevel world, Villager villager, GlobalPos p_234016_3_, BlockState state, CallbackInfo ci) { + ArclightCaptures.captureEntityChangeBlock(villager); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/BrainUtilMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/brain/BrainUtilMixin.java similarity index 59% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/BrainUtilMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/brain/BrainUtilMixin.java index ae3b63e5..9863f8d9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/brain/BrainUtilMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/brain/BrainUtilMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.brain; +package io.izzel.arclight.common.mixin.core.world.entity.ai.brain; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.brain.BrainUtil; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.behavior.BehaviorUtils; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.entity.Item; import org.bukkit.event.entity.EntityDropItemEvent; @@ -15,17 +15,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(BrainUtil.class) +@Mixin(BehaviorUtils.class) public class BrainUtilMixin { - @Inject(method = "spawnItemNearEntity", cancellable = true, at = @At("HEAD")) - private static void arclight$noEmptyLoot(LivingEntity entity, ItemStack stack, Vector3d offset, CallbackInfo ci) { + @Inject(method = "throwItem", cancellable = true, at = @At("HEAD")) + private static void arclight$noEmptyLoot(LivingEntity entity, ItemStack stack, Vec3 offset, CallbackInfo ci) { if (stack.isEmpty()) ci.cancel(); } - @Inject(method = "spawnItemNearEntity", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private static void arclight$entityDropItem(LivingEntity entity, ItemStack stack, Vector3d offset, CallbackInfo ci, double d, ItemEntity itemEntity) { + @Inject(method = "throwItem", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private static void arclight$entityDropItem(LivingEntity entity, ItemStack stack, Vec3 offset, CallbackInfo ci, double d, ItemEntity itemEntity) { EntityDropItemEvent event = new EntityDropItemEvent(((EntityBridge) entity).bridge$getBukkitEntity(), (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity()); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/BreakDoorGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/BreakDoorGoalMixin.java new file mode 100644 index 00000000..c239f603 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/BreakDoorGoalMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; + +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.goal.BreakDoorGoal; +import net.minecraft.world.entity.ai.goal.DoorInteractGoal; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(BreakDoorGoal.class) +public abstract class BreakDoorGoalMixin extends DoorInteractGoal { + + public BreakDoorGoalMixin(Mob entityIn) { + super(entityIn); + } + + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void arclight$breakDoor(CallbackInfo ci) { + if (CraftEventFactory.callEntityBreakDoorEvent(this.mob, this.doorPos).isCancelled()) { + this.start(); + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/DefendVillageTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/DefendVillageTargetGoalMixin.java similarity index 57% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/DefendVillageTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/DefendVillageTargetGoalMixin.java index cfdb89de..93c263f1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/DefendVillageTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/DefendVillageTargetGoalMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.ai.goal.DefendVillageTargetGoal; -import net.minecraft.entity.passive.IronGolemEntity; +import net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal; +import net.minecraft.world.entity.animal.IronGolem; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -14,10 +14,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(DefendVillageTargetGoal.class) public class DefendVillageTargetGoalMixin { - @Shadow @Final private IronGolemEntity irongolem; + @Shadow @Final private IronGolem golem; - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) public void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.irongolem).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.DEFEND_VILLAGE, true); + ((MobEntityBridge) this.golem).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.DEFEND_VILLAGE, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/EatGrassGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/EatBlockGoalMixin.java similarity index 65% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/EatGrassGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/EatBlockGoalMixin.java index 4f15baa8..31cfa5a6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/EatGrassGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/EatBlockGoalMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ai.goal.EatGrassGoal; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ai.goal.EatBlockGoal; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityChangeBlockEvent; @@ -15,25 +15,25 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(EatGrassGoal.class) -public class EatGrassGoalMixin { +@Mixin(EatBlockGoal.class) +public class EatBlockGoalMixin { private transient BlockPos arclight$pos; - @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 0, remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;)Z")) + @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 0, remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;)Z")) public void arclight$capturePos1(CallbackInfo ci, BlockPos pos) { arclight$pos = pos; } - @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 1, remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;)Z")) + @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", ordinal = 1, remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;)Z")) public void arclight$capturePos2(CallbackInfo ci, BlockPos pos) { - arclight$pos = pos.down(); + arclight$pos = pos.below(); } - @Redirect(method = "tick", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;)Z")) - public boolean arclight$entityChangeBlock(World world, Entity entity) { + @Redirect(method = "tick", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;)Z")) + public boolean arclight$entityChangeBlock(Level world, Entity entity) { boolean b = ForgeEventFactory.getMobGriefingEvent(world, entity); - EntityChangeBlockEvent event = CraftEventFactory.callEntityChangeBlockEvent(entity, arclight$pos, Blocks.AIR.getDefaultState(), !b); + EntityChangeBlockEvent event = CraftEventFactory.callEntityChangeBlockEvent(entity, arclight$pos, Blocks.AIR.defaultBlockState(), !b); arclight$pos = null; return !event.isCancelled(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/FollowOwnerGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/FollowOwnerGoalMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/FollowOwnerGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/FollowOwnerGoalMixin.java index 663d14d2..e07eb1f9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/FollowOwnerGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/FollowOwnerGoalMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.entity.ai.goal.FollowOwnerGoal; -import net.minecraft.entity.passive.TameableEntity; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.ai.goal.FollowOwnerGoal; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftEntity; @@ -19,23 +19,23 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class FollowOwnerGoalMixin { // @formatter:off - @Shadow @Final private TameableEntity tameable; + @Shadow @Final private TamableAnimal tamable; // @formatter:on private transient boolean arclight$cancelled; - @Redirect(method = "tryToTeleportToLocation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/TameableEntity;setLocationAndAngles(DDDFF)V")) - public void arclight$teleport(TameableEntity tameableEntity, double x, double y, double z, float yaw, float pitch) { - CraftEntity craftEntity = ((EntityBridge) this.tameable).bridge$getBukkitEntity(); + @Redirect(method = "maybeTeleportTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/TamableAnimal;setLocationAndAngles(DDDFF)V")) + public void arclight$teleport(TamableAnimal tameableEntity, double x, double y, double z, float yaw, float pitch) { + CraftEntity craftEntity = ((EntityBridge) this.tamable).bridge$getBukkitEntity(); Location location = new Location(craftEntity.getWorld(), x, y, z, yaw, pitch); EntityTeleportEvent event = new EntityTeleportEvent(craftEntity, craftEntity.getLocation(), location); Bukkit.getPluginManager().callEvent(event); if (!(arclight$cancelled = event.isCancelled())) { - tameableEntity.setLocationAndAngles(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch()); + tameableEntity.moveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch()); } } - @Inject(method = "tryToTeleportToLocation", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/pathfinding/PathNavigator;clearPath()V")) + @Inject(method = "maybeTeleportTo", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ai/navigation/PathNavigation;stop()V")) public void arclight$returnIfFail(int x, int y, int z, CallbackInfoReturnable cir) { if (arclight$cancelled) { cir.setReturnValue(false); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/HurtByTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/HurtByTargetGoalMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/HurtByTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/HurtByTargetGoalMixin.java index d1673694..2ed34455 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/HurtByTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/HurtByTargetGoalMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.goal.HurtByTargetGoal; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,13 +13,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(HurtByTargetGoal.class) public class HurtByTargetGoalMixin extends TargetGoalMixin { - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) public void arclight$reason1(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); } - @Inject(method = "setAttackTarget", at = @At("HEAD")) - public void arclight$reason2(MobEntity mobIn, LivingEntity targetIn, CallbackInfo ci) { + @Inject(method = "alertOther", at = @At("HEAD")) + public void arclight$reason2(Mob mobIn, LivingEntity targetIn, CallbackInfo ci) { ((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/NearestAttackableTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/NearestAttackableTargetGoalMixin.java new file mode 100644 index 00000000..bf3ea5c2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/NearestAttackableTargetGoalMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(NearestAttackableTargetGoal.class) +public class NearestAttackableTargetGoalMixin extends TargetGoalMixin { + + @Shadow protected LivingEntity target; + + @Inject(method = "start", at = @At("HEAD")) + public void arclight$reason(CallbackInfo ci) { + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(this.target instanceof ServerPlayer ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.CLOSEST_ENTITY, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtByTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtByTargetGoalMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtByTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtByTargetGoalMixin.java index 268bed58..8732ee78 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtByTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtByTargetGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.ai.goal.OwnerHurtByTargetGoal; +import net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,8 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(OwnerHurtByTargetGoal.class) public class OwnerHurtByTargetGoalMixin extends TargetGoalMixin { - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) public void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtTargetGoalMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtTargetGoalMixin.java index 097662f5..92f20c1b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/OwnerHurtTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/OwnerHurtTargetGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.ai.goal.OwnerHurtTargetGoal; +import net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,8 +11,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(OwnerHurtTargetGoal.class) public class OwnerHurtTargetGoalMixin extends TargetGoalMixin { - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) public void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakBlockGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/RemoveBlockGoalMixin.java similarity index 63% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakBlockGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/RemoveBlockGoalMixin.java index 97a179e8..9b6c5f3f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/BreakBlockGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/RemoveBlockGoalMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.goal.BreakBlockGoal; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.goal.RemoveBlockGoal; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.entity.EntityInteractEvent; @@ -16,17 +16,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(BreakBlockGoal.class) -public class BreakBlockGoalMixin { +@Mixin(RemoveBlockGoal.class) +public class RemoveBlockGoalMixin { // @formatter:off - @Shadow @Final private MobEntity entity; + @Shadow @Final private Mob removerMob; // @formatter:on @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void arclight$removeBlock(CallbackInfo ci, World world, BlockPos pos, BlockPos pos1) { - EntityInteractEvent event = new EntityInteractEvent(((MobEntityBridge) this.entity).bridge$getBukkitEntity(), CraftBlock.at(world, pos1)); + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void arclight$removeBlock(CallbackInfo ci, Level world, BlockPos pos, BlockPos pos1) { + EntityInteractEvent event = new EntityInteractEvent(((MobEntityBridge) this.removerMob).bridge$getBukkitEntity(), CraftBlock.at(world, pos1)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { ci.cancel(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TriggerSkeletonTrapGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/SkeletonTrapGoalMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TriggerSkeletonTrapGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/SkeletonTrapGoalMixin.java index d8ce513b..653626ce 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TriggerSkeletonTrapGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/SkeletonTrapGoalMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ai.goal.TriggerSkeletonTrapGoal; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.passive.horse.SkeletonHorseEntity; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.animal.horse.SkeletonHorse; +import net.minecraft.world.entity.animal.horse.SkeletonTrapGoal; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.weather.LightningStrikeEvent; import org.spongepowered.asm.mixin.Final; @@ -18,28 +18,28 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(TriggerSkeletonTrapGoal.class) -public class TriggerSkeletonTrapGoalMixin { +@Mixin(SkeletonTrapGoal.class) +public class SkeletonTrapGoalMixin { // @formatter:off - @Shadow @Final private SkeletonHorseEntity horse; + @Shadow @Final private SkeletonHorse horse; // @formatter:on - @Inject(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"), - slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/TriggerSkeletonTrapGoal;createHorse(Lnet/minecraft/world/DifficultyInstance;)Lnet/minecraft/entity/passive/horse/AbstractHorseEntity;"))) + @Inject(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;func_242417_l(Lnet/minecraft/world/entity/Entity;)V"), + slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/SkeletonTrapGoal;createHorse(Lnet/minecraft/world/DifficultyInstance;)Lnet/minecraft/world/entity/animal/horse/AbstractHorse;"))) private void arclight$thunder(CallbackInfo ci) { - ((WorldBridge) this.horse.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.TRAP); + ((WorldBridge) this.horse.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.TRAP); } - @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$addHorse(ServerWorld world, Entity entityIn) { - ((ServerWorldBridge) world).bridge$strikeLightning((LightningBoltEntity) entityIn, LightningStrikeEvent.Cause.TRAP); + @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$addHorse(ServerLevel world, Entity entityIn) { + ((ServerWorldBridge) world).bridge$strikeLightning((LightningBolt) entityIn, LightningStrikeEvent.Cause.TRAP); return true; } - @Inject(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ai/goal/TriggerSkeletonTrapGoal;createHorse(Lnet/minecraft/world/DifficultyInstance;)Lnet/minecraft/entity/passive/horse/AbstractHorseEntity;"))) + @Inject(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;func_242417_l(Lnet/minecraft/world/entity/Entity;)V"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/SkeletonTrapGoal;createHorse(Lnet/minecraft/world/DifficultyInstance;)Lnet/minecraft/world/entity/animal/horse/AbstractHorse;"))) private void arclight$jockey(CallbackInfo ci) { - ((WorldBridge) this.horse.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.JOCKEY); + ((WorldBridge) this.horse.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.JOCKEY); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TargetGoalMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TargetGoalMixin.java index dadd6a10..ad3bfded 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/ai/goal/TargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TargetGoalMixin.java @@ -1,8 +1,8 @@ -package io.izzel.arclight.common.mixin.core.entity.ai.goal; +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.goal.TargetGoal; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.ai.goal.target.TargetGoal; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -15,15 +15,15 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(TargetGoal.class) public class TargetGoalMixin { - @Shadow @Final protected MobEntity goalOwner; + @Shadow @Final protected Mob mob; - @Inject(method = "shouldContinueExecuting", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) + @Inject(method = "canContinueToUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) private void arclight$reason(CallbackInfoReturnable cir) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_ENTITY, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_ENTITY, true); } - @Inject(method = "resetTask", at = @At("HEAD")) + @Inject(method = "stop", at = @At("HEAD")) private void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TemptGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TemptGoalMixin.java new file mode 100644 index 00000000..53409453 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/goal/TemptGoalMixin.java @@ -0,0 +1,39 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.goal; + +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.ai.goal.TemptGoal; +import net.minecraft.world.entity.player.Player; +import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(TemptGoal.class) +public abstract class TemptGoalMixin { + + // @formatter:off + @Shadow protected Player player; + @Shadow @Final protected PathfinderMob mob; + // @formatter:on + + @Inject(method = "canUse", cancellable = true, at = @At(value = "FIELD", shift = At.Shift.AFTER, opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/entity/ai/goal/TemptGoal;player:Lnet/minecraft/world/entity/player/Player;")) + public void arclight$tempt(CallbackInfoReturnable cir) { + boolean tempt = this.player != null; + if (tempt) { + EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this.mob, this.player, EntityTargetEvent.TargetReason.TEMPT); + if (event.isCancelled()) { + cir.setReturnValue(false); + return; + } + this.player = (event.getTarget() == null) ? null : ((CraftHumanEntity) event.getTarget()).getHandle(); + } + cir.setReturnValue(tempt); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ambient/BatMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ambient/BatMixin.java new file mode 100644 index 00000000..0bb467ea --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ambient/BatMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ambient; + +import io.izzel.arclight.common.mixin.core.world.entity.MobMixin; +import net.minecraft.world.entity.ambient.Bat; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Bat.class) +public abstract class BatMixin extends MobMixin { + + // @formatter:off + @Shadow public abstract boolean isResting(); + // @formatter:on + + @Inject(method = "customServerAiStep", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ambient/Bat;setResting(Z)V")) + private void arclight$toggleSleep(CallbackInfo ci) { + if (!CraftEventFactory.handleBatToggleSleepEvent((Bat) (Object) this, !this.isResting())) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AbstractFishMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AbstractFishMixin.java new file mode 100644 index 00000000..164219dd --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AbstractFishMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.entity.animal.AbstractFish; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(AbstractFish.class) +public abstract class AbstractFishMixin extends PathfinderMobMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean removeWhenFarAway(double distanceToClosestPlayer) { + return true; + } + + @Inject(method = "setFromBucket", at = @At("RETURN")) + private void arclight$updatePersist(boolean p_203706_1_, CallbackInfo ci) { + this.persistenceRequired = this.isPersistenceRequired(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AnimalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AnimalMixin.java new file mode 100644 index 00000000..04b7f70d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/AnimalMixin.java @@ -0,0 +1,136 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.passive.AnimalEntityBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.AgeableMobMixin; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.AgeableMob; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityEnterLoveModeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; + +@Mixin(Animal.class) +public abstract class AnimalMixin extends AgeableMobMixin implements AnimalEntityBridge { + + // @formatter:off + @Shadow public InteractionResult mobInteract(Player playerIn, InteractionHand hand) { return null; } + @Shadow public int inLove; + @Shadow public abstract void resetLove(); + @Shadow @Nullable public abstract ServerPlayer getLoveCause(); + // @formatter:on + + public ItemStack breedItem; + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean hurt(DamageSource source, float amount) { + return super.hurt(source, amount); + } + + @Inject(method = "setInLove(Lnet/minecraft/world/entity/player/Player;)V", cancellable = true, at = @At("HEAD")) + private void arclight$enterLove(Player player, CallbackInfo ci) { + EntityEnterLoveModeEvent event = CraftEventFactory.callEntityEnterLoveModeEvent(player, (Animal) (Object) this, 600); + if (event.isCancelled()) { + ci.cancel(); + } else { + arclight$loveTime = event.getTicksInLove(); + } + } + + private transient int arclight$loveTime; + + @Inject(method = "setInLove(Lnet/minecraft/world/entity/player/Player;)V", at = @At(value = "FIELD", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/animal/Animal;inLove:I")) + private void arclight$inLove(Player player, CallbackInfo ci) { + this.inLove = arclight$loveTime; + if (player != null) { + this.breedItem = player.getInventory().getSelected(); + } + } + + @Override + public ItemStack bridge$getBreedItem() { + return breedItem; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void spawnChildFromBreeding(ServerLevel world, Animal animalEntity) { + AgeableMob child = this.getBreedOffspring(world, animalEntity); + final BabyEntitySpawnEvent event = new BabyEntitySpawnEvent((Animal) (Object) this, animalEntity, child); + final boolean cancelled = MinecraftForge.EVENT_BUS.post(event); + child = event.getChild(); + if (cancelled) { + //Reset the "inLove" state for the animals + this.setAge(6000); + animalEntity.setAge(6000); + this.resetLove(); + animalEntity.resetLove(); + return; + } + if (child != null) { + if (child instanceof TamableAnimal && ((TamableAnimal) child).isTame()) { + child.persistenceRequired = true; + } + ServerPlayer serverplayerentity = this.getLoveCause(); + if (serverplayerentity == null && animalEntity.getLoveCause() != null) { + serverplayerentity = animalEntity.getLoveCause(); + } + + int experience = this.getRandom().nextInt(7) + 1; + org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(child, (Animal) (Object) this, animalEntity, serverplayerentity, this.breedItem, experience); + if (entityBreedEvent.isCancelled()) { + return; + } + experience = entityBreedEvent.getExperience(); + + if (serverplayerentity != null) { + serverplayerentity.awardStat(Stats.ANIMALS_BRED); + CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity, (Animal) (Object) this, animalEntity, child); + } + + this.setAge(6000); + animalEntity.setAge(6000); + this.resetLove(); + animalEntity.resetLove(); + child.setBaby(true); + child.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); + ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); + world.addFreshEntityWithPassengers(child); + world.broadcastEntityEvent((Animal) (Object) this, (byte) 18); + if (world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { + if (experience > 0) { + world.addFreshEntity(new ExperienceOrb(world, this.getX(), this.getY(), this.getZ(), experience)); + } + } + + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BeeMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BeeMixin.java index 26b9560c..1522f0f3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BeeMixin.java @@ -1,9 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.passive.BeeEntity; -import net.minecraft.util.DamageSource; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.animal.Bee; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -12,14 +13,14 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(BeeEntity.class) -public abstract class BeeEntityMixin extends AnimalEntityMixin { +@Mixin(Bee.class) +public abstract class BeeMixin extends AnimalMixin { // @formatter:off - @Shadow private BeeEntity.PollinateGoal pollinateGoal; + @Shadow Bee.BeePollinateGoal beePollinateGoal; // @formatter:on - @Inject(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$sting(Entity entityIn, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } @@ -29,14 +30,14 @@ public abstract class BeeEntityMixin extends AnimalEntityMixin { * @reason */ @Overwrite - public boolean attackEntityFrom(DamageSource source, float amount) { + public boolean hurt(DamageSource source, float amount) { if (this.isInvulnerableTo(source)) { return false; } else { - Entity entity = source.getTrueSource(); - boolean ret = super.attackEntityFrom(source, amount); - if (ret && !this.world.isRemote) { - this.pollinateGoal.cancel(); + Entity entity = source.getEntity(); + boolean ret = super.hurt(source, amount); + if (ret && !this.level.isClientSide) { + this.beePollinateGoal.stopPollinating(); } return ret; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_FindPollinationTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_GrowCropGoalMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_FindPollinationTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_GrowCropGoalMixin.java index 2fa2093a..425fffbd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/BeeEntity_FindPollinationTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_GrowCropGoalMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.passive.BeeEntity; -import net.minecraft.state.IntegerProperty; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.animal.Bee; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -13,15 +13,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(targets = "net.minecraft.entity.passive.BeeEntity.FindPollinationTargetGoal") -public class BeeEntity_FindPollinationTargetGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.animal.Bee.BeeGrowCropGoal") +public class Bee_GrowCropGoalMixin { - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_226483_b_"}, remap = false) - private BeeEntity outerThis; + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_28021_"}, remap = false) + private Bee outerThis; - @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playEvent(ILnet/minecraft/util/math/BlockPos;I)V")) + @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(ILnet/minecraft/core/BlockPos;I)V")) private void arclight$entityChangeBlock(CallbackInfo ci, int i, BlockPos blockPos, BlockState blockState, Block block, boolean flag, IntegerProperty property) { - if (CraftEventFactory.callEntityChangeBlockEvent(outerThis, blockPos, blockState.with(property, blockState.get(property) + 1)).isCancelled()) { + if (CraftEventFactory.callEntityChangeBlockEvent(outerThis, blockPos, blockState.setValue(property, blockState.getValue(property) + 1)).isCancelled()) { ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_HurtByOtherGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_HurtByOtherGoalMixin.java new file mode 100644 index 00000000..b1aeb5b3 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Bee_HurtByOtherGoalMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.world.entity.animal.Bee.BeeHurtByOtherGoal") +public class Bee_HurtByOtherGoalMixin { + + @Inject(method = "alertOther", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$reason(Mob mobIn, LivingEntity targetIn, CallbackInfo ci) { + ((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java new file mode 100644 index 00000000..e42b1d49 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java @@ -0,0 +1,60 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.network.protocol.game.ClientboundAddMobPacket; +import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Bucketable; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemUtils; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.player.PlayerBucketEntityEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +import java.util.Optional; + +@Mixin(Bucketable.class) +public interface BucketableMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + static Optional bucketMobPickup(Player player, InteractionHand hand, T entity) { + ItemStack itemstack = player.getItemInHand(hand); + if (itemstack.getItem() == Items.WATER_BUCKET && entity.isAlive()) { + // entity.playSound(entity.getPickupSound(), 1.0F, 1.0F); + ItemStack itemstack1 = entity.getBucketItemStack(); + entity.saveToBucketTag(itemstack1); + PlayerBucketEntityEvent event = CraftEventFactory.callPlayerFishBucketEvent(entity, player, itemstack, itemstack1); + itemstack1 = CraftItemStack.asNMSCopy(event.getEntityBucket()); + if (event.isCancelled()) { + player.containerMenu.sendAllDataToRemote(); // We need to update inventory to resync client's bucket + ((ServerPlayer) player).connection.send(new ClientboundAddMobPacket(entity)); // We need to play out these packets as the client assumes the fish is gone + ((ServerPlayer) player).connection.send(new ClientboundSetEntityDataPacket(entity.getId(), entity.getEntityData(), true)); // Need to send data such as the display name to client + return Optional.of(InteractionResult.FAIL); + } + entity.playSound(entity.getPickupSound(), 1.0F, 1.0F); + ItemStack itemstack2 = ItemUtils.createFilledResult(itemstack, player, itemstack1, false); + player.setItemInHand(hand, itemstack2); + Level level = entity.level; + if (!level.isClientSide) { + CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer) player, itemstack1); + } + + entity.discard(); + return Optional.of(InteractionResult.sidedSuccess(level.isClientSide)); + } else { + return Optional.empty(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ChickenMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ChickenMixin.java new file mode 100644 index 00000000..67b58d73 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ChickenMixin.java @@ -0,0 +1,34 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.animal.Chicken; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Chicken.class) +public abstract class ChickenMixin extends AnimalMixin { + + // @formatter:off + @Shadow public abstract boolean isChickenJockey(); + // @formatter:on + + @Inject(method = "aiStep", at = @At("HEAD")) + private void arclight$persist(CallbackInfo ci) { + if (this.isChickenJockey()) { + this.persistenceRequired = !this.removeWhenFarAway(0.0); + } + } + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Chicken;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$forceDropOn(CallbackInfo ci) { + this.forceDrops = true; + } + + @Inject(method = "aiStep", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/animal/Chicken;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$forceDropOff(CallbackInfo ci) { + this.forceDrops = false; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/CowMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/CowMixin.java new file mode 100644 index 00000000..ee4758cc --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/CowMixin.java @@ -0,0 +1,42 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.animal.Cow; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ItemUtils; +import net.minecraft.world.item.Items; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(Cow.class) +public abstract class CowMixin extends AnimalMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public InteractionResult mobInteract(Player playerEntity, InteractionHand hand) { + ItemStack itemstack = playerEntity.getItemInHand(hand); + if (itemstack.getItem() == Items.BUCKET && !this.isBaby()) { + playerEntity.playSound(SoundEvents.COW_MILK, 1.0F, 1.0F); + org.bukkit.event.player.PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) playerEntity.level, playerEntity, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET); + + if (event.isCancelled()) { + return InteractionResult.PASS; + } + ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, playerEntity, CraftItemStack.asNMSCopy(event.getItemStack())); + playerEntity.setItemInHand(hand, itemstack1); + return InteractionResult.sidedSuccess(this.level.isClientSide); + } else { + return super.mobInteract(playerEntity, hand); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntity_SwimWithPlayerGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinEntity_SwimWithPlayerGoalMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntity_SwimWithPlayerGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinEntity_SwimWithPlayerGoalMixin.java index b30a6822..de15bd0a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/DolphinEntity_SwimWithPlayerGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinEntity_SwimWithPlayerGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.player.Player; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,20 +9,20 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = "net.minecraft.entity.passive.DolphinEntity.SwimWithPlayerGoal") +@Mixin(targets = "net.minecraft.world.entity.animal.Dolphin.DolphinSwimWithPlayerGoal") public class DolphinEntity_SwimWithPlayerGoalMixin { // @formatter:off - @Shadow private PlayerEntity targetPlayer; + @Shadow private Player player; // @formatter:on - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) private void arclight$potionReason1(CallbackInfo ci) { - ((LivingEntityBridge) this.targetPlayer).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.DOLPHIN); + ((LivingEntityBridge) this.player).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.DOLPHIN); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$potionReason2(CallbackInfo ci) { - ((LivingEntityBridge) this.targetPlayer).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.DOLPHIN); + ((LivingEntityBridge) this.player).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.DOLPHIN); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java new file mode 100644 index 00000000..c63b1033 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java @@ -0,0 +1,21 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.entity.animal.Dolphin; +import net.minecraft.world.entity.item.ItemEntity; + +@Mixin(Dolphin.class) +public abstract class DolphinMixin extends PathfinderMobMixin { + + @Inject(method = "pickUpItem", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Dolphin;setItemSlot(Lnet/minecraft/world/entity/EquipmentSlot;Lnet/minecraft/world/item/ItemStack;)V")) + private void arclight$entityPick(ItemEntity itemEntity, CallbackInfo ci) { + if (CraftEventFactory.callEntityPickupItemEvent((Dolphin) (Object) this, itemEntity, 0, false).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java new file mode 100644 index 00000000..1289fc1b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.UUID; + +@Mixin(Fox.class) +public abstract class FoxMixin extends AnimalMixin implements FoxEntityBridge { + + // @formatter:off + @Invoker("addTrustedUUID") @Override public abstract void bridge$addTrustedUUID(UUID uuidIn); + // @formatter:on + + @Redirect(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Fox;canHoldItem(Lnet/minecraft/world/item/ItemStack;)Z")) + private boolean arclight$pickupEvent(Fox foxEntity, ItemStack stack, ItemEntity itemEntity) { + return CraftEventFactory.callEntityPickupItemEvent((Fox) (Object) this, itemEntity, stack.getCount() - 1, !this.canHoldItem(stack)).isCancelled(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_BreedGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_BreedGoalMixin.java new file mode 100644 index 00000000..33e2f5c2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_BreedGoalMixin.java @@ -0,0 +1,87 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.passive.AnimalEntityBridge; +import io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.ai.goal.BreedGoal; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.level.GameRules; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.living.BabyEntitySpawnEvent; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityBreedEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(targets = "net.minecraft.world.entity.animal.Fox.FoxBreedGoal") +public abstract class Fox_BreedGoalMixin extends BreedGoal { + + public Fox_BreedGoalMixin(Animal animal, double speedIn) { + super(animal, speedIn); + } + + /** + * @author IzzekAkuz + * @reason + */ + @Overwrite + protected void breed() { + ServerLevel serverworld = (ServerLevel) this.level; + Fox foxentity = (Fox) this.animal.getBreedOffspring(serverworld, this.partner); + final BabyEntitySpawnEvent event = new BabyEntitySpawnEvent(animal, partner, foxentity); + final boolean cancelled = MinecraftForge.EVENT_BUS.post(event); + foxentity = (Fox) event.getChild(); + if (cancelled) { + //Reset the "inLove" state for the animals + this.animal.setAge(6000); + this.partner.setAge(6000); + this.animal.resetLove(); + this.partner.resetLove(); + return; + } + if (foxentity != null) { + ServerPlayer serverplayerentity = this.animal.getLoveCause(); + ServerPlayer serverplayerentity1 = this.partner.getLoveCause(); + ServerPlayer serverplayerentity2 = serverplayerentity; + if (serverplayerentity != null) { + ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUUID()); + } else { + serverplayerentity2 = serverplayerentity1; + } + + if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) { + ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUUID()); + } + int experience = this.animal.getRandom().nextInt(7) + 1; + final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.partner, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience); + if (entityBreedEvent.isCancelled()) { + return; + } + experience = entityBreedEvent.getExperience(); + if (serverplayerentity2 != null) { + serverplayerentity2.awardStat(Stats.ANIMALS_BRED); + CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.partner, foxentity); + } + + this.animal.setAge(6000); + this.partner.setAge(6000); + this.animal.resetLove(); + this.partner.resetLove(); + foxentity.setAge(-24000); + foxentity.moveTo(this.animal.getX(), this.animal.getY(), this.animal.getZ(), 0.0F, 0.0F); + serverworld.addFreshEntityWithPassengers(foxentity); + this.level.broadcastEntityEvent(this.animal, (byte) 18); + if (this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { + if (experience > 0) { + this.level.addFreshEntity(new ExperienceOrb(this.level, this.animal.getX(), this.animal.getY(), this.animal.getZ(), experience)); + } + } + + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_EatBerriesGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_EatBerriesGoalMixin.java new file mode 100644 index 00000000..2b1ec103 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Fox_EatBerriesGoalMixin.java @@ -0,0 +1,43 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.ai.goal.MoveToBlockGoal; +import net.minecraft.world.entity.animal.Fox; +import net.minecraft.world.level.block.SweetBerryBushBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(Fox.FoxEatBerriesGoal.class) +public abstract class Fox_EatBerriesGoalMixin extends MoveToBlockGoal { + + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_28672_"}, remap = false) + private Fox outerThis; + + public Fox_EatBerriesGoalMixin(PathfinderMob creature, double speedIn, int length) { + super(creature, speedIn, length); + } + + @Inject(method = "pickSweetBerries", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", remap = false, target = "Ljava/util/Random;nextInt(I)I")) + private void arclight$eatBerry(CallbackInfo ci, BlockState state) { + if (CraftEventFactory.callEntityChangeBlockEvent(outerThis, this.blockPos, state.setValue(SweetBerryBushBlock.AGE, 1)).isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "pickGlowBerry", at = @At("HEAD")) + private void arclight$pickGlowBerryPre(BlockState p_148927_, CallbackInfo ci) { + ArclightCaptures.captureEntityChangeBlock(outerThis); + } + + @Inject(method = "pickGlowBerry", at = @At("RETURN")) + private void arclight$pickGlowBerryPost(BlockState p_148927_, CallbackInfo ci) { + ArclightCaptures.getEntityChangeBlock(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/IronGolemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/IronGolemMixin.java new file mode 100644 index 00000000..92dd1db2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/IronGolemMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.animal.IronGolem; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(IronGolem.class) +public abstract class IronGolemMixin extends PathfinderMobMixin { + + @Inject(method = "doPush", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/IronGolem;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$targetReason(Entity entityIn, CallbackInfo ci) { + bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.COLLISION, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/MushroomCowMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/MushroomCowMixin.java new file mode 100644 index 00000000..b7630f58 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/MushroomCowMixin.java @@ -0,0 +1,40 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.animal.Cow; +import net.minecraft.world.entity.animal.MushroomCow; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityTransformEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Collections; +import java.util.List; + +@Mixin(MushroomCow.class) +public abstract class MushroomCowMixin extends AnimalMixin { + + @Redirect(method = "onSheared", remap = false, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/MushroomCow;remove(Z)V")) + private void arclight$animalTransformPre(MushroomCow mushroomCow, boolean keepData) { + } + + @Inject(method = "onSheared", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$animalTransform(Player player, ItemStack item, Level world, BlockPos pos, int fortune, CallbackInfoReturnable> cir, Cow cowEntity) { + if (CraftEventFactory.callEntityTransformEvent((MushroomCow) (Object) this, cowEntity, EntityTransformEvent.TransformReason.SHEARED).isCancelled()) { + cir.setReturnValue(Collections.emptyList()); + } else { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SHEARED); + this.remove(false); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/OcelotMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/OcelotMixin.java new file mode 100644 index 00000000..ac53317d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/OcelotMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.animal.Ocelot; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Ocelot.class) +public abstract class OcelotMixin extends AnimalMixin { + + // @formatter:off + @Shadow abstract boolean isTrusting(); + // @formatter:on + + public boolean spawnBonus = true; + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean removeWhenFarAway(double distanceToClosestPlayer) { + return !this.isTrusting() /*&& this.ticksExisted > 2400*/; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java new file mode 100644 index 00000000..d6c8d565 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java @@ -0,0 +1,37 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.animal.Panda; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.function.Predicate; + +@Mixin(Panda.class) +public abstract class PandaMixin extends AnimalMixin { + + @Shadow @Final static Predicate PANDA_ITEMS; + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void pickUpItem(ItemEntity itemEntity) { + boolean cancel = this.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty() && PANDA_ITEMS.test(itemEntity); + if (!CraftEventFactory.callEntityPickupItemEvent((Panda) (Object) this, itemEntity, 0, cancel).isCancelled()) { + ItemStack itemstack = itemEntity.getItem(); + this.setItemSlot(EquipmentSlot.MAINHAND, itemstack); + this.handDropChances[EquipmentSlot.MAINHAND.getIndex()] = 2.0F; + this.take(itemEntity, itemstack.getCount()); + itemEntity.discard(); + } + + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Panda_HurtByTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Panda_HurtByTargetGoalMixin.java new file mode 100644 index 00000000..891eabe2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Panda_HurtByTargetGoalMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.world.entity.animal.Panda.PandaHurtByTargetGoal") +public class Panda_HurtByTargetGoalMixin { + + @Inject(method = "alertOther", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$reason(Mob mobIn, LivingEntity targetIn, CallbackInfo ci) { + ((MobEntityBridge) mobIn).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ParrotMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ParrotMixin.java new file mode 100644 index 00000000..5f79b8f2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ParrotMixin.java @@ -0,0 +1,37 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.animal.Parrot; +import net.minecraft.world.entity.player.Player; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Parrot.class) +public abstract class ParrotMixin extends AnimalMixin { + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Parrot;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$feed(Player playerIn, InteractionHand hand, CallbackInfoReturnable cir) { + bridge$pushEffectCause(EntityPotionEffectEvent.Cause.FOOD); + } + + @Redirect(method = "hurt", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/entity/animal/Parrot;setOrderedToSit(Z)V")) + private void arclight$handledInSuper(Parrot parrotEntity, boolean p_233687_1_) { + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean isPushable() { + return super.isPushable(); // CraftBukkit - collidable API + } + +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java new file mode 100644 index 00000000..5f5a5770 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java @@ -0,0 +1,29 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.animal.Pig; +import net.minecraft.world.entity.monster.ZombifiedPiglin; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; +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; + +@Mixin(Pig.class) +public abstract class PigMixin extends AnimalMixin { + + @Inject(method = "thunderHit", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$pigZap(ServerLevel world, LightningBolt lightningBolt, CallbackInfo ci, ZombifiedPiglin piglin) { + if (CraftEventFactory.callPigZapEvent((Pig) (Object) this, lightningBolt, piglin).isCancelled()) { + ci.cancel(); + } else { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PufferfishEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PufferfishEntityMixin.java new file mode 100644 index 00000000..ec132ca1 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PufferfishEntityMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.animal.Pufferfish; +import net.minecraft.world.entity.player.Player; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Pufferfish.class) +public abstract class PufferfishEntityMixin extends AbstractFishMixin { + + @Inject(method = "touch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$attack(Mob mobEntity, CallbackInfo ci) { + ((MobEntityBridge) mobEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + } + + @Inject(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$collide(Player entityIn, CallbackInfo ci) { + ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/RabbitMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/RabbitMixin.java new file mode 100644 index 00000000..5963ebe6 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/RabbitMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.animal.Rabbit; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Rabbit.class) +public abstract class RabbitMixin extends AnimalMixin { + + // @formatter:off + @Shadow public abstract void setSpeedModifier(double newSpeed); + // @formatter:on + + public void initializePathFinderGoals() { + this.setSpeedModifier(0.0D); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntity_RaidFarmGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Rabbit_RaidGardenGoalMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntity_RaidFarmGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Rabbit_RaidGardenGoalMixin.java index 8dcdeb5d..6320715c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/RabbitEntity_RaidFarmGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Rabbit_RaidGardenGoalMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.CarrotBlock; -import net.minecraft.entity.passive.RabbitEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.animal.Rabbit; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.CarrotBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -16,23 +16,23 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(targets = "net.minecraft.entity.passive.RabbitEntity.RaidFarmGoal") -public class RabbitEntity_RaidFarmGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.animal.Rabbit.RaidGardenGoal") +public class Rabbit_RaidGardenGoalMixin { - @Shadow @Final private RabbitEntity rabbit; + @Shadow @Final private Rabbit rabbit; @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$entityChangeBlock(CallbackInfo ci, World world, BlockPos blockPos, BlockState blockState, Block block, Integer integer) { + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$entityChangeBlock(CallbackInfo ci, Level world, BlockPos blockPos, BlockState blockState, Block block, Integer integer) { if (integer == 0) { - if (CraftEventFactory.callEntityChangeBlockEvent(this.rabbit, blockPos, Blocks.AIR.getDefaultState()).isCancelled()) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.rabbit, blockPos, Blocks.AIR.defaultBlockState()).isCancelled()) { ci.cancel(); } } else { if (CraftEventFactory.callEntityChangeBlockEvent( this.rabbit, blockPos, - blockState.with(CarrotBlock.AGE, integer - 1) + blockState.setValue(CarrotBlock.AGE, integer - 1) ).isCancelled()) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntity1Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Sheep1Mixin.java similarity index 57% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntity1Mixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Sheep1Mixin.java index 0fe54f3f..494c5637 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntity1Mixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Sheep1Mixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; import org.bukkit.inventory.InventoryView; import org.spongepowered.asm.mixin.Mixin; -@Mixin(targets = "net/minecraft/entity/passive/SheepEntity$1") -public abstract class SheepEntity1Mixin implements ContainerBridge { +@Mixin(targets = "net/minecraft/world/entity/animal/Sheep$1") +public abstract class Sheep1Mixin implements ContainerBridge { @Override public InventoryView bridge$getBukkitView() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SheepMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SheepMixin.java index 6a8f7d31..20f80795 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/SheepEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SheepMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.passive; +package io.izzel.arclight.common.mixin.core.world.entity.animal; import io.izzel.arclight.common.bridge.inventory.CraftingInventoryBridge; -import net.minecraft.entity.passive.SheepEntity; -import net.minecraft.inventory.CraftResultInventory; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.DyeColor; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.inventory.ResultContainer; +import net.minecraft.world.item.DyeColor; import org.bukkit.Bukkit; import org.bukkit.entity.Sheep; import org.bukkit.event.entity.SheepRegrowWoolEvent; @@ -15,20 +15,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(SheepEntity.class) -public abstract class SheepEntityMixin extends AnimalEntityMixin { +@Mixin(net.minecraft.world.entity.animal.Sheep.class) +public abstract class SheepMixin extends AnimalMixin { - @Inject(method = "shear", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;I)Lnet/minecraft/entity/item/ItemEntity;")) + @Inject(method = "shear", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Sheep;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;")) private void arclight$forceDrop(CallbackInfo ci) { forceDrops = true; } - @Inject(method = "shear", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/passive/SheepEntity;entityDropItem(Lnet/minecraft/util/IItemProvider;I)Lnet/minecraft/entity/item/ItemEntity;")) + @Inject(method = "shear", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/animal/Sheep;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;")) private void arclight$forceDropReset(CallbackInfo ci) { forceDrops = false; } - @Inject(method = "eatGrassBonus", cancellable = true, at = @At("HEAD")) + @Inject(method = "ate", cancellable = true, at = @At("HEAD")) private void arclight$regrow(CallbackInfo ci) { SheepRegrowWoolEvent event = new SheepRegrowWoolEvent((Sheep) this.getBukkitEntity()); Bukkit.getPluginManager().callEvent(event); @@ -37,8 +37,8 @@ public abstract class SheepEntityMixin extends AnimalEntityMixin { } } - @Inject(method = "createDyeColorCraftingInventory", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) - private static void arclight$resultInv(DyeColor color, DyeColor color1, CallbackInfoReturnable cir, CraftingInventory craftingInventory) { - ((CraftingInventoryBridge) craftingInventory).bridge$setResultInventory(new CraftResultInventory()); + @Inject(method = "makeContainer", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) + private static void arclight$resultInv(DyeColor color, DyeColor color1, CallbackInfoReturnable cir, CraftingContainer craftingInventory) { + ((CraftingInventoryBridge) craftingInventory).bridge$setResultInventory(new ResultContainer()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin.java new file mode 100644 index 00000000..4e1ae190 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/SnowGolemMixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.animal.SnowGolem; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; + +@Mixin(SnowGolem.class) +public abstract class SnowGolemMixin extends PathfinderMobMixin { + + @Redirect(method = "aiStep", at = @At(value = "FIELD", target = "Lnet/minecraft/world/damagesource/DamageSource;ON_FIRE:Lnet/minecraft/world/damagesource/DamageSource;")) + private DamageSource arclight$useMelting() { + return CraftEventFactory.MELTING; + } + + @Redirect(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$blockForm(Level world, BlockPos pos, BlockState state) { + return CraftEventFactory.handleBlockFormEvent(world, pos, state, (SnowGolem) (Object) this); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TameableAnimalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TameableAnimalMixin.java new file mode 100644 index 00000000..9934fdd2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TameableAnimalMixin.java @@ -0,0 +1,14 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.world.entity.TamableAnimal; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(TamableAnimal.class) +public abstract class TameableAnimalMixin extends AnimalMixin { + + // @formatter:off + @Shadow public abstract boolean isTame(); + // @formatter:on +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TurtleMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TurtleMixin.java new file mode 100644 index 00000000..81bd099f --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/TurtleMixin.java @@ -0,0 +1,45 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.passive.TurtleEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.animal.Turtle; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Turtle.class) +public abstract class TurtleMixin extends AnimalMixin implements TurtleEntityBridge { + + // @formatter:off + @Accessor("layEggCounter") public abstract int bridge$getDigging(); + @Invoker("setLayingEgg") public abstract void bridge$setDigging(boolean digging); + @Accessor("layEggCounter") public abstract void bridge$setDigging(int i); + @Invoker("setHasEgg") public abstract void bridge$setHasEgg(boolean b); + // @formatter:on + + @Inject(method = "ageBoundaryReached", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Turtle;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$forceDrop(CallbackInfo ci) { + forceDrops = true; + } + + @Inject(method = "ageBoundaryReached", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/animal/Turtle;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$forceDropReset(CallbackInfo ci) { + forceDrops = false; + } + + @Inject(method = "thunderHit", at = @At("HEAD")) + private void arclight$lightning(ServerLevel world, LightningBolt lightningBolt, CallbackInfo ci) { + CraftEventFactory.entityDamage = lightningBolt; + } + + @Inject(method = "thunderHit", at = @At("RETURN")) + private void arclight$lightningReset(ServerLevel world, LightningBolt lightningBolt, CallbackInfo ci) { + CraftEventFactory.entityDamage = null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Turtle_LayEggGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Turtle_LayEggGoalMixin.java new file mode 100644 index 00000000..2d364b9d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/Turtle_LayEggGoalMixin.java @@ -0,0 +1,56 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import io.izzel.arclight.common.bridge.entity.passive.TurtleEntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.ai.goal.MoveToBlockGoal; +import net.minecraft.world.entity.animal.Turtle; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.TurtleEggBlock; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(targets = "net.minecraft.world.entity.animal.Turtle.TurtleLayEggGoal") +public abstract class Turtle_LayEggGoalMixin extends MoveToBlockGoal { + + @Shadow @Final private Turtle turtle; + + public Turtle_LayEggGoalMixin(PathfinderMob creature, double speedIn, int length) { + super(creature, speedIn, length); + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void tick() { + super.tick(); + BlockPos blockpos = this.turtle.blockPosition(); + if (!this.turtle.isInWater() && this.isReachedTarget()) { + if (((TurtleEntityBridge) this.turtle).bridge$getDigging() < 1) { + ((TurtleEntityBridge) this.turtle).bridge$setDigging(true); + } else if (((TurtleEntityBridge) this.turtle).bridge$getDigging() > 200) { + Level world = this.turtle.level; + if (!CraftEventFactory.callEntityChangeBlockEvent(this.turtle, this.blockPos.above(), (Blocks.TURTLE_EGG.defaultBlockState()).setValue(TurtleEggBlock.EGGS, this.turtle.getRandom().nextInt(4) + 1)).isCancelled()) { + world.playSound(null, blockpos, SoundEvents.TURTLE_LAY_EGG, SoundSource.BLOCKS, 0.3f, 0.9f + world.random.nextFloat() * 0.2f); + world.setBlock(this.blockPos.above(), (Blocks.TURTLE_EGG.defaultBlockState()).setValue(TurtleEggBlock.EGGS, this.turtle.getRandom().nextInt(4) + 1), 3); + } + ((TurtleEntityBridge) this.turtle).bridge$setHasEgg(false); + ((TurtleEntityBridge) this.turtle).bridge$setDigging(false); + this.turtle.setInLoveTime(600); + } + + if (this.turtle.isLayingEgg()) { + ((TurtleEntityBridge) this.turtle).bridge$setDigging(((TurtleEntityBridge) this.turtle).bridge$getDigging() + 1); + } + } + + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/WolfMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/WolfMixin.java new file mode 100644 index 00000000..249e8154 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/WolfMixin.java @@ -0,0 +1,39 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.animal.Wolf; +import net.minecraft.world.entity.player.Player; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Wolf.class) +public abstract class WolfMixin extends TameableAnimalMixin { + + @Redirect(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Wolf;setOrderedToSit(Z)V")) + private void arclight$handledBy(Wolf wolfEntity, boolean p_233687_1_) { + } + + @Inject(method = "setTame", at = @At("RETURN")) + private void arclight$healToMax(boolean tamed, CallbackInfo ci) { + if (tamed) { + this.setHealth(this.getMaxHealth()); + } + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Wolf;heal(F)V")) + private void arclight$healReason(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.EATING); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Wolf;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$attackReason(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FORGOT_TARGET, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/AbstractHorseEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/AbstractHorseMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/AbstractHorseEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/AbstractHorseMixin.java index fd464b05..543d3828 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/AbstractHorseEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/AbstractHorseMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.entity.passive.horse; +package io.izzel.arclight.common.mixin.core.world.entity.animal.horse; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import io.izzel.arclight.common.mixin.core.entity.passive.AnimalEntityMixin; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.passive.horse.AbstractHorseEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.world.World; +import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.animal.horse.AbstractHorse; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.HorseJumpEvent; @@ -21,40 +21,40 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(AbstractHorseEntity.class) -public abstract class AbstractHorseEntityMixin extends AnimalEntityMixin { +@Mixin(AbstractHorse.class) +public abstract class AbstractHorseMixin extends AnimalMixin { public int maxDomestication; @Inject(method = "", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { this.maxDomestication = 100; } - @Redirect(method = "initHorseChest", at = @At(value = "NEW", target = "net/minecraft/inventory/Inventory")) - private Inventory arclight$createInv(int slots) { - Inventory inventory = new Inventory(slots); + @Redirect(method = "createInventory", at = @At(value = "NEW", target = "net/minecraft/world/SimpleContainer")) + private SimpleContainer arclight$createInv(int slots) { + SimpleContainer inventory = new SimpleContainer(slots); ((IInventoryBridge) inventory).setOwner((InventoryHolder) this.getBukkitEntity()); return inventory; } - @Inject(method = "handleEating", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/horse/AbstractHorseEntity;heal(F)V")) - private void arclight$healByEating(PlayerEntity player, ItemStack stack, CallbackInfoReturnable cir) { + @Inject(method = "handleEating", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;heal(F)V")) + private void arclight$healByEating(Player player, ItemStack stack, CallbackInfoReturnable cir) { bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.EATING); } - @Inject(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/horse/AbstractHorseEntity;heal(F)V")) + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;heal(F)V")) private void arclight$healByRegen(CallbackInfo ci) { bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.REGEN); } - @Inject(method = "writeAdditional", at = @At("RETURN")) - private void arclight$writeTemper(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "addAdditionalSaveData", at = @At("RETURN")) + private void arclight$writeTemper(CompoundTag compound, CallbackInfo ci) { compound.putInt("Bukkit.MaxDomestication", this.maxDomestication); } - @Inject(method = "readAdditional", at = @At("RETURN")) - private void arclight$readTemper(CompoundNBT compound, CallbackInfo ci) { + @Inject(method = "readAdditionalSaveData", at = @At("RETURN")) + private void arclight$readTemper(CompoundTag compound, CallbackInfo ci) { if (compound.contains("Bukkit.MaxDomestication")) { this.maxDomestication = compound.getInt("Bukkit.MaxDomestication"); } @@ -68,7 +68,7 @@ public abstract class AbstractHorseEntityMixin extends AnimalEntityMixin { } else { power = 0.4F + 0.4F * (float) i / 90.0F; } - HorseJumpEvent event = CraftEventFactory.callHorseJumpEvent((AbstractHorseEntity) (Object) this, power); + HorseJumpEvent event = CraftEventFactory.callHorseJumpEvent((AbstractHorse) (Object) this, power); if (event.isCancelled()) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/TraderLlamaEntity_FollowTraderGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaEntity_FollowTraderGoalMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/TraderLlamaEntity_FollowTraderGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaEntity_FollowTraderGoalMixin.java index 397067d9..79b126f5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/passive/horse/TraderLlamaEntity_FollowTraderGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaEntity_FollowTraderGoalMixin.java @@ -1,19 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.passive.horse; +package io.izzel.arclight.common.mixin.core.world.entity.animal.horse; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.ai.goal.TargetGoalMixin; -import net.minecraft.entity.passive.horse.TraderLlamaEntity; +import io.izzel.arclight.common.mixin.core.world.entity.ai.goal.TargetGoalMixin; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(TraderLlamaEntity.FollowTraderGoal.class) +@Mixin(targets = "net.minecraft.world.entity.animal.horse.TraderLlama.TraderLlamaDefendWanderingTraderGoal") public class TraderLlamaEntity_FollowTraderGoalMixin extends TargetGoalMixin { - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) private void arclight$reason(CallbackInfo ci) { - ((MobEntityBridge) this.goalOwner).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER, true); + ((MobEntityBridge) this.mob).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER, true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java new file mode 100644 index 00000000..fc202d44 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java @@ -0,0 +1,47 @@ +package io.izzel.arclight.common.mixin.core.world.entity.boss.enderdragon; + +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.ExplosionPrimeEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(EndCrystal.class) +public abstract class EnderCrystalMixin extends EntityMixin { + + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private void arclight$blockIgnite(CallbackInfo ci) { + if (CraftEventFactory.callBlockIgniteEvent(this.level, this.blockPosition(), (EndCrystal) (Object) this).isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EndCrystal;remove()V")) + private void arclight$entityDamage(DamageSource source, float amount, CallbackInfoReturnable cir) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((EndCrystal) (Object)this, source, amount)) { + cir.setReturnValue(false); + } + } + + @Redirect(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;")) + private Explosion arclight$blockPrime(Level world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, Explosion.BlockInteraction modeIn) { + ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), explosionRadius, false); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + this.unsetRemoved(); + return null; + } else { + return world.explode(entityIn, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java new file mode 100644 index 00000000..6e726c27 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java @@ -0,0 +1,128 @@ +package io.izzel.arclight.common.mixin.core.world.entity.boss.enderdragon; + +import io.izzel.arclight.common.mixin.core.world.entity.MobMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.entity.boss.enderdragon.phases.DragonPhaseInstance; +import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.ArrayList; +import java.util.List; + +@Mixin(EnderDragon.class) +public abstract class EnderDragonMixin extends MobMixin { + + private Explosion explosionSource = new Explosion(null, (EnderDragon) (Object) this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.BlockInteraction.DESTROY); + + @Redirect(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/phases/DragonPhaseInstance;getFlyTargetLocation()Lnet/minecraft/world/phys/Vec3;")) + private Vec3 arclight$noMoveHovering(DragonPhaseInstance phase) { + Vec3 vec3d = phase.getFlyTargetLocation(); + return vec3d != null && phase.getPhase() != EnderDragonPhase.HOVERING ? vec3d : null; + } + + @Redirect(method = "checkCrystals", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;setHealth(F)V")) + private void arclight$regainHealth(EnderDragon enderDragonEntity, float health) { + EntityRegainHealthEvent event = new EntityRegainHealthEvent(this.getBukkitEntity(), 1.0F, EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + this.setHealth((float) (this.getHealth() + event.getAmount())); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + private boolean checkWalls(final AABB axisalignedbb) { + final int i = Mth.floor(axisalignedbb.minX); + final int j = Mth.floor(axisalignedbb.minY); + final int k = Mth.floor(axisalignedbb.minZ); + final int l = Mth.floor(axisalignedbb.maxX); + final int i2 = Mth.floor(axisalignedbb.maxY); + final int j2 = Mth.floor(axisalignedbb.maxZ); + boolean flag = false; + boolean flag2 = false; + final List destroyedBlocks = new ArrayList<>(); + for (int k2 = i; k2 <= l; ++k2) { + for (int l2 = j; l2 <= i2; ++l2) { + for (int i3 = k; i3 <= j2; ++i3) { + final BlockPos blockposition = new BlockPos(k2, l2, i3); + final BlockState iblockdata = this.level.getBlockState(blockposition); + final net.minecraft.world.level.block.Block block = iblockdata.getBlock(); + if (!iblockdata.isAir() && iblockdata.getMaterial() != Material.FIRE) { + if (net.minecraftforge.common.ForgeHooks.canEntityDestroy(this.level, blockposition, (EnderDragon) (Object) this) && !BlockTags.DRAGON_IMMUNE.contains(block)) { + flag2 = true; + destroyedBlocks.add(CraftBlock.at(this.level, blockposition)); + } else { + flag = true; + } + } + } + } + } + if (!flag2) { + return flag; + } + final org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity(); + final EntityExplodeEvent event = new EntityExplodeEvent(bukkitEntity, bukkitEntity.getLocation(), destroyedBlocks, 0.0f); + bukkitEntity.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return flag; + } + if (event.getYield() == 0.0f) { + for (final org.bukkit.block.Block block2 : event.blockList()) { + this.level.removeBlock(new BlockPos(block2.getX(), block2.getY(), block2.getZ()), false); + } + } else { + for (final org.bukkit.block.Block block2 : event.blockList()) { + final org.bukkit.Material blockId = block2.getType(); + if (blockId.isAir()) { + continue; + } + final CraftBlock craftBlock = (CraftBlock) block2; + final BlockPos blockposition2 = craftBlock.getPosition(); + final net.minecraft.world.level.block.Block nmsBlock = craftBlock.getNMS().getBlock(); + if (nmsBlock.dropFromExplosion(this.explosionSource)) { + BlockEntity tileentity = craftBlock.getNMS().hasBlockEntity() ? this.level.getBlockEntity(blockposition2) : null; + LootContext.Builder loottableinfo_builder = new LootContext.Builder((ServerLevel)this.level).withRandom(this.level.random).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockposition2)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withParameter(LootContextParams.EXPLOSION_RADIUS, 1.0f / event.getYield()).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity); + for (ItemStack stack : craftBlock.getNMS().getDrops(loottableinfo_builder)) { + Block.popResource(this.level, blockposition2, stack); + } + craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level, blockposition2, ItemStack.EMPTY); + // net.minecraft.block.Block.spawnDrops(craftBlock.getNMS(), loottableinfo_builder); + } + nmsBlock.wasExploded(this.level, blockposition2, this.explosionSource); + this.level.removeBlock(blockposition2, false); + } + } + if (flag2) { + final BlockPos blockposition3 = new BlockPos(i + this.random.nextInt(l - i + 1), j + this.random.nextInt(i2 - j + 1), k + this.random.nextInt(j2 - k + 1)); + this.level.levelEvent(2008, blockposition3, 0); + } + return flag; + } + +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/EnderDragonPhaseManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/EnderDragonPhaseManagerMixin.java new file mode 100644 index 00000000..c3fa48bc --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/EnderDragonPhaseManagerMixin.java @@ -0,0 +1,58 @@ +package io.izzel.arclight.common.mixin.core.world.entity.boss.enderdragon.phases; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.entity.boss.enderdragon.phases.DragonPhaseInstance; +import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase; +import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhaseManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.entity.CraftEnderDragon; +import org.bukkit.event.entity.EnderDragonChangePhaseEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(EnderDragonPhaseManager.class) +public abstract class EnderDragonPhaseManagerMixin { + + // @formatter:off + @Shadow @Final private static Logger LOGGER; + @Shadow @Final private EnderDragon dragon; + @Shadow private DragonPhaseInstance currentPhase; + @Shadow public abstract T getPhase(EnderDragonPhase phaseIn); + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void setPhase(EnderDragonPhase phaseIn) { + if (this.currentPhase == null || phaseIn != this.currentPhase.getPhase()) { + if (this.currentPhase != null) { + this.currentPhase.end(); + } + + EnderDragonChangePhaseEvent event = new EnderDragonChangePhaseEvent( + (CraftEnderDragon) ((EntityBridge) this.dragon).bridge$getBukkitEntity(), + (this.currentPhase == null) ? null : CraftEnderDragon.getBukkitPhase(this.currentPhase.getPhase()), + CraftEnderDragon.getBukkitPhase(phaseIn) + ); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + phaseIn = CraftEnderDragon.getMinecraftPhase(event.getNewPhase()); + + this.currentPhase = this.getPhase(phaseIn); + if (!this.dragon.level.isClientSide) { + this.dragon.getEntityData().set(EnderDragon.DATA_PHASE, phaseIn.getId()); + } + + LOGGER.debug("Dragon is now in phase {} on the {}", phaseIn, this.dragon.level.isClientSide ? "client" : "server"); + this.currentPhase.begin(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java new file mode 100644 index 00000000..9c46dbde --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java @@ -0,0 +1,160 @@ +package io.izzel.arclight.common.mixin.core.world.entity.boss.wither; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerBossEvent; +import net.minecraft.util.Mth; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.targeting.TargetingConditions; +import net.minecraft.world.entity.boss.wither.WitherBoss; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.event.ForgeEventFactory; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.List; + +@Mixin(WitherBoss.class) +public abstract class WitherBossMixin extends PathfinderMobMixin { + + // @formatter:off + @Shadow public abstract int getInvulnerableTicks(); + @Shadow public abstract void setInvulnerableTicks(int time); + @Shadow @Final private int[] nextHeadUpdate; + @Shadow @Final private int[] idleHeadUpdates; + @Shadow protected abstract void performRangedAttack(int head, double x, double y, double z, boolean invulnerable); + @Shadow public abstract int getAlternativeTarget(int head); + @Shadow public abstract void setAlternativeTarget(int targetOffset, int newId); + @Shadow protected abstract void performRangedAttack(int head, LivingEntity target); + @Shadow @Final private static TargetingConditions TARGETING_CONDITIONS; + @Shadow private int destroyBlocksTick; + @Shadow @Final public ServerBossEvent bossEvent; + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void customServerAiStep() { + if (this.getInvulnerableTicks() > 0) { + int k1 = this.getInvulnerableTicks() - 1; + this.bossEvent.setProgress(1.0F - (float) k1 / 220.0F); + if (k1 <= 0) { + Explosion.BlockInteraction explosion$blockinteraction = ForgeEventFactory.getMobGriefingEvent(this.level, (WitherBoss) (Object) this) ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE; + ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + this.level.explode((WitherBoss) (Object) this, this.getX(), this.getEyeY(), this.getZ(), event.getRadius(), event.getFire(), explosion$blockinteraction); + } + if (!this.isSilent()) { + this.level.globalLevelEvent(1023, this.blockPosition(), 0); + } + } + + this.setInvulnerableTicks(k1); + if (this.tickCount % 10 == 0) { + bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER_SPAWN); + this.heal(10.0F); + } + + } else { + super.customServerAiStep(); + + for (int i = 1; i < 3; ++i) { + if (this.tickCount >= this.nextHeadUpdate[i - 1]) { + this.nextHeadUpdate[i - 1] = this.tickCount + 10 + this.random.nextInt(10); + if (this.level.getDifficulty() == Difficulty.NORMAL || this.level.getDifficulty() == Difficulty.HARD) { + int i3 = i - 1; + int j3 = this.idleHeadUpdates[i - 1]; + this.idleHeadUpdates[i3] = this.idleHeadUpdates[i - 1] + 1; + if (j3 > 15) { + double d0 = Mth.nextDouble(this.random, this.getX() - 10.0D, this.getX() + 10.0D); + double d1 = Mth.nextDouble(this.random, this.getY() - 5.0D, this.getY() + 5.0D); + double d2 = Mth.nextDouble(this.random, this.getZ() - 10.0D, this.getZ() + 10.0D); + this.performRangedAttack(i + 1, d0, d1, d2, true); + this.idleHeadUpdates[i - 1] = 0; + } + } + + int l1 = this.getAlternativeTarget(i); + if (l1 > 0) { + LivingEntity livingentity = (LivingEntity) this.level.getEntity(l1); + if (livingentity != null && this.canAttack(livingentity) && !(this.distanceToSqr(livingentity) > 900.0D) && this.hasLineOfSight(livingentity)) { + this.performRangedAttack(i + 1, livingentity); + this.nextHeadUpdate[i - 1] = this.tickCount + 40 + this.random.nextInt(20); + this.idleHeadUpdates[i - 1] = 0; + } else { + if (CraftEventFactory.callEntityTargetLivingEvent((WitherBoss) (Object) this, livingentity, EntityTargetEvent.TargetReason.CLOSEST_ENTITY).isCancelled()) + continue; + this.setAlternativeTarget(i, 0); + } + } else { + List list = this.level.getNearbyEntities(LivingEntity.class, TARGETING_CONDITIONS, (WitherBoss) (Object) this, this.getBoundingBox().inflate(20.0D, 8.0D, 20.0D)); + if (!list.isEmpty()) { + LivingEntity livingentity1 = list.get(this.random.nextInt(list.size())); + if (CraftEventFactory.callEntityTargetLivingEvent((WitherBoss) (Object) this, livingentity1, EntityTargetEvent.TargetReason.CLOSEST_ENTITY).isCancelled()) + continue; + this.setAlternativeTarget(i, livingentity1.getId()); + } + } + } + } + + if (this.getTarget() != null) { + this.setAlternativeTarget(0, this.getTarget().getId()); + } else { + this.setAlternativeTarget(0, 0); + } + + if (this.destroyBlocksTick > 0) { + --this.destroyBlocksTick; + if (this.destroyBlocksTick == 0 && ForgeEventFactory.getMobGriefingEvent(this.level, (WitherBoss) (Object) this)) { + int j1 = Mth.floor(this.getY()); + int i2 = Mth.floor(this.getX()); + int j2 = Mth.floor(this.getZ()); + boolean flag = false; + + for (int j = -1; j <= 1; ++j) { + for (int k2 = -1; k2 <= 1; ++k2) { + for (int k = 0; k <= 3; ++k) { + int l2 = i2 + j; + int l = j1 + k; + int i1 = j2 + k2; + BlockPos blockpos = new BlockPos(l2, l, i1); + BlockState blockstate = this.level.getBlockState(blockpos); + if (blockstate.canEntityDestroy(this.level, blockpos, (WitherBoss) (Object) this) && ForgeEventFactory.onEntityDestroyBlock((WitherBoss) (Object) this, blockpos, blockstate)) { + if (CraftEventFactory.callEntityChangeBlockEvent((WitherBoss) (Object) this, blockpos, Blocks.AIR.defaultBlockState()).isCancelled()) { + continue; + } + flag = this.level.destroyBlock(blockpos, true, (WitherBoss) (Object) this) || flag; + } + } + } + } + + if (flag) { + this.level.levelEvent(null, 1022, this.blockPosition(), 0); + } + } + } + + if (this.tickCount % 20 == 0) { + bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.REGEN); + this.heal(1.0F); + } + + this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth()); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ArmorStandEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ArmorStandEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java index 72133f94..2ebc6e82 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ArmorStandEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java @@ -1,20 +1,17 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.decoration; import com.google.common.collect.Lists; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin; -import net.minecraft.entity.item.ArmorStandEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.EquipmentSlotType; -import net.minecraft.item.ItemStack; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Hand; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; +import io.izzel.arclight.common.mixin.core.world.entity.LivingEntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftEquipmentSlot; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -37,83 +34,83 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -@Mixin(ArmorStandEntity.class) -public abstract class ArmorStandEntityMixin extends LivingEntityMixin { +@Mixin(net.minecraft.world.entity.decoration.ArmorStand.class) +public abstract class ArmorStandMixin extends LivingEntityMixin { // @formatter:off - @Shadow private boolean canInteract; - @Shadow public abstract ItemStack getItemStackFromSlot(EquipmentSlotType slotIn); + @Shadow private boolean invisible; + @Shadow public abstract ItemStack getItemBySlot(net.minecraft.world.entity.EquipmentSlot slotIn); @Shadow @Final private NonNullList handItems; @Shadow @Final private NonNullList armorItems; // @formatter:on @Override public float getBukkitYaw() { - return this.rotationYaw; + return this.yRot; } - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/entity/item/ArmorStandEntity;remove()V")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill()V")) public void arclight$damageDropOut(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((ArmorStandEntity) (Object) this, source, amount)) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((net.minecraft.world.entity.decoration.ArmorStand) (Object) this, source, amount)) { cir.setReturnValue(false); } else { arclight$callEntityDeath(); } } - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/util/DamageSource;isExplosion()Z")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/damagesource/DamageSource;isExplosion()Z")) public void arclight$damageNormal(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((ArmorStandEntity) (Object) this, source, amount, true, this.canInteract)) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((net.minecraft.world.entity.decoration.ArmorStand) (Object) this, source, amount, true, this.invisible)) { cir.setReturnValue(false); } } - @Redirect(method = "attackEntityFrom", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/item/ArmorStandEntity;canInteract:Z")) - private boolean arclight$softenCondition(ArmorStandEntity entity) { + @Redirect(method = "hurt", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;invisible:Z")) + private boolean arclight$softenCondition(net.minecraft.world.entity.decoration.ArmorStand entity) { return false; } - @Inject(method = "attackEntityFrom", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/entity/item/ArmorStandEntity;remove()V")) + @Inject(method = "hurt", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill()V")) private void arclight$damageDeath1(DamageSource source, float amount, CallbackInfoReturnable cir) { arclight$callEntityDeath(); } - @Inject(method = "attackEntityFrom", at = @At(value = "INVOKE", ordinal = 2, target = "Lnet/minecraft/entity/item/ArmorStandEntity;remove()V")) + @Inject(method = "hurt", at = @At(value = "INVOKE", ordinal = 2, target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill()V")) private void arclight$damageDeath2(DamageSource source, float amount, CallbackInfoReturnable cir) { arclight$callEntityDeath(); } - @Inject(method = "damageArmorStand", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ArmorStandEntity;remove()V")) + @Inject(method = "causeDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill()V")) private void arclight$deathEvent2(DamageSource source, float p_213817_2_, CallbackInfo ci) { arclight$callEntityDeath(); } - @Redirect(method = "func_213816_g", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ArmorStandEntity;spawnDrops(Lnet/minecraft/util/DamageSource;)V")) - private void arclight$dropLater(ArmorStandEntity entity, DamageSource damageSourceIn) { + @Redirect(method = "brokenByAnything", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;dropAllDeathLoot(Lnet/minecraft/world/damagesource/DamageSource;)V")) + private void arclight$dropLater(net.minecraft.world.entity.decoration.ArmorStand entity, DamageSource damageSourceIn) { } - @Redirect(method = "func_213816_g", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;spawnAsEntity(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/item/ItemStack;)V")) - private void arclight$captureDropsDeath(World worldIn, BlockPos pos, ItemStack stack) { + @Redirect(method = "brokenByAnything", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;popResource(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V")) + private void arclight$captureDropsDeath(Level worldIn, BlockPos pos, ItemStack stack) { arclight$tryCaptureDrops(worldIn, pos, stack); } - @Inject(method = "func_213816_g", at = @At("RETURN")) + @Inject(method = "brokenByAnything", at = @At("RETURN")) private void arclight$spawnLast(DamageSource source, CallbackInfo ci) { - this.spawnDrops(source); + this.dropAllDeathLoot(source); } @Override - protected boolean canDropLoot() { + protected boolean shouldDropExperience() { return true; } - @Inject(method = "onKillCommand", at = @At("HEAD")) + @Inject(method = "kill", at = @At("HEAD")) private void arclight$deathEvent(CallbackInfo ci) { arclight$callEntityDeath(); } - private void arclight$tryCaptureDrops(World worldIn, BlockPos pos, ItemStack stack) { - if (!worldIn.isRemote && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.DO_TILE_DROPS) && !worldIn.restoringBlockSnapshots) { // do not drop items while restoring blockstates, prevents item dupe + private void arclight$tryCaptureDrops(Level worldIn, BlockPos pos, ItemStack stack) { + if (!worldIn.isClientSide && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots) { // do not drop items while restoring blockstates, prevents item dupe ItemEntity itementity = new ItemEntity(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack); arclight$drops().add(itementity); } @@ -140,12 +137,12 @@ public abstract class ArmorStandEntityMixin extends LivingEntityMixin { } else { drops = captureDrops.stream().map(ItemEntity::getItem).map(CraftItemStack::asCraftMirror).collect(Collectors.toList()); } - CraftEventFactory.callEntityDeathEvent((ArmorStandEntity) (Object) this, drops); + CraftEventFactory.callEntityDeathEvent((net.minecraft.world.entity.decoration.ArmorStand) (Object) this, drops); } - @Inject(method = "equipOrSwap", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;abilities:Lnet/minecraft/entity/player/PlayerAbilities;")) - public void arclight$manipulateEvent(PlayerEntity playerEntity, EquipmentSlotType slotType, ItemStack itemStack, Hand hand, CallbackInfoReturnable cir) { - ItemStack itemStack1 = this.getItemStackFromSlot(slotType); + @Inject(method = "swapItem", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getAbilities()Lnet/minecraft/world/entity/player/Abilities;")) + public void arclight$manipulateEvent(net.minecraft.world.entity.player.Player playerEntity, net.minecraft.world.entity.EquipmentSlot slotType, ItemStack itemStack, InteractionHand hand, CallbackInfoReturnable cir) { + ItemStack itemStack1 = this.getItemBySlot(slotType); org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemStack1); org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(itemStack); @@ -163,8 +160,8 @@ public abstract class ArmorStandEntityMixin extends LivingEntityMixin { } @Override - public void setSlot(EquipmentSlotType slotIn, ItemStack stack, boolean silent) { - switch (slotIn.getSlotType()) { + public void setSlot(net.minecraft.world.entity.EquipmentSlot slotIn, ItemStack stack, boolean silent) { + switch (slotIn.getType()) { case HAND: this.bridge$playEquipSound(stack, silent); this.handItems.set(slotIn.getIndex(), stack); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemFrameEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ItemFrameMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemFrameEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ItemFrameMixin.java index 693dae9e..8d3de8ff 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemFrameEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ItemFrameMixin.java @@ -1,15 +1,16 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.decoration; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.ItemFrameEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; +import io.izzel.arclight.common.mixin.core.world.entity.item.HangingEntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.decoration.ItemFrame; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.phys.AABB; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -18,14 +19,14 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ItemFrameEntity.class) -public abstract class ItemFrameEntityMixin extends HangingEntityMixin { +@Mixin(ItemFrame.class) +public abstract class ItemFrameMixin extends HangingEntityMixin { - @Shadow @Final private static DataParameter ITEM; + @Shadow @Final private static EntityDataAccessor DATA_ITEM; - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ItemFrameEntity;dropItemOrSelf(Lnet/minecraft/entity/Entity;Z)V")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ItemFrame;dropItem(Lnet/minecraft/world/entity/Entity;Z)V")) private void arclight$damageNonLiving(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (CraftEventFactory.handleNonLivingEntityDamageEvent((ItemFrameEntity) (Object) this, source, amount, false) || this.removed) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((ItemFrame) (Object) this, source, amount, false) || this.isRemoved()) { cir.setReturnValue(true); } } @@ -34,24 +35,24 @@ public abstract class ItemFrameEntityMixin extends HangingEntityMixin { if (!itemstack.isEmpty()) { itemstack = itemstack.copy(); itemstack.setCount(1); - itemstack.setAttachedEntity((ItemFrameEntity) (Object) this); + itemstack.setEntityRepresentation((ItemFrame) (Object) this); } - this.getDataManager().set(ITEM, itemstack); + this.getEntityData().set(DATA_ITEM, itemstack); if (!itemstack.isEmpty() && playSound) { - this.playSound(SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, 1.0f, 1.0f); + this.playSound(SoundEvents.ITEM_FRAME_ADD_ITEM, 1.0f, 1.0f); } - if (flag && this.hangingPosition != null) { - this.world.updateComparatorOutputLevel(this.hangingPosition, Blocks.AIR); + if (flag && this.pos != null) { + this.level.updateNeighbourForOutputSignal(this.pos, Blocks.AIR); } } - private static AxisAlignedBB calculateBoundingBox(Entity entity, BlockPos blockPosition, Direction direction, int width, int height) { + private static AABB calculateBoundingBox(Entity entity, BlockPos blockPosition, Direction direction, int width, int height) { double d0 = 0.46875; - double locX = blockPosition.getX() + 0.5 - direction.getXOffset() * 0.46875; - double locY = blockPosition.getY() + 0.5 - direction.getYOffset() * 0.46875; - double locZ = blockPosition.getZ() + 0.5 - direction.getZOffset() * 0.46875; + double locX = blockPosition.getX() + 0.5 - direction.getStepX() * 0.46875; + double locY = blockPosition.getY() + 0.5 - direction.getStepY() * 0.46875; + double locZ = blockPosition.getZ() + 0.5 - direction.getStepZ() * 0.46875; if (entity != null) { - entity.setRawPosition(locX, locY, locZ); + entity.setPosRaw(locX, locY, locZ); } double d2 = width; double d3 = height; @@ -74,6 +75,6 @@ public abstract class ItemFrameEntityMixin extends HangingEntityMixin { d2 /= 32.0; d3 /= 32.0; d4 /= 32.0; - return new AxisAlignedBB(locX - d2, locY - d3, locZ - d4, locX + d2, locY + d3, locZ + d4); + return new AABB(locX - d2, locY - d3, locZ - d4, locX + d2, locY + d3, locZ + d4); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java new file mode 100644 index 00000000..394f9d22 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java @@ -0,0 +1,69 @@ +package io.izzel.arclight.common.mixin.core.world.entity.decoration; + +import io.izzel.arclight.common.mixin.core.world.entity.item.HangingEntityMixin; +import net.minecraft.network.protocol.game.ClientboundSetEntityLinkPacket; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.decoration.LeashFenceKnotEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.AABB; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(LeashFenceKnotEntity.class) +public abstract class LeashFenceKnotEntityMixin extends HangingEntityMixin { + + @Inject(method = "recalculateBoundingBox", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;updateChunkPos(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$checkIfValid(CallbackInfo ci) { + if (!valid) ci.cancel(); + } + + /** + * @author IzzelAliz + * @reason + */ + @SuppressWarnings("ConstantConditions") + @Overwrite + public InteractionResult interact(final Player entityhuman, final InteractionHand enumhand) { + if (this.level.isClientSide) { + return InteractionResult.SUCCESS; + } + boolean flag = false; + final double d0 = 7.0; + final List list = this.level.getEntitiesOfClass(Mob.class, new AABB(this.getX() - 7.0, this.getY() - 7.0, this.getZ() - 7.0, this.getX() + 7.0, this.getY() + 7.0, this.getZ() + 7.0)); + for (final Mob entityinsentient : list) { + if (entityinsentient.getLeashHolder() == entityhuman) { + if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, (LeashFenceKnotEntity) (Object) this, entityhuman).isCancelled()) { + ((ServerPlayer) entityhuman).connection.send(new ClientboundSetEntityLinkPacket(entityinsentient, entityinsentient.getLeashHolder())); + } else { + entityinsentient.setLeashedTo((LeashFenceKnotEntity) (Object) this, true); + flag = true; + } + } + } + if (!flag) { + boolean die = true; + for (final Mob entityinsentient : list) { + if (entityinsentient.isLeashed() && entityinsentient.getLeashHolder() == (Object) this) { + if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) { + die = false; + } else { + entityinsentient.dropLeash(true, !entityhuman.getAbilities().instabuild); + } + } + } + if (die) { + this.discard(); + } + } + return InteractionResult.CONSUME; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/PaintingMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/PaintingMixin.java new file mode 100644 index 00000000..801e5cdd --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/PaintingMixin.java @@ -0,0 +1,28 @@ +package io.izzel.arclight.common.mixin.core.world.entity.decoration; + +import com.google.common.collect.Lists; +import io.izzel.arclight.common.mixin.core.world.entity.item.HangingEntityMixin; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.decoration.Motive; +import net.minecraft.world.entity.decoration.Painting; +import net.minecraft.world.level.Level; +import net.minecraftforge.registries.ForgeRegistries; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(Painting.class) +public abstract class PaintingMixin extends HangingEntityMixin { + + @Shadow public Motive motive; + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { + final List list = Lists.newArrayList(ForgeRegistries.PAINTING_TYPES.getValues()); + this.motive = list.get(this.random.nextInt(list.size())); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/FallingBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/FallingBlockEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java index ab4a3ad6..aea70f66 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/FallingBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java @@ -1,10 +1,11 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.item; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.item.FallingBlockEntity; -import net.minecraft.util.math.BlockPos; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -17,22 +18,22 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(FallingBlockEntity.class) public abstract class FallingBlockEntityMixin extends EntityMixin { - @Shadow private BlockState fallTile; + @Shadow private BlockState blockState; - @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) + @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) private void arclight$entityChangeBlock(CallbackInfo ci, Block block, BlockPos pos) { - if (CraftEventFactory.callEntityChangeBlockEvent((FallingBlockEntity) (Object) this, pos, this.fallTile).isCancelled()) { + if (CraftEventFactory.callEntityChangeBlockEvent((FallingBlockEntity) (Object) this, pos, this.blockState).isCancelled()) { ci.cancel(); } } - @Inject(method = "onLivingFall", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - private void arclight$damageSource(float distance, float damageMultiplier, CallbackInfoReturnable cir) { + @Inject(method = "causeFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + private void arclight$damageSource(float distance, float damageMultiplier, DamageSource source, CallbackInfoReturnable cir) { CraftEventFactory.entityDamage = (FallingBlockEntity) (Object) this; } - @Inject(method = "onLivingFall", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) - private void arclight$damageSourceReset(float distance, float damageMultiplier, CallbackInfoReturnable cir) { + @Inject(method = "causeFallDamage", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + private void arclight$damageSourceReset(float distance, float damageMultiplier, DamageSource source, CallbackInfoReturnable cir) { CraftEventFactory.entityDamage = null; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/HangingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java similarity index 63% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/HangingEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java index 31df334b..c047bc75 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/HangingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.item; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.util.IndirectEntityDamageSourceBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.block.material.Material; -import net.minecraft.entity.Entity; -import net.minecraft.entity.MoverType; -import net.minecraft.entity.item.HangingEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.Direction; -import net.minecraft.util.IndirectEntityDamageSource; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.vector.Vector3d; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.damagesource.IndirectEntityDamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.decoration.HangingEntity; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.entity.Hanging; import org.bukkit.event.hanging.HangingBreakByEntityEvent; @@ -28,12 +28,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public abstract class HangingEntityMixin extends EntityMixin { // @formatter:off - @Shadow public BlockPos hangingPosition; + @Shadow public BlockPos pos; // @formatter:on - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;remove()V")) + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/HangingEntity;discard()V")) private void arclight$hangingBreak(CallbackInfo ci) { - Material material = this.world.getBlockState(new BlockPos(this.getPosition())).getMaterial(); + Material material = this.level.getBlockState(new BlockPos(this.blockPosition())).getMaterial(); HangingBreakEvent.RemoveCause cause; if (!material.equals(Material.AIR)) { cause = HangingBreakEvent.RemoveCause.OBSTRUCTION; @@ -42,14 +42,14 @@ public abstract class HangingEntityMixin extends EntityMixin { } HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), cause); Bukkit.getPluginManager().callEvent(event); - if (this.removed || event.isCancelled()) { + if (this.isRemoved() || event.isCancelled()) { ci.cancel(); } } - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;remove()V")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/HangingEntity;kill()V")) private void arclight$hangingBreakByAttack(DamageSource source, float amount, CallbackInfoReturnable cir) { - Entity damager = (source instanceof IndirectEntityDamageSource) ? ((IndirectEntityDamageSourceBridge) source).bridge$getProximateDamageSource() : source.getTrueSource(); + Entity damager = (source instanceof IndirectEntityDamageSource) ? ((IndirectEntityDamageSourceBridge) source).bridge$getProximateDamageSource() : source.getEntity(); HangingBreakEvent event; if (damager != null) { event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), ((EntityBridge) damager).bridge$getBukkitEntity(), source.isExplosion() ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.ENTITY); @@ -57,25 +57,25 @@ public abstract class HangingEntityMixin extends EntityMixin { event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), source.isExplosion() ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.DEFAULT); } Bukkit.getPluginManager().callEvent(event); - if (this.removed || event.isCancelled()) { + if (this.isRemoved() || event.isCancelled()) { cir.setReturnValue(true); } } - @Inject(method = "move", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/HangingEntity;remove()V")) - private void arclight$hangingBreakByMove(MoverType typeIn, Vector3d pos, CallbackInfo ci) { - if (this.removed) { + @Inject(method = "move", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/HangingEntity;kill()V")) + private void arclight$hangingBreakByMove(MoverType typeIn, Vec3 pos, CallbackInfo ci) { + if (this.isRemoved()) { ci.cancel(); return; } HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); Bukkit.getPluginManager().callEvent(event); - if (this.removed || event.isCancelled()) { + if (this.isRemoved() || event.isCancelled()) { ci.cancel(); } } - @Inject(method = "addVelocity", cancellable = true, at = @At("HEAD")) + @Inject(method = "push", cancellable = true, at = @At("HEAD")) private void arclight$noVelocity(double x, double y, double z, CallbackInfo ci) { ci.cancel(); } @@ -84,21 +84,21 @@ public abstract class HangingEntityMixin extends EntityMixin { return i % 32 == 0 ? 0.5D : 0.0D; } - private static AxisAlignedBB calculateBoundingBox(Entity entity, BlockPos blockPosition, Direction direction, int width, int height) { + private static AABB calculateBoundingBox(Entity entity, BlockPos blockPosition, Direction direction, int width, int height) { double d0 = blockPosition.getX() + 0.5; double d2 = blockPosition.getY() + 0.5; double d3 = blockPosition.getZ() + 0.5; double d4 = 0.46875; double d5 = a(width); double d6 = a(height); - d0 -= direction.getXOffset() * 0.46875; - d3 -= direction.getZOffset() * 0.46875; + d0 -= direction.getStepX() * 0.46875; + d3 -= direction.getStepZ() * 0.46875; d2 += d6; - Direction enumdirection = direction.rotateYCCW(); - d0 += d5 * enumdirection.getXOffset(); - d3 += d5 * enumdirection.getZOffset(); + Direction enumdirection = direction.getCounterClockWise(); + d0 += d5 * enumdirection.getStepX(); + d3 += d5 * enumdirection.getStepZ(); if (entity != null) { - entity.setRawPosition(d0, d2, d3); + entity.setPosRaw(d0, d2, d3); } double d7 = width; double d8 = height; @@ -111,6 +111,6 @@ public abstract class HangingEntityMixin extends EntityMixin { d7 /= 32.0; d8 /= 32.0; d9 /= 32.0; - return new AxisAlignedBB(d0 - d7, d2 - d8, d3 - d9, d0 + d7, d2 + d8, d3 + d9); + return new AABB(d0 - d7, d2 - d8, d3 - d9, d0 + d7, d2 + d8, d3 + d9); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java similarity index 69% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java index 1137cf97..ffc464bc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/ItemEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java @@ -1,17 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.item; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.network.datasync.EntityDataManagerBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.network.datasync.DataParameter; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.stats.Stats; -import net.minecraft.util.DamageSource; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.fmllegacy.hooks.BasicEventHooks; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.Item; @@ -33,20 +34,20 @@ import java.util.UUID; public abstract class ItemEntityMixin extends EntityMixin { // @formatter:off - @Shadow @Final private static DataParameter ITEM; + @Shadow @Final private static EntityDataAccessor DATA_ITEM; @Shadow public int pickupDelay; @Shadow public abstract ItemStack getItem(); @Shadow private UUID owner; // @formatter:on - @Inject(method = "func_213858_a", cancellable = true, at = @At("HEAD")) + @Inject(method = "merge(Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;)V", cancellable = true, at = @At("HEAD")) private static void arclight$itemMerge(ItemEntity from, ItemStack stack1, ItemEntity to, ItemStack stack2, CallbackInfo ci) { if (CraftEventFactory.callItemMergeEvent(to, from).isCancelled()) { ci.cancel(); } } - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ItemEntity;markVelocityChanged()V")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;markHurt()V")) private void arclight$damageNonLiving(DamageSource source, float amount, CallbackInfoReturnable cir) { if (CraftEventFactory.handleNonLivingEntityDamageEvent((ItemEntity) (Object) this, source, amount)) { cir.setReturnValue(false); @@ -55,7 +56,7 @@ public abstract class ItemEntityMixin extends EntityMixin { @Override public void burn(float amount) { - this.attackEntityFrom(DamageSource.IN_FIRE, amount); + this.hurt(DamageSource.IN_FIRE, amount); } /** @@ -63,23 +64,23 @@ public abstract class ItemEntityMixin extends EntityMixin { * @reason */ @Overwrite - public void onCollideWithPlayer(final PlayerEntity entity) { - if (!this.world.isRemote) { + public void playerTouch(final Player entity) { + if (!this.level.isClientSide) { if (this.pickupDelay > 0) return; final ItemStack itemstack = this.getItem(); - final net.minecraft.item.Item item = itemstack.getItem(); + final net.minecraft.world.item.Item item = itemstack.getItem(); final int i = itemstack.getCount(); int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup((ItemEntity) (Object) this, entity); if (hook < 0) return; ItemStack copy = itemstack.copy(); - final int canHold = ((PlayerInventoryBridge) entity.inventory).bridge$canHold(itemstack); + final int canHold = ((PlayerInventoryBridge) entity.getInventory()).bridge$canHold(itemstack); final int remaining = i - canHold; if (this.pickupDelay <= 0 && (hook == 1 || canHold > 0)) { copy.setCount(canHold); - net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerItemPickupEvent(entity, (ItemEntity) (Object) this, copy); + BasicEventHooks.firePlayerItemPickupEvent(entity, (ItemEntity) (Object) this, copy); itemstack.setCount(canHold); final PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), (Item) this.getBukkitEntity(), remaining); @@ -101,13 +102,14 @@ public abstract class ItemEntityMixin extends EntityMixin { } else if (this.pickupDelay == 0) { this.pickupDelay = -1; } - if (this.pickupDelay == 0 && (this.owner == null /*|| 6000 - this.age <= 200*/ || this.owner.equals(entity.getUniqueID())) && entity.inventory.addItemStackToInventory(itemstack)) { - entity.onItemPickup((ItemEntity) (Object) this, i); + if (this.pickupDelay == 0 && (this.owner == null /*|| 6000 - this.age <= 200*/ || this.owner.equals(entity.getUUID())) && entity.getInventory().add(itemstack)) { + entity.take((ItemEntity) (Object) this, i); if (itemstack.isEmpty()) { - this.remove(); + this.discard(); itemstack.setCount(i); } - entity.addStat(Stats.ITEM_PICKED_UP.get(item), i); + entity.awardStat(Stats.ITEM_PICKED_UP.get(item), i); + entity.onItemPickup((ItemEntity) (Object) this); } } } @@ -121,10 +123,10 @@ public abstract class ItemEntityMixin extends EntityMixin { @Inject(method = "setItem", at = @At("RETURN")) private void arclight$markDirty(ItemStack stack, CallbackInfo ci) { - ((EntityDataManagerBridge) this.getDataManager()).bridge$markDirty(ITEM); + ((EntityDataManagerBridge) this.getEntityData()).bridge$markDirty(DATA_ITEM); } - @Redirect(method = "func_226531_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/ItemEntity;setItem(Lnet/minecraft/item/ItemStack;)V")) + @Redirect(method = "merge(Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;setItem(Lnet/minecraft/world/item/ItemStack;)V")) private static void arclight$setNonEmpty(ItemEntity itemEntity, ItemStack stack) { if (!stack.isEmpty()) { itemEntity.setItem(stack); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java new file mode 100644 index 00000000..08ad89d5 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java @@ -0,0 +1,89 @@ +package io.izzel.arclight.common.mixin.core.world.entity.item; + +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.item.PrimedTnt; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import org.bukkit.Bukkit; +import org.bukkit.entity.Explosive; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(PrimedTnt.class) +public abstract class PrimedTntMixin extends EntityMixin { + + // @formatter:off + @Shadow public abstract int getFuse(); + @Shadow public abstract void setFuse(int p_32086_); + // @formatter:on + + public float yield; + public boolean isIncendiary; + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { + yield = 4; + isIncendiary = false; + } + + @Inject(method = "(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/entity/LivingEntity;)V", at = @At("RETURN")) + private void arclight$init(Level worldIn, double x, double y, double z, LivingEntity igniter, CallbackInfo ci) { + yield = 4; + isIncendiary = false; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void tick() { + if (!this.isNoGravity()) { + this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D)); + } + + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.98D)); + if (this.onGround) { + this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D)); + } + + int i = this.getFuse() - 1; + + this.setFuse(i); + if (i <= 0) { + if (!this.level.isClientSide) { + this.explode(); + } + this.discard(); + } else { + this.updateInWaterStateAndDoFluidPushing(); + if (this.level.isClientSide) { + this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D); + } + } + + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void explode() { + ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) this.getBukkitEntity()); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + this.level.explode((PrimedTnt) (Object) this, this.getX(), this.getY(0.0625), this.getZ(), event.getRadius(), event.getFire(), Explosion.BlockInteraction.BREAK); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/AbstractSkeletonMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/AbstractSkeletonMixin.java new file mode 100644 index 00000000..6334498b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/AbstractSkeletonMixin.java @@ -0,0 +1,36 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.AbstractSkeleton; +import net.minecraft.world.entity.projectile.AbstractArrow; +import net.minecraft.world.item.ItemStack; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityShootBowEvent; +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; + +@Mixin(AbstractSkeleton.class) +public abstract class AbstractSkeletonMixin extends PathfinderMobMixin { + + @Inject(method = "performRangedAttack", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/AbstractSkeleton;playSound(Lnet/minecraft/sounds/SoundEvent;FF)V")) + private void arclight$shootBow(LivingEntity target, float distanceFactor, CallbackInfo ci, ItemStack itemStack, AbstractArrow arrowEntity) { + EntityShootBowEvent event = CraftEventFactory.callEntityShootBowEvent((AbstractSkeleton) (Object) this, this.getMainHandItem(), null, arrowEntity, InteractionHand.MAIN_HAND, 0.8F, true); + if (event.isCancelled()) { + event.getProjectile().remove(); + ci.cancel(); + return; + } + if (event.getProjectile() != ((EntityBridge) arrowEntity).bridge$getBukkitEntity()) { + this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F)); + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CaveSpiderEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CaveSpiderMixin.java similarity index 54% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CaveSpiderEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CaveSpiderMixin.java index e68272ab..458b6f6b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/CaveSpiderEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CaveSpiderMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.CaveSpiderEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.CaveSpider; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(CaveSpiderEntity.class) -public abstract class CaveSpiderEntityMixin extends SpiderEntityMixin { +@Mixin(CaveSpider.class) +public abstract class CaveSpiderMixin extends SpiderMixin { - @Inject(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$potionAttack(Entity entityIn, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java new file mode 100644 index 00000000..22c99281 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java @@ -0,0 +1,83 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.monster.CreeperEntityBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.AreaEffectCloud; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.monster.Creeper; +import net.minecraft.world.level.Explosion; +import net.minecraftforge.event.ForgeEventFactory; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreeperPowerEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import 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.Collection; + +@Mixin(Creeper.class) +public abstract class CreeperMixin extends PathfinderMobMixin implements CreeperEntityBridge { + + // @formatter:off + @Shadow @Final private static EntityDataAccessor DATA_IS_POWERED; + @Shadow public int explosionRadius; + @Shadow protected abstract void spawnLingeringCloud(); + @Shadow private int swell; + // @formatter:on + + @Inject(method = "thunderHit", cancellable = true, at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/monster/Creeper;entityData:Lnet/minecraft/network/syncher/SynchedEntityData;")) + private void arclight$lightningBolt(ServerLevel world, LightningBolt lightningBolt, CallbackInfo ci) { + if (CraftEventFactory.callCreeperPowerEvent((Creeper) (Object) this, lightningBolt, CreeperPowerEvent.PowerCause.LIGHTNING).isCancelled()) { + ci.cancel(); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void explodeCreeper() { + if (!this.level.isClientSide) { + Explosion.BlockInteraction explosion_effect = ForgeEventFactory.getMobGriefingEvent(this.level, (Creeper) (Object) this) ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.NONE; + final float f = this.entityData.get(DATA_IS_POWERED) ? 2.0f : 1.0f; + final ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), this.explosionRadius * f, false); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + this.dead = true; + this.level.explode((Creeper) (Object) this, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), explosion_effect); + this.discard(); + this.spawnLingeringCloud(); + } else { + this.swell = 0; + } + } + } + + @Inject(method = "spawnLingeringCloud", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$creeperCloud(CallbackInfo ci, Collection collection, AreaEffectCloud areaeffectcloudentity) { + areaeffectcloudentity.setOwner((Creeper) (Object) this); + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EXPLOSION); + } + + public void setPowered(boolean power) { + this.entityData.set(DATA_IS_POWERED, power); + } + + @Override + public void bridge$setPowered(boolean power) { + setPowered(power); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ElderGuardianMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ElderGuardianMixin.java new file mode 100644 index 00000000..46e91d06 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ElderGuardianMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.ElderGuardian; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ElderGuardian.class) +public abstract class ElderGuardianMixin extends PathfinderMobMixin { + + @Redirect(method = "customServerAiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$potionReason(ServerPlayer playerEntity, MobEffectInstance effectInstanceIn, Entity entity) { + ((ServerPlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + return playerEntity.addEffect(effectInstanceIn); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderManMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderManMixin.java new file mode 100644 index 00000000..433bf54c --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderManMixin.java @@ -0,0 +1,67 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.monster.EndermanEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.AttributeInstance; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.monster.EnderMan; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import javax.annotation.Nullable; + +@Mixin(EnderMan.class) +public abstract class EnderManMixin extends PathfinderMobMixin implements EndermanEntityBridge { + + // @formatter:off + @Shadow private int targetChangeTime; + @Shadow @Final private static EntityDataAccessor DATA_CREEPY; + @Shadow @Final private static EntityDataAccessor DATA_STARED_AT; + @Shadow @Final private static AttributeModifier SPEED_MODIFIER_ATTACKING; + // @formatter:on + + @Override + public void bridge$updateTarget(LivingEntity livingEntity) { + AttributeInstance modifiableattributeinstance = this.getAttribute(Attributes.MOVEMENT_SPEED); + if (livingEntity == null) { + this.targetChangeTime = 0; + this.entityData.set(DATA_CREEPY, false); + this.entityData.set(DATA_STARED_AT, false); + modifiableattributeinstance.removeModifier(SPEED_MODIFIER_ATTACKING); + } else { + this.targetChangeTime = this.tickCount; + this.entityData.set(DATA_CREEPY, true); + if (!modifiableattributeinstance.hasModifier(SPEED_MODIFIER_ATTACKING)) { + modifiableattributeinstance.addTransientModifier(SPEED_MODIFIER_ATTACKING); + } + } + } + + @Override + public boolean setGoalTarget(LivingEntity livingEntity, EntityTargetEvent.TargetReason reason, boolean fireEvent) { + if (!super.setGoalTarget(livingEntity, reason, fireEvent)) { + return false; + } + bridge$updateTarget(getTarget()); + return true; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void setTarget(@Nullable LivingEntity entity) { + this.bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); + super.setTarget(entity); + if (arclight$targetSuccess) { + bridge$updateTarget(getTarget()); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_PlaceBlockGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanLeaveBlockGoalMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_PlaceBlockGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanLeaveBlockGoalMixin.java index 6bdb53ef..b82defe8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_PlaceBlockGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanLeaveBlockGoalMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; -import net.minecraft.block.BlockState; -import net.minecraft.entity.monster.EndermanEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -15,16 +15,16 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Random; -@Mixin(targets = "net.minecraft.entity.monster.EndermanEntity.PlaceBlockGoal") -public class EndermanEntity_PlaceBlockGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.monster.EnderMan.EndermanLeaveBlockGoal") +public class EnderMan_EndermanLeaveBlockGoalMixin { // @formatter:off - @Shadow @Final private EndermanEntity enderman; + @Shadow @Final private EnderMan enderman; // @formatter:on @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$entityChangeBlock(CallbackInfo ci, Random random, World world, int i, int j, int k, BlockPos blockPos, BlockState blockState, BlockPos blockPos1, BlockState blockState1, BlockState blockState2) { + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$entityChangeBlock(CallbackInfo ci, Random random, Level world, int i, int j, int k, BlockPos blockPos, BlockState blockState, BlockPos blockPos1, BlockState blockState1, BlockState blockState2) { if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockPos, blockState2).isCancelled()) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_TakeBlockGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanTakeBlockGoalMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_TakeBlockGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanTakeBlockGoalMixin.java index 977d9588..e8fe7fcf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/EndermanEntity_TakeBlockGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EnderMan_EndermanTakeBlockGoalMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; -import net.minecraft.block.Blocks; -import net.minecraft.entity.monster.EndermanEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.monster.EnderMan; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -15,17 +15,17 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Random; -@Mixin(targets = "net.minecraft.entity.monster.EndermanEntity.TakeBlockGoal") -public class EndermanEntity_TakeBlockGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.monster.EnderMan.EndermanTakeBlockGoal") +public class EnderMan_EndermanTakeBlockGoalMixin { // @formatter:off - @Shadow @Final private EndermanEntity enderman; + @Shadow @Final private EnderMan enderman; // @formatter:on @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/EndermanEntity;setHeldBlockState(Lnet/minecraft/block/BlockState;)V")) - private void arclight$entityChangeBlock(CallbackInfo ci, Random random, World world, int i, int j, int k, BlockPos blockPos) { - if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockPos, Blocks.AIR.getDefaultState()).isCancelled()) { + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/EnderMan;setCarriedBlock(Lnet/minecraft/world/level/block/state/BlockState;)V")) + private void arclight$entityChangeBlock(CallbackInfo ci, Random random, Level world, int i, int j, int k, BlockPos blockPos) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockPos, Blocks.AIR.defaultBlockState()).isCancelled()) { ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Ghast_GhastShootFireballGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Ghast_GhastShootFireballGoalMixin.java new file mode 100644 index 00000000..9d306562 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Ghast_GhastShootFireballGoalMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import io.izzel.arclight.common.bridge.entity.projectile.DamagingProjectileEntityBridge; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.Ghast; +import net.minecraft.world.level.Level; + +@Mixin(targets = "net.minecraft.world.entity.monster.Ghast.GhastShootFireballGoal") +public abstract class Ghast_GhastShootFireballGoalMixin { + + @Shadow @Final private Ghast ghast; + + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$setYaw(Level world, Entity entityIn) { + ((DamagingProjectileEntityBridge) entityIn).bridge$setBukkitYield(this.ghast.getExplosionPower()); + return world.addFreshEntity(entityIn); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/HuskEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/HuskMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/HuskEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/HuskMixin.java index 10ce789f..996e032a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/HuskEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/HuskMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.HuskEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.Husk; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(HuskEntity.class) -public abstract class HuskEntityMixin extends ZombieEntityMixin { +@Mixin(Husk.class) +public abstract class HuskMixin extends ZombieMixin { - @Inject(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$reason(Entity entityIn, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_BlindnessSpellGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_BlindnessSpellGoalMixin.java similarity index 54% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_BlindnessSpellGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_BlindnessSpellGoalMixin.java index 3a7c725d..5a7aaf8f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_BlindnessSpellGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_BlindnessSpellGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.monster.IllusionerEntity; +import net.minecraft.world.entity.monster.Illusioner; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,13 +9,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = "net.minecraft.entity.monster.IllusionerEntity.BlindnessSpellGoal") -public class IllusionerEntity_BlindnessSpellGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.monster.Illusioner.IllusionerBlindnessSpellGoal") +public class Illusioner_BlindnessSpellGoalMixin { - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_210765_a"}, remap = false) - private IllusionerEntity outerThis; + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_32941_"}, remap = false) + private Illusioner outerThis; - @Inject(method = "castSpell", at = @At("HEAD")) + @Inject(method = "performSpellCasting", at = @At("HEAD")) private void arclight$reason(CallbackInfo ci) { ((LivingEntityBridge) outerThis).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_MirrorSpellGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_MirrorSpellGoalMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_MirrorSpellGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_MirrorSpellGoalMixin.java index ce0e311c..a82d7101 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/IllusionerEntity_MirrorSpellGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Illusioner_MirrorSpellGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.monster.IllusionerEntity; +import net.minecraft.world.entity.monster.Illusioner; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,13 +9,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = "net.minecraft.entity.monster.IllusionerEntity.MirrorSpellGoal") -public class IllusionerEntity_MirrorSpellGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.monster.Illusioner.IllusionerMirrorSpellGoal") +public class Illusioner_MirrorSpellGoalMixin { - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_210767_a"}, remap = false) - private IllusionerEntity outerThis; + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_32955_"}, remap = false) + private Illusioner outerThis; - @Inject(method = "castSpell", at = @At("HEAD")) + @Inject(method = "performSpellCasting", at = @At("HEAD")) private void arclight$reason(CallbackInfo ci) { ((LivingEntityBridge) outerThis).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ILLUSION); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Phantom_AttackPlayerTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Phantom_AttackPlayerTargetGoalMixin.java new file mode 100644 index 00000000..debb0707 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Phantom_AttackPlayerTargetGoalMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.entity.monster.Phantom; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(targets = "net.minecraft.world.entity.monster.Phantom.PhantomAttackPlayerTargetGoal") +public abstract class Phantom_AttackPlayerTargetGoalMixin { + + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_33191_"}, remap = false) + private Phantom outerThis; + + @Inject(method = "canContinueToUse", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/entity/monster/Phantom$PhantomAttackPlayerTargetGoal;canAttack(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/ai/targeting/TargetingConditions;)Z")) + private void arclight$reason(CallbackInfoReturnable cir) { + ((MobEntityBridge) outerThis).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/RavagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/RavagerMixin.java new file mode 100644 index 00000000..caf7863c --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/RavagerMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.Ravager; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(Ravager.class) +public abstract class RavagerMixin extends PathfinderMobMixin { + + @Redirect(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$entityChangeBlock(Level world, BlockPos pos, boolean dropBlock, Entity entityIn) { + return !CraftEventFactory.callEntityChangeBlockEvent((Ravager) (Object) this, pos, Blocks.AIR.defaultBlockState()).isCancelled() + && world.destroyBlock(pos, dropBlock, entityIn); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ShulkerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ShulkerMixin.java new file mode 100644 index 00000000..40975826 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ShulkerMixin.java @@ -0,0 +1,78 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.monster.Shulker; +import net.minecraft.world.phys.AABB; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityTeleportEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; + +@Mixin(Shulker.class) +public abstract class ShulkerMixin extends PathfinderMobMixin { + + // @formatter:off + @Shadow @Nullable protected abstract Direction findAttachableSurface(BlockPos p_149811_); + @Shadow protected abstract void setAttachFace(Direction p_149789_); + @Shadow @Final protected static EntityDataAccessor DATA_PEEK_ID; + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected boolean teleportSomewhere() { + if (!this.isNoAi() && this.isAlive()) { + BlockPos blockpos = this.blockPosition(); + + for (int i = 0; i < 5; ++i) { + BlockPos blockpos1 = blockpos.offset(Mth.randomBetweenInclusive(this.random, -8, 8), Mth.randomBetweenInclusive(this.random, -8, 8), Mth.randomBetweenInclusive(this.random, -8, 8)); + if (blockpos1.getY() > this.level.getMinBuildHeight() && this.level.isEmptyBlock(blockpos1) && this.level.getWorldBorder().isWithinBounds(blockpos1) && this.level.noCollision((Shulker) (Object) this, (new AABB(blockpos1)).deflate(1.0E-6D))) { + Direction direction = this.findAttachableSurface(blockpos1); + if (direction != null) { + EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), new Location(((WorldBridge) this.level).bridge$getWorld(), blockpos1.getX(), blockpos1.getY(), blockpos1.getZ())); + Bukkit.getPluginManager().callEvent(teleport); + if (!teleport.isCancelled()) { + Location to = teleport.getTo(); + blockpos1 = new BlockPos(to.getX(), to.getY(), to.getZ()); + } else { + return false; + } + this.unRide(); + this.setAttachFace(direction); + this.playSound(SoundEvents.SHULKER_TELEPORT, 1.0F, 1.0F); + this.setPos((double) blockpos1.getX() + 0.5D, blockpos1.getY(), (double) blockpos1.getZ() + 0.5D); + this.entityData.set(DATA_PEEK_ID, (byte) 0); + this.setTarget(null); + return true; + } + } + } + + return false; + } else { + return false; + } + } + + @Inject(method = "hitByShulkerBullet", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$breedCause(CallbackInfo ci) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java new file mode 100644 index 00000000..916baec0 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java @@ -0,0 +1,29 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.ai.goal.RandomStrollGoal; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.InfestedBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(targets = "net.minecraft.world.entity.monster.Silverfish.SilverfishMergeWithStoneGoal") +public abstract class Silverfish_MergeWithStoneGoalMixin extends RandomStrollGoal { + + public Silverfish_MergeWithStoneGoalMixin(PathfinderMob creatureIn, double speedIn) { + super(creatureIn, speedIn); + } + + @Inject(method = "start", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelAccessor;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$entityChangeBlock(CallbackInfo ci, LevelAccessor world, BlockPos blockPos, BlockState blockState) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockPos, InfestedBlock.infestedStateByHost(blockState)).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_SummonSilverfishGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_WakeUpFriendsGoalMixin.java similarity index 60% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_SummonSilverfishGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_WakeUpFriendsGoalMixin.java index fd9a0119..c7600226 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SilverfishEntity_SummonSilverfishGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_WakeUpFriendsGoalMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.api.ArclightVersion; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.SilverfishBlock; -import net.minecraft.entity.ai.goal.Goal; -import net.minecraft.entity.monster.SilverfishEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.ai.goal.Goal; +import net.minecraft.world.entity.monster.Silverfish; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.InfestedBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; @@ -18,11 +18,11 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.Random; -@Mixin(targets = "net.minecraft.entity.monster.SilverfishEntity.SummonSilverfishGoal") -public abstract class SilverfishEntity_SummonSilverfishGoalMixin extends Goal { +@Mixin(targets = "net.minecraft.world.entity.monster.Silverfish.SilverfishWakeUpFriendsGoal") +public abstract class Silverfish_WakeUpFriendsGoalMixin extends Goal { @Shadow private int lookForFriends; - @Shadow @Final private SilverfishEntity silverfish; + @Shadow @Final private Silverfish silverfish; /** * @author IzzelAliz @@ -32,18 +32,18 @@ public abstract class SilverfishEntity_SummonSilverfishGoalMixin extends Goal { public void tick() { --this.lookForFriends; if (this.lookForFriends <= 0) { - World world = this.silverfish.world; - Random random = this.silverfish.getRNG(); - BlockPos blockpos = this.silverfish.getPosition(); + Level world = this.silverfish.level; + Random random = this.silverfish.getRandom(); + BlockPos blockpos = this.silverfish.blockPosition(); for (int i = 0; i <= 5 && i >= -5; i = (i <= 0 ? 1 : 0) - i) { for (int j = 0; j <= 10 && j >= -10; j = (j <= 0 ? 1 : 0) - j) { for (int k = 0; k <= 10 && k >= -10; k = (k <= 0 ? 1 : 0) - k) { - BlockPos blockpos1 = blockpos.add(j, i, k); + BlockPos blockpos1 = blockpos.offset(j, i, k); BlockState blockstate = world.getBlockState(blockpos1); Block block = blockstate.getBlock(); - if (block instanceof SilverfishBlock) { - if (CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockpos1, Blocks.AIR.getDefaultState()).isCancelled()) { + if (block instanceof InfestedBlock) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.silverfish, blockpos1, Blocks.AIR.defaultBlockState()).isCancelled()) { continue; } if (ForgeEventFactory.getMobGriefingEvent(world, this.silverfish)) { @@ -53,7 +53,7 @@ public abstract class SilverfishEntity_SummonSilverfishGoalMixin extends Goal { world.destroyBlock(blockpos1, true); } } else { - world.setBlockState(blockpos1, ((SilverfishBlock) block).getMimickedBlock().getDefaultState(), 3); + world.setBlock(blockpos1, ((InfestedBlock) block).getHostBlock().defaultBlockState(), 3); } if (random.nextBoolean()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SlimeEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SlimeMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SlimeEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SlimeMixin.java index 7195dc02..f804d2c9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/SlimeEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SlimeMixin.java @@ -1,11 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.MobEntityMixin; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.monster.SlimeEntity; -import net.minecraft.util.text.ITextComponent; +import io.izzel.arclight.common.mixin.core.world.entity.MobMixin; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.Slime; @@ -19,15 +18,14 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.ArrayList; import java.util.List; -@Mixin(SlimeEntity.class) -public abstract class SlimeEntityMixin extends MobEntityMixin { +@Mixin(net.minecraft.world.entity.monster.Slime.class) +public abstract class SlimeMixin extends MobMixin { // @formatter:off - @Shadow public abstract int getSlimeSize(); - @Shadow public abstract EntityType getType(); + @Shadow public abstract int getSize(); + @Shadow public abstract EntityType getType(); // @formatter:on - /** * @author IzzelAliz * @reason @@ -35,13 +33,13 @@ public abstract class SlimeEntityMixin extends MobEntityMixin { @Overwrite(remap = false) @Override public void remove(boolean keepData) { - int i = this.getSlimeSize(); - if (!this.world.isRemote && i > 1 && this.getShouldBeDead() && !this.removed) { - ITextComponent itextcomponent = this.getCustomName(); - boolean flag = this.isAIDisabled(); + int i = this.getSize(); + if (!this.level.isClientSide && i > 1 && this.isDeadOrDying()) { + Component itextcomponent = this.getCustomName(); + boolean flag = this.isNoAi(); float f = (float) i / 4.0F; int j = i / 2; - int k = 2 + this.rand.nextInt(3); + int k = 2 + this.random.nextInt(3); SlimeSplitEvent event = new SlimeSplitEvent((Slime) this.getBukkitEntity(), k); Bukkit.getPluginManager().callEvent(event); @@ -55,24 +53,24 @@ public abstract class SlimeEntityMixin extends MobEntityMixin { for (int l = 0; l < k; ++l) { float f1 = ((float) (l % 2) - 0.5F) * f; float f2 = ((float) (l / 2) - 0.5F) * f; - SlimeEntity slimeentity = this.getType().create(this.world); - if (this.isNoDespawnRequired()) { - slimeentity.enablePersistence(); + net.minecraft.world.entity.monster.Slime slimeentity = this.getType().create(this.level); + if (this.isPersistenceRequired()) { + slimeentity.setPersistenceRequired(); } slimeentity.setCustomName(itextcomponent); - slimeentity.setNoAI(flag); + slimeentity.setNoAi(flag); slimeentity.setInvulnerable(this.isInvulnerable()); - slimeentity.setSlimeSize(j, true); - slimeentity.setLocationAndAngles(this.getPosX() + (double) f1, this.getPosY() + 0.5D, this.getPosZ() + (double) f2, this.rand.nextFloat() * 360.0F, 0.0F); + slimeentity.setSize(j, true); + slimeentity.moveTo(this.getX() + (double) f1, this.getY() + 0.5D, this.getZ() + (double) f2, this.random.nextFloat() * 360.0F, 0.0F); slimes.add(slimeentity); } - if (CraftEventFactory.callEntityTransformEvent((SlimeEntity) (Object) this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { + if (CraftEventFactory.callEntityTransformEvent((net.minecraft.world.entity.monster.Slime) (Object) this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { return; } for (LivingEntity living : slimes) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); - this.world.addEntity(living); + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); + this.level.addFreshEntity(living); } } super.remove(keepData); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpellcastingIllager_UseSpellGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpellcastingIllager_UseSpellGoalMixin.java new file mode 100644 index 00000000..23dea261 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpellcastingIllager_UseSpellGoalMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import net.minecraft.world.entity.monster.SpellcasterIllager; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(SpellcasterIllager.SpellcasterUseSpellGoal.class) +public abstract class SpellcastingIllager_UseSpellGoalMixin { + + // @formatter:off + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_33774_"}, remap = false) private SpellcasterIllager outerThis; + @Shadow protected abstract SpellcasterIllager.IllagerSpell getSpell(); + // @formatter:on + + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/SpellcasterIllager$SpellcasterUseSpellGoal;performSpellCasting()V")) + private void arclight$castSpell(CallbackInfo ci) { + if (!CraftEventFactory.handleEntitySpellCastEvent(outerThis, this.getSpell())) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpiderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpiderMixin.java new file mode 100644 index 00000000..afad8966 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/SpiderMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnGroupData; +import net.minecraft.world.entity.monster.Spider; +import net.minecraft.world.level.ServerLevelAccessor; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Spider.class) +public abstract class SpiderMixin extends PathfinderMobMixin { + + @Inject(method = "finalizeSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Spider;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$potionReason(ServerLevelAccessor worldIn, DifficultyInstance difficultyIn, MobSpawnType reason, SpawnGroupData spawnDataIn, CompoundTag dataTag, CallbackInfoReturnable cir) { + bridge$pushEffectCause(EntityPotionEffectEvent.Cause.SPIDER_SPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/VexEntity_CopyOwnerTargetGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Vex_CopyOwnerTargetGoalMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/VexEntity_CopyOwnerTargetGoalMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Vex_CopyOwnerTargetGoalMixin.java index aa5cb7f0..e680c40c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/VexEntity_CopyOwnerTargetGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Vex_CopyOwnerTargetGoalMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.entity.monster.VexEntity; +import net.minecraft.world.entity.monster.Vex; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -9,13 +9,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = "net.minecraft.entity.monster.VexEntity.CopyOwnerTargetGoal") -public abstract class VexEntity_CopyOwnerTargetGoalMixin { +@Mixin(targets = "net.minecraft.world.entity.monster.Vex.VexCopyOwnerTargetGoal") +public abstract class Vex_CopyOwnerTargetGoalMixin { - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_190883_a"}, remap = false) - private VexEntity outerThis; + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "f_34052_"}, remap = false) + private Vex outerThis; - @Inject(method = "startExecuting", at = @At("HEAD")) + @Inject(method = "start", at = @At("HEAD")) private void arclight$reason(CallbackInfo ci) { ((MobEntityBridge) outerThis).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, true); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitchMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitchMixin.java new file mode 100644 index 00000000..7c7cd777 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitchMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.mixin.core.world.entity.raider.RaiderMixin; +import net.minecraft.world.entity.monster.Witch; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Witch.class) +public abstract class WitchMixin extends RaiderMixin { + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Witch;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$reason(CallbackInfo ci) { + bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitherSkeletonEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitherSkeletonMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitherSkeletonEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitherSkeletonMixin.java index d21a3749..8361e2cd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/WitherSkeletonEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/WitherSkeletonMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.WitherSkeletonEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.monster.WitherSkeleton; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(WitherSkeletonEntity.class) -public abstract class WitherSkeletonEntityMixin extends AbstractSkeletonEntityMixin { +@Mixin(WitherSkeleton.class) +public abstract class WitherSkeletonMixin extends AbstractSkeletonMixin { - @Inject(method = "attackEntityAsMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$reason(Entity entityIn, CallbackInfoReturnable cir) { ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieMixin.java new file mode 100644 index 00000000..79d306e7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieMixin.java @@ -0,0 +1,83 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import io.izzel.arclight.mixin.Eject; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnGroupData; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraftforge.event.entity.living.ZombieEvent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Zombie; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTransformEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(net.minecraft.world.entity.monster.Zombie.class) +public abstract class ZombieMixin extends PathfinderMobMixin { + + @Inject(method = "convertToZombieType", at = @At("HEAD")) + private void arclight$transformReason(EntityType entityType, CallbackInfo ci) { + this.bridge$pushTransformReason(EntityTransformEvent.TransformReason.DROWNED); + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.DROWNED); + } + + @Inject(method = "convertToZombieType", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN")) + private void arclight$stopConversion(EntityType entityType, CallbackInfo ci, net.minecraft.world.entity.monster.Zombie zombieEntity) { + if (zombieEntity == null) { + ((Zombie) this.bridge$getBukkitEntity()).setConversionTime(-1); + } + } + + @Inject(method = "hurt", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Zombie;finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/MobSpawnType;Lnet/minecraft/world/entity/SpawnGroupData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/entity/SpawnGroupData;")) + private void arclight$spawnWithReason(DamageSource source, float amount, CallbackInfoReturnable cir, ServerLevel world, LivingEntity livingEntity, int i, int j, int k, ZombieEvent.SummonAidEvent event, net.minecraft.world.entity.monster.Zombie zombieEntity) { + ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); + if (livingEntity != null) { + ((MobEntityBridge) zombieEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); + } + } + + @Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) + private void arclight$entityCombust(Entity entity, int seconds) { + EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false); + } + } + + @Eject(method = "onKillEntity", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;func_233656_b_(Lnet/minecraft/entity/EntityType;Z)Lnet/minecraft/entity/MobEntity;")) + private T arclight$transform(Villager villagerEntity, EntityType entityType, boolean flag, CallbackInfo ci) { + ((WorldBridge) villagerEntity.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.INFECTION); + ((MobEntityBridge) villagerEntity).bridge$pushTransformReason(EntityTransformEvent.TransformReason.INFECTION); + T t = villagerEntity.convertTo(entityType, flag); + if (t == null) { + ci.cancel(); + } + return t; + } + + @Inject(method = "finalizeSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ServerLevelAccessor;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$mount(ServerLevelAccessor worldIn, DifficultyInstance difficultyIn, MobSpawnType reason, SpawnGroupData spawnDataIn, CompoundTag dataTag, CallbackInfoReturnable cir) { + ((WorldBridge) worldIn.getLevel()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.MOUNT); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieVillagerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieVillagerMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieVillagerEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieVillagerMixin.java index 916ecc1a..ac30bb23 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombieVillagerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombieVillagerMixin.java @@ -1,11 +1,10 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.monster.ZombieVillagerEntity; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; import org.bukkit.entity.ZombieVillager; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; @@ -17,22 +16,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.UUID; -@Mixin(ZombieVillagerEntity.class) -public abstract class ZombieVillagerEntityMixin extends ZombieEntityMixin { +@Mixin(net.minecraft.world.entity.monster.ZombieVillager.class) +public abstract class ZombieVillagerMixin extends ZombieMixin { - @Inject(method = "startConverting", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;removePotionEffect(Lnet/minecraft/potion/Effect;)Z")) + @Inject(method = "startConverting", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/ZombieVillager;removeEffect(Lnet/minecraft/world/effect/MobEffect;)Z")) private void arclight$convert1(UUID conversionStarterIn, int conversionTimeIn, CallbackInfo ci) { this.persist = true; bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONVERSION); } - @Inject(method = "startConverting", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "startConverting", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/ZombieVillager;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void arclight$convert2(UUID conversionStarterIn, int conversionTimeIn, CallbackInfo ci) { bridge$pushEffectCause(EntityPotionEffectEvent.Cause.CONVERSION); } @Eject(method = "cureZombie", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;func_233656_b_(Lnet/minecraft/entity/EntityType;Z)Lnet/minecraft/entity/MobEntity;")) - private T arclight$cure(ZombieVillagerEntity zombieVillagerEntity, EntityType entityType, boolean flag, CallbackInfo ci) { + private T arclight$cure(net.minecraft.world.entity.monster.ZombieVillager zombieVillagerEntity, EntityType entityType, boolean flag, CallbackInfo ci) { T t = this.a(entityType, flag, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED); if (t == null) { ((ZombieVillager) this.bridge$getBukkitEntity()).setConversionTime(-1); @@ -43,13 +42,13 @@ public abstract class ZombieVillagerEntityMixin extends ZombieEntityMixin { return t; } - @Inject(method = "cureZombie", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;entityDropItem(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$dropPre(ServerWorld world, CallbackInfo ci) { + @Inject(method = "finishConversion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/ZombieVillager;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$dropPre(ServerLevel world, CallbackInfo ci) { this.forceDrops = true; } - @Inject(method = "cureZombie", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/monster/ZombieVillagerEntity;entityDropItem(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/entity/item/ItemEntity;")) - private void arclight$dropPost(ServerWorld world, CallbackInfo ci) { + @Inject(method = "finishConversion", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/monster/ZombieVillager;spawnAtLocation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/entity/item/ItemEntity;")) + private void arclight$dropPost(ServerLevel world, CallbackInfo ci) { this.forceDrops = false; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombifiedPiglinEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombifiedPiglinMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombifiedPiglinEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombifiedPiglinMixin.java index e3779f26..fc0bdebd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/monster/ZombifiedPiglinEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/ZombifiedPiglinMixin.java @@ -1,13 +1,13 @@ -package io.izzel.arclight.common.mixin.core.entity.monster; +package io.izzel.arclight.common.mixin.core.world.entity.monster; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; import io.izzel.arclight.mixin.Eject; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ai.attributes.Attributes; -import net.minecraft.entity.monster.ZombifiedPiglinEntity; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.monster.ZombifiedPiglin; +import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; import org.bukkit.entity.PigZombie; import org.bukkit.event.entity.EntityTargetEvent; @@ -21,13 +21,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.UUID; -@Mixin(ZombifiedPiglinEntity.class) -public abstract class ZombifiedPiglinEntityMixin extends ZombieEntityMixin { +@Mixin(ZombifiedPiglin.class) +public abstract class ZombifiedPiglinMixin extends ZombieMixin { // @formatter:off - @Shadow public abstract UUID getAngerTarget(); - @Shadow public abstract void setAngerTarget(@Nullable UUID target); - @Shadow public abstract void setAngerTime(int time); + @Shadow public abstract UUID getPersistentAngerTarget(); + @Shadow public abstract void setPersistentAngerTarget(@Nullable UUID target); + @Shadow public abstract void setRemainingPersistentAngerTime(int time); // @formatter:on /** @@ -35,15 +35,15 @@ public abstract class ZombifiedPiglinEntityMixin extends ZombieEntityMixin { * @reason */ @Overwrite - private void func_241411_fa_() { + private void alertOthers() { double d0 = this.getAttributeValue(Attributes.FOLLOW_RANGE); - AxisAlignedBB axisalignedbb = AxisAlignedBB.fromVector(this.getPositionVec()).grow(d0, 10.0D, d0); - for (ZombifiedPiglinEntity piglinEntity : this.world.getLoadedEntitiesWithinAABB(ZombifiedPiglinEntity.class, axisalignedbb)) { + AABB axisalignedbb = AABB.unitCubeFromLowerCorner(this.position()).inflate(d0, 10.0D, d0); + for (ZombifiedPiglin piglinEntity : this.level.getEntitiesOfClass(ZombifiedPiglin.class, axisalignedbb)) { if (piglinEntity != (Object) this) { - if (piglinEntity.getAttackTarget() == null) { - if (!piglinEntity.isOnSameTeam(this.getAttackTarget())) { + if (piglinEntity.getTarget() == null) { + if (!piglinEntity.isAlliedTo(this.getTarget())) { ((MobEntityBridge) piglinEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY, true); - piglinEntity.setAttackTarget(this.getAttackTarget()); + piglinEntity.setTarget(this.getTarget()); } } } @@ -51,14 +51,14 @@ public abstract class ZombifiedPiglinEntityMixin extends ZombieEntityMixin { } @Eject(method = "func_230258_H__", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/monster/ZombifiedPiglinEntity;setAngerTime(I)V")) - private void arclight$pigAngry(ZombifiedPiglinEntity piglinEntity, int time, CallbackInfo ci) { - Entity entity = ((ServerWorld) this.world).getEntityByUuid(this.getAngerTarget()); + private void arclight$pigAngry(ZombifiedPiglin piglinEntity, int time, CallbackInfo ci) { + Entity entity = ((ServerLevel) this.level).getEntity(this.getPersistentAngerTarget()); PigZombieAngerEvent event = new PigZombieAngerEvent((PigZombie) this.getBukkitEntity(), entity == null ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), time); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - this.setAngerTarget(null); + this.setPersistentAngerTarget(null); ci.cancel(); } - this.setAngerTime(event.getNewAnger()); + this.setRemainingPersistentAngerTime(event.getNewAnger()); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java new file mode 100644 index 00000000..670f96fa --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java @@ -0,0 +1,118 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster.piglin; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import io.izzel.arclight.common.bridge.entity.monster.piglin.PiglinBridge; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.memory.MemoryModuleType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.monster.piglin.Piglin; +import net.minecraft.world.entity.monster.piglin.PiglinAi; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.entity.PiglinBarterEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.List; + +@Mixin(PiglinAi.class) +public abstract class PiglinAiMixin { + + // @formatter:off + @Shadow private static void stopWalking(Piglin p_234531_0_) { } + @Shadow private static ItemStack removeOneItemFromItemEntity(ItemEntity p_234465_0_) { return null; } + @Shadow private static void holdInOffhand(Piglin p_241427_0_, ItemStack p_241427_1_) { } + @Shadow private static void admireGoldItem(LivingEntity p_234501_0_) { } + @Shadow private static boolean hasEatenRecently(Piglin p_234538_0_) { return false; } + @Shadow private static void eat(Piglin p_234536_0_) { } + @Shadow private static void putInInventory(Piglin p_234498_0_, ItemStack p_234498_1_) { } + @Shadow protected static boolean isLovedItem(ItemStack p_149966_) { return false; } + @Shadow private static boolean isFood(ItemStack p_149970_) { return false; } + @Shadow private static boolean isBarterCurrency(ItemStack p_149968_) { return false; } + @Shadow private static List getBarterResponseItems(Piglin p_34997_) { return null; } + @Shadow private static void throwItems(Piglin p_34861_, List p_34862_) { } + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected static void pickUpItem(Piglin piglinEntity, ItemEntity itemEntity) { + ItemStack itemstack; + stopWalking(piglinEntity); + if (itemEntity.getItem().getItem() == Items.GOLD_NUGGET && !CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, 0, false).isCancelled()) { + piglinEntity.take(itemEntity, itemEntity.getItem().getCount()); + itemstack = itemEntity.getItem(); + itemEntity.discard(); + } else if (!CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, itemEntity.getItem().getCount() - 1, false).isCancelled()) { + piglinEntity.take(itemEntity, 1); + itemstack = removeOneItemFromItemEntity(itemEntity); + } else { + return; + } + + if (isLovedByPiglin(itemstack, piglinEntity)) { + piglinEntity.getBrain().eraseMemory(MemoryModuleType.TIME_TRYING_TO_REACH_ADMIRE_ITEM); + holdInOffhand(piglinEntity, itemstack); + admireGoldItem(piglinEntity); + } else if (isFood(itemstack) && !hasEatenRecently(piglinEntity)) { + eat(piglinEntity); + } else { + ((MobEntityBridge) piglinEntity).bridge$captureItemDrop(itemEntity); + boolean flag = piglinEntity.equipItemIfPossible(itemstack); + if (!flag) { + putInInventory(piglinEntity, itemstack); + } + } + } + + protected static boolean isLovedByPiglin(ItemStack itemstack, Piglin piglin) { + return isLovedItem(itemstack) || (((PiglinBridge) piglin).bridge$getInterestItems().contains(itemstack.getItem()) + || ((PiglinBridge) piglin).bridge$getAllowedBarterItems().contains(itemstack.getItem())); + } + + private static boolean isBarterItem(ItemStack itemstack, Piglin piglin) { + return isBarterCurrency(itemstack) || ((PiglinBridge) piglin).bridge$getAllowedBarterItems().contains(itemstack.getItem()); + } + + @Redirect(method = "stopHoldingOffHandItem", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/ItemStack;isPiglinCurrency()Z")) + private static boolean arclight$customBarter(ItemStack stack, Piglin piglin) { + return isBarterItem(stack, piglin); + } + + @Redirect(method = "stopHoldingOffHandItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/piglin/PiglinAi;throwItems(Lnet/minecraft/world/entity/monster/piglin/Piglin;Ljava/util/List;)V")) + private static void arclight$barterEvent(Piglin piglin, List items) { + ItemStack stack = piglin.getItemInHand(InteractionHand.OFF_HAND); + PiglinBarterEvent event = CraftEventFactory.callPiglinBarterEvent(piglin, getBarterResponseItems(piglin), stack); + if (!event.isCancelled()) { + throwItems(piglin, event.getOutcome().stream().map(CraftItemStack::asNMSCopy).toList()); + } + } + + @Redirect(method = "stopHoldingOffHandItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/piglin/PiglinAi;isLovedItem(Lnet/minecraft/world/item/ItemStack;)Z")) + private static boolean arclight$customLove(ItemStack stack, Piglin piglin) { + return isLovedByPiglin(stack, piglin); + } + + @Redirect(method = "wantsToPickup", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/ItemStack;isPiglinCurrency()Z")) + private static boolean arclight$customBanter2(ItemStack stack, Piglin piglin) { + return isBarterItem(stack, piglin); + } + + @Redirect(method = "canAdmire", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/ItemStack;isPiglinCurrency()Z")) + private static boolean arclight$customBanter3(ItemStack stack, Piglin piglin) { + return isBarterItem(stack, piglin); + } + + @Redirect(method = "isNotHoldingLovedItemInOffHand", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/entity/monster/piglin/PiglinAi;isLovedItem(Lnet/minecraft/world/item/ItemStack;)Z")) + private static boolean arclight$customLove2(ItemStack stack, Piglin piglin) { + return isLovedByPiglin(stack, piglin); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinMixin.java new file mode 100644 index 00000000..b311be5b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinMixin.java @@ -0,0 +1,66 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster.piglin; + +import io.izzel.arclight.common.bridge.entity.monster.piglin.PiglinBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.core.Registry; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.monster.piglin.Piglin; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +@Mixin(Piglin.class) +public abstract class PiglinMixin extends PathfinderMobMixin implements PiglinBridge { + + public Set allowedBarterItems = new HashSet<>(); + public Set interestItems = new HashSet<>(); + + @Override + public Set bridge$getAllowedBarterItems() { + return allowedBarterItems; + } + + @Override + public Set bridge$getInterestItems() { + return interestItems; + } + + @Inject(method = "addAdditionalSaveData", at = @At("RETURN")) + private void arclight$writeAdditional(CompoundTag compound, CallbackInfo ci) { + ListTag barterList = new ListTag(); + allowedBarterItems.stream().map(Registry.ITEM::getKey).map(ResourceLocation::toString).map(StringTag::valueOf).forEach(barterList::add); + compound.put("Bukkit.BarterList", barterList); + ListTag interestList = new ListTag(); + interestItems.stream().map(Registry.ITEM::getKey).map(ResourceLocation::toString).map(StringTag::valueOf).forEach(interestList::add); + compound.put("Bukkit.InterestList", interestList); + } + + @Inject(method = "readAdditionalSaveData", at = @At("RETURN")) + private void arclight$readAdditional(CompoundTag compound, CallbackInfo ci) { + this.allowedBarterItems = compound.getList("Bukkit.BarterList", 8).stream().map(Tag::getAsString).map(ResourceLocation::tryParse).map(Registry.ITEM::get).collect(Collectors.toCollection(HashSet::new)); + this.interestItems = compound.getList("Bukkit.InterestList", 8).stream().map(Tag::getAsString).map(ResourceLocation::tryParse).map(Registry.ITEM::get).collect(Collectors.toCollection(HashSet::new)); + } + + @Redirect(method = "holdInOffHand", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/ItemStack;isPiglinCurrency()Z")) + private boolean arclight$customBarter(ItemStack itemStack) { + return itemStack.isPiglinCurrency() || allowedBarterItems.contains(itemStack.getItem()); + } + + @Redirect(method = "canReplaceCurrentItem(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Z", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/piglin/PiglinAi;isLovedItem(Lnet/minecraft/world/item/ItemStack;)Z")) + private boolean arclight$customLoved(ItemStack stack) { + return PiglinAiMixin.isLovedItem(stack) || interestItems.contains(stack.getItem()) || allowedBarterItems.contains(stack.getItem()); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/AbstractVillagerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/AbstractVillagerMixin.java similarity index 59% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/AbstractVillagerEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/AbstractVillagerMixin.java index 1295aafd..e25c7349 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/AbstractVillagerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/AbstractVillagerMixin.java @@ -1,15 +1,14 @@ -package io.izzel.arclight.common.mixin.core.entity.merchant.villager; +package io.izzel.arclight.common.mixin.core.world.entity.npc; import io.izzel.arclight.common.bridge.entity.merchant.IMerchantBridge; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.bridge.item.MerchantOfferBridge; -import io.izzel.arclight.common.mixin.core.entity.CreatureEntityMixin; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.merchant.villager.AbstractVillagerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.MerchantOffer; -import net.minecraft.item.MerchantOffers; -import net.minecraft.world.World; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; +import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftMerchant; import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe; @@ -24,24 +23,24 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(AbstractVillagerEntity.class) -public abstract class AbstractVillagerEntityMixin extends CreatureEntityMixin implements IMerchantBridge { +@Mixin(net.minecraft.world.entity.npc.AbstractVillager.class) +public abstract class AbstractVillagerMixin extends PathfinderMobMixin implements IMerchantBridge { - @Shadow @Final private Inventory villagerInventory; + @Shadow @Final private SimpleContainer inventory; @Inject(method = "", at = @At("RETURN")) - private void arclight$init(EntityType type, World worldIn, CallbackInfo ci) { - ((IInventoryBridge) this.villagerInventory).setOwner((InventoryHolder) this.getBukkitEntity()); + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { + ((IInventoryBridge) this.inventory).setOwner((InventoryHolder) this.getBukkitEntity()); } private CraftMerchant craftMerchant; @Override public CraftMerchant bridge$getCraftMerchant() { - return (craftMerchant == null) ? craftMerchant = new CraftMerchant((AbstractVillagerEntity) (Object) this) : craftMerchant; + return (craftMerchant == null) ? craftMerchant = new CraftMerchant((net.minecraft.world.entity.npc.AbstractVillager) (Object) this) : craftMerchant; } - @Redirect(method = "addTrades", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/item/MerchantOffers;add(Ljava/lang/Object;)Z")) + @Redirect(method = "addOffersFromItemListings", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/trading/MerchantOffers;add(Ljava/lang/Object;)Z")) private boolean arclight$gainOffer(MerchantOffers merchantOffers, Object e) { MerchantOffer offer = (MerchantOffer) e; VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), ((MerchantOfferBridge) offer).bridge$asBukkit()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/VillagerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/VillagerEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java index a5195edf..a23b170d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/VillagerEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java @@ -1,12 +1,11 @@ -package io.izzel.arclight.common.mixin.core.entity.merchant.villager; +package io.izzel.arclight.common.mixin.core.world.entity.npc; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.merchant.villager.VillagerEntity; -import net.minecraft.entity.monster.WitchEntity; -import net.minecraft.entity.passive.IronGolemEntity; -import net.minecraft.item.MerchantOffer; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.animal.IronGolem; +import net.minecraft.world.entity.monster.Witch; +import net.minecraft.world.item.trading.MerchantOffer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.Villager; @@ -23,34 +22,34 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import io.izzel.arclight.common.bridge.item.MerchantOfferBridge; -@Mixin(VillagerEntity.class) -public abstract class VillagerEntityMixin extends AbstractVillagerEntityMixin { +@Mixin(net.minecraft.world.entity.npc.Villager.class) +public abstract class VillagerMixin extends AbstractVillagerMixin { - @Inject(method = "updateAITasks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/merchant/villager/VillagerEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "customServerAiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/npc/Villager;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void arclight$reason(CallbackInfo ci) { bridge$pushEffectCause(EntityPotionEffectEvent.Cause.VILLAGER_TRADE); } - @Redirect(method = "recalculateSpecialPricesFor", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/item/MerchantOffer;increaseSpecialPrice(I)V")) + @Redirect(method = "updateSpecialPrices", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/item/trading/MerchantOffer;addToSpecialPriceDiff(I)V")) private void arclight$replenish(MerchantOffer merchantOffer, int add) { VillagerReplenishTradeEvent event = new VillagerReplenishTradeEvent((Villager) this.getBukkitEntity(), ((MerchantOfferBridge) merchantOffer).bridge$asBukkit(), add); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { - merchantOffer.increaseSpecialPrice(event.getBonus()); + merchantOffer.addToSpecialPriceDiff(event.getBonus()); } } - @Inject(method = "causeLightningStrike", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$transformWitch(ServerWorld serverWorld, LightningBoltEntity lightningBolt, CallbackInfo ci, WitchEntity witchEntity) { - if (CraftEventFactory.callEntityTransformEvent((VillagerEntity) (Object) this, witchEntity, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) { + @Inject(method = "thunderHit", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;func_242417_l(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$transformWitch(ServerLevel serverWorld, LightningBolt lightningBolt, CallbackInfo ci, Witch witchEntity) { + if (CraftEventFactory.callEntityTransformEvent((net.minecraft.world.entity.npc.Villager) (Object) this, witchEntity, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) { ci.cancel(); } else { ((WorldBridge) serverWorld).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); } } - @Inject(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$ironGolemReason(ServerWorld world, CallbackInfoReturnable cir) { + @Inject(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;func_242417_l(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$ironGolemReason(ServerLevel world, CallbackInfoReturnable cir) { ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/WanderingTraderEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java similarity index 65% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/WanderingTraderEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java index f04f2b5d..6144036e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/villager/WanderingTraderEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.entity.merchant.villager; +package io.izzel.arclight.common.mixin.core.world.entity.npc; import io.izzel.arclight.common.bridge.item.MerchantOfferBridge; -import net.minecraft.entity.merchant.villager.WanderingTraderEntity; -import net.minecraft.item.MerchantOffer; -import net.minecraft.item.MerchantOffers; +import net.minecraft.world.entity.npc.WanderingTrader; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.item.trading.MerchantOffers; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe; import org.bukkit.entity.AbstractVillager; @@ -12,10 +12,10 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(WanderingTraderEntity.class) -public abstract class WanderingTraderEntityMixin extends AbstractVillagerEntityMixin { +@Mixin(WanderingTrader.class) +public abstract class WanderingTraderMixin extends AbstractVillagerMixin { - @Redirect(method = "populateTradeData", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/item/MerchantOffers;add(Ljava/lang/Object;)Z")) + @Redirect(method = "updateTrades", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/item/trading/MerchantOffers;add(Ljava/lang/Object;)Z")) private boolean arclight$gainOffer(MerchantOffers merchantOffers, Object e) { MerchantOffer offer = (MerchantOffer) e; VillagerAcquireTradeEvent event = new VillagerAcquireTradeEvent((AbstractVillager) getBukkitEntity(), ((MerchantOfferBridge) offer).bridge$asBukkit()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/InventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/InventoryMixin.java new file mode 100644 index 00000000..d842976d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/InventoryMixin.java @@ -0,0 +1,120 @@ +package io.izzel.arclight.common.mixin.core.world.entity.player; + +import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; +import io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge; +import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.InventoryHolder; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.ArrayList; +import java.util.List; + +@Mixin(Inventory.class) +public abstract class InventoryMixin implements Container, IInventoryBridge, PlayerInventoryBridge { + + // @formatter:off + @Shadow @Final public NonNullList items; + @Shadow @Final public NonNullList offhand; + @Shadow @Final public NonNullList armor; + @Shadow @Final private List> compartments; + @Shadow @Final public Player player; + @Shadow protected abstract boolean hasRemainingSpaceForItem(ItemStack stack1, ItemStack stack2); + // @formatter:on + + private List transactions = new ArrayList<>(); + private int maxStack = MAX_STACK; + + public int canHold(ItemStack stack) { + int remains = stack.getCount(); + for (int i = 0; i < this.items.size(); ++i) { + ItemStack slot = this.getItem(i); + if (slot.isEmpty()) return stack.getCount(); + + if (this.hasRemainingSpaceForItem(slot, stack)) { + remains -= (slot.getMaxStackSize() < this.getMaxStackSize() ? slot.getMaxStackSize() : this.getMaxStackSize()) - slot.getCount(); + } + if (remains <= 0) return stack.getCount(); + } + ItemStack offhandItemStack = this.getItem(this.items.size() + this.armor.size()); + if (this.hasRemainingSpaceForItem(offhandItemStack, stack)) { + remains -= (offhandItemStack.getMaxStackSize() < this.getMaxStackSize() ? offhandItemStack.getMaxStackSize() : this.getMaxStackSize()) - offhandItemStack.getCount(); + } + if (remains <= 0) return stack.getCount(); + + return stack.getCount() - remains; + } + + @Override + public int bridge$canHold(ItemStack stack) { + return canHold(stack); + } + + public List getArmorContents() { + return this.armor; + } + + @Override + public List getContents() { + List combined = new ArrayList<>(items.size() + offhand.size() + armor.size()); + for (List sub : this.compartments) { + combined.addAll(sub); + } + return combined; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transactions.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transactions.remove(who); + } + + @Override + public List getViewers() { + return transactions; + } + + @Override + public InventoryHolder getOwner() { + return ((PlayerEntityBridge) this.player).bridge$getBukkitEntity(); + } + + @Override + public void setOwner(InventoryHolder owner) { } + + @Override + public int getMaxStackSize() { + if (maxStack == 0) maxStack = MAX_STACK; + return maxStack; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public Location getLocation() { + return ((PlayerEntityBridge) this.player).bridge$getBukkitEntity().getLocation(); + } + + @Override + public Recipe getCurrentRecipe() { return null; } + + @Override + public void setCurrentRecipe(Recipe recipe) { } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java new file mode 100644 index 00000000..8ad16221 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java @@ -0,0 +1,583 @@ +package io.izzel.arclight.common.mixin.core.world.entity.player; + +import com.mojang.authlib.GameProfile; +import com.mojang.datafixers.util.Either; +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.InternalEntityBridge; +import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; +import io.izzel.arclight.common.bridge.util.DamageSourceBridge; +import io.izzel.arclight.common.bridge.util.FoodStatsBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.LivingEntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.stats.Stat; +import net.minecraft.stats.Stats; +import net.minecraft.util.Mth; +import net.minecraft.util.Unit; +import net.minecraft.world.Difficulty; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.HumanoidArm; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobType; +import net.minecraft.world.entity.TamableAnimal; +import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.boss.EnderDragonPart; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Abilities; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.food.FoodData; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.PlayerEnderChestContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.SwordItem; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.scores.Scoreboard; +import net.minecraftforge.common.ForgeHooks; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.util.CraftVector; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityExhaustionEvent; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.player.PlayerBedLeaveEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +import org.bukkit.scoreboard.Team; +import org.bukkit.util.Vector; +import org.spigotmc.SpigotWorldConfig; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.List; + +@Mixin(net.minecraft.world.entity.player.Player.class) +public abstract class PlayerMixin extends LivingEntityMixin implements PlayerEntityBridge { + + // @formatter:off + @Shadow public abstract String getScoreboardName(); + @Shadow @Final private Abilities abilities; + @Shadow public abstract float getAttackStrengthScale(float adjustTicks); + @Shadow public abstract void resetAttackStrengthTicker(); + @Shadow public abstract SoundSource getSoundSource(); + @Shadow public abstract float getSpeed(); + @Shadow public abstract void sweepAttack(); + @Shadow public abstract void crit(Entity entityHit); + @Shadow public abstract void magicCrit(Entity entityHit); + @Shadow public abstract void awardStat(ResourceLocation p_195067_1_, int p_195067_2_); + @Shadow public abstract void causeFoodExhaustion(float exhaustion); + @Shadow private long timeEntitySatOnShoulder; + @Shadow public abstract void setShoulderEntityRight(CompoundTag tag); + @Shadow public abstract void setShoulderEntityLeft(CompoundTag tag); + @Shadow public abstract CompoundTag getShoulderEntityRight(); + @Shadow public abstract CompoundTag getShoulderEntityLeft(); + @Shadow public int experienceLevel; + @Shadow @Final private Inventory inventory; + @Shadow public AbstractContainerMenu containerMenu; + @Shadow @Final public InventoryMenu inventoryMenu; + @Shadow public abstract void awardStat(Stat stat); + @Shadow public abstract void awardStat(ResourceLocation stat); + @Shadow public abstract Component getDisplayName(); + @Shadow public abstract HumanoidArm getMainArm(); + @Shadow public float experienceProgress; + @Shadow public int totalExperience; + @Shadow protected FoodData foodData; + @Shadow protected boolean isImmobile() { return false; } + @Shadow public abstract Scoreboard getScoreboard(); + @Shadow protected PlayerEnderChestContainer enderChestInventory; + @Shadow public abstract Either startSleepInBed(BlockPos at); + @Shadow public int sleepCounter; + @Shadow public abstract GameProfile getGameProfile(); + // @formatter:on + + public boolean fauxSleeping; + public int oldLevel; + + @Inject(method = "", at = @At("RETURN")) + private void arclight$init(Level p_i241920_1_, BlockPos p_i241920_2_, float p_i241920_3_, GameProfile p_i241920_4_, CallbackInfo ci) { + oldLevel = -1; + ((FoodStatsBridge) this.foodData).bridge$setEntityHuman((net.minecraft.world.entity.player.Player) (Object) this); + ((IInventoryBridge) this.enderChestInventory).setOwner(this.getBukkitEntity()); + } + + @Override + public boolean bridge$isFauxSleeping() { + return fauxSleeping; + } + + @Inject(method = "turtleHelmetTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$turtleHelmet(CallbackInfo ci) { + bridge$pushEffectCause(EntityPotionEffectEvent.Cause.TURTLE_HELMET); + } + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;heal(F)V")) + private void arclight$healByRegen(CallbackInfo ci) { + bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.REGEN); + } + + @Inject(method = "drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;", + cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "RETURN", ordinal = 1)) + private void arclight$playerDropItem(ItemStack droppedItem, boolean dropAround, boolean traceItem, CallbackInfoReturnable cir, double d0, ItemEntity itemEntity) { + Player player = (Player) this.getBukkitEntity(); + Item drop = (Item) ((EntityBridge) itemEntity).bridge$getBukkitEntity(); + + PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); + if (traceItem && (cur == null || cur.getAmount() == 0)) { + // The complete stack was dropped + player.getInventory().setItemInHand(drop.getItemStack()); + } else if (traceItem && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { + // Only one item is dropped + cur.setAmount(cur.getAmount() + 1); + player.getInventory().setItemInHand(cur); + } else { + // Fallback + player.getInventory().addItem(drop.getItemStack()); + } + cir.setReturnValue(null); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean hurt(DamageSource source, float amount) { + if (!ForgeHooks.onPlayerAttack((net.minecraft.world.entity.player.Player) (Object) this, source, amount)) + return false; + if (this.isInvulnerableTo(source)) { + return false; + } else if (this.abilities.invulnerable && !source.isBypassInvul()) { + this.forceExplosionKnockback = true; + return false; + } else { + this.noActionTime = 0; + if (this.getHealth() <= 0.0F) { + return false; + } else { + if (source.scalesWithDifficulty()) { + if (this.level.getDifficulty() == Difficulty.PEACEFUL) { + // amount = 0.0F; + return false; + } + + if (this.level.getDifficulty() == Difficulty.EASY) { + amount = Math.min(amount / 2.0F + 1.0F, amount); + } + + if (this.level.getDifficulty() == Difficulty.HARD) { + amount = amount * 3.0F / 2.0F; + } + } + + boolean damaged = super.hurt(source, amount); + if (damaged) { + this.removeEntitiesOnShoulder(); + } + return damaged; + //return amount == 0.0F ? false : super.attackEntityFrom(source, amount); + } + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean canHarmPlayer(final net.minecraft.world.entity.player.Player entityhuman) { + Team team; + if (entityhuman instanceof ServerPlayer) { + final ServerPlayer thatPlayer = (ServerPlayer) entityhuman; + team = ((ServerPlayerEntityBridge) thatPlayer).bridge$getBukkitEntity().getScoreboard().getPlayerTeam(((ServerPlayerEntityBridge) thatPlayer).bridge$getBukkitEntity()); + if (team == null || team.allowFriendlyFire()) { + return true; + } + } else { + final OfflinePlayer thisPlayer = Bukkit.getOfflinePlayer(entityhuman.getScoreboardName()); + team = Bukkit.getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer); + if (team == null || team.allowFriendlyFire()) { + return true; + } + } + if ((Object) this instanceof ServerPlayer) { + return !team.hasPlayer(((ServerPlayerEntityBridge) this).bridge$getBukkitEntity()); + } + return !team.hasPlayer(Bukkit.getOfflinePlayer(this.getScoreboardName())); + } + + @Inject(method = "actuallyHurt", cancellable = true, at = @At("HEAD")) + private void arclight$damageEntityCustom(DamageSource damageSrc, float damageAmount, CallbackInfo ci) { + damageEntity0(damageSrc, damageAmount); + ci.cancel(); + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void attack(final Entity entity) { + if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((net.minecraft.world.entity.player.Player) (Object) this, entity)) + return; + if (entity.isAttackable() && !entity.skipAttackInteraction((net.minecraft.world.entity.player.Player) (Object) this)) { + float f = (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE); + float f2; + if (entity instanceof LivingEntity) { + f2 = EnchantmentHelper.getDamageBonus(this.getMainHandItem(), ((LivingEntity) entity).getMobType()); + } else { + f2 = EnchantmentHelper.getDamageBonus(this.getMainHandItem(), MobType.UNDEFINED); + } + final float f3 = this.getAttackStrengthScale(0.5f); + f *= 0.2f + f3 * f3 * 0.8f; + f2 *= f3; + // this.resetAttackStrengthTicker(); + if (f > 0.0f || f2 > 0.0f) { + final boolean flag = f3 > 0.9f; + boolean flag2 = false; + float i = (float) this.getAttributeValue(Attributes.ATTACK_KNOCKBACK); // Forge: Initialize this value to the attack knockback attribute of the player, which is by default 0 + i += EnchantmentHelper.getKnockbackBonus((net.minecraft.world.entity.player.Player) (Object) this); + if (this.isSprinting() && flag) { + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0f, 1.0f); + ++i; + flag2 = true; + } + boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity; + flag3 = flag3 && !this.isSprinting(); + net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((net.minecraft.world.entity.player.Player) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F); + flag3 = hitResult != null; + if (flag3) { + f *= hitResult.getDamageModifier(); + } + f += f2; + boolean flag4 = false; + final double d0 = this.walkDist - this.walkDistO; + if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getSpeed()) { + final ItemStack itemstack = this.getItemInHand(InteractionHand.MAIN_HAND); + if (itemstack.getItem() instanceof SwordItem) { + flag4 = true; + } + } + float f4 = 0.0f; + boolean flag5 = false; + final int j = EnchantmentHelper.getFireAspect((net.minecraft.world.entity.player.Player) (Object) this); + if (entity instanceof LivingEntity) { + f4 = ((LivingEntity) entity).getHealth(); + if (j > 0 && !entity.isOnFire()) { + final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1); + Bukkit.getPluginManager().callEvent(combustEvent); + if (!combustEvent.isCancelled()) { + flag5 = true; + ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false); + } + } + } + final Vec3 vec3d = entity.getDeltaMovement(); + final boolean flag6 = entity.hurt(DamageSource.playerAttack((net.minecraft.world.entity.player.Player) (Object) this), f); + if (flag6) { + if (i > 0) { + if (entity instanceof LivingEntity) { + ((LivingEntity) entity).knockback(i * 0.5f, Mth.sin(this.yRot * 0.017453292f), -Mth.cos(this.yRot * 0.017453292f)); + } else { + entity.push(-Mth.sin(this.yRot * 0.017453292f) * i * 0.5f, 0.1, Mth.cos(this.yRot * 0.017453292f) * i * 0.5f); + } + this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 1.0, 0.6)); + this.setSprinting(false); + } + if (flag4) { + final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((net.minecraft.world.entity.player.Player) (Object) this) * f; + final List list = this.level.getEntitiesOfClass(LivingEntity.class, entity.getBoundingBox().inflate(1.0, 0.25, 1.0)); + for (final LivingEntity entityliving : list) { + if (entityliving != (Object) this && entityliving != entity && !this.isAlliedTo(entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr(entityliving) < 9.0 && entityliving.hurt(((DamageSourceBridge) DamageSource.playerAttack((net.minecraft.world.entity.player.Player) (Object) this)).bridge$sweep(), f5)) { + entityliving.knockback(0.4f, Mth.sin(this.yRot * 0.017453292f), -Mth.cos(this.yRot * 0.017453292f)); + } + } + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0f, 1.0f); + this.sweepAttack(); + } + if (entity instanceof ServerPlayer && entity.hurtMarked) { + boolean cancelled = false; + final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(); + final Vector velocity = CraftVector.toBukkit(vec3d); + final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + cancelled = true; + } else if (!velocity.equals(event.getVelocity())) { + player.setVelocity(event.getVelocity()); + } + if (!cancelled) { + ((ServerPlayer) entity).connection.send(new ClientboundSetEntityMotionPacket(entity)); + entity.hurtMarked = false; + entity.setDeltaMovement(vec3d); + } + } + if (flag3) { + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0f, 1.0f); + this.crit(entity); + } + if (!flag3 && !flag4) { + if (flag) { + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0f, 1.0f); + } else { + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0f, 1.0f); + } + } + if (f2 > 0.0f) { + this.magicCrit(entity); + } + this.setLastHurtMob(entity); + if (entity instanceof LivingEntity) { + EnchantmentHelper.doPostHurtEffects((LivingEntity) entity, (net.minecraft.world.entity.player.Player) (Object) this); + } + EnchantmentHelper.doPostDamageEffects((net.minecraft.world.entity.player.Player) (Object) this, entity); + final ItemStack itemstack2 = this.getMainHandItem(); + Object object = entity; + if (entity instanceof EnderDragonPart) { + object = ((EnderDragonPart) entity).parentMob; + } + if (!this.level.isClientSide && !itemstack2.isEmpty() && object instanceof LivingEntity) { + ItemStack copy = itemstack2.copy(); + itemstack2.hurtEnemy((LivingEntity) object, (net.minecraft.world.entity.player.Player) (Object) this); + if (itemstack2.isEmpty()) { + net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((net.minecraft.world.entity.player.Player) (Object) this, copy, InteractionHand.MAIN_HAND); + this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); + } + } + if (entity instanceof LivingEntity) { + final float f6 = f4 - ((LivingEntity) entity).getHealth(); + this.awardStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f)); + if (j > 0) { + final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4); + Bukkit.getPluginManager().callEvent(combustEvent2); + if (!combustEvent2.isCancelled()) { + ((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false); + } + } + if (this.level instanceof ServerLevel && f6 > 2.0f) { + final int k = (int) (f6 * 0.5); + ((ServerLevel) this.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, entity.getX(), entity.getY() + entity.getBbHeight() * 0.5f, entity.getZ(), k, 0.1, 0.0, 0.1, 0.2); + } + } + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.ATTACK); + this.causeFoodExhaustion(((WorldBridge) level).bridge$spigotConfig().combatExhaustion); + } else { + this.level.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0f, 1.0f); + if (flag5) { + entity.clearFire(); + } + if (this instanceof ServerPlayerEntityBridge) { + ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory(); + } + } + } + } + } + + protected transient boolean arclight$forceSleep; + + public Either sleep(BlockPos at, boolean force) { + this.arclight$forceSleep = force; + return this.startSleepInBed(at); + } + + @Override + public Either bridge$trySleep(BlockPos at, boolean force) { + return sleep(at, force); + } + + @Inject(method = "stopSleepInBed", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Player;sleepCounter:I")) + private void arclight$wakeup(boolean flag, boolean flag1, CallbackInfo ci) { + BlockPos blockPos = this.getSleepingPos().orElse(null); + if (this.bridge$getBukkitEntity() instanceof Player) { + Player player = (Player) this.bridge$getBukkitEntity(); + Block bed; + if (blockPos != null) { + bed = CraftBlock.at(this.level, blockPos); + } else { + bed = ((WorldBridge) this.level).bridge$getWorld().getBlockAt(player.getLocation()); + } + PlayerBedLeaveEvent event = new PlayerBedLeaveEvent(player, bed, true); + Bukkit.getPluginManager().callEvent(event); + } + } + + @Redirect(method = "jumpFromGround", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhaustInfo(net.minecraft.world.entity.player.Player player, float f) { + SpigotWorldConfig config = ((WorldBridge) level).bridge$spigotConfig(); + if (config != null) { + if (this.isSprinting()) { + f = config.jumpSprintExhaustion; + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); + } else { + f = config.jumpWalkExhaustion; + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.JUMP); + } + } + this.causeFoodExhaustion(f); + } + + @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;setSharedFlag(IZ)V")) + private void arclight$toggleGlide(net.minecraft.world.entity.player.Player playerEntity, int flag, boolean set) { + if (playerEntity.getSharedFlag(flag) != set && !CraftEventFactory.callToggleGlideEvent((net.minecraft.world.entity.player.Player) (Object) this, set).isCancelled()) { + playerEntity.setSharedFlag(flag, set); + } + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause1(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.SWIM); + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause2(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 2, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause3(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 3, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause4(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.SPRINT); + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 4, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause5(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.CROUCH); + } + + @Inject(method = "checkMovementStatistics", at = @At(value = "INVOKE", ordinal = 5, target = "Lnet/minecraft/world/entity/player/Player;causeFoodExhaustion(F)V")) + private void arclight$exhauseCause6(double p_36379_, double p_36380_, double p_36381_, CallbackInfo ci) { + bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason.WALK); + } + + @Inject(method = "startFallFlying", cancellable = true, at = @At("HEAD")) + private void arclight$startGlidingEvent(CallbackInfo ci) { + if (CraftEventFactory.callToggleGlideEvent((net.minecraft.world.entity.player.Player) (Object) this, true).isCancelled()) { + this.setSharedFlag(7, true); + this.setSharedFlag(7, false); + ci.cancel(); + } + } + + @Inject(method = "stopFallFlying", cancellable = true, at = @At("HEAD")) + private void arclight$stopGlidingEvent(CallbackInfo ci) { + if (CraftEventFactory.callToggleGlideEvent((net.minecraft.world.entity.player.Player) (Object) this, false).isCancelled()) { + ci.cancel(); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void removeEntitiesOnShoulder() { + if (this.timeEntitySatOnShoulder + 20L < this.level.getGameTime()) { + if (this.spawnEntityFromShoulder(this.getShoulderEntityLeft())) { + this.setShoulderEntityLeft(new CompoundTag()); + } + if (this.spawnEntityFromShoulder(this.getShoulderEntityRight())) { + this.setShoulderEntityRight(new CompoundTag()); + } + } + } + + private boolean spawnEntityFromShoulder(final CompoundTag nbttagcompound) { + return this.level.isClientSide || nbttagcompound.isEmpty() || EntityType.create(nbttagcompound, this.level).map(entity -> { + if (entity instanceof TamableAnimal) { + ((TamableAnimal) entity).setOwnerUUID(this.uuid); + } + entity.setPos(this.getX(), this.getY() + 0.699999988079071, this.getZ()); + return ((ServerWorldBridge) this.level).bridge$addEntitySerialized(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); + }).orElse(true); + } + + public CraftHumanEntity getBukkitEntity() { + return (CraftHumanEntity) ((InternalEntityBridge) this).internal$getBukkitEntity(); + } + + @Override + public CraftHumanEntity bridge$getBukkitEntity() { + return (CraftHumanEntity) ((InternalEntityBridge) this).internal$getBukkitEntity(); + } + + @Override + public void setSlot(EquipmentSlot slotIn, ItemStack stack, boolean silent) { + if (slotIn == EquipmentSlot.MAINHAND) { + this.bridge$playEquipSound(stack, silent); + this.inventory.items.set(this.inventory.selected, stack); + } else if (slotIn == EquipmentSlot.OFFHAND) { + this.bridge$playEquipSound(stack, silent); + this.inventory.offhand.set(0, stack); + } else if (slotIn.getType() == EquipmentSlot.Type.ARMOR) { + this.bridge$playEquipSound(stack, silent); + this.inventory.armor.set(slotIn.getIndex(), stack); + } + } + + @Redirect(method = "causeFoodExhaustion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/food/FoodData;addExhaustion(F)V")) + private void arclight$exhaustEvent(FoodData foodData, float amount) { + EntityExhaustionEvent.ExhaustionReason reason = arclight$exhaustReason == null ? EntityExhaustionEvent.ExhaustionReason.UNKNOWN : arclight$exhaustReason; + arclight$exhaustReason = null; + EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent((net.minecraft.world.entity.player.Player) (Object) this, reason, amount); + if (!event.isCancelled()) { + this.foodData.addExhaustion(event.getExhaustion()); + } + } + + private EntityExhaustionEvent.ExhaustionReason arclight$exhaustReason; + + public void applyExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) { + bridge$pushExhaustReason(reason); + this.causeFoodExhaustion(f); + } + + @Override + public void bridge$pushExhaustReason(EntityExhaustionEvent.ExhaustionReason reason) { + arclight$exhaustReason = reason; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerEntityMixin.java new file mode 100644 index 00000000..38dfb8d1 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/ServerPlayerEntityMixin.java @@ -0,0 +1,963 @@ +package io.izzel.arclight.common.mixin.core.world.entity.player; + +import com.mojang.datafixers.util.Either; +import io.izzel.arclight.common.bridge.block.PortalInfoBridge; +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.InternalEntityBridge; +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; +import io.izzel.arclight.common.bridge.network.play.ServerPlayNetHandlerBridge; +import io.izzel.arclight.common.bridge.util.FoodStatsBridge; +import io.izzel.arclight.common.bridge.world.TeleporterBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import io.izzel.arclight.common.mod.util.BlackholeNetHandler; +import io.izzel.arclight.common.mod.server.block.ChestBlockDoubleInventoryHacks; +import net.minecraft.BlockUtil; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.ChatType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket; +import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; +import net.minecraft.network.protocol.game.ClientboundGameEventPacket; +import net.minecraft.network.protocol.game.ClientboundHorseScreenOpenPacket; +import net.minecraft.network.protocol.game.ClientboundLevelEventPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerCombatPacket; +import net.minecraft.network.protocol.game.ClientboundRespawnPacket; +import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; +import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; +import net.minecraft.network.protocol.game.ServerboundClientInformationPacket; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.PlayerRespawnLogic; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerPlayerGameMode; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.players.PlayerList; +import net.minecraft.stats.Stat; +import net.minecraft.stats.Stats; +import net.minecraft.util.Mth; +import net.minecraft.util.Unit; +import net.minecraft.world.Container; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.damagesource.CombatTracker; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.HumanoidArm; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.horse.AbstractHorse; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.monster.Monster; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodData; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.HorseInventoryMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.BiomeManager; +import net.minecraft.world.level.block.NetherPortalBlock; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.portal.PortalInfo; +import net.minecraft.world.level.storage.LevelData; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.scores.Score; +import net.minecraft.world.scores.Scoreboard; +import net.minecraft.world.scores.Team; +import net.minecraft.world.scores.criteria.ObjectiveCriteria; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.ITeleporter; +import net.minecraftforge.fml.hooks.BasicEventHooks; +import net.minecraftforge.fml.server.ServerLifecycleHooks; +import org.apache.logging.log4j.Logger; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.WeatherType; +import org.bukkit.craftbukkit.v.CraftServer; +import org.bukkit.craftbukkit.v.CraftWorld; +import org.bukkit.craftbukkit.v.entity.CraftPlayer; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.event.CraftPortalEvent; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v.scoreboard.CraftScoreboardManager; +import org.bukkit.craftbukkit.v.util.CraftChatMessage; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerChangedMainHandEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerLocaleChangeEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.MainHand; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.Optional; +import java.util.OptionalInt; +import java.util.Random; +import java.util.UUID; +import java.util.function.Consumer; + +@Mixin(ServerPlayer.class) +public abstract class ServerPlayerEntityMixin extends PlayerMixin implements ServerPlayerEntityBridge { + + // @formatter:off + @Shadow @Final public MinecraftServer server; + @Shadow protected abstract int getCoprime(int p_205735_1_); + @Shadow @Final public ServerPlayerGameMode gameMode; + @Shadow public ServerGamePacketListenerImpl connection; + @Shadow public abstract boolean isSpectator(); + @Shadow public abstract void resetStat(Stat stat); + @Shadow public abstract void closeContainer(); + @Shadow public abstract void setCamera(Entity entityToSpectate); + @Shadow public boolean isChangingDimension; + @Shadow public abstract ServerLevel getLevel(); + @Shadow public boolean wonGame; + @Shadow private boolean seenCredits; + @Shadow @Nullable private Vec3 enteredNetherPosition; + @Shadow public abstract void triggerDimensionChangeTriggers(ServerLevel p_213846_1_); + @Shadow public int lastSentExp; + @Shadow private float lastSentHealth; + @Shadow private int lastSentFood; + @Shadow public int containerCounter; + @Shadow(remap = false) private String language; + @Shadow public abstract void teleportTo(ServerLevel newWorld, double x, double y, double z, float yaw, float pitch); + @Shadow public abstract void giveExperiencePoints(int p_195068_1_); + @Shadow private ResourceKey respawnDimension; + @Shadow @Nullable public abstract BlockPos getRespawnPosition(); + @Shadow public abstract float getRespawnAngle(); + @Shadow protected abstract void tellNeutralMobsThatIDied(); + @Shadow protected abstract void createEndPlatform(ServerLevel p_242110_1_, BlockPos p_242110_2_); + @Shadow @Final private static Logger LOGGER; + @Shadow public abstract boolean isCreative(); + @Shadow public abstract void setRespawnPosition(ResourceKey p_242111_1_, @org.jetbrains.annotations.Nullable BlockPos p_242111_2_, float p_242111_3_, boolean p_242111_4_, boolean p_242111_5_); + @Shadow protected abstract boolean bedBlocked(BlockPos p_241156_1_, Direction p_241156_2_); + @Shadow protected abstract boolean bedInRange(BlockPos p_241147_1_, Direction p_241147_2_); + @Shadow public abstract void sendMessage(Component component, UUID senderUUID); + // @formatter:on + + public String displayName; + public Component listName; + public org.bukkit.Location compassTarget; + public int newExp = 0; + public int newLevel = 0; + public int newTotalExp = 0; + public boolean keepLevel = false; + public double maxHealthCache; + public boolean joining = true; + public boolean sentListPacket = false; + public Integer clientViewDistance; + public long timeOffset = 0; + public boolean relativeTime = true; + public WeatherType weather = null; + private float pluginRainPosition; + private float pluginRainPositionPrevious; + public String locale = "en_us"; + private boolean arclight$initialized = false; + + @Inject(method = "", at = @At("RETURN")) + public void arclight$init(CallbackInfo ci) { + this.displayName = this.getGameProfile() != null ? getScoreboardName() : "~FakePlayer~"; + this.canPickUpLoot = true; + this.maxHealthCache = this.getMaxHealth(); + this.arclight$initialized = true; + if ((Object) this instanceof FakePlayer) { + this.connection = new BlackholeNetHandler(this.getServer(), (ServerPlayer) (Object) this); + } + } + + @Override + public boolean bridge$initialized() { + return this.arclight$initialized; + } + + public final BlockPos getSpawnPoint(ServerLevel worldserver) { + BlockPos blockposition = worldserver.getSharedSpawnPos(); + if (worldserver.dimensionType().hasSkyLight() && worldserver.serverLevelData.getGameType() != GameType.ADVENTURE) { + long k; + long l; + int i = Math.max(0, this.server.getSpawnRadius(worldserver)); + int j = Mth.floor(worldserver.getWorldBorder().getDistanceToBorder(blockposition.getX(), blockposition.getZ())); + if (j < i) { + i = j; + } + if (j <= 1) { + i = 1; + } + int i1 = (l = (k = (long) (i * 2 + 1)) * k) > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l; + int j1 = this.getCoprime(i1); + int k1 = new Random().nextInt(i1); + for (int l1 = 0; l1 < i1; ++l1) { + int i2 = (k1 + j1 * l1) % i1; + int j2 = i2 % (i * 2 + 1); + int k2 = i2 / (i * 2 + 1); + BlockPos blockposition1 = PlayerRespawnLogic.getOverworldRespawnPos(worldserver, blockposition.getX() + j2 - i, blockposition.getZ() + k2 - i, false); + if (blockposition1 == null) continue; + return blockposition1; + } + } + return blockposition; + } + + @Override + public BlockPos bridge$getSpawnPoint(ServerLevel world) { + return getSpawnPoint(world); + } + + @Inject(method = "readAdditionalSaveData", at = @At("RETURN")) + private void arclight$readExtra(CompoundTag compound, CallbackInfo ci) { + this.getBukkitEntity().readExtraData(compound); + String spawnWorld = compound.getString("SpawnWorld"); + CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld); + if (oldWorld != null) { + this.respawnDimension = oldWorld.getHandle().dimension(); + } + } + + @Redirect(method = "addAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hasOnePlayerPassenger()Z")) + private boolean arclight$nonPersistVehicle(Entity entity) { + Entity entity1 = this.getVehicle(); + boolean persistVehicle = true; + if (entity1 != null) { + Entity vehicle; + for (vehicle = entity1; vehicle != null; vehicle = vehicle.getVehicle()) { + if (!((EntityBridge) vehicle).bridge$isPersist()) { + persistVehicle = false; + break; + } + } + } + return persistVehicle && entity.hasOnePlayerPassenger(); + } + + @Inject(method = "addAdditionalSaveData", at = @At("RETURN")) + private void arclight$writeExtra(CompoundTag compound, CallbackInfo ci) { + this.getBukkitEntity().setExtraData(compound); + } + + @Override + public void setLevel(Level world) { + super.setLevel(world); + if (world == null) { + this.revive(); + Vec3 position = null; + if (this.respawnDimension != null && (world = ServerLifecycleHooks.getCurrentServer().getLevel(this.respawnDimension)) != null && this.getRespawnPosition() != null) { + position = Player.findRespawnPositionAndUseSpawnBlock((ServerLevel) world, this.getRespawnPosition(), this.getRespawnAngle(), false, false).orElse(null); + } + if (world == null || position == null) { + world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle(); + position = Vec3.atCenterOf(((ServerLevel) world).getSharedSpawnPos()); + } + this.level = world; + this.setPos(position.x(), position.y(), position.z()); + } + this.gameMode.setLevel((ServerLevel) world); + } + + @Inject(method = "tick", at = @At("HEAD")) + private void arclight$joining(CallbackInfo ci) { + if (this.joining) { + this.joining = false; + } + } + + @Redirect(method = "doTick", at = @At(value = "NEW", target = "net/minecraft/network/protocol/game/ClientboundSetHealthPacket")) + private ClientboundSetHealthPacket arclight$useScaledHealth(float healthIn, int foodLevelIn, float saturationLevelIn) { + return new ClientboundSetHealthPacket(this.getBukkitEntity().getScaledHealth(), foodLevelIn, saturationLevelIn); + } + + @Inject(method = "doTick", at = @At(value = "FIELD", target = "Lnet/minecraft/server/level/ServerPlayer;tickCount:I")) + private void arclight$updateHealthAndExp(CallbackInfo ci) { + if (this.maxHealthCache != this.getMaxHealth()) { + this.getBukkitEntity().updateScaledHealth(); + } + if (this.oldLevel == -1) { + this.oldLevel = this.experienceLevel; + } + if (this.oldLevel != this.experienceLevel) { + CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); + this.oldLevel = this.experienceLevel; + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void die(DamageSource damagesource) { + if (net.minecraftforge.common.ForgeHooks.onLivingDeath((ServerPlayer) (Object) this, damagesource)) + return; + boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); + if (this.removed) { + return; + } + boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator(); + Inventory copyInv; + if (keepInventory) { + copyInv = this.inventory; + } else { + copyInv = new Inventory((ServerPlayer) (Object) this); + copyInv.replaceWith(this.inventory); + } + this.dropAllDeathLoot(damagesource); + + Component defaultMessage = this.getCombatTracker().getDeathMessage(); + String deathmessage = defaultMessage.getString(); + List loot = new ArrayList<>(); + Collection drops = this.captureDrops(null); + if (drops != null) { + for (ItemEntity entity : drops) { + CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(entity.getItem()); + loot.add(craftItemStack); + } + } + if (!keepInventory) { + this.inventory.replaceWith(copyInv); + } + PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent((ServerPlayer) (Object) this, loot, deathmessage, keepInventory); + if (this.containerMenu != this.inventoryMenu) { + this.closeContainer(); + } + String deathMessage = event.getDeathMessage(); + if (deathMessage != null && deathMessage.length() > 0 && flag) { + Component itextcomponent; + if (deathMessage.equals(deathmessage)) { + itextcomponent = this.getCombatTracker().getDeathMessage(); + } else { + itextcomponent = CraftChatMessage.fromStringOrNull(deathMessage); + } + this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent), (p_212356_2_) -> { + if (!p_212356_2_.isSuccess()) { + int i = 256; + String s = itextcomponent.getString(256); + Component itextcomponent1 = new TranslatableComponent("death.attack.message_too_long", (new TextComponent(s)).withStyle(ChatFormatting.YELLOW)); + Component itextcomponent2 = (new TranslatableComponent("death.attack.even_more_magic", this.getDisplayName())).withStyle((p_212357_1_) -> { + return p_212357_1_.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent1)); + }); + this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED, itextcomponent2)); + } + + }); + Team scoreboardteambase = this.getTeam(); + if (scoreboardteambase != null && scoreboardteambase.getDeathMessageVisibility() != Team.Visibility.ALWAYS) { + if (scoreboardteambase.getDeathMessageVisibility() == Team.Visibility.HIDE_FOR_OTHER_TEAMS) { + this.server.getPlayerList().broadcastToTeam((ServerPlayer) (Object) this, itextcomponent); + } else if (scoreboardteambase.getDeathMessageVisibility() == Team.Visibility.HIDE_FOR_OWN_TEAM) { + this.server.getPlayerList().broadcastToAllExceptTeam((ServerPlayer) (Object) this, itextcomponent); + } + } else { + this.server.getPlayerList().broadcastMessage(itextcomponent, ChatType.SYSTEM, Util.NIL_UUID); + } + } else { + this.connection.send(new ClientboundPlayerCombatPacket(this.getCombatTracker(), ClientboundPlayerCombatPacket.Event.ENTITY_DIED)); + } + this.removeEntitiesOnShoulder(); + + if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { + this.tellNeutralMobsThatIDied(); + } + + this.dropExperience(); + + if (!event.getKeepInventory()) { + this.inventory.clearContent(); + } + this.setCamera((ServerPlayer) (Object) this); + ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(ObjectiveCriteria.DEATH_COUNT, this.getScoreboardName(), Score::increment); + + LivingEntity entityliving = this.getKillCredit(); + if (entityliving != null) { + this.awardStat(Stats.ENTITY_KILLED_BY.get(entityliving.getType())); + entityliving.awardKillScore((ServerPlayer) (Object) this, this.deathScore, damagesource); + this.createWitherRose(entityliving); + } + + this.level.broadcastEntityEvent((ServerPlayer) (Object) this, (byte) 3); + this.awardStat(Stats.DEATHS); + this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_DEATH)); + this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)); + this.clearFire(); + this.setSharedFlag(0, false); + this.getCombatTracker().recheckStatus(); + } + + @Redirect(method = "awardKillScore", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/scores/Scoreboard;forAllObjectives(Lnet/minecraft/world/scores/criteria/ObjectiveCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) + private void arclight$useCustomScoreboard(Scoreboard scoreboard, ObjectiveCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { + ((CraftServer) Bukkit.getServer()).getScoreboardManager().getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); + } + + @Redirect(method = "handleTeamKill", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/scores/Scoreboard;forAllObjectives(Lnet/minecraft/world/scores/criteria/ObjectiveCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) + private void arclight$teamKill(Scoreboard scoreboard, ObjectiveCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { + ((CraftServer) Bukkit.getServer()).getScoreboardManager().getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); + } + + @Inject(method = "isPvpAllowed", cancellable = true, at = @At("HEAD")) + private void arclight$pvpMode(CallbackInfoReturnable cir) { + cir.setReturnValue(((WorldBridge) this.level).bridge$isPvpMode()); + } + + /** + * @author IzzelAliz + * @reason + */ + @Nullable + @Overwrite + protected PortalInfo findDimensionEntryPoint(ServerLevel p_241829_1_) { + PortalInfo portalinfo = super.findDimensionEntryPoint(p_241829_1_); + if (portalinfo != null && ((WorldBridge) this.level).bridge$getTypeKey() == DimensionType.OVERWORLD_LOCATION && ((WorldBridge) p_241829_1_).bridge$getTypeKey() == DimensionType.END_LOCATION) { + Vec3 vector3d = portalinfo.pos.add(0.0D, -1.0D, 0.0D); + PortalInfo newInfo = new PortalInfo(vector3d, Vec3.ZERO, 90.0F, 0.0F); + ((PortalInfoBridge) newInfo).bridge$setWorld(p_241829_1_); + ((PortalInfoBridge) newInfo).bridge$setPortalEventInfo(((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo()); + return newInfo; + } else { + return portalinfo; + } + } + + @Override + public Entity bridge$changeDimension(ServerLevel world, PlayerTeleportEvent.TeleportCause cause) { + this.arclight$cause = cause; + return changeDimension(world); + } + + private transient PlayerTeleportEvent.TeleportCause arclight$cause; + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite(remap = false) + @Nullable + public Entity changeDimension(ServerLevel server, ITeleporter teleporter) { + if (this.isSleeping()) { + return (ServerPlayer) (Object) this; + } + if (!ForgeHooks.onTravelToDimension((ServerPlayer) (Object) this, server.dimension())) return null; + + PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause; + arclight$cause = null; + + // this.invulnerableDimensionChange = true; + ServerLevel serverworld = this.getLevel(); + ResourceKey registrykey = ((WorldBridge) serverworld).bridge$getTypeKey(); + if (registrykey == DimensionType.END_LOCATION && ((WorldBridge) server).bridge$getTypeKey() == DimensionType.OVERWORLD_LOCATION && teleporter.isVanilla()) { //Forge: Fix non-vanilla teleporters triggering end credits + this.isChangingDimension = true; + this.unRide(); + this.getLevel().removePlayer((ServerPlayer) (Object) this, true); //Forge: The player entity is cloned so keep the data until after cloning calls copyFrom + if (!this.wonGame) { + this.wonGame = true; + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.WIN_GAME, this.seenCredits ? 0.0F : 1.0F)); + this.seenCredits = true; + } + + return (ServerPlayer) (Object) this; + } else { + LevelData iworldinfo = server.getLevelData(); + this.connection.send(new ClientboundRespawnPacket(server.dimensionType(), server.dimension(), BiomeManager.obfuscateSeed(server.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), server.isDebug(), server.isFlat(), true)); + this.connection.send(new ClientboundChangeDifficultyPacket(iworldinfo.getDifficulty(), iworldinfo.isDifficultyLocked())); + PlayerList playerlist = this.server.getPlayerList(); + playerlist.sendPlayerPermissionLevel((ServerPlayer) (Object) this); + serverworld.removeEntity((ServerPlayer) (Object) this, true); //Forge: the player entity is moved to the new world, NOT cloned. So keep the data alive with no matching invalidate call. + this.revive(); + PortalInfo portalinfo = teleporter.getPortalInfo((ServerPlayer) (Object) this, server, this::findDimensionEntryPoint); + ServerLevel[] exitWorld = new ServerLevel[]{server}; + if (portalinfo != null) { + Entity e = teleporter.placeEntity((ServerPlayer) (Object) this, serverworld, exitWorld[0], this.yRot, spawnPortal -> {//Forge: Start vanilla logic + serverworld.getProfiler().push("moving"); + + if (((PortalInfoBridge) portalinfo).bridge$getWorld() != null) { + exitWorld[0] = ((PortalInfoBridge) portalinfo).bridge$getWorld(); + } + if (exitWorld[0] != null) { + if (registrykey == DimensionType.OVERWORLD_LOCATION && ((WorldBridge) exitWorld[0]).bridge$getTypeKey() == DimensionType.NETHER_LOCATION) { + this.enteredNetherPosition = this.position(); + } else if (spawnPortal && ((WorldBridge) exitWorld[0]).bridge$getTypeKey() == DimensionType.END_LOCATION + && (((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo() == null || ((PortalInfoBridge) portalinfo).bridge$getPortalEventInfo().getCanCreatePortal())) { + this.createEndPlatform(exitWorld[0], new BlockPos(portalinfo.pos)); + } + } + + Location enter = this.getBukkitEntity().getLocation(); + Location exit = (exitWorld[0] == null) ? null : new Location(((WorldBridge) exitWorld[0]).bridge$getWorld(), portalinfo.pos.x, portalinfo.pos.y, portalinfo.pos.z, portalinfo.yRot, portalinfo.xRot); + PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, cause); + Bukkit.getServer().getPluginManager().callEvent(tpEvent); + if (tpEvent.isCancelled() || tpEvent.getTo() == null) { + return null; + } + exit = tpEvent.getTo(); + + serverworld.getProfiler().pop(); + serverworld.getProfiler().push("placing"); + + this.isChangingDimension = true; + ServerLevel newWorld = ((CraftWorld) exit.getWorld()).getHandle(); + if (newWorld != exitWorld[0]) { + exitWorld[0] = newWorld; + LevelData newWorldInfo = exitWorld[0].getLevelData(); + this.connection.send(new ClientboundRespawnPacket(exitWorld[0].dimensionType(), exitWorld[0].dimension(), BiomeManager.obfuscateSeed(exitWorld[0].getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), exitWorld[0].isDebug(), exitWorld[0].isFlat(), true)); + this.connection.send(new ClientboundChangeDifficultyPacket(newWorldInfo.getDifficulty(), newWorldInfo.isDifficultyLocked())); + } + + this.setLevel(exitWorld[0]); + exitWorld[0].addDuringPortalTeleport((ServerPlayer) (Object) this); + + ((ServerPlayNetHandlerBridge) this.connection).bridge$teleport(exit); + this.connection.resetPosition(); + + serverworld.getProfiler().pop(); + this.triggerDimensionChangeTriggers(exitWorld[0]); + return (ServerPlayer) (Object) this;//forge: this is part of the ITeleporter patch + });//Forge: End vanilla logic + if (e == null) { + serverworld.addDuringPortalTeleport((ServerPlayer) (Object) this); + return (ServerPlayer) (Object) this; + } else if (e != (Object) this) { + throw new IllegalArgumentException(String.format("Teleporter %s returned not the player entity but instead %s, expected PlayerEntity %s", teleporter, e, this)); + } + + this.gameMode.setLevel(exitWorld[0]); + this.connection.send(new ClientboundPlayerAbilitiesPacket(this.abilities)); + playerlist.sendLevelInfo((ServerPlayer) (Object) this, exitWorld[0]); + playerlist.sendAllPlayerInfo((ServerPlayer) (Object) this); + + for (MobEffectInstance effectinstance : this.getActiveEffects()) { + this.connection.send(new ClientboundUpdateMobEffectPacket(this.getId(), effectinstance)); + } + + if (teleporter.playTeleportSound((ServerPlayer) (Object) this, serverworld, exitWorld[0])) { + this.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false)); + } + this.lastSentExp = -1; + this.lastSentHealth = -1.0F; + this.lastSentFood = -1; + BasicEventHooks.firePlayerChangedDimensionEvent((ServerPlayer) (Object) this, serverworld.dimension(), exitWorld[0].dimension()); + PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), ((WorldBridge) serverworld).bridge$getWorld()); + Bukkit.getPluginManager().callEvent(changeEvent); + } + + return (ServerPlayer) (Object) this; + } + } + + @Override + protected CraftPortalEvent callPortalEvent(Entity entity, ServerLevel exitWorldServer, BlockPos exitPosition, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { + Location enter = this.getBukkitEntity().getLocation(); + Location exit = new Location(((WorldBridge) exitWorldServer).bridge$getWorld(), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ(), this.yRot, this.xRot); + PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, 128, true, creationRadius); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null) { + return null; + } + return new CraftPortalEvent(event); + } + + @Override + protected Optional findOrCreatePortal(ServerLevel worldserver, BlockPos blockposition, boolean flag, int searchRadius, boolean canCreatePortal, int createRadius) { + Optional optional = super.findOrCreatePortal(worldserver, blockposition, flag, searchRadius, canCreatePortal, createRadius); + if (optional.isPresent() || !canCreatePortal) { + return optional; + } + Direction.Axis enumdirection_enumaxis = this.level.getBlockState(this.portalEntrancePos).getOptionalValue(NetherPortalBlock.AXIS).orElse(Direction.Axis.X); + Optional optional1 = ((TeleporterBridge) worldserver.getPortalForcer()).bridge$createPortal(blockposition, enumdirection_enumaxis, (ServerPlayer) (Object) this, createRadius); + if (!optional1.isPresent()) { + LOGGER.error("Unable to create a portal, likely target out of worldborder"); + } + return optional1; + } + + private Either getBedResult(BlockPos blockposition, Direction enumdirection) { + if (!this.isSleeping() && this.isAlive()) { + if (!this.level.dimensionType().natural()) { + return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_HERE); + } + if (!this.bedInRange(blockposition, enumdirection)) { + return Either.left(Player.BedSleepingProblem.TOO_FAR_AWAY); + } + if (this.bedBlocked(blockposition, enumdirection)) { + return Either.left(Player.BedSleepingProblem.OBSTRUCTED); + } + this.setRespawnPosition(this.level.dimension(), blockposition, this.yRot, false, true); + if (this.level.isDay()) { + return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW); + } + if (!this.isCreative()) { + double d0 = 8.0; + double d1 = 5.0; + Vec3 vec3d = Vec3.atBottomCenterOf(blockposition); + List list = this.level.getEntitiesOfClass(Monster.class, new AABB(vec3d.x() - 8.0, vec3d.y() - 5.0, vec3d.z() - 8.0, vec3d.x() + 8.0, vec3d.y() + 5.0, vec3d.z() + 8.0), entitymonster -> entitymonster.isPreventingPlayerRest((ServerPlayer) (Object) this)); + if (!list.isEmpty()) { + return Either.left(Player.BedSleepingProblem.NOT_SAFE); + } + } + return Either.right(Unit.INSTANCE); + } + return Either.left(Player.BedSleepingProblem.OTHER_PROBLEM); + } + + @Redirect(method = "startSleepInBed", at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/datafixers/util/Either;left(Ljava/lang/Object;)Lcom/mojang/datafixers/util/Either;")) + private Either arclight$failSleep(L value, BlockPos pos) { + Either either = Either.left(value); + return arclight$fireBedEvent(either, pos); + } + + @Redirect(method = "startSleepInBed", at = @At(value = "INVOKE", remap = false, target = "Lcom/mojang/datafixers/util/Either;ifRight(Ljava/util/function/Consumer;)Lcom/mojang/datafixers/util/Either;")) + private Either arclight$successSleep(Either either, Consumer consumer, BlockPos pos) { + return arclight$fireBedEvent(either, pos).ifRight(consumer); + } + + @SuppressWarnings("unchecked") + private Either arclight$fireBedEvent(Either e, BlockPos pos) { + Either either = (Either) e; + if (either.left().orElse(null) == Player.BedSleepingProblem.OTHER_PROBLEM) { + return (Either) either; + } else { + if (arclight$forceSleep) { + either = Either.right(Unit.INSTANCE); + } + return (Either) CraftEventFactory.callPlayerBedEnterEvent((ServerPlayer) (Object) this, pos, either); + } + } + + @Inject(method = "stopSleepInBed", cancellable = true, at = @At(value = "HEAD")) + private void arclight$wakeupOutBed(boolean p_225652_1_, boolean p_225652_2_, CallbackInfo ci) { + if (!this.isSleeping()) ci.cancel(); + } + + public int nextContainerCounter() { + this.nextContainerCounter(); + return this.containerCounter; + } + + @Inject(method = "openMenu", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/MenuProvider;createMenu(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/inventory/AbstractContainerMenu;")) + private void arclight$invOpen(MenuProvider itileinventory, CallbackInfoReturnable cir, AbstractContainerMenu container) { + if (container != null) { + ((ContainerBridge) container).bridge$setTitle(itileinventory.getDisplayName()); + boolean cancelled = false; + ArclightCaptures.captureContainerOwner((ServerPlayer) (Object) this); + container = CraftEventFactory.callInventoryOpenEvent((ServerPlayer) (Object) this, container, cancelled); + ArclightCaptures.resetContainerOwner(); + if (container == null && !cancelled) { + if (itileinventory instanceof Container) { + ((Container) itileinventory).stopOpen((ServerPlayer) (Object) this); + } else if (ChestBlockDoubleInventoryHacks.isInstance(itileinventory)) { + ChestBlockDoubleInventoryHacks.get(itileinventory).stopOpen((ServerPlayer) (Object) this); + } + cir.setReturnValue(OptionalInt.empty()); + } + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void openHorseInventory(final AbstractHorse entityhorseabstract, final Container iinventory) { + this.nextContainerCounter(); + AbstractContainerMenu container = new HorseInventoryMenu(this.containerCounter, this.inventory, iinventory, entityhorseabstract); + ((ContainerBridge) container).bridge$setTitle(entityhorseabstract.getDisplayName()); + container = CraftEventFactory.callInventoryOpenEvent((ServerPlayer) (Object) this, container); + if (container == null) { + iinventory.stopOpen((ServerPlayer) (Object) this); + return; + } + if (this.containerMenu != this.inventoryMenu) { + this.closeContainer(); + } + this.connection.send(new ClientboundHorseScreenOpenPacket(this.containerCounter, iinventory.getContainerSize(), entityhorseabstract.getId())); + (this.containerMenu = container).addSlotListener((ServerPlayer) (Object) this); + net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerContainerEvent.Open((ServerPlayer) (Object) this, this.containerMenu)); + } + + @Inject(method = "refreshContainer", at = @At("RETURN")) + private void arclight$sendExtra(AbstractContainerMenu container, NonNullList itemsList, CallbackInfo ci) { + ArclightCaptures.captureContainerOwner((ServerPlayer) (Object) this); + if (EnumSet.of(InventoryType.CRAFTING, InventoryType.WORKBENCH).contains(((ContainerBridge) container).bridge$getBukkitView().getType())) { + this.connection.send(new ClientboundContainerSetSlotPacket(container.containerId, 0, container.getSlot(0).getItem())); + } + ArclightCaptures.resetContainerOwner(); + } + + @Inject(method = "doCloseContainer", at = @At("HEAD")) + private void arclight$invClose(CallbackInfo ci) { + if (this.containerMenu != this.inventoryMenu) { + CraftEventFactory.handleInventoryCloseEvent((ServerPlayer) (Object) this); + } + } + + @Redirect(method = "awardStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/scores/Scoreboard;forAllObjectives(Lnet/minecraft/world/scores/criteria/ObjectiveCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) + private void arclight$addStats(Scoreboard scoreboard, ObjectiveCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { + ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); + } + + @Redirect(method = "resetStat", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/scores/Scoreboard;forAllObjectives(Lnet/minecraft/world/scores/criteria/ObjectiveCriteria;Ljava/lang/String;Ljava/util/function/Consumer;)V")) + private void arclight$takeStats(Scoreboard scoreboard, ObjectiveCriteria p_197893_1_, String p_197893_2_, Consumer p_197893_3_) { + ((CraftScoreboardManager) Bukkit.getScoreboardManager()).getScoreboardScores(p_197893_1_, p_197893_2_, p_197893_3_); + } + + @Inject(method = "resetSentInfo", at = @At("HEAD")) + private void arclight$setExpUpdate(CallbackInfo ci) { + this.lastSentExp = -1; + } + + public void sendMessage(UUID uuid, Component[] components) { + for (final Component component : components) { + this.sendMessage(component, uuid == null ? Util.NIL_UUID : uuid); + } + } + + @Override + public void bridge$sendMessage(Component[] components, UUID uuid) { + sendMessage(uuid, components); + } + + @Override + public void bridge$sendMessage(Component component, UUID uuid) { + this.sendMessage(component, uuid == null ? Util.NIL_UUID : uuid); + } + + @Inject(method = "setGameMode", cancellable = true, at = @At("HEAD")) + private void arclight$gameModeChange(GameType gameType, CallbackInfo ci) { + if (gameType == this.gameMode.getGameModeForPlayer()) { + ci.cancel(); + return; + } + + PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(getBukkitEntity(), GameMode.getByValue(gameType.getId())); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "updateOptions", at = @At("HEAD")) + private void arclight$settingChange(ServerboundClientInformationPacket packetIn, CallbackInfo ci) { + if (this.getMainArm() != packetIn.getMainHand()) { + PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), (this.getMainArm() == HumanoidArm.LEFT) ? MainHand.LEFT : MainHand.RIGHT); + Bukkit.getPluginManager().callEvent(event); + } + if (!this.language.equals(packetIn.getLanguage())) { + PlayerLocaleChangeEvent event2 = new PlayerLocaleChangeEvent(this.getBukkitEntity(), packetIn.getLanguage()); + Bukkit.getPluginManager().callEvent(event2); + } + this.locale = packetIn.getLanguage(); + this.clientViewDistance = packetIn.viewDistance; + } + + @Inject(method = "setCamera", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;teleportTo(DDD)V")) + private void arclight$spectatorReason(Entity entityToSpectate, CallbackInfo ci) { + this.bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause.SPECTATE); + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + @Nullable + public Component getTabListDisplayName() { + return listName; + } + + @Inject(method = "teleportTo", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/server/level/ServerPlayer;stopRiding()V")) + private void arclight$handleBy(ServerLevel world, double x, double y, double z, float yaw, float pitch, CallbackInfo ci) { + PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause; + arclight$cause = null; + this.getBukkitEntity().teleport(new Location(((WorldBridge) world).bridge$getWorld(), x, y, z, yaw, pitch), cause); + ci.cancel(); + } + + public void a(ServerLevel worldserver, double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { + bridge$pushChangeDimensionCause(cause); + teleportTo(worldserver, d0, d1, d2, f, f1); + } + + public CraftPlayer getBukkitEntity() { + return (CraftPlayer) ((InternalEntityBridge) this).internal$getBukkitEntity(); + } + + @Override + public CraftPlayer bridge$getBukkitEntity() { + return (CraftPlayer) ((InternalEntityBridge) this).internal$getBukkitEntity(); + } + + @Override + public void bridge$pushChangeDimensionCause(PlayerTeleportEvent.TeleportCause cause) { + arclight$cause = cause; + } + + @Override + public Optional bridge$getTeleportCause() { + try { + return Optional.ofNullable(arclight$cause); + } finally { + arclight$cause = null; + } + } + + public long getPlayerTime() { + if (this.relativeTime) { + return this.level.getDayTime() + this.timeOffset; + } + return this.level.getDayTime() - this.level.getDayTime() % 24000L + this.timeOffset; + } + + public WeatherType getPlayerWeather() { + return this.weather; + } + + public void setPlayerWeather(WeatherType type, boolean plugin) { + if (!plugin && this.weather != null) { + return; + } + if (plugin) { + this.weather = type; + } + if (type == WeatherType.DOWNFALL) { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.STOP_RAINING, 0.0f)); + } else { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0f)); + } + } + + public void updateWeather(float oldRain, float newRain, float oldThunder, float newThunder) { + if (this.weather == null) { + if (oldRain != newRain) { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.RAIN_LEVEL_CHANGE, newRain)); + } + } else if (this.pluginRainPositionPrevious != this.pluginRainPosition) { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.RAIN_LEVEL_CHANGE, this.pluginRainPosition)); + } + if (oldThunder != newThunder) { + if (this.weather == WeatherType.DOWNFALL || this.weather == null) { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE, newThunder)); + } else { + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE, 0.0f)); + } + } + } + + public void tickWeather() { + if (this.weather == null) { + return; + } + this.pluginRainPositionPrevious = this.pluginRainPosition; + if (this.weather == WeatherType.DOWNFALL) { + this.pluginRainPosition += (float) 0.01; + } else { + this.pluginRainPosition -= (float) 0.01; + } + this.pluginRainPosition = Mth.clamp(this.pluginRainPosition, 0.0f, 1.0f); + } + + public void resetPlayerWeather() { + this.weather = null; + this.setPlayerWeather(this.level.getLevelData().isRaining() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false); + } + + @Override + public String toString() { + return super.toString() + "(" + this.getScoreboardName() + " at " + this.getX() + "," + this.getY() + "," + this.getZ() + ")"; + } + + public void forceSetPositionRotation(double x, double y, double z, float yaw, float pitch) { + this.moveTo(x, y, z, yaw, pitch); + this.connection.resetPosition(); + } + + @Override + protected boolean isImmobile() { + return super.isImmobile() || !this.getBukkitEntity().isOnline(); + } + + @Override + public Scoreboard getScoreboard() { + return this.getBukkitEntity().getScoreboard().getHandle(); + } + + public void reset() { + float exp = 0.0f; + boolean keepInventory = this.level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY); + if (this.keepLevel || keepInventory) { + exp = this.experienceProgress; + this.newTotalExp = this.totalExperience; + this.newLevel = this.experienceLevel; + } + this.setHealth(this.getMaxHealth()); + this.remainingFireTicks = 0; + this.fallDistance = 0.0f; + this.foodData = new FoodData(); + ((FoodStatsBridge) this.foodData).bridge$setEntityHuman((ServerPlayer) (Object) this); + this.experienceLevel = this.newLevel; + this.totalExperience = this.newTotalExp; + this.experienceProgress = 0.0f; + this.deathTime = 0; + this.setArrowCount(0, true); + this.removeAllEffects(EntityPotionEffectEvent.Cause.DEATH); + this.effectsDirty = true; + this.containerMenu = this.inventoryMenu; + this.lastHurtByPlayer = null; + this.lastHurtByMob = null; + this.combatTracker = new CombatTracker((ServerPlayer) (Object) this); + this.lastSentExp = -1; + if (this.keepLevel || keepInventory) { + this.experienceProgress = exp; + } else { + this.giveExperiencePoints(this.newExp); + } + this.keepLevel = false; + } + + @Override + public boolean bridge$isMovementBlocked() { + return isImmobile(); + } + + @Override + public void bridge$setCompassTarget(Location location) { + this.compassTarget = location; + } + + @Override + public boolean bridge$isJoining() { + return joining; + } + + @Override + public void bridge$reset() { + reset(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java new file mode 100644 index 00000000..6b9b3082 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java @@ -0,0 +1,82 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge; +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.CraftServer; +import org.bukkit.craftbukkit.v.entity.CraftItem; +import org.bukkit.entity.AbstractArrow; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.player.PlayerPickupArrowEvent; +import org.bukkit.projectiles.ProjectileSource; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(net.minecraft.world.entity.projectile.AbstractArrow.class) +public abstract class AbstractArrowMixin extends ProjectileMixin { + + // @formatter:off + @Shadow public boolean inGround; + @Shadow public abstract boolean isNoPhysics(); + @Shadow public int shakeTime; + @Shadow public net.minecraft.world.entity.projectile.AbstractArrow.Pickup pickup; + @Shadow protected abstract ItemStack getPickupItem(); + // @formatter:on + + @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/entity/projectile/AbstractArrow;hasImpulse:Z")) + private void arclight$hitEvent(CallbackInfo ci, HitResult hitResult) { + this.preOnHit(hitResult); + } + + @Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) + private void arclight$fireShot(Entity entity, int seconds, EntityHitResult result) { + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); + Bukkit.getPluginManager().callEvent(combustEvent); + if (!combustEvent.isCancelled()) { + ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void playerTouch(Player playerEntity) { + if (!this.level.isClientSide && (this.inGround || this.isNoPhysics()) && this.shakeTime <= 0) { + ItemStack itemstack = this.getPickupItem(); + if (this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) playerEntity.getInventory()).bridge$canHold(itemstack) > 0) { + ItemEntity item = new ItemEntity(this.level, this.getX(), this.getY(), this.getZ(), itemstack); + PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (net.minecraft.world.entity.projectile.AbstractArrow) (Object) this, item), (AbstractArrow) this.getBukkitEntity()); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + itemstack = item.getItem(); + } + if ((this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.ALLOWED && playerEntity.getInventory().add(itemstack)) || (this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.CREATIVE_ONLY && playerEntity.getAbilities().instabuild)) { + playerEntity.take((net.minecraft.world.entity.projectile.AbstractArrow) (Object) this, 1); + this.discard(); + } + } + } + + @Inject(method = "setOwner", at = @At("HEAD")) + private void arclight$setShooter(Entity entityIn, CallbackInfo ci) { + this.projectileSource = entityIn == null ? null : (ProjectileSource) ((EntityBridge) entityIn).bridge$getBukkitEntity(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java new file mode 100644 index 00000000..9ef5b206 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java @@ -0,0 +1,69 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.projectile.DamagingProjectileEntityBridge; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.HitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(AbstractHurtingProjectile.class) +public abstract class AbstractHurtingProjectileMixin extends ProjectileMixin implements DamagingProjectileEntityBridge { + + // @formatter:off + @Shadow public double xPower; + @Shadow public double yPower; + @Shadow public double zPower; + // @formatter:on + + public float bukkitYield; + public boolean isIncendiary; + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType p_i50173_1_, Level p_i50173_2_, CallbackInfo ci) { + this.bukkitYield = 1; + this.isIncendiary = true; + } + + public void setDirection(double d0, double d1, double d2) { + double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); + + this.xPower = d0 / d3 * 0.1D; + this.yPower = d1 / d3 * 0.1D; + this.zPower = d2 / d3 * 0.1D; + } + + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;onHit(Lnet/minecraft/world/phys/HitResult;)V")) + private void arclight$preOnHit(AbstractHurtingProjectile abstractHurtingProjectile, HitResult hitResult) { + this.preOnHit(hitResult); + } + + @Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;onHit(Lnet/minecraft/world/phys/HitResult;)V")) + private void arclight$projectileHit(CallbackInfo ci, Entity entity, HitResult rayTraceResult) { + if (this.isRemoved()) { + CraftEventFactory.callProjectileHitEvent((AbstractHurtingProjectile) (Object) this, rayTraceResult); + } + } + + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getLookAngle()Lnet/minecraft/world/phys/Vec3;")) + private void arclight$nonLivingAttack(DamageSource source, float amount, CallbackInfoReturnable cir) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((AbstractHurtingProjectile) (Object) this, source, amount, false)) { + cir.setReturnValue(false); + } + } + + @Override + public void bridge$setBukkitYield(float yield) { + this.bukkitYield = yield; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ArrowEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ArrowEntityMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ArrowEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ArrowEntityMixin.java index fdd64ec7..67133255 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/ArrowEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ArrowEntityMixin.java @@ -1,15 +1,6 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; +package io.izzel.arclight.common.mixin.core.world.entity.projectile; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.ArrowEntity; -import net.minecraft.network.datasync.DataParameter; -import net.minecraft.potion.EffectInstance; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionUtils; -import net.minecraft.potion.Potions; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.Registry; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Implements; @@ -22,24 +13,33 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import io.izzel.arclight.common.bridge.entity.projectile.ArrowEntityBridge; import java.util.Set; +import net.minecraft.core.Registry; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.Arrow; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.alchemy.Potions; -@Mixin(ArrowEntity.class) +@Mixin(Arrow.class) @Implements(@Interface(iface = ArrowEntityBridge.Hack.class, prefix = "hack$")) -public abstract class ArrowEntityMixin extends AbstractArrowEntityMixin implements ArrowEntityBridge { +public abstract class ArrowEntityMixin extends AbstractArrowMixin implements ArrowEntityBridge { // @formatter:off - @Shadow @Final private static DataParameter COLOR; - @Shadow @Final public Set customPotionEffects; + @Shadow @Final private static EntityDataAccessor ID_EFFECT_COLOR; + @Shadow @Final public Set effects; @Shadow private Potion potion; // @formatter:on - @Inject(method = "arrowHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doPostHurtEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void arclight$arrowHit(LivingEntity living, CallbackInfo ci) { ((LivingEntityBridge) living).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ARROW); } public void refreshEffects() { - this.getDataManager().set(COLOR, PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects))); + this.getEntityData().set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects))); } @Override @@ -52,12 +52,12 @@ public abstract class ArrowEntityMixin extends AbstractArrowEntityMixin implemen } public void hack$setType(final String string) { - this.potion = Registry.POTION.getOrDefault(new ResourceLocation(string)); - this.getDataManager().set(COLOR, PotionUtils.getPotionColorFromEffectList(PotionUtils.mergeEffects(this.potion, this.customPotionEffects))); + this.potion = Registry.POTION.get(new ResourceLocation(string)); + this.getEntityData().set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects))); } public boolean isTipped() { - return !this.customPotionEffects.isEmpty() || this.potion != Potions.EMPTY; + return !this.effects.isEmpty() || this.potion != Potions.EMPTY; } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java new file mode 100644 index 00000000..fdeb859f --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.EvokerFangs; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EvokerFangs.class) +public abstract class EvokerFangsMixin extends EntityMixin { + + @Inject(method = "dealDamageTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + private void arclight$entityDamage(LivingEntity p_190551_1_, CallbackInfo ci) { + CraftEventFactory.entityDamage = (EvokerFangs) (Object) this; + } + + @Inject(method = "dealDamageTo", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + private void arclight$entityDamageReset(LivingEntity p_190551_1_, CallbackInfo ci) { + CraftEventFactory.entityDamage = null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java new file mode 100644 index 00000000..60f95b0e --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireballMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.projectile.Fireball; +import net.minecraft.world.item.ItemStack; +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; + +@Mixin(Fireball.class) +public abstract class FireballMixin extends AbstractHurtingProjectileMixin { + + @Inject(method = "readAdditionalSaveData", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/Fireball;setItem(Lnet/minecraft/world/item/ItemStack;)V")) + private void arclight$nonNullItem(CompoundTag compound, CallbackInfo ci, ItemStack stack) { + if (stack.isEmpty()) ci.cancel(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireworkRocketEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java similarity index 64% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireworkRocketEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java index 01e10efb..828864f4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/FireworkRocketEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; +package io.izzel.arclight.common.mixin.core.world.entity.projectile; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.projectile.FireworkRocketEntity; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.entity.projectile.FireworkRocketEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,19 +11,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(FireworkRocketEntity.class) public abstract class FireworkRocketEntityMixin extends EntityMixin { - @Inject(method = "func_213893_k", cancellable = true, at = @At("HEAD")) + @Inject(method = "explode", cancellable = true, at = @At("HEAD")) private void arclight$fireworksExplode(CallbackInfo ci) { if (CraftEventFactory.callFireworkExplodeEvent((FireworkRocketEntity) (Object) this).isCancelled()) { ci.cancel(); } } - @Inject(method = "dealExplosionDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) + @Inject(method = "dealExplosionDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) private void arclight$damageSource(CallbackInfo ci) { CraftEventFactory.entityDamage = (FireworkRocketEntity) (Object) this; } - @Inject(method = "dealExplosionDamage", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/LivingEntity;attackEntityFrom(Lnet/minecraft/util/DamageSource;F)Z")) + @Inject(method = "dealExplosionDamage", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/LivingEntity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) private void arclight$damageSourceReset(CallbackInfo ci) { CraftEventFactory.entityDamage = null; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java new file mode 100644 index 00000000..c9a19cee --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java @@ -0,0 +1,169 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.stats.Stats; +import net.minecraft.tags.ItemTags; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.BuiltInLootTables; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.LootTable; +import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.phys.HitResult; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.ItemFishedEvent; +import org.bukkit.Bukkit; +import org.bukkit.entity.FishHook; +import org.bukkit.event.player.PlayerFishEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Collections; +import java.util.List; + +@Mixin(FishingHook.class) +public abstract class FishingHookMixin extends ProjectileMixin { + + // @formatter:off + @Shadow public Entity hookedIn; + @Shadow private int nibble; + @Shadow @Final private int luck; + @Shadow public abstract Player getPlayerOwner(); + @Shadow private int timeUntilHooked; + @Shadow private int timeUntilLured; + @Shadow @Final private int lureSpeed; + @Shadow protected abstract void pullEntity(Entity p_150156_); + // @formatter:on + + public int minWaitTime = 100; + public int maxWaitTime = 600; + public boolean applyLure = true; + + @Redirect(method = "checkCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;onHit(Lnet/minecraft/world/phys/HitResult;)V")) + private void arclight$collide(FishingHook fishingHook, HitResult hitResult) { + this.preOnHit(hitResult); + } + + @Inject(method = "catchingFish", at = @At(value = "FIELD", shift = At.Shift.AFTER, ordinal = 0, target = "Lnet/minecraft/world/entity/projectile/FishingHook;timeUntilHooked:I")) + private void arclight$attemptFail(BlockPos blockPos, CallbackInfo ci) { + PlayerFishEvent event = new PlayerFishEvent(((ServerPlayerEntityBridge) this.getPlayerOwner()).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT); + Bukkit.getPluginManager().callEvent(event); + } + + @Inject(method = "catchingFish", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;playSound(Lnet/minecraft/sounds/SoundEvent;FF)V")) + private void arclight$fishBite(BlockPos blockPos, CallbackInfo ci) { + PlayerFishEvent event = new PlayerFishEvent(((ServerPlayerEntityBridge) this.getPlayerOwner()).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "catchingFish", at = @At("RETURN")) + private void arclight$modifyWaitingTime(BlockPos p_37146_, CallbackInfo ci) { + if (this.nibble <= 0 && this.timeUntilHooked <= 0 && this.timeUntilLured <= 0) { + this.timeUntilLured = Mth.nextInt(this.random, this.minWaitTime, this.maxWaitTime); + this.timeUntilLured -= (this.applyLure) ? this.lureSpeed * 20 * 5 : 0; + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public int retrieve(ItemStack stack) { + Player playerentity = this.getPlayerOwner(); + if (!this.level.isClientSide && playerentity != null) { + int i = 0; + ItemFishedEvent event = null; + if (this.hookedIn != null) { + PlayerFishEvent fishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), ((EntityBridge) this.hookedIn).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY); + Bukkit.getPluginManager().callEvent(fishEvent); + if (fishEvent.isCancelled()) { + return 0; + } + this.pullEntity(this.hookedIn); + CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) playerentity, stack, (FishingHook) (Object) this, Collections.emptyList()); + this.level.broadcastEntityEvent((FishingHook) (Object) this, (byte) 31); + i = this.hookedIn instanceof ItemEntity ? 3 : 5; + } else if (this.nibble > 0) { + LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerLevel) this.level)).withParameter(LootContextParams.ORIGIN, this.position()).withParameter(LootContextParams.TOOL, stack).withParameter(LootContextParams.THIS_ENTITY, (FishingHook) (Object) this).withRandom(this.random).withLuck((float) this.luck + playerentity.getLuck()); + LootTable loottable = this.level.getServer().getLootTables().get(BuiltInLootTables.FISHING); + List list = loottable.getRandomItems(lootcontext$builder.create(LootContextParamSets.FISHING)); + event = new ItemFishedEvent(list, this.onGround ? 2 : 1, (FishingHook) (Object) this); + MinecraftForge.EVENT_BUS.post(event); + if (event.isCanceled()) { + this.discard(); + return event.getRodDamage(); + } + CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayer) playerentity, stack, (FishingHook) (Object) this, list); + + for (ItemStack itemstack : list) { + ItemEntity itementity = new ItemEntity(this.level, this.getX(), this.getY(), this.getZ(), itemstack); + PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), ((EntityBridge) itementity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH); + playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1); + Bukkit.getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + return 0; + } + double d0 = playerentity.getX() - this.getX(); + double d1 = playerentity.getY() - this.getY(); + double d2 = playerentity.getZ() - this.getZ(); + double d3 = 0.1D; + itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); + this.level.addFreshEntity(itementity); + if (playerFishEvent.getExpToDrop() > 0) { + playerentity.level.addFreshEntity(new ExperienceOrb(playerentity.level, playerentity.getX(), playerentity.getY() + 0.5D, playerentity.getZ() + 0.5D, playerFishEvent.getExpToDrop())); + } + if (itemstack.is(ItemTags.FISHES)) { + playerentity.awardStat(Stats.FISH_CAUGHT, 1); + } + } + + i = 1; + } + + if (this.onGround) { + PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND); + Bukkit.getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + return 0; + } + i = 2; + } + + if (i == 0) { + PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) playerentity).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN); + Bukkit.getPluginManager().callEvent(playerFishEvent); + if (playerFishEvent.isCancelled()) { + return 0; + } + } + + this.discard(); + return event == null ? i : event.getRodDamage(); + } else { + return 0; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java new file mode 100644 index 00000000..3de1d8a2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java @@ -0,0 +1,50 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.LargeFireball; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import org.bukkit.Bukkit; +import org.bukkit.event.entity.ExplosionPrimeEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LargeFireball.class) +public abstract class LargeFireballMixin extends AbstractHurtingProjectileMixin { + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType p_i50163_1_, Level worldIn, CallbackInfo ci) { + this.isIncendiary = worldIn.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); + } + + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;DDDI)V", at = @At("RETURN")) + private void arclight$init(Level level, LivingEntity p_181152_, double p_181153_, double p_181154_, double p_181155_, int p_181156_, CallbackInfo ci) { + this.isIncendiary = level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); + } + + @Redirect(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;")) + private Explosion arclight$explodePrime(Level world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, boolean causesFire, Explosion.BlockInteraction modeIn) { + ExplosionPrimeEvent event = new ExplosionPrimeEvent((org.bukkit.entity.Explosive) this.getBukkitEntity()); + event.setRadius(explosionRadius); + event.setFire(causesFire); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + return this.level.explode((LargeFireball) (Object) this, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); + } else { + return null; + } + } + + @Inject(method = "readAdditionalSaveData", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;getByte(Ljava/lang/String;)B")) + private void arclight$setYield(CompoundTag compound, CallbackInfo ci) { + this.bukkitYield = compound.getInt("ExplosionPower"); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ProjectileMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ProjectileMixin.java new file mode 100644 index 00000000..4a1b3b99 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ProjectileMixin.java @@ -0,0 +1,54 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import org.bukkit.craftbukkit.v.entity.CraftEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.projectiles.ProjectileSource; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; + +@Mixin(Projectile.class) +public abstract class ProjectileMixin extends EntityMixin { + + // @formatter:off + @Shadow @Nullable public abstract Entity getOwner(); + @Shadow protected void onHit(HitResult result) { } + // @formatter:on + + @Inject(method = "setOwner", at = @At("RETURN")) + private void arclight$updateSource(Entity entityIn, CallbackInfo ci) { + if (entityIn != null) { + CraftEntity entity = ((EntityBridge) entityIn).bridge$getBukkitEntity(); + if (entity instanceof ProjectileSource) { + this.projectileSource = ((ProjectileSource) entity); + } + } + } + + private boolean hitCancelled = false; + + @Inject(method = "onHitBlock", cancellable = true, at = @At("HEAD")) + private void arclight$cancelBlockHit(BlockHitResult result, CallbackInfo ci) { + if (hitCancelled) { + ci.cancel(); + } + } + + protected void preOnHit(HitResult hitResult) { + org.bukkit.event.entity.ProjectileHitEvent event = CraftEventFactory.callProjectileHitEvent((Projectile) (Object) this, hitResult); + this.hitCancelled = event != null && event.isCancelled(); + if (hitResult.getType() == HitResult.Type.BLOCK || !this.hitCancelled) { + this.onHit(hitResult); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java new file mode 100644 index 00000000..1d4ce9bb --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java @@ -0,0 +1,58 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.core.Direction; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.ShulkerBullet; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import javax.annotation.Nullable; + +@Mixin(ShulkerBullet.class) +public abstract class ShulkerBulletMixin extends EntityMixin { + + // @formatter:off + @Shadow private Entity finalTarget; + @Shadow @Nullable private Direction currentMoveDirection; + @Shadow protected abstract void selectNextMoveDirection(@Nullable Direction.Axis p_184569_1_); + // @formatter:on + + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/Direction$Axis;)V", at = @At("RETURN")) + private void arclight$init(Level worldIn, LivingEntity ownerIn, Entity targetIn, Direction.Axis p_i46772_4_, CallbackInfo ci) { + this.projectileSource = ((LivingEntityBridge) ownerIn).bridge$getBukkitEntity(); + } + + @Inject(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$reason(EntityHitResult result, CallbackInfo ci) { + ((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + } + + @Inject(method = "hurt", cancellable = true, at = @At("HEAD")) + private void arclight$damageBullet(DamageSource source, float amount, CallbackInfoReturnable cir) { + if (CraftEventFactory.handleNonLivingEntityDamageEvent((ShulkerBullet) (Object) this, source, amount, false)) { + cir.setReturnValue(false); + } + } + + public Entity getTarget() { + return this.finalTarget; + } + + public void setTarget(final Entity e) { + this.finalTarget = e; + this.currentMoveDirection = Direction.UP; + this.selectNextMoveDirection(Direction.Axis.X); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java new file mode 100644 index 00000000..d5f61a8a --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java @@ -0,0 +1,51 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.projectile.SmallFireball; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityCombustByEntityEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(SmallFireball.class) +public abstract class SmallFireballMixin extends FireballMixin { + + @Inject(method = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;DDD)V", at = @At("RETURN")) + private void arclight$init(Level worldIn, LivingEntity shooter, double accelX, double accelY, double accelZ, CallbackInfo ci) { + if (this.getOwner() != null && this.getOwner() instanceof Mob) { + this.isIncendiary = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); + } + } + + @Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) + private void arclight$entityCombust(Entity entity, int seconds) { + if (this.isIncendiary) { + EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + ((EntityBridge) entity).bridge$setOnFire(event.getDuration(), false); + } + } + } + + @Inject(method = "onHitBlock", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private void arclight$burnBlock(BlockHitResult result, CallbackInfo ci, Entity entity, BlockPos pos) { + if (!this.isIncendiary || CraftEventFactory.callBlockIgniteEvent(this.level, pos, (SmallFireball) (Object) this).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SpectralArrowEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SpectralArrowMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SpectralArrowEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SpectralArrowMixin.java index 04d9e47f..e62dc534 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/SpectralArrowEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SpectralArrowMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; +package io.izzel.arclight.common.mixin.core.world.entity.projectile; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.projectile.SpectralArrowEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.SpectralArrow; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(SpectralArrowEntity.class) -public abstract class SpectralArrowEntityMixin extends AbstractArrowEntityMixin { +@Mixin(SpectralArrow.class) +public abstract class SpectralArrowMixin extends AbstractArrowMixin { - @Inject(method = "arrowHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doPostHurtEffects", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) private void arclight$hit(LivingEntity living, CallbackInfo ci) { ((LivingEntityBridge) living).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ARROW); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableItemProjectileMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableItemProjectileMixin.java new file mode 100644 index 00000000..ee4aa535 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableItemProjectileMixin.java @@ -0,0 +1,40 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.Util; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.world.entity.projectile.ThrowableItemProjectile; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(ThrowableItemProjectile.class) +public abstract class ThrowableItemProjectileMixin extends ThrowableProjectileMixin { + + // @formatter:off + @Shadow protected abstract Item getDefaultItem(); + @Shadow @Final private static EntityDataAccessor DATA_ITEM_STACK; + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void setItem(ItemStack stack) { + if (stack.getItem() != this.getDefaultItem() || stack.hasTag()) { + this.getEntityData().set(DATA_ITEM_STACK, Util.make(stack.copy(), (itemStack) -> { + if (!itemStack.isEmpty()) { + itemStack.setCount(1); + } + })); + } + + } + + public Item getDefaultItemPublic() { + return this.getDefaultItem(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableProjectileMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableProjectileMixin.java new file mode 100644 index 00000000..813f73d5 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrowableProjectileMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.ThrowableProjectile; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.HitResult; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ThrowableProjectile.class) +public abstract class ThrowableProjectileMixin extends ProjectileMixin { + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, LivingEntity livingEntityIn, Level worldIn, CallbackInfo ci) { + this.projectileSource = ((LivingEntityBridge) livingEntityIn).bridge$getBukkitEntity(); + } + + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ThrowableProjectile;onHit(Lnet/minecraft/world/phys/HitResult;)V")) + private void arclight$projectileHit(ThrowableProjectile entity, HitResult result) { + this.preOnHit(result); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EggEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EggEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java index b534f3ac..fd8771ed 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/projectile/EggEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.entity.projectile; +package io.izzel.arclight.common.mixin.core.world.entity.projectile; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.entity.projectile.EggEntity; -import net.minecraft.util.math.RayTraceResult; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.ThrownEgg; +import net.minecraft.world.phys.HitResult; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Ageable; @@ -16,28 +16,28 @@ import org.bukkit.event.player.PlayerEggThrowEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; -@Mixin(EggEntity.class) -public abstract class EggEntityMixin extends ThrowableEntityMixin { +@Mixin(ThrownEgg.class) +public abstract class ThrownEggMixin extends ThrowableProjectileMixin { /** * @author IzzelAliz * @reason */ @Overwrite - protected void onImpact(final RayTraceResult result) { - super.onImpact(result); - if (!this.world.isRemote) { - boolean hatching = this.rand.nextInt(8) == 0; + protected void onHit(final HitResult result) { + super.onHit(result); + if (!this.level.isClientSide) { + boolean hatching = this.random.nextInt(8) == 0; byte b0 = 1; - if (this.rand.nextInt(32) == 0) { + if (this.random.nextInt(32) == 0) { b0 = 4; } if (!hatching) { b0 = 0; } org.bukkit.entity.EntityType hatchingType = org.bukkit.entity.EntityType.CHICKEN; - Entity shooter = this.getShooter(); - if (shooter instanceof ServerPlayerEntity) { + Entity shooter = this.getOwner(); + if (shooter instanceof ServerPlayer) { PlayerEggThrowEvent event = new PlayerEggThrowEvent(((ServerPlayerEntityBridge) shooter).bridge$getBukkitEntity(), (Egg) this.getBukkitEntity(), hatching, b0, hatchingType); Bukkit.getPluginManager().callEvent(event); b0 = event.getNumHatches(); @@ -46,16 +46,16 @@ public abstract class EggEntityMixin extends ThrowableEntityMixin { } if (hatching) { for (int i = 0; i < b0; ++i) { - Entity entity = ((WorldBridge) this.world).bridge$getWorld().createEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, 0.0f), hatchingType.getEntityClass()); + Entity entity = ((WorldBridge) this.level).bridge$getWorld().createEntity(new Location(((WorldBridge) this.level).bridge$getWorld(), this.getX(), this.getY(), this.getZ(), this.yRot, 0.0f), hatchingType.getEntityClass()); if (((EntityBridge) entity).bridge$getBukkitEntity() instanceof Ageable) { ((Ageable) ((EntityBridge) entity).bridge$getBukkitEntity()).setBaby(); } - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG); - this.world.addEntity(entity); + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG); + this.level.addFreshEntity(entity); } } - this.world.setEntityState((EggEntity) (Object) this, (byte) 3); - this.remove(); + this.level.broadcastEntityEvent((ThrownEgg) (Object) this, (byte) 3); + this.discard(); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java new file mode 100644 index 00000000..68c14321 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.world.entity.projectile.ThrownEnderpearl; +import net.minecraft.world.phys.HitResult; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ThrownEnderpearl.class) +public abstract class ThrownEnderpearlMixin extends ThrowableProjectileMixin { + + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$spawnEndermite(HitResult result, CallbackInfo ci) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.ENDER_PEARL); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java new file mode 100644 index 00000000..8560e097 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java @@ -0,0 +1,35 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ExperienceOrb; +import net.minecraft.world.entity.projectile.ThrownExperienceBottle; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.alchemy.Potions; +import net.minecraft.world.phys.HitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.ExpBottleEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(ThrownExperienceBottle.class) +public abstract class ThrownExperienceBottleMixin extends ThrowableItemProjectileMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void onHit(HitResult result) { + super.onHit(result); + if (!this.level.isClientSide) { + int i = 3 + this.level.random.nextInt(5) + this.level.random.nextInt(5); + ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ThrownExperienceBottle) (Object) this, i); + i = event.getExperience(); + if (event.getShowEffect()) { + this.level.levelEvent(2002, this.blockPosition(), PotionUtils.getColor(Potions.WATER)); + } + ExperienceOrb.award((ServerLevel) this.level, this.position(), i); + this.discard(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java new file mode 100644 index 00000000..03bfea84 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java @@ -0,0 +1,133 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.entity.AreaEffectCloud; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.ThrownPotion; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.level.block.AbstractCandleBlock; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.CampfireBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.LingeringPotionSplashEvent; +import org.bukkit.event.entity.PotionSplashEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Mixin(ThrownPotion.class) +public abstract class ThrownPotionMixin extends ThrowableItemProjectileMixin { + + @Redirect(method = "onHit", at = @At(value = "INVOKE", remap = false, ordinal = 1, target = "Ljava/util/List;isEmpty()Z")) + private boolean arclight$callEvent(List list) { + return false; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + private void applySplash(List list, @Nullable Entity entity) { + AABB axisalignedbb = this.getBoundingBox().inflate(4.0, 2.0, 4.0); + List list2 = this.level.getEntitiesOfClass(LivingEntity.class, axisalignedbb); + Map affected = new HashMap<>(); + if (!list2.isEmpty()) { + for (LivingEntity entityliving : list2) { + if (entityliving.isAffectedByPotions()) { + double d0 = this.distanceToSqr(entityliving); + if (d0 >= 16.0) { + continue; + } + double d2 = 1.0 - Math.sqrt(d0) / 4.0; + if (entityliving == entity) { + d2 = 1.0; + } + affected.put(((LivingEntityBridge) entityliving).bridge$getBukkitEntity(), d2); + } + } + } + PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((ThrownPotion) (Object) this, affected); + if (!event.isCancelled() && list != null && !list.isEmpty()) { + for (org.bukkit.entity.LivingEntity victim : event.getAffectedEntities()) { + if (!(victim instanceof CraftLivingEntity)) { + continue; + } + LivingEntity entityliving2 = ((CraftLivingEntity) victim).getHandle(); + double d2 = event.getIntensity(victim); + for (MobEffectInstance mobeffect : list) { + MobEffect mobeffectlist = mobeffect.getEffect(); + if (!((WorldBridge) this.level).bridge$isPvpMode() && this.getOwner() instanceof ServerPlayer && entityliving2 instanceof ServerPlayer && entityliving2 != this.getOwner()) { + int i = MobEffect.getId(mobeffectlist); + if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18) { + continue; + } + if (i == 19) { + continue; + } + } + if (mobeffectlist.isInstantenous()) { + mobeffectlist.applyInstantenousEffect((ThrownPotion) (Object) this, this.getOwner(), entityliving2, mobeffect.getAmplifier(), d2); + } else { + int i = (int) (d2 * mobeffect.getDuration() + 0.5); + if (i <= 20) { + continue; + } + ((LivingEntityBridge) entityliving2).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.POTION_SPLASH); + entityliving2.addEffect(new MobEffectInstance(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible())); + } + } + } + } + } + + @Inject(method = "makeAreaOfEffectCloud", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$makeCloud(ItemStack p_190542_1_, Potion p_190542_2_, CallbackInfo ci, AreaEffectCloud entity) { + LingeringPotionSplashEvent event = CraftEventFactory.callLingeringPotionSplashEvent((ThrownPotion) (Object) this, entity); + if (event.isCancelled() || entity.isRemoved()) { + ci.cancel(); + entity.discard(); + } + } + + @Inject(method = "dowseFire", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + private void arclight$entityChangeBlock(BlockPos pos, CallbackInfo ci) { + if (CraftEventFactory.callEntityChangeBlockEvent((ThrownPotion) (Object) this, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "dowseFire", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(Lnet/minecraft/world/entity/player/Player;ILnet/minecraft/core/BlockPos;I)V")) + private void arclight$entityChangeBlock2(BlockPos pos, CallbackInfo ci, BlockState state) { + if (CraftEventFactory.callEntityChangeBlockEvent((ThrownPotion) (Object) this, pos, state.setValue(CampfireBlock.LIT, false)).isCancelled()) { + ci.cancel(); + } + } + + @Inject(method = "dowseFire", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/AbstractCandleBlock;extinguish(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)V")) + private void arclight$entityChangeBlock3(BlockPos pos, CallbackInfo ci, BlockState state) { + if (CraftEventFactory.callEntityChangeBlockEvent((ThrownPotion) (Object) this, pos, state.setValue(AbstractCandleBlock.LIT, false)).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java new file mode 100644 index 00000000..888d7ab0 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java @@ -0,0 +1,31 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.projectile.TridentEntityBridge; +import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.projectile.ThrownTrident; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import org.bukkit.event.weather.LightningStrikeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ThrownTrident.class) +public abstract class ThrownTridentMixin extends AbstractArrowMixin implements TridentEntityBridge { + + @Shadow public ItemStack tridentItem; + + @Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$lightning(Level world, Entity entityIn) { + ((ServerWorldBridge) this.level).bridge$strikeLightning((LightningBolt) entityIn, LightningStrikeEvent.Cause.TRIDENT); + return true; + } + + @Override + public void bridge$setThrownStack(ItemStack itemStack) { + this.tridentItem = itemStack; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java new file mode 100644 index 00000000..63069f73 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java @@ -0,0 +1,41 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.WitherSkull; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.EntityHitResult; +import org.bukkit.Bukkit; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.ExplosionPrimeEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WitherSkull.class) +public abstract class WitherSkullMixin extends AbstractHurtingProjectileMixin { + + @Inject(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V")) + private void arclight$heal(EntityHitResult result, CallbackInfo ci) { + ((LivingEntityBridge) this.getOwner()).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER); + } + + @Inject(method = "onHitEntity", require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$effect(EntityHitResult result, CallbackInfo ci) { + ((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); + } + + @Redirect(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Explosion$BlockInteraction;)Lnet/minecraft/world/level/Explosion;")) + private Explosion arclight$explode(Level world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, boolean causesFire, Explosion.BlockInteraction modeIn) { + ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), explosionRadius, causesFire); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { + return this.level.explode((WitherSkull) (Object) this, xIn, yIn, zIn, event.getRadius(), event.getFire(), modeIn); + } + return null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java new file mode 100644 index 00000000..439518d7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.raider; + +import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.raid.Raid; +import net.minecraft.world.entity.raid.Raider; +import net.minecraft.world.item.ItemStack; +import org.bukkit.event.entity.EntityPotionEffectEvent; +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; + +@Mixin(Raider.class) +public abstract class RaiderMixin extends PathfinderMobMixin { + + @Inject(method = "die", locals = LocalCapture.CAPTURE_FAILHARD, require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$raid(DamageSource cause, CallbackInfo ci, Entity entity, Raid raid, ItemStack itemStack, Player playerEntity) { + ((PlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/Raider_HoldGroundAttackGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/Raider_HoldGroundAttackGoalMixin.java new file mode 100644 index 00000000..b8b03c54 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/Raider_HoldGroundAttackGoalMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.raider; + +import io.izzel.arclight.common.bridge.entity.MobEntityBridge; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.raid.Raider; +import org.bukkit.event.entity.EntityTargetEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(Raider.HoldGroundAttackGoal.class) +public abstract class Raider_HoldGroundAttackGoalMixin { + + @Redirect(method = "start", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raider;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$reason(Raider abstractRaiderEntity, LivingEntity entitylivingbaseIn) { + ((MobEntityBridge) abstractRaiderEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); + abstractRaiderEntity.setTarget(entitylivingbaseIn); + } + + @Redirect(method = "stop", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raider;setTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$reason2(Raider abstractRaiderEntity, LivingEntity entitylivingbaseIn) { + ((MobEntityBridge) abstractRaiderEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.FOLLOW_LEADER, true); + abstractRaiderEntity.setTarget(entitylivingbaseIn); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/ContainerMinecartEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartContainerMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/ContainerMinecartEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartContainerMixin.java index 096da497..eeff0c04 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/minecart/ContainerMinecartEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartContainerMixin.java @@ -1,13 +1,13 @@ -package io.izzel.arclight.common.mixin.core.entity.item.minecart; +package io.izzel.arclight.common.mixin.core.world.entity.vehicle; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.item.minecart.ContainerMinecartEntity; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; -import net.minecraft.world.World; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.vehicle.AbstractMinecartContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.level.Level; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; @@ -21,21 +21,21 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.ArrayList; import java.util.List; -@Mixin(ContainerMinecartEntity.class) -public abstract class ContainerMinecartEntityMixin extends AbstractMinecartEntityMixin implements IInventoryBridge, IInventory { +@Mixin(AbstractMinecartContainer.class) +public abstract class AbstractMinecartContainerMixin extends AbstractMinecartMixin implements IInventoryBridge, Container { - @Shadow private NonNullList minecartContainerItems; + @Shadow private NonNullList itemStacks; - @Inject(method = "(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, World world, CallbackInfo ci) { - this.minecartContainerItems = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, Level world, CallbackInfo ci) { + this.itemStacks = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY); maxStack = MAX_STACK; transaction = new ArrayList<>(); } - @Inject(method = "(Lnet/minecraft/entity/EntityType;DDDLnet/minecraft/world/World;)V", at = @At("RETURN")) - private void arclight$init(EntityType type, double x, double y, double z, World world, CallbackInfo ci) { - this.minecartContainerItems = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY); + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;DDDLnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, double x, double y, double z, Level world, CallbackInfo ci) { + this.itemStacks = NonNullList.withSize(getContainerSize(), ItemStack.EMPTY); maxStack = MAX_STACK; transaction = new ArrayList<>(); } @@ -45,7 +45,7 @@ public abstract class ContainerMinecartEntityMixin extends AbstractMinecartEntit @Override public List getContents() { - return this.minecartContainerItems; + return this.itemStacks; } @Override @@ -76,7 +76,7 @@ public abstract class ContainerMinecartEntityMixin extends AbstractMinecartEntit } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (maxStack == 0) maxStack = 64; return maxStack; } @@ -92,12 +92,12 @@ public abstract class ContainerMinecartEntityMixin extends AbstractMinecartEntit } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartMixin.java new file mode 100644 index 00000000..8f4707a1 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/AbstractMinecartMixin.java @@ -0,0 +1,317 @@ +package io.izzel.arclight.common.mixin.core.world.entity.vehicle; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.tags.BlockTags; +import net.minecraft.util.Mth; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySelector; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MoverType; +import net.minecraft.world.entity.animal.IronGolem; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.vehicle.AbstractMinecart; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseRailBlock; +import net.minecraft.world.level.block.PoweredRailBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.vehicle.VehicleDamageEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.event.vehicle.VehicleMoveEvent; +import org.bukkit.event.vehicle.VehicleUpdateEvent; +import org.bukkit.util.Vector; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(AbstractMinecart.class) +public abstract class AbstractMinecartMixin extends EntityMixin { + + // @formatter:off + @Shadow public abstract void setHurtDir(int rollingDirection); + @Shadow public abstract int getHurtDir(); + @Shadow public abstract void setHurtTime(int rollingAmplitude); + @Shadow public abstract void setDamage(float damage); + @Shadow public abstract float getDamage(); + @Shadow public abstract void destroy(DamageSource source); + @Shadow public abstract int getHurtTime(); + @Shadow private int lSteps; + @Shadow private double lx; + @Shadow private double ly; + @Shadow private double lz; + @Shadow private double lyr; + @Shadow private double lxr; + @Shadow protected abstract void moveAlongTrack(BlockPos pos, BlockState state); + @Shadow public abstract void activateMinecart(int x, int y, int z, boolean receivingPower); + @Shadow private boolean flipped; + @Shadow public abstract AbstractMinecart.Type getMinecartType(); + @Shadow(remap = false) public abstract boolean canUseRail(); + // @formatter:on + + public boolean slowWhenEmpty = true; + private double derailedX = 0.5; + private double derailedY = 0.5; + private double derailedZ = 0.5; + private double flyingX = 0.95; + private double flyingY = 0.95; + private double flyingZ = 0.95; + public double maxSpeed = 0.4D; + + @Inject(method = "(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/level/Level;)V", at = @At("RETURN")) + private void arclight$init(EntityType type, Level worldIn, CallbackInfo ci) { + slowWhenEmpty = true; + derailedX = 0.5; + derailedY = 0.5; + derailedZ = 0.5; + flyingX = 0.95; + flyingY = 0.95; + flyingZ = 0.95; + maxSpeed = 0.4D; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public boolean hurt(DamageSource source, float amount) { + if (this.level.isClientSide || this.isRemoved()) { + return true; + } + if (this.isInvulnerableTo(source)) { + return false; + } + Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + org.bukkit.entity.Entity passenger = (source.getEntity() == null) ? null : ((EntityBridge) source.getEntity()).bridge$getBukkitEntity(); + VehicleDamageEvent event = new VehicleDamageEvent(vehicle, passenger, amount); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return false; + } + amount = (float) event.getDamage(); + this.setHurtDir(-this.getHurtDir()); + this.setHurtTime(10); + this.markHurt(); + this.setDamage(this.getDamage() + amount * 10.0f); + boolean flag = source.getEntity() instanceof Player && ((Player) source.getEntity()).getAbilities().instabuild; + if (flag || this.getDamage() > 40.0f) { + VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, passenger); + Bukkit.getPluginManager().callEvent(destroyEvent); + if (destroyEvent.isCancelled()) { + this.setDamage(40.0f); + return true; + } + this.ejectPassengers(); + if (flag && !this.hasCustomName()) { + this.discard(); + } else { + this.destroy(source); + } + } + return true; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void tick() { + double prevX = this.getX(); + double prevY = this.getY(); + double prevZ = this.getZ(); + float prevYaw = this.yRot; + float prevPitch = this.xRot; + if (this.getHurtTime() > 0) { + this.setHurtTime(this.getHurtTime() - 1); + } + if (this.getDamage() > 0.0f) { + this.setDamage(this.getDamage() - 1.0f); + } + if (this.getY() < -64.0) { + this.outOfWorld(); + } + if (this.level.isClientSide) { + if (this.lSteps > 0) { + double d0 = this.getX() + (this.lx - this.getX()) / this.lSteps; + double d2 = this.getY() + (this.ly - this.getY()) / this.lSteps; + double d3 = this.getZ() + (this.lz - this.getZ()) / this.lSteps; + double d4 = Mth.wrapDegrees(this.lyr - this.yRot); + this.yRot += (float) (d4 / this.lSteps); + this.xRot += (float) ((this.lxr - this.xRot) / this.lSteps); + --this.lSteps; + this.setPos(d0, d2, d3); + this.setRot(this.yRot, this.xRot); + } else { + this.setPos(this.getX(), this.getY(), this.getZ()); + this.setRot(this.yRot, this.xRot); + } + } else { + /* + this.prevPosX = this.getPosX(); + this.prevPosY = this.getPosY(); + this.prevPosZ = this.getPosZ(); + */ + if (!this.isNoGravity()) { + this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.04, 0.0)); + } + int i = Mth.floor(this.getX()); + int j = Mth.floor(this.getY()); + int k = Mth.floor(this.getZ()); + if (this.level.getBlockState(new BlockPos(i, j - 1, k)).is(BlockTags.RAILS)) { + --j; + } + BlockPos blockposition = new BlockPos(i, j, k); + BlockState blockstate = this.level.getBlockState(blockposition); + if (this.canUseRail() && BaseRailBlock.isRail(blockstate)) { + this.moveAlongTrack(blockposition, blockstate); + if (blockstate.getBlock() instanceof PoweredRailBlock && ((PoweredRailBlock) blockstate.getBlock()).isActivatorRail()) { + this.activateMinecart(i, j, k, blockstate.getValue(PoweredRailBlock.POWERED)); + } + } else { + this.comeOffTrack(); + } + this.checkInsideBlocks(); + this.xRot = 0.0f; + double d5 = this.xo - this.getX(); + double d6 = this.zo - this.getZ(); + if (d5 * d5 + d6 * d6 > 0.001) { + this.yRot = (float) (Mth.atan2(d6, d5) * 180.0 / 3.141592653589793); + if (this.flipped) { + this.yRot += 180.0f; + } + } + double d7 = Mth.wrapDegrees(this.yRot - this.yRotO); + if (d7 < -170.0 || d7 >= 170.0) { + this.yRot += 180.0f; + this.flipped = !this.flipped; + } + this.setRot(this.yRot, this.xRot); + org.bukkit.World bworld = ((WorldBridge) this.level).bridge$getWorld(); + Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); + Location to = new Location(bworld, this.getX(), this.getY(), this.getZ(), this.yRot, this.xRot); + Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle)); + if (!from.equals(to)) { + Bukkit.getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to)); + } + if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01) { + List list = this.level.getEntities((AbstractMinecart) (Object) this, this.getBoundingBox().inflate(0.20000000298023224, 0.0, 0.20000000298023224), EntitySelector.pushableBy((AbstractMinecart) (Object) this)); + if (!list.isEmpty()) { + for (Entity entity : list) { + if (!(entity instanceof Player) && !(entity instanceof IronGolem) && !(entity instanceof AbstractMinecart) && !this.isVehicle() && !entity.isPassenger()) { + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity()); + Bukkit.getPluginManager().callEvent(collisionEvent); + if (!collisionEvent.isCancelled()) { + entity.startRiding((AbstractMinecart) (Object) this); + } + } else { + if (!isPassengerOfSameVehicle(entity)) { + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity()); + Bukkit.getPluginManager().callEvent(collisionEvent); + if (collisionEvent.isCancelled()) { + continue; + } + } + entity.push((AbstractMinecart) (Object) this); + } + } + } + } else { + for (Entity entity2 : this.level.getEntities((AbstractMinecart) (Object) this, this.getBoundingBox().inflate(0.20000000298023224, 0.0, 0.20000000298023224))) { + if (!this.hasPassenger(entity2) && entity2.isPushable() && entity2 instanceof AbstractMinecart) { + VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity2).bridge$getBukkitEntity()); + Bukkit.getPluginManager().callEvent(collisionEvent2); + if (collisionEvent2.isCancelled()) { + continue; + } + entity2.push((AbstractMinecart) (Object) this); + } + } + } + this.updateInWaterStateAndDoFluidPushing(); + if (this.isInLava()) { + this.lavaHurt(); + this.fallDistance *= 0.5F; + } + this.firstTick = false; + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected double getMaxSpeed() { + return maxSpeed; + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void comeOffTrack() { + final double d0 = this.getMaxSpeed(); + final Vec3 vec3d = this.getDeltaMovement(); + this.setDeltaMovement(Mth.clamp(vec3d.x, -d0, d0), vec3d.y, Mth.clamp(vec3d.z, -d0, d0)); + if (this.onGround) { + this.setDeltaMovement(new Vec3(this.getDeltaMovement().x * this.derailedX, this.getDeltaMovement().y * this.derailedY, this.getDeltaMovement().z * this.derailedZ)); + } + this.move(MoverType.SELF, this.getDeltaMovement()); + if (!this.onGround) { + this.setDeltaMovement(new Vec3(this.getDeltaMovement().x * this.flyingX, this.getDeltaMovement().y * this.flyingY, this.getDeltaMovement().z * this.flyingZ)); + } + } + + @Redirect(method = "applyNaturalSlowdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;isVehicle()Z")) + private boolean arclight$slowWhenEmpty(AbstractMinecart abstractMinecartEntity) { + return this.isVehicle() || !this.slowWhenEmpty; + } + + @Inject(method = "push", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;hasPassenger(Lnet/minecraft/world/entity/Entity;)Z")) + private void arclight$vehicleCollide(Entity entityIn, CallbackInfo ci) { + if (!this.hasPassenger(entityIn)) { + VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity()); + Bukkit.getPluginManager().callEvent(collisionEvent); + if (collisionEvent.isCancelled()) { + ci.cancel(); + } + } + } + + public Vector getFlyingVelocityMod() { + return new Vector(flyingX, flyingY, flyingZ); + } + + public void setFlyingVelocityMod(Vector flying) { + flyingX = flying.getX(); + flyingY = flying.getY(); + flyingZ = flying.getZ(); + } + + public Vector getDerailedVelocityMod() { + return new Vector(derailedX, derailedY, derailedZ); + } + + public void setDerailedVelocityMod(Vector derailed) { + derailedX = derailed.getX(); + derailedY = derailed.getY(); + derailedZ = derailed.getZ(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/BoatEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/BoatMixin.java similarity index 62% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/BoatEntityMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/BoatMixin.java index a6a31b5c..72721a21 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/item/BoatEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/BoatMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.entity.item; +package io.izzel.arclight.common.mixin.core.world.entity.vehicle; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import io.izzel.arclight.common.mixin.core.entity.EntityMixin; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.BoatEntity; -import net.minecraft.util.DamageSource; +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.vehicle.Boat; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Vehicle; @@ -22,12 +22,12 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(BoatEntity.class) -public abstract class BoatEntityMixin extends EntityMixin { +@Mixin(Boat.class) +public abstract class BoatMixin extends EntityMixin { // @formatter:off - @Shadow public abstract float getDamageTaken(); - @Shadow public abstract void setDamageTaken(float damageTaken); + @Shadow public abstract float getDamage(); + @Shadow public abstract void setDamage(float damageTaken); // @formatter:on public double maxSpeed = 0.4D; @@ -36,10 +36,10 @@ public abstract class BoatEntityMixin extends EntityMixin { public boolean landBoats = false; private Location lastLocation; - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/BoatEntity;setForwardDirection(I)V")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/Boat;setHurtDir(I)V")) private void arclight$damageVehicle(DamageSource source, float amount, CallbackInfoReturnable cir) { Vehicle vehicle = (Vehicle) this.getBukkitEntity(); - org.bukkit.entity.Entity attacker = (source.getTrueSource() == null) ? null : ((EntityBridge) source.getTrueSource()).bridge$getBukkitEntity(); + org.bukkit.entity.Entity attacker = (source.getEntity() == null) ? null : ((EntityBridge) source.getEntity()).bridge$getBukkitEntity(); VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, amount); Bukkit.getPluginManager().callEvent(event); @@ -49,25 +49,25 @@ public abstract class BoatEntityMixin extends EntityMixin { } } - @Inject(method = "attackEntityFrom", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/entity/item/BoatEntity;getDamageTaken()F")) + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/vehicle/Boat;getDamage()F")) private void arclight$destroyVehicle(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (this.getDamageTaken() > 40.0F) { + if (this.getDamage() > 40.0F) { Vehicle vehicle = (Vehicle) this.getBukkitEntity(); - org.bukkit.entity.Entity attacker = (source.getTrueSource() == null) ? null : ((EntityBridge) source.getTrueSource()).bridge$getBukkitEntity(); + org.bukkit.entity.Entity attacker = (source.getEntity() == null) ? null : ((EntityBridge) source.getEntity()).bridge$getBukkitEntity(); VehicleDestroyEvent event = new VehicleDestroyEvent(vehicle, attacker); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - this.setDamageTaken(40F); + this.setDamage(40F); cir.setReturnValue(true); } } } - @Inject(method = "applyEntityCollision", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;applyEntityCollision(Lnet/minecraft/entity/Entity;)V")) + @Inject(method = "push", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;push(Lnet/minecraft/world/entity/Entity;)V")) private void arclight$collideVehicle(Entity entityIn, CallbackInfo ci) { - if (isRidingSameEntity(entityIn)) { + if (isPassengerOfSameVehicle(entityIn)) { VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), ((EntityBridge) entityIn).bridge$getBukkitEntity()); Bukkit.getPluginManager().callEvent(event); @@ -77,10 +77,10 @@ public abstract class BoatEntityMixin extends EntityMixin { } } - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/item/BoatEntity;updateRocking()V")) + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/Boat;tickBubbleColumn()V")) private void arclight$updateVehicle(CallbackInfo ci) { - final org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld(); - final Location to = new Location(bworld, this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, this.rotationPitch); + final org.bukkit.World bworld = ((WorldBridge) this.level).bridge$getWorld(); + final Location to = new Location(bworld, this.getX(), this.getY(), this.getZ(), this.yRot, this.xRot); final Vehicle vehicle = (Vehicle) this.getBukkitEntity(); Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle)); if (this.lastLocation != null && !this.lastLocation.equals(to)) { @@ -90,9 +90,9 @@ public abstract class BoatEntityMixin extends EntityMixin { this.lastLocation = vehicle.getLocation(); } - @Redirect(method = "updateFallState", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/item/BoatEntity;removed:Z")) - private boolean arclight$breakVehicle(BoatEntity boatEntity) { - if (!boatEntity.removed) { + @Redirect(method = "checkFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/Boat;isRemoved()Z")) + private boolean arclight$breakVehicle(Boat boatEntity) { + if (!boatEntity.isRemoved()) { final Vehicle vehicle = (Vehicle) this.getBukkitEntity(); final VehicleDestroyEvent event = new VehicleDestroyEvent(vehicle, null); Bukkit.getPluginManager().callEvent(event); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java new file mode 100644 index 00000000..d37002b2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartCommandBlock_MinecartCommandBaseMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.vehicle; + +import io.izzel.arclight.common.bridge.command.ICommandSourceBridge; +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.world.entity.vehicle.MinecartCommandBlock; +import org.bukkit.command.CommandSender; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(MinecartCommandBlock.MinecartCommandBase.class) +public abstract class MinecartCommandBlock_MinecartCommandBaseMixin implements ICommandSourceBridge { + + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_210168_a"}, remap = false) + private MinecartCommandBlock outerThis; + + public CommandSender getBukkitSender(CommandSourceStack wrapper) { + return ((EntityBridge) outerThis).bridge$getBukkitEntity(); + } + + @Override + public CommandSender bridge$getBukkitSender(CommandSourceStack wrapper) { + return getBukkitSender(wrapper); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/WorldGenRegionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/WorldGenRegionMixin.java index a9ffb4b4..fc362ad6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/WorldGenRegionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/WorldGenRegionMixin.java @@ -1,12 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.gen; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.SectionPos; -import net.minecraft.world.gen.WorldGenRegion; -import net.minecraft.world.gen.feature.structure.Structure; -import net.minecraft.world.gen.feature.structure.StructureStart; -import net.minecraft.world.server.ServerWorld; import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Final; @@ -15,17 +9,23 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import java.util.stream.Stream; +import net.minecraft.core.SectionPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.structure.StructureStart; @Mixin(WorldGenRegion.class) public abstract class WorldGenRegionMixin implements WorldBridge { // @formatter:off - @Shadow public abstract boolean addEntity(Entity entityIn); - @Shadow @Final private ServerWorld world; + @Shadow public abstract boolean addFreshEntity(Entity entityIn); + @Shadow @Final private ServerLevel level; // @formatter:on public boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { - return this.addEntity(entity); + return this.addFreshEntity(entity); } @Override @@ -39,7 +39,7 @@ public abstract class WorldGenRegionMixin implements WorldBridge { @Override public CraftWorld bridge$getWorld() { - return ((WorldBridge) this.world).bridge$getWorld(); + return ((WorldBridge) this.level).bridge$getWorld(); } @Override @@ -52,7 +52,7 @@ public abstract class WorldGenRegionMixin implements WorldBridge { * @reason MC-199487 */ @Overwrite - public Stream> func_241827_a(SectionPos p_241827_1_, Structure p_241827_2_) { - return this.world.getStructureManager().getStructureManager((WorldGenRegion) (Object) this).func_235011_a_(p_241827_1_, p_241827_2_); + public Stream> startsForFeature(SectionPos p_241827_1_, StructureFeature p_241827_2_) { + return this.level.structureFeatureManager().forWorldGenRegion((WorldGenRegion) (Object) this).startsForFeature(p_241827_1_, p_241827_2_); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/StructureManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/StructureManagerMixin.java index 81d52c88..3b87e504 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/StructureManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/StructureManagerMixin.java @@ -1,19 +1,19 @@ package io.izzel.arclight.common.mixin.core.world.gen.feature.structure; import io.izzel.arclight.common.bridge.world.IWorldBridge; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.structure.StructureManager; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.StructureFeatureManager; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(StructureManager.class) +@Mixin(StructureFeatureManager.class) public class StructureManagerMixin { - @Shadow @Final private IWorld world; + @Shadow @Final private LevelAccessor level; - public World getWorld() { - return ((IWorldBridge) this.world).bridge$getMinecraftWorld(); + public Level getWorld() { + return ((IWorldBridge) this.level).bridge$getMinecraftWorld(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/SwampHutPieceMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/SwampHutPieceMixin.java index cd32ca2d..4ad8be2d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/SwampHutPieceMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/structure/SwampHutPieceMixin.java @@ -1,14 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.gen.feature.structure; import io.izzel.arclight.common.bridge.world.IWorldWriterBridge; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.MutableBoundingBox; -import net.minecraft.world.ISeedReader; -import net.minecraft.world.IServerWorld; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.feature.structure.StructureManager; -import net.minecraft.world.gen.feature.structure.SwampHutPiece; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -17,17 +9,25 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Random; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.SwamplandHutPiece; -@Mixin(SwampHutPiece.class) +@Mixin(SwamplandHutPiece.class) public class SwampHutPieceMixin { - @Inject(method = "func_230383_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ISeedReader;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$spawnReason1(ISeedReader worldIn, StructureManager p_230383_2_, ChunkGenerator p_230383_3_, Random p_230383_4_, MutableBoundingBox p_230383_5_, ChunkPos p_230383_6_, BlockPos p_230383_7_, CallbackInfoReturnable cir) { + @Inject(method = "postProcess", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$spawnReason1(WorldGenLevel worldIn, StructureFeatureManager p_230383_2_, ChunkGenerator p_230383_3_, Random p_230383_4_, BoundingBox p_230383_5_, ChunkPos p_230383_6_, BlockPos p_230383_7_, CallbackInfoReturnable cir) { ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.CHUNK_GEN); } - @Inject(method = "func_214821_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private void arclight$spawnReason2(IServerWorld worldIn, MutableBoundingBox p_214821_2_, CallbackInfo ci) { + @Inject(method = "spawnCat", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ServerLevelAccessor;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private void arclight$spawnReason2(ServerLevelAccessor worldIn, BoundingBox p_214821_2_, CallbackInfo ci) { ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.CHUNK_GEN); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/template/TemplateManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/template/TemplateManagerMixin.java index 738a8263..e7107653 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/template/TemplateManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/gen/feature/template/TemplateManagerMixin.java @@ -1,11 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.gen.feature.template; import com.mojang.datafixers.DataFixer; -import net.minecraft.resources.IResourceManager; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.gen.feature.template.Template; -import net.minecraft.world.gen.feature.template.TemplateManager; -import net.minecraft.world.storage.SaveFormat; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -16,14 +11,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Collections; import java.util.Map; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.storage.LevelStorageSource; -@Mixin(TemplateManager.class) +@Mixin(StructureManager.class) public class TemplateManagerMixin { - @Shadow @Final @Mutable private Map templates; + @Shadow @Final @Mutable private Map structureRepository; @Inject(method = "", at = @At("RETURN")) - private void arclight$init(IResourceManager p_i232119_1_, SaveFormat.LevelSave p_i232119_2_, DataFixer fixer, CallbackInfo ci) { - this.templates = Collections.synchronizedMap(this.templates); + private void arclight$init(ResourceManager p_i232119_1_, LevelStorageSource.LevelStorageAccess p_i232119_2_, DataFixer fixer, CallbackInfo ci) { + this.structureRepository = Collections.synchronizedMap(this.structureRepository); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/IMerchantMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MerchantMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/IMerchantMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MerchantMixin.java index a21af7bb..a4cf0f18 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/entity/merchant/IMerchantMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/MerchantMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.entity.merchant; +package io.izzel.arclight.common.mixin.core.world.item; import io.izzel.arclight.common.bridge.entity.merchant.IMerchantBridge; -import net.minecraft.entity.merchant.IMerchant; +import net.minecraft.world.item.trading.Merchant; import org.bukkit.craftbukkit.v.inventory.CraftMerchant; import org.spongepowered.asm.mixin.Mixin; -@Mixin(IMerchant.class) -public interface IMerchantMixin extends IMerchantBridge { +@Mixin(Merchant.class) +public interface MerchantMixin extends IMerchantBridge { default CraftMerchant getCraftMerchant() { return bridge$getCraftMerchant(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/DamageEnchantmentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/DamageEnchantmentMixin.java similarity index 60% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/DamageEnchantmentMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/DamageEnchantmentMixin.java index 92903287..dfb354b6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/enchantment/DamageEnchantmentMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/DamageEnchantmentMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.enchantment; +package io.izzel.arclight.common.mixin.core.world.item.enchantment; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.enchantment.DamageEnchantment; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.enchantment.DamageEnchantment; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -13,7 +13,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(DamageEnchantment.class) public class DamageEnchantmentMixin { - @Inject(method = "onEntityDamaged", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) + @Inject(method = "doPostAttack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) public void arclight$entityDamage(LivingEntity user, Entity target, int level, CallbackInfo ci) { ((LivingEntityBridge) target).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/FrostWalkerEnchantmentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/FrostWalkerEnchantmentMixin.java new file mode 100644 index 00000000..621633d5 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/item/enchantment/FrostWalkerEnchantmentMixin.java @@ -0,0 +1,48 @@ +package io.izzel.arclight.common.mixin.core.world.item.enchantment; + +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.enchantment.FrostWalkerEnchantment; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.phys.shapes.CollisionContext; +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 { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public static void onEntityMoved(LivingEntity living, Level worldIn, BlockPos pos, int level) { + if (living.isOnGround()) { + BlockState blockstate = Blocks.FROSTED_ICE.defaultBlockState(); + float f = (float) Math.min(16, 2 + level); + BlockPos.MutableBlockPos blockpos$mutable = new BlockPos.MutableBlockPos(); + + for (BlockPos blockpos : BlockPos.betweenClosed(pos.offset((double) (-f), -1.0D, (double) (-f)), pos.offset((double) f, -1.0D, (double) f))) { + if (blockpos.closerThan(living.position(), (double) f)) { + blockpos$mutable.set(blockpos.getX(), blockpos.getY() + 1, blockpos.getZ()); + BlockState blockstate1 = worldIn.getBlockState(blockpos$mutable); + if (blockstate1.isAir()) { + BlockState blockstate2 = worldIn.getBlockState(blockpos); + boolean isFull = blockstate2.getBlock() == Blocks.WATER && blockstate2.getValue(LiquidBlock.LEVEL) == 0; //TODO: Forge, modded waters? + if (blockstate2.getMaterial() == Material.WATER && isFull && blockstate.canSurvive(worldIn, blockpos) && worldIn.isUnobstructed(blockstate, blockpos, CollisionContext.empty()) && !net.minecraftforge.event.ForgeEventFactory.onBlockPlace(living, net.minecraftforge.common.util.BlockSnapshot.create(worldIn.dimension(), worldIn, blockpos), net.minecraft.core.Direction.UP)) { + if (CraftEventFactory.handleBlockFormEvent(worldIn, blockpos, blockstate, living)) { + worldIn.getBlockTicks().scheduleTick(blockpos, Blocks.FROSTED_ICE, Mth.nextInt(living.getRandom(), 60, 120)); + } + } + } + } + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooBlockMixin.java new file mode 100644 index 00000000..77477feb --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooBlockMixin.java @@ -0,0 +1,75 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BambooBlock; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BambooLeaves; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.block.state.properties.Property; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Random; + +@Mixin(BambooBlock.class) +public abstract class BambooBlockMixin extends BlockMixin { + + @Shadow @Final public static EnumProperty LEAVES; + @Shadow @Final public static IntegerProperty AGE; + @Shadow @Final public static IntegerProperty STAGE; + + @Redirect(method = "performBonemeal", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getValue(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;")) + private > T arclight$skipIfCancel(BlockState state, Property property) { + if (!state.is(Blocks.BAMBOO)) { + return (T) Integer.valueOf(1); + } else { + return state.getValue(property); + } + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + protected void growBamboo(BlockState blockStateIn, Level worldIn, BlockPos posIn, Random rand, int height) { + BlockState blockstate = worldIn.getBlockState(posIn.below()); + BlockPos blockpos = posIn.below(2); + BlockState blockstate1 = worldIn.getBlockState(blockpos); + BambooLeaves bambooleaves = BambooLeaves.NONE; + + boolean update = false; + + if (height >= 1) { + if (blockstate.is(Blocks.BAMBOO) && blockstate.getValue(LEAVES) != BambooLeaves.NONE) { + if (blockstate.is(Blocks.BAMBOO) && blockstate.getValue(LEAVES) != BambooLeaves.NONE) { + bambooleaves = BambooLeaves.LARGE; + if (blockstate1.is(Blocks.BAMBOO)) { + update = true; + } + } + } else { + bambooleaves = BambooLeaves.SMALL; + } + } + + int newAge = blockStateIn.getValue(AGE) != 1 && !blockstate1.is(Blocks.BAMBOO) ? 0 : 1; + int newState = (height < 11 || !(rand.nextFloat() < 0.25F)) && height != 15 ? 0 : 1; + + if (CraftEventFactory.handleBlockSpreadEvent(worldIn, posIn, posIn.above(), + this.defaultBlockState().setValue(AGE, newAge).setValue(LEAVES, bambooleaves).setValue(STAGE, newState), 3)) { + if (update) { + worldIn.setBlock(posIn.below(), blockstate.setValue(LEAVES, BambooLeaves.SMALL), 3); + worldIn.setBlock(blockpos, blockstate1.setValue(LEAVES, BambooLeaves.NONE), 3); + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooSaplingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooSaplingBlockMixin.java new file mode 100644 index 00000000..e9ce0fdc --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BambooSaplingBlockMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BambooSaplingBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BambooSaplingBlock.class) +public class BambooSaplingBlockMixin { + + @Redirect(method = "growBamboo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockSpread(Level world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockSpreadEvent(world, pos.below(), pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BaseFireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BaseFireBlockMixin.java new file mode 100644 index 00000000..a6fdb3b7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BaseFireBlockMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseFireBlock; +import net.minecraft.world.level.block.Blocks; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BaseFireBlock.class) +public class BaseFireBlockMixin { + + @Redirect(method = "onPlace", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public boolean arclight$extinguish2(Level world, BlockPos pos, boolean isMoving) { + if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { + world.removeBlock(pos, isMoving); + } + return false; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BasePressurePlateBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BasePressurePlateBlockMixin.java new file mode 100644 index 00000000..34caeffa --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BasePressurePlateBlockMixin.java @@ -0,0 +1,38 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BasePressurePlateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BasePressurePlateBlock.class) +public abstract class BasePressurePlateBlockMixin { + + // @formatter:off + @Shadow protected abstract int getSignalStrength(Level worldIn, BlockPos pos); + @Shadow @Final protected static AABB TOUCH_AABB; + // @formatter:on + + @Redirect(method = "checkPressed", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/BasePressurePlateBlock;getSignalStrength(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)I")) + public int arclight$blockRedstone(BasePressurePlateBlock abstractPressurePlateBlock, Level worldIn, BlockPos pos, Level world, BlockPos blockPos, BlockState state, int oldRedstoneStrength) { + int newStrength = this.getSignalStrength(worldIn, pos); + boolean flag = oldRedstoneStrength > 0; + boolean flag1 = newStrength > 0; + + if (flag != flag1) { + BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(worldIn, blockPos), oldRedstoneStrength, newStrength); + Bukkit.getPluginManager().callEvent(event); + newStrength = event.getNewCurrent(); + } + return newStrength; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BedBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BedBlockMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BedBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BedBlockMixin.java index ef3f0360..bbed1665 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BedBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BedBlockMixin.java @@ -1,6 +1,6 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BedBlock; +import net.minecraft.world.level.block.BedBlock; import org.spongepowered.asm.mixin.Mixin; // todo 重新检查爆炸和 BedEvent 实现 diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BeehiveBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BeehiveBlockMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BeehiveBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BeehiveBlockMixin.java index cd7b72cc..bcdc16c6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/BeehiveBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BeehiveBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; -import net.minecraft.block.BeehiveBlock; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.BeeEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Bee; +import net.minecraft.world.level.block.BeehiveBlock; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,9 +12,9 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(BeehiveBlock.class) public class BeehiveBlockMixin { - @Redirect(method = "angerNearbyBees", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/BeeEntity;setAttackTarget(Lnet/minecraft/entity/LivingEntity;)V")) - private void arclight$targetReason(BeeEntity beeEntity, LivingEntity livingEntity) { + @Redirect(method = "angerNearbyBees", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Bee;setAttackTarget(Lnet/minecraft/world/entity/LivingEntity;)V")) + private void arclight$targetReason(Bee beeEntity, LivingEntity livingEntity) { ((MobEntityBridge) beeEntity).bridge$pushGoalTargetReason(EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); - beeEntity.setAttackTarget(livingEntity); + beeEntity.setTarget(livingEntity); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BlockMixin.java new file mode 100644 index 00000000..50e9e94c --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BlockMixin.java @@ -0,0 +1,86 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.block.BlockBridge; +import io.izzel.arclight.common.mixin.core.world.level.block.state.BlockBehaviourMixin; +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.extensions.IForgeBlock; +import org.bukkit.craftbukkit.v.CraftWorld; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.block.BlockBreakEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; +import java.util.List; + +@Mixin(Block.class) +public abstract class BlockMixin extends BlockBehaviourMixin implements BlockBridge { + + // @formatter:off + @Shadow public abstract BlockState defaultBlockState(); + @Shadow @Nullable public BlockState getStateForPlacement(BlockPlaceContext context) { return null; } + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public static void popResource(Level worldIn, BlockPos pos, ItemStack stack) { + if (!worldIn.isClientSide && !stack.isEmpty() && worldIn.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && !worldIn.restoringBlockSnapshots) { + float f = 0.5F; + double d0 = (double) (worldIn.random.nextFloat() * 0.5F) + 0.25D; + double d1 = (double) (worldIn.random.nextFloat() * 0.5F) + 0.25D; + double d2 = (double) (worldIn.random.nextFloat() * 0.5F) + 0.25D; + ItemEntity itemEntity = new ItemEntity(worldIn, (double) pos.getX() + d0, (double) pos.getY() + d1, (double) pos.getZ() + d2, stack); + itemEntity.setDefaultPickUpDelay(); + List blockDrops = ArclightCaptures.getBlockDrops(); + if (blockDrops == null) { + worldIn.addFreshEntity(itemEntity); + } else { + blockDrops.add(itemEntity); + } + } + } + + public int getExpDrop(BlockState blockState, ServerLevel world, BlockPos blockPos, ItemStack itemStack) { + int silkTouch = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, itemStack); + int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, itemStack); + return ((IForgeBlock) this).getExpDrop(blockState, world, blockPos, fortune, silkTouch); + } + + @Override + public int bridge$getExpDrop(BlockState blockState, ServerLevel world, BlockPos blockPos, ItemStack itemStack) { + return getExpDrop(blockState, world, blockPos, itemStack); + } + + @Inject(method = "playerDestroy", at = @At("RETURN")) + private void arclight$handleBlockDrops(Level worldIn, Player player, BlockPos pos, BlockState blockState, BlockEntity te, ItemStack stack, CallbackInfo ci) { + List blockDrops = ArclightCaptures.getBlockDrops(); + org.bukkit.block.BlockState state = ArclightCaptures.getBlockBreakPlayerState(); + BlockBreakEvent breakEvent = ArclightCaptures.resetBlockBreakPlayer(); + if (player instanceof ServerPlayer && blockDrops != null && (breakEvent == null || breakEvent.isDropItems())) { + CraftBlock craftBlock = CraftBlock.at(((CraftWorld) state.getWorld()).getHandle(), pos); + CraftEventFactory.handleBlockDropItemEvent(craftBlock, state, ((ServerPlayer) player), blockDrops); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BushBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BushBlockMixin.java new file mode 100644 index 00000000..5d6e5569 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/BushBlockMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.BushBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BushBlock.class) +public abstract class BushBlockMixin extends BlockMixin { + + @Redirect(method = "updateShape", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;defaultBlockState()Lnet/minecraft/world/level/block/state/BlockState;")) + public BlockState arclight$blockFade(Block block, BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { + if (!CraftEventFactory.callBlockPhysicsEvent(worldIn, currentPos).isCancelled()) { + return block.defaultBlockState(); + } else { + return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractButtonBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ButtonBlockMixin.java similarity index 66% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractButtonBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ButtonBlockMixin.java index e7905fbd..9c274405 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/AbstractButtonBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ButtonBlockMixin.java @@ -1,16 +1,6 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.AbstractButtonBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.BooleanProperty; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -27,19 +17,29 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.List; import java.util.Random; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.ButtonBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.BlockHitResult; -@Mixin(AbstractButtonBlock.class) -public class AbstractButtonBlockMixin { +@Mixin(ButtonBlock.class) +public class ButtonBlockMixin { // @formatter:off @Shadow @Final public static BooleanProperty POWERED; // @formatter:on @Inject(method = "checkPressed", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/Property;)Ljava/lang/Comparable;")) - public void arclight$entityInteract(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getValue(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;")) + public void arclight$entityInteract(BlockState state, Level worldIn, BlockPos pos, CallbackInfo ci, List list, boolean flag) { - boolean flag1 = state.get(AbstractButtonBlock.POWERED); + boolean flag1 = state.getValue(ButtonBlock.POWERED); if (flag1 != flag && flag) { Block block = CraftBlock.at(worldIn, pos); boolean allowed = false; @@ -63,8 +63,8 @@ public class AbstractButtonBlockMixin { } @Inject(method = "checkPressed", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockRedstone3(BlockState state, World worldIn, BlockPos pos, CallbackInfo ci, + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockRedstone3(BlockState state, Level worldIn, BlockPos pos, CallbackInfo ci, List list, boolean flag, boolean flag1) { Block block = CraftBlock.at(worldIn, pos); int old = (flag1) ? 15 : 0; @@ -78,10 +78,10 @@ public class AbstractButtonBlockMixin { } } - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "HEAD")) - public void arclight$blockRedstone1(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - if (!state.get(POWERED)) { - boolean powered = state.get(POWERED); + @Inject(method = "use", cancellable = true, at = @At(value = "HEAD")) + public void arclight$blockRedstone1(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, CallbackInfoReturnable cir) { + if (!state.getValue(POWERED)) { + boolean powered = state.getValue(POWERED); Block block = CraftBlock.at(worldIn, pos); int old = (powered) ? 15 : 0; int current = (!powered) ? 15 : 0; @@ -95,8 +95,8 @@ public class AbstractButtonBlockMixin { } } - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$blockRedstone2(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$blockRedstone2(BlockState state, ServerLevel worldIn, BlockPos pos, Random rand, CallbackInfo ci) { Block block = CraftBlock.at(worldIn, pos); BlockRedstoneEvent event = new BlockRedstoneEvent(block, 15, 0); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CactusBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CactusBlockMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CactusBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CactusBlockMixin.java index 664c143e..2f5842b2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CactusBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CactusBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CactusBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; @@ -17,18 +17,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(CactusBlock.class) public class CactusBlockMixin { - @Inject(method = "onEntityCollision", at = @At("HEAD")) - private void arclight$cactusDamage1(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + @Inject(method = "entityInside", at = @At("HEAD")) + private void arclight$cactusDamage1(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { CraftEventFactory.blockDamage = CraftBlock.at(worldIn, pos); } - @Inject(method = "onEntityCollision", at = @At("RETURN")) - private void arclight$cactusDamage2(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + @Inject(method = "entityInside", at = @At("RETURN")) + private void arclight$cactusDamage2(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { CraftEventFactory.blockDamage = null; } - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private boolean arclight$blockGrow(ServerWorld serverWorld, BlockPos pos, BlockState state) { + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$blockGrow(ServerLevel serverWorld, BlockPos pos, BlockState state) { return CraftEventFactory.handleBlockGrowEvent(serverWorld, pos, state); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CakeBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CakeBlockMixin.java new file mode 100644 index 00000000..f214fcd7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CakeBlockMixin.java @@ -0,0 +1,28 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.food.FoodData; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.CakeBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(CakeBlock.class) +public class CakeBlockMixin { + + @Redirect(method = "eat", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/food/FoodData;eat(IF)V")) + private static void arclight$eatCake(FoodData foodStats, int foodLevelIn, float foodSaturationModifier, LevelAccessor worldIn, BlockPos pos, BlockState state, Player player) { + int old = foodStats.getFoodLevel(); + FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(player, old + foodLevelIn); + if (!event.isCancelled()) { + foodStats.eat(event.getFoodLevel() - old, foodSaturationModifier); + } + ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity().sendHealthUpdate(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CampfireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CampfireBlockMixin.java new file mode 100644 index 00000000..1f0a3dac --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CampfireBlockMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CampfireBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(CampfireBlock.class) +public class CampfireBlockMixin { + + @Inject(method = "onProjectileHit", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$onFire(Level worldIn, BlockState state, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { + if (CraftEventFactory.callBlockIgniteEvent(worldIn, hit.getBlockPos(), projectile).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CarvedPumpkinBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CarvedPumpkinBlockMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CarvedPumpkinBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CarvedPumpkinBlockMixin.java index 8e7c6c31..6d88bf0e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CarvedPumpkinBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CarvedPumpkinBlockMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CarvedPumpkinBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CarvedPumpkinBlock; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.util.Constants; import org.bukkit.craftbukkit.v.util.BlockStateListPopulator; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -22,25 +22,25 @@ public class CarvedPumpkinBlockMixin { private transient BlockStateListPopulator arclight$populator; private transient boolean arclight$success = false; - @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$storeUpdate1(World world, BlockPos pos, BlockState newState, int flags) { + @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$storeUpdate1(Level world, BlockPos pos, BlockState newState, int flags) { if (arclight$populator == null) { arclight$populator = new BlockStateListPopulator(world); } - return arclight$populator.setBlockState(pos, newState, flags); + return arclight$populator.setBlock(pos, newState, flags); } - @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playEvent(ILnet/minecraft/util/math/BlockPos;I)V")) - public void arclight$storeUpdate2(World world, int type, BlockPos pos, int data) { + @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(ILnet/minecraft/core/BlockPos;I)V")) + public void arclight$storeUpdate2(Level world, int type, BlockPos pos, int data) { // do nothing } - @Inject(method = "trySpawnGolem", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public void arclight$returnIfFail(World world, BlockPos blockPos, CallbackInfo ci) { + @Inject(method = "trySpawnGolem", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public void arclight$returnIfFail(Level world, BlockPos blockPos, CallbackInfo ci) { if (arclight$success) { if (arclight$populator != null) { for (BlockPos pos : arclight$populator.getBlocks()) { - world.playEvent(Constants.WorldEvents.BREAK_BLOCK_EFFECTS, pos, Block.getStateId(world.getBlockState(pos))); + world.levelEvent(Constants.WorldEvents.BREAK_BLOCK_EFFECTS, pos, Block.getId(world.getBlockState(pos))); } arclight$populator.updateList(); } @@ -51,15 +51,15 @@ public class CarvedPumpkinBlockMixin { arclight$success = false; } - @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public boolean arclight$spawnSnow(World world, Entity entityIn) { + @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public boolean arclight$spawnSnow(Level world, Entity entityIn) { ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BUILD_SNOWMAN); - return arclight$success = world.addEntity(entityIn); + return arclight$success = world.addFreshEntity(entityIn); } - @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public boolean arclight$spawnIron(World world, Entity entityIn) { + @Redirect(method = "trySpawnGolem", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public boolean arclight$spawnIron(Level world, Entity entityIn) { ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BUILD_IRONGOLEM); - return arclight$success = world.addEntity(entityIn); + return arclight$success = world.addFreshEntity(entityIn); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CauldronBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CauldronBlockMixin.java new file mode 100644 index 00000000..32792bc1 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CauldronBlockMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mod.server.block.CauldronHooks; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CauldronBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.event.block.CauldronLevelChangeEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(CauldronBlock.class) +public class CauldronBlockMixin { + + @Redirect(method = "receiveStalactiteDrip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$drip(Level level, BlockPos pos, BlockState state, BlockState old) { + return CauldronHooks.changeLevel(old, level, pos, state, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CaveVinesMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CaveVinesMixin.java new file mode 100644 index 00000000..e2d77b36 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CaveVinesMixin.java @@ -0,0 +1,62 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.core.BlockPos; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CaveVines; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.player.PlayerHarvestBlockEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +import java.util.Collections; + +@Mixin(CaveVines.class) +public interface CaveVinesMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + static InteractionResult use(BlockState state, Level level, BlockPos pos) { + if (state.getValue(CaveVines.BERRIES)) { + Entity entity = ArclightCaptures.getEntityChangeBlock(); + if (entity != null) { + if (CraftEventFactory.callEntityChangeBlockEvent(entity, pos, state.setValue(CaveVines.BERRIES, false)).isCancelled()) { + return InteractionResult.SUCCESS; + } + + if (entity instanceof Player) { + PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(level, pos, (Player) entity, Collections.singletonList(new ItemStack(Items.GLOW_BERRIES, 1))); + if (event.isCancelled()) { + return InteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block + } + for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) { + Block.popResource(level, pos, CraftItemStack.asNMSCopy(itemStack)); + } + } else { + Block.popResource(level, pos, new ItemStack(Items.GLOW_BERRIES, 1)); + } + } + Block.popResource(level, pos, new ItemStack(Items.GLOW_BERRIES, 1)); + float f = Mth.randomBetween(level.random, 0.8F, 1.2F); + level.playSound(null, pos, SoundEvents.CAVE_VINES_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, f); + level.setBlock(pos, state.setValue(CaveVines.BERRIES, Boolean.FALSE), 2); + return InteractionResult.sidedSuccess(level.isClientSide); + } else { + return InteractionResult.PASS; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChestBlock2Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChestBlock2Mixin.java new file mode 100644 index 00000000..03f7a85d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChestBlock2Mixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mod.server.block.ChestBlockDoubleInventoryHacks; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +import java.util.Optional; + +@Mixin(targets = "net/minecraft/world/level/block/ChestBlock$2") +public class ChestBlock2Mixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public Optional acceptDouble(final ChestBlockEntity p_225539_1_, final ChestBlockEntity p_225539_2_) { + final CompoundContainer iinventory = new CompoundContainer(p_225539_1_, p_225539_2_); + return Optional.ofNullable(ChestBlockDoubleInventoryHacks.create(p_225539_1_, p_225539_2_, iinventory)); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChorusFlowerBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChorusFlowerBlockMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChorusFlowerBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChorusFlowerBlockMixin.java index fcab5e0e..74f5590f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ChorusFlowerBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ChorusFlowerBlockMixin.java @@ -1,16 +1,16 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.ChorusFlowerBlock; -import net.minecraft.block.ChorusPlantBlock; -import net.minecraft.state.IntegerProperty; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReader; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChorusFlowerBlock; +import net.minecraft.world.level.block.ChorusPlantBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -25,10 +25,10 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin { // @formatter:off @Shadow @Final public static IntegerProperty AGE; - @Shadow @Final private ChorusPlantBlock plantBlock; - @Shadow private static boolean areAllNeighborsEmpty(IWorldReader worldIn, BlockPos pos, @Nullable Direction excludingSide) { return false; } - @Shadow protected abstract void placeGrownFlower(World worldIn, BlockPos pos, int age); - @Shadow protected abstract void placeDeadFlower(World worldIn, BlockPos pos); + @Shadow @Final private ChorusPlantBlock plant; + @Shadow private static boolean allNeighborsEmpty(LevelReader worldIn, BlockPos pos, @Nullable Direction excludingSide) { return false; } + @Shadow protected abstract void placeGrownFlower(Level worldIn, BlockPos pos, int age); + @Shadow protected abstract void placeDeadFlower(Level worldIn, BlockPos pos); // @formatter:on /** @@ -36,23 +36,23 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin { * @reason */ @Overwrite - public void randomTick(BlockState state, ServerWorld worldIn, BlockPos pos, Random random) { - BlockPos blockpos = pos.up(); - if (worldIn.isAirBlock(blockpos) && blockpos.getY() < 256) { - int i = state.get(AGE); + public void randomTick(BlockState state, ServerLevel worldIn, BlockPos pos, Random random) { + BlockPos blockpos = pos.above(); + if (worldIn.isEmptyBlock(blockpos) && blockpos.getY() < 256) { + int i = state.getValue(AGE); if (i < 5 && net.minecraftforge.common.ForgeHooks.onCropsGrowPre(worldIn, blockpos, state, true)) { boolean flag = false; boolean flag1 = false; - BlockState blockstate = worldIn.getBlockState(pos.down()); + BlockState blockstate = worldIn.getBlockState(pos.below()); Block block = blockstate.getBlock(); if (block == Blocks.END_STONE) { flag = true; - } else if (block == this.plantBlock) { + } else if (block == this.plant) { int j = 1; for (int k = 0; k < 4; ++k) { - Block block1 = worldIn.getBlockState(pos.down(j + 1)).getBlock(); - if (block1 != this.plantBlock) { + Block block1 = worldIn.getBlockState(pos.below(j + 1)).getBlock(); + if (block1 != this.plant) { if (block1 == Blocks.END_STONE) { flag1 = true; } @@ -65,13 +65,13 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin { if (j < 2 || j <= random.nextInt(flag1 ? 5 : 4)) { flag = true; } - } else if (blockstate.isAir(worldIn, pos.down())) { + } else if (blockstate.isAir()) { flag = true; } - if (flag && areAllNeighborsEmpty(worldIn, blockpos, (Direction) null) && worldIn.isAirBlock(pos.up(2))) { - if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, this.getDefaultState().with(ChorusFlowerBlock.AGE, i), 2)) { - worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2); + if (flag && allNeighborsEmpty(worldIn, blockpos, (Direction) null) && worldIn.isEmptyBlock(pos.above(2))) { + if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, this.defaultBlockState().setValue(ChorusFlowerBlock.AGE, i), 2)) { + worldIn.setBlock(pos, this.plant.getStateForPlacement(worldIn, pos), 2); this.placeGrownFlower(worldIn, blockpos, i); } } else if (i < 4) { @@ -83,10 +83,10 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin { boolean flag2 = false; for (int i1 = 0; i1 < l; ++i1) { - Direction direction = Direction.Plane.HORIZONTAL.random(random); - BlockPos blockpos1 = pos.offset(direction); - if (worldIn.isAirBlock(blockpos1) && worldIn.isAirBlock(blockpos1.down()) && areAllNeighborsEmpty(worldIn, blockpos1, direction.getOpposite())) { - if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, this.getDefaultState().with(ChorusFlowerBlock.AGE, i + 1), 2)) { + Direction direction = Direction.Plane.HORIZONTAL.getRandomDirection(random); + BlockPos blockpos1 = pos.relative(direction); + if (worldIn.isEmptyBlock(blockpos1) && worldIn.isEmptyBlock(blockpos1.below()) && allNeighborsEmpty(worldIn, blockpos1, direction.getOpposite())) { + if (CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, this.defaultBlockState().setValue(ChorusFlowerBlock.AGE, i + 1), 2)) { this.placeGrownFlower(worldIn, blockpos1, i + 1); flag2 = true; } @@ -94,14 +94,14 @@ public abstract class ChorusFlowerBlockMixin extends BlockMixin { } if (flag2) { - worldIn.setBlockState(pos, this.plantBlock.makeConnections(worldIn, pos), 2); + worldIn.setBlock(pos, this.plant.getStateForPlacement(worldIn, pos), 2); } else { - if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) { + if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.defaultBlockState().setValue(ChorusFlowerBlock.AGE, 5), 2)) { this.placeDeadFlower(worldIn, pos); } } } else { - if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.getDefaultState().with(ChorusFlowerBlock.AGE, 5), 2)) { + if (CraftEventFactory.handleBlockGrowEvent(worldIn, pos, this.defaultBlockState().setValue(ChorusFlowerBlock.AGE, 5), 2)) { this.placeDeadFlower(worldIn, pos); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CocoaBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CocoaBlockMixin.java new file mode 100644 index 00000000..56b82607 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CocoaBlockMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.CocoaBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(CocoaBlock.class) +public class CocoaBlockMixin { + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockGrow1(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } + + @Redirect(method = "performBonemeal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private boolean arclight$blockGrow2(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CommandBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CommandBlockMixin.java new file mode 100644 index 00000000..c12fe5dd --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CommandBlockMixin.java @@ -0,0 +1,50 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CommandBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.CommandBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(CommandBlock.class) +public abstract class CommandBlockMixin { + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { + if (!worldIn.isClientSide) { + BlockEntity tileentity = worldIn.getBlockEntity(pos); + if (tileentity instanceof CommandBlockEntity) { + CommandBlockEntity commandblocktileentity = (CommandBlockEntity) tileentity; + boolean flag = worldIn.hasNeighborSignal(pos); + boolean flag1 = commandblocktileentity.isPowered(); + + org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldIn, pos); + int old = flag1 ? 15 : 0; + int current = flag ? 15 : 0; + BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current); + Bukkit.getPluginManager().callEvent(eventRedstone); + flag = eventRedstone.getNewCurrent() > 0; + + commandblocktileentity.setPowered(flag); + if (!flag1 && !commandblocktileentity.isAutomatic() && commandblocktileentity.getMode() != CommandBlockEntity.Mode.SEQUENCE) { + if (flag) { + commandblocktileentity.markConditionMet(); + worldIn.getBlockTicks().scheduleTick(pos, (CommandBlock) (Object) this, 1); + } + + } + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComparatorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComparatorBlockMixin.java new file mode 100644 index 00000000..677c7cb8 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComparatorBlockMixin.java @@ -0,0 +1,29 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.ComparatorBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ComparatorBlock.class) +public class ComparatorBlockMixin { + + @Inject(method = "refreshOutputState", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockRedstone1(Level worldIn, BlockPos pos, BlockState state, CallbackInfo ci) { + if (CraftEventFactory.callRedstoneChange(worldIn, pos, 15, 0).getNewCurrent() != 0) { + ci.cancel(); + } + } + + @Inject(method = "refreshOutputState", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockRedstone2(Level worldIn, BlockPos pos, BlockState state, CallbackInfo ci) { + if (CraftEventFactory.callRedstoneChange(worldIn, pos, 0, 15).getNewCurrent() != 15) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlockMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlockMixin.java index f95e6931..0d1d16cc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlockMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; import it.unimi.dsi.fastutil.objects.Object2FloatMap; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComposterBlock; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.state.IntegerProperty; -import net.minecraft.util.IItemProvider; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.ComposterBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; import org.bukkit.craftbukkit.v.util.DummyGeneratorAccess; @@ -30,15 +30,15 @@ public abstract class ComposterBlockMixin { // @formatter:off @Shadow @Final public static IntegerProperty LEVEL; - @Shadow @Final public static Object2FloatMap CHANCES; - @Shadow public static BlockState resetFillState(BlockState state, IWorld world, BlockPos pos) { return null; } - @Shadow public static BlockState empty(BlockState state, World world, BlockPos pos) { return null; } + @Shadow @Final public static Object2FloatMap COMPOSTABLES; + @Shadow public static BlockState empty(BlockState state, LevelAccessor world, BlockPos pos) { return null; } + @Shadow public static BlockState extractProduce(BlockState state, Level world, BlockPos pos) { return null; } // @formatter:on @SuppressWarnings("UnresolvedMixinReference") - @Redirect(method = "createInventory", at = @At(value = "NEW", target = "()Lnet/minecraft/block/ComposterBlock$EmptyInventory;")) - public ComposterBlock.EmptyInventory arclight$newEmpty(BlockState blockState, IWorld world, BlockPos blockPos) { - ComposterBlock.EmptyInventory inventory = new ComposterBlock.EmptyInventory(); + @Redirect(method = "getContainer", at = @At(value = "NEW", target = "()Lnet/minecraft/block/ComposterBlock$EmptyInventory;")) + public ComposterBlock.EmptyContainer arclight$newEmpty(BlockState blockState, LevelAccessor world, BlockPos blockPos) { + ComposterBlock.EmptyContainer inventory = new ComposterBlock.EmptyContainer(); ((IInventoryBridge) inventory).setOwner(new CraftBlockInventoryHolder(world, blockPos, inventory)); return inventory; } @@ -48,10 +48,10 @@ public abstract class ComposterBlockMixin { * @reason */ @Overwrite - public static BlockState attemptFill(BlockState state, ServerWorld world, ItemStack stack, BlockPos pos) { - int i = state.get(LEVEL); - if (i < 7 && CHANCES.containsKey(stack.getItem())) { - double rand = world.rand.nextDouble(); + public static BlockState insertItem(BlockState state, ServerLevel world, ItemStack stack, BlockPos pos) { + int i = state.getValue(LEVEL); + if (i < 7 && COMPOSTABLES.containsKey(stack.getItem())) { + double rand = world.random.nextDouble(); BlockState state1 = attemptCompost(state, DummyGeneratorAccess.INSTANCE, pos, stack, rand); if (state == state1 || CraftEventFactory.callEntityChangeBlockEvent(ArclightCaptures.getEntityChangeBlock(), pos, state1).isCancelled()) { @@ -66,37 +66,37 @@ public abstract class ComposterBlockMixin { } } - @Inject(method = "empty", cancellable = true, at = @At("HEAD")) - private static void arclight$emptyComposter(BlockState state, World world, BlockPos pos, CallbackInfoReturnable cir) { + @Inject(method = "extractProduce", cancellable = true, at = @At("HEAD")) + private static void arclight$emptyComposter(BlockState state, Level world, BlockPos pos, CallbackInfoReturnable cir) { Entity entity = ArclightCaptures.getEntityChangeBlock(); if (entity != null) { - BlockState blockState = resetFillState(state, DummyGeneratorAccess.INSTANCE, pos); + BlockState blockState = empty(state, DummyGeneratorAccess.INSTANCE, pos); if (CraftEventFactory.callEntityChangeBlockEvent(entity, pos, blockState).isCancelled()) { cir.setReturnValue(state); } } } - private static BlockState d(BlockState state, World world, BlockPos pos, Entity entity) { + private static BlockState d(BlockState state, Level world, BlockPos pos, Entity entity) { ArclightCaptures.captureEntityChangeBlock(entity); - return empty(state, world, pos); + return extractProduce(state, world, pos); } - private static BlockState b(BlockState state, IWorld world, BlockPos pos, ItemStack stack, double rand) { + private static BlockState b(BlockState state, LevelAccessor world, BlockPos pos, ItemStack stack, double rand) { return attemptCompost(state, world, pos, stack, rand); } - private static BlockState attemptCompost(BlockState state, IWorld world, BlockPos pos, ItemStack stack, double rand) { - int i = state.get(LEVEL); - float f = CHANCES.getFloat(stack.getItem()); + private static BlockState attemptCompost(BlockState state, LevelAccessor world, BlockPos pos, ItemStack stack, double rand) { + int i = state.getValue(LEVEL); + float f = COMPOSTABLES.getFloat(stack.getItem()); if ((i != 0 || !(f > 0.0F)) && !(rand < (double) f)) { return state; } else { int j = i + 1; - BlockState blockstate = state.with(LEVEL, j); - world.setBlockState(pos, blockstate, 3); + BlockState blockstate = state.setValue(LEVEL, j); + world.setBlock(pos, blockstate, 3); if (j == 7) { - world.getPendingBlockTicks().scheduleTick(pos, state.getBlock(), 20); + world.getBlockTicks().scheduleTick(pos, state.getBlock(), 20); } return blockstate; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_EmptyInventoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_EmptyContainerMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_EmptyInventoryMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_EmptyContainerMixin.java index 36c8f1f6..27d99a7c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ComposterBlock_EmptyInventoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_EmptyContainerMixin.java @@ -1,20 +1,20 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; -import net.minecraft.block.ComposterBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.ComposterBlock; import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; import org.spongepowered.asm.mixin.Mixin; -@Mixin(ComposterBlock.EmptyInventory.class) -public abstract class ComposterBlock_EmptyInventoryMixin extends InventoryMixin { +@Mixin(ComposterBlock.EmptyContainer.class) +public abstract class ComposterBlock_EmptyContainerMixin extends InventoryMixin { public void arclight$constructor() { throw new RuntimeException(); } - public void arclight$constructor(IWorld world, BlockPos blockPos) { + public void arclight$constructor(LevelAccessor world, BlockPos blockPos) { arclight$constructor(); this.setOwner(new CraftBlockInventoryHolder(world, blockPos, this)); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_InputContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_InputContainerMixin.java new file mode 100644 index 00000000..1550a983 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_InputContainerMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.world.level.block.ComposterBlock$InputContainer") +public abstract class ComposterBlock_InputContainerMixin extends InventoryMixin { + + @Inject(method = "(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)V", at = @At("RETURN")) + public void arclight$setOwner(BlockState blockState, LevelAccessor world, BlockPos blockPos, CallbackInfo ci) { + this.setOwner(new CraftBlockInventoryHolder(world, blockPos, this)); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_OutputContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_OutputContainerMixin.java new file mode 100644 index 00000000..f2622673 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ComposterBlock_OutputContainerMixin.java @@ -0,0 +1,47 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mixin.core.inventory.InventoryMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.ComposterBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.inventory.CraftBlockInventoryHolder; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(targets = "net.minecraft.world.level.block.ComposterBlock$OutputContainer") +public abstract class ComposterBlock_OutputContainerMixin extends InventoryMixin { + + // @formatter:off + @Shadow @Final private BlockState state; + @Shadow @Final private LevelAccessor level; + @Shadow @Final private BlockPos pos; + @Shadow private boolean changed; + // @formatter:on + + @Inject(method = "(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V", at = @At("RETURN")) + public void arclight$setOwner(BlockState blockState, LevelAccessor world, BlockPos blockPos, ItemStack itemStack, CallbackInfo ci) { + this.setOwner(new CraftBlockInventoryHolder(world, blockPos, this)); + } + + /** + * @author IzzelAliz + * @reason + */ + @Overwrite + public void setChanged() { + if (this.isEmpty()) { + ComposterBlock.empty(this.state, this.level, this.pos); + this.changed = true; + } else { + this.level.setBlock(this.pos, this.state, 3); + this.changed = false; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ConcretePowderBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ConcretePowderBlockMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ConcretePowderBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ConcretePowderBlockMixin.java index f7a4134d..c74a89c1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ConcretePowderBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ConcretePowderBlockMixin.java @@ -1,12 +1,12 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ConcretePowderBlock; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.ConcretePowderBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -22,20 +22,20 @@ import org.spongepowered.asm.mixin.injection.Redirect; public abstract class ConcretePowderBlockMixin extends FallingBlockMixin { // @formatter:off - @Shadow @Final private BlockState solidifiedState; + @Shadow @Final private BlockState concrete; // @formatter:on - @Redirect(method = "onEndFalling", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockForm(World world, BlockPos pos, BlockState newState, int flags) { + @Redirect(method = "onLand", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockForm(Level world, BlockPos pos, BlockState newState, int flags) { return CraftEventFactory.handleBlockFormEvent(world, pos, newState, flags); } - @Redirect(method = "getStateForPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;")) - public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockItemUseContext context) { - World world = context.getWorld(); - BlockPos blockPos = context.getPos(); + @Redirect(method = "getStateForPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/ConcretePowderBlock;concrete:Lnet/minecraft/world/level/block/state/BlockState;")) + public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockPlaceContext context) { + Level world = context.getLevel(); + BlockPos blockPos = context.getClickedPos(); CraftBlockState blockState = CraftBlockState.getBlockState(world, blockPos); - blockState.setData(this.solidifiedState); + blockState.setData(this.concrete); BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { @@ -44,18 +44,18 @@ public abstract class ConcretePowderBlockMixin extends FallingBlockMixin { return super.getStateForPlacement(context); } - @Redirect(method = "updatePostPlacement", at = @At(value = "FIELD", target = "Lnet/minecraft/block/ConcretePowderBlock;solidifiedState:Lnet/minecraft/block/BlockState;")) - public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (!(worldIn instanceof World)) { - return this.solidifiedState; + @Redirect(method = "updateShape", at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/ConcretePowderBlock;concrete:Lnet/minecraft/world/level/block/state/BlockState;")) + public BlockState arclight$blockForm(@Coerce ConcretePowderBlockMixin block, BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { + if (!(worldIn instanceof Level)) { + return this.concrete; } CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos); - blockState.setData(this.solidifiedState); + blockState.setData(this.concrete); BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { return blockState.getHandle(); } - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralBlockMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralBlockMixin.java index 4e1b7518..54a3f29c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralBlockMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -22,9 +22,9 @@ public class CoralBlockMixin { @Shadow @Final private Block deadBlock; // @formatter:on - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.getDefaultState()).isCancelled()) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.defaultBlockState()).isCancelled()) { ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralFanBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralFanBlockMixin.java new file mode 100644 index 00000000..bdd8c1d9 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralFanBlockMixin.java @@ -0,0 +1,32 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.BaseCoralPlantTypeBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralFanBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(CoralFanBlock.class) +public class CoralFanBlockMixin { + + // @formatter:off + @Shadow @Final private Block deadBlock; + // @formatter:on + + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.defaultBlockState().setValue(BaseCoralPlantTypeBlock.WATERLOGGED, false)).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralPlantBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralPlantBlockMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralPlantBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralPlantBlockMixin.java index 1c62f3ac..7f1d4718 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/CoralPlantBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralPlantBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.AbstractCoralPlantBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralPlantBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.BaseCoralPlantTypeBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralPlantBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -23,9 +23,9 @@ public class CoralPlantBlockMixin { @Shadow @Final private Block deadBlock; // @formatter:on - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockFade(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.getDefaultState().with(AbstractCoralPlantBlock.WATERLOGGED, false)).isCancelled()) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.defaultBlockState().setValue(BaseCoralPlantTypeBlock.WATERLOGGED, false)).isCancelled()) { ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralWallFanBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralWallFanBlockMixin.java new file mode 100644 index 00000000..1839a10a --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CoralWallFanBlockMixin.java @@ -0,0 +1,35 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.BaseCoralPlantTypeBlock; +import net.minecraft.world.level.block.BaseCoralWallFanBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.CoralWallFanBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(CoralWallFanBlock.class) +public class CoralWallFanBlockMixin { + + // @formatter:off + @Shadow @Final private Block deadBlock; + // @formatter:on + + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, this.deadBlock.defaultBlockState() + .setValue(BaseCoralPlantTypeBlock.WATERLOGGED, Boolean.FALSE) + .setValue(BaseCoralWallFanBlock.FACING, state.getValue(BaseCoralWallFanBlock.FACING))).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin.java new file mode 100644 index 00000000..6e9f3e75 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/CropBlockMixin.java @@ -0,0 +1,36 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.event.ForgeEventFactory; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(CropBlock.class) +public class CropBlockMixin { + + @Redirect(method = "growCrops(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockGrowGrow(Level world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } + + @Redirect(method = "entityInside", at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/event/ForgeEventFactory;getMobGriefingEvent(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;)Z")) + public boolean arclight$entityChangeBlock(Level world, Entity entity, BlockState state, Level worldIn, BlockPos pos) { + boolean result = ForgeEventFactory.getMobGriefingEvent(world, entity); + EntityChangeBlockEvent event = CraftEventFactory.callEntityChangeBlockEvent(entity, pos, state, result); + return event.isCancelled(); + } + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockGrowTick(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DaylightDetectorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DaylightDetectorBlockMixin.java new file mode 100644 index 00000000..14fe814e --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DaylightDetectorBlockMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DaylightDetectorBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(DaylightDetectorBlock.class) +public class DaylightDetectorBlockMixin { + + @ModifyVariable(method = "updateSignalStrength", index = 3, name = "i", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static int arclight$blockRedstone(int i, BlockState blockState, Level world, BlockPos blockPos) { + return CraftEventFactory.callRedstoneChange(world, blockPos, blockState.getValue(DaylightDetectorBlock.POWER), i).getNewCurrent(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DetectorRailBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DetectorRailBlockMixin.java similarity index 66% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DetectorRailBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DetectorRailBlockMixin.java index f3717070..ea0000fd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DetectorRailBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DetectorRailBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.DetectorRailBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DetectorRailBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -21,8 +21,8 @@ public class DetectorRailBlockMixin { private transient boolean arclight$flag; - @Inject(method = "updatePoweredState", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ)) - public void arclight$blockRedstone(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci, boolean flag, boolean flag1) { + @Inject(method = "checkPressed", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ)) + public void arclight$blockRedstone(Level worldIn, BlockPos pos, BlockState state, CallbackInfo ci, boolean flag, boolean flag1) { if (flag != flag1) { Block block = CraftBlock.at(worldIn, pos); @@ -34,7 +34,7 @@ public class DetectorRailBlockMixin { } // todo 注入顺序 - @ModifyVariable(method = "updatePoweredState", index = 5, name = "flag1", at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ)) + @ModifyVariable(method = "checkPressed", index = 5, name = "flag1", at = @At(value = "JUMP", ordinal = 1, opcode = Opcodes.IFEQ)) public boolean arclight$blockRedstone(boolean flag1) { return arclight$flag; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneDiodeBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DiodeBlockMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneDiodeBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DiodeBlockMixin.java index c889d21f..2c5c5ae1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneDiodeBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DiodeBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneDiodeBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.DiodeBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,18 +12,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; -@Mixin(RedstoneDiodeBlock.class) -public class RedstoneDiodeBlockMixin { +@Mixin(DiodeBlock.class) +public class DiodeBlockMixin { - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$turnOff(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$turnOff(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 15, 0).getNewCurrent() != 0) { ci.cancel(); } } - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$turnOn(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$turnOn(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 0, 15).getNewCurrent() != 15) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DispenserBlockMixin_Accessor.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DispenserBlockMixin_Accessor.java new file mode 100644 index 00000000..d994f34b --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DispenserBlockMixin_Accessor.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.dispenser.DispenseItemBehavior; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.DispenserBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(DispenserBlock.class) +public interface DispenserBlockMixin_Accessor { + + @Accessor("DISPENSER_REGISTRY") + static Map getDispenseBehaviorRegistry() { + return null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoorBlockMixin.java similarity index 58% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoorBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoorBlockMixin.java index 7df9e623..c177259a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DoorBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoorBlockMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.state.BooleanProperty; -import net.minecraft.state.EnumProperty; -import net.minecraft.state.properties.DoubleBlockHalf; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; +import net.minecraft.world.level.block.state.properties.EnumProperty; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.BlockRedstoneEvent; @@ -24,7 +24,7 @@ public abstract class DoorBlockMixin { @Shadow @Final public static EnumProperty HALF; @Shadow @Final public static BooleanProperty POWERED; @Shadow @Final public static BooleanProperty OPEN; - @Shadow protected abstract void playSound(World worldIn, BlockPos pos, boolean isOpening); + @Shadow protected abstract void playSound(Level worldIn, BlockPos pos, boolean isOpening); // @formatter:on /** @@ -32,8 +32,8 @@ public abstract class DoorBlockMixin { * @reason */ @Overwrite - public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { - BlockPos blockPos = pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN); + public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { + BlockPos blockPos = pos.relative(state.getValue(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN); org.bukkit.block.Block bukkitBlock = CraftBlock.at(worldIn, pos); org.bukkit.block.Block blockTop = CraftBlock.at(worldIn, blockPos); @@ -41,18 +41,18 @@ public abstract class DoorBlockMixin { int power = bukkitBlock.getBlockPower(); int powerTop = blockTop.getBlockPower(); if (powerTop > power) power = powerTop; - int oldPower = state.get(DoorBlock.POWERED) ? 15 : 0; + int oldPower = state.getValue(DoorBlock.POWERED) ? 15 : 0; if (oldPower == 0 ^ power == 0) { BlockRedstoneEvent event = new BlockRedstoneEvent(bukkitBlock, oldPower, power); Bukkit.getPluginManager().callEvent(event); boolean flag = event.getNewCurrent() > 0; - if (flag != state.get(OPEN)) { + if (flag != state.getValue(OPEN)) { this.playSound(worldIn, pos, flag); } - worldIn.setBlockState(pos, state.with(POWERED, flag).with(OPEN, flag), 2); + worldIn.setBlock(pos, state.setValue(POWERED, flag).setValue(OPEN, flag), 2); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoublePlantBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoublePlantBlockMixin.java new file mode 100644 index 00000000..36271869 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DoublePlantBlockMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DoublePlantBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DoublePlantBlock.class) +public class DoublePlantBlockMixin { + + @Inject(method = "playerWillDestroy", cancellable = true, at = @At("HEAD")) + public void arclight$blockPhysics(Level worldIn, BlockPos pos, BlockState state, Player player, CallbackInfo ci) { + if (CraftEventFactory.callBlockPhysicsEvent(worldIn, pos).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DragonEggBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DragonEggBlockMixin.java similarity index 79% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DragonEggBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DragonEggBlockMixin.java index d8e68037..f151983f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DragonEggBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DragonEggBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.DragonEggBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DragonEggBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.BlockFromToEvent; @@ -19,8 +19,8 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class DragonEggBlockMixin { @Inject(method = "teleport", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;isRemote:Z")) - public void arclight$blockFromTo(BlockState blockState, World world, BlockPos blockPos, CallbackInfo ci, + at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/Level;isClientSide:Z")) + public void arclight$blockFromTo(BlockState blockState, Level world, BlockPos blockPos, CallbackInfo ci, int i, BlockPos pos) { org.bukkit.block.Block from = CraftBlock.at(world, blockPos); org.bukkit.block.Block to = CraftBlock.at(world, pos); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DropperBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DropperBlockMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DropperBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DropperBlockMixin.java index 4aba844b..7dd95d16 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/DropperBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DropperBlockMixin.java @@ -1,18 +1,18 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.inventory.IInventoryBridge; -import net.minecraft.block.DispenserBlock; -import net.minecraft.block.DropperBlock; -import net.minecraft.dispenser.IDispenseItemBehavior; -import net.minecraft.dispenser.ProxyBlockSource; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.DispenserTileEntity; -import net.minecraft.tileentity.HopperTileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.BlockSourceImpl; +import net.minecraft.core.Direction; +import net.minecraft.core.dispenser.DispenseItemBehavior; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.DispenserBlock; +import net.minecraft.world.level.block.DropperBlock; +import net.minecraft.world.level.block.entity.DispenserBlockEntity; +import net.minecraft.world.level.block.entity.HopperBlockEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; @@ -26,34 +26,34 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(DropperBlock.class) public class DropperBlockMixin { - @Shadow @Final private static IDispenseItemBehavior DISPENSE_BEHAVIOR; + @Shadow @Final private static DispenseItemBehavior DISPENSE_BEHAVIOUR; /** * @author IzzelAliz * @reason */ @Overwrite - public void dispense(ServerWorld worldIn, BlockPos pos) { - ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos); - DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity(); - int i = dispensertileentity.getDispenseSlot(); + public void dispenseFrom(ServerLevel worldIn, BlockPos pos) { + BlockSourceImpl proxyblocksource = new BlockSourceImpl(worldIn, pos); + DispenserBlockEntity dispensertileentity = proxyblocksource.getEntity(); + int i = dispensertileentity.getRandomSlot(); if (i < 0) { - worldIn.playEvent(1001, pos, 0); + worldIn.levelEvent(1001, pos, 0); } else { - ItemStack itemstack = dispensertileentity.getStackInSlot(i); + ItemStack itemstack = dispensertileentity.getItem(i); if (!itemstack.isEmpty() && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, dispensertileentity, i, itemstack)) { - Direction direction = worldIn.getBlockState(pos).get(DispenserBlock.FACING); - IInventory iinventory = HopperTileEntity.getInventoryAtPosition(worldIn, pos.offset(direction)); + Direction direction = worldIn.getBlockState(pos).getValue(DispenserBlock.FACING); + Container iinventory = HopperBlockEntity.getContainerAt(worldIn, pos.relative(direction)); ItemStack itemstack1; if (iinventory == null) { - itemstack1 = DISPENSE_BEHAVIOR.dispense(proxyblocksource, itemstack); + itemstack1 = DISPENSE_BEHAVIOUR.dispense(proxyblocksource, itemstack); } else { ItemStack split = itemstack.copy().split(1); CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(split); Inventory destinationInventory; // Have to special case large chests as they work oddly - if (iinventory instanceof DoubleSidedInventory) { - destinationInventory = new CraftInventoryDoubleChest((DoubleSidedInventory) iinventory); + if (iinventory instanceof CompoundContainer) { + destinationInventory = new CraftInventoryDoubleChest((CompoundContainer) iinventory); } else { destinationInventory = ((IInventoryBridge) iinventory).getOwnerInventory(); } @@ -62,7 +62,7 @@ public class DropperBlockMixin { if (event.isCancelled()) { return; } - itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite()); + itemstack1 = HopperBlockEntity.addItem(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite()); if (event.getItem().equals(craftItemStack) && itemstack1.isEmpty()) { itemstack1 = itemstack.copy(); itemstack1.shrink(1); @@ -71,7 +71,7 @@ public class DropperBlockMixin { } } - dispensertileentity.setInventorySlotContents(i, itemstack1); + dispensertileentity.setItem(i, itemstack1); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/EndPortalBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/EndPortalBlockMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/EndPortalBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/EndPortalBlockMixin.java index 74951ed0..a3ba71dd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/EndPortalBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/EndPortalBlockMixin.java @@ -1,17 +1,17 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.EndPortalBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.EndPortalBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.entity.EntityPortalEnterEvent; @@ -23,13 +23,13 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(EndPortalBlock.class) public class EndPortalBlockMixin { - @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getWorld(Lnet/minecraft/util/RegistryKey;)Lnet/minecraft/world/server/ServerWorld;")) - public ServerWorld arclight$enterPortal(MinecraftServer minecraftServer, RegistryKey dimension, BlockState state, World worldIn, BlockPos pos, Entity entityIn) { - ServerWorld world = minecraftServer.getWorld(dimension); + @Redirect(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getLevel(Lnet/minecraft/resources/ResourceKey;)Lnet/minecraft/server/level/ServerLevel;")) + public ServerLevel arclight$enterPortal(MinecraftServer minecraftServer, ResourceKey dimension, BlockState state, Level worldIn, BlockPos pos, Entity entityIn) { + ServerLevel world = minecraftServer.getLevel(dimension); EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ())); Bukkit.getPluginManager().callEvent(event); - if (entityIn instanceof ServerPlayerEntity && world != null) { + if (entityIn instanceof ServerPlayer && world != null) { ((ServerPlayerEntityBridge) entityIn).bridge$changeDimension(world, PlayerTeleportEvent.TeleportCause.END_PORTAL); return null; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FallingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FallingBlockMixin.java new file mode 100644 index 00000000..56db6617 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FallingBlockMixin.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.FallingBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(FallingBlock.class) +public abstract class FallingBlockMixin extends BlockMixin { + + // @formatter:off + @Shadow public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { return null; } + // @formatter:on +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FarmBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FarmBlockMixin.java new file mode 100644 index 00000000..82547264 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FarmBlockMixin.java @@ -0,0 +1,30 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FarmBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(FarmBlock.class) +public abstract class FarmBlockMixin extends BlockMixin { + + @Inject(method = "turnToDirt", cancellable = true, at = @At("HEAD")) + private static void arclight$blockFade(BlockState state, Level worldIn, BlockPos pos, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$moistureChange(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleMoistureChangeEvent(world, pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FenceGateBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FenceGateBlockMixin.java similarity index 64% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FenceGateBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FenceGateBlockMixin.java index 379dd88b..b32b67c1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FenceGateBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FenceGateBlockMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.FenceGateBlock; -import net.minecraft.state.BooleanProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.FenceGateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -22,10 +22,10 @@ public class FenceGateBlockMixin { @Shadow @Final public static BooleanProperty POWERED; // @formatter:on - @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isBlockPowered(Lnet/minecraft/util/math/BlockPos;)Z")) - private boolean arclight$blockRedstone(World world, BlockPos pos, BlockState state) { - boolean powered = world.isBlockPowered(pos); - boolean oldPowered = state.get(POWERED); + @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;hasNeighborSignal(Lnet/minecraft/core/BlockPos;)Z")) + private boolean arclight$blockRedstone(Level world, BlockPos pos, BlockState state) { + boolean powered = world.hasNeighborSignal(pos); + boolean oldPowered = state.getValue(POWERED); if (oldPowered != powered) { int newPower = powered ? 15 : 0; int oldPower = oldPowered ? 15 : 0; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FireBlockMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FireBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FireBlockMixin.java index f1fe7912..27dbbf3c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FireBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FireBlockMixin.java @@ -1,16 +1,16 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.block.FireBlockBridge; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FireBlock; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FireBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -32,13 +32,13 @@ import java.util.Random; public abstract class FireBlockMixin implements FireBlockBridge { // @formatter:off - @Shadow protected abstract BlockState getStateForPlacement(IBlockReader blockReader, BlockPos pos); - @Shadow @Final private Object2IntMap flammabilities; + @Shadow protected abstract BlockState getStateForPlacement(BlockGetter blockReader, BlockPos pos); + @Shadow @Final private Object2IntMap burnOdds; // @formatter:on - @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$fireSpread(ServerWorld world, BlockPos mutablePos, BlockState newState, int flags, - BlockState state, ServerWorld worldIn, BlockPos pos) { + @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$fireSpread(ServerLevel world, BlockPos mutablePos, BlockState newState, int flags, + BlockState state, ServerLevel worldIn, BlockPos pos) { if (world.getBlockState(mutablePos).getBlock() != Blocks.FIRE) { if (!CraftEventFactory.callBlockIgniteEvent(world, mutablePos, pos).isCancelled()) { return CraftEventFactory.handleBlockSpreadEvent(world, pos, mutablePos, newState, flags); @@ -47,18 +47,18 @@ public abstract class FireBlockMixin implements FireBlockBridge { return false; } - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public boolean arclight$extinguish1(ServerWorld world, BlockPos pos, boolean isMoving) { - if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.getDefaultState()).isCancelled()) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public boolean arclight$extinguish1(ServerLevel world, BlockPos pos, boolean isMoving) { + if (!CraftEventFactory.callBlockFadeEvent(world, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { world.removeBlock(pos, isMoving); } return false; } - @Inject(method = "tryCatchFire", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) - public void arclight$blockBurn(World worldIn, BlockPos pos, int chance, Random random, int age, Direction face, CallbackInfo ci) { + @Inject(method = "tryCatchFire", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/level/Level;getBlockState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;")) + public void arclight$blockBurn(Level worldIn, BlockPos pos, int chance, Random random, int age, Direction face, CallbackInfo ci) { Block theBlock = CraftBlock.at(worldIn, pos); - Block sourceBlock = CraftBlock.at(worldIn, pos.offset(face)); + Block sourceBlock = CraftBlock.at(worldIn, pos.relative(face)); BlockBurnEvent event = new BlockBurnEvent(theBlock, sourceBlock); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -66,24 +66,24 @@ public abstract class FireBlockMixin implements FireBlockBridge { } } - @Redirect(method = "updatePostPlacement", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDefaultState()Lnet/minecraft/block/BlockState;")) - public BlockState arclight$blockFade(net.minecraft.block.Block block, BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (!(worldIn instanceof World)) { - return Blocks.AIR.getDefaultState(); + @Redirect(method = "updateShape", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;defaultBlockState()Lnet/minecraft/world/level/block/state/BlockState;")) + public BlockState arclight$blockFade(net.minecraft.world.level.block.Block block, BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { + if (!(worldIn instanceof Level)) { + return Blocks.AIR.defaultBlockState(); } CraftBlockState blockState = CraftBlockState.getBlockState(worldIn, currentPos); - blockState.setData(Blocks.AIR.getDefaultState()); + blockState.setData(Blocks.AIR.defaultBlockState()); BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - return this.getStateForPlacement(worldIn, currentPos).with(FireBlock.AGE, stateIn.get(FireBlock.AGE)); + return this.getStateForPlacement(worldIn, currentPos).setValue(FireBlock.AGE, stateIn.getValue(FireBlock.AGE)); } else { return blockState.getHandle(); } } @Override - public boolean bridge$canBurn(net.minecraft.block.Block block) { - return this.flammabilities.containsKey(block); + public boolean bridge$canBurn(net.minecraft.world.level.block.Block block) { + return this.burnOdds.containsKey(block); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FungusBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FungusBlockMixin.java similarity index 64% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FungusBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FungusBlockMixin.java index 75543ba0..e589fae3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/FungusBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/FungusBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FungusBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FungusBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.TreeType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,8 +18,8 @@ import java.util.Random; public class FungusBlockMixin { @SuppressWarnings("ConstantConditions") - @Inject(method = "grow", at = @At("HEAD")) - private void arclight$captureTree(ServerWorld worldIn, Random rand, BlockPos pos, BlockState state, CallbackInfo ci) { + @Inject(method = "performBonemeal", at = @At("HEAD")) + private void arclight$captureTree(ServerLevel worldIn, Random rand, BlockPos pos, BlockState state, CallbackInfo ci) { if ((Object) this == Blocks.WARPED_FUNGUS) { ArclightCaptures.captureTreeType(TreeType.WARPED_FUNGUS); } else if ((Object) this == Blocks.CRIMSON_FUNGUS) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrassBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrassBlockMixin.java new file mode 100644 index 00000000..bf85e05d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrassBlockMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.GrassBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(GrassBlock.class) +public class GrassBlockMixin { + + @Redirect(method = "performBonemeal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockGrow(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrowingPlantHeadBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrowingPlantHeadBlockMixin.java new file mode 100644 index 00000000..f016c3c1 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/GrowingPlantHeadBlockMixin.java @@ -0,0 +1,21 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.GrowingPlantHeadBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Random; + +@Mixin(GrowingPlantHeadBlock.class) +public class GrowingPlantHeadBlockMixin { + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private boolean arclight$blockGrow(ServerLevel world, BlockPos to, BlockState state, BlockState state1, ServerLevel worldIn, BlockPos from, Random random) { + return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/IceBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/IceBlockMixin.java new file mode 100644 index 00000000..c106b693 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/IceBlockMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.IceBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(IceBlock.class) +public class IceBlockMixin { + + @Inject(method = "melt", cancellable = true, at = @At("HEAD")) + public void arclight$blockFade(BlockState blockState, Level world, BlockPos blockPos, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(world, blockPos, world.dimensionType().ultraWarm() + ? Blocks.AIR.defaultBlockState() : Blocks.WATER.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/InfestedBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/InfestedBlockMixin.java new file mode 100644 index 00000000..f957f79f --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/InfestedBlockMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.InfestedBlock; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(InfestedBlock.class) +public class InfestedBlockMixin { + + @Inject(method = "spawnInfestation", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public void arclight$spawn(ServerLevel world, BlockPos pos, CallbackInfo ci) { + ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SILVERFISH_BLOCK); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/JukeBoxBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/JukeBoxBlockMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/JukeBoxBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/JukeBoxBlockMixin.java index 9c77af47..c9cbe404 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/JukeBoxBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/JukeBoxBlockMixin.java @@ -1,7 +1,7 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.JukeboxBlock; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.JukeboxBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; @Mixin(JukeboxBlock.class) public class JukeBoxBlockMixin { - @ModifyArg(method = "insertRecord", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/JukeboxTileEntity;setRecord(Lnet/minecraft/item/ItemStack;)V")) + @ModifyArg(method = "setRecord", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/JukeboxBlockEntity;setRecord(Lnet/minecraft/world/item/ItemStack;)V")) private ItemStack arclight$oneItem(ItemStack stack) { if (!stack.isEmpty()) { stack.setCount(1); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LayeredCauldronBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LayeredCauldronBlockMixin.java new file mode 100644 index 00000000..21928e49 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LayeredCauldronBlockMixin.java @@ -0,0 +1,56 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.mod.server.block.CauldronHooks; +import io.izzel.arclight.mixin.Eject; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.LayeredCauldronBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.event.block.CauldronLevelChangeEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LayeredCauldronBlock.class) +public class LayeredCauldronBlockMixin { + + @Redirect(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;clearFire()V")) + private void arclight$extinguish1(Entity entity) { + } + + @Inject(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/LayeredCauldronBlock;handleEntityOnFireInside(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + private void arclight$extinguish2(BlockState p_153534_, Level p_153535_, BlockPos p_153536_, Entity entity, CallbackInfo ci) { + CauldronHooks.setChangeReason(entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH); + } + + @Inject(method = "entityInside", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/block/LayeredCauldronBlock;handleEntityOnFireInside(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + private void arclight$extinguish3(BlockState p_153534_, Level p_153535_, BlockPos p_153536_, Entity p_153537_, CallbackInfo ci) { + if (!CauldronHooks.getResult()) { + ci.cancel(); + } + CauldronHooks.reset(); + } + + @Redirect(method = "lowerFillLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private static boolean arclight$lowerFill(Level level, BlockPos pos, BlockState state, BlockState old) { + return CauldronHooks.changeLevel(old, level, pos, state, CauldronHooks.getEntity(), CauldronHooks.getReason()); + } + + @Redirect(method = "handlePrecipitation", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private static boolean arclight$precipitation(Level level, BlockPos pos, BlockState state, BlockState old) { + return CauldronHooks.changeLevel(old, level, pos, state, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); + } + + @Eject(method = "receiveStalactiteDrip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private static boolean arclight$drip(Level level, BlockPos pos, BlockState state, BlockState old, CallbackInfo ci) { + if (CauldronHooks.changeLevel(old, level, pos, state, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { + return true; + } else { + ci.cancel(); + return false; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeavesBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeavesBlockMixin.java similarity index 56% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeavesBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeavesBlockMixin.java index 27f06c0f..ba8100c4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeavesBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeavesBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeavesBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.LeavesDecayEvent; @@ -17,8 +17,8 @@ import java.util.Random; @Mixin(LeavesBlock.class) public class LeavesBlockMixin { - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/LeavesBlock;spawnDrops(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$leavesDecay(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/LeavesBlock;dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$leavesDecay(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { LeavesDecayEvent event = new LeavesDecayEvent(CraftBlock.at(worldIn, pos)); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled() || worldIn.getBlockState(pos).getBlock() != (Object) this) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LecternBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LecternBlockMixin.java new file mode 100644 index 00000000..4e980508 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LecternBlockMixin.java @@ -0,0 +1,31 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.LecternBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.LecternBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(LecternBlock.class) +public class LecternBlockMixin { + + @Redirect(method = "popBook", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getBlockEntity(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/entity/BlockEntity;")) + private BlockEntity arclight$noValidate(Level world, BlockPos pos) { + return ((WorldBridge) world).bridge$getTileEntity(pos, false); + } + + @Inject(method = "popBook", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/core/Direction;getStepX()I")) + private void arclight$returnIfEmpty(BlockState state, Level worldIn, BlockPos pos, CallbackInfo ci, BlockEntity tileEntity, LecternBlockEntity lecternTileEntity, Direction direction, ItemStack itemStack) { + if (itemStack.isEmpty()) ci.cancel(); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeverBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeverBlockMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeverBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeverBlockMixin.java index b1e62643..3c7839d5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/LeverBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LeverBlockMixin.java @@ -1,13 +1,13 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeverBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.BooleanProperty; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.LeverBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.BlockHitResult; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -26,9 +26,9 @@ public class LeverBlockMixin { @Shadow @Final public static BooleanProperty POWERED; // @formatter:on - @Inject(method = "onBlockActivated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/LeverBlock;setPowered(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) - public void arclight$blockRedstone(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit, CallbackInfoReturnable cir) { - boolean flag = state.get(POWERED); + @Inject(method = "use", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/LeverBlock;pull(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;")) + public void arclight$blockRedstone(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, CallbackInfoReturnable cir) { + boolean flag = state.getValue(POWERED); Block block = CraftBlock.at(worldIn, pos); int old = (flag) ? 15 : 0; int current = (!flag) ? 15 : 0; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LilyPadBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LilyPadBlockMixin.java new file mode 100644 index 00000000..2dfbb795 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LilyPadBlockMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.WaterlilyBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WaterlilyBlock.class) +public class LilyPadBlockMixin { + + @Inject(method = "entityInside", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z")) + public void arclight$entityChangeBlock(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + if (CraftEventFactory.callEntityChangeBlockEvent(entityIn, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LiquidBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LiquidBlockMixin.java new file mode 100644 index 00000000..6312e1b4 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/LiquidBlockMixin.java @@ -0,0 +1,31 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LiquidBlock.class) +public class LiquidBlockMixin { + + private transient boolean arclight$fizz = true; + + @Redirect(method = "shouldSpreadLiquid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean arclight$blockForm(Level world, BlockPos pos, BlockState state) { + return arclight$fizz = CraftEventFactory.handleBlockFormEvent(world, pos, state); + } + + @Inject(method = "fizz", cancellable = true, at = @At("HEAD")) + public void arclight$fizz(LevelAccessor worldIn, BlockPos pos, CallbackInfo ci) { + if (!arclight$fizz) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MagmaBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MagmaBlockMixin.java new file mode 100644 index 00000000..afd0c3a7 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MagmaBlockMixin.java @@ -0,0 +1,27 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.MagmaBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MagmaBlock.class) +public class MagmaBlockMixin { + + @Inject(method = "stepOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + public void arclight$blockDamagePre(Level worldIn, BlockPos pos, BlockState state, Entity entityIn, CallbackInfo ci) { + CraftEventFactory.blockDamage = CraftBlock.at(worldIn, pos); + } + + @Inject(method = "stepOn", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + public void arclight$blockDamagePost(Level worldIn, BlockPos pos, BlockState state, Entity entityIn, CallbackInfo ci) { + CraftEventFactory.blockDamage = null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MushroomBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MushroomBlockMixin.java similarity index 52% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MushroomBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MushroomBlockMixin.java index c16bc90f..3850acad 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/MushroomBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/MushroomBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.MushroomBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.MushroomBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.TreeType; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; @@ -19,14 +19,14 @@ import java.util.Random; @Mixin(MushroomBlock.class) public class MushroomBlockMixin { - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$blockSpread(ServerWorld world, BlockPos toPos, BlockState newState, int flags, BlockState state, ServerWorld worldIn, BlockPos fromPos) { + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$blockSpread(ServerLevel world, BlockPos toPos, BlockState newState, int flags, BlockState state, ServerLevel worldIn, BlockPos fromPos) { return CraftEventFactory.handleBlockSpreadEvent(world, fromPos, toPos, newState, flags); } @SuppressWarnings("ConstantConditions") - @Inject(method = "grow(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Ljava/util/Random;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/feature/ConfiguredFeature;generate(Lnet/minecraft/world/ISeedReader;Lnet/minecraft/world/gen/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;)Z")) - private void arclight$captureTree(ServerWorld world, BlockPos pos, BlockState state, Random rand, CallbackInfoReturnable cir) { + @Inject(method = "growMushroom(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Ljava/util/Random;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/feature/ConfiguredFeature;place(Lnet/minecraft/world/level/WorldGenLevel;Lnet/minecraft/world/level/chunk/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/core/BlockPos;)Z")) + private void arclight$captureTree(ServerLevel world, BlockPos pos, BlockState state, Random rand, CallbackInfoReturnable cir) { if ((Object) this == Blocks.BROWN_MUSHROOM) { ArclightCaptures.captureTreeType(TreeType.BROWN_MUSHROOM); } else if ((Object) this == Blocks.RED_MUSHROOM) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherPortalBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherPortalBlockMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherPortalBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherPortalBlockMixin.java index 1881e1cc..e8574d3f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherPortalBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherPortalBlockMixin.java @@ -1,19 +1,19 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.EntityTypeBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.NetherPortalBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.NetherPortalBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -27,13 +27,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(NetherPortalBlock.class) public class NetherPortalBlockMixin { - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;")) - public Entity arclight$spawn(EntityType entityType, ServerWorld worldIn, CompoundNBT compound, ITextComponent customName, PlayerEntity playerIn, BlockPos pos, SpawnReason reason, boolean flag, boolean flag1) { + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityType;spawn(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/network/chat/Component;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/MobSpawnType;ZZ)Lnet/minecraft/world/entity/Entity;")) + public Entity arclight$spawn(EntityType entityType, ServerLevel worldIn, CompoundTag compound, Component customName, Player playerIn, BlockPos pos, MobSpawnType reason, boolean flag, boolean flag1) { return ((EntityTypeBridge) entityType).bridge$spawnCreature(worldIn, compound, customName, playerIn, pos, reason, flag, flag1, CreatureSpawnEvent.SpawnReason.NETHER_PORTAL); } - @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPortal(Lnet/minecraft/util/math/BlockPos;)V")) - public void arclight$portalEnter(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + @Inject(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;handleInsidePortal(Lnet/minecraft/core/BlockPos;)V")) + public void arclight$portalEnter(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { EntityPortalEnterEvent event = new EntityPortalEnterEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), new Location(((WorldBridge) worldIn).bridge$getWorld(), pos.getX(), pos.getY(), pos.getZ())); Bukkit.getPluginManager().callEvent(event); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherWartBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherWartBlockMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherWartBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherWartBlockMixin.java index 7cfa4583..51b4186f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/NetherWartBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NetherWartBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.NetherWartBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.NetherWartBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,8 +12,8 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(NetherWartBlock.class) public class NetherWartBlockMixin { - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public boolean arclight$cropGrow(ServerWorld world, BlockPos pos, BlockState newState, int flags) { + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$cropGrow(ServerLevel world, BlockPos pos, BlockState newState, int flags) { return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NoteBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NoteBlockMixin.java new file mode 100644 index 00000000..5256f45c --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/NoteBlockMixin.java @@ -0,0 +1,59 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.block.NoteBlockBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.NoteBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.block.NotePlayEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(NoteBlock.class) +public abstract class NoteBlockMixin implements NoteBlockBridge { + + // @formatter:off + @Shadow protected abstract void playNote(Level worldIn, BlockPos pos); + // @formatter:on + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/NoteBlock;playNote(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$callNote2(NoteBlock noteBlock, Level worldIn, BlockPos pos, BlockState blockState) { + this.bridge$play(worldIn, pos, blockState); + } + + @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/NoteBlock;playNote(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$callNote1(NoteBlock noteBlock, Level worldIn, BlockPos pos, BlockState blockState) { + this.play(worldIn, pos, blockState); + } + + @Redirect(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/NoteBlock;playNote(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$callNote3(NoteBlock noteBlock, Level worldIn, BlockPos pos, BlockState blockState) { + this.play(worldIn, pos, blockState); + } + + private transient BlockState arclight$state; + + private void play(Level worldIn, BlockPos pos, BlockState state) { + arclight$state = state; + this.playNote(worldIn, pos); + arclight$state = null; + } + + @Override + public void bridge$play(Level worldIn, BlockPos pos, BlockState state) { + this.play(worldIn, pos, state); + } + + @Inject(method = "playNote", cancellable = true, require = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;blockEvent(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;II)V")) + private void arclight$notePlay(Level worldIn, BlockPos pos, CallbackInfo ci) { + NotePlayEvent event = CraftEventFactory.callNotePlayEvent(worldIn, pos, arclight$state.getValue(NoteBlock.INSTRUMENT), arclight$state.getValue(NoteBlock.NOTE)); + if (event.isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ObserverBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ObserverBlockMixin.java similarity index 55% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ObserverBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ObserverBlockMixin.java index 16161d07..34c183a5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/ObserverBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ObserverBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ObserverBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.ObserverBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,15 +15,15 @@ import java.util.Random; @Mixin(ObserverBlock.class) public class ObserverBlockMixin { - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$redstoneChange1(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$redstoneChange1(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 15, 0).getNewCurrent() != 0) { ci.cancel(); } } - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$redstoneChange2(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$redstoneChange2(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 0, 15).getNewCurrent() != 15) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PistonBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PistonBlockMixin.java similarity index 64% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PistonBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PistonBlockMixin.java index 594901b0..e6d681f6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PistonBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PistonBlockMixin.java @@ -1,13 +1,13 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import com.google.common.collect.ImmutableList; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.PistonBlock; -import net.minecraft.block.PistonBlockStructureHelper; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.piston.PistonBaseBlock; +import net.minecraft.world.level.block.piston.PistonStructureResolver; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlock; @@ -26,15 +26,15 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.AbstractList; import java.util.List; -@Mixin(PistonBlock.class) +@Mixin(PistonBaseBlock.class) public class PistonBlockMixin { // @formatter:off @Shadow @Final private boolean isSticky; // @formatter:on - @Inject(method = "checkForMove", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addBlockEvent(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;II)V")) - public void arclight$pistonRetract(World worldIn, BlockPos pos, BlockState state, CallbackInfo ci, Direction direction) { + @Inject(method = "checkIfExtend", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;blockEvent(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;II)V")) + public void arclight$pistonRetract(Level worldIn, BlockPos pos, BlockState state, CallbackInfo ci, Direction direction) { if (!this.isSticky) { Block block = CraftBlock.at(worldIn, pos); BlockPistonRetractEvent event = new BlockPistonRetractEvent(block, ImmutableList.of(), CraftBlock.notchToBlockFace(direction)); @@ -45,14 +45,14 @@ public class PistonBlockMixin { } } - @Inject(method = "doMove", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/block/PistonBlockStructureHelper;getBlocksToDestroy()Ljava/util/List;")) - public void arclight$pistonAction(World worldIn, BlockPos pos, Direction directionIn, boolean extending, CallbackInfoReturnable cir, - BlockPos blockPos, PistonBlockStructureHelper helper) { + @Inject(method = "moveBlocks", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, + at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/block/piston/PistonStructureResolver;getToDestroy()Ljava/util/List;")) + public void arclight$pistonAction(Level worldIn, BlockPos pos, Direction directionIn, boolean extending, CallbackInfoReturnable cir, + BlockPos blockPos, PistonStructureResolver helper) { final Block craftBlock = CraftBlock.at(worldIn, pos); - final List moved = helper.getBlocksToMove(); - final List broken = helper.getBlocksToDestroy(); + final List moved = helper.getToPush(); + final List broken = helper.getToDestroy(); class BlockList extends AbstractList { @@ -84,12 +84,12 @@ public class PistonBlockMixin { if (event.isCancelled()) { for (BlockPos b : broken) { - worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3); + worldIn.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), worldIn.getBlockState(b), 3); } for (BlockPos b : moved) { - worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3); - b = b.offset(direction); - worldIn.notifyBlockUpdate(b, Blocks.AIR.getDefaultState(), worldIn.getBlockState(b), 3); + worldIn.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), worldIn.getBlockState(b), 3); + b = b.relative(direction); + worldIn.sendBlockUpdated(b, Blocks.AIR.defaultBlockState(), worldIn.getBlockState(b), 3); } cir.setReturnValue(false); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalInfoMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalInfoMixin.java similarity index 68% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalInfoMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalInfoMixin.java index 22fce6de..97e8d9f0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PortalInfoMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalInfoMixin.java @@ -1,15 +1,15 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.block.PortalInfoBridge; -import net.minecraft.block.PortalInfo; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.portal.PortalInfo; import org.bukkit.craftbukkit.v.event.CraftPortalEvent; import org.spongepowered.asm.mixin.Mixin; @Mixin(PortalInfo.class) public class PortalInfoMixin implements PortalInfoBridge { - public ServerWorld world; + public ServerLevel world; public CraftPortalEvent portalEventInfo; @Override @@ -23,12 +23,12 @@ public class PortalInfoMixin implements PortalInfoBridge { } @Override - public void bridge$setWorld(ServerWorld world) { + public void bridge$setWorld(ServerLevel world) { this.world = world; } @Override - public ServerWorld bridge$getWorld() { + public ServerLevel bridge$getWorld() { return this.world; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalSizeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalSizeMixin.java new file mode 100644 index 00000000..183c54aa --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PortalSizeMixin.java @@ -0,0 +1,107 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.block.PortalInfoBridge; +import io.izzel.arclight.common.bridge.block.PortalSizeBridge; +import io.izzel.arclight.common.bridge.world.IWorldBridge; +import io.izzel.arclight.common.bridge.world.WorldBridge; +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.BlockUtil; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.NetherPortalBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.portal.PortalInfo; +import net.minecraft.world.level.portal.PortalShape; +import net.minecraft.world.phys.Vec3; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.block.CraftBlockState; +import org.bukkit.craftbukkit.v.event.CraftPortalEvent; +import org.bukkit.event.world.PortalCreateEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; + +@Mixin(PortalShape.class) +public abstract class PortalSizeMixin implements PortalSizeBridge { + + // @formatter:off + @Shadow @Final private LevelAccessor level; + @Shadow public abstract void createPortalBlocks(); + @Shadow @Final private Direction.Axis axis; + @Shadow @Nullable private BlockPos bottomLeft; + @Shadow private int height; + @Shadow @Final private Direction rightDir; + @Shadow private int width; + @Shadow public static PortalInfo createPortalInfo(ServerLevel world, BlockUtil.FoundRectangle result, Direction.Axis axis, Vec3 offsetVector, EntityDimensions size, Vec3 motion, float rotationYaw, float rotationPitch) { return null; } + // @formatter:on + + List blocks = new ArrayList<>(); + + @Redirect(method = "getDistanceUntilEdgeAboveFrame", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;test(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Z")) + private boolean arclight$captureBlock(BlockBehaviour.StatePredicate predicate, net.minecraft.world.level.block.state.BlockState p_test_1_, BlockGetter p_test_2_, BlockPos pos) { + boolean test = predicate.test(p_test_1_, p_test_2_, pos); + if (test) { + blocks.add(CraftBlock.at(this.level, pos).getState()); + } + return test; + } + + @Inject(method = "createPortalBlocks", cancellable = true, at = @At("HEAD")) + private void arclight$buildPortal(CallbackInfo ci) { + World world = ((WorldBridge) ((IWorldBridge) this.level).bridge$getMinecraftWorld()).bridge$getWorld(); + net.minecraft.world.level.block.state.BlockState blockState = Blocks.NETHER_PORTAL.defaultBlockState().setValue(NetherPortalBlock.AXIS, this.axis); + BlockPos.betweenClosed(this.bottomLeft, this.bottomLeft.relative(Direction.UP, this.height - 1).relative(this.rightDir, this.width - 1)).forEach(pos -> { + CraftBlockState state = CraftBlockState.getBlockState(((IWorldBridge) this.level).bridge$getMinecraftWorld(), pos, 18); + state.setData(blockState); + this.blocks.add(state); + }); + PortalCreateEvent event = new PortalCreateEvent(this.blocks, world, null, PortalCreateEvent.CreateReason.FIRE); + Bukkit.getPluginManager().callEvent(event); + arclight$ret = !event.isCancelled(); + if (event.isCancelled()) { + ci.cancel(); + } + } + + private transient boolean arclight$ret; + + public boolean createPortal() { + this.createPortalBlocks(); + return arclight$ret; + } + + @Override + public boolean bridge$createPortal() { + return createPortal(); + } + + @SuppressWarnings("ConstantConditions") + @Redirect(method = "createPortalInfo", at = @At(value = "NEW", target = "net/minecraft/world/level/portal/PortalInfo")) + private static PortalInfo arclight$setPortalInfo(Vec3 pos, Vec3 motion, float rotationYaw, float rotationPitch, ServerLevel world) { + PortalInfo portalInfo = new PortalInfo(pos, motion, rotationYaw, rotationPitch); + ((PortalInfoBridge) portalInfo).bridge$setWorld(world); + ((PortalInfoBridge) portalInfo).bridge$setPortalEventInfo(ArclightCaptures.getCraftPortalEvent()); + return portalInfo; + } + + private static PortalInfo a(ServerLevel world, BlockUtil.FoundRectangle result, Direction.Axis axis, Vec3 offsetVector, EntityDimensions size, Vec3 motion, float rotationYaw, float rotationPitch, CraftPortalEvent event) { + ArclightCaptures.captureCraftPortalEvent(event); + return createPortalInfo(world, result, axis, offsetVector, size, motion, rotationYaw, rotationPitch); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PoweredRailBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PoweredRailBlockMixin.java similarity index 64% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PoweredRailBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PoweredRailBlockMixin.java index ddcd8a03..cd33a4e0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PoweredRailBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PoweredRailBlockMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.PoweredRailBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.PoweredRailBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -16,8 +16,8 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class PoweredRailBlockMixin { @Inject(method = "updateState", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockRedstone(BlockState state, World worldIn, BlockPos pos, Block blockIn, CallbackInfo ci, boolean flag) { + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockRedstone(BlockState state, Level worldIn, BlockPos pos, Block blockIn, CallbackInfo ci, boolean flag) { int power = flag ? 15 : 0; int newPower = CraftEventFactory.callRedstoneChange(worldIn, pos, power, 15 - power).getNewCurrent(); if (newPower == power) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PressurePlateBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PressurePlateBlockMixin.java similarity index 60% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PressurePlateBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PressurePlateBlockMixin.java index ecc48c46..00de77c9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/PressurePlateBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/PressurePlateBlockMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.PressurePlateBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.PressurePlateBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -23,11 +23,11 @@ import org.spongepowered.asm.mixin.Shadow; import java.util.List; @Mixin(PressurePlateBlock.class) -public abstract class PressurePlateBlockMixin extends AbstractPressurePlateBlockMixin { +public abstract class PressurePlateBlockMixin extends BasePressurePlateBlockMixin { // @formatter:off @Shadow @Final private PressurePlateBlock.Sensitivity sensitivity; - @Shadow protected abstract int getRedstoneStrength(BlockState state); + @Shadow protected abstract int getSignalForState(BlockState state); // @formatter:on /** @@ -35,15 +35,15 @@ public abstract class PressurePlateBlockMixin extends AbstractPressurePlateBlock * @reason */ @Overwrite - protected int computeRedstoneStrength(World worldIn, BlockPos pos) { - AxisAlignedBB axisalignedbb = PRESSURE_AABB.offset(pos); + protected int getSignalStrength(Level worldIn, BlockPos pos) { + AABB axisalignedbb = TOUCH_AABB.move(pos); List list; switch (this.sensitivity) { case EVERYTHING: - list = worldIn.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb); + list = worldIn.getEntities(null, axisalignedbb); break; case MOBS: - list = worldIn.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb); + list = worldIn.getEntitiesOfClass(LivingEntity.class, axisalignedbb); break; default: return 0; @@ -51,11 +51,11 @@ public abstract class PressurePlateBlockMixin extends AbstractPressurePlateBlock if (!list.isEmpty()) { for (Entity entity : list) { - if (this.getRedstoneStrength(worldIn.getBlockState(pos)) == 0) { + if (this.getSignalForState(worldIn.getBlockState(pos)) == 0) { Cancellable cancellable; - if (entity instanceof PlayerEntity) { - cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, pos, null, null, null); + if (entity instanceof Player) { + cancellable = CraftEventFactory.callPlayerInteractEvent((Player) entity, Action.PHYSICAL, pos, null, null, null); } else { cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos)); Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); @@ -66,7 +66,7 @@ public abstract class PressurePlateBlockMixin extends AbstractPressurePlateBlock continue; } } - if (!entity.doesEntityNotTriggerPressurePlate()) { + if (!entity.isIgnoringBlockTriggers()) { return 15; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneLampBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneLampBlockMixin.java similarity index 53% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneLampBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneLampBlockMixin.java index 3784979a..4e2ed69c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneLampBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneLampBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneLampBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RedstoneLampBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -17,15 +17,15 @@ import java.util.Random; @Mixin(RedstoneLampBlock.class) public class RedstoneLampBlockMixin { - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$redstoneChange(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) { + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$redstoneChange(BlockState state, ServerLevel worldIn, BlockPos pos, Random rand, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 15, 0).getNewCurrent() != 0) { ci.cancel(); } } - @Inject(method = "neighborChanged", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void arclight$blockRedstone(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving, CallbackInfo ci) { + @Inject(method = "neighborChanged", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void arclight$blockRedstone(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving, CallbackInfo ci) { if (CraftEventFactory.callRedstoneChange(worldIn, pos, 0, 15).getNewCurrent() != 15) { ci.cancel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneOreBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneOreBlockMixin.java new file mode 100644 index 00000000..6c156aaf --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneOreBlockMixin.java @@ -0,0 +1,85 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.RedStoneOreBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Random; + +@Mixin(RedStoneOreBlock.class) +public abstract class RedstoneOreBlockMixin { + + // @formatter:off + @Shadow private static void interact(BlockState state, Level world, BlockPos pos) { } + // @formatter:on + + private static transient Entity arclight$entity; + + @Inject(method = "attack", at = @At(value = "HEAD")) + public void arclight$interact1(BlockState state, Level worldIn, BlockPos pos, Player player, CallbackInfo ci) { + arclight$entity = player; + } + + @Inject(method = "stepOn", cancellable = true, at = @At(value = "HEAD")) + public void arclight$entityInteract(Level worldIn, BlockPos pos, BlockState state, Entity entityIn, CallbackInfo ci) { + if (entityIn instanceof Player) { + PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(((Player) entityIn), Action.PHYSICAL, pos, null, null, null); + if (event.isCancelled()) { + ci.cancel(); + return; + } + } else { + EntityInteractEvent event = new EntityInteractEvent(((EntityBridge) entityIn).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos)); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + ci.cancel(); + return; + } + } + arclight$entity = entityIn; + } + + @Inject(method = "use", at = @At(value = "HEAD")) + public void arclight$interact3(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, CallbackInfoReturnable cir) { + arclight$entity = player; + } + + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, state.setValue(RedStoneOreBlock.LIT, false)).isCancelled()) { + ci.cancel(); + } + } + + private static void interact(BlockState blockState, Level world, BlockPos blockPos, Entity entity) { + arclight$entity = entity; + interact(blockState, world, blockPos); + } + + @Inject(method = "interact", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void arclight$entityChangeBlock(BlockState blockState, Level world, BlockPos blockPos, CallbackInfo ci) { + if (CraftEventFactory.callEntityChangeBlockEvent(arclight$entity, blockPos, blockState.setValue(RedStoneOreBlock.LIT, true)).isCancelled()) { + ci.cancel(); + } + arclight$entity = null; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneTorchBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneTorchBlockMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneTorchBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneTorchBlockMixin.java index e09795ee..588a39c5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/RedstoneTorchBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneTorchBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneTorchBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.RedstoneTorchBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.BlockRedstoneEvent; @@ -17,9 +17,9 @@ import java.util.Random; @Mixin(RedstoneTorchBlock.class) public class RedstoneTorchBlockMixin { - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$blockRedstone1(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) { - int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0; + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$blockRedstone1(BlockState state, ServerLevel worldIn, BlockPos pos, Random rand, CallbackInfo ci) { + int oldCurrent = state.getValue(RedstoneTorchBlock.LIT) ? 15 : 0; if (oldCurrent != 0) { CraftBlock block = CraftBlock.at(worldIn, pos); BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, 0); @@ -30,9 +30,9 @@ public class RedstoneTorchBlockMixin { } } - @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void arclight$blockRedstone2(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand, CallbackInfo ci) { - int oldCurrent = state.get(RedstoneTorchBlock.LIT) ? 15 : 0; + @Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$blockRedstone2(BlockState state, ServerLevel worldIn, BlockPos pos, Random rand, CallbackInfo ci) { + int oldCurrent = state.getValue(RedstoneTorchBlock.LIT) ? 15 : 0; if (oldCurrent != 15) { CraftBlock block = CraftBlock.at(worldIn, pos); BlockRedstoneEvent event = new BlockRedstoneEvent(block, oldCurrent, 15); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneWireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneWireBlockMixin.java new file mode 100644 index 00000000..a974ace3 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/RedstoneWireBlockMixin.java @@ -0,0 +1,33 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.RedStoneWireBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.event.block.BlockRedstoneEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(RedStoneWireBlock.class) +public abstract class RedstoneWireBlockMixin { + + // @formatter:off + @Shadow protected abstract int calculateTargetStrength(Level world, BlockPos pos); + // @formatter:on + + @Redirect(method = "updatePowerStrength", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/RedStoneWireBlock;calculateTargetStrength(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)I")) + public int arclight$blockRedstone(RedStoneWireBlock redstoneWireBlock, Level world, BlockPos pos, Level world1, BlockPos pos1, BlockState state) { + int i = this.calculateTargetStrength(world, pos); + int oldPower = state.getValue(RedStoneWireBlock.POWER); + if (oldPower != i) { + BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, pos), oldPower, i); + Bukkit.getPluginManager().callEvent(event); + i = event.getNewCurrent(); + } + return i; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SaplingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SaplingBlockMixin.java similarity index 92% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SaplingBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SaplingBlockMixin.java index 8f7381a1..10fe3c87 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SaplingBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SaplingBlockMixin.java @@ -1,6 +1,6 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.SaplingBlock; +import net.minecraft.world.level.block.SaplingBlock; import org.spongepowered.asm.mixin.Mixin; // todo Re-implement this diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ScaffoldingBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ScaffoldingBlockMixin.java new file mode 100644 index 00000000..c870ac68 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/ScaffoldingBlockMixin.java @@ -0,0 +1,32 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ScaffoldingBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Property; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Random; + +@Mixin(ScaffoldingBlock.class) +public class ScaffoldingBlockMixin { + + @Redirect(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/block/state/BlockState;getValue(Lnet/minecraft/world/level/block/state/properties/Property;)Ljava/lang/Comparable;")) + public Comparable arclight$blockFade(BlockState state, Property property, BlockState blockState, ServerLevel worldIn, BlockPos pos, Random random) { + Integer integer = state.getValue(property); + if (integer == 7) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { + return 6; + } else { + return integer; + } + } else { + return integer; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SnowBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SnowBlockMixin.java new file mode 100644 index 00000000..c1f01d97 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SnowBlockMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SnowLayerBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(SnowLayerBlock.class) +public class SnowBlockMixin { + + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/SnowLayerBlock;dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpongeBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpongeBlockMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpongeBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpongeBlockMixin.java index 93dcc5f4..6354c9c7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/SpongeBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpongeBlockMixin.java @@ -1,21 +1,20 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import com.google.common.collect.Lists; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FlowingFluidBlock; -import net.minecraft.block.IBucketPickupHandler; -import net.minecraft.block.SpongeBlock; -import net.minecraft.block.material.Material; -import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.Fluids; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.tags.FluidTags; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.block.SpongeBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Material; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.block.CraftBlockState; @@ -36,7 +35,7 @@ public class SpongeBlockMixin { */ @SuppressWarnings("unchecked") @Overwrite - private boolean absorb(World worldIn, BlockPos pos) { + private boolean removeWaterBreadthFirstSearch(Level worldIn, BlockPos pos) { Queue> queue = Lists.newLinkedList(); queue.add(new Tuple<>(pos, 0)); int i = 0; @@ -48,26 +47,26 @@ public class SpongeBlockMixin { int j = tuple.getB(); for (Direction direction : Direction.values()) { - BlockPos blockpos1 = blockpos.offset(direction); + BlockPos blockpos1 = blockpos.relative(direction); BlockState blockstate = blockList.getBlockState(blockpos1); FluidState ifluidstate = blockList.getFluidState(blockpos1); Material material = blockstate.getMaterial(); - if (ifluidstate.isTagged(FluidTags.WATER)) { - if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) { + if (ifluidstate.is(FluidTags.WATER)) { + if (blockstate.getBlock() instanceof BucketPickup && !((BucketPickup) blockstate.getBlock()).pickupBlock(worldIn, blockpos1, blockstate).isEmpty()) { ++i; if (j < 6) { queue.add(new Tuple<>(blockpos1, j + 1)); } - } else if (blockstate.getBlock() instanceof FlowingFluidBlock) { - worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3); + } else if (blockstate.getBlock() instanceof LiquidBlock) { + worldIn.setBlock(blockpos1, Blocks.AIR.defaultBlockState(), 3); ++i; if (j < 6) { queue.add(new Tuple<>(blockpos1, j + 1)); } - } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) { + } else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) { //TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null; // Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity); - blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3); + blockList.setBlock(blockpos1, Blocks.AIR.defaultBlockState(), 3); ++i; if (j < 6) { queue.add(new Tuple<>(blockpos1, j + 1)); @@ -98,18 +97,18 @@ public class SpongeBlockMixin { FluidState fluid = worldIn.getFluidState(blockposition2); Material material = iblockdata.getMaterial(); - if (fluid.isTagged(FluidTags.WATER)) { - if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) { + if (fluid.is(FluidTags.WATER)) { + if (iblockdata.getBlock() instanceof BucketPickup && !((BucketPickup) iblockdata.getBlock()).pickupBlock(blockList, blockposition2, iblockdata).isEmpty()) { // NOP - } else if (iblockdata.getBlock() instanceof FlowingFluidBlock) { + } else if (iblockdata.getBlock() instanceof LiquidBlock) { // NOP - } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) { - TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null; + } else if (material == Material.WATER_PLANT || material == Material.REPLACEABLE_WATER_PLANT) { + BlockEntity tileentity = iblockdata.hasBlockEntity() ? worldIn.getBlockEntity(blockposition2) : null; - Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity); + Block.dropResources(iblockdata, worldIn, blockposition2, tileentity); } } - worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag()); + worldIn.setBlock(blockposition2, block.getHandle(), block.getFlag()); } } return i > 0; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpreadableSnowyDirtBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpreadableSnowyDirtBlockMixin.java new file mode 100644 index 00000000..bcc07f0a --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SpreadableSnowyDirtBlockMixin.java @@ -0,0 +1,31 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SpreadingSnowyDirtBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(SpreadingSnowyDirtBlock.class) +public class SpreadableSnowyDirtBlockMixin { + + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public void arclight$blockFade(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.DIRT.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean arclight$blockSpread(ServerLevel world, BlockPos to, BlockState state, BlockState state1, ServerLevel worldIn, BlockPos from) { + return CraftEventFactory.handleBlockSpreadEvent(world, from, to, state); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/StemBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/StemBlockMixin.java new file mode 100644 index 00000000..e032d2ea --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/StemBlockMixin.java @@ -0,0 +1,43 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.StemBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(StemBlock.class) +public class StemBlockMixin { + + private transient boolean arclight$success = false; + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$cropGrow1(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } + + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public void arclight$returnIfFail(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (!arclight$success) { + ci.cancel(); + } + arclight$success = false; + } + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean arclight$cropGrow2(ServerLevel world, BlockPos pos, BlockState state) { + return arclight$success = CraftEventFactory.handleBlockGrowEvent(world, pos, state); + } + + @Redirect(method = "performBonemeal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$cropGrow3(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SugarCaneBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SugarCaneBlockMixin.java new file mode 100644 index 00000000..10cee992 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SugarCaneBlockMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.SugarCaneBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(SugarCaneBlock.class) +public class SugarCaneBlockMixin { + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean arclight$cropGrow(ServerLevel world, BlockPos pos, BlockState state) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, state); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SweetBerryBushBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SweetBerryBushBlockMixin.java new file mode 100644 index 00000000..c8cb0df4 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/SweetBerryBushBlockMixin.java @@ -0,0 +1,65 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.SweetBerryBushBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.player.PlayerHarvestBlockEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Collections; + +@Mixin(SweetBerryBushBlock.class) +public class SweetBerryBushBlockMixin { + + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public boolean arclight$cropGrow(ServerLevel world, BlockPos pos, BlockState newState, int flags) { + return CraftEventFactory.handleBlockGrowEvent(world, pos, newState, flags); + } + + @Inject(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + public void arclight$damagePre(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + CraftEventFactory.blockDamage = CraftBlock.at(worldIn, pos); + } + + @Inject(method = "entityInside", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + public void arclight$damagePost(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + CraftEventFactory.blockDamage = null; + } + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/SweetBerryBushBlock;popResource(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/item/ItemStack;)V")) + private void arclight$playerHarvest(Level worldIn, BlockPos pos, ItemStack stack, BlockState state, Level worldIn1, BlockPos pos1, Player player) { + PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(worldIn, pos, player, Collections.singletonList(stack)); + arclight$ret = event.isCancelled(); + if (!event.isCancelled()) { + for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) { + Block.popResource(worldIn, pos, CraftItemStack.asNMSCopy(itemStack)); + } + } + } + + private transient boolean arclight$ret; + + @Inject(method = "use", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + private void arclight$returnIfFail(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit, CallbackInfoReturnable cir) { + if (arclight$ret) { + cir.setReturnValue(InteractionResult.SUCCESS); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin.java new file mode 100644 index 00000000..b730eb3e --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TntBlockMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.TntBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TntBlock.class) +public class TntBlockMixin { + + @Inject(method = "onProjectileHit", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraft/world/level/block/TntBlock;catchFire(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Direction;Lnet/minecraft/world/entity/LivingEntity;)V")) + public void arclight$entityChangeBlock(Level worldIn, BlockState state, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { + if (CraftEventFactory.callEntityChangeBlockEvent(projectile, hit.getBlockPos(), Blocks.AIR.defaultBlockState()).isCancelled()) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TrapDoorBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TrapDoorBlockMixin.java similarity index 50% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TrapDoorBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TrapDoorBlockMixin.java index 866b78f1..a05a50cf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TrapDoorBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TrapDoorBlockMixin.java @@ -1,10 +1,10 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.TrapDoorBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.BlockRedstoneEvent; @@ -15,15 +15,15 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(TrapDoorBlock.class) public class TrapDoorBlockMixin { - @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isBlockPowered(Lnet/minecraft/util/math/BlockPos;)Z")) - public boolean arclight$blockRedstone(World world, BlockPos pos, BlockState state, World worldIn, BlockPos blockPos, Block blockIn, BlockPos fromPos, boolean isMoving) { - boolean flag = world.isBlockPowered(pos); - if (flag != state.get(TrapDoorBlock.POWERED)) { + @Redirect(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;hasNeighborSignal(Lnet/minecraft/core/BlockPos;)Z")) + public boolean arclight$blockRedstone(Level world, BlockPos pos, BlockState state, Level worldIn, BlockPos blockPos, Block blockIn, BlockPos fromPos, boolean isMoving) { + boolean flag = world.hasNeighborSignal(pos); + if (flag != state.getValue(TrapDoorBlock.POWERED)) { org.bukkit.block.Block craftBlock = CraftBlock.at(world, pos); int power = craftBlock.getBlockPower(); - int oldPower = state.get(TrapDoorBlock.OPEN) ? 15 : 0; + int oldPower = state.getValue(TrapDoorBlock.OPEN) ? 15 : 0; - if (oldPower == 0 ^ power == 0 || blockIn.getDefaultState().canProvidePower()) { + if (oldPower == 0 ^ power == 0 || blockIn.defaultBlockState().isSignalSource()) { BlockRedstoneEvent event = new BlockRedstoneEvent(craftBlock, oldPower, power); Bukkit.getPluginManager().callEvent(event); return event.getNewCurrent() > 0; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireBlockMixin.java similarity index 61% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireBlockMixin.java index cfa074cd..9b30808d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireBlockMixin.java @@ -1,14 +1,14 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.TripWireBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.BooleanProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.TripWireBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -27,7 +27,7 @@ public abstract class TripWireBlockMixin extends BlockMixin { // @formatter:off @Shadow @Final public static BooleanProperty POWERED; - @Shadow protected abstract void notifyHook(World worldIn, BlockPos pos, BlockState state); + @Shadow protected abstract void updateSource(Level worldIn, BlockPos pos, BlockState state); // @formatter:on /** @@ -35,21 +35,21 @@ public abstract class TripWireBlockMixin extends BlockMixin { * @reason */ @Overwrite - private void updateState(World worldIn, BlockPos pos) { + private void checkPressed(Level worldIn, BlockPos pos) { BlockState blockstate = worldIn.getBlockState(pos); - boolean flag = blockstate.get(POWERED); + boolean flag = blockstate.getValue(POWERED); boolean flag1 = false; - List list = worldIn.getEntitiesWithinAABBExcludingEntity(null, blockstate.getShape(worldIn, pos).getBoundingBox().offset(pos)); + List list = worldIn.getEntities(null, blockstate.getShape(worldIn, pos).bounds().move(pos)); if (!list.isEmpty()) { for (Entity entity : list) { - if (!entity.doesEntityNotTriggerPressurePlate()) { + if (!entity.isIgnoringBlockTriggers()) { flag1 = true; break; } } } - if (flag != flag1 && flag1 && blockstate.get(TripWireBlock.ATTACHED)) { + if (flag != flag1 && flag1 && blockstate.getValue(TripWireBlock.ATTACHED)) { org.bukkit.block.Block block = CraftBlock.at(worldIn, pos); boolean allowed = false; @@ -58,8 +58,8 @@ public abstract class TripWireBlockMixin extends BlockMixin { if (object != null) { Cancellable cancellable; - if (object instanceof PlayerEntity) { - cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) object, Action.PHYSICAL, pos, null, null, null); + if (object instanceof Player) { + cancellable = CraftEventFactory.callPlayerInteractEvent((Player) object, Action.PHYSICAL, pos, null, null, null); } else if (object instanceof Entity) { cancellable = new EntityInteractEvent(((EntityBridge) object).bridge$getBukkitEntity(), block); Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); @@ -80,13 +80,13 @@ public abstract class TripWireBlockMixin extends BlockMixin { } if (flag1 != flag) { - blockstate = blockstate.with(POWERED, flag1); - worldIn.setBlockState(pos, blockstate, 3); - this.notifyHook(worldIn, pos, blockstate); + blockstate = blockstate.setValue(POWERED, flag1); + worldIn.setBlock(pos, blockstate, 3); + this.updateSource(worldIn, pos, blockstate); } if (flag1) { - worldIn.getPendingBlockTicks().scheduleTick(new BlockPos(pos), (Block) (Object) this, 10); + worldIn.getBlockTicks().scheduleTick(new BlockPos(pos), (Block) (Object) this, 10); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireHookBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireHookBlockMixin.java similarity index 62% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireHookBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireHookBlockMixin.java index 5be8f1ef..b2461764 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TripWireHookBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TripWireHookBlockMixin.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; -import net.minecraft.block.BlockState; -import net.minecraft.block.TripWireHookBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.TripWireHookBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.block.BlockRedstoneEvent; @@ -15,8 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(TripWireHookBlock.class) public class TripWireHookBlockMixin { - @Inject(method = "calculateState", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/block/TripWireHookBlock;playSound(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ZZZZ)V")) - public void arclight$blockRedstone(World worldIn, BlockPos pos, BlockState hookState, boolean attaching, boolean shouldNotifyNeighbours, int searchRange, BlockState state, CallbackInfo ci) { + @Inject(method = "calculateState", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/level/block/TripWireHookBlock;playSound(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;ZZZZ)V")) + public void arclight$blockRedstone(Level worldIn, BlockPos pos, BlockState hookState, boolean attaching, boolean shouldNotifyNeighbours, int searchRange, BlockState state, CallbackInfo ci) { BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(worldIn, pos), 15, 0); Bukkit.getPluginManager().callEvent(event); if (event.getNewCurrent() > 0) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TurtleEggBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TurtleEggBlockMixin.java similarity index 54% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TurtleEggBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TurtleEggBlockMixin.java index ff21c584..c3a2f9d9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/TurtleEggBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/TurtleEggBlockMixin.java @@ -1,16 +1,16 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.TurtleEggBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.IntegerProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.TurtleEggBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.IntegerProperty; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -35,32 +35,32 @@ public class TurtleEggBlockMixin { @Shadow @Final public static IntegerProperty HATCH; @Inject(method = "randomTick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, - at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) - private void arclight$hatch(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci, int i) { - if (!CraftEventFactory.handleBlockGrowEvent(worldIn, pos, state.with(HATCH, i + 1), 2)) { + at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + private void arclight$hatch(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci, int i) { + if (!CraftEventFactory.handleBlockGrowEvent(worldIn, pos, state.setValue(HATCH, i + 1), 2)) { ci.cancel(); } } - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private boolean arclight$handledHatch(ServerWorld world, BlockPos pos, BlockState newState, int flags) { + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private boolean arclight$handledHatch(ServerLevel world, BlockPos pos, BlockState newState, int flags) { return true; } - @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V")) - private void arclight$born(BlockState state, ServerWorld worldIn, BlockPos pos, Random random, CallbackInfo ci) { - if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.getDefaultState()).isCancelled()) { + @Inject(method = "randomTick", cancellable = true, at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;playSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + private void arclight$born(BlockState state, ServerLevel worldIn, BlockPos pos, Random random, CallbackInfo ci) { + if (CraftEventFactory.callBlockFadeEvent(worldIn, pos, Blocks.AIR.defaultBlockState()).isCancelled()) { ci.cancel(); } else { ((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.EGG); } } - @Inject(method = "tryTrample", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/TurtleEggBlock;removeOneEgg(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V")) - public void arclight$stepOn(World world, BlockPos pos, Entity entity, int i, CallbackInfo ci) { + @Inject(method = "destroyEgg", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/TurtleEggBlock;decreaseEggs(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V")) + public void arclight$stepOn(Level world, BlockState state, BlockPos pos, Entity entity, int i, CallbackInfo ci) { Cancellable cancellable; - if (entity instanceof PlayerEntity) { - cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, pos, null, null, null); + if (entity instanceof Player) { + cancellable = CraftEventFactory.callPlayerInteractEvent((Player) entity, Action.PHYSICAL, pos, null, null, null); } else { cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(world, pos)); Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/VineBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/VineBlockMixin.java new file mode 100644 index 00000000..730a4e3e --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/VineBlockMixin.java @@ -0,0 +1,115 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.VineBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Random; + +@Mixin(VineBlock.class) +public abstract class VineBlockMixin extends BlockMixin { + + // @formatter:off + @Shadow public static BooleanProperty getPropertyForFace(Direction side) { return null; } + @Shadow protected abstract boolean canSpread(BlockGetter blockReader, BlockPos pos); + @Shadow public static boolean isAcceptableNeighbour(BlockGetter blockReader, BlockPos worldIn, Direction neighborPos) { return false; } + @Shadow @Final public static BooleanProperty UP; + @Shadow protected abstract boolean canSupportAtFace(BlockGetter blockReader, BlockPos pos, Direction direction); + @Shadow protected abstract boolean hasHorizontalConnection(BlockState state); + @Shadow protected abstract BlockState copyRandomFaces(BlockState state, BlockState state2, Random rand); + // @formatter:on + + /** + * @author IzzelAliz + * @reason + */ + @SuppressWarnings("ConstantConditions") + @Overwrite + public void randomTick(BlockState state, ServerLevel worldIn, BlockPos pos, Random random) { + if (worldIn.random.nextInt(4) == 0 && worldIn.isAreaLoaded(pos, 4)) { // Forge: check area to prevent loading unloaded chunks + Direction direction = Direction.getRandom(random); + BlockPos blockpos = pos.above(); + if (direction.getAxis().isHorizontal() && !state.getValue(getPropertyForFace(direction))) { + if (this.canSpread(worldIn, pos)) { + BlockPos blockpos4 = pos.relative(direction); + BlockState blockstate4 = worldIn.getBlockState(blockpos4); + if (blockstate4.isAir()) { + Direction direction3 = direction.getClockWise(); + Direction direction4 = direction.getCounterClockWise(); + boolean flag = state.getValue(getPropertyForFace(direction3)); + boolean flag1 = state.getValue(getPropertyForFace(direction4)); + BlockPos blockpos2 = blockpos4.relative(direction3); + BlockPos blockpos3 = blockpos4.relative(direction4); + if (flag && isAcceptableNeighbour(worldIn, blockpos2, direction3)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.defaultBlockState().setValue(getPropertyForFace(direction3), Boolean.TRUE), 2); + } else if (flag1 && isAcceptableNeighbour(worldIn, blockpos3, direction4)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.defaultBlockState().setValue(getPropertyForFace(direction4), Boolean.TRUE), 2); + } else { + Direction direction1 = direction.getOpposite(); + if (flag && worldIn.isEmptyBlock(blockpos2) && isAcceptableNeighbour(worldIn, pos.relative(direction3), direction1)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos2, this.defaultBlockState().setValue(getPropertyForFace(direction1), Boolean.TRUE), 2); + } else if (flag1 && worldIn.isEmptyBlock(blockpos3) && isAcceptableNeighbour(worldIn, pos.relative(direction4), direction1)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos3, this.defaultBlockState().setValue(getPropertyForFace(direction1), Boolean.TRUE), 2); + } else if ((double) worldIn.random.nextFloat() < 0.05D && isAcceptableNeighbour(worldIn, blockpos4.above(), Direction.UP)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos4, this.defaultBlockState().setValue(UP, Boolean.TRUE), 2); + } + } + } else if (isAcceptableNeighbour(worldIn, blockpos4, direction)) { + worldIn.setBlock(pos, state.setValue(getPropertyForFace(direction), Boolean.TRUE), 2); + } + + } + } else { + if (direction == Direction.UP && pos.getY() < worldIn.getMaxBuildHeight() - 1) { + if (this.canSupportAtFace(worldIn, pos, direction)) { + worldIn.setBlock(pos, state.setValue(UP, Boolean.TRUE), 2); + return; + } + + if (worldIn.isEmptyBlock(blockpos)) { + if (!this.canSpread(worldIn, pos)) { + return; + } + + BlockState blockstate3 = state; + + for (Direction direction2 : Direction.Plane.HORIZONTAL) { + if (random.nextBoolean() || !isAcceptableNeighbour(worldIn, blockpos.relative(direction2), Direction.UP)) { + blockstate3 = blockstate3.setValue(getPropertyForFace(direction2), Boolean.FALSE); + } + } + + if (this.hasHorizontalConnection(blockstate3)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos, blockstate3, 2); + } + + return; + } + } + + if (pos.getY() > worldIn.getMinBuildHeight()) { + BlockPos blockpos1 = pos.below(); + BlockState blockstate = worldIn.getBlockState(blockpos1); + boolean isAir = blockstate.isAir(); + if (isAir || blockstate.is((Block) (Object) this)) { + BlockState blockstate1 = isAir ? this.defaultBlockState() : blockstate; + BlockState blockstate2 = this.copyRandomFaces(state, blockstate1, random); + if (blockstate1 != blockstate2 && this.hasHorizontalConnection(blockstate2)) { + CraftEventFactory.handleBlockSpreadEvent(worldIn, pos, blockpos1, blockstate2, 2); + } + } + } + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WeightedPressurePlateBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WeightedPressurePlateBlockMixin.java similarity index 67% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WeightedPressurePlateBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WeightedPressurePlateBlockMixin.java index 571b6ac7..bca4ca76 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WeightedPressurePlateBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WeightedPressurePlateBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.EntityBridge; -import net.minecraft.block.WeightedPressurePlateBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.WeightedPressurePlateBlock; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -21,14 +21,14 @@ import java.util.List; @Mixin(WeightedPressurePlateBlock.class) public class WeightedPressurePlateBlockMixin { - @Redirect(method = "computeRedstoneStrength", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/List;size()I")) - public int arclight$entityInteract(List list, World worldIn, BlockPos pos) { + @Redirect(method = "getSignalStrength", at = @At(value = "INVOKE", remap = false, target = "Ljava/util/List;size()I")) + public int arclight$entityInteract(List list, Level worldIn, BlockPos pos) { int i = 0; for (Entity entity : list) { Cancellable cancellable; - if (entity instanceof PlayerEntity) { - cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, pos, null, null, null); + if (entity instanceof Player) { + cancellable = CraftEventFactory.callPlayerInteractEvent((Player) entity, Action.PHYSICAL, pos, null, null, null); } else { cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(worldIn, pos)); Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherRoseBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherRoseBlockMixin.java similarity index 51% rename from arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherRoseBlockMixin.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherRoseBlockMixin.java index 1ec7e6a9..f29c1233 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/block/WitherRoseBlockMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherRoseBlockMixin.java @@ -1,11 +1,11 @@ -package io.izzel.arclight.common.mixin.core.block; +package io.izzel.arclight.common.mixin.core.world.level.block; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.block.BlockState; -import net.minecraft.block.WitherRoseBlock; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.WitherRoseBlock; +import net.minecraft.world.level.block.state.BlockState; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -15,8 +15,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WitherRoseBlock.class) public class WitherRoseBlockMixin { - @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;addPotionEffect(Lnet/minecraft/potion/EffectInstance;)Z")) - private void arclight$cause(BlockState state, World worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + @Inject(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;)Z")) + private void arclight$cause(BlockState state, Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { ((LivingEntityBridge) entityIn).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.WITHER_ROSE); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherSkullBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherSkullBlockMixin.java new file mode 100644 index 00000000..9e4a6062 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/WitherSkullBlockMixin.java @@ -0,0 +1,60 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import io.izzel.arclight.common.bridge.world.WorldBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.WitherSkullBlock; +import net.minecraft.world.level.block.entity.SkullBlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.util.Constants; +import org.bukkit.craftbukkit.v.util.BlockStateListPopulator; +import org.bukkit.event.entity.CreatureSpawnEvent; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WitherSkullBlock.class) +public class WitherSkullBlockMixin { + + private static transient BlockStateListPopulator arclight$populator; + private static transient boolean arclight$success = false; + + @Redirect(method = "checkSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static boolean arclight$storeUpdate1(Level world, BlockPos pos, BlockState newState, int flags) { + if (arclight$populator == null) { + arclight$populator = new BlockStateListPopulator(world); + } + return arclight$populator.setBlock(pos, newState, flags); + } + + @Redirect(method = "checkSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(ILnet/minecraft/core/BlockPos;I)V")) + private static void arclight$storeUpdate2(Level world, int type, BlockPos pos, int data) { + // do nothing + } + + @Inject(method = "checkSpawn", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private static void arclight$returnIfFail(Level worldIn, BlockPos blockPos, SkullBlockEntity tileEntity, CallbackInfo ci) { + if (arclight$success) { + if (arclight$populator != null) { + for (BlockPos pos : arclight$populator.getBlocks()) { + worldIn.levelEvent(Constants.WorldEvents.BREAK_BLOCK_EFFECTS, pos, Block.getId(worldIn.getBlockState(pos))); + } + arclight$populator.updateList(); + } + } else { + ci.cancel(); + } + arclight$populator = null; + arclight$success = false; + } + + @Redirect(method = "checkSpawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private static boolean arclight$spawnWither(Level world, Entity entityIn) { + ((WorldBridge) world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BUILD_WITHER); + return arclight$success = world.addFreshEntity(entityIn); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviourMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviourMixin.java new file mode 100644 index 00000000..7bf10ec2 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviourMixin.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.common.mixin.core.world.level.block.state; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(BlockBehaviour.class) +public abstract class BlockBehaviourMixin { + + // @formatter:off + @Shadow public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { return null; } + // @formatter:on +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviour_BlockStateBaseMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviour_BlockStateBaseMixin.java new file mode 100644 index 00000000..f47396ac --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/state/BlockBehaviour_BlockStateBaseMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.level.block.state; + +import io.izzel.arclight.common.mod.util.ArclightCaptures; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockBehaviour; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(BlockBehaviour.BlockStateBase.class) +public class BlockBehaviour_BlockStateBaseMixin { + + @Inject(method = "entityInside", at = @At("HEAD")) + private void arclight$captureBlockCollide(Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + ArclightCaptures.captureDamageEventBlock(pos); + } + + @Inject(method = "entityInside", at = @At("RETURN")) + private void arclight$resetBlockCollide(Level worldIn, BlockPos pos, Entity entityIn, CallbackInfo ci) { + ArclightCaptures.captureDamageEventBlock(null); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidManagerMixin.java index 2065b40e..08c7341a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidManagerMixin.java @@ -1,11 +1,5 @@ package io.izzel.arclight.common.mixin.core.world.raid; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.potion.Effects; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.DimensionType; -import net.minecraft.world.raid.Raid; -import net.minecraft.world.raid.RaidManager; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -16,20 +10,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Map; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.raid.Raid; +import net.minecraft.world.entity.raid.Raids; +import net.minecraft.world.level.dimension.DimensionType; -@Mixin(RaidManager.class) +@Mixin(Raids.class) public class RaidManagerMixin { // @formatter:off - @Shadow @Final public Map byId; + @Shadow @Final public Map raidMap; // @formatter:on - @Inject(method = "badOmenTick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;increaseLevel(Lnet/minecraft/entity/player/PlayerEntity;)V")) - public void arclight$raidTrigger(ServerPlayerEntity playerEntity, CallbackInfoReturnable cir, + @Inject(method = "createOrExtendRaid", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;absorbBadOmen(Lnet/minecraft/world/entity/player/Player;)V")) + public void arclight$raidTrigger(ServerPlayer playerEntity, CallbackInfoReturnable cir, DimensionType dimensionType, BlockPos pos, BlockPos pos1, Raid raid) { if (!CraftEventFactory.callRaidTriggerEvent(raid, playerEntity)) { - playerEntity.removePotionEffect(Effects.BAD_OMEN); - this.byId.remove(raid.getId(), raid); + playerEntity.removeEffect(MobEffects.BAD_OMEN); + this.raidMap.remove(raid.getId(), raid); cir.setReturnValue(null); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidMixin.java index 3654f638..6194ecac 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/raid/RaidMixin.java @@ -3,12 +3,6 @@ package io.izzel.arclight.common.mixin.core.world.raid; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.raid.RaidBridge; -import net.minecraft.advancements.criterion.PositionTrigger; -import net.minecraft.entity.monster.AbstractRaiderEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.raid.Raid; -import net.minecraft.world.server.ServerWorld; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.Player; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -29,63 +23,69 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import net.minecraft.advancements.critereon.LocationTrigger; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.raid.Raid; +import net.minecraft.world.entity.raid.Raider; @Mixin(Raid.class) public class RaidMixin implements RaidBridge { // @formatter:off - @Shadow @Final private Map> raiders; - @Shadow @Final private ServerWorld world; + @Shadow @Final private Map> groupRaiderMap; + @Shadow @Final private ServerLevel level; // @formatter:on - @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/raid/Raid;stop()V"), + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/raid/Raid;stop()V"), slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/world/Difficulty;PEACEFUL:Lnet/minecraft/world/Difficulty;"))) public void arclight$stopPeace(CallbackInfo ci) { CraftEventFactory.callRaidStopEvent((Raid) (Object) this, RaidStopEvent.Reason.PEACE); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;stop()V"), + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;stop()V"), slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;isVillage(Lnet/minecraft/util/math/BlockPos;)Z"), - to = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/raid/Raid;ticksActive:J") + from = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;isVillage(Lnet/minecraft/core/BlockPos;)Z"), + to = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/entity/raid/Raid;ticksActive:J") )) public void arclight$stopNotInVillage(CallbackInfo ci) { CraftEventFactory.callRaidStopEvent((Raid) (Object) this, RaidStopEvent.Reason.NOT_IN_VILLAGE); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;stop()V"), + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;stop()V"), slice = @Slice( - from = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/raid/Raid;ticksActive:J"), - to = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;getRaiderCount()I") + from = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/world/entity/raid/Raid;ticksActive:J"), + to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;getTotalRaidersAlive()I") )) public void arclight$stopTimeout(CallbackInfo ci) { CraftEventFactory.callRaidStopEvent((Raid) (Object) this, RaidStopEvent.Reason.TIMEOUT); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;stop()V"), + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;stop()V"), slice = @Slice( - from = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;shouldSpawnGroup()Z"), - to = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;isStarted()Z") + from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;shouldSpawnGroup()Z"), + to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;isStarted()Z") )) public void arclight$stopUnspawnable(CallbackInfo ci) { CraftEventFactory.callRaidStopEvent((Raid) (Object) this, RaidStopEvent.Reason.UNSPAWNABLE); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;stop()V"), - slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;isOver()Z"))) + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;stop()V"), + slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;isOver()Z"))) public void arclight$stopFinish(CallbackInfo ci) { CraftEventFactory.callRaidStopEvent((Raid) (Object) this, RaidStopEvent.Reason.FINISHED); } - @Inject(method = "tick", at = @At(value = "FIELD", shift = At.Shift.BY, by = 2, target = "Lnet/minecraft/world/raid/Raid$Status;LOSS:Lnet/minecraft/world/raid/Raid$Status;")) + @Inject(method = "tick", at = @At(value = "FIELD", shift = At.Shift.BY, by = 2, target = "Lnet/minecraft/world/entity/raid/Raid$RaidStatus;LOSS:Lnet/minecraft/world/entity/raid/Raid$RaidStatus;")) public void arclight$finishNone(CallbackInfo ci) { CraftEventFactory.callRaidFinishEvent((Raid) (Object) this, new ArrayList<>()); } private transient List arclight$winners; - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/criterion/PositionTrigger;trigger(Lnet/minecraft/entity/player/ServerPlayerEntity;)V")) - public void arclight$addWinner(PositionTrigger trigger, ServerPlayerEntity player) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/critereon/LocationTrigger;trigger(Lnet/minecraft/server/level/ServerPlayer;)V")) + public void arclight$addWinner(LocationTrigger trigger, ServerPlayer player) { trigger.trigger(player); if (arclight$winners == null) { arclight$winners = new ArrayList<>(); @@ -93,24 +93,24 @@ public class RaidMixin implements RaidBridge { arclight$winners.add(((ServerPlayerEntityBridge) player).bridge$getBukkitEntity()); } - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;markDirty()V")) + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;setDirty()V")) public void arclight$finish(CallbackInfo ci) { List winners = this.arclight$winners == null ? new ArrayList<>() : this.arclight$winners; this.arclight$winners = null; CraftEventFactory.callRaidFinishEvent((Raid) (Object) this, winners); } - private transient AbstractRaiderEntity arclight$leader; - private transient List arclight$raiders; + private transient Raider arclight$leader; + private transient List arclight$raiders; - @Redirect(method = "spawnNextWave", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;setLeader(ILnet/minecraft/entity/monster/AbstractRaiderEntity;)V")) - public void arclight$captureLeader(Raid raid, int raidId, AbstractRaiderEntity entity) { + @Redirect(method = "spawnGroup", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;setLeader(ILnet/minecraft/world/entity/raid/Raider;)V")) + public void arclight$captureLeader(Raid raid, int raidId, Raider entity) { raid.setLeader(raidId, entity); arclight$leader = entity; } - @Redirect(method = "spawnNextWave", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/raid/Raid;joinRaid(ILnet/minecraft/entity/monster/AbstractRaiderEntity;Lnet/minecraft/util/math/BlockPos;Z)V")) - public void arclight$captureRaider(Raid raid, int wave, AbstractRaiderEntity entity, BlockPos pos, boolean flag) { + @Redirect(method = "spawnGroup", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/raid/Raid;joinRaid(ILnet/minecraft/world/entity/raid/Raider;Lnet/minecraft/core/BlockPos;Z)V")) + public void arclight$captureRaider(Raid raid, int wave, Raider entity, BlockPos pos, boolean flag) { raid.joinRaid(wave, entity, pos, flag); if (arclight$raiders == null) { arclight$raiders = new ArrayList<>(); @@ -118,26 +118,26 @@ public class RaidMixin implements RaidBridge { arclight$raiders.add(entity); } - @Inject(method = "spawnNextWave", at = @At("RETURN")) + @Inject(method = "spawnGroup", at = @At("RETURN")) public void arclight$spawnWave(BlockPos pos, CallbackInfo ci) { CraftEventFactory.callRaidSpawnWaveEvent((Raid) (Object) this, arclight$leader, arclight$raiders); } - @Inject(method = "joinRaid(ILnet/minecraft/entity/monster/AbstractRaiderEntity;Lnet/minecraft/util/math/BlockPos;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - public void arclight$addEntity(int wave, AbstractRaiderEntity p_221317_2_, BlockPos p_221317_3_, boolean p_221317_4_, CallbackInfo ci) { - ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.RAID); + @Inject(method = "joinRaid(ILnet/minecraft/world/entity/raid/Raider;Lnet/minecraft/core/BlockPos;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + public void arclight$addEntity(int wave, Raider p_221317_2_, BlockPos p_221317_3_, boolean p_221317_4_, CallbackInfo ci) { + ((WorldBridge) this.level).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.RAID); } - public Collection getRaiders() { - HashSet set = new HashSet<>(); - for (Set entities : this.raiders.values()) { + public Collection getRaiders() { + HashSet set = new HashSet<>(); + for (Set entities : this.groupRaiderMap.values()) { set.addAll(entities); } return set; } @Override - public Collection bridge$getRaiders() { + public Collection bridge$getRaiders() { return getRaiders(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkHolderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkHolderMixin.java index de83603d..82d9bd60 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkHolderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkHolderMixin.java @@ -5,12 +5,6 @@ import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge; import io.izzel.arclight.common.bridge.world.server.ChunkHolderBridge; import io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge; import io.izzel.arclight.common.mod.ArclightMod; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkStatus; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.server.ChunkHolder; -import net.minecraft.world.server.ChunkManager; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -22,42 +16,48 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.concurrent.CompletableFuture; +import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ChunkMap; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.LevelChunk; @Mixin(ChunkHolder.class) public abstract class ChunkHolderMixin implements ChunkHolderBridge { // @formatter:off - @Shadow public int prevChunkLevel; - @Shadow public abstract CompletableFuture> func_219301_a(ChunkStatus p_219301_1_); + @Shadow public int oldTicketLevel; + @Shadow public abstract CompletableFuture> getFutureIfPresentUnchecked(ChunkStatus p_219301_1_); @Shadow @Final private ChunkPos pos; - @Override @Accessor("prevChunkLevel") public abstract int bridge$getOldTicketLevel(); + @Override @Accessor("oldTicketLevel") public abstract int bridge$getOldTicketLevel(); // @formatter:on - public Chunk getFullChunk() { - if (!ChunkHolder.getLocationTypeFromLevel(this.prevChunkLevel).isAtLeast(ChunkHolder.LocationType.BORDER)) { + public LevelChunk getFullChunk() { + if (!ChunkHolder.getFullChunkStatus(this.oldTicketLevel).isOrAfter(ChunkHolder.FullChunkStatus.BORDER)) { return null; // note: using oldTicketLevel for isLoaded checks } - CompletableFuture> statusFuture = this.func_219301_a(ChunkStatus.FULL); - Either either = statusFuture.getNow(null); - return either == null ? null : (Chunk) either.left().orElse(null); + CompletableFuture> statusFuture = this.getFutureIfPresentUnchecked(ChunkStatus.FULL); + Either either = statusFuture.getNow(null); + return either == null ? null : (LevelChunk) either.left().orElse(null); } @Override - public Chunk bridge$getFullChunk() { + public LevelChunk bridge$getFullChunk() { return this.getFullChunk(); } - @Inject(method = "processUpdates", at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 0), + @Inject(method = "updateFutures", at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) - public void arclight$onChunkUnload(ChunkManager chunkManager, CallbackInfo ci, ChunkStatus chunkStatus, + public void arclight$onChunkUnload(ChunkMap chunkManager, CallbackInfo ci, ChunkStatus chunkStatus, ChunkStatus chunkStatus1, boolean flag, boolean flag1, - ChunkHolder.LocationType locationType, ChunkHolder.LocationType locationType1) { - if (locationType.isAtLeast(ChunkHolder.LocationType.BORDER) && !locationType1.isAtLeast(ChunkHolder.LocationType.BORDER)) { - this.func_219301_a(ChunkStatus.FULL).thenAccept((either) -> { - Chunk chunk = (Chunk) either.left().orElse(null); + ChunkHolder.FullChunkStatus locationType, ChunkHolder.FullChunkStatus locationType1) { + if (locationType.isOrAfter(ChunkHolder.FullChunkStatus.BORDER) && !locationType1.isOrAfter(ChunkHolder.FullChunkStatus.BORDER)) { + this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> { + LevelChunk chunk = (LevelChunk) either.left().orElse(null); if (chunk != null) { ((ChunkManagerBridge) chunkManager).bridge$getCallbackExecutor().execute(() -> { - chunk.setModified(true); + chunk.setUnsaved(true); ((ChunkBridge) chunk).bridge$unloadCallback(); }); } @@ -72,13 +72,13 @@ public abstract class ChunkHolderMixin implements ChunkHolderBridge { } } - @Inject(method = "processUpdates", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void arclight$onChunkLoad(ChunkManager chunkManager, CallbackInfo ci, ChunkStatus chunkStatus, + @Inject(method = "updateFutures", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) + public void arclight$onChunkLoad(ChunkMap chunkManager, CallbackInfo ci, ChunkStatus chunkStatus, ChunkStatus chunkStatus1, boolean flag, boolean flag1, - ChunkHolder.LocationType locationType, ChunkHolder.LocationType locationType1) { - if (!locationType.isAtLeast(ChunkHolder.LocationType.BORDER) && locationType1.isAtLeast(ChunkHolder.LocationType.BORDER)) { - this.func_219301_a(ChunkStatus.FULL).thenAccept((either) -> { - Chunk chunk = (Chunk) either.left().orElse(null); + ChunkHolder.FullChunkStatus locationType, ChunkHolder.FullChunkStatus locationType1) { + if (!locationType.isOrAfter(ChunkHolder.FullChunkStatus.BORDER) && locationType1.isOrAfter(ChunkHolder.FullChunkStatus.BORDER)) { + this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> { + LevelChunk chunk = (LevelChunk) either.left().orElse(null); if (chunk != null) { ((ChunkManagerBridge) chunkManager).bridge$getCallbackExecutor().execute( ((ChunkBridge) chunk)::bridge$loadCallback diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManagerMixin.java index a49d85d4..b24f6895 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManagerMixin.java @@ -3,13 +3,6 @@ package io.izzel.arclight.common.mixin.core.world.server; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge; import io.izzel.arclight.common.mod.util.ArclightCallbackExecutor; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.DimensionType; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.server.ChunkHolder; -import net.minecraft.world.server.ChunkManager; -import net.minecraft.world.server.ServerWorld; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -19,23 +12,30 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import javax.annotation.Nullable; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ChunkMap; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.dimension.DimensionType; import java.util.function.BooleanSupplier; -@Mixin(ChunkManager.class) +@Mixin(ChunkMap.class) public abstract class ChunkManagerMixin implements ChunkManagerBridge { // @formatter:off - @Shadow @Nullable protected abstract ChunkHolder func_219220_a(long chunkPosIn); - @Shadow protected abstract Iterable getLoadedChunksIterable(); - @Shadow abstract boolean isOutsideSpawningRadius(ChunkPos chunkPosIn); - @Shadow protected abstract void tickEntityTracker(); + @Shadow @Nullable protected abstract ChunkHolder getUpdatingChunkIfPresent(long chunkPosIn); + @Shadow protected abstract Iterable getChunks(); + @Shadow abstract boolean noPlayersCloseForSpawning(ChunkPos chunkPosIn); + @Shadow protected abstract void tick(); @Shadow @Final @Mutable public ChunkGenerator generator; @Invoker("tick") public abstract void bridge$tick(BooleanSupplier hasMoreTime); @Invoker("setViewDistance") public abstract void bridge$setViewDistance(int i); // @formatter:on - @Redirect(method = "loadChunkData", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;getDimensionKey()Lnet/minecraft/util/RegistryKey;")) - private RegistryKey arclight$useTypeKey(ServerWorld serverWorld) { + @Redirect(method = "readChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;dimension()Lnet/minecraft/resources/ResourceKey;")) + private ResourceKey arclight$useTypeKey(ServerLevel serverWorld) { return ((WorldBridge) serverWorld).bridge$getTypeKey(); } @@ -48,22 +48,22 @@ public abstract class ChunkManagerMixin implements ChunkManagerBridge { @Override public ChunkHolder bridge$chunkHolderAt(long chunkPos) { - return func_219220_a(chunkPos); + return getUpdatingChunkIfPresent(chunkPos); } @Override public Iterable bridge$getLoadedChunksIterable() { - return this.getLoadedChunksIterable(); + return this.getChunks(); } @Override public boolean bridge$isOutsideSpawningRadius(ChunkPos chunkPosIn) { - return this.isOutsideSpawningRadius(chunkPosIn); + return this.noPlayersCloseForSpawning(chunkPosIn); } @Override public void bridge$tickEntityTracker() { - this.tickEntityTracker(); + this.tick(); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManager_EntityTrackerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManager_EntityTrackerMixin.java index 457cb390..9ddcc80a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManager_EntityTrackerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ChunkManager_EntityTrackerMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.server; import io.izzel.arclight.common.bridge.world.TrackedEntityBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.world.TrackedEntity; -import net.minecraft.world.server.ChunkManager; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -13,17 +9,21 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Set; +import net.minecraft.server.level.ChunkMap; +import net.minecraft.server.level.ServerEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; -@Mixin(ChunkManager.EntityTracker.class) +@Mixin(ChunkMap.TrackedEntity.class) public abstract class ChunkManager_EntityTrackerMixin { // @formatter:off - @Shadow @Final private TrackedEntity entry; - @Shadow @Final public Set trackingPlayers; + @Shadow @Final private ServerEntity serverEntity; + @Shadow @Final public Set seenBy; // @formatter:on @Inject(method = "", at = @At("RETURN")) - private void arclight$setTrackedPlayers(ChunkManager outer, Entity entity, int range, int updateFrequency, boolean sendVelocityUpdates, CallbackInfo ci) { - ((TrackedEntityBridge) this.entry).bridge$setTrackedPlayers(this.trackingPlayers); + private void arclight$setTrackedPlayers(ChunkMap outer, Entity entity, int range, int updateFrequency, boolean sendVelocityUpdates, CallbackInfo ci) { + ((TrackedEntityBridge) this.serverEntity).bridge$setTrackedPlayers(this.seenBy); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProviderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProviderMixin.java index eb2d4189..bab8646a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProviderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProviderMixin.java @@ -5,17 +5,6 @@ import io.izzel.arclight.common.bridge.world.server.ChunkHolderBridge; import io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge; import io.izzel.arclight.common.bridge.world.server.ServerChunkProviderBridge; import io.izzel.arclight.common.bridge.world.server.TicketManagerBridge; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.GameRules; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.server.ChunkHolder; -import net.minecraft.world.server.ChunkManager; -import net.minecraft.world.server.ServerChunkProvider; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.server.ServerWorldLightManager; -import net.minecraft.world.server.TicketManager; -import net.minecraft.world.storage.IWorldInfo; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -27,32 +16,43 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Redirect; import javax.annotation.Nullable; +import net.minecraft.server.level.ChunkHolder; +import net.minecraft.server.level.ChunkMap; +import net.minecraft.server.level.DistanceManager; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ThreadedLevelLightEngine; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.storage.LevelData; import java.io.IOException; import java.util.function.Consumer; -@Mixin(ServerChunkProvider.class) +@Mixin(ServerChunkCache.class) public abstract class ServerChunkProviderMixin implements ServerChunkProviderBridge { // @formatter:off @Shadow public abstract void save(boolean flush); - @Shadow @Final private ServerWorldLightManager lightManager; - @Shadow @Final public ChunkManager chunkManager; - @Shadow @Final public ServerWorld world; - @Shadow @Final private TicketManager ticketManager; - @Shadow protected abstract void invalidateCaches(); - @Shadow @Nullable protected abstract ChunkHolder func_217213_a(long chunkPosIn); - @Shadow protected abstract boolean func_217235_l(); - @Shadow protected abstract boolean func_217224_a(@Nullable ChunkHolder chunkHolderIn, int p_217224_2_); - @Shadow public boolean spawnHostiles; - @Shadow public boolean spawnPassives; - @Shadow protected abstract void func_241098_a_(long p_241098_1_, Consumer p_241098_3_); + @Shadow @Final private ThreadedLevelLightEngine lightEngine; + @Shadow @Final public ChunkMap chunkMap; + @Shadow @Final public ServerLevel level; + @Shadow @Final private DistanceManager distanceManager; + @Shadow protected abstract void clearCache(); + @Shadow @Nullable protected abstract ChunkHolder getVisibleChunkIfPresent(long chunkPosIn); + @Shadow protected abstract boolean runDistanceManagerUpdates(); + @Shadow protected abstract boolean chunkAbsent(@Nullable ChunkHolder chunkHolderIn, int p_217224_2_); + @Shadow public boolean spawnEnemies; + @Shadow public boolean spawnFriendlies; + @Shadow protected abstract void getFullChunk(long p_241098_1_, Consumer p_241098_3_); @Shadow @Final @Mutable public ChunkGenerator generator; - @Invoker("func_217235_l") public abstract boolean bridge$tickDistanceManager(); - @Accessor("lightManager") public abstract ServerWorldLightManager bridge$getLightManager(); + @Invoker("runDistanceManagerUpdates") public abstract boolean bridge$tickDistanceManager(); + @Accessor("lightEngine") public abstract ThreadedLevelLightEngine bridge$getLightManager(); // @formatter:on public boolean isChunkLoaded(final int chunkX, final int chunkZ) { - final ChunkHolder chunk = ((ChunkManagerBridge) this.chunkManager).bridge$chunkHolderAt(ChunkPos.asLong(chunkX, chunkZ)); + final ChunkHolder chunk = ((ChunkManagerBridge) this.chunkMap).bridge$chunkHolderAt(ChunkPos.asLong(chunkX, chunkZ)); return chunk != null && ((ChunkHolderBridge) chunk).bridge$getFullChunk() != null; } @@ -64,22 +64,22 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri @Override public void bridge$setChunkGenerator(ChunkGenerator chunkGenerator) { this.generator = chunkGenerator; - ((ChunkManagerBridge) this.chunkManager).bridge$setChunkGenerator(chunkGenerator); + ((ChunkManagerBridge) this.chunkMap).bridge$setChunkGenerator(chunkGenerator); } @Override public void bridge$setViewDistance(int viewDistance) { - ((ChunkManagerBridge) this.chunkManager).bridge$setViewDistance(viewDistance); + ((ChunkManagerBridge) this.chunkMap).bridge$setViewDistance(viewDistance); } - @ModifyVariable(method = "func_217233_c", index = 4, at = @At("HEAD")) + @ModifyVariable(method = "getChunkFutureMainThread", index = 4, at = @At("HEAD")) private boolean arclight$skipIfUnloading(boolean flag, int chunkX, int chunkZ) { if (flag) { - ChunkHolder chunkholder = this.func_217213_a(ChunkPos.asLong(chunkX, chunkZ)); + ChunkHolder chunkholder = this.getVisibleChunkIfPresent(ChunkPos.asLong(chunkX, chunkZ)); if (chunkholder != null) { - ChunkHolder.LocationType chunkStatus = ChunkHolder.getLocationTypeFromLevel(((ChunkHolderBridge) chunkholder).bridge$getOldTicketLevel()); - ChunkHolder.LocationType currentStatus = ChunkHolder.getLocationTypeFromLevel(chunkholder.getChunkLevel()); - return !chunkStatus.isAtLeast(ChunkHolder.LocationType.BORDER) || currentStatus.isAtLeast(ChunkHolder.LocationType.BORDER); + ChunkHolder.FullChunkStatus chunkStatus = ChunkHolder.getFullChunkStatus(((ChunkHolderBridge) chunkholder).bridge$getOldTicketLevel()); + ChunkHolder.FullChunkStatus currentStatus = ChunkHolder.getFullChunkStatus(chunkholder.getTicketLevel()); + return !chunkStatus.isOrAfter(ChunkHolder.FullChunkStatus.BORDER) || currentStatus.isOrAfter(ChunkHolder.FullChunkStatus.BORDER); } else { return true; } @@ -88,15 +88,15 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri } } - @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) - private boolean arclight$noPlayer(GameRules gameRules, GameRules.RuleKey key) { - return gameRules.getBoolean(key) && !this.world.getPlayers().isEmpty(); + @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/GameRules;getBoolean(Lnet/minecraft/world/level/GameRules$Key;)Z")) + private boolean arclight$noPlayer(GameRules gameRules, GameRules.Key key) { + return gameRules.getBoolean(key) && !this.level.players().isEmpty(); } - @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/storage/IWorldInfo;getGameTime()J")) - private long arclight$ticksPer(IWorldInfo worldInfo) { + @Redirect(method = "tickChunks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelData;getGameTime()J")) + private long arclight$ticksPer(LevelData worldInfo) { long gameTime = worldInfo.getGameTime(); - long ticksPer = ((WorldBridge) this.world).bridge$ticksPerAnimalSpawns(); + long ticksPer = ((WorldBridge) this.level).bridge$ticksPerAnimalSpawns(); return (ticksPer != 0L && gameTime % ticksPer == 0) ? 0 : 1; } @@ -104,18 +104,18 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri if (save) { this.save(true); } - this.lightManager.close(); - this.chunkManager.close(); + this.lightEngine.close(); + this.chunkMap.close(); } public void purgeUnload() { - this.world.getProfiler().startSection("purge"); - ((TicketManagerBridge) this.ticketManager).bridge$tick(); + this.level.getProfiler().push("purge"); + ((TicketManagerBridge) this.distanceManager).bridge$tick(); this.bridge$tickDistanceManager(); - this.world.getProfiler().endStartSection("unload"); - ((ChunkManagerBridge) this.chunkManager).bridge$tick(() -> true); - this.world.getProfiler().endSection(); - this.invalidateCaches(); + this.level.getProfiler().popPush("unload"); + ((ChunkManagerBridge) this.chunkMap).bridge$tick(() -> true); + this.level.getProfiler().pop(); + this.clearCache(); } @Override @@ -128,7 +128,7 @@ public abstract class ServerChunkProviderMixin implements ServerChunkProviderBri this.purgeUnload(); } - @Redirect(method = "func_217224_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ChunkHolder;getChunkLevel()I")) + @Redirect(method = "chunkAbsent", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkHolder;getTicketLevel()I")) public int arclight$useOldTicketLevel(ChunkHolder chunkHolder) { return ((ChunkHolderBridge) chunkHolder).bridge$getOldTicketLevel(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProvider_ChunkExecutorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProvider_ChunkExecutorMixin.java index 7cb6235f..d0c5cb41 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProvider_ChunkExecutorMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerChunkProvider_ChunkExecutorMixin.java @@ -4,18 +4,18 @@ import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; import io.izzel.arclight.common.bridge.world.server.ChunkManagerBridge; import io.izzel.arclight.common.bridge.world.server.ServerChunkProviderBridge; import io.izzel.arclight.common.mod.server.ArclightServer; -import net.minecraft.util.concurrent.ThreadTaskExecutor; -import net.minecraft.world.server.ServerChunkProvider; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.util.thread.BlockableEventLoop; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "net.minecraft.world.server.ServerChunkProvider$ChunkExecutor") -public abstract class ServerChunkProvider_ChunkExecutorMixin extends ThreadTaskExecutor { +@Mixin(targets = "net.minecraft.server.level.ServerChunkCache$MainThreadExecutor") +public abstract class ServerChunkProvider_ChunkExecutorMixin extends BlockableEventLoop { // @formatter:off - @Shadow(aliases = {"this$0", "field_213181_a"}, remap = false) @Final private ServerChunkProvider outer; + @Shadow(aliases = {"this$0", "field_213181_a"}, remap = false) @Final private ServerChunkCache outer; // @formatter:on protected ServerChunkProvider_ChunkExecutorMixin(String nameIn) { @@ -27,16 +27,16 @@ public abstract class ServerChunkProvider_ChunkExecutorMixin extends ThreadTaskE * @reason */ @Overwrite - protected boolean driveOne() { + protected boolean pollTask() { try { if (((ServerChunkProviderBridge) outer).bridge$tickDistanceManager()) { return true; } else { - ((ServerChunkProviderBridge) outer).bridge$getLightManager().func_215588_z_(); - return super.driveOne(); + ((ServerChunkProviderBridge) outer).bridge$getLightManager().tryScheduleUpdate(); + return super.pollTask(); } } finally { - ((ChunkManagerBridge) outer.chunkManager).bridge$getCallbackExecutor().run(); + ((ChunkManagerBridge) outer.chunkMap).bridge$getCallbackExecutor().run(); ((MinecraftServerBridge) ArclightServer.getMinecraftServer()).bridge$drainQueuedTasks(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerWorldMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerWorldMixin.java index 9534349d..b9c9ac7e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerWorldMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/ServerWorldMixin.java @@ -17,40 +17,39 @@ import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.arclight.common.mod.util.DelegateWorldInfo; import io.izzel.arclight.i18n.ArclightConfig; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.LightningBoltEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.IInventory; -import net.minecraft.network.IPacket; -import net.minecraft.network.play.server.SSpawnParticlePacket; -import net.minecraft.particles.IParticleData; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.DamageSource; -import net.minecraft.util.IProgressUpdate; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.DimensionType; -import net.minecraft.world.Explosion; -import net.minecraft.world.ExplosionContext; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.listener.IChunkStatusListener; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.server.ServerChunkProvider; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.ISpecialSpawner; -import net.minecraft.world.storage.DerivedWorldInfo; -import net.minecraft.world.storage.IServerWorldInfo; -import net.minecraft.world.storage.MapData; -import net.minecraft.world.storage.SaveFormat; -import net.minecraft.world.storage.ServerWorldInfo; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.progress.ChunkProgressListener; +import net.minecraft.util.ProgressListener; +import net.minecraft.world.Container; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.CustomSpawner; +import net.minecraft.world.level.Explosion; +import net.minecraft.world.level.ExplosionDamageCalculator; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; +import net.minecraft.world.level.storage.DerivedLevelData; +import net.minecraft.world.level.storage.LevelStorageSource; +import net.minecraft.world.level.storage.PrimaryLevelData; +import net.minecraft.world.level.storage.ServerLevelData; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftWorld; import org.bukkit.craftbukkit.v.entity.CraftHumanEntity; @@ -87,76 +86,76 @@ import java.util.UUID; import java.util.concurrent.Executor; import java.util.logging.Level; -@Mixin(ServerWorld.class) +@Mixin(ServerLevel.class) @Implements(@Interface(iface = ServerWorldBridge.Hack.class, prefix = "hack$")) public abstract class ServerWorldMixin extends WorldMixin implements ServerWorldBridge { // @formatter:off - @Shadow public abstract boolean addEntity(Entity entityIn); - @Shadow public abstract boolean summonEntity(Entity entityIn); - @Shadow public abstract int spawnParticle(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed); - @Shadow protected abstract boolean sendPacketWithinDistance(ServerPlayerEntity player, boolean longDistance, double posX, double posY, double posZ, IPacket packet); + @Shadow public abstract boolean addFreshEntity(Entity entityIn); + @Shadow public abstract boolean addWithUUID(Entity entityIn); + @Shadow public abstract int sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed); + @Shadow protected abstract boolean sendParticles(ServerPlayer player, boolean longDistance, double posX, double posY, double posZ, Packet packet); @Shadow @Nonnull public abstract MinecraftServer shadow$getServer(); - @Shadow @Final private List players; + @Shadow @Final private List players; @Shadow @Final public Int2ObjectMap entitiesById; - @Shadow public abstract ServerChunkProvider getChunkProvider(); + @Shadow public abstract ServerChunkCache getChunkSource(); @Shadow private boolean allPlayersSleeping; @Shadow protected abstract void wakeUpAllPlayers(); - @Shadow @Final private ServerChunkProvider serverChunkProvider; - @Shadow protected abstract boolean hasDuplicateEntity(Entity entityIn); - @Shadow @Final public static BlockPos END_SPAWN_AREA; - @Shadow @Final public IServerWorldInfo serverWorldInfo; + @Shadow @Final private ServerChunkCache chunkSource; + @Shadow protected abstract boolean isUUIDUsed(Entity entityIn); + @Shadow @Final public static BlockPos END_SPAWN_POINT; + @Shadow @Final public ServerLevelData serverLevelData; // @formatter:on @SuppressWarnings({"FieldCanBeLocal", "unused"}) - public ServerWorldInfo $$worldDataServer; - public SaveFormat.LevelSave convertable; + public PrimaryLevelData $$worldDataServer; + public LevelStorageSource.LevelStorageAccess convertable; public UUID uuid; - public void arclight$constructor(MinecraftServer server, Executor backgroundExecutor, SaveFormat.LevelSave levelSave, IServerWorldInfo serverWorldInfo, RegistryKey dimension, DimensionType dimensionType, IChunkStatusListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking) { + public void arclight$constructor(MinecraftServer server, Executor backgroundExecutor, LevelStorageSource.LevelStorageAccess levelSave, ServerLevelData serverWorldInfo, ResourceKey dimension, DimensionType dimensionType, ChunkProgressListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking) { throw new RuntimeException(); } - public void arclight$constructor(MinecraftServer server, Executor backgroundExecutor, SaveFormat.LevelSave levelSave, IServerWorldInfo serverWorldInfo, RegistryKey dimension, DimensionType dimensionType, IChunkStatusListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) { + public void arclight$constructor(MinecraftServer server, Executor backgroundExecutor, LevelStorageSource.LevelStorageAccess levelSave, ServerLevelData serverWorldInfo, ResourceKey dimension, DimensionType dimensionType, ChunkProgressListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) { arclight$constructor(server, backgroundExecutor, levelSave, serverWorldInfo, dimension, dimensionType, statusListener, chunkGenerator, isDebug, seed, specialSpawners, shouldBeTicking); this.generator = gen; this.environment = env; if (gen != null) { - CustomChunkGenerator generator = new CustomChunkGenerator((ServerWorld) (Object) this, this.serverChunkProvider.getChunkGenerator(), gen); - ((ServerChunkProviderBridge) this.serverChunkProvider).bridge$setChunkGenerator(generator); + CustomChunkGenerator generator = new CustomChunkGenerator((ServerLevel) (Object) this, this.chunkSource.getGenerator(), gen); + ((ServerChunkProviderBridge) this.chunkSource).bridge$setChunkGenerator(generator); } bridge$getWorld(); } - @Inject(method = "(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/storage/SaveFormat$LevelSave;Lnet/minecraft/world/storage/IServerWorldInfo;Lnet/minecraft/util/RegistryKey;Lnet/minecraft/world/DimensionType;Lnet/minecraft/world/chunk/listener/IChunkStatusListener;Lnet/minecraft/world/gen/ChunkGenerator;ZJLjava/util/List;Z)V", at = @At("RETURN")) - private void arclight$init(MinecraftServer minecraftServer, Executor backgroundExecutor, SaveFormat.LevelSave levelSave, IServerWorldInfo worldInfo, RegistryKey dimension, DimensionType dimensionType, IChunkStatusListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking, CallbackInfo ci) { - this.pvpMode = minecraftServer.isPVPEnabled(); + @Inject(method = "(Lnet/minecraft/server/MinecraftServer;Ljava/util/concurrent/Executor;Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lnet/minecraft/world/level/storage/ServerLevelData;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/DimensionType;Lnet/minecraft/server/level/progress/ChunkProgressListener;Lnet/minecraft/world/level/chunk/ChunkGenerator;ZJLjava/util/List;Z)V", at = @At("RETURN")) + private void arclight$init(MinecraftServer minecraftServer, Executor backgroundExecutor, LevelStorageSource.LevelStorageAccess levelSave, ServerLevelData worldInfo, ResourceKey dimension, DimensionType dimensionType, ChunkProgressListener statusListener, ChunkGenerator chunkGenerator, boolean isDebug, long seed, List specialSpawners, boolean shouldBeTicking, CallbackInfo ci) { + this.pvpMode = minecraftServer.isPvpAllowed(); this.convertable = levelSave; - this.uuid = WorldUUID.getUUID(levelSave.getDimensionFolder(this.getDimensionKey())); - if (worldInfo instanceof ServerWorldInfo) { - this.$$worldDataServer = (ServerWorldInfo) worldInfo; - } else if (worldInfo instanceof DerivedWorldInfo) { + this.uuid = WorldUUID.getUUID(levelSave.getDimensionPath(this.getDimensionKey())); + if (worldInfo instanceof PrimaryLevelData) { + this.$$worldDataServer = (PrimaryLevelData) worldInfo; + } else if (worldInfo instanceof DerivedLevelData) { // damn spigot again - this.$$worldDataServer = DelegateWorldInfo.wrap(((DerivedWorldInfo) worldInfo)); + this.$$worldDataServer = DelegateWorldInfo.wrap(((DerivedLevelData) worldInfo)); ((DerivedWorldInfoBridge) worldInfo).bridge$setDimType(this.getTypeKey()); if (ArclightConfig.spec().getCompat().isSymlinkWorld()) { - WorldSymlink.create((DerivedWorldInfo) worldInfo, levelSave.getDimensionFolder(this.getDimensionKey())); + WorldSymlink.create((DerivedLevelData) worldInfo, levelSave.getDimensionPath(this.getDimensionKey())); } } - ((ServerChunkProviderBridge) this.serverChunkProvider).bridge$setViewDistance(spigotConfig.viewDistance); - ((WorldInfoBridge) this.$$worldDataServer).bridge$setWorld((ServerWorld) (Object) this); + ((ServerChunkProviderBridge) this.chunkSource).bridge$setViewDistance(spigotConfig.viewDistance); + ((WorldInfoBridge) this.$$worldDataServer).bridge$setWorld((ServerLevel) (Object) this); } - public Chunk getChunkIfLoaded(int x, int z) { - return this.serverChunkProvider.getChunk(x, z, false); + public LevelChunk getChunkIfLoaded(int x, int z) { + return this.chunkSource.getChunk(x, z, false); } - public int sendParticles(final ServerPlayerEntity sender, final T t0, final double d0, final double d1, final double d2, final int i, final double d3, final double d4, final double d5, final double d6, final boolean force) { - SSpawnParticlePacket packet = new SSpawnParticlePacket(t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i); + public int sendParticles(final ServerPlayer sender, final T t0, final double d0, final double d1, final double d2, final int i, final double d3, final double d4, final double d5, final double d6, final boolean force) { + ClientboundLevelParticlesPacket packet = new ClientboundLevelParticlesPacket(t0, force, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i); int j = 0; - for (ServerPlayerEntity entity : this.players) { + for (ServerPlayer entity : this.players) { if (sender == null || ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity().canSee(((ServerPlayerEntityBridge) sender).bridge$getBukkitEntity())) { - if (this.sendPacketWithinDistance(entity, force, d0, d1, d2, packet)) { + if (this.sendParticles(entity, force, d0, d1, d2, packet)) { ++j; } } @@ -165,21 +164,21 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } @Override - public SaveFormat.LevelSave bridge$getConvertable() { + public LevelStorageSource.LevelStorageAccess bridge$getConvertable() { return this.convertable; } - @Inject(method = "onEntityAdded", at = @At("RETURN")) + @Inject(method = "add", at = @At("RETURN")) private void arclight$validEntity(Entity entityIn, CallbackInfo ci) { ((EntityBridge) entityIn).bridge$setValid(true); } - @Inject(method = "updateEntity", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;tick()V")) + @Inject(method = "tickNonPassenger", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;tick()V")) private void arclight$tickPortal(Entity entityIn, CallbackInfo ci) { ((EntityBridge) entityIn).bridge$postTick(); } - @Inject(method = "tickPassenger", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/entity/Entity;updateRidden()V")) + @Inject(method = "tickPassenger", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;rideTick()V")) private void arclight$tickPortalPassenger(Entity ridingEntity, Entity passengerEntity, CallbackInfo ci) { ((EntityBridge) passengerEntity).bridge$postTick(); } @@ -189,13 +188,13 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld ((EntityBridge) entityIn).bridge$setValid(false); } - @Inject(method = "tickEnvironment", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - public void arclight$thunder(Chunk chunkIn, int randomTickSpeed, CallbackInfo ci) { + @Inject(method = "tickChunk", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + public void arclight$thunder(LevelChunk chunkIn, int randomTickSpeed, CallbackInfo ci) { bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); } - @Redirect(method = "tickEnvironment", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/server/ServerWorld;addEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean arclight$thunder(ServerWorld serverWorld, Entity entityIn) { + @Redirect(method = "tickChunk", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private boolean arclight$thunder(ServerLevel serverWorld, Entity entityIn) { return strikeLightning(entityIn, LightningStrikeEvent.Cause.WEATHER); } @@ -212,36 +211,36 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld if (lightning.isCancelled()) { return false; } - return this.addEntity(entity); + return this.addFreshEntity(entity); } - @Redirect(method = "tickEnvironment", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public boolean arclight$snowForm(ServerWorld serverWorld, BlockPos pos, BlockState state) { + @Redirect(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public boolean arclight$snowForm(ServerLevel serverWorld, BlockPos pos, BlockState state) { return CraftEventFactory.handleBlockFormEvent(serverWorld, pos, state, null); } @Inject(method = "save", at = @At(value = "JUMP", ordinal = 0, opcode = Opcodes.IFNULL)) - private void arclight$worldSaveEvent(IProgressUpdate progress, boolean flush, boolean skipSave, CallbackInfo ci) { + private void arclight$worldSaveEvent(ProgressListener progress, boolean flush, boolean skipSave, CallbackInfo ci) { Bukkit.getPluginManager().callEvent(new WorldSaveEvent(bridge$getWorld())); } @Inject(method = "save", at = @At("RETURN")) - private void arclight$saveLevelDat(IProgressUpdate progress, boolean flush, boolean skipSave, CallbackInfo ci) { - if (this.serverWorldInfo instanceof ServerWorldInfo) { - ServerWorldInfo worldInfo = (ServerWorldInfo) this.serverWorldInfo; - worldInfo.setWorldBorderSerializer(this.getWorldBorder().getSerializer()); - worldInfo.setCustomBossEventData(this.shadow$getServer().getCustomBossEvents().write()); - this.convertable.saveLevel(this.shadow$getServer().dynamicRegistries, worldInfo, this.shadow$getServer().getPlayerList().getHostPlayerData()); + private void arclight$saveLevelDat(ProgressListener progress, boolean flush, boolean skipSave, CallbackInfo ci) { + if (this.serverLevelData instanceof PrimaryLevelData) { + PrimaryLevelData worldInfo = (PrimaryLevelData) this.serverLevelData; + worldInfo.setWorldBorder(this.getWorldBorder().createSettings()); + worldInfo.setCustomBossEvents(this.shadow$getServer().getCustomBossEvents().save()); + this.convertable.saveDataTag(this.shadow$getServer().registryHolder, worldInfo, this.shadow$getServer().getPlayerList().getSingleplayerData()); } } - @Inject(method = "onChunkUnloading", at = @At("HEAD")) - public void arclight$closeOnChunkUnloading(Chunk chunkIn, CallbackInfo ci) { - for (TileEntity tileentity : chunkIn.getTileEntityMap().values()) { - if (tileentity instanceof IInventory) { + @Inject(method = "unload", at = @At("HEAD")) + public void arclight$closeOnChunkUnloading(LevelChunk chunkIn, CallbackInfo ci) { + for (BlockEntity tileentity : chunkIn.getBlockEntities().values()) { + if (tileentity instanceof Container) { for (HumanEntity h : Lists.newArrayList(((IInventoryBridge) tileentity).getViewers())) { if (h instanceof CraftHumanEntity) { - ((CraftHumanEntity) h).getHandle().closeScreen(); + ((CraftHumanEntity) h).getHandle().closeContainer(); } } } @@ -250,18 +249,18 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld private transient boolean arclight$force; - @Redirect(method = "spawnParticle(Lnet/minecraft/particles/IParticleData;DDDIDDDD)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;sendPacketWithinDistance(Lnet/minecraft/entity/player/ServerPlayerEntity;ZDDDLnet/minecraft/network/IPacket;)Z")) - public boolean arclight$particleVisible(ServerWorld serverWorld, ServerPlayerEntity player, boolean longDistance, double posX, double posY, double posZ, IPacket packet) { - return this.sendPacketWithinDistance(player, arclight$force, posX, posY, posZ, packet); + @Redirect(method = "sendParticles(Lnet/minecraft/core/particles/ParticleOptions;DDDIDDDD)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;sendParticles(Lnet/minecraft/server/level/ServerPlayer;ZDDDLnet/minecraft/network/protocol/Packet;)Z")) + public boolean arclight$particleVisible(ServerLevel serverWorld, ServerPlayer player, boolean longDistance, double posX, double posY, double posZ, Packet packet) { + return this.sendParticles(player, arclight$force, posX, posY, posZ, packet); } - public int sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force) { + public int sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force) { arclight$force = force; - return this.spawnParticle(type, posX, posY, posZ, particleCount, xOffset, yOffset, zOffset, speed); + return this.sendParticles(type, posX, posY, posZ, particleCount, xOffset, yOffset, zOffset, speed); } @Override - public int bridge$sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force) { + public int bridge$sendParticles(T type, double posX, double posY, double posZ, int particleCount, double xOffset, double yOffset, double zOffset, double speed, boolean force) { return this.sendParticles(type, posX, posY, posZ, particleCount, xOffset, yOffset, zOffset, speed, force); } @@ -273,22 +272,22 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } @Override - public void bridge$strikeLightning(LightningBoltEntity entity, LightningStrikeEvent.Cause cause) { + public void bridge$strikeLightning(LightningBolt entity, LightningStrikeEvent.Cause cause) { strikeLightning(entity, cause); } private transient CreatureSpawnEvent.SpawnReason arclight$reason; - @Inject(method = "addEntity0", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z")) + @Inject(method = "addEntity", cancellable = true, at = @At(value = "INVOKE", remap = false, target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z")) private void arclight$addEntityEvent(Entity entityIn, CallbackInfoReturnable cir) { CreatureSpawnEvent.SpawnReason reason = arclight$reason == null ? CreatureSpawnEvent.SpawnReason.DEFAULT : arclight$reason; arclight$reason = null; - if (!CraftEventFactory.doEntityAddEventCalling((ServerWorld) (Object) this, entityIn, reason)) { + if (!CraftEventFactory.doEntityAddEventCalling((ServerLevel) (Object) this, entityIn, reason)) { cir.setReturnValue(false); } } - @Inject(method = "addEntity0", at = @At("RETURN")) + @Inject(method = "addEntity", at = @At("RETURN")) public void arclight$resetReason(Entity entityIn, CallbackInfoReturnable cir) { arclight$reason = null; } @@ -305,7 +304,7 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld public boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { bridge$pushAddEntityReason(reason); - return addEntity(entity); + return addFreshEntity(entity); } @Override @@ -315,7 +314,7 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld public boolean addEntitySerialized(Entity entity, CreatureSpawnEvent.SpawnReason reason) { bridge$pushAddEntityReason(reason); - return summonEntity(entity); + return addWithUUID(entity); } @Override @@ -324,7 +323,7 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } public boolean addAllEntitiesSafely(Entity entity, CreatureSpawnEvent.SpawnReason reason) { - if (entity.getSelfAndPassengers().anyMatch(this::hasDuplicateEntity)) { + if (entity.getSelfAndPassengers().anyMatch(this::isUUIDUsed)) { return false; } return this.bridge$addAllEntities(entity, reason); @@ -335,10 +334,10 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld return addAllEntitiesSafely(entity, reason); } - @Inject(method = "createExplosion", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, - target = "Lnet/minecraft/world/Explosion;doExplosionB(Z)V"), locals = LocalCapture.CAPTURE_FAILHARD) - public void arclight$doExplosion(Entity entityIn, DamageSource damageSourceIn, @Nullable ExplosionContext context, double xIn, double yIn, double zIn, - float explosionRadius, boolean causesFire, Explosion.Mode modeIn, CallbackInfoReturnable cir, + @Inject(method = "explode", cancellable = true, at = @At(value = "INVOKE", shift = At.Shift.AFTER, + target = "Lnet/minecraft/world/level/Explosion;finalizeExplosion(Z)V"), locals = LocalCapture.CAPTURE_FAILHARD) + public void arclight$doExplosion(Entity entityIn, DamageSource damageSourceIn, @Nullable ExplosionDamageCalculator context, double xIn, double yIn, double zIn, + float explosionRadius, boolean causesFire, Explosion.BlockInteraction modeIn, CallbackInfoReturnable cir, Explosion explosion) { if (((ExplosionBridge) explosion).bridge$wasCancelled()) { cir.setReturnValue(explosion); @@ -351,16 +350,16 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld */ @Overwrite @Nullable - public MapData getMapData(String mapName) { - return this.shadow$getServer().func_241755_D_().getSavedData().get(() -> { - MapData newMap = new MapData(mapName); + public MapItemSavedData getMapData(String mapName) { + return this.shadow$getServer().overworld().getDataStorage().get(() -> { + MapItemSavedData newMap = new MapItemSavedData(mapName); MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) newMap).bridge$getMapView()); Bukkit.getServer().getPluginManager().callEvent(event); return newMap; }, mapName); } - @Inject(method = "updateBlock", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;notifyNeighborsOfStateChange(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/Block;)V")) + @Inject(method = "blockUpdated", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;updateNeighborsAt(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/Block;)V")) private void arclight$returnIfPopulate(BlockPos pos, Block block, CallbackInfo ci) { if (populating) { ci.cancel(); @@ -368,22 +367,22 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } @Override - public TileEntity bridge$getTileEntity(BlockPos blockPos) { + public BlockEntity bridge$getTileEntity(BlockPos blockPos) { return this.getTileEntity(blockPos); } - public TileEntity hack$getTileEntity(BlockPos pos) { + public BlockEntity hack$getTileEntity(BlockPos pos) { return this.getTileEntity(pos); } @Override - public TileEntity getTileEntity(BlockPos pos) { + public BlockEntity getTileEntity(BlockPos pos) { return getTileEntity(pos, true); } @Override - public TileEntity getTileEntity(BlockPos pos, boolean validate) { - TileEntity result = super.getTileEntity(pos); + public BlockEntity getTileEntity(BlockPos pos, boolean validate) { + BlockEntity result = super.getTileEntity(pos); if (!validate || Thread.currentThread() != arclight$getMainThread()) { return result; } @@ -392,7 +391,7 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld Block type = state.getBlock(); if (result != null && type != Blocks.AIR) { - if (!result.getType().isValidBlock(type)) { + if (!result.getType().isValid(type)) { result = fixTileEntity(pos, state, type, result); } } @@ -400,11 +399,11 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld return result; } - private TileEntity fixTileEntity(BlockPos pos, Block type, TileEntity found) { + private BlockEntity fixTileEntity(BlockPos pos, Block type, BlockEntity found) { return fixTileEntity(pos, getBlockState(pos), type, found); } - private TileEntity fixTileEntity(BlockPos pos, BlockState state, Block type, TileEntity found) { + private BlockEntity fixTileEntity(BlockPos pos, BlockState state, Block type, BlockEntity found) { ResourceLocation registryName = found.getType().getRegistryName(); if (registryName == null || !registryName.getNamespace().equals("minecraft")) { return found; @@ -417,9 +416,9 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld + "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}); if (type.hasTileEntity(state)) { - TileEntity replacement = type.createTileEntity(state, (IBlockReader) this); + BlockEntity replacement = type.createTileEntity(state, (BlockGetter) this); if (replacement == null) return found; - replacement.setWorldAndPos(((World) (Object) this), pos); + replacement.setLevelAndPosition(((net.minecraft.world.level.Level) (Object) this), pos); this.setTileEntity(pos, replacement); return replacement; } else { @@ -427,8 +426,8 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } } - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;setDayTime(J)V")) - private void arclight$timeSkip(ServerWorld world, long time) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setDayTime(J)V")) + private void arclight$timeSkip(ServerLevel world, long time) { TimeSkipEvent event = new TimeSkipEvent(this.bridge$getWorld(), TimeSkipEvent.SkipReason.NIGHT_SKIP, (time - time % 24000L) - this.getDayTime()); Bukkit.getPluginManager().callEvent(event); arclight$timeSkipCancelled = event.isCancelled(); @@ -440,8 +439,8 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld private transient boolean arclight$timeSkipCancelled; - @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;wakeUpAllPlayers()V")) - private void arclight$notWakeIfCancelled(ServerWorld world) { + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;wakeUpAllPlayers()V")) + private void arclight$notWakeIfCancelled(ServerLevel world) { if (!arclight$timeSkipCancelled) { this.wakeUpAllPlayers(); } @@ -449,8 +448,8 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld } @Override - public ServerWorld bridge$getMinecraftWorld() { - return (ServerWorld) (Object) this; + public ServerLevel bridge$getMinecraftWorld() { + return (ServerLevel) (Object) this; } /** @@ -459,17 +458,17 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld */ @SuppressWarnings({"unchecked", "rawtypes"}) @Overwrite - public static void setupEndSpawnPlatform(ServerWorld world) { - BlockPos blockpos = END_SPAWN_AREA; + public static void makeObsidianPlatform(ServerLevel world) { + BlockPos blockpos = END_SPAWN_POINT; int i = blockpos.getX(); int j = blockpos.getY() - 2; int k = blockpos.getZ(); BlockStateListPopulator blockList = new BlockStateListPopulator(world); - BlockPos.getAllInBoxMutable(i - 2, j + 1, k - 2, i + 2, j + 3, k + 2).forEach((pos) -> { - blockList.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState(), 3); + BlockPos.betweenClosed(i - 2, j + 1, k - 2, i + 2, j + 3, k + 2).forEach((pos) -> { + blockList.setBlock(pos, Blocks.OBSIDIAN.defaultBlockState(), 3); }); - BlockPos.getAllInBoxMutable(i - 2, j, k - 2, i + 2, j, k + 2).forEach((pos) -> { - blockList.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState(), 3); + BlockPos.betweenClosed(i - 2, j, k - 2, i + 2, j, k + 2).forEach((pos) -> { + blockList.setBlock(pos, Blocks.OBSIDIAN.defaultBlockState(), 3); }); CraftWorld bworld = ((WorldBridge) world).bridge$getWorld(); boolean spawnPortal = ArclightCaptures.getEndPortalSpawn(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketManagerMixin.java index d2188adc..b634ba3c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketManagerMixin.java @@ -3,11 +3,11 @@ package io.izzel.arclight.common.mixin.core.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.server.level.DistanceManager; +import net.minecraft.server.level.Ticket; +import net.minecraft.server.level.TicketType; 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 net.minecraft.world.level.ChunkPos; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,16 +15,16 @@ import org.spongepowered.asm.mixin.gen.Invoker; import java.util.Iterator; -@Mixin(TicketManager.class) +@Mixin(DistanceManager.class) public abstract class TicketManagerMixin implements TicketManagerBridge { // @formatter:off - @Shadow private long currentTime; - @Shadow @Final private TicketManager.ChunkTicketTracker ticketTracker; - @Shadow protected abstract SortedArraySet> getTicketSet(long p_229848_1_); - @Shadow private static int getLevel(SortedArraySet> p_229844_0_) { return 0; } + @Shadow private long ticketTickCounter; + @Shadow @Final private DistanceManager.ChunkTicketTracker ticketTracker; + @Shadow protected abstract SortedArraySet> getTickets(long p_229848_1_); + @Shadow private static int getTicketLevelAt(SortedArraySet> p_229844_0_) { return 0; } @Shadow @Final public Long2ObjectOpenHashMap>> tickets; - @Invoker("tick") public abstract void bridge$tick(); + @Invoker("purgeStaleTickets") public abstract void bridge$tick(); // @formatter:on @SuppressWarnings("unused") // mock @@ -39,12 +39,12 @@ public abstract class TicketManagerMixin implements TicketManagerBridge { public boolean addTicketAtLevel(TicketType type, ChunkPos pos, int level, T value) { Ticket ticket = new Ticket<>(type, level, value); - return this.addTicket(pos.asLong(), ticket); + return this.addTicket(pos.toLong(), ticket); } public boolean removeTicketAtLevel(TicketType type, ChunkPos pos, int level, T value) { Ticket ticket = new Ticket<>(type, level, value); - return this.removeTicket(pos.asLong(), ticket); + return this.removeTicket(pos.toLong(), ticket); } @Override @@ -63,7 +63,7 @@ public abstract class TicketManagerMixin implements TicketManagerBridge { } private boolean removeTicket(long chunkPosIn, Ticket ticketIn) { - SortedArraySet> ticketSet = this.getTicketSet(chunkPosIn); + SortedArraySet> ticketSet = this.getTickets(chunkPosIn); boolean removed = false; if (ticketSet.remove(ticketIn)) { removed = true; @@ -71,7 +71,7 @@ public abstract class TicketManagerMixin implements TicketManagerBridge { if (ticketSet.isEmpty()) { this.tickets.remove(chunkPosIn); } - this.ticketTracker.updateSourceLevel(chunkPosIn, getLevel(ticketSet), false); + this.ticketTracker.update(chunkPosIn, getTicketLevelAt(ticketSet), false); return removed; } @@ -86,12 +86,12 @@ public abstract class TicketManagerMixin implements TicketManagerBridge { } private boolean addTicket(long chunkPosIn, Ticket ticketIn) { - SortedArraySet> 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); + SortedArraySet> ticketSet = this.getTickets(chunkPosIn); + int level = getTicketLevelAt(ticketSet); + Ticket ticket = ticketSet.addOrGet(ticketIn); + ticket.setCreatedTick(this.ticketTickCounter); + if (ticketIn.getTicketLevel() < level) { + this.ticketTracker.update(chunkPosIn, ticketIn.getTicketLevel(), true); } return ticketIn == ticket; } @@ -108,7 +108,7 @@ public abstract class TicketManagerMixin implements TicketManagerBridge { Long2ObjectMap.Entry>> entry = iterator.next(); SortedArraySet> tickets = entry.getValue(); if (tickets.remove(target)) { - this.ticketTracker.updateSourceLevel(entry.getLongKey(), getLevel(tickets), false); + this.ticketTracker.update(entry.getLongKey(), getTicketLevelAt(tickets), false); if (tickets.isEmpty()) { iterator.remove(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketTypeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketTypeMixin.java index ed7e2d39..704a3e29 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketTypeMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/server/TicketTypeMixin.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mixin.core.world.server; import io.izzel.arclight.common.bridge.world.server.TicketTypeBridge; +import net.minecraft.server.level.TicketType; import net.minecraft.util.Unit; -import net.minecraft.world.server.TicketType; import org.bukkit.plugin.Plugin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -15,6 +15,6 @@ public abstract class TicketTypeMixin implements TicketTypeBridge { private static final TicketType PLUGIN = TicketType.create("plugin", (a, b) -> 0); private static final TicketType PLUGIN_TICKET = TicketType.create("plugin_ticket", Comparator.comparing(it -> it.getClass().getName())); - @Override @Accessor(value = "lifespan") + @Override @Accessor(value = "timeout") public abstract void bridge$setLifespan(long lifespan); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/AbstractSpawnerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/AbstractSpawnerMixin.java index e2892096..0611b280 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/AbstractSpawnerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/AbstractSpawnerMixin.java @@ -3,20 +3,20 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.entity.MobEntityBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntitySpawnPlacementRegistry; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MobEntity; -import net.minecraft.entity.SpawnReason; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.particles.ParticleTypes; -import net.minecraft.util.WeightedSpawnerEntity; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.AbstractSpawner; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnPlacements; +import net.minecraft.world.level.BaseSpawner; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.SpawnData; +import net.minecraft.world.phys.AABB; import net.minecraftforge.event.ForgeEventFactory; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -31,27 +31,27 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.List; import java.util.Optional; -@Mixin(AbstractSpawner.class) +@Mixin(BaseSpawner.class) public abstract class AbstractSpawnerMixin { // @formatter:off - @Shadow public abstract World getWorld(); - @Shadow @Final public List potentialSpawns; - @Shadow protected abstract boolean isActivated(); - @Shadow private double prevMobRotation; - @Shadow private double mobRotation; - @Shadow public abstract BlockPos getSpawnerPosition(); + @Shadow public abstract Level getLevel(); + @Shadow @Final public List spawnPotentials; + @Shadow protected abstract boolean isNearPlayer(); + @Shadow private double oSpin; + @Shadow private double spin; + @Shadow public abstract BlockPos getPos(); @Shadow public int spawnDelay; - @Shadow protected abstract void resetTimer(); + @Shadow protected abstract void delay(); @Shadow public int spawnCount; - @Shadow public WeightedSpawnerEntity spawnData; + @Shadow public SpawnData nextSpawnData; @Shadow public int spawnRange; @Shadow public int maxNearbyEntities; // @formatter:on - @Inject(method = "setEntityType", at = @At("RETURN")) + @Inject(method = "setEntityId", at = @At("RETURN")) public void arclight$clearMobs(EntityType type, CallbackInfo ci) { - this.potentialSpawns.clear(); + this.spawnPotentials.clear(); } /** @@ -60,26 +60,26 @@ public abstract class AbstractSpawnerMixin { */ @Overwrite public void tick() { - if (!this.isActivated()) { - this.prevMobRotation = this.mobRotation; + if (!this.isNearPlayer()) { + this.oSpin = this.spin; } else { - World world = this.getWorld(); - BlockPos blockpos = this.getSpawnerPosition(); - if (!(world instanceof ServerWorld)) { - double d3 = (double) blockpos.getX() + world.rand.nextDouble(); - double d4 = (double) blockpos.getY() + world.rand.nextDouble(); - double d5 = (double) blockpos.getZ() + world.rand.nextDouble(); + Level world = this.getLevel(); + BlockPos blockpos = this.getPos(); + if (!(world instanceof ServerLevel)) { + double d3 = (double) blockpos.getX() + world.random.nextDouble(); + double d4 = (double) blockpos.getY() + world.random.nextDouble(); + double d5 = (double) blockpos.getZ() + world.random.nextDouble(); world.addParticle(ParticleTypes.SMOKE, d3, d4, d5, 0.0D, 0.0D, 0.0D); world.addParticle(ParticleTypes.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D); if (this.spawnDelay > 0) { --this.spawnDelay; } - this.prevMobRotation = this.mobRotation; - this.mobRotation = (this.mobRotation + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D; + this.oSpin = this.spin; + this.spin = (this.spin + (double) (1000.0F / ((float) this.spawnDelay + 200.0F))) % 360.0D; } else { if (this.spawnDelay == -1) { - this.resetTimer(); + this.delay(); } if (this.spawnDelay > 0) { @@ -90,70 +90,70 @@ public abstract class AbstractSpawnerMixin { boolean flag = false; for (int i = 0; i < this.spawnCount; ++i) { - CompoundNBT compoundnbt = this.spawnData.getNbt(); - Optional> optional = EntityType.readEntityType(compoundnbt); + CompoundTag compoundnbt = this.nextSpawnData.getTag(); + Optional> optional = EntityType.by(compoundnbt); if (!optional.isPresent()) { - this.resetTimer(); + this.delay(); return; } - ListNBT listnbt = compoundnbt.getList("Pos", 6); + ListTag listnbt = compoundnbt.getList("Pos", 6); int j = listnbt.size(); - double d0 = j >= 1 ? listnbt.getDouble(0) : (double) blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D; - double d1 = j >= 2 ? listnbt.getDouble(1) : (double) (blockpos.getY() + world.rand.nextInt(3) - 1); - double d2 = j >= 3 ? listnbt.getDouble(2) : (double) blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double) this.spawnRange + 0.5D; - if (world.hasNoCollisions(optional.get().getBoundingBoxWithSizeApplied(d0, d1, d2))) { - ServerWorld serverworld = (ServerWorld) world; - if (EntitySpawnPlacementRegistry.canSpawnEntity(optional.get(), serverworld, SpawnReason.SPAWNER, new BlockPos(d0, d1, d2), world.getRandom())) { - Entity entity = EntityType.loadEntityAndExecute(compoundnbt, world, (p_221408_6_) -> { - p_221408_6_.setLocationAndAngles(d0, d1, d2, p_221408_6_.rotationYaw, p_221408_6_.rotationPitch); + double d0 = j >= 1 ? listnbt.getDouble(0) : (double) blockpos.getX() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawnRange + 0.5D; + double d1 = j >= 2 ? listnbt.getDouble(1) : (double) (blockpos.getY() + world.random.nextInt(3) - 1); + double d2 = j >= 3 ? listnbt.getDouble(2) : (double) blockpos.getZ() + (world.random.nextDouble() - world.random.nextDouble()) * (double) this.spawnRange + 0.5D; + if (world.noCollision(optional.get().getAABB(d0, d1, d2))) { + ServerLevel serverworld = (ServerLevel) world; + if (SpawnPlacements.checkSpawnRules(optional.get(), serverworld, MobSpawnType.SPAWNER, new BlockPos(d0, d1, d2), world.getRandom())) { + Entity entity = EntityType.loadEntityRecursive(compoundnbt, world, (p_221408_6_) -> { + p_221408_6_.moveTo(d0, d1, d2, p_221408_6_.yRot, p_221408_6_.xRot); return p_221408_6_; }); if (entity == null) { - this.resetTimer(); + this.delay(); return; } - int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB(blockpos.getX(), blockpos.getY(), blockpos.getZ(), blockpos.getX() + 1, blockpos.getY() + 1, blockpos.getZ() + 1)).grow(this.spawnRange)).size(); + int k = world.getEntitiesOfClass(entity.getClass(), (new AABB(blockpos.getX(), blockpos.getY(), blockpos.getZ(), blockpos.getX() + 1, blockpos.getY() + 1, blockpos.getZ() + 1)).inflate(this.spawnRange)).size(); if (k >= this.maxNearbyEntities) { - this.resetTimer(); + this.delay(); return; } - entity.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), world.rand.nextFloat() * 360.0F, 0.0F); - if (entity instanceof MobEntity) { - MobEntity mobentity = (MobEntity) entity; - if (!ForgeEventFactory.canEntitySpawnSpawner(mobentity, world, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), (AbstractSpawner) (Object) this)) { + entity.moveTo(entity.getX(), entity.getY(), entity.getZ(), world.random.nextFloat() * 360.0F, 0.0F); + if (entity instanceof Mob) { + Mob mobentity = (Mob) entity; + if (!ForgeEventFactory.canEntitySpawnSpawner(mobentity, world, (float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), (BaseSpawner) (Object) this)) { continue; } - if (this.spawnData.getNbt().size() == 1 && this.spawnData.getNbt().contains("id", 8)) { - if (!ForgeEventFactory.doSpecialSpawn(mobentity, world, (float) entity.getPosX(), (float) entity.getPosY(), (float) entity.getPosZ(), (AbstractSpawner) (Object) this, SpawnReason.SPAWNER)) - ((MobEntity) entity).onInitialSpawn(serverworld, world.getDifficultyForLocation(entity.getPosition()), SpawnReason.SPAWNER, null, null); + if (this.nextSpawnData.getTag().size() == 1 && this.nextSpawnData.getTag().contains("id", 8)) { + if (!ForgeEventFactory.doSpecialSpawn(mobentity, world, (float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), (BaseSpawner) (Object) this, MobSpawnType.SPAWNER)) + ((Mob) entity).finalizeSpawn(serverworld, world.getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.SPAWNER, null, null); } - if (((WorldBridge) mobentity.world).bridge$spigotConfig().nerfSpawnerMobs) { + if (((WorldBridge) mobentity.level).bridge$spigotConfig().nerfSpawnerMobs) { ((MobEntityBridge) mobentity).bridge$setAware(false); } } if (CraftEventFactory.callSpawnerSpawnEvent(entity, blockpos).isCancelled()) { - Entity vehicle = entity.getRidingEntity(); + Entity vehicle = entity.getVehicle(); if (vehicle != null) { vehicle.remove(); } - for (Entity passenger : entity.getRecursivePassengers()) { + for (Entity passenger : entity.getIndirectPassengers()) { passenger.remove(); } continue; } if (!((ServerWorldBridge) serverworld).bridge$addAllEntitiesSafely(entity, CreatureSpawnEvent.SpawnReason.SPAWNER)) { - this.resetTimer(); + this.delay(); return; } - world.playEvent(2004, blockpos, 0); - if (entity instanceof MobEntity) { - ((MobEntity) entity).spawnExplosionParticle(); + world.levelEvent(2004, blockpos, 0); + if (entity instanceof Mob) { + ((Mob) entity).spawnAnim(); } flag = true; @@ -162,7 +162,7 @@ public abstract class AbstractSpawnerMixin { } if (flag) { - this.resetTimer(); + this.delay(); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PatrolSpawnerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PatrolSpawnerMixin.java index 34995ef0..7e10f9d4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PatrolSpawnerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PatrolSpawnerMixin.java @@ -1,9 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.PatrolSpawner; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -11,12 +8,15 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Random; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.levelgen.PatrolSpawner; @Mixin(PatrolSpawner.class) public class PatrolSpawnerMixin { - @Inject(method = "spawnPatroller", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - public void arclight$spawnReason(ServerWorld worldIn, BlockPos p_222695_2_, Random random, boolean p_222695_4_, CallbackInfoReturnable cir) { + @Inject(method = "spawnPatrolMember", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + public void arclight$spawnReason(ServerLevel worldIn, BlockPos p_222695_2_, Random random, boolean p_222695_4_, CallbackInfoReturnable cir) { ((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.PATROL); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PhantomSpawnerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PhantomSpawnerMixin.java index a7823a82..8c9e5231 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PhantomSpawnerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/PhantomSpawnerMixin.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.PhantomSpawner; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.levelgen.PhantomSpawner; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -12,8 +12,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PhantomSpawner.class) public class PhantomSpawnerMixin { - @Inject(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - public void arclight$spawnReason(ServerWorld worldIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs, CallbackInfoReturnable cir) { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + public void arclight$spawnReason(ServerLevel worldIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs, CallbackInfoReturnable cir) { ((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.NATURAL); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WanderingTraderSpawnerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WanderingTraderSpawnerMixin.java index 55497a21..f420df5b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WanderingTraderSpawnerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WanderingTraderSpawnerMixin.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.world.WorldBridge; -import net.minecraft.entity.merchant.villager.WanderingTraderEntity; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.WanderingTraderSpawner; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.npc.WanderingTrader; +import net.minecraft.world.entity.npc.WanderingTraderSpawner; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,13 +14,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(WanderingTraderSpawner.class) public class WanderingTraderSpawnerMixin { - @Inject(method = "func_234562_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;")) - public void arclight$spawnReason1(ServerWorld serverWorld, CallbackInfoReturnable cir) { + @Inject(method = "spawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityType;spawn(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/network/chat/Component;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/MobSpawnType;ZZ)Lnet/minecraft/world/entity/Entity;")) + public void arclight$spawnReason1(ServerLevel serverWorld, CallbackInfoReturnable cir) { ((WorldBridge) serverWorld).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.NATURAL); } - @Inject(method = "func_242373_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawn(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/nbt/CompoundNBT;Lnet/minecraft/util/text/ITextComponent;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;")) - public void arclight$spawnReason2(ServerWorld serverWorld, WanderingTraderEntity p_242373_2_, int p_242373_3_, CallbackInfo ci) { + @Inject(method = "tryToSpawnLlamaFor", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/EntityType;spawn(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/network/chat/Component;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/MobSpawnType;ZZ)Lnet/minecraft/world/entity/Entity;")) + public void arclight$spawnReason2(ServerLevel serverWorld, WanderingTrader p_242373_2_, int p_242373_3_, CallbackInfo ci) { ((WorldBridge) serverWorld).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.NATURAL); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawnerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawnerMixin.java index ad145fd8..7a0b84de 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawnerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawnerMixin.java @@ -3,16 +3,6 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.world.IWorldWriterBridge; import io.izzel.arclight.common.bridge.world.WorldBridge; import io.izzel.arclight.common.bridge.world.spawner.WorldEntitySpawnerBridge; -import net.minecraft.entity.EntityClassification; -import net.minecraft.entity.MobEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IServerWorld; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.spawner.WorldEntitySpawner; -import net.minecraft.world.storage.IWorldInfo; import org.bukkit.event.entity.CreatureSpawnEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -24,23 +14,33 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.NaturalSpawner; +import net.minecraft.world.level.ServerLevelAccessor; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.storage.LevelData; -@Mixin(WorldEntitySpawner.class) +@Mixin(NaturalSpawner.class) public abstract class WorldEntitySpawnerMixin { // @formatter:off - @Shadow @Final private static EntityClassification[] field_234961_c_; - @Shadow public static void func_234967_a_(EntityClassification p_234967_0_, ServerWorld p_234967_1_, Chunk p_234967_2_, WorldEntitySpawner.IDensityCheck p_234967_3_, WorldEntitySpawner.IOnSpawnDensityAdder p_234967_4_) { } + @Shadow @Final private static MobCategory[] SPAWNING_CATEGORIES; + @Shadow public static void spawnCategoryForChunk(MobCategory p_234967_0_, ServerLevel p_234967_1_, LevelChunk p_234967_2_, NaturalSpawner.SpawnPredicate p_234967_3_, NaturalSpawner.AfterSpawnCallback p_234967_4_) { } // @formatter:on - @Redirect(method = "func_234964_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;preventDespawn()Z")) - private static boolean arclight$specialDespawn(MobEntity mobEntity) { + @Redirect(method = "createState", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;requiresCustomPersistence()Z")) + private static boolean arclight$specialDespawn(Mob mobEntity) { return false; } - @Redirect(method = "func_234964_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/MobEntity;isNoDespawnRequired()Z")) - private static boolean arclight$specialDespawn2(MobEntity mobEntity) { - return mobEntity.canDespawn(0) && mobEntity.isNoDespawnRequired(); + @Redirect(method = "createState", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;isPersistenceRequired()Z")) + private static boolean arclight$specialDespawn2(Mob mobEntity) { + return mobEntity.removeWhenFarAway(0) && mobEntity.isPersistenceRequired(); } /** @@ -48,18 +48,18 @@ public abstract class WorldEntitySpawnerMixin { * @reason */ @Overwrite - public static void func_234979_a_(ServerWorld world, Chunk chunk, WorldEntitySpawner.EntityDensityManager manager, boolean flag, boolean flag1, boolean flag2) { - world.getProfiler().startSection("spawner"); - EntityClassification[] classifications = field_234961_c_; - IWorldInfo worldInfo = world.getWorldInfo(); + public static void spawnForChunk(ServerLevel world, LevelChunk chunk, NaturalSpawner.SpawnState manager, boolean flag, boolean flag1, boolean flag2) { + world.getProfiler().push("spawner"); + MobCategory[] classifications = SPAWNING_CATEGORIES; + LevelData worldInfo = world.getLevelData(); boolean spawnAnimalThisTick = ((WorldBridge) world).bridge$ticksPerAnimalSpawns() != 0L && worldInfo.getGameTime() % ((WorldBridge) world).bridge$ticksPerAnimalSpawns() == 0L; boolean spawnMonsterThisTick = ((WorldBridge) world).bridge$ticksPerMonsterSpawns() != 0L && worldInfo.getGameTime() % ((WorldBridge) world).bridge$ticksPerMonsterSpawns() == 0L; boolean spawnWaterThisTick = ((WorldBridge) world).bridge$ticksPerWaterSpawns() != 0L && worldInfo.getGameTime() % ((WorldBridge) world).bridge$ticksPerWaterSpawns() == 0L; boolean spawnAmbientThisTick = ((WorldBridge) world).bridge$ticksPerAmbientSpawns() != 0L && worldInfo.getGameTime() % ((WorldBridge) world).bridge$ticksPerAmbientSpawns() == 0L; boolean spawnWaterAmbientThisTick = ((WorldBridge) world).bridge$ticksPerWaterAmbientSpawns() != 0L && worldInfo.getGameTime() % ((WorldBridge) world).bridge$ticksPerWaterAmbientSpawns() == 0L; - for (EntityClassification classification : classifications) { + for (MobCategory classification : classifications) { boolean spawnThisTick = true; - int limit = classification.getMaxNumberOfCreature(); + int limit = classification.getMaxInstancesPerChunk(); switch (classification) { case MONSTER: { spawnThisTick = spawnMonsterThisTick; @@ -89,23 +89,23 @@ public abstract class WorldEntitySpawnerMixin { } if (spawnThisTick) { if (limit != 0) { - if ((flag || !classification.getPeacefulCreature()) && (flag1 || classification.getPeacefulCreature()) && (flag2 || !classification.getAnimal()) + if ((flag || !classification.isFriendly()) && (flag1 || classification.isFriendly()) && (flag2 || !classification.isPersistent()) && ((WorldEntitySpawnerBridge.EntityDensityManagerBridge) manager).bridge$canSpawn(classification, limit)) { - func_234967_a_(classification, world, chunk, ((WorldEntitySpawnerBridge.EntityDensityManagerBridge) manager)::bridge$canSpawn, ((WorldEntitySpawnerBridge.EntityDensityManagerBridge) manager)::bridge$updateDensity); + spawnCategoryForChunk(classification, world, chunk, ((WorldEntitySpawnerBridge.EntityDensityManagerBridge) manager)::bridge$canSpawn, ((WorldEntitySpawnerBridge.EntityDensityManagerBridge) manager)::bridge$updateDensity); } } } } - world.getProfiler().endSection(); + world.getProfiler().pop(); } - @Inject(method = "func_234966_a_", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/server/ServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private static void arclight$naturalSpawn(EntityClassification p_234966_0_, ServerWorld worldIn, IChunk p_234966_2_, BlockPos p_234966_3_, WorldEntitySpawner.IDensityCheck p_234966_4_, WorldEntitySpawner.IOnSpawnDensityAdder p_234966_5_, CallbackInfo ci) { + @Inject(method = "spawnCategoryForPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private static void arclight$naturalSpawn(MobCategory p_234966_0_, ServerLevel worldIn, ChunkAccess p_234966_2_, BlockPos p_234966_3_, NaturalSpawner.SpawnPredicate p_234966_4_, NaturalSpawner.AfterSpawnCallback p_234966_5_, CallbackInfo ci) { ((WorldBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.NATURAL); } - @Inject(method = "performWorldGenSpawning", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/IServerWorld;func_242417_l(Lnet/minecraft/entity/Entity;)V")) - private static void arclight$worldGenSpawn(IServerWorld worldIn, Biome biomeIn, int centerX, int centerZ, Random diameterX, CallbackInfo ci) { + @Inject(method = "spawnMobsForChunkGeneration", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ServerLevelAccessor;addFreshEntityWithPassengers(Lnet/minecraft/world/entity/Entity;)V")) + private static void arclight$worldGenSpawn(ServerLevelAccessor worldIn, Biome biomeIn, int centerX, int centerZ, Random diameterX, CallbackInfo ci) { ((IWorldWriterBridge) worldIn).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.CHUNK_GEN); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawner_EntityDensityManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawner_EntityDensityManagerMixin.java index 7fa1b488..06bfd46e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawner_EntityDensityManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/spawner/WorldEntitySpawner_EntityDensityManagerMixin.java @@ -2,39 +2,39 @@ package io.izzel.arclight.common.mixin.core.world.spawner; import io.izzel.arclight.common.bridge.world.spawner.WorldEntitySpawnerBridge; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.minecraft.entity.EntityClassification; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.MobEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.chunk.IChunk; -import net.minecraft.world.spawner.WorldEntitySpawner; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.NaturalSpawner; +import net.minecraft.world.level.chunk.ChunkAccess; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(WorldEntitySpawner.EntityDensityManager.class) +@Mixin(NaturalSpawner.SpawnState.class) public abstract class WorldEntitySpawner_EntityDensityManagerMixin implements WorldEntitySpawnerBridge.EntityDensityManagerBridge { // @formatter:off - @Shadow protected abstract void func_234990_a_(MobEntity p_234990_1_, IChunk p_234990_2_); - @Shadow @Final private int field_234981_a_; - @Shadow @Final private Object2IntOpenHashMap field_234982_b_; - @Shadow protected abstract boolean func_234989_a_(EntityType p_234989_1_, BlockPos p_234989_2_, IChunk p_234989_3_); + @Shadow protected abstract void afterSpawn(Mob p_234990_1_, ChunkAccess p_234990_2_); + @Shadow @Final private int spawnableChunkCount; + @Shadow @Final private Object2IntOpenHashMap mobCategoryCounts; + @Shadow protected abstract boolean canSpawn(EntityType p_234989_1_, BlockPos p_234989_2_, ChunkAccess p_234989_3_); // @formatter:on @Override - public boolean bridge$canSpawn(EntityType entityType, BlockPos pos, IChunk chunk) { - return this.func_234989_a_(entityType, pos, chunk); + public boolean bridge$canSpawn(EntityType entityType, BlockPos pos, ChunkAccess chunk) { + return this.canSpawn(entityType, pos, chunk); } @Override - public void bridge$updateDensity(MobEntity mobEntity, IChunk chunk) { - this.func_234990_a_(mobEntity, chunk); + public void bridge$updateDensity(Mob mobEntity, ChunkAccess chunk) { + this.afterSpawn(mobEntity, chunk); } @Override - public boolean bridge$canSpawn(EntityClassification classification, int limit) { - int i = limit * this.field_234981_a_ / 289; - return this.field_234982_b_.getInt(classification) < i; + public boolean bridge$canSpawn(MobCategory classification, int limit) { + int i = limit * this.spawnableChunkCount / 289; + return this.mobCategoryCounts.getInt(classification) < i; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/DerivedWorldInfoMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/DerivedWorldInfoMixin.java index 03c97b4a..686f6d93 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/DerivedWorldInfoMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/DerivedWorldInfoMixin.java @@ -2,51 +2,51 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.world.storage.DerivedWorldInfoBridge; import io.izzel.arclight.i18n.ArclightConfig; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.DimensionType; -import net.minecraft.world.storage.DerivedWorldInfo; -import net.minecraft.world.storage.IServerWorldInfo; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.DerivedLevelData; +import net.minecraft.world.level.storage.ServerLevelData; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -@Mixin(DerivedWorldInfo.class) +@Mixin(DerivedLevelData.class) public class DerivedWorldInfoMixin implements DerivedWorldInfoBridge { - @Shadow @Final private IServerWorldInfo delegate; + @Shadow @Final private ServerLevelData wrapped; - private RegistryKey typeKey; + private ResourceKey typeKey; /** * @author IzzelAliz * @reason */ @Overwrite - public String getWorldName() { - if (typeKey == null || typeKey == DimensionType.OVERWORLD) { - return this.delegate.getWorldName(); + public String getLevelName() { + if (typeKey == null || typeKey == DimensionType.OVERWORLD_LOCATION) { + return this.wrapped.getLevelName(); } else { if (ArclightConfig.spec().getCompat().isSymlinkWorld()) { - String worldName = this.delegate.getWorldName() + "_"; + String worldName = this.wrapped.getLevelName() + "_"; String suffix; - if (typeKey == DimensionType.THE_END) { + if (typeKey == DimensionType.END_LOCATION) { suffix = "nether"; - } else if (typeKey == DimensionType.THE_NETHER) { + } else if (typeKey == DimensionType.NETHER_LOCATION) { suffix = "the_end"; } else { - suffix = (typeKey.getLocation().getNamespace() + "/" + typeKey.getLocation().getPath()).replace('/', '_'); + suffix = (typeKey.location().getNamespace() + "/" + typeKey.location().getPath()).replace('/', '_'); } return worldName + suffix; } else { - String worldName = this.delegate.getWorldName() + "/"; + String worldName = this.wrapped.getLevelName() + "/"; String suffix; - if (typeKey == DimensionType.THE_END) { + if (typeKey == DimensionType.END_LOCATION) { suffix = "DIM1"; - } else if (typeKey == DimensionType.THE_NETHER) { + } else if (typeKey == DimensionType.NETHER_LOCATION) { suffix = "DIM-1"; } else { - suffix = typeKey.getLocation().getNamespace() + "/" + typeKey.getLocation().getPath(); + suffix = typeKey.location().getNamespace() + "/" + typeKey.location().getPath(); } return worldName + suffix; } @@ -54,12 +54,12 @@ public class DerivedWorldInfoMixin implements DerivedWorldInfoBridge { } @Override - public IServerWorldInfo bridge$getDelegate() { - return delegate; + public ServerLevelData bridge$getDelegate() { + return wrapped; } @Override - public void bridge$setDimType(RegistryKey typeKey) { + public void bridge$setDimType(ResourceKey typeKey) { this.typeKey = typeKey; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapDataMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapDataMixin.java index c5b6fd5f..19e020e8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapDataMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapDataMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.world.storage.MapDataBridge; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.World; -import net.minecraft.world.storage.MapData; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.CraftWorld; @@ -20,12 +16,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; import java.util.UUID; import java.util.function.Supplier; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; -@Mixin(MapData.class) +@Mixin(MapItemSavedData.class) public abstract class MapDataMixin implements MapDataBridge { // @formatter:off - @Shadow public RegistryKey dimension; + @Shadow public ResourceKey dimension; // @formatter:on public CraftMapView mapView; @@ -34,13 +34,13 @@ public abstract class MapDataMixin implements MapDataBridge { @Inject(method = "", at = @At("RETURN")) public void arclight$init(String mapname, CallbackInfo ci) { - this.mapView = new CraftMapView((MapData) (Object) this); + this.mapView = new CraftMapView((MapItemSavedData) (Object) this); this.server = (CraftServer) Bukkit.getServer(); } @SuppressWarnings("OptionalUsedAsFieldOrParameterType") - @Redirect(method = "read", at = @At(value = "INVOKE", target = "Ljava/util/Optional;orElseThrow(Ljava/util/function/Supplier;)Ljava/lang/Object;")) - public Object arclight$customDimension(Optional> optional, Supplier exceptionSupplier, CompoundNBT nbt) { + @Redirect(method = "load", at = @At(value = "INVOKE", target = "Ljava/util/Optional;orElseThrow(Ljava/util/function/Supplier;)Ljava/lang/Object;")) + public Object arclight$customDimension(Optional> optional, Supplier exceptionSupplier, CompoundTag nbt) { return optional.orElseGet(() -> { long least = nbt.getLong("UUIDLeast"); long most = nbt.getLong("UUIDMost"); @@ -48,19 +48,19 @@ public abstract class MapDataMixin implements MapDataBridge { this.uniqueId = new UUID(most, least); CraftWorld world = (CraftWorld) this.server.getWorld(this.uniqueId); if (world != null) { - return world.getHandle().getDimensionKey(); + return world.getHandle().dimension(); } } throw new IllegalArgumentException("Invalid map dimension: " + nbt.get("dimension")); }); } - @Inject(method = "write", at = @At("HEAD")) - public void arclight$storeDimension(CompoundNBT compound, CallbackInfoReturnable cir) { + @Inject(method = "save", at = @At("HEAD")) + public void arclight$storeDimension(CompoundTag compound, CallbackInfoReturnable cir) { if (this.uniqueId == null) { for (org.bukkit.World world : this.server.getWorlds()) { CraftWorld cWorld = (CraftWorld) world; - if (cWorld.getHandle().getDimensionKey() != this.dimension) continue; + if (cWorld.getHandle().dimension() != this.dimension) continue; this.uniqueId = cWorld.getUID(); break; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapData_MapInfoMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapData_MapInfoMixin.java index 29c30039..a8fbbf8c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapData_MapInfoMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/MapData_MapInfoMixin.java @@ -1,13 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FilledMapItem; -import net.minecraft.item.ItemStack; -import net.minecraft.network.IPacket; -import net.minecraft.network.play.server.SMapDataPacket; -import net.minecraft.world.storage.MapData; -import net.minecraft.world.storage.MapDecoration; import org.bukkit.craftbukkit.v.map.RenderData; import org.bukkit.craftbukkit.v.util.CraftChatMessage; import org.bukkit.map.MapCursor; @@ -18,21 +11,28 @@ import org.spongepowered.asm.mixin.Shadow; import io.izzel.arclight.common.bridge.world.storage.MapDataBridge; import javax.annotation.Nullable; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundMapItemDataPacket; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.MapItem; +import net.minecraft.world.level.saveddata.maps.MapDecoration; +import net.minecraft.world.level.saveddata.maps.MapItemSavedData; import java.util.ArrayList; import java.util.Collection; -@Mixin(MapData.MapInfo.class) +@Mixin(MapItemSavedData.HoldingPlayer.class) public class MapData_MapInfoMixin { // @formatter:off - @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_176107_c"}, remap = false) private MapData outerThis; - @Shadow private boolean isDirty; - @Shadow private int minX; - @Shadow private int minY; - @Shadow private int maxX; - @Shadow private int maxY; + @SuppressWarnings("target") @Shadow(aliases = {"this$0", "field_176107_c"}, remap = false) private MapItemSavedData outerThis; + @Shadow private boolean dirtyData; + @Shadow private int minDirtyX; + @Shadow private int minDirtyY; + @Shadow private int maxDirtyX; + @Shadow private int maxDirtyY; @Shadow private int tick; - @Shadow @Final public PlayerEntity player; + @Shadow @Final public Player player; // @formatter:on /** @@ -41,7 +41,7 @@ public class MapData_MapInfoMixin { */ @Overwrite @Nullable - public IPacket getPacket(ItemStack stack) { + public Packet nextUpdatePacket(ItemStack stack) { RenderData render = ((MapDataBridge) outerThis).bridge$getMapView().render(((ServerPlayerEntityBridge) this.player).bridge$getBukkitEntity()); // CraftBukkit Collection icons = new ArrayList<>(); for (MapCursor cursor : render.cursors) { @@ -50,11 +50,11 @@ public class MapData_MapInfoMixin { cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption()))); } } - if (this.isDirty) { - this.isDirty = false; - return new SMapDataPacket(FilledMapItem.getMapId(stack), outerThis.scale, outerThis.trackingPosition, outerThis.locked, icons, render.buffer, this.minX, this.minY, this.maxX + 1 - this.minX, this.maxY + 1 - this.minY); + if (this.dirtyData) { + this.dirtyData = false; + return new ClientboundMapItemDataPacket(MapItem.getMapId(stack), outerThis.scale, outerThis.trackingPosition, outerThis.locked, icons, render.buffer, this.minDirtyX, this.minDirtyY, this.maxDirtyX + 1 - this.minDirtyX, this.maxDirtyY + 1 - this.minDirtyY); } else { - return this.tick++ % 5 == 0 ? new SMapDataPacket(FilledMapItem.getMapId(stack), outerThis.scale, outerThis.trackingPosition, outerThis.locked, icons, render.buffer, 0, 0, 0, 0) : null; + return this.tick++ % 5 == 0 ? new ClientboundMapItemDataPacket(MapItem.getMapId(stack), outerThis.scale, outerThis.trackingPosition, outerThis.locked, icons, render.buffer, 0, 0, 0, 0) : null; } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/PlayerDataMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/PlayerDataMixin.java index d81df0f9..676355e2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/PlayerDataMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/PlayerDataMixin.java @@ -2,11 +2,6 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.world.storage.PlayerDataBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.world.storage.PlayerData; import org.apache.logging.log4j.Logger; import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.spongepowered.asm.mixin.Final; @@ -18,21 +13,26 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.io.File; import java.io.FileInputStream; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.storage.PlayerDataStorage; -@Mixin(PlayerData.class) +@Mixin(PlayerDataStorage.class) public class PlayerDataMixin implements PlayerDataBridge { // @formatter:off - @Shadow @Final private File playerDataFolder; + @Shadow @Final private File playerDir; @Shadow @Final private static Logger LOGGER; // @formatter:on - @Inject(method = "loadPlayerData", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;contains(Ljava/lang/String;I)Z")) - private void arclight$lastSeenTime(PlayerEntity player, CallbackInfoReturnable cir) { - if (player instanceof ServerPlayerEntity) { + @Inject(method = "load", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;contains(Ljava/lang/String;I)Z")) + private void arclight$lastSeenTime(Player player, CallbackInfoReturnable cir) { + if (player instanceof ServerPlayer) { CraftPlayer craftPlayer = ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(); // Only update first played if it is older than the one we have - long modified = new File(this.playerDataFolder, player.getUniqueID().toString() + ".dat").lastModified(); + long modified = new File(this.playerDir, player.getUUID().toString() + ".dat").lastModified(); if (modified < craftPlayer.getFirstPlayed()) { craftPlayer.setFirstPlayed(modified); } @@ -40,14 +40,14 @@ public class PlayerDataMixin implements PlayerDataBridge { } public File getPlayerDir() { - return this.playerDataFolder; + return this.playerDir; } - public CompoundNBT getPlayerData(String uuid) { + public CompoundTag getPlayerData(String uuid) { try { - final File file1 = new File(this.playerDataFolder, uuid + ".dat"); + final File file1 = new File(this.playerDir, uuid + ".dat"); if (file1.exists()) { - return CompressedStreamTools.readCompressed(new FileInputStream(file1)); + return NbtIo.readCompressed(new FileInputStream(file1)); } } catch (Exception exception) { LOGGER.warn("Failed to load player data for " + uuid); @@ -61,7 +61,7 @@ public class PlayerDataMixin implements PlayerDataBridge { } @Override - public CompoundNBT bridge$getPlayerData(String uuid) { + public CompoundTag bridge$getPlayerData(String uuid) { return getPlayerData(uuid); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormatMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormatMixin.java index 7a5e301f..bcdfd4b0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormatMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormatMixin.java @@ -1,34 +1,34 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.world.storage.SaveFormatBridge; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.Dimension; -import net.minecraft.world.storage.SaveFormat; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import java.io.IOException; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.storage.LevelStorageSource; -@Mixin(SaveFormat.class) +@Mixin(LevelStorageSource.class) public abstract class SaveFormatMixin implements SaveFormatBridge { // @formatter:off - @Shadow public abstract SaveFormat.LevelSave getLevelSave(String saveName) throws IOException; + @Shadow public abstract LevelStorageSource.LevelStorageAccess createAccess(String saveName) throws IOException; // @formatter:on - public SaveFormat.LevelSave getLevelSave(String saveName, RegistryKey world) throws IOException { - SaveFormat.LevelSave save = getLevelSave(saveName); + public LevelStorageSource.LevelStorageAccess getLevelSave(String saveName, ResourceKey world) throws IOException { + LevelStorageSource.LevelStorageAccess save = createAccess(saveName); ((LevelSaveBridge) save).bridge$setDimType(world); return save; } // mock - public SaveFormat.LevelSave c(String saveName, RegistryKey world) throws IOException { + public LevelStorageSource.LevelStorageAccess c(String saveName, ResourceKey world) throws IOException { return getLevelSave(saveName, world); } @Override - public SaveFormat.LevelSave bridge$getLevelSave(String saveName, RegistryKey world) throws IOException { + public LevelStorageSource.LevelStorageAccess bridge$getLevelSave(String saveName, ResourceKey world) throws IOException { return getLevelSave(saveName, world); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormat_LevelSaveMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormat_LevelSaveMixin.java index 15ca2ce1..f4d23d04 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormat_LevelSaveMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/SaveFormat_LevelSaveMixin.java @@ -1,10 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.storage; import io.izzel.arclight.common.bridge.world.storage.SaveFormatBridge; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.Dimension; -import net.minecraft.world.World; -import net.minecraft.world.storage.SaveFormat; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,36 +10,40 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.io.File; import java.nio.file.Path; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.storage.LevelStorageSource; -@Mixin(SaveFormat.LevelSave.class) +@Mixin(LevelStorageSource.LevelStorageAccess.class) public class SaveFormat_LevelSaveMixin implements SaveFormatBridge.LevelSaveBridge { - @Shadow @Final public Path saveDir; + @Shadow @Final public Path levelPath; - private RegistryKey dimensionType; + private ResourceKey dimensionType; - public void arclight$constructor(SaveFormat saveFormat, String saveName) { + public void arclight$constructor(LevelStorageSource saveFormat, String saveName) { throw new RuntimeException(); } - public void arclight$constructor(SaveFormat saveFormat, String saveName, RegistryKey dimensionType) { + public void arclight$constructor(LevelStorageSource saveFormat, String saveName, ResourceKey dimensionType) { arclight$constructor(saveFormat, saveName); this.dimensionType = dimensionType; } @Override - public void bridge$setDimType(RegistryKey typeKey) { + public void bridge$setDimType(ResourceKey typeKey) { this.dimensionType = typeKey; } - @Inject(method = "getDimensionFolder", cancellable = true, at = @At("HEAD")) - private void arclight$useActualType(RegistryKey dimensionKey, CallbackInfoReturnable cir) { - if (dimensionType == Dimension.OVERWORLD) { - cir.setReturnValue(this.saveDir.toFile()); - } else if (dimensionType == Dimension.THE_NETHER) { - cir.setReturnValue(new File(this.saveDir.toFile(), "DIM-1")); - } else if (dimensionType == Dimension.THE_END) { - cir.setReturnValue(new File(this.saveDir.toFile(), "DIM1")); + @Inject(method = "getDimensionPath", cancellable = true, at = @At("HEAD")) + private void arclight$useActualType(ResourceKey dimensionKey, CallbackInfoReturnable cir) { + if (dimensionType == LevelStem.OVERWORLD) { + cir.setReturnValue(this.levelPath.toFile()); + } else if (dimensionType == LevelStem.NETHER) { + cir.setReturnValue(new File(this.levelPath.toFile(), "DIM-1")); + } else if (dimensionType == LevelStem.END) { + cir.setReturnValue(new File(this.levelPath.toFile(), "DIM1")); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/ServerWorldInfoMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/ServerWorldInfoMixin.java index 9e298d91..140a7ab1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/ServerWorldInfoMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/storage/ServerWorldInfoMixin.java @@ -2,13 +2,13 @@ package io.izzel.arclight.common.mixin.core.world.storage; import com.mojang.serialization.Lifecycle; import io.izzel.arclight.common.bridge.world.storage.WorldInfoBridge; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.play.server.SServerDifficultyPacket; +import net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Difficulty; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.server.ServerWorld; -import net.minecraft.world.storage.ServerWorldInfo; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.LevelSettings; +import net.minecraft.world.level.storage.PrimaryLevelData; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.weather.ThunderChangeEvent; @@ -20,19 +20,19 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ServerWorldInfo.class) +@Mixin(PrimaryLevelData.class) public abstract class ServerWorldInfoMixin implements WorldInfoBridge { // @formatter:off - @Shadow public abstract String getWorldName(); + @Shadow public abstract String getLevelName(); @Shadow private boolean thundering; @Shadow private boolean raining; @Shadow public abstract boolean isDifficultyLocked(); - @Shadow private WorldSettings worldSettings; - @Shadow @Final private Lifecycle lifecycle; + @Shadow private LevelSettings settings; + @Shadow @Final private Lifecycle worldGenSettingsLifecycle; // @formatter:on - public ServerWorld world; + public ServerLevel world; @Inject(method = "setThundering", cancellable = true, at = @At("HEAD")) private void arclight$thunder(boolean thunderingIn, CallbackInfo ci) { @@ -40,7 +40,7 @@ public abstract class ServerWorldInfoMixin implements WorldInfoBridge { return; } - World world = Bukkit.getWorld(this.getWorldName()); + World world = Bukkit.getWorld(this.getLevelName()); if (world != null) { ThunderChangeEvent event = new ThunderChangeEvent(world, thunderingIn); Bukkit.getServer().getPluginManager().callEvent(event); @@ -56,7 +56,7 @@ public abstract class ServerWorldInfoMixin implements WorldInfoBridge { return; } - World world = Bukkit.getWorld(this.getWorldName()); + World world = Bukkit.getWorld(this.getLevelName()); if (world != null) { WeatherChangeEvent event = new WeatherChangeEvent(world, isRaining); Bukkit.getServer().getPluginManager().callEvent(event); @@ -68,35 +68,35 @@ public abstract class ServerWorldInfoMixin implements WorldInfoBridge { @Inject(method = "setDifficulty", at = @At("RETURN")) private void arclight$sendDiffChange(Difficulty newDifficulty, CallbackInfo ci) { - SServerDifficultyPacket packet = new SServerDifficultyPacket(newDifficulty, this.isDifficultyLocked()); - for (PlayerEntity player : this.world.getPlayers()) { - ((ServerPlayerEntity) player).connection.sendPacket(packet); + ClientboundChangeDifficultyPacket packet = new ClientboundChangeDifficultyPacket(newDifficulty, this.isDifficultyLocked()); + for (Player player : this.world.players()) { + ((ServerPlayer) player).connection.send(packet); } } @Override - public void bridge$setWorld(ServerWorld world) { + public void bridge$setWorld(ServerLevel world) { this.world = world; } @Override - public ServerWorld bridge$getWorld() { + public ServerLevel bridge$getWorld() { return world; } public void checkName(String name) { - if (!this.worldSettings.worldName.equals(name)) { - this.worldSettings.worldName = name; + if (!this.settings.levelName.equals(name)) { + this.settings.levelName = name; } } @Override - public WorldSettings bridge$getWorldSettings() { - return this.worldSettings; + public LevelSettings bridge$getWorldSettings() { + return this.settings; } @Override public Lifecycle bridge$getLifecycle() { - return this.lifecycle; + return this.worldGenSettingsLifecycle; } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/FMLWorldPersistenceHookMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/FMLWorldPersistenceHookMixin.java index 69f32b79..399684bc 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/FMLWorldPersistenceHookMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/FMLWorldPersistenceHookMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.forge; import com.google.common.collect.Multimap; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.ListNBT; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.storage.IServerConfiguration; -import net.minecraft.world.storage.SaveFormat; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.storage.LevelStorageSource; +import net.minecraft.world.level.storage.WorldData; import net.minecraftforge.fml.FMLWorldPersistenceHook; import net.minecraftforge.fml.MavenVersionStringHelper; import net.minecraftforge.fml.ModList; @@ -31,19 +31,19 @@ public class FMLWorldPersistenceHookMixin { @Shadow @Final private static Logger LOGGER; @Shadow @Final private static Marker WORLDPERSISTENCE; - private final Map map = new HashMap<>(); + private final Map map = new HashMap<>(); private boolean injected = false; @Redirect(method = "readData", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/registries/GameData;injectSnapshot(Ljava/util/Map;ZZ)Lcom/google/common/collect/Multimap;")) private Multimap arclight$handleInject(Map snapshot, boolean injectFrozenData, boolean isLocalWorld, - SaveFormat.LevelSave levelSave, IServerConfiguration serverInfo, CompoundNBT tag) { + LevelStorageSource.LevelStorageAccess levelSave, WorldData serverInfo, CompoundTag tag) { if (!injected) { injected = true; return GameData.injectSnapshot(snapshot, injectFrozenData, isLocalWorld); } else { // TODO Properly remap registry and id map.put(levelSave.getWorldDir(), tag.getCompound("Registries").copy()); - LOGGER.debug(WORLDPERSISTENCE, "Skipped registry injection for {}", serverInfo.getWorldName()); + LOGGER.debug(WORLDPERSISTENCE, "Skipped registry injection for {}", serverInfo.getLevelName()); return null; } } @@ -53,31 +53,31 @@ public class FMLWorldPersistenceHookMixin { * @reason */ @Overwrite - public CompoundNBT getDataForWriting(SaveFormat.LevelSave levelSave, IServerConfiguration serverInfo) { - CompoundNBT fmlData = new CompoundNBT(); - ListNBT modList = new ListNBT(); + public CompoundTag getDataForWriting(LevelStorageSource.LevelStorageAccess levelSave, WorldData serverInfo) { + CompoundTag fmlData = new CompoundTag(); + ListTag modList = new ListTag(); ModList.get().getMods().forEach(mi -> { - final CompoundNBT mod = new CompoundNBT(); + final CompoundTag mod = new CompoundTag(); mod.putString("ModId", mi.getModId()); mod.putString("ModVersion", MavenVersionStringHelper.artifactVersionToString(mi.getVersion())); modList.add(mod); }); fmlData.put("LoadingModList", modList); - CompoundNBT nbt = map.get(levelSave.getWorldDir()); + CompoundTag nbt = map.get(levelSave.getWorldDir()); if (nbt != null) { fmlData.put("Registries", nbt); - LOGGER.debug(WORLDPERSISTENCE, "Skipped ID Map collection for {}", serverInfo.getWorldName()); + LOGGER.debug(WORLDPERSISTENCE, "Skipped ID Map collection for {}", serverInfo.getLevelName()); } else { - CompoundNBT registries = new CompoundNBT(); + CompoundTag registries = new CompoundTag(); fmlData.put("Registries", registries); - LOGGER.debug(WORLDPERSISTENCE, "Gathering id map for writing to world save {}", serverInfo.getWorldName()); + LOGGER.debug(WORLDPERSISTENCE, "Gathering id map for writing to world save {}", serverInfo.getLevelName()); for (Map.Entry e : RegistryManager.ACTIVE.takeSnapshot(true).entrySet()) { registries.put(e.getKey().toString(), e.getValue().write()); } - LOGGER.debug(WORLDPERSISTENCE, "ID Map collection complete {}", serverInfo.getWorldName()); + LOGGER.debug(WORLDPERSISTENCE, "ID Map collection complete {}", serverInfo.getLevelName()); } return fmlData; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeEventFactoryMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeEventFactoryMixin.java index 983db461..1788acc4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeEventFactoryMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeEventFactoryMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.forge; -import net.minecraft.entity.Entity; -import net.minecraft.util.Direction; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.Entity; import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.event.ForgeEventFactory; import org.spongepowered.asm.mixin.Mixin; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java index 70ae0213..d49092c2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeHooksMixin.java @@ -1,12 +1,12 @@ package io.izzel.arclight.common.mixin.forge; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemUseContext; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.Level; import net.minecraftforge.common.ForgeHooks; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -18,18 +18,18 @@ import io.izzel.arclight.common.mod.util.ArclightCaptures; public class ForgeHooksMixin { @Inject(method = "onPlaceItemIntoWorld", remap = false, at = @At("HEAD")) - private static void arclight$captureHand(ItemUseContext context, CallbackInfoReturnable cir) { + private static void arclight$captureHand(UseOnContext context, CallbackInfoReturnable cir) { ArclightCaptures.capturePlaceEventHand(context.getHand()); } @Inject(method = "onPlaceItemIntoWorld", remap = false, at = @At("RETURN")) - private static void arclight$removeHand(ItemUseContext context, CallbackInfoReturnable cir) { - ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND); + private static void arclight$removeHand(UseOnContext context, CallbackInfoReturnable cir) { + ArclightCaptures.getPlaceEventHand(InteractionHand.MAIN_HAND); } @Inject(method = "canEntityDestroy", cancellable = true, remap = false, at = @At("HEAD")) - private static void arclight$returnIfNotLoaded(World world, BlockPos pos, LivingEntity entity, CallbackInfoReturnable cir) { - if (!world.getChunkProvider().isChunkLoaded(new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4))) { + private static void arclight$returnIfNotLoaded(Level world, BlockPos pos, LivingEntity entity, CallbackInfoReturnable cir) { + if (!world.getChunkSource().isEntityTickingChunk(new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4))) { cir.setReturnValue(false); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/NetworkHooksMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/NetworkHooksMixin.java index 0973ecfe..17c91b48 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/NetworkHooksMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/NetworkHooksMixin.java @@ -2,13 +2,13 @@ package io.izzel.arclight.common.mixin.forge; import io.izzel.arclight.common.bridge.inventory.container.ContainerBridge; import io.izzel.arclight.common.mod.util.ArclightCaptures; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; +import net.minecraft.network.Connection; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraftforge.fml.network.NetworkHooks; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; @@ -24,24 +24,24 @@ import java.util.function.Consumer; @Mixin(NetworkHooks.class) public class NetworkHooksMixin { - @Inject(method = "openGui(Lnet/minecraft/entity/player/ServerPlayerEntity;Lnet/minecraft/inventory/container/INamedContainerProvider;Ljava/util/function/Consumer;)V", - cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/container/Container;getType()Lnet/minecraft/inventory/container/ContainerType;")) - private static void arclight$openContainer(ServerPlayerEntity player, INamedContainerProvider containerSupplier, Consumer extraDataWriter, CallbackInfo ci, - int currentId, PacketBuffer extraData, PacketBuffer output, Container container) { + @Inject(method = "openGui(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/MenuProvider;Ljava/util/function/Consumer;)V", + cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;getType()Lnet/minecraft/world/inventory/MenuType;")) + private static void arclight$openContainer(ServerPlayer player, MenuProvider containerSupplier, Consumer extraDataWriter, CallbackInfo ci, + int currentId, FriendlyByteBuf extraData, FriendlyByteBuf output, AbstractContainerMenu container) { ((ContainerBridge) container).bridge$setTitle(containerSupplier.getDisplayName()); ArclightCaptures.captureContainerOwner(player); container = CraftEventFactory.callInventoryOpenEvent(player, container); ArclightCaptures.resetContainerOwner(); if (container == null) { - if (containerSupplier instanceof IInventory) { - ((IInventory) containerSupplier).closeInventory(player); + if (containerSupplier instanceof Container) { + ((Container) containerSupplier).stopOpen(player); } ci.cancel(); } } @Inject(method = "sendMCRegistryPackets", remap = false, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/network/FMLMCRegisterPacketHandler;addChannels(Ljava/util/Set;Lnet/minecraft/network/NetworkManager;)V")) - private static void arclight$withBukkitChannels(NetworkManager manager, String direction, CallbackInfo ci, Set resourceLocations) { + private static void arclight$withBukkitChannels(Connection manager, String direction, CallbackInfo ci, Set resourceLocations) { Bukkit.getMessenger().getIncomingChannels().stream().map(ResourceLocation::new).forEach(resourceLocations::add); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/PacketDistributorMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/PacketDistributorMixin.java index 74122113..d825f2df 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/PacketDistributorMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/PacketDistributorMixin.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mixin.forge; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; +import net.minecraft.network.protocol.Packet; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.fml.network.PacketDistributor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -17,11 +17,11 @@ public class PacketDistributorMixin { * @reason */ @Overwrite(remap = false) - private Consumer> playerConsumer(Supplier entityPlayerMPSupplier) { + private Consumer> playerConsumer(Supplier entityPlayerMPSupplier) { return p -> { - ServerPlayerEntity entity = entityPlayerMPSupplier.get(); - if (entity.connection != null && entity.connection.netManager != null) { - entity.connection.netManager.sendPacket(p); + ServerPlayer entity = entityPlayerMPSupplier.get(); + if (entity.connection != null && entity.connection.connection != null) { + entity.connection.connection.send(p); } }; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/ArclightConstants.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/ArclightConstants.java index 4bdc1fe4..bf8faec2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/ArclightConstants.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/ArclightConstants.java @@ -3,15 +3,15 @@ package io.izzel.arclight.common.mod; import com.google.common.collect.ImmutableList; import io.izzel.arclight.api.EnumHelper; import io.izzel.arclight.api.Unsafe; -import net.minecraft.loot.LootParameter; -import net.minecraft.loot.LootParameters; +import net.minecraft.world.level.storage.loot.parameters.LootContextParam; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import org.bukkit.TreeType; public class ArclightConstants { public static final TreeType MOD = EnumHelper.addEnum(TreeType.class, "MOD", ImmutableList.of(), ImmutableList.of()); - public static final LootParameter LOOTING_MOD = Unsafe.getStatic(LootParameters.class, "LOOTING_MOD"); + public static final LootContextParam LOOTING_MOD = Unsafe.getStatic(LootContextParams.class, "LOOTING_MOD"); /** * Arclight marker magic value for non-used custom dimension diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/compat/AstralSorceryHooks.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/compat/AstralSorceryHooks.java index a61f8740..96876cb1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/compat/AstralSorceryHooks.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/compat/AstralSorceryHooks.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mod.compat; -import net.minecraft.entity.Entity; +import net.minecraft.world.entity.Entity; public class AstralSorceryHooks { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightContainer.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightContainer.java index 7f9a8a0c..9dd75d5c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightContainer.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightContainer.java @@ -8,13 +8,12 @@ import io.izzel.arclight.common.mod.ArclightMod; import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.tools.product.Product; import io.izzel.tools.product.Product2; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.Container; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Recipe; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.SlotItemHandler; @@ -54,21 +53,21 @@ public class ArclightContainer { } } - private static IInventory getActualInventoryForSlot(Slot slot) { + private static Container getActualInventoryForSlot(Slot slot) { if (slot instanceof SlotItemHandler) { return getInventoryFromWrapper(((SlotItemHandler) slot).getItemHandler()); } else { - return slot.inventory; + return slot.container; } } - private static IInventory getInventoryFromWrapper(IItemHandler handler) { + private static Container getInventoryFromWrapper(IItemHandler handler) { if (handler instanceof CombinedInvWrapper) { IItemHandlerModifiable[] handlers = ((IItemHandlerModifiable[]) Unsafe.getObject(handler, HANDLERS_OFFSET)); - IInventory last = null; + Container last = null; for (IItemHandlerModifiable modifiable : handlers) { - IInventory inventory = getInventoryFromWrapper(modifiable); - if (inventory instanceof PlayerInventory) { + Container inventory = getInventoryFromWrapper(modifiable); + if (inventory instanceof net.minecraft.world.entity.player.Inventory) { return inventory; } else { last = inventory; @@ -84,18 +83,18 @@ public class ArclightContainer { } } - public static InventoryView createInvView(Container container) { - Product2 containerInfo = getContainerInfo(container); + public static InventoryView createInvView(AbstractContainerMenu container) { + Product2 containerInfo = getContainerInfo(container); Inventory viewing = new CraftInventory(new ContainerInvWrapper(container, containerInfo._2, containerInfo._1)); return new CraftInventoryView(((PlayerEntityBridge) containerInfo._1).bridge$getBukkitEntity(), viewing, container); } - public static void updateView(Container container, InventoryView inventoryView) { + public static void updateView(AbstractContainerMenu container, InventoryView inventoryView) { Inventory topInventory = inventoryView.getTopInventory(); if (topInventory instanceof CraftInventory) { - IInventory inventory = ((CraftInventory) topInventory).getInventory(); + Container inventory = ((CraftInventory) topInventory).getInventory(); if (inventory instanceof ContainerInvWrapper) { - Product2 containerInfo = getContainerInfo(container); + Product2 containerInfo = getContainerInfo(container); ((ContainerInvWrapper) inventory).setOwner(((PlayerEntityBridge) containerInfo._1).bridge$getBukkitEntity()); ((ContainerInvWrapper) inventory).setSize(containerInfo._2); } @@ -103,17 +102,17 @@ public class ArclightContainer { } // todo check this - private static Product2 getContainerInfo(Container container) { - PlayerEntity candidate = ArclightCaptures.getContainerOwner(); + private static Product2 getContainerInfo(AbstractContainerMenu container) { + Player candidate = ArclightCaptures.getContainerOwner(); int bottomBegin = -1, bottomEnd = -1; - for (ListIterator iterator = container.inventorySlots.listIterator(); iterator.hasNext(); ) { + for (ListIterator iterator = container.slots.listIterator(); iterator.hasNext(); ) { Slot slot = iterator.next(); - IInventory inventory = getActualInventoryForSlot(slot); - if (inventory instanceof PlayerInventory) { - if (candidate != null && ((PlayerInventory) inventory).player != candidate) { - ArclightMod.LOGGER.warn("Multiple player found in {}/{}, previous {}, new {}", container, container.getClass(), candidate, ((PlayerInventory) inventory).player); + Container inventory = getActualInventoryForSlot(slot); + if (inventory instanceof net.minecraft.world.entity.player.Inventory) { + if (candidate != null && ((net.minecraft.world.entity.player.Inventory) inventory).player != candidate) { + ArclightMod.LOGGER.warn("Multiple player found in {}/{}, previous {}, new {}", container, container.getClass(), candidate, ((net.minecraft.world.entity.player.Inventory) inventory).player); } - candidate = ((PlayerInventory) inventory).player; + candidate = ((net.minecraft.world.entity.player.Inventory) inventory).player; if (bottomBegin == -1 || bottomBegin < bottomEnd) { bottomBegin = iterator.previousIndex(); } @@ -127,19 +126,19 @@ public class ArclightContainer { throw new RuntimeException("candidate cannot be null, " + container + "/" + container.getClass()); } if (bottomBegin < bottomEnd || bottomBegin == -1) { - bottomBegin = container.inventorySlots.size(); + bottomBegin = container.slots.size(); } return Product.of(candidate, bottomBegin); } - private static class ContainerInvWrapper implements IInventory, IInventoryBridge { + private static class ContainerInvWrapper implements Container, IInventoryBridge { - private final Container container; + private final AbstractContainerMenu container; private int size; private InventoryHolder owner; private final List viewers = new ArrayList<>(); - public ContainerInvWrapper(Container container, int size, PlayerEntity owner) { + public ContainerInvWrapper(AbstractContainerMenu container, int size, Player owner) { this.container = container; this.size = size; this.owner = ((PlayerEntityBridge) owner).bridge$getBukkitEntity(); @@ -150,68 +149,68 @@ public class ArclightContainer { } @Override - public int getSizeInventory() { + public int getContainerSize() { return size; } @Override public boolean isEmpty() { - for (Slot slot : container.inventorySlots) { - if (!slot.getStack().isEmpty()) return false; + for (Slot slot : container.slots) { + if (!slot.getItem().isEmpty()) return false; } return true; } @Override - public @NotNull ItemStack getStackInSlot(int index) { + public @NotNull ItemStack getItem(int index) { if (index >= size) return ItemStack.EMPTY; - return container.getSlot(index).getStack(); + return container.getSlot(index).getItem(); } @Override - public @NotNull ItemStack decrStackSize(int index, int count) { + public @NotNull ItemStack removeItem(int index, int count) { if (index >= size) return ItemStack.EMPTY; - return container.getSlot(index).decrStackSize(count); + return container.getSlot(index).remove(count); } @Override - public @NotNull ItemStack removeStackFromSlot(int index) { + public @NotNull ItemStack removeItemNoUpdate(int index) { if (index >= size) return ItemStack.EMPTY; - return container.getSlot(index).decrStackSize(Integer.MAX_VALUE); + return container.getSlot(index).remove(Integer.MAX_VALUE); } @Override - public void setInventorySlotContents(int index, @NotNull ItemStack stack) { + public void setItem(int index, @NotNull ItemStack stack) { if (index >= size) return; - container.putStackInSlot(index, stack); + container.setItem(index, stack); } @Override - public int getInventoryStackLimit() { + public int getMaxStackSize() { if (size <= 0) return 0; - return container.getSlot(0).getSlotStackLimit(); + return container.getSlot(0).getMaxStackSize(); } @Override - public void markDirty() { + public void setChanged() { } @Override - public boolean isUsableByPlayer(@NotNull PlayerEntity player) { - return this.container.canInteractWith(player); + public boolean stillValid(@NotNull Player player) { + return this.container.stillValid(player); } @Override - public void clear() { - for (Slot slot : this.container.inventorySlots) { - slot.decrStackSize(Integer.MAX_VALUE); + public void clearContent() { + for (Slot slot : this.container.slots) { + slot.remove(Integer.MAX_VALUE); } } @Override public List getContents() { - container.detectAndSendChanges(); - return container.inventoryItemStacks.subList(0, size); + container.broadcastChanges(); + return container.lastSlots.subList(0, size); } @Override @@ -252,12 +251,12 @@ public class ArclightContainer { } @Override - public IRecipe getCurrentRecipe() { + public Recipe getCurrentRecipe() { return null; } @Override - public void setCurrentRecipe(IRecipe recipe) { + public void setCurrentRecipe(Recipe recipe) { } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightPermissionHandler.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightPermissionHandler.java index ddef84bc..772227f3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightPermissionHandler.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightPermissionHandler.java @@ -2,7 +2,6 @@ package io.izzel.arclight.common.mod.server; import com.mojang.authlib.GameProfile; import io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge; -import net.minecraft.entity.player.PlayerEntity; import net.minecraftforge.server.permission.DefaultPermissionLevel; import net.minecraftforge.server.permission.IPermissionHandler; import net.minecraftforge.server.permission.context.IContext; @@ -65,7 +64,7 @@ public class ArclightPermissionHandler implements IPermissionHandler { @Override public boolean hasPermission(@NotNull GameProfile profile, @NotNull String node, @Nullable IContext context) { if (context != null) { - PlayerEntity player = context.getPlayer(); + net.minecraft.world.entity.player.Player player = context.getPlayer(); if (player != null) { return ((PlayerEntityBridge) player).bridge$getBukkitEntity().hasPermission(node); } @@ -75,7 +74,7 @@ public class ArclightPermissionHandler implements IPermissionHandler { return player.hasPermission(node); } else { Permission perm = Bukkit.getServer().getPluginManager().getPermission(node); - boolean isOp = ArclightServer.getMinecraftServer().getPlayerList().canSendCommands(profile); + boolean isOp = ArclightServer.getMinecraftServer().getPlayerList().isOp(profile); if (perm != null) { return perm.getDefault().getValue(isOp); } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightServer.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightServer.java index 8d054430..325db258 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightServer.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/ArclightServer.java @@ -3,11 +3,11 @@ package io.izzel.arclight.common.mod.server; import io.izzel.arclight.common.bridge.bukkit.CraftServerBridge; import io.izzel.arclight.common.bridge.server.MinecraftServerBridge; import io.izzel.arclight.common.mod.ArclightMod; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.DedicatedServer; -import net.minecraft.server.management.PlayerList; -import net.minecraft.util.RegistryKey; -import net.minecraft.world.DimensionType; +import net.minecraft.server.players.PlayerList; +import net.minecraft.world.level.dimension.DimensionType; import net.minecraftforge.fml.server.ServerLifecycleHooks; import org.bukkit.World; import org.bukkit.craftbukkit.v.CraftServer; @@ -54,7 +54,7 @@ public class ArclightServer { public static boolean isPrimaryThread() { if (server == null) { - return Thread.currentThread().equals(getMinecraftServer().getExecutionThread()); + return Thread.currentThread().equals(getMinecraftServer().getRunningThread()); } else { return server.isPrimaryThread(); } @@ -66,8 +66,8 @@ public class ArclightServer { public static void executeOnMainThread(Runnable runnable) { ((MinecraftServerBridge) getMinecraftServer()).bridge$queuedProcess(runnable); - if (LockSupport.getBlocker(getMinecraftServer().getExecutionThread()) == "waiting for tasks") { - LockSupport.unpark(getMinecraftServer().getExecutionThread()); + if (LockSupport.getBlocker(getMinecraftServer().getRunningThread()) == "waiting for tasks") { + LockSupport.unpark(getMinecraftServer().getRunningThread()); } } @@ -75,11 +75,11 @@ public class ArclightServer { return mainThreadExecutor; } - public static World.Environment getEnvironment(RegistryKey key) { + public static World.Environment getEnvironment(ResourceKey key) { return BukkitRegistry.DIM_MAP.get(key); } - public static RegistryKey getDimensionType(World.Environment environment) { + public static ResourceKey getDimensionType(World.Environment environment) { return BukkitRegistry.DIM_MAP.inverse().get(environment); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java index 03a0f199..9a6fb587 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java @@ -16,19 +16,19 @@ import io.izzel.arclight.common.mod.util.types.ArclightPotionEffect; import io.izzel.arclight.i18n.ArclightConfig; import io.izzel.arclight.i18n.conf.EntityPropertySpec; import io.izzel.arclight.i18n.conf.MaterialPropertySpec; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.entity.item.PaintingType; -import net.minecraft.entity.merchant.villager.VillagerProfession; -import net.minecraft.item.Item; -import net.minecraft.item.Items; -import net.minecraft.potion.Effect; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.stats.StatType; import net.minecraft.stats.Stats; -import net.minecraft.util.RegistryKey; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.DimensionType; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.decoration.Motive; +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.dimension.DimensionType; import net.minecraftforge.fml.CrashReportExtender; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistry; @@ -70,11 +70,11 @@ public class BukkitRegistry { private static final Map MATERIAL_BLOCK = Unsafe.getStatic(CraftMagicNumbers.class, "MATERIAL_BLOCK"); private static final Map ENTITY_NAME_MAP = Unsafe.getStatic(EntityType.class, "NAME_MAP"); private static final Map ENVIRONMENT_MAP = Unsafe.getStatic(World.Environment.class, "lookup"); - static final BiMap, World.Environment> DIM_MAP = - HashBiMap.create(ImmutableMap., World.Environment>builder() - .put(DimensionType.OVERWORLD, World.Environment.NORMAL) - .put(DimensionType.THE_NETHER, World.Environment.NETHER) - .put(DimensionType.THE_END, World.Environment.THE_END) + static final BiMap, World.Environment> DIM_MAP = + HashBiMap.create(ImmutableMap., World.Environment>builder() + .put(DimensionType.OVERWORLD_LOCATION, World.Environment.NORMAL) + .put(DimensionType.NETHER_LOCATION, World.Environment.NETHER) + .put(DimensionType.END_LOCATION, World.Environment.THE_END) .build()); private static final Map ART_BY_NAME = Unsafe.getStatic(Art.class, "BY_NAME"); private static final Map ART_BY_ID = Unsafe.getStatic(Art.class, "BY_ID"); @@ -141,7 +141,7 @@ public class BukkitRegistry { List newTypes = new ArrayList<>(); Field key = Arrays.stream(Art.class.getDeclaredFields()).filter(it -> it.getName().equals("key")).findAny().orElse(null); long keyOffset = Unsafe.objectFieldOffset(key); - for (PaintingType paintingType : ForgeRegistries.PAINTING_TYPES) { + for (Motive paintingType : ForgeRegistries.PAINTING_TYPES) { String lookupName = paintingType.getRegistryName().getPath().toLowerCase(Locale.ROOT); Art bukkit = Art.getByName(lookupName); if (bukkit == null) { @@ -163,7 +163,7 @@ public class BukkitRegistry { List newTypes = new ArrayList<>(); Field key = Arrays.stream(Biome.class.getDeclaredFields()).filter(it -> it.getName().equals("key")).findAny().orElse(null); long keyOffset = Unsafe.objectFieldOffset(key); - for (net.minecraft.world.biome.Biome biome : ForgeRegistries.BIOMES) { + for (net.minecraft.world.level.biome.Biome biome : ForgeRegistries.BIOMES) { String name = ResourceLocationUtil.standardize(biome.getRegistryName()); Biome bukkit; try { @@ -209,17 +209,17 @@ public class BukkitRegistry { public static void registerEnvironments() { int i = World.Environment.values().length; List newTypes = new ArrayList<>(); - Registry registry = ArclightServer.getMinecraftServer().getDynamicRegistries().getRegistry(Registry.DIMENSION_TYPE_KEY); - for (Map.Entry, DimensionType> entry : registry.getEntries()) { - RegistryKey key = entry.getKey(); + Registry registry = ArclightServer.getMinecraftServer().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY); + for (Map.Entry, DimensionType> entry : registry.entrySet()) { + ResourceKey key = entry.getKey(); World.Environment environment = DIM_MAP.get(key); if (environment == null) { - String name = ResourceLocationUtil.standardize(key.getLocation()); + String name = ResourceLocationUtil.standardize(key.location()); environment = EnumHelper.makeEnum(World.Environment.class, name, i, ENV_CTOR, ImmutableList.of(i - 1)); newTypes.add(environment); ENVIRONMENT_MAP.put(i - 1, environment); DIM_MAP.put(key, environment); - ArclightMod.LOGGER.debug("Registered {} as environment {}", key.getLocation(), environment); + ArclightMod.LOGGER.debug("Registered {} as environment {}", key.location(), environment); i++; } } @@ -231,7 +231,7 @@ public class BukkitRegistry { int origin = EntityType.values().length; int i = origin; List newTypes = new ArrayList<>(ForgeRegistries.ENTITIES.getEntries().size() - origin + 1); // UNKNOWN - for (net.minecraft.entity.EntityType type : ForgeRegistries.ENTITIES) { + for (net.minecraft.world.entity.EntityType type : ForgeRegistries.ENTITIES) { ResourceLocation location = type.getRegistryName(); EntityType entityType = null; boolean found = false; @@ -257,7 +257,7 @@ public class BukkitRegistry { int origin = Enchantment.values().length; int size = ForgeRegistries.ENCHANTMENTS.getEntries().size(); putBool(Enchantment.class, "acceptingNew", true); - for (net.minecraft.enchantment.Enchantment enc : ForgeRegistries.ENCHANTMENTS) { + for (net.minecraft.world.item.enchantment.Enchantment enc : ForgeRegistries.ENCHANTMENTS) { try { String name = ResourceLocationUtil.standardize(enc.getRegistryName()); ArclightEnchantment enchantment = new ArclightEnchantment(enc, name); @@ -274,11 +274,11 @@ public class BukkitRegistry { private static void loadPotions() { int origin = PotionEffectType.values().length; int size = ForgeRegistries.POTIONS.getEntries().size(); - int maxId = ForgeRegistries.POTIONS.getValues().stream().mapToInt(Effect::getId).max().orElse(0); + int maxId = ForgeRegistries.POTIONS.getValues().stream().mapToInt(MobEffect::getId).max().orElse(0); PotionEffectType[] types = new PotionEffectType[maxId + 1]; putStatic(PotionEffectType.class, "byId", types); putBool(PotionEffectType.class, "acceptingNew", true); - for (Effect eff : ForgeRegistries.POTIONS) { + for (MobEffect eff : ForgeRegistries.POTIONS) { try { String name = ResourceLocationUtil.standardize(eff.getRegistryName()); ArclightPotionEffect effect = new ArclightPotionEffect(eff, name); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ArclightTileInventory.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ArclightTileInventory.java index ec6ede34..83be1559 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ArclightTileInventory.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ArclightTileInventory.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.block; -import net.minecraft.inventory.IInventory; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.Container; +import net.minecraft.world.level.block.entity.BlockEntity; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v.block.CraftBlockEntityState; import org.bukkit.craftbukkit.v.inventory.CraftInventory; @@ -9,7 +9,7 @@ import org.bukkit.inventory.BlockInventoryHolder; import org.bukkit.inventory.Inventory; import org.jetbrains.annotations.NotNull; -public class ArclightTileInventory extends CraftBlockEntityState implements BlockInventoryHolder { +public class ArclightTileInventory extends CraftBlockEntityState implements BlockInventoryHolder { public ArclightTileInventory(Block block, Class tileEntityClass) { super(block, tileEntityClass); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/CauldronHooks.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/CauldronHooks.java new file mode 100644 index 00000000..955f074c --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/CauldronHooks.java @@ -0,0 +1,58 @@ +package io.izzel.arclight.common.mod.server.block; + +import io.izzel.arclight.common.bridge.entity.EntityBridge; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v.block.CraftBlock; +import org.bukkit.craftbukkit.v.block.CraftBlockState; +import org.bukkit.event.block.CauldronLevelChangeEvent; + +public class CauldronHooks { + + private static Entity entity; + private static CauldronLevelChangeEvent.ChangeReason reason = CauldronLevelChangeEvent.ChangeReason.UNKNOWN; + private static boolean lastRet = true; + + public static void setChangeReason(Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { + CauldronHooks.entity = entity; + CauldronHooks.reason = reason; + } + + public static void reset() { + CauldronHooks.entity = null; + CauldronHooks.reason = CauldronLevelChangeEvent.ChangeReason.UNKNOWN; + CauldronHooks.lastRet = true; + } + + public static Entity getEntity() { + return entity; + } + + public static CauldronLevelChangeEvent.ChangeReason getReason() { + return reason; + } + + public static boolean getResult() { + return lastRet; + } + + public static boolean changeLevel(BlockState old, Level world, BlockPos pos, BlockState state, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { + CraftBlockState newState = CraftBlockState.getBlockState(world, pos); + newState.setData(state); + CauldronLevelChangeEvent event = new CauldronLevelChangeEvent( + CraftBlock.at(world, pos), + (entity == null) ? null : ((EntityBridge) entity).bridge$getBukkitEntity(), + reason, newState + ); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + return lastRet = false; + } else { + newState.update(true); + return lastRet = true; + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ChestBlockDoubleInventoryHacks.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ChestBlockDoubleInventoryHacks.java similarity index 57% rename from arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ChestBlockDoubleInventoryHacks.java rename to arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ChestBlockDoubleInventoryHacks.java index 93b3f757..54d7575f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ChestBlockDoubleInventoryHacks.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/block/ChestBlockDoubleInventoryHacks.java @@ -1,9 +1,9 @@ -package io.izzel.arclight.common.mod.util; +package io.izzel.arclight.common.mod.server.block; import io.izzel.arclight.api.Unsafe; -import net.minecraft.inventory.DoubleSidedInventory; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.tileentity.ChestTileEntity; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.level.block.entity.ChestBlockEntity; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType; @@ -20,23 +20,23 @@ public class ChestBlockDoubleInventoryHacks { cl = Class.forName("net.minecraft.block.ChestBlock$DoubleInventory"); Field field = cl.getDeclaredField("inventorylargechest"); offset = Unsafe.objectFieldOffset(field); - ctor = Unsafe.lookup().findConstructor(cl, MethodType.methodType(void.class, ChestTileEntity.class, ChestTileEntity.class, DoubleSidedInventory.class)); + ctor = Unsafe.lookup().findConstructor(cl, MethodType.methodType(void.class, ChestBlockEntity.class, ChestBlockEntity.class, CompoundContainer.class)); } catch (Exception e) { e.printStackTrace(); } } - public static DoubleSidedInventory get(Object obj) { - return (DoubleSidedInventory) Unsafe.getObject(obj, offset); + public static CompoundContainer get(Object obj) { + return (CompoundContainer) Unsafe.getObject(obj, offset); } public static boolean isInstance(Object obj) { return cl.isInstance(obj); } - public static INamedContainerProvider create(ChestTileEntity entity, ChestTileEntity entity1, DoubleSidedInventory inventory) { + public static MenuProvider create(ChestBlockEntity entity, ChestBlockEntity entity1, CompoundContainer inventory) { try { - return (INamedContainerProvider) ctor.invoke(entity, entity1, inventory); + return (MenuProvider) ctor.invoke(entity, entity1, inventory); } catch (Throwable throwable) { throw new RuntimeException(throwable); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightFakePlayer.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightFakePlayer.java index bf85b8d0..7630c7b6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightFakePlayer.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightFakePlayer.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mod.server.entity; import com.mojang.authlib.GameProfile; -import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.level.ServerPlayer; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftPlayer; public class ArclightFakePlayer extends CraftPlayer { - public ArclightFakePlayer(CraftServer server, ServerPlayerEntity entity) { + public ArclightFakePlayer(CraftServer server, ServerPlayer entity) { super(server, entity); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java index 893e3c22..8f9b59ef 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModChestedHorse.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.passive.horse.AbstractChestedHorseEntity; +import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftChestedHorse; @@ -14,7 +14,7 @@ public class ArclightModChestedHorse extends CraftChestedHorse { private final EntityType entityType; - public ArclightModChestedHorse(CraftServer server, AbstractChestedHorseEntity entity) { + public ArclightModChestedHorse(CraftServer server, AbstractChestedHorse entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java index 52ce9bbf..af7fa6c5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModEntity.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.Entity; +import net.minecraft.world.entity.Entity; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftEntity; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java index 9642ef40..9c3895ea 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModHorse.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.passive.horse.AbstractHorseEntity; +import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftAbstractHorse; @@ -14,7 +14,7 @@ public class ArclightModHorse extends CraftAbstractHorse { private final EntityType entityType; - public ArclightModHorse(CraftServer server, AbstractHorseEntity entity) { + public ArclightModHorse(CraftServer server, AbstractHorse entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java index 73180962..f53f6d79 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModLivingEntity.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.LivingEntity; +import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java index 00195845..b52b7e4c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecart.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.item.minecart.AbstractMinecartEntity; +import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMinecart; @@ -12,7 +12,7 @@ public class ArclightModMinecart extends CraftMinecart { private final EntityType entityType; - public ArclightModMinecart(CraftServer server, AbstractMinecartEntity entity) { + public ArclightModMinecart(CraftServer server, AbstractMinecart entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java index 91c6dea1..26007283 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMinecartContainer.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.item.minecart.ContainerMinecartEntity; +import net.minecraft.world.entity.vehicle.AbstractMinecartContainer; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMinecartContainer; @@ -12,7 +12,7 @@ public class ArclightModMinecartContainer extends CraftMinecartContainer { private final EntityType entityType; - public ArclightModMinecartContainer(CraftServer server, ContainerMinecartEntity entity) { + public ArclightModMinecartContainer(CraftServer server, AbstractMinecartContainer entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java index 712fee74..13fc7a46 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModMob.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.MobEntity; +import net.minecraft.world.entity.Mob; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftMob; @@ -13,7 +13,7 @@ public class ArclightModMob extends CraftMob { private final EntityType entityType; - public ArclightModMob(CraftServer server, MobEntity entity) { + public ArclightModMob(CraftServer server, Mob entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java index c27e174f..de874686 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModProjectile.java @@ -1,8 +1,8 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.Entity; -import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.projectile.Projectile; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftProjectile; @@ -14,7 +14,7 @@ public class ArclightModProjectile extends CraftProjectile { private final EntityType entityType; public ArclightModProjectile(CraftServer server, Entity entity) { - super(server, (ProjectileEntity) entity); + super(server, (Projectile) entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java index 2f4c52c7..e0ac5015 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/entity/ArclightModRaider.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.entity; import io.izzel.arclight.common.mod.util.ResourceLocationUtil; -import net.minecraft.entity.monster.AbstractRaiderEntity; +import net.minecraft.world.entity.raid.Raider; import net.minecraftforge.registries.ForgeRegistries; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.entity.CraftRaider; @@ -13,7 +13,7 @@ public class ArclightModRaider extends CraftRaider { private final EntityType entityType; - public ArclightModRaider(CraftServer server, AbstractRaiderEntity entity) { + public ArclightModRaider(CraftServer server, Raider entity) { super(server, entity); this.entityType = EntityType.valueOf(ResourceLocationUtil.standardize(ForgeRegistries.ENTITIES.getKey(entity.getType()))); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ArclightEventFactory.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ArclightEventFactory.java index c29fccf6..915a0a3f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ArclightEventFactory.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ArclightEventFactory.java @@ -1,7 +1,6 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.bridge.entity.LivingEntityBridge; -import net.minecraft.entity.LivingEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.entity.Entity; @@ -13,6 +12,7 @@ import org.bukkit.event.entity.EntityResurrectEvent; import org.bukkit.inventory.ItemStack; import java.util.List; +import net.minecraft.world.entity.LivingEntity; public abstract class ArclightEventFactory { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockBreakEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockBreakEventDispatcher.java index f011939b..65d3d492 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockBreakEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockBreakEventDispatcher.java @@ -2,9 +2,9 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.block.Blocks; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.Blocks; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.bukkit.Bukkit; @@ -20,7 +20,7 @@ public class BlockBreakEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onBreakBlock(BlockEvent.BreakEvent event) { - if (!event.getWorld().isRemote()) { + if (!event.getWorld().isClientSide()) { CraftBlock craftBlock = CraftBlock.at(event.getWorld(), event.getPos()); BlockBreakEvent breakEvent = new BlockBreakEvent(craftBlock, ((ServerPlayerEntityBridge) event.getPlayer()).bridge$getBukkitEntity()); ArclightCaptures.captureBlockBreakPlayer(breakEvent); @@ -36,8 +36,8 @@ public class BlockBreakEventDispatcher { public void onFarmlandBreak(BlockEvent.FarmlandTrampleEvent event) { Entity entity = event.getEntity(); Cancellable cancellable; - if (entity instanceof PlayerEntity) { - cancellable = CraftEventFactory.callPlayerInteractEvent((PlayerEntity) entity, Action.PHYSICAL, event.getPos(), null, null, null); + if (entity instanceof Player) { + cancellable = CraftEventFactory.callPlayerInteractEvent((Player) entity, Action.PHYSICAL, event.getPos(), null, null, null); } else { cancellable = new EntityInteractEvent(((EntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(event.getWorld(), event.getPos())); Bukkit.getPluginManager().callEvent((EntityInteractEvent) cancellable); @@ -48,7 +48,7 @@ public class BlockBreakEventDispatcher { return; } - if (CraftEventFactory.callEntityChangeBlockEvent(entity, event.getPos(), Blocks.DIRT.getDefaultState()).isCancelled()) { + if (CraftEventFactory.callEntityChangeBlockEvent(entity, event.getPos(), Blocks.DIRT.defaultBlockState()).isCancelled()) { event.setCanceled(true); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockPlaceEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockPlaceEventDispatcher.java index 5887ba58..3eba11eb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockPlaceEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/BlockPlaceEventDispatcher.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mod.server.event; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; +import net.minecraft.core.Direction; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -27,17 +27,17 @@ public class BlockPlaceEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onBlockPlace(BlockEvent.EntityPlaceEvent event) { Entity entity = event.getEntity(); - if (entity instanceof ServerPlayerEntity) { - ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity; + if (entity instanceof ServerPlayer) { + ServerPlayer playerEntity = (ServerPlayer) entity; Player player = ((CraftServer) Bukkit.getServer()).getPlayer(playerEntity); Direction direction = ArclightCaptures.getPlaceEventDirection(); if (direction != null) { - Hand hand = ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND); + InteractionHand hand = ArclightCaptures.getPlaceEventHand(InteractionHand.MAIN_HAND); CraftBlock placedBlock = ArclightBlockSnapshot.fromBlockSnapshot(event.getBlockSnapshot(), true); - CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().offset(direction.getOpposite())); + CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().relative(direction.getOpposite())); ItemStack bukkitStack; EquipmentSlot bukkitHand; - if (hand == Hand.MAIN_HAND) { + if (hand == InteractionHand.MAIN_HAND) { bukkitStack = player.getInventory().getItemInMainHand(); bukkitHand = EquipmentSlot.HAND; } else { @@ -63,19 +63,19 @@ public class BlockPlaceEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onMultiPlace(BlockEvent.EntityMultiPlaceEvent event) { Entity entity = event.getEntity(); - if (entity instanceof ServerPlayerEntity) { - ServerPlayerEntity playerEntity = (ServerPlayerEntity) entity; + if (entity instanceof ServerPlayer) { + ServerPlayer playerEntity = (ServerPlayer) entity; Player player = ((CraftServer) Bukkit.getServer()).getPlayer(playerEntity); Direction direction = ArclightCaptures.getPlaceEventDirection(); if (direction != null) { - Hand hand = ArclightCaptures.getPlaceEventHand(Hand.MAIN_HAND); + InteractionHand hand = ArclightCaptures.getPlaceEventHand(InteractionHand.MAIN_HAND); List placedBlocks = new ArrayList<>(event.getReplacedBlockSnapshots().size()); for (BlockSnapshot snapshot : event.getReplacedBlockSnapshots()) { placedBlocks.add(ArclightBlockSnapshot.fromBlockSnapshot(snapshot, true).getState()); } - CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().offset(direction.getOpposite())); + CraftBlock againstBlock = CraftBlock.at(event.getWorld(), event.getPos().relative(direction.getOpposite())); ItemStack bukkitStack; - if (hand == Hand.MAIN_HAND) { + if (hand == InteractionHand.MAIN_HAND) { bukkitStack = player.getInventory().getItemInMainHand(); } else { bukkitStack = player.getInventory().getItemInOffHand(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ChunkEventHandler.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ChunkEventHandler.java index d82f8dca..0a479fc4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ChunkEventHandler.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/ChunkEventHandler.java @@ -1,10 +1,10 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.bridge.world.chunk.ChunkBridge; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.INBT; -import net.minecraft.world.chunk.ChunkStatus; -import net.minecraft.world.chunk.IChunk; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraftforge.event.world.ChunkDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; @@ -13,19 +13,19 @@ public class ChunkEventHandler { @SubscribeEvent public void onChunkLoad(ChunkDataEvent.Load event) { - if (event.getStatus() == ChunkStatus.Type.LEVELCHUNK) { - IChunk chunk = event.getChunk(); - CompoundNBT nbt = event.getData(); - INBT values = nbt.get("ChunkBukkitValues"); - if (values instanceof CompoundNBT) { - ((ChunkBridge) chunk).bridge$getPersistentContainer().putAll((CompoundNBT) values); + if (event.getStatus() == ChunkStatus.ChunkType.LEVELCHUNK) { + ChunkAccess chunk = event.getChunk(); + CompoundTag nbt = event.getData(); + Tag values = nbt.get("ChunkBukkitValues"); + if (values instanceof CompoundTag) { + ((ChunkBridge) chunk).bridge$getPersistentContainer().putAll((CompoundTag) values); } } } @SubscribeEvent public void onChunkSave(ChunkDataEvent.Save event) { - IChunk chunk = event.getChunk(); + ChunkAccess chunk = event.getChunk(); if (chunk instanceof ChunkBridge) { CraftPersistentDataContainer container = ((ChunkBridge) chunk).bridge$getPersistentContainer(); if (!container.isEmpty()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java index b4a7f324..de3ac9ad 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityEventDispatcher.java @@ -2,9 +2,9 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.mod.util.ArclightCaptures; import io.izzel.tools.collection.XmapList; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraftforge.event.entity.EntityStruckByLightningEvent; import net.minecraftforge.event.entity.living.AnimalTameEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; @@ -22,9 +22,9 @@ public class EntityEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onLivingDeath(LivingDropsEvent event) { - if (event.getEntityLiving() instanceof ServerPlayerEntity) { + if (event.getEntityLiving() instanceof ServerPlayer) { // handled at ServerPlayerEntityMixin#onDeath - // Cancelled at io.izzel.arclight.common.mixin.core.entity.LivingEntityMixin#arclight$cancelEvent + // Cancelled at io.izzel.arclight.common.mixin.core.world.entity.LivingEntityMixin#arclight$cancelEvent // event.setCanceled(true); return; } @@ -36,8 +36,8 @@ public class EntityEventDispatcher { List itemStackList = XmapList.create((List) drops, ItemStack.class, (ItemEntity entity) -> CraftItemStack.asCraftMirror(entity.getItem()), itemStack -> { - ItemEntity itemEntity = new ItemEntity(livingEntity.world, livingEntity.getPosX(), livingEntity.getPosY(), livingEntity.getPosZ(), CraftItemStack.asNMSCopy(itemStack)); - itemEntity.setDefaultPickupDelay(); + ItemEntity itemEntity = new ItemEntity(livingEntity.level, livingEntity.getX(), livingEntity.getY(), livingEntity.getZ(), CraftItemStack.asNMSCopy(itemStack)); + itemEntity.setDefaultPickUpDelay(); return itemEntity; }); ArclightEventFactory.callEntityDeathEvent(livingEntity, itemStackList); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityTeleportEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityTeleportEventDispatcher.java index 9bb8ad3e..22baaef1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityTeleportEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/EntityTeleportEventDispatcher.java @@ -2,7 +2,7 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.bridge.entity.EntityBridge; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.event.entity.living.EnderTeleportEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.bukkit.Bukkit; @@ -16,7 +16,7 @@ public class EntityTeleportEventDispatcher { @SubscribeEvent(receiveCanceled = true) public void onTeleport(EnderTeleportEvent event) { - if (event.getEntity() instanceof ServerPlayerEntity) { + if (event.getEntity() instanceof ServerPlayer) { CraftPlayer player = ((ServerPlayerEntityBridge) event.getEntity()).bridge$getBukkitEntity(); PlayerTeleportEvent bukkitEvent = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), event.getTargetX(), event.getTargetY(), event.getTargetZ()), PlayerTeleportEvent.TeleportCause.ENDER_PEARL); Bukkit.getPluginManager().callEvent(bukkitEvent); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/WorldEventDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/WorldEventDispatcher.java index fc6a512d..7a7a9dac 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/WorldEventDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/event/WorldEventDispatcher.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.server.event; import io.izzel.arclight.common.bridge.bukkit.CraftServerBridge; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.server.level.ServerLevel; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import org.bukkit.Bukkit; @@ -10,8 +10,8 @@ public class WorldEventDispatcher { @SubscribeEvent public void onWorldUnload(WorldEvent.Unload event) { - if (event.getWorld() instanceof ServerWorld) { - ((CraftServerBridge) Bukkit.getServer()).bridge$removeWorld(((ServerWorld) event.getWorld())); + if (event.getWorld() instanceof ServerLevel) { + ((CraftServerBridge) Bukkit.getServer()).bridge$removeWorld(((ServerLevel) event.getWorld())); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WorldSymlink.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WorldSymlink.java index cd90dcdf..7a72879b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WorldSymlink.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WorldSymlink.java @@ -1,18 +1,18 @@ package io.izzel.arclight.common.mod.server.world; import io.izzel.arclight.common.mod.ArclightMod; -import net.minecraft.world.storage.DerivedWorldInfo; import org.bukkit.Bukkit; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import net.minecraft.world.level.storage.DerivedLevelData; public class WorldSymlink { - public static void create(DerivedWorldInfo worldInfo, File dimensionFolder) { - String name = worldInfo.getWorldName(); + public static void create(DerivedLevelData worldInfo, File dimensionFolder) { + String name = worldInfo.getLevelName(); Path source = new File(Bukkit.getWorldContainer(), name).toPath(); Path dest = dimensionFolder.toPath(); try { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WrappedWorlds.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WrappedWorlds.java index 3280c33c..c7945db1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WrappedWorlds.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/world/WrappedWorlds.java @@ -1,14 +1,13 @@ package io.izzel.arclight.common.mod.server.world; import io.izzel.arclight.common.mod.ArclightMod; -import net.minecraft.world.World; -import net.minecraft.world.server.ServerWorld; - import java.lang.reflect.Field; import java.util.HashMap; import java.util.HashSet; import java.util.Optional; import java.util.function.Function; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; public class WrappedWorlds { @@ -16,12 +15,12 @@ public class WrappedWorlds { private static final HashMap, Field> FIELD = new HashMap<>(); public static Optional getDelegate(Class cl) { - if (cl.equals(ServerWorld.class)) { + if (cl.equals(ServerLevel.class)) { return Optional.empty(); } else { return getOrCreate(cl, key -> { for (Field f : cl.getDeclaredFields()) { - if (World.class.isAssignableFrom(f.getType())) { + if (Level.class.isAssignableFrom(f.getType())) { ArclightMod.LOGGER.debug("{} delegates to field {}", cl, f.getName()); f.setAccessible(true); return f; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightBlockSnapshot.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightBlockSnapshot.java index 97b09b71..1af9e9ae 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightBlockSnapshot.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightBlockSnapshot.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mod.util; -import net.minecraft.block.BlockState; +import net.minecraft.world.level.block.state.BlockState; import net.minecraftforge.common.util.BlockSnapshot; import org.bukkit.craftbukkit.v.block.CraftBlock; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightCaptures.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightCaptures.java index 7918f0f5..3009e2ec 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightCaptures.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightCaptures.java @@ -1,14 +1,14 @@ package io.izzel.arclight.common.mod.util; import io.izzel.arclight.common.mod.ArclightConstants; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.container.Container; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.datafix.codec.DatapackCodec; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.level.DataPackConfig; import org.bukkit.TreeType; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.v.event.CraftPortalEvent; @@ -97,13 +97,13 @@ public class ArclightCaptures { } } - private static Hand placeEventHand; + private static InteractionHand placeEventHand; - public static void capturePlaceEventHand(Hand hand) { + public static void capturePlaceEventHand(InteractionHand hand) { ArclightCaptures.placeEventHand = hand; } - public static Hand getPlaceEventHand(Hand hand) { + public static InteractionHand getPlaceEventHand(InteractionHand hand) { try { return placeEventHand == null ? hand : placeEventHand; } finally { @@ -125,13 +125,13 @@ public class ArclightCaptures { } } - private static transient Container arclight$capturedContainer; + private static transient AbstractContainerMenu arclight$capturedContainer; - public static void captureWorkbenchContainer(Container container) { + public static void captureWorkbenchContainer(AbstractContainerMenu container) { arclight$capturedContainer = container; } - public static Container getWorkbenchContainer() { + public static AbstractContainerMenu getWorkbenchContainer() { try { return arclight$capturedContainer; } finally { @@ -167,13 +167,13 @@ public class ArclightCaptures { } } - private static transient PlayerEntity containerOwner; + private static transient Player containerOwner; - public static void captureContainerOwner(PlayerEntity entity) { + public static void captureContainerOwner(Player entity) { containerOwner = entity; } - public static PlayerEntity getContainerOwner() { + public static Player getContainerOwner() { return containerOwner; } @@ -216,13 +216,13 @@ public class ArclightCaptures { } } - private static transient DatapackCodec datapackCodec; + private static transient DataPackConfig datapackCodec; - public static void captureDatapackConfig(DatapackCodec codec) { + public static void captureDatapackConfig(DataPackConfig codec) { datapackCodec = codec; } - public static DatapackCodec getDatapackConfig() { + public static DataPackConfig getDatapackConfig() { try { return datapackCodec; } finally { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightHeadLoader.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightHeadLoader.java index f384d9b1..579b9cc5 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightHeadLoader.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightHeadLoader.java @@ -6,12 +6,12 @@ import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfile; import com.mojang.authlib.ProfileLookupCallback; import com.mojang.authlib.properties.Property; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.tileentity.SkullTileEntity; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import java.util.UUID; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.SkullBlockEntity; public class ArclightHeadLoader extends CacheLoader { @@ -29,16 +29,16 @@ public class ArclightHeadLoader extends CacheLoader { profiles[0] = gp; } }; - ((CraftServer) Bukkit.getServer()).getServer().getGameProfileRepository().findProfilesByNames(new String[]{key}, Agent.MINECRAFT, gameProfileLookup); + ((CraftServer) Bukkit.getServer()).getServer().getProfileRepository().findProfilesByNames(new String[]{key}, Agent.MINECRAFT, gameProfileLookup); GameProfile profile = profiles[0]; if (profile == null) { - UUID uuid = PlayerEntity.getUUID(new GameProfile(null, key)); + UUID uuid = Player.createPlayerUUID(new GameProfile(null, key)); profile = new GameProfile(uuid, key); gameProfileLookup.onProfileLookupSucceeded(profile); } else { Property property = Iterables.getFirst((profile.getProperties()).get("textures"), null); if (property == null) { - profile = SkullTileEntity.sessionService.fillProfileProperties(profile, true); + profile = SkullBlockEntity.sessionService.fillProfileProperties(profile, true); } } return profile; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java index 219ee610..b335d926 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightPingEvent.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mod.util; import io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.NetworkManager; +import net.minecraft.network.Connection; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.util.CraftIconCache; @@ -21,8 +21,8 @@ public class ArclightPingEvent extends ServerListPingEvent { public CraftIconCache icon; private final Object[] players; - public ArclightPingEvent(NetworkManager networkManager, MinecraftServer server) { - super(((InetSocketAddress) networkManager.getRemoteAddress()).getAddress(), server.getMOTD(), server.getPlayerList().getMaxPlayers()); + public ArclightPingEvent(Connection networkManager, MinecraftServer server) { + super(((InetSocketAddress) networkManager.getRemoteAddress()).getAddress(), server.getMotd(), server.getPlayerList().getMaxPlayers()); this.icon = ((CraftServer) Bukkit.getServer()).getServerIcon(); this.players = server.getPlayerList().players.toArray(); } @@ -41,7 +41,7 @@ public class ArclightPingEvent extends ServerListPingEvent { return new Iterator() { int i; int ret = Integer.MIN_VALUE; - ServerPlayerEntity player; + ServerPlayer player; @Override public boolean hasNext() { @@ -50,7 +50,7 @@ public class ArclightPingEvent extends ServerListPingEvent { } Object[] currentPlayers = players; for (int length = currentPlayers.length, i = this.i; i < length; ++i) { - ServerPlayerEntity player = (ServerPlayerEntity) currentPlayers[i]; + ServerPlayer player = (ServerPlayer) currentPlayers[i]; if (player != null) { this.i = i + 1; this.player = player; @@ -65,7 +65,7 @@ public class ArclightPingEvent extends ServerListPingEvent { if (!this.hasNext()) { throw new NoSuchElementException(); } - ServerPlayerEntity player = this.player; + ServerPlayer player = this.player; this.player = null; this.ret = this.i - 1; return ((ServerPlayerEntityBridge) player).bridge$getBukkitEntity(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightSpecialRecipe.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightSpecialRecipe.java index e2e2ede5..eee02749 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightSpecialRecipe.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ArclightSpecialRecipe.java @@ -1,7 +1,7 @@ package io.izzel.arclight.common.mod.util; import io.izzel.arclight.common.bridge.item.crafting.RecipeManagerBridge; -import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.item.crafting.Recipe; import net.minecraftforge.fml.server.ServerLifecycleHooks; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.v.inventory.CraftComplexRecipe; @@ -12,16 +12,16 @@ import org.jetbrains.annotations.NotNull; public class ArclightSpecialRecipe extends CraftComplexRecipe { - private final IRecipe recipe; + private final Recipe recipe; - public ArclightSpecialRecipe(IRecipe recipe) { + public ArclightSpecialRecipe(Recipe recipe) { super(null); this.recipe = recipe; } @Override public @NotNull ItemStack getResult() { - return CraftItemStack.asCraftMirror(this.recipe.getRecipeOutput()); + return CraftItemStack.asCraftMirror(this.recipe.getResultItem()); } @Override diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BlackholeNetHandler.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BlackholeNetHandler.java index 0ef4f77d..45f0ffd2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BlackholeNetHandler.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BlackholeNetHandler.java @@ -2,40 +2,40 @@ package io.izzel.arclight.common.mod.util; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.PacketDirection; -import net.minecraft.network.play.ServerPlayNetHandler; +import net.minecraft.network.Connection; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.PacketFlow; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; import org.jetbrains.annotations.Nullable; -public class BlackholeNetHandler extends ServerPlayNetHandler { +public class BlackholeNetHandler extends ServerGamePacketListenerImpl { - public BlackholeNetHandler(MinecraftServer server, ServerPlayerEntity playerIn) { + public BlackholeNetHandler(MinecraftServer server, ServerPlayer playerIn) { super(server, new BlackholeNetworkManager(), playerIn); } @Override - public void sendPacket(IPacket packetIn) { + public void send(Packet packetIn) { } @Override - public void sendPacket(IPacket packetIn, @Nullable GenericFutureListener> futureListeners) { + public void send(Packet packetIn, @Nullable GenericFutureListener> futureListeners) { } - private static class BlackholeNetworkManager extends NetworkManager { + private static class BlackholeNetworkManager extends Connection { public BlackholeNetworkManager() { - super(PacketDirection.SERVERBOUND); + super(PacketFlow.SERVERBOUND); } @Override - public void sendPacket(IPacket packetIn) { + public void send(Packet packetIn) { } @Override - public void sendPacket(IPacket packetIn, @Nullable GenericFutureListener> p_201058_2_) { + public void send(Packet packetIn, @Nullable GenericFutureListener> p_201058_2_) { } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BukkitDispatcher.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BukkitDispatcher.java index bba9cac7..9d8df6eb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BukkitDispatcher.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/BukkitDispatcher.java @@ -3,14 +3,14 @@ package io.izzel.arclight.common.mod.util; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; -import net.minecraft.command.CommandSource; -import net.minecraft.command.Commands; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.CraftServer; import org.bukkit.craftbukkit.v.command.BukkitCommandWrapper; import org.bukkit.craftbukkit.v.command.VanillaCommandWrapper; -public class BukkitDispatcher extends CommandDispatcher { +public class BukkitDispatcher extends CommandDispatcher { private final Commands commands; @@ -19,8 +19,8 @@ public class BukkitDispatcher extends CommandDispatcher { } @Override - public LiteralCommandNode register(LiteralArgumentBuilder command) { - LiteralCommandNode node = command.build(); + public LiteralCommandNode register(LiteralArgumentBuilder command) { + LiteralCommandNode node = command.build(); if (!(node.getCommand() instanceof BukkitCommandWrapper)) { VanillaCommandWrapper wrapper = new VanillaCommandWrapper(this.commands, node); ((CraftServer) Bukkit.getServer()).getCommandMap().register("forge", wrapper); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/DelegateWorldInfo.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/DelegateWorldInfo.java index c180cf7d..a7547bb8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/DelegateWorldInfo.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/DelegateWorldInfo.java @@ -3,45 +3,44 @@ package io.izzel.arclight.common.mod.util; import com.mojang.serialization.Lifecycle; import io.izzel.arclight.common.bridge.world.storage.WorldInfoBridge; import io.izzel.arclight.common.bridge.world.storage.DerivedWorldInfoBridge; -import net.minecraft.command.TimerCallbackManager; -import net.minecraft.crash.CrashReportCategory; +import net.minecraft.CrashReportCategory; +import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.Difficulty; -import net.minecraft.world.GameRules; -import net.minecraft.world.GameType; -import net.minecraft.world.WorldSettings; -import net.minecraft.world.border.WorldBorder; -import net.minecraft.world.gen.settings.DimensionGeneratorSettings; -import net.minecraft.world.storage.DerivedWorldInfo; -import net.minecraft.world.storage.IServerWorldInfo; -import net.minecraft.world.storage.ServerWorldInfo; - +import net.minecraft.world.level.GameRules; +import net.minecraft.world.level.GameType; +import net.minecraft.world.level.LevelSettings; +import net.minecraft.world.level.border.WorldBorder; +import net.minecraft.world.level.levelgen.WorldGenSettings; +import net.minecraft.world.level.storage.DerivedLevelData; +import net.minecraft.world.level.storage.PrimaryLevelData; +import net.minecraft.world.level.storage.ServerLevelData; +import net.minecraft.world.level.timers.TimerQueue; import java.util.UUID; @SuppressWarnings("all") -public class DelegateWorldInfo extends ServerWorldInfo { +public class DelegateWorldInfo extends PrimaryLevelData { - private final DerivedWorldInfo derivedWorldInfo; + private final DerivedLevelData derivedWorldInfo; - public DelegateWorldInfo(WorldSettings worldSettings, DimensionGeneratorSettings generatorSettings, Lifecycle lifecycle, DerivedWorldInfo derivedWorldInfo) { + public DelegateWorldInfo(LevelSettings worldSettings, WorldGenSettings generatorSettings, Lifecycle lifecycle, DerivedLevelData derivedWorldInfo) { super(worldSettings, generatorSettings, lifecycle); this.derivedWorldInfo = derivedWorldInfo; } @Override - public int getSpawnX() { - return derivedWorldInfo.getSpawnX(); + public int getXSpawn() { + return derivedWorldInfo.getXSpawn(); } @Override - public int getSpawnY() { - return derivedWorldInfo.getSpawnY(); + public int getYSpawn() { + return derivedWorldInfo.getYSpawn(); } @Override - public int getSpawnZ() { - return derivedWorldInfo.getSpawnZ(); + public int getZSpawn() { + return derivedWorldInfo.getZSpawn(); } @Override @@ -60,8 +59,8 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public String getWorldName() { - return derivedWorldInfo.getWorldName(); + public String getLevelName() { + return derivedWorldInfo.getLevelName(); } @Override @@ -100,18 +99,18 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public void setSpawnX(int x) { - derivedWorldInfo.setSpawnX(x); + public void setXSpawn(int x) { + derivedWorldInfo.setXSpawn(x); } @Override - public void setSpawnY(int y) { - derivedWorldInfo.setSpawnY(y); + public void setYSpawn(int y) { + derivedWorldInfo.setYSpawn(y); } @Override - public void setSpawnZ(int z) { - derivedWorldInfo.setSpawnZ(z); + public void setZSpawn(int z) { + derivedWorldInfo.setZSpawn(z); } @Override @@ -165,8 +164,8 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public boolean areCommandsAllowed() { - return derivedWorldInfo.areCommandsAllowed(); + public boolean getAllowCommands() { + return derivedWorldInfo.getAllowCommands(); } @Override @@ -180,18 +179,18 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public GameRules getGameRulesInstance() { - return derivedWorldInfo.getGameRulesInstance(); + public GameRules getGameRules() { + return derivedWorldInfo.getGameRules(); } @Override - public WorldBorder.Serializer getWorldBorderSerializer() { - return derivedWorldInfo.getWorldBorderSerializer(); + public WorldBorder.Settings getWorldBorder() { + return derivedWorldInfo.getWorldBorder(); } @Override - public void setWorldBorderSerializer(WorldBorder.Serializer serializer) { - derivedWorldInfo.setWorldBorderSerializer(serializer); + public void setWorldBorder(WorldBorder.Settings serializer) { + derivedWorldInfo.setWorldBorder(serializer); } @Override @@ -205,7 +204,7 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public TimerCallbackManager getScheduledEvents() { + public TimerQueue getScheduledEvents() { return derivedWorldInfo.getScheduledEvents(); } @@ -230,37 +229,37 @@ public class DelegateWorldInfo extends ServerWorldInfo { } @Override - public void setWanderingTraderID(UUID id) { - derivedWorldInfo.setWanderingTraderID(id); + public void setWanderingTraderId(UUID id) { + derivedWorldInfo.setWanderingTraderId(id); } @Override - public void addToCrashReport(CrashReportCategory category) { - derivedWorldInfo.addToCrashReport(category); + public void fillCrashReportCategory(CrashReportCategory category) { + derivedWorldInfo.fillCrashReportCategory(category); } - public static DelegateWorldInfo wrap(DerivedWorldInfo worldInfo) { + public static DelegateWorldInfo wrap(DerivedLevelData worldInfo) { return new DelegateWorldInfo(worldSettings(worldInfo), generatorSettings(worldInfo), lifecycle(worldInfo), worldInfo); } - private static WorldSettings worldSettings(IServerWorldInfo worldInfo) { - if (worldInfo instanceof ServerWorldInfo) { + private static LevelSettings worldSettings(ServerLevelData worldInfo) { + if (worldInfo instanceof PrimaryLevelData) { return ((WorldInfoBridge) worldInfo).bridge$getWorldSettings(); } else { return worldSettings(((DerivedWorldInfoBridge) worldInfo).bridge$getDelegate()); } } - private static DimensionGeneratorSettings generatorSettings(IServerWorldInfo worldInfo) { - if (worldInfo instanceof ServerWorldInfo) { - return ((ServerWorldInfo) worldInfo).getDimensionGeneratorSettings(); + private static WorldGenSettings generatorSettings(ServerLevelData worldInfo) { + if (worldInfo instanceof PrimaryLevelData) { + return ((PrimaryLevelData) worldInfo).worldGenSettings(); } else { return generatorSettings(((DerivedWorldInfoBridge) worldInfo).bridge$getDelegate()); } } - private static Lifecycle lifecycle(IServerWorldInfo worldInfo) { - if (worldInfo instanceof ServerWorldInfo) { + private static Lifecycle lifecycle(ServerLevelData worldInfo) { + if (worldInfo instanceof PrimaryLevelData) { return ((WorldInfoBridge) worldInfo).bridge$getLifecycle(); } else { return lifecycle(((DerivedWorldInfoBridge) worldInfo).bridge$getDelegate()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ResourceLocationUtil.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ResourceLocationUtil.java index cdbb0b5b..7afe341e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ResourceLocationUtil.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/ResourceLocationUtil.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mod.util; import com.google.common.base.Preconditions; -import net.minecraft.util.ResourceLocation; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.Contract; import java.util.Locale; +import net.minecraft.resources.ResourceLocation; public class ResourceLocationUtil { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/WrappedContents.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/WrappedContents.java index 71a28096..63622f79 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/WrappedContents.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/WrappedContents.java @@ -1,9 +1,9 @@ package io.izzel.arclight.common.mod.util; import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; +import net.minecraft.core.NonNullList; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; import javax.annotation.ParametersAreNonnullByDefault; @@ -12,29 +12,29 @@ import javax.annotation.ParametersAreNonnullByDefault; @ParametersAreNonnullByDefault public class WrappedContents extends NonNullList { - private final IInventory inventory; + private final Container inventory; - public WrappedContents(IInventory inventory) { + public WrappedContents(Container inventory) { this.inventory = inventory; } @NotNull @Override public ItemStack get(int i) { - return inventory.getStackInSlot(i); + return inventory.getItem(i); } @Override public ItemStack set(int i, ItemStack stack) { - ItemStack ret = inventory.getStackInSlot(i); - inventory.setInventorySlotContents(i, stack); + ItemStack ret = inventory.getItem(i); + inventory.setItem(i, stack); return ret; } @Override public void add(int i, ItemStack stack) { - if (inventory.getStackInSlot(i).isEmpty()) { - inventory.setInventorySlotContents(i, stack); + if (inventory.getItem(i).isEmpty()) { + inventory.setItem(i, stack); } else { throw new UnsupportedOperationException(); } @@ -42,16 +42,16 @@ public class WrappedContents extends NonNullList { @Override public ItemStack remove(int i) { - return inventory.removeStackFromSlot(i); + return inventory.removeItemNoUpdate(i); } @Override public int size() { - return inventory.getSizeInventory(); + return inventory.getContainerSize(); } @Override public void clear() { - inventory.clear(); + inventory.clearContent(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/log/ArclightLoggerAdapter.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/log/ArclightLoggerAdapter.java index 8f51fe51..36bd4b19 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/log/ArclightLoggerAdapter.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/log/ArclightLoggerAdapter.java @@ -3,7 +3,6 @@ package io.izzel.arclight.common.mod.util.log; import org.apache.logging.log4j.jul.ApiLogger; import org.apache.logging.log4j.jul.CoreLoggerAdapter; import org.apache.logging.log4j.spi.LoggerContext; -import sun.reflect.CallerSensitive; import java.util.ResourceBundle; import java.util.function.Supplier; @@ -34,12 +33,10 @@ public class ArclightLoggerAdapter extends CoreLoggerAdapter { this.logger = logger; } - @CallerSensitive public static Logger getLogger(String name) { return Logger.getLogger(name); } - @CallerSensitive public static Logger getLogger(String name, String resourceBundleName) { return Logger.getLogger(name, resourceBundleName); } @@ -48,7 +45,6 @@ public class ArclightLoggerAdapter extends CoreLoggerAdapter { return Logger.getAnonymousLogger(); } - @CallerSensitive public static Logger getAnonymousLogger(String resourceBundleName) { return Logger.getAnonymousLogger(resourceBundleName); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightEnchantment.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightEnchantment.java index fecbb3c2..50c4af2c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightEnchantment.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightEnchantment.java @@ -1,6 +1,6 @@ package io.izzel.arclight.common.mod.util.types; -import net.minecraft.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.Enchantment; import org.bukkit.craftbukkit.v.enchantments.CraftEnchantment; import org.jetbrains.annotations.NotNull; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightPotionEffect.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightPotionEffect.java index 676e9ce0..c197d360 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightPotionEffect.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/util/types/ArclightPotionEffect.java @@ -1,13 +1,13 @@ package io.izzel.arclight.common.mod.util.types; -import net.minecraft.potion.Effect; +import net.minecraft.world.effect.MobEffect; import org.bukkit.craftbukkit.v.potion.CraftPotionEffectType; public class ArclightPotionEffect extends CraftPotionEffectType { private final String name; - public ArclightPotionEffect(Effect handle, String name) { + public ArclightPotionEffect(MobEffect handle, String name) { super(handle); this.name = name; } diff --git a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg index 0787e231..3e692df9 100644 --- a/arclight-common/src/main/resources/META-INF/accesstransformer.cfg +++ b/arclight-common/src/main/resources/META-INF/accesstransformer.cfg @@ -1,444 +1,386 @@ -# Arclight 1.14 -public net.minecraft.command.impl.TeleportCommand$Facing -public net.minecraft.world.server.TicketManager$ChunkTicketTracker -public net.minecraft.world.server.Ticket (Lnet/minecraft/world/server/TicketType;ILjava/lang/Object;J)V -public net.minecraft.network.play.client.CPlayerPacket field_149479_a #x -public net.minecraft.network.play.client.CPlayerPacket field_149477_b #y -public net.minecraft.network.play.client.CPlayerPacket field_149478_c #z -public net.minecraft.network.play.client.CPlayerPacket field_149476_e #yaw -public net.minecraft.network.play.client.CPlayerPacket field_149473_f #pitch -public net.minecraft.network.play.client.CPlayerPacket field_149480_h #moving -public net.minecraft.network.play.client.CPlayerPacket field_149481_i #rotating -public net.minecraft.server.management.BanEntry func_73682_e()Z #hasBanExpired -public net.minecraft.network.login.ServerLoginNetHandler$State -public-f net.minecraft.entity.ai.attributes.RangedAttribute field_111118_b #maximumValue -public net.minecraft.util.math.shapes.IDoubleListMerger -public net.minecraft.util.math.shapes.IndirectMerger (Lit/unimi/dsi/fastutil/doubles/DoubleList;Lit/unimi/dsi/fastutil/doubles/DoubleList;ZZ)V -public net.minecraft.util.math.shapes.DoubleCubeMergingList (II)V -public net.minecraft.block.ComposterBlock$EmptyInventory -public net.minecraft.tileentity.SkullTileEntity field_184299_k #sessionService -public net.minecraft.item.crafting.Ingredient (Ljava/util/stream/Stream;)V -public net.minecraft.world.server.TicketManager field_219377_e #tickets -public net.minecraft.world.server.TicketManager$PlayerChunkTracker -public net.minecraft.world.server.TicketManager$PlayerTicketTracker -# Arclight 1.15 -public net.minecraft.entity.Entity field_70165_t #posX -public net.minecraft.entity.Entity field_70163_u #posY -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.tileentity.TileEntity field_145850_b #world -public net.minecraft.world.server.Ticket (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 -public net.minecraft.entity.passive.BeeEntity field_226364_bD_ #stayOutOfHiveCountdown -public net.minecraft.entity.passive.BeeEntity$PollinateGoal -public net.minecraft.entity.passive.BeeEntity.PollinateGoal func_226504_l_()V #cancel -public net.minecraft.tileentity.BeehiveTileEntity$Bee -public net.minecraft.tileentity.BeehiveTileEntity$Bee field_226977_a_ #entityData -public net.minecraft.entity.passive.BeeEntity$PollinateGoal func_226504_l_()V #cancel -public net.minecraft.world.GameRules$RuleValue func_223553_a(Ljava/lang/String;)V #setStringValue -public net.minecraft.world.GameRules$BooleanValue func_223553_a(Ljava/lang/String;)V #setStringValue -public net.minecraft.world.GameRules$IntegerValue func_223553_a(Ljava/lang/String;)V #setStringValue -# Arclight 1.16 -public net.minecraft.block.ComposterBlock func_235490_d_(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState; #resetFillState -public net.minecraft.util.text.Style (Lnet/minecraft/util/text/Color;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Lnet/minecraft/util/text/event/ClickEvent;Lnet/minecraft/util/text/event/HoverEvent;Ljava/lang/String;Lnet/minecraft/util/ResourceLocation;)V -public net.minecraft.entity.player.SpawnLocationHelper func_241092_a_(Lnet/minecraft/world/server/ServerWorld;IIZ)Lnet/minecraft/util/math/BlockPos; #func_241092_a_ -public net.minecraft.server.MinecraftServer field_240767_f_ #field_240767_f_ -public net.minecraftforge.registries.NamespacedWrapper -public net.minecraftforge.registries.NamespacedDefaultedWrapper -public net.minecraft.command.arguments.ArgumentTypes$Entry -# Bukkit -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.monster.MagmaCubeEntity func_70799_a(IZ)V -public net.minecraft.block.DropperBlock func_176439_d(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V -public net.minecraft.world.server.ChunkManager$EntityTracker -public net.minecraft.item.crafting.Ingredient$IItemList -public net.minecraft.item.crafting.Ingredient$SingleItemList -public net.minecraft.block.DispenserBlock func_176439_d(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V -public net.minecraft.entity.item.HangingEntity func_174859_a(Lnet/minecraft/util/Direction;)V -public net.minecraft.entity.monster.SlimeEntity func_70799_a(IZ)V -public net.minecraft.advancements.PlayerAdvancements field_192758_f -public net.minecraft.advancements.AdvancementManager field_192783_b -public net.minecraft.advancements.AdvancementManager field_223388_c -public net.minecraft.advancements.AdvancementList field_192092_b -public net.minecraft.entity.ai.attributes.RangedAttribute field_111118_b -public net.minecraft.block.Block field_149782_v -public net.minecraft.state.StateHolder field_177233_b -public net.minecraft.block.DispenserBlock field_149943_a -public net.minecraft.block.JukeboxBlock func_203419_a(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V -public net.minecraft.block.RedstoneWireBlock func_212567_a(ILnet/minecraft/block/BlockState;)I -public net.minecraft.block.ShulkerBoxBlock field_190958_b -public net.minecraft.world.BossInfo field_186751_c -public net.minecraft.world.BossInfo field_186752_d -public net.minecraft.world.BossInfo field_186749_a -public net.minecraft.world.ServerBossInfo func_186759_a(Lnet/minecraft/network/play/server/SUpdateBossInfoPacket$Operation;)V -public net.minecraft.world.ServerBossInfo field_186764_j -public net.minecraft.world.LockCode field_180161_b -public net.minecraft.world.chunk.Chunk field_76645_j -public net.minecraft.world.chunk.Chunk field_76634_f -public net.minecraft.world.chunk.Chunk field_76636_d -public net.minecraft.world.chunk.Chunk field_150816_i -public net.minecraft.world.chunk.Chunk field_76637_e -public net.minecraft.world.server.ServerChunkProvider field_217247_m -public net.minecraft.world.server.ServerChunkProvider field_217246_l -public net.minecraft.world.server.ServerChunkProvider field_186029_c -public net.minecraft.world.chunk.ChunkSection field_205512_a -public net.minecraft.command.CommandSource field_197041_c -public net.minecraft.inventory.container.RepairContainer field_82854_e -public net.minecraft.inventory.container.RepairContainer field_82857_m -public net.minecraft.inventory.container.DispenserContainer field_178146_a -public net.minecraft.inventory.container.WorkbenchContainer field_217070_e -public net.minecraft.util.datafix.fixes.ItemIntIDToString field_188221_a -public net.minecraft.util.datafix.fixes.SpawnEggNames field_188226_a -public net.minecraft.server.dedicated.DedicatedServer field_184115_n -public net.minecraft.world.dimension.DimensionType field_212682_f -public net.minecraft.world.dimension.DimensionType field_201038_g -public net.minecraft.world.dimension.DimensionType func_212677_a(Ljava/lang/String;Lnet/minecraft/world/dimension/DimensionType;)Lnet/minecraft/world/dimension/DimensionType; -public net.minecraft.world.end.DragonFightManager field_186109_c -public net.minecraft.entity.Entity field_190534_ay -public net.minecraft.entity.Entity func_70083_f(I)Z -public net.minecraft.entity.Entity func_190531_bD()I -public net.minecraft.entity.Entity func_70022_Q()Ljava/lang/String; -public net.minecraft.entity.Entity field_184238_ar -public net.minecraft.entity.Entity field_70171_ac -public net.minecraft.entity.Entity field_184244_h -public net.minecraft.entity.Entity func_70052_a(IZ)V -public net.minecraft.entity.passive.AnimalEntity field_146084_br -public net.minecraft.entity.passive.AnimalEntity field_70881_d -public net.minecraft.entity.AreaEffectCloudEntity field_184509_av -public net.minecraft.entity.AreaEffectCloudEntity field_184510_aw -public net.minecraft.entity.AreaEffectCloudEntity field_184511_ax -public net.minecraft.entity.AreaEffectCloudEntity field_184507_at -public net.minecraft.entity.AreaEffectCloudEntity field_184506_as -public net.minecraft.entity.item.ArmorStandEntity field_175444_bi -public net.minecraft.entity.item.ArmorStandEntity field_175443_bh -public net.minecraft.entity.item.ArmorStandEntity field_175438_bj -public net.minecraft.entity.item.ArmorStandEntity field_175440_bl -public net.minecraft.entity.item.ArmorStandEntity field_175439_bk -public net.minecraft.entity.item.ArmorStandEntity field_175441_bm -public net.minecraft.entity.item.ArmorStandEntity func_175413_k(Z)V -public net.minecraft.entity.item.ArmorStandEntity func_175426_l(Z)V -public net.minecraft.entity.item.ArmorStandEntity func_181027_m(Z)V -public net.minecraft.entity.item.ArmorStandEntity func_175420_a(Z)V -public net.minecraft.entity.projectile.AbstractArrowEntity field_70252_j -public net.minecraft.entity.projectile.AbstractArrowEntity field_70254_i -public net.minecraft.entity.projectile.AbstractArrowEntity field_70256_ap -public net.minecraft.entity.monster.CreeperEntity func_146077_cc()V -public net.minecraft.entity.monster.CreeperEntity field_82226_g -public net.minecraft.entity.monster.CreeperEntity field_82225_f -public net.minecraft.entity.item.EyeOfEnderEntity field_70223_e -public net.minecraft.entity.item.EyeOfEnderEntity field_70221_f -public net.minecraft.entity.item.EyeOfEnderEntity field_70224_b -public net.minecraft.entity.item.EyeOfEnderEntity field_70225_c -public net.minecraft.entity.item.EyeOfEnderEntity field_70222_d -public net.minecraft.entity.item.ExperienceOrbEntity field_70530_e -public net.minecraft.entity.item.FallingBlockEntity field_145809_g -public net.minecraft.entity.item.FireworkRocketEntity field_184566_a -public net.minecraft.entity.item.FireworkRocketEntity field_92055_b -public net.minecraft.entity.passive.fish.AbstractFishEntity func_203705_dA()Z -public net.minecraft.entity.passive.FoxEntity func_213474_a(Lnet/minecraft/entity/passive/FoxEntity$Type;)V -public net.minecraft.entity.passive.FoxEntity func_213485_x(Z)V -public net.minecraft.entity.monster.GuardianEntity field_175481_bq -public net.minecraft.entity.item.HangingEntity field_174861_a -public net.minecraft.entity.passive.horse.AbstractHorseEntity field_110271_bv -public net.minecraft.entity.passive.horse.AbstractHorseEntity field_110296_bG -public net.minecraft.entity.passive.horse.AbstractHorseEntity func_110226_cD()V -public net.minecraft.entity.player.PlayerEntity func_71053_j()V -public net.minecraft.entity.player.PlayerEntity func_192029_h(Lnet/minecraft/nbt/CompoundNBT;)V -public net.minecraft.entity.player.PlayerEntity func_192031_i(Lnet/minecraft/nbt/CompoundNBT;)V -public net.minecraft.entity.player.PlayerEntity field_71076_b -public net.minecraft.entity.monster.SpellcastingIllagerEntity func_193083_dm()Lnet/minecraft/entity/monster/SpellcastingIllagerEntity$SpellType; -public net.minecraft.entity.MobEntity field_184655_bs -public net.minecraft.entity.MobEntity field_82174_bp -public net.minecraft.entity.MobEntity field_184659_bA -public net.minecraft.entity.MobEntity field_184653_bB -public net.minecraft.entity.MobEntity field_82179_bU -public net.minecraft.entity.item.ItemEntity field_70292_b -public net.minecraft.entity.item.ItemEntity field_145804_b -public net.minecraft.entity.LivingEntity field_184632_c -public net.minecraft.entity.LivingEntity field_70713_bf -public net.minecraft.entity.LivingEntity field_70756_c -public net.minecraft.entity.LivingEntity field_70717_bb -public net.minecraft.entity.LivingEntity field_110153_bc -public net.minecraft.entity.LivingEntity field_70755_b -public net.minecraft.entity.LivingEntity field_70752_e -public net.minecraft.entity.passive.horse.LlamaEntity func_190706_p(I)V -public net.minecraft.entity.item.minecart.MinecartCommandBlockEntity field_184273_a -public net.minecraft.entity.item.minecart.ContainerMinecartEntity field_184290_c -public net.minecraft.entity.item.minecart.ContainerMinecartEntity field_184291_d -public net.minecraft.entity.monster.ZombiePigmanEntity field_70837_d -public net.minecraft.entity.player.ServerPlayerEntity field_147101_bU -public net.minecraft.entity.player.ServerPlayerEntity field_71144_ck -public net.minecraft.entity.player.ServerPlayerEntity field_71148_cg -public net.minecraft.entity.player.ServerPlayerEntity func_71117_bO()V -public net.minecraft.entity.player.ServerPlayerEntity field_71130_g -public net.minecraft.entity.player.ServerPlayerEntity field_184851_cj -public net.minecraft.entity.projectile.PotionEntity func_184544_n()Z -public net.minecraft.entity.projectile.ThrowableEntity field_70192_c -public net.minecraft.entity.projectile.ThrowableEntity field_200218_h -public net.minecraft.entity.monster.ShulkerEntity field_190770_bw -public net.minecraft.entity.projectile.SpectralArrowEntity field_184562_f -public net.minecraft.entity.projectile.TridentEntity field_203054_h -public net.minecraft.entity.projectile.ArrowEntity field_184561_h -public net.minecraft.entity.projectile.ArrowEntity func_191507_d(I)V -public net.minecraft.entity.merchant.villager.VillagerEntity func_175554_cu()V -public net.minecraft.entity.boss.WitherEntity field_184744_bE -public net.minecraft.entity.monster.ZombieEntity field_204709_bA -public net.minecraft.entity.monster.ZombieEntity field_204708_bE -public net.minecraft.entity.monster.ZombieEntity func_204704_a(I)V -public net.minecraft.entity.monster.ZombieVillagerEntity field_184739_bx -public net.minecraft.entity.monster.ZombieVillagerEntity field_82234_d -public net.minecraft.entity.monster.ZombieVillagerEntity field_191992_by -public net.minecraft.util.text.TextFormatting field_96329_z -public net.minecraft.world.Explosion field_77283_e -public net.minecraft.util.FoodStats field_75126_c -public net.minecraft.util.FoodStats field_75127_a -public net.minecraft.util.FoodStats field_75125_b -public net.minecraft.world.GameRules$RuleValue func_223556_a(Lnet/minecraft/server/MinecraftServer;)V -public net.minecraft.inventory.CraftingInventory field_70465_c -public net.minecraft.inventory.DoubleSidedInventory field_70477_b -public net.minecraft.inventory.DoubleSidedInventory field_70478_c -public net.minecraft.inventory.MerchantInventory field_70473_e -public net.minecraft.inventory.Inventory field_70482_c -public net.minecraft.item.WallOrFloorItem field_195947_b -# public net.minecraft.item.BucketItem field_77876_a -public net.minecraft.util.CooldownTracker$Cooldown -public net.minecraft.util.CooldownTracker$Cooldown field_185138_b -public net.minecraft.util.CooldownTracker field_185147_a -public net.minecraft.util.CooldownTracker field_185148_b -public net.minecraft.server.management.UserListEntry func_152640_f()Ljava/lang/Object; -public net.minecraft.item.MerchantOffer field_222231_i -public net.minecraft.item.MerchantOffer field_222228_f -public net.minecraft.item.MerchantOffer field_222225_c -public net.minecraft.item.MerchantOffer field_222226_d -public net.minecraft.item.MerchantOffer field_222232_j -public net.minecraft.server.MinecraftServer func_71237_c(Ljava/lang/String;)V -public net.minecraft.server.MinecraftServer field_184112_s -public net.minecraft.server.MinecraftServer field_213217_au -public net.minecraft.server.MinecraftServer func_213186_a(Lnet/minecraft/world/chunk/listener/IChunkStatusListener;)V -public net.minecraft.server.MinecraftServer field_175590_aa -public net.minecraft.server.MinecraftServer field_213220_d -public net.minecraft.server.MinecraftServer field_71305_c -public net.minecraft.world.spawner.AbstractSpawner func_190895_g()Lnet/minecraft/util/ResourceLocation; -public net.minecraft.world.spawner.AbstractSpawner field_98292_k -public net.minecraft.world.spawner.AbstractSpawner field_98293_h -public net.minecraft.world.spawner.AbstractSpawner field_98283_g -public net.minecraft.world.spawner.AbstractSpawner field_98285_e -public net.minecraft.world.spawner.AbstractSpawner field_98289_l -public net.minecraft.world.spawner.AbstractSpawner field_98294_i -public net.minecraft.world.spawner.AbstractSpawner field_98282_f -public net.minecraft.world.spawner.AbstractSpawner field_98286_b -public net.minecraft.world.spawner.AbstractSpawner field_98290_m -public net.minecraft.nbt.JsonToNBT func_193606_k()Lnet/minecraft/nbt/INBT; -public net.minecraft.nbt.JsonToNBT func_193596_c(Ljava/lang/String;)Lnet/minecraft/nbt/INBT; -public net.minecraft.network.NetworkManager field_150746_k -public net.minecraft.network.NetworkManager field_150743_l -public net.minecraft.network.handshake.client.CHandshakePacket field_149598_b -public net.minecraft.network.handshake.client.CHandshakePacket field_149599_c -public net.minecraft.network.play.client.CCustomPayloadPacket field_149561_c -public net.minecraft.network.play.client.CCustomPayloadPacket field_149562_a -public net.minecraft.network.play.client.CResourcePackStatusPacket field_179719_b -public net.minecraft.network.play.client.CClientSettingsPacket field_149528_b -public net.minecraft.network.play.server.SChangeBlockPacket field_197686_b -public net.minecraft.network.play.server.SPlayerListHeaderFooterPacket field_179702_b -public net.minecraft.network.play.server.SPlayerListHeaderFooterPacket field_179703_a -public net.minecraft.network.play.server.SSpawnPositionPacket field_179801_a -public net.minecraft.entity.player.PlayerAbilities field_75096_f -public net.minecraft.entity.player.PlayerAbilities field_75097_g -public net.minecraft.world.server.ChunkHolder field_219316_k -public net.minecraft.world.server.ChunkHolder field_219328_w -public net.minecraft.world.server.ChunkManager$EntityTracker field_219406_f -public net.minecraft.world.server.ChunkManager field_219267_u -public net.minecraft.world.server.ChunkManager field_219258_l -public net.minecraft.world.server.ChunkManager func_219229_a(Lnet/minecraft/world/chunk/IChunk;)Z -public net.minecraft.world.server.ChunkManager field_219272_z -public net.minecraft.world.server.ChunkManager field_219261_o -public net.minecraft.world.server.ChunkManager field_219251_e -public net.minecraft.world.server.ChunkManager field_219252_f -public net.minecraft.world.server.ChunkManager field_219255_i -public net.minecraft.world.server.ChunkManager field_219266_t -public net.minecraft.server.management.PlayerList field_72412_k -public net.minecraft.server.management.PlayerList field_72404_b -public net.minecraft.server.management.PlayerList func_96456_a(Lnet/minecraft/scoreboard/ServerScoreboard;Lnet/minecraft/entity/player/ServerPlayerEntity;)V -public net.minecraft.server.dedicated.PropertyManager field_73672_b -public net.minecraft.item.crafting.Ingredient func_199806_d()V -public net.minecraft.item.crafting.Ingredient field_193371_b -public net.minecraft.world.chunk.storage.RegionFileCache field_219102_c -public net.minecraft.scoreboard.ScoreObjective field_96683_d -public net.minecraft.inventory.container.Slot field_75225_a -public net.minecraft.world.server.Ticket field_219482_c -public net.minecraft.tileentity.BannerTileEntity field_175120_a -public net.minecraft.tileentity.BannerTileEntity field_175118_f -public net.minecraft.tileentity.BeaconTileEntity field_213936_m -public net.minecraft.tileentity.BeaconTileEntity field_146008_p -public net.minecraft.tileentity.BeaconTileEntity field_146012_l -public net.minecraft.tileentity.BeaconTileEntity field_146013_m -public net.minecraft.tileentity.BeaconTileEntity field_146010_n -public net.minecraft.tileentity.BedTileEntity field_193053_a -public net.minecraft.tileentity.BrewingStandTileEntity field_145946_k -public net.minecraft.tileentity.BrewingStandTileEntity field_184278_m -public net.minecraft.tileentity.CampfireTileEntity field_213988_b -public net.minecraft.tileentity.CampfireTileEntity field_213989_c -public net.minecraft.tileentity.LockableTileEntity field_174901_a -public net.minecraft.tileentity.LockableTileEntity field_213909_b -public net.minecraft.tileentity.EndGatewayTileEntity field_195504_f -public net.minecraft.tileentity.EndGatewayTileEntity field_195507_i -public net.minecraft.tileentity.EndGatewayTileEntity field_195506_h -public net.minecraft.tileentity.AbstractFurnaceTileEntity field_214018_j -public net.minecraft.tileentity.AbstractFurnaceTileEntity field_214020_l -public net.minecraft.tileentity.AbstractFurnaceTileEntity field_214021_m -public net.minecraft.tileentity.LecternTileEntity field_214048_a -public net.minecraft.tileentity.LecternTileEntity func_214035_a(I)V -public net.minecraft.tileentity.LockableLootTileEntity field_184284_m -public net.minecraft.tileentity.LockableLootTileEntity field_184285_n -public net.minecraft.tileentity.SignTileEntity field_145916_j -public net.minecraft.tileentity.SkullTileEntity field_152110_j -public net.minecraft.tileentity.StructureBlockTileEntity field_184421_f -public net.minecraft.tileentity.StructureBlockTileEntity field_184428_m -public net.minecraft.tileentity.StructureBlockTileEntity field_189730_q -public net.minecraft.tileentity.StructureBlockTileEntity field_184422_g -public net.minecraft.tileentity.StructureBlockTileEntity field_184425_j -public net.minecraft.tileentity.StructureBlockTileEntity field_184423_h -public net.minecraft.tileentity.StructureBlockTileEntity field_184426_k -public net.minecraft.tileentity.StructureBlockTileEntity field_189731_r -public net.minecraft.tileentity.StructureBlockTileEntity field_189728_o -public net.minecraft.tileentity.StructureBlockTileEntity field_189729_p -public net.minecraft.tileentity.StructureBlockTileEntity field_184424_i -public net.minecraft.world.World field_72986_A -public net.minecraft.world.storage.MapData field_76202_j -public net.minecraft.world.storage.DimensionSavedDataManager field_212778_c -public net.minecraft.world.storage.ServerWorldInfo field_237342_b_ # settings -public net.minecraft.world.server.ServerWorld field_217498_x -public-f net.minecraft.inventory.container.Container field_75153_a -public-f net.minecraft.inventory.container.Container field_75151_b -public-f net.minecraft.item.crafting.RecipeManager field_199522_d -public-f net.minecraft.server.dedicated.DedicatedServer field_71340_o -public-f net.minecraft.entity.AreaEffectCloudEntity field_184503_f -public-f net.minecraft.entity.projectile.FishingBobberEntity field_146042_b -public-f net.minecraft.entity.MobEntity field_70714_bg -public-f net.minecraft.entity.MobEntity field_70715_bh -public-f net.minecraft.entity.LivingEntity field_94063_bt -public-f net.minecraft.entity.LivingEntity field_70771_an -private-f net.minecraft.item.ItemStack field_151002_e -public-f net.minecraft.item.MerchantOffer field_222223_a -public-f net.minecraft.item.MerchantOffer field_222224_b -public-f net.minecraft.item.MerchantOffer field_222227_e -public-f net.minecraft.server.MinecraftServer field_195579_af -public-f net.minecraft.server.MinecraftServer field_71310_m -private-f net.minecraft.server.MinecraftServer field_147144_o -public-f net.minecraft.server.MinecraftServer field_71308_o -public-f net.minecraft.world.server.TicketType field_223186_k -public-f net.minecraft.world.World field_73011_w -public net.minecraft.entity.monster.GuardianEntity func_110147_ax()V -public net.minecraft.entity.monster.ElderGuardianEntity func_110147_ax()V -public net.minecraft.world.server.ServerBossInfo func_186759_a(Lnet/minecraft/network/play/server/SUpdateBossInfoPacket$Operation;)V -public net.minecraft.world.server.ServerBossInfo field_186764_j -public net.minecraft.world.server.TicketManager field_219377_e -public net.minecraft.util.datafix.fixes.BlockStateFlatteningMap func_199194_a(ILjava/lang/String;[Ljava/lang/String;)V +# Arclight 1.17 +public net.minecraft.world.entity.Entity f_19851_ +public net.minecraft.world.entity.raid.Raider$HoldGroundAttackGoal +public net.minecraft.world.entity.monster.SpellcasterIllager$SpellcasterUseSpellGoal +public net.minecraft.world.entity.monster.SpellcasterIllager$IllagerSpell +# Misc +public net.minecraft.server.PlayerAdvancements f_135964_ +public net.minecraft.server.level.PlayerRespawnLogic m_8264_(Lnet/minecraft/server/level/ServerLevel;IIZ)Lnet/minecraft/core/BlockPos; +public net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase f_60599_ +public net.minecraft.world.level.dimension.end.EndDragonFight f_64073_ +public net.minecraft.world.level.dimension.end.EndDragonFight f_64072_ +public net.minecraft.world.level.dimension.end.EndDragonFight f_64061_ +public net.minecraft.world.level.dimension.end.EndDragonFight f_64060_ +public net.minecraft.world.level.dimension.end.EndDragonFight f_64070_ +public net.minecraft.world.level.dimension.end.EndDragonFight m_64087_(Lnet/minecraft/world/level/dimension/end/DragonRespawnAnimation;)V +public net.minecraft.world.level.dimension.end.EndDragonFight m_64105_()Lnet/minecraft/world/level/block/state/pattern/BlockPattern$BlockPatternMatch; +public net.minecraft.world.level.dimension.end.EndDragonFight m_64093_(Z)V +public net.minecraft.world.entity.raid.Raids f_37951_ +public net.minecraft.world.level.block.entity.BeehiveBlockEntity$BeeData +public net.minecraft.world.level.block.entity.BeehiveBlockEntity$BeeData f_58782_ +public net.minecraft.world.entity.projectile.Fireball m_37018_()Lnet/minecraft/world/item/ItemStack; +public net.minecraft.network.protocol.game.ServerboundClientInformationPacket f_133864_ +public net.minecraft.network.protocol.game.ServerboundClientInformationPacket f_133863_ +public net.minecraft.world.SimpleContainer f_19147_ +public net.minecraft.server.dedicated.Settings f_139798_ +public net.minecraft.world.entity.vehicle.MinecartCommandBlock f_38503_ +public-f net.minecraft.world.item.trading.MerchantOffer f_45311_ +public-f net.minecraft.world.item.trading.MerchantOffer f_45310_ +public net.minecraft.world.item.trading.MerchantOffer f_45313_ +public net.minecraft.world.item.trading.MerchantOffer f_45312_ +public net.minecraft.world.item.trading.MerchantOffer f_45315_ +public-f net.minecraft.world.item.trading.MerchantOffer f_45314_ +public net.minecraft.world.item.trading.MerchantOffer f_45319_ +public net.minecraft.world.item.trading.MerchantOffer f_45318_ +public net.minecraft.world.food.FoodData f_38697_ +public net.minecraft.world.food.FoodData f_38698_ +public net.minecraft.world.food.FoodData f_38696_ +public net.minecraft.world.level.BaseSpawner f_45442_ +public net.minecraft.world.level.BaseSpawner f_45453_ +public net.minecraft.world.level.BaseSpawner f_45443_ +public net.minecraft.world.level.BaseSpawner f_45444_ +public net.minecraft.world.level.BaseSpawner f_45447_ +public net.minecraft.world.level.BaseSpawner f_45448_ +public net.minecraft.world.level.BaseSpawner f_45449_ +public net.minecraft.world.level.BaseSpawner f_45451_ +public net.minecraft.world.level.BaseSpawner f_45452_ +public net.minecraft.world.inventory.DispenserMenu f_39431_ +public net.minecraft.network.chat.Style (Lnet/minecraft/network/chat/TextColor;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Ljava/lang/Boolean;Lnet/minecraft/network/chat/ClickEvent;Lnet/minecraft/network/chat/HoverEvent;Ljava/lang/String;Lnet/minecraft/resources/ResourceLocation;)V +public net.minecraft.world.level.saveddata.maps.MapItemSavedData f_77896_ +public net.minecraft.world.item.ItemCooldowns f_41515_ +public net.minecraft.world.item.ItemCooldowns f_41516_ +public net.minecraft.world.entity.monster.piglin.AbstractPiglin f_34649_ +public net.minecraft.world.entity.monster.piglin.AbstractPiglin m_34665_()Z +public-f net.minecraft.world.level.LevelSettings f_46902_ +public-f net.minecraft.world.level.LevelSettings f_46904_ +public-f net.minecraft.world.item.crafting.RecipeManager f_44007_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134118_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134125_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134124_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134122_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134121_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134120_ +public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket f_134119_ +public net.minecraft.server.commands.TeleportCommand$LookAt +public-f net.minecraft.server.level.TicketType f_9452_ +public net.minecraft.util.datafix.fixes.ItemIdFix f_15937_ +public net.minecraft.world.level.block.entity.BrewingStandBlockEntity f_58979_ +public net.minecraft.world.level.block.entity.BrewingStandBlockEntity f_58976_ +public net.minecraft.world.entity.projectile.ThrownPotion m_37553_()Z +public net.minecraft.world.entity.projectile.FishingHook$FishHookState +public net.minecraft.world.entity.animal.MushroomCow m_28928_(Lnet/minecraft/world/entity/animal/MushroomCow$MushroomType;)V +public net.minecraft.world.entity.AreaEffectCloud f_19692_ +public net.minecraft.world.entity.AreaEffectCloud f_19693_ +public net.minecraft.world.entity.AreaEffectCloud f_19691_ +public net.minecraft.world.entity.AreaEffectCloud f_19689_ +public net.minecraft.world.entity.AreaEffectCloud f_19688_ +public-f net.minecraft.world.entity.AreaEffectCloud f_19685_ +public net.minecraft.world.entity.item.ItemEntity f_31986_ +public net.minecraft.world.entity.item.ItemEntity f_31985_ +public net.minecraft.network.protocol.game.ClientboundTabListPacket f_133480_ +public net.minecraft.network.protocol.game.ClientboundTabListPacket f_133481_ public net.minecraft.world.dimension.DimensionType (ILjava/lang/String;Ljava/lang/String;Ljava/util/function/BiFunction;ZLnet/minecraft/world/biome/IBiomeMagnifier;)V -public net.minecraft.entity.passive.BeeEntity func_226418_eL_()I -public net.minecraft.entity.passive.BeeEntity field_226369_bI_ -public net.minecraft.entity.passive.BeeEntity func_226453_u_(I)V -public net.minecraft.entity.passive.BeeEntity func_226447_r_(Z)V -public net.minecraft.entity.passive.BeeEntity func_226449_s_(Z)V -public net.minecraft.entity.boss.dragon.EnderDragonEntity field_70977_g -public net.minecraft.entity.item.FireworkRocketEntity field_213895_d -public net.minecraft.entity.passive.FoxEntity field_213509_bB -public net.minecraft.entity.passive.FoxEntity field_213510_bD -public net.minecraft.entity.passive.MooshroomEntity func_213446_a(Lnet/minecraft/entity/passive/MooshroomEntity$Type;)V -public net.minecraft.entity.monster.PillagerEntity field_213677_bz -public net.minecraft.entity.player.ServerPlayerEntity func_213846_b(Lnet/minecraft/world/server/ServerWorld;)V -public net.minecraft.entity.monster.ZombieVillagerEntity func_191991_a(Ljava/util/UUID;I)V -# public net.minecraft.item.BucketItem field_77876_a -public net.minecraft.world.raid.RaidManager field_215175_a -public net.minecraft.world.raid.Raid field_221352_p -public net.minecraft.world.raid.Raid field_221345_i -public net.minecraft.world.raid.Raid field_221359_w -public net.minecraft.world.raid.Raid field_221346_j -public net.minecraft.world.raid.Raid field_221351_o -public net.minecraft.item.crafting.Ingredient$SingleItemList (Lnet/minecraft/item/ItemStack;)V -public net.minecraft.tileentity.BeehiveTileEntity field_226959_b_ -public net.minecraft.tileentity.StructureBlockTileEntity field_184427_l -public net.minecraft.world.World field_217407_c -public net.minecraft.block.DispenserBlock func_176439_d(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;)V -public net.minecraft.block.DropperBlock func_176439_d(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/util/math/BlockPos;)V -public net.minecraft.block.AbstractBlock$AbstractBlockState field_235705_i_ -public net.minecraft.util.text.Color field_240741_d_ -public net.minecraft.world.storage.SaveFormat$LevelSave field_237279_c_ -public net.minecraft.world.storage.SaveFormat field_215786_c -public net.minecraft.util.datafix.fixes.BlockStateFlatteningMap func_199194_a(ILjava/lang/String;[Ljava/lang/String;)V -public net.minecraft.world.end.DragonFightManager field_186119_m -public net.minecraft.world.end.DragonFightManager field_186121_o -public net.minecraft.world.end.DragonFightManager func_186094_a(Z)V -public net.minecraft.world.end.DragonFightManager func_186091_h()Lnet/minecraft/block/pattern/BlockPattern$PatternHelper; -public net.minecraft.world.end.DragonFightManager field_186122_p -public net.minecraft.world.end.DragonFightManager func_186095_a(Lnet/minecraft/world/end/DragonSpawnState;)V -public net.minecraft.world.end.DragonFightManager field_186110_d -public net.minecraft.entity.Entity field_242273_aw -public net.minecraft.entity.passive.BeeEntity field_226364_bD_ -public net.minecraft.entity.projectile.EyeOfEnderEntity field_70223_e -public net.minecraft.entity.projectile.EyeOfEnderEntity field_70221_f -public net.minecraft.entity.projectile.EyeOfEnderEntity field_70224_b -public net.minecraft.entity.projectile.EyeOfEnderEntity field_70225_c -public net.minecraft.entity.projectile.EyeOfEnderEntity field_70222_d -public net.minecraft.entity.projectile.AbstractFireballEntity func_213896_l()Lnet/minecraft/item/ItemStack; -public net.minecraft.entity.projectile.FireworkRocketEntity field_184566_a -public net.minecraft.entity.projectile.FireworkRocketEntity field_213895_d -public net.minecraft.entity.projectile.FireworkRocketEntity field_92055_b -public net.minecraft.entity.monster.HoglinEntity field_234359_bz_ -public net.minecraft.entity.monster.HoglinEntity field_234358_by_ -public net.minecraft.entity.monster.HoglinEntity func_234368_eV_()Z -public net.minecraft.entity.passive.horse.HorseEntity func_234238_a_(Lnet/minecraft/entity/passive/horse/CoatColors;Lnet/minecraft/entity/passive/horse/CoatTypes;)V -public net.minecraft.entity.item.ItemFrameEntity field_234259_an_ -public net.minecraft.entity.effect.LightningBoltEntity field_184529_d -public net.minecraft.entity.item.minecart.CommandBlockMinecartEntity field_184273_a -public net.minecraft.entity.passive.PigEntity field_234214_bx_ -public net.minecraft.entity.monster.piglin.PiglinEntity field_234407_bB_ -public net.minecraft.entity.monster.piglin.AbstractPiglinEntity field_242334_c -public net.minecraft.entity.monster.piglin.AbstractPiglinEntity func_242335_eK()Z -public net.minecraft.entity.projectile.ProjectileItemEntity func_213882_k()Lnet/minecraft/item/ItemStack; -public net.minecraft.entity.passive.RabbitEntity func_184651_r()V -public net.minecraft.entity.passive.StriderEntity field_234313_bz_ -public net.minecraft.state.StateHolder field_235890_a_ -public net.minecraft.server.Main func_240761_a_(Lnet/minecraft/world/storage/SaveFormat$LevelSave;Lcom/mojang/datafixers/DataFixer;ZLjava/util/function/BooleanSupplier;Lcom/google/common/collect/ImmutableSet;)V -public net.minecraft.server.MinecraftServer field_195576_ac -public net.minecraft.server.MinecraftServer field_240766_e_ -public net.minecraft.network.play.client.CClientSettingsPacket field_149530_a -public net.minecraft.network.play.server.SWorldSpawnChangedPacket field_240831_a_ -public net.minecraft.item.crafting.RecipeBook field_194077_a -public net.minecraft.tileentity.BarrelTileEntity func_213963_a(Lnet/minecraft/block/BlockState;Z)V -public net.minecraft.tileentity.BarrelTileEntity func_213965_a(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/SoundEvent;)V -public net.minecraft.tileentity.ChestTileEntity func_195483_a(Lnet/minecraft/util/SoundEvent;)V -public net.minecraft.tileentity.ChestTileEntity field_145987_o -public net.minecraft.tileentity.ShulkerBoxTileEntity field_190598_h -public net.minecraft.tileentity.SignTileEntity field_145915_a -public net.minecraft.world.server.ServerWorld field_241103_E_ -public-f net.minecraft.resources.DataPackRegistries field_240953_c_ -protected-f net.minecraft.server.MinecraftServer field_240768_i_ -public-f net.minecraft.world.WorldSettings field_77170_d -public-f net.minecraft.world.WorldSettings field_234943_a_ -public net.minecraft.entity.projectile.FishingBobberEntity$State -public net.minecraft.world.chunk.NibbleArray func_177482_a(II)V # setIndex -public net.minecraft.world.biome.BiomeContainer field_242704_g # biomeRegistry -public net.minecraft.util.datafix.fixes.BlockStateFlatteningMap func_199194_a(ILjava/lang/String;[Ljava/lang/String;)V -public net.minecraft.entity.item.ArmorStandEntity field_175442_bg -public net.minecraft.entity.projectile.FishingBobberEntity field_184528_c -public net.minecraft.entity.projectile.FishingBobberEntity field_190627_av -public net.minecraft.entity.projectile.FishingBobberEntity field_146043_c -public net.minecraft.entity.projectile.FishingBobberEntity func_184527_k()V -public net.minecraft.entity.projectile.FishingBobberEntity func_190622_s()V -public net.minecraft.entity.item.ItemFrameEntity field_82337_e -public net.minecraft.entity.LivingEntity field_184635_h -public net.minecraft.entity.item.minecart.FurnaceMinecartEntity field_94110_c -public net.minecraft.entity.item.TNTEntity field_94084_b -public net.minecraft.item.ItemUseContext (Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/math/BlockRayTraceResult;)V -public net.minecraft.server.MinecraftServer field_240767_f_ -public net.minecraft.block.SoundType field_185862_o -public net.minecraft.block.SoundType field_185865_r -public net.minecraft.entity.LivingEntity func_241353_q_()V -public net.minecraft.entity.monster.DrownedEntity field_204717_b -public net.minecraft.entity.monster.DrownedEntity field_204716_a +public net.minecraft.world.level.block.entity.BarrelBlockEntity m_58606_(Lnet/minecraft/world/level/block/state/BlockState;Z)V +public net.minecraft.world.level.block.entity.BarrelBlockEntity m_58600_(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/sounds/SoundEvent;)V +public net.minecraft.server.Main m_129674_(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lcom/mojang/datafixers/DataFixer;ZLjava/util/function/BooleanSupplier;Lcom/google/common/collect/ImmutableSet;)V +public net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity f_58318_ +public net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity f_58319_ +public net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity f_58316_ +public net.minecraft.world.entity.animal.AbstractFish m_142392_()Z +public-f net.minecraft.world.inventory.AbstractContainerMenu f_38839_ +public-f net.minecraft.world.inventory.AbstractContainerMenu f_38841_ +public net.minecraft.server.players.StoredUserEntry m_11373_()Ljava/lang/Object; +public net.minecraft.world.entity.projectile.ThrownTrident f_37555_ +public net.minecraft.world.entity.Mob f_21355_ +public net.minecraft.world.entity.Mob f_21353_ +public net.minecraft.world.entity.Mob f_21348_ +public net.minecraft.world.entity.Mob f_21347_ +public-f net.minecraft.world.entity.Mob f_21346_ +public-f net.minecraft.world.entity.Mob f_21345_ +public net.minecraft.world.entity.Mob f_21356_ +public net.minecraft.world.item.crafting.Ingredient$ItemValue +public net.minecraft.world.item.crafting.Ingredient$ItemValue (Lnet/minecraft/world/item/ItemStack;)V +public net.minecraft.world.entity.player.Abilities f_35940_ +public net.minecraft.world.entity.player.Abilities f_35939_ +public net.minecraft.commands.synchronization.ArgumentTypes$Entry +public net.minecraft.world.inventory.CraftingContainer f_39323_ +public net.minecraft.world.entity.animal.Pig f_29459_ +public net.minecraft.network.chat.TextColor f_131258_ +public net.minecraft.world.entity.monster.Guardian f_32806_ +public net.minecraft.world.entity.monster.Zombie f_34266_ +public net.minecraft.world.entity.monster.Zombie f_34261_ +public net.minecraft.world.entity.monster.Zombie m_34278_(I)V +public net.minecraft.server.network.ServerLoginPacketListenerImpl$State +public net.minecraft.world.item.crafting.Ingredient$Value +public net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity f_59605_ +public net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity f_59606_ +public net.minecraft.world.level.storage.PrimaryLevelData f_78443_ +public net.minecraft.world.inventory.MerchantContainer f_40000_ +public net.minecraft.world.level.chunk.DataLayer m_62557_(II)V +public net.minecraft.world.entity.decoration.ItemFrame f_31755_ +public net.minecraft.world.entity.decoration.ItemFrame f_31754_ +public net.minecraft.world.entity.decoration.ItemFrame m_6022_(Lnet/minecraft/core/Direction;)V +public net.minecraft.server.ServerAdvancementManager f_136022_ +public net.minecraft.server.ServerAdvancementManager f_136023_ +public net.minecraft.world.CompoundContainer f_18910_ +public net.minecraft.world.CompoundContainer f_18911_ +public net.minecraft.world.entity.projectile.AbstractArrow f_36703_ +public net.minecraft.world.entity.projectile.AbstractArrow f_36699_ +public net.minecraft.world.entity.projectile.AbstractArrow f_36697_ +public net.minecraft.world.entity.monster.MagmaCube m_7839_(IZ)V +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58653_ +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58654_ +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58655_ +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58650_ +public net.minecraft.world.level.block.entity.BeaconBlockEntity f_58652_ +public net.minecraft.server.level.ServerPlayer f_8920_ +public net.minecraft.server.level.ServerPlayer f_8921_ +public net.minecraft.server.level.ServerPlayer f_8927_ +public net.minecraft.server.level.ServerPlayer m_9217_()V +public net.minecraft.server.level.ServerPlayer m_9209_(Lnet/minecraft/server/level/ServerLevel;)V +public net.minecraft.world.item.StandingAndWallBlockItem f_43246_ +public net.minecraft.world.entity.projectile.ThrowableItemProjectile m_37454_()Lnet/minecraft/world/item/ItemStack; +public net.minecraft.world.phys.shapes.IndirectMerger (Lit/unimi/dsi/fastutil/doubles/DoubleList;Lit/unimi/dsi/fastutil/doubles/DoubleList;ZZ)V +public net.minecraft.world.entity.animal.Bee f_27698_ +public net.minecraft.world.entity.animal.Bee f_27711_ +public net.minecraft.world.entity.animal.Bee m_27925_(Z)V +public net.minecraft.world.entity.animal.Bee m_27919_(Z)V +public net.minecraft.server.level.ServerChunkCache f_8328_ +public net.minecraft.server.level.ServerChunkCache f_8335_ +public net.minecraft.server.level.ServerChunkCache f_8336_ +public net.minecraft.world.entity.projectile.EyeOfEnder f_36954_ +public net.minecraft.world.entity.projectile.EyeOfEnder f_36951_ +public net.minecraft.world.entity.projectile.EyeOfEnder f_36950_ +public net.minecraft.world.entity.projectile.EyeOfEnder f_36953_ +public net.minecraft.world.entity.projectile.EyeOfEnder f_36952_ +public net.minecraft.network.Connection f_129469_ +public net.minecraft.network.Connection f_129468_ +public net.minecraft.network.protocol.game.ServerboundResourcePackPacket f_134406_ +public net.minecraft.world.level.block.SoundType f_56737_ +public net.minecraft.world.level.block.SoundType f_56733_ +public net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity f_59926_ +public net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity f_59929_ +public net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity f_59928_ +public net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity f_59646_ +public net.minecraft.world.level.block.ShulkerBoxBlock f_56185_ +public net.minecraft.world.entity.vehicle.MinecartFurnace f_38548_ +public net.minecraft.world.entity.monster.Pillager f_33259_ +public net.minecraft.world.entity.animal.horse.AbstractHorse f_30520_ +public net.minecraft.world.entity.animal.horse.AbstractHorse m_30625_()V +public net.minecraft.world.scores.Objective f_83304_ +public net.minecraft.world.level.block.DropperBlock m_5824_(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;)V +public net.minecraft.world.entity.monster.SpellcasterIllager m_33737_()Lnet/minecraft/world/entity/monster/SpellcasterIllager$IllagerSpell; +public net.minecraft.world.level.Level f_46423_ +public-f net.minecraft.world.level.Level f_46421_ +public net.minecraft.world.level.Level f_46442_ +public net.minecraft.nbt.TagParser m_129368_(Ljava/lang/String;)Lnet/minecraft/nbt/Tag; +public net.minecraft.nbt.TagParser m_129375_()Lnet/minecraft/nbt/Tag; +private-f net.minecraft.world.item.ItemStack f_41589_ +public net.minecraft.server.level.ChunkMap$TrackedEntity +public net.minecraft.server.level.ChunkMap$TrackedEntity f_140475_ +public net.minecraft.util.datafix.fixes.BlockStateData m_14942_(ILjava/lang/String;[Ljava/lang/String;)V +public net.minecraft.world.entity.animal.Animal f_27555_ +public net.minecraft.world.entity.animal.Animal f_27554_ +public net.minecraft.world.level.block.ComposterBlock m_52002_(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState; +public net.minecraft.world.entity.projectile.FireworkRocketEntity f_37021_ +public net.minecraft.world.entity.projectile.FireworkRocketEntity f_37023_ +public net.minecraft.world.entity.projectile.FireworkRocketEntity f_37019_ +public net.minecraft.server.level.DistanceManager$PlayerTicketTracker +public net.minecraftforge.registries.NamespacedDefaultedWrapper +public net.minecraft.world.item.ItemCooldowns$CooldownInstance +public net.minecraft.world.item.ItemCooldowns$CooldownInstance f_41534_ +public net.minecraft.server.level.ServerLevel f_8549_ +public net.minecraft.server.level.DistanceManager$ChunkTicketTracker +public net.minecraft.world.entity.animal.Fox f_28439_ +public net.minecraft.world.entity.animal.Fox f_28440_ +public net.minecraft.world.entity.animal.Fox m_28464_(Lnet/minecraft/world/entity/animal/Fox$Type;)V +public net.minecraft.world.entity.animal.Fox m_28626_(Z)V +public net.minecraft.world.level.GameRules$IntegerValue m_7377_(Ljava/lang/String;)V +public net.minecraft.world.level.block.entity.SkullBlockEntity f_59756_ +public net.minecraft.world.level.block.entity.SkullBlockEntity f_59757_ +public net.minecraft.world.entity.animal.Rabbit m_8099_()V +public net.minecraft.world.entity.animal.horse.Horse m_30699_(Lnet/minecraft/world/entity/animal/horse/Variant;Lnet/minecraft/world/entity/animal/horse/Markings;)V +public net.minecraft.world.entity.monster.Strider f_33857_ +public net.minecraft.util.datafix.fixes.ItemSpawnEggFix f_16031_ +public net.minecraft.world.entity.raid.Raid f_37672_ +public net.minecraft.world.entity.raid.Raid f_37673_ +public net.minecraft.world.entity.raid.Raid f_37686_ +public net.minecraft.world.entity.raid.Raid f_37678_ +public net.minecraft.world.entity.raid.Raid f_37679_ +public net.minecraft.world.level.GameRules$Value m_7377_(Ljava/lang/String;)V +public net.minecraft.world.level.GameRules$Value m_46368_(Lnet/minecraft/server/MinecraftServer;)V +public net.minecraft.world.level.chunk.LevelChunk f_62775_ +public net.minecraft.world.level.chunk.LevelChunk f_62776_ +public net.minecraft.world.level.chunk.LevelChunk f_62777_ +public net.minecraft.world.level.chunk.LevelChunk f_62779_ +public net.minecraft.world.entity.item.FallingBlockEntity f_31939_ +public net.minecraft.world.level.block.DispenserBlock f_52661_ +public net.minecraft.world.level.block.DispenserBlock m_5824_(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;)V +public net.minecraft.server.level.DistanceManager$FixedPlayerDistanceChunkTracker +public net.minecraft.world.entity.animal.Bee$BeePollinateGoal +public net.minecraft.world.entity.animal.Bee$BeePollinateGoal m_28087_()V +public net.minecraft.world.level.chunk.ChunkBiomeContainer f_62111_ +public net.minecraft.server.MinecraftServer f_129725_ +public net.minecraft.server.MinecraftServer f_129746_ +public net.minecraft.server.MinecraftServer f_129745_ +public net.minecraft.server.MinecraftServer f_129756_ +private-f net.minecraft.server.MinecraftServer f_129755_ +public-f net.minecraft.server.MinecraftServer f_129744_ +public net.minecraft.server.MinecraftServer f_129738_ +protected-f net.minecraft.server.MinecraftServer f_129749_ +public net.minecraft.server.MinecraftServer f_129759_ +public net.minecraft.server.MinecraftServer f_129762_ +public net.minecraft.server.MinecraftServer f_129740_ +public net.minecraft.server.MinecraftServer m_129940_(Lnet/minecraft/server/level/progress/ChunkProgressListener;)V +public net.minecraft.world.level.chunk.storage.RegionFileStorage f_63699_ +public net.minecraft.world.entity.decoration.HangingEntity f_31698_ +public net.minecraft.world.entity.decoration.HangingEntity m_6022_(Lnet/minecraft/core/Direction;)V +public net.minecraft.world.level.Explosion f_46016_ +public net.minecraft.world.entity.LivingEntity f_20948_ +public-f net.minecraft.world.entity.LivingEntity f_20926_ +public net.minecraft.world.entity.LivingEntity f_20949_ +public-f net.minecraft.world.entity.LivingEntity f_20944_ +public net.minecraft.world.entity.LivingEntity f_20945_ +public net.minecraft.world.entity.LivingEntity f_20888_ +public net.minecraft.world.entity.LivingEntity f_20898_ +public net.minecraft.world.entity.LivingEntity f_20940_ +public net.minecraft.world.entity.LivingEntity f_20950_ +public net.minecraft.world.entity.LivingEntity f_20961_ +public net.minecraft.world.entity.LivingEntity m_21315_()V +public net.minecraft.world.entity.player.Player f_36110_ +public net.minecraft.world.entity.player.Player m_6101_()I +public net.minecraft.world.entity.player.Player m_36364_(Lnet/minecraft/nbt/CompoundTag;)V +public net.minecraft.world.entity.player.Player m_36362_(Lnet/minecraft/nbt/CompoundTag;)V +public net.minecraft.world.entity.player.Player m_6915_()V +public net.minecraft.world.entity.animal.horse.Llama m_30840_(I)V +public net.minecraft.server.level.Ticket f_9422_ +public net.minecraft.server.level.Ticket m_9429_(J)V +public net.minecraft.server.level.Ticket (Lnet/minecraft/server/level/TicketType;ILjava/lang/Object;)V +public net.minecraft.server.level.Ticket (Lnet/minecraft/world/server/TicketType;ILjava/lang/Object;J)V +public net.minecraft.world.level.block.entity.BannerBlockEntity f_58474_ +public net.minecraft.world.level.block.entity.BannerBlockEntity f_58475_ +public net.minecraft.world.LockCode f_19103_ +public net.minecraft.world.item.crafting.Ingredient f_43903_ +public net.minecraft.world.item.crafting.Ingredient (Ljava/util/stream/Stream;)V +public net.minecraft.world.item.crafting.Ingredient m_43948_()V +public net.minecraft.advancements.AdvancementList f_139326_ +public net.minecraft.world.level.GameRules$BooleanValue m_7377_(Ljava/lang/String;)V +public net.minecraft.world.entity.boss.enderdragon.EnderDragon f_31089_ +public net.minecraft.world.level.storage.DimensionDataStorage f_78144_ +public net.minecraft.world.entity.LightningBolt f_20862_ +public net.minecraft.world.inventory.Slot f_40217_ +public net.minecraft.world.level.block.JukeboxBlock m_54260_(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V +public net.minecraft.world.entity.boss.wither.WitherBoss f_31430_ +public net.minecraft.world.entity.item.PrimedTnt f_32072_ +public net.minecraft.server.level.ChunkMap f_140139_ +public net.minecraft.server.level.ChunkMap f_140136_ +public net.minecraft.server.level.ChunkMap f_140129_ +public net.minecraft.server.level.ChunkMap f_140130_ +public net.minecraft.server.level.ChunkMap f_140150_ +public net.minecraft.server.level.ChunkMap f_140145_ +public net.minecraft.server.level.ChunkMap f_140144_ +public net.minecraft.server.level.ChunkMap f_140133_ +public net.minecraft.server.level.ChunkMap m_140258_(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59820_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59822_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59813_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59824_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59823_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59815_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59814_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59825_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59817_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59816_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59819_ +public net.minecraft.world.level.block.entity.StructureBlockEntity f_59818_ +public net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket f_133981_ +public net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket f_133980_ +public net.minecraft.network.protocol.handshake.ClientIntentionPacket f_134721_ +public net.minecraft.network.protocol.handshake.ClientIntentionPacket f_134722_ +public-f net.minecraft.world.entity.ai.attributes.RangedAttribute f_22308_ +public-f net.minecraft.server.ServerResources f_136146_ +public net.minecraft.world.entity.projectile.SpectralArrow f_37409_ +public net.minecraft.world.entity.monster.Creeper f_32271_ +public net.minecraft.world.entity.monster.Creeper f_32272_ +public net.minecraft.world.entity.monster.Creeper m_32315_()V +public net.minecraft.world.level.storage.LevelStorageSource$LevelStorageAccess f_78271_ +public net.minecraft.world.inventory.CraftingMenu f_39350_ +public net.minecraft.server.level.ServerBossEvent f_8298_ +public net.minecraft.server.level.ChunkHolder f_140006_ +public net.minecraft.server.level.ChunkHolder f_140016_ +public net.minecraft.server.level.DistanceManager f_140761_ +public net.minecraft.world.entity.monster.ZombieVillager f_34359_ +public net.minecraft.world.entity.monster.ZombieVillager f_34365_ +public net.minecraft.world.entity.monster.ZombieVillager f_34360_ +public net.minecraft.world.entity.monster.ZombieVillager m_34383_(Ljava/util/UUID;I)V +public net.minecraft.world.level.block.entity.BlockEntity f_58857_ +public net.minecraft.world.entity.decoration.ArmorStand f_31525_ +public net.minecraft.world.entity.decoration.ArmorStand f_31526_ +public net.minecraft.world.entity.decoration.ArmorStand f_31543_ +public net.minecraft.world.entity.decoration.ArmorStand f_31542_ +public net.minecraft.world.entity.decoration.ArmorStand f_31545_ +public net.minecraft.world.entity.decoration.ArmorStand f_31544_ +public net.minecraft.world.entity.decoration.ArmorStand f_31541_ +public net.minecraft.world.entity.decoration.ArmorStand m_31681_(Z)V +public net.minecraft.world.entity.decoration.ArmorStand m_31678_(Z)V +public net.minecraft.world.entity.decoration.ArmorStand m_31675_(Z)V +public net.minecraft.world.entity.decoration.ArmorStand m_31603_(Z)V +public net.minecraft.world.phys.shapes.DiscreteCubeMerger (II)V +public net.minecraft.world.entity.projectile.FishingHook f_37101_ +public net.minecraft.world.entity.projectile.FishingHook f_37095_ +public net.minecraft.world.entity.projectile.FishingHook f_37094_ +public net.minecraft.world.entity.monster.Shulker f_33393_ +public net.minecraft.world.level.block.entity.BedBlockEntity f_58724_ +public net.minecraft.stats.RecipeBook f_12680_ +public net.minecraft.world.entity.monster.Drowned f_32341_ +public net.minecraft.world.entity.monster.Drowned f_32340_ +public net.minecraft.world.level.block.entity.BaseContainerBlockEntity f_58621_ +public net.minecraft.world.level.block.entity.BaseContainerBlockEntity f_58622_ +public net.minecraft.server.players.PlayerList f_11196_ +public net.minecraft.server.players.PlayerList f_11204_ +public net.minecraft.server.players.PlayerList m_11273_(Lnet/minecraft/server/ServerScoreboard;Lnet/minecraft/server/level/ServerPlayer;)V +public net.minecraft.world.level.block.entity.SignBlockEntity f_59720_ +public net.minecraft.world.level.block.entity.SignBlockEntity f_59721_ +public net.minecraft.world.entity.monster.Slime m_7839_(IZ)V +public net.minecraft.world.level.block.ComposterBlock$EmptyContainer +public net.minecraft.world.entity.ExperienceOrb f_20770_ +public net.minecraft.world.entity.monster.piglin.Piglin f_34679_ +public net.minecraft.world.entity.monster.hoglin.Hoglin f_34485_ +public net.minecraft.world.entity.monster.hoglin.Hoglin f_34484_ +public net.minecraft.world.entity.monster.hoglin.Hoglin m_34557_()Z +public net.minecraft.world.entity.Entity f_19839_ +public net.minecraft.world.entity.Entity f_19823_ +public net.minecraft.world.entity.Entity f_19798_ +public net.minecraft.world.entity.Entity f_19831_ +public net.minecraft.world.entity.Entity m_20078_()Ljava/lang/String; +public net.minecraft.world.entity.Entity m_20291_(I)Z +public net.minecraft.world.entity.Entity m_20115_(IZ)V +public net.minecraft.world.entity.Entity m_6101_()I +public-f net.minecraft.server.dedicated.DedicatedServer f_139604_ +public net.minecraft.server.dedicated.DedicatedServer f_139602_ +public net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket f_131732_ +public net.minecraft.world.entity.projectile.Arrow f_36852_ +public net.minecraft.world.entity.projectile.Arrow m_36882_(I)V +public net.minecraft.server.players.BanListEntry m_7524_()Z +public net.minecraft.world.BossEvent f_18843_ +public net.minecraft.world.BossEvent f_18842_ +public net.minecraft.world.BossEvent f_18840_ +public net.minecraft.world.level.block.entity.CampfireBlockEntity f_59044_ +public net.minecraft.world.level.block.entity.CampfireBlockEntity f_59043_ +public net.minecraft.world.entity.npc.Villager m_35528_()V +public net.minecraft.world.item.context.UseOnContext (Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/phys/BlockHitResult;)V +public net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket f_133111_ +public net.minecraft.world.entity.vehicle.AbstractMinecartContainer f_38204_ +public net.minecraft.world.entity.vehicle.AbstractMinecartContainer f_38205_ +public net.minecraft.world.level.block.entity.BeehiveBlockEntity f_58733_ +public net.minecraft.world.level.chunk.LevelChunkSection f_62967_ +public net.minecraft.ChatFormatting f_126622_ +public net.minecraft.commands.CommandSourceStack f_81288_ +public net.minecraft.world.phys.shapes.IndexMerger +public net.minecraft.world.level.block.entity.LecternBlockEntity f_59525_ +public net.minecraft.world.level.block.entity.LecternBlockEntity m_59532_(I)V +public net.minecraftforge.registries.NamespacedWrapper +public net.minecraft.world.inventory.AnvilMenu f_39002_ +public net.minecraft.world.inventory.AnvilMenu f_39001_ +public net.minecraft.world.level.block.state.StateHolder f_61110_ +public net.minecraft.world.level.storage.LevelStorageSource f_78194_ diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index 167614f9..0c0566a1 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -16,248 +16,15 @@ "mixinPriority": 500, "mixins": [ "advancements.AdvancementMixin", - "advancements.FunctionManagerMixin", - "advancements.PlayerAdvancementsMixin", - "block.AbstractBlock_AbstractBlockStateMixin", - "block.AbstractBlockMixin", - "block.AbstractButtonBlockMixin", - "block.AbstractFireBlockMixin", - "block.AbstractPressurePlateBlockMixin", - "block.AbstractTopPlantBlockMixin", - "block.BambooBlockMixin", - "block.BambooSaplingBlockMixin", - "block.BeehiveBlockMixin", - "block.BlockMixin", - "block.BushBlockMixin", - "block.CactusBlockMixin", - "block.CakeBlockMixin", - "block.CampfireBlockMixin", - "block.CarvedPumpkinBlockMixin", - "block.CauldronBlockMixin", - "block.ChestBlock2Mixin", - "block.ChorusFlowerBlockMixin", - "block.CocoaBlockMixin", - "block.CommandBlockBlockMixin", - "block.ComparatorBlockMixin", - "block.ComposterBlock_EmptyInventoryMixin", - "block.ComposterBlock_FullInventoryMixin", - "block.ComposterBlock_PartialInventoryMixin", - "block.ComposterBlockMixin", - "block.ConcretePowderBlockMixin", - "block.CoralBlockMixin", - "block.CoralFinBlockMixin", - "block.CoralPlantBlockMixin", - "block.CoralWallFanBlockMixin", - "block.CropsBlockMixin", - "block.DaylightDetectorBlockMixin", - "block.DetectorRailBlockMixin", - "block.DispenserBlockMixin_Accessor", - "block.DoorBlockMixin", - "block.DoublePlantBlockMixin", - "block.DragonEggBlockMixin", - "block.DropperBlockMixin", - "block.EndPortalBlockMixin", - "block.FallingBlockMixin", - "block.FarmlandBlockMixin", - "block.FenceGateBlockMixin", - "block.FireBlockMixin", - "block.FlowingFluidBlockMixin", - "block.FungusBlockMixin", - "block.GrassBlockMixin", - "block.IceBlockMixin", - "block.JukeBoxBlockMixin", - "block.LeavesBlockMixin", - "block.LecternBlockMixin", - "block.LeverBlockMixin", - "block.LilyPadBlockMixin", - "block.MagmaBlockMixin", - "block.MushroomBlockMixin", - "block.NetherPortalBlockMixin", - "block.NetherWartBlockMixin", - "block.NoteBlockMixin", - "block.ObserverBlockMixin", - "block.PistonBlockMixin", - "block.PortalInfoMixin", - "block.PortalSizeMixin", - "block.PoweredRailBlockMixin", - "block.PressurePlateBlockMixin", - "block.RedstoneDiodeBlockMixin", - "block.RedstoneLampBlockMixin", - "block.RedstoneOreBlockMixin", - "block.RedstoneTorchBlockMixin", - "block.RedstoneWireBlockMixin", - "block.SaplingBlockMixin", - "block.ScaffoldingBlockMixin", - "block.SilverfishBlockMixin", - "block.SnowBlockMixin", - "block.SpongeBlockMixin", - "block.SpreadableSnowyDirtBlockMixin", - "block.StemBlockMixin", - "block.SugarCaneBlockMixin", - "block.SweetBerryBushBlockMixin", - "block.TNTBlockMixin", - "block.TrapDoorBlockMixin", - "block.TripWireBlockMixin", - "block.TripWireHookBlockMixin", - "block.TurtleEggBlockMixin", - "block.VineBlockMixin", - "block.WeightedPressurePlateBlockMixin", - "block.WitherRoseBlockMixin", - "block.WitherSkeletonSkullBlockMixin", - "command.CommandNodeMixin", - "command.CommandsMixin", - "command.CommandSourceMixin", - "command.ICommandSourceMixin", - "command.arguments.ArgumentTypesMixin", - "command.arguments.BlockStateParserMixin", - "command.arguments.EntityArgumentMixin", - "command.arguments.EntitySelectorMixin", - "command.arguments.EntitySelectorParserMixin", - "command.impl.EffectCommandMixin", - "command.impl.GameRuleCommandMixin", - "command.impl.ReloadCommandMixin", - "command.impl.SummonCommandMixin", - "command.impl.TeleportCommandMixin", - "command.impl.TimeCommandMixin", - "enchantment.DamageEnchantmentMixin", - "enchantment.FrostWalkerEnchantmentMixin", - "entity.AgeableEntityMixin", - "entity.AreaEffectCloudEntityMixin", - "entity.BoostHelperMixin", - "entity.CreatureEntityMixin", - "entity.EntityMixin", - "entity.EntityTypeMixin", - "entity.IAngerableMixin", - "entity.LivingEntityMixin", - "entity.MobEntityMixin", - "entity.ai.attributes.RangedAttributeMixin", - "entity.ai.brain.BrainUtilMixin", - "entity.ai.brain.task.AssignProfessionTaskMixin", - "entity.ai.brain.task.ChangeJobTaskMixin", - "entity.ai.brain.task.CreateBabyVillagerTaskMixin", - "entity.ai.brain.task.FarmerWorkTaskMixin", - "entity.ai.brain.task.FarmTaskMixin", - "entity.ai.brain.task.FindNewAttackTargetTaskMixin", - "entity.ai.brain.task.ForgetAttackTargetTaskMixin", - "entity.ai.brain.task.InteractWithDoorTaskMixin", - "entity.ai.goal.BreakBlockGoalMixin", - "entity.ai.goal.BreakDoorGoalMixin", - "entity.ai.goal.DefendVillageTargetGoalMixin", - "entity.ai.goal.EatGrassGoalMixin", - "entity.ai.goal.FollowOwnerGoalMixin", - "entity.ai.goal.HurtByTargetGoalMixin", - "entity.ai.goal.NearestAttackableTargetGoalMixin", - "entity.ai.goal.OwnerHurtByTargetGoalMixin", - "entity.ai.goal.OwnerHurtTargetGoalMixin", - "entity.ai.goal.TargetGoalMixin", - "entity.ai.goal.TemptGoalMixin", - "entity.ai.goal.TriggerSkeletonTrapGoalMixin", - "entity.boss.WitherEntityMixin", - "entity.boss.dragon.EnderDragonEntityMixin", - "entity.boss.dragon.phase.PhaseManagerMixin", - "entity.effect.LightningBoltEntityMixin", - "entity.item.ArmorStandEntityMixin", - "entity.item.BoatEntityMixin", - "entity.item.EnderCrystalEntityMixin", - "entity.item.EnderPearlEntityMixin", - "entity.item.ExperienceBottleEntityMixin", - "entity.item.ExperienceOrbEntityMixin", - "entity.item.FallingBlockEntityMixin", - "entity.item.HangingEntityMixin", - "entity.item.ItemEntityMixin", - "entity.item.ItemFrameEntityMixin", - "entity.item.LeashKnotEntityMixin", - "entity.item.PaintingEntityMixin", - "entity.item.TNTEntityMixin", - "entity.item.minecart.AbstractMinecartEntityMixin", - "entity.item.minecart.CommandBlockMinecartEntity_MinecartCommandLogicMixin", - "entity.item.minecart.ContainerMinecartEntityMixin", - "entity.merchant.IMerchantMixin", - "entity.merchant.villager.AbstractVillagerEntityMixin", - "entity.merchant.villager.VillagerEntityMixin", - "entity.merchant.villager.WanderingTraderEntityMixin", - "entity.monster.AbstractRaiderEntity_FindTargetGoalMixin", - "entity.monster.AbstractRaiderEntityMixin", - "entity.monster.AbstractSkeletonEntityMixin", - "entity.monster.CaveSpiderEntityMixin", - "entity.monster.CreeperEntityMixin", - "entity.monster.ElderGuardianEntityMixin", - "entity.monster.EndermanEntity_PlaceBlockGoalMixin", - "entity.monster.EndermanEntity_TakeBlockGoalMixin", - "entity.monster.EndermanEntityMixin", - "entity.monster.GhastEntity_FireballAttackGoalMixin", - "entity.monster.HuskEntityMixin", - "entity.monster.IllusionerEntity_BlindnessSpellGoalMixin", - "entity.monster.IllusionerEntity_MirrorSpellGoalMixin", - "entity.monster.PhantomEntity_AttackPlayerGoalMixin", - "entity.monster.RavagerEntityMixin", - "entity.monster.ShulkerEntityMixin", - "entity.monster.SilverfishEntity_HideInStoneGoalMixin", - "entity.monster.SilverfishEntity_SummonSilverfishGoalMixin", - "entity.monster.SlimeEntityMixin", - "entity.monster.SpellcastingIllagerEntity_UseSpellGoalMixin", - "entity.monster.SpiderEntityMixin", - "entity.monster.VexEntity_CopyOwnerTargetGoalMixin", - "entity.monster.WitchEntityMixin", - "entity.monster.WitherSkeletonEntityMixin", - "entity.monster.ZombieEntityMixin", - "entity.monster.ZombieVillagerEntityMixin", - "entity.monster.ZombifiedPiglinEntityMixin", - "entity.monster.piglin.PiglinTasksMixin", - "entity.passive.AnimalEntityMixin", - "entity.passive.BatEntityMixin", - "entity.passive.BeeEntity_AngerGoalMixin", - "entity.passive.BeeEntity_FindPollinationTargetGoalMixin", - "entity.passive.BeeEntityMixin", - "entity.passive.ChickenEntityMixin", - "entity.passive.CowEntityMixin", - "entity.passive.DolphinEntity_SwimWithPlayerGoalMixin", - "entity.passive.DolphinEntityMixin", - "entity.passive.FoxEntity_EatBerriesGoalMixin", - "entity.passive.FoxEntity_MateGoalMixin", - "entity.passive.FoxEntity_RevengeGoalMixin", - "entity.passive.FoxEntityMixin", - "entity.passive.IronGolemEntityMixin", - "entity.passive.MooshroomEntityMixin", - "entity.passive.OcelotEntityMixin", - "entity.passive.PandaEntity_RevengeGoalMixin", - "entity.passive.PandaEntityMixin", - "entity.passive.ParrotEntityMixin", - "entity.passive.PigEntityMixin", - "entity.passive.RabbitEntity_RaidFarmGoalMixin", - "entity.passive.RabbitEntityMixin", - "entity.passive.SheepEntity1Mixin", - "entity.passive.SheepEntityMixin", - "entity.passive.SnowGolemEntityMixin", - "entity.passive.TameableEntityMixin", - "entity.passive.TurtleEntity_LayEggGoalMixin", - "entity.passive.TurtleEntityMixin", - "entity.passive.WolfEntityMixin", - "entity.passive.fish.AbstractFishEntityMixin", - "entity.passive.fish.PufferfishEntityMixin", - "entity.passive.horse.AbstractHorseEntityMixin", - "entity.passive.horse.TraderLlamaEntity_FollowTraderGoalMixin", - "entity.player.PlayerEntityMixin", - "entity.player.PlayerInventoryMixin", - "entity.player.ServerPlayerEntityMixin", - "entity.projectile.AbstractArrowEntityMixin", - "entity.projectile.AbstractFireballEntityMixin", - "entity.projectile.ArrowEntityMixin", - "entity.projectile.DamagingProjectileEntityMixin", - "entity.projectile.EggEntityMixin", - "entity.projectile.EvokerFangsEntityMixin", - "entity.projectile.FireballEntityMixin", - "entity.projectile.FireworkRocketEntityMixin", - "entity.projectile.FishingBobberEntityMixin", - "entity.projectile.PotionEntityMixin", - "entity.projectile.ProjectileEntityMixin", - "entity.projectile.ProjectileItemEntityMixin", - "entity.projectile.ShulkerBulletEntityMixin", - "entity.projectile.SmallFireballEntityMixin", - "entity.projectile.SpectralArrowEntityMixin", - "entity.projectile.ThrowableEntityMixin", - "entity.projectile.TridentEntityMixin", - "entity.projectile.WitherSkullEntityMixin", + "commands.CommandNodeMixin", + "commands.CommandsMixin", + "commands.CommandSourceMixin", + "commands.CommandSourceStackMixin", + "commands.arguments.EntityArgumentMixin", + "commands.arguments.blocks.BlockStateParserMixin", + "commands.arguments.selector.EntitySelectorMixin", + "commands.arguments.selector.EntitySelectorParserMixin", + "commands.synchronization.ArgumentTypesMixin", "fluid.FlowingFluidMixin", "fluid.LavaFluidMixin", "inventory.CraftingInventoryMixin", @@ -365,6 +132,14 @@ "server.CustomServerBossInfoMixin", "server.MainMixin", "server.MinecraftServerMixin", + "server.PlayerAdvancementsMixin", + "server.ServerFunctionManagerMixin", + "server.commands.EffectCommandMixin", + "server.commands.GameRuleCommandMixin", + "server.commands.ReloadCommandMixin", + "server.commands.SummonCommandMixin", + "server.commands.TeleportCommandMixin", + "server.commands.TimeCommandMixin", "server.dedicated.DedicatedServerMixin", "server.management.BanEntryMixin", "server.management.PlayerInteractionManagerMixin", @@ -414,10 +189,240 @@ "world.chunk.ChunkMixin", "world.chunk.storage.ChunkLoaderMixin", "world.chunk.storage.RegionFileCacheMixin", + "world.entity.AgeableMobMixin", + "world.entity.AreaEffectCloudEntityMixin", + "world.entity.ItemBaseSteeringMixin", + "world.entity.EntityMixin", + "world.entity.EntityTypeMixin", + "world.entity.ExperienceOrbMixin", + "world.entity.IAngerableMixin", + "world.entity.LightningBoltMixin", + "world.entity.LivingEntityMixin", + "world.entity.MobMixin", + "world.entity.PathfinderMobMixin", + "world.entity.ai.attributes.RangedAttributeMixin", + "world.entity.ai.behavior.AssignProfessionFromJobSiteMixin", + "world.entity.ai.behavior.HarvestFarmlandMixin", + "world.entity.ai.behavior.InteractWithDoorMixin", + "world.entity.ai.behavior.ResetProfessionMixin", + "world.entity.ai.behavior.StartAttackingMixin", + "world.entity.ai.behavior.StopAttackingIfTargetInvalidMixin", + "world.entity.ai.behavior.VillagerMakeLoveMixin", + "world.entity.ai.behavior.WorkAtComposterMixin", + "world.entity.ai.brain.BrainUtilMixin", + "world.entity.ai.goal.BreakDoorGoalMixin", + "world.entity.ai.goal.DefendVillageTargetGoalMixin", + "world.entity.ai.goal.EatBlockGoalMixin", + "world.entity.ai.goal.FollowOwnerGoalMixin", + "world.entity.ai.goal.HurtByTargetGoalMixin", + "world.entity.ai.goal.NearestAttackableTargetGoalMixin", + "world.entity.ai.goal.OwnerHurtByTargetGoalMixin", + "world.entity.ai.goal.OwnerHurtTargetGoalMixin", + "world.entity.ai.goal.RemoveBlockGoalMixin", + "world.entity.ai.goal.SkeletonTrapGoalMixin", + "world.entity.ai.goal.TargetGoalMixin", + "world.entity.ai.goal.TemptGoalMixin", + "world.entity.ambient.BatMixin", + "world.entity.animal.AbstractFishMixin", + "world.entity.animal.AnimalMixin", + "world.entity.animal.Bee_GrowCropGoalMixin", + "world.entity.animal.Bee_HurtByOtherGoalMixin", + "world.entity.animal.BeeMixin", + "world.entity.animal.BucketableMixin", + "world.entity.animal.PufferfishEntityMixin", + "world.entity.animal.horse.AbstractHorseMixin", + "world.entity.animal.horse.TraderLlamaEntity_FollowTraderGoalMixin", + "world.entity.boss.WitherEntityMixin", + "world.entity.boss.enderdragon.EnderCrystalMixin", + "world.entity.boss.enderdragon.EnderDragonMixin", + "world.entity.boss.enderdragon.phases.EnderDragonPhaseManagerMixin", + "world.entity.boss.wither.WitherBossMixin", + "world.entity.decoration.ItemFrameMixin", + "world.entity.decoration.LeashFenceKnotEntityMixin", + "world.entity.decoration.PaintingMixin", + "world.entity.item.ArmorStandEntityMixin", + "world.entity.item.FallingBlockEntityMixin", + "world.entity.item.HangingEntityMixin", + "world.entity.item.ItemEntityMixin", + "world.entity.item.PrimedTntMixin", + "world.entity.monster.AbstractSkeletonMixin", + "world.entity.monster.CaveSpiderMixin", + "world.entity.monster.CreeperMixin", + "world.entity.monster.ElderGuardianMixin", + "world.entity.monster.EnderMan_EndermanLeaveBlockGoalMixin", + "world.entity.monster.EnderMan_EndermanTakeBlockGoalMixin", + "world.entity.monster.EnderManMixin", + "world.entity.monster.Ghast_GhastShootFireballGoalMixin", + "world.entity.monster.HuskMixin", + "world.entity.monster.Illusioner_BlindnessSpellGoalMixin", + "world.entity.monster.Illusioner_MirrorSpellGoalMixin", + "world.entity.monster.Phantom_AttackPlayerTargetGoalMixin", + "world.entity.monster.RavagerMixin", + "world.entity.monster.ShulkerMixin", + "world.entity.monster.Silverfish_MergeWithStoneGoalMixin", + "world.entity.monster.Silverfish_WakeUpFriendsGoalMixin", + "world.entity.monster.SlimeMixin", + "world.entity.monster.SpellcastingIllager_UseSpellGoalMixin", + "world.entity.monster.SpiderMixin", + "world.entity.monster.Vex_CopyOwnerTargetGoalMixin", + "world.entity.monster.WitchMixin", + "world.entity.monster.WitherSkeletonMixin", + "world.entity.monster.ZombieMixin", + "world.entity.monster.ZombieVillagerMixin", + "world.entity.monster.ZombifiedPiglinMixin", + "world.entity.monster.piglin.PiglinAiMixin", + "world.entity.monster.piglin.PiglinMixin", + "world.entity.npc.AbstractVillagerMixin", + "world.entity.npc.VillagerMixin", + "world.entity.npc.WanderingTraderMixin", + "world.entity.animal.ChickenMixin", + "world.entity.animal.CowMixin", + "world.entity.animal.DolphinEntity_SwimWithPlayerGoalMixin", + "world.entity.animal.DolphinMixin", + "world.entity.animal.Fox_EatBerriesGoalMixin", + "world.entity.animal.Fox_BreedGoalMixin", + "world.entity.passive.FoxEntity_RevengeGoalMixin", + "world.entity.animal.FoxMixin", + "world.entity.animal.IronGolemMixin", + "world.entity.animal.MushroomCowMixin", + "world.entity.animal.OcelotMixin", + "world.entity.animal.Panda_HurtByTargetGoalMixin", + "world.entity.animal.PandaMixin", + "world.entity.animal.ParrotMixin", + "world.entity.animal.PigMixin", + "world.entity.animal.Rabbit_RaidGardenGoalMixin", + "world.entity.animal.RabbitMixin", + "world.entity.animal.Sheep1Mixin", + "world.entity.animal.SheepMixin", + "world.entity.animal.SnowGolemMixin", + "world.entity.animal.TameableAnimalMixin", + "world.entity.animal.Turtle_LayEggGoalMixin", + "world.entity.animal.TurtleMixin", + "world.entity.animal.WolfMixin", + "world.entity.player.PlayerMixin", + "world.entity.player.InventoryMixin", + "world.entity.player.ServerPlayerEntityMixin", + "world.entity.projectile.AbstractArrowMixin", + "world.entity.projectile.FireballMixin", + "world.entity.projectile.ArrowEntityMixin", + "world.entity.projectile.AbstractHurtingProjectileMixin", + "world.entity.projectile.ThrownEggMixin", + "world.entity.projectile.EvokerFangsMixin", + "world.entity.projectile.LargeFireballMixin", + "world.entity.projectile.FireworkRocketEntityMixin", + "world.entity.projectile.FishingHookMixin", + "world.entity.projectile.ThrownPotionMixin", + "world.entity.projectile.ProjectileMixin", + "world.entity.projectile.ShulkerBulletMixin", + "world.entity.projectile.SmallFireballMixin", + "world.entity.projectile.SpectralArrowMixin", + "world.entity.projectile.ThrowableItemProjectileMixin", + "world.entity.projectile.ThrowableProjectileMixin", + "world.entity.projectile.ThrownEnderpearlMixin", + "world.entity.projectile.ThrownExperienceBottleMixin", + "world.entity.projectile.ThrownTridentMixin", + "world.entity.projectile.WitherSkullMixin", + "world.entity.raider.Raider_HoldGroundAttackGoalMixin", + "world.entity.raider.RaiderMixin", + "world.entity.vehicle.AbstractMinecartContainerMixin", + "world.entity.vehicle.AbstractMinecartMixin", + "world.entity.vehicle.BoatMixin", + "world.entity.vehicle.MinecartCommandBlock_MinecartCommandBaseMixin", "world.gen.WorldGenRegionMixin", "world.gen.feature.structure.StructureManagerMixin", "world.gen.feature.structure.SwampHutPieceMixin", "world.gen.feature.template.TemplateManagerMixin", + "world.item.MerchantMixin", + "world.item.enchantment.DamageEnchantmentMixin", + "world.item.enchantment.FrostWalkerEnchantmentMixin", + "world.level.block.BambooBlockMixin", + "world.level.block.BambooSaplingBlockMixin", + "world.level.block.BaseFireBlockMixin", + "world.level.block.BasePressurePlateBlockMixin", + "world.level.block.BeehiveBlockMixin", + "world.level.block.BlockMixin", + "world.level.block.BushBlockMixin", + "world.level.block.ButtonBlockMixin", + "world.level.block.CactusBlockMixin", + "world.level.block.CakeBlockMixin", + "world.level.block.CampfireBlockMixin", + "world.level.block.CarvedPumpkinBlockMixin", + "world.level.block.CauldronBlockMixin", + "world.level.block.CaveVinesMixin", + "world.level.block.ChestBlock2Mixin", + "world.level.block.ChorusFlowerBlockMixin", + "world.level.block.CocoaBlockMixin", + "world.level.block.CommandBlockMixin", + "world.level.block.ComparatorBlockMixin", + "world.level.block.ComposterBlock_EmptyContainerMixin", + "world.level.block.ComposterBlock_InputContainerMixin", + "world.level.block.ComposterBlock_OutputContainerMixin", + "world.level.block.ComposterBlockMixin", + "world.level.block.ConcretePowderBlockMixin", + "world.level.block.CoralBlockMixin", + "world.level.block.CoralFanBlockMixin", + "world.level.block.CoralPlantBlockMixin", + "world.level.block.CoralWallFanBlockMixin", + "world.level.block.CropBlockMixin", + "world.level.block.DaylightDetectorBlockMixin", + "world.level.block.DetectorRailBlockMixin", + "world.level.block.DiodeBlockMixin", + "world.level.block.DispenserBlockMixin_Accessor", + "world.level.block.DoorBlockMixin", + "world.level.block.DoublePlantBlockMixin", + "world.level.block.DragonEggBlockMixin", + "world.level.block.DropperBlockMixin", + "world.level.block.EndPortalBlockMixin", + "world.level.block.FallingBlockMixin", + "world.level.block.FarmBlockMixin", + "world.level.block.FenceGateBlockMixin", + "world.level.block.FireBlockMixin", + "world.level.block.FungusBlockMixin", + "world.level.block.GrassBlockMixin", + "world.level.block.GrowingPlantHeadBlockMixin", + "world.level.block.IceBlockMixin", + "world.level.block.InfestedBlockMixin", + "world.level.block.JukeBoxBlockMixin", + "world.level.block.LayeredCauldronBlockMixin", + "world.level.block.LeavesBlockMixin", + "world.level.block.LecternBlockMixin", + "world.level.block.LeverBlockMixin", + "world.level.block.LilyPadBlockMixin", + "world.level.block.LiquidBlockMixin", + "world.level.block.MagmaBlockMixin", + "world.level.block.MushroomBlockMixin", + "world.level.block.NetherPortalBlockMixin", + "world.level.block.NetherWartBlockMixin", + "world.level.block.NoteBlockMixin", + "world.level.block.ObserverBlockMixin", + "world.level.block.PistonBlockMixin", + "world.level.block.PortalInfoMixin", + "world.level.block.PortalSizeMixin", + "world.level.block.PoweredRailBlockMixin", + "world.level.block.PressurePlateBlockMixin", + "world.level.block.RedstoneLampBlockMixin", + "world.level.block.RedstoneOreBlockMixin", + "world.level.block.RedstoneTorchBlockMixin", + "world.level.block.RedstoneWireBlockMixin", + "world.level.block.SaplingBlockMixin", + "world.level.block.ScaffoldingBlockMixin", + "world.level.block.SnowBlockMixin", + "world.level.block.SpongeBlockMixin", + "world.level.block.SpreadableSnowyDirtBlockMixin", + "world.level.block.StemBlockMixin", + "world.level.block.SugarCaneBlockMixin", + "world.level.block.SweetBerryBushBlockMixin", + "world.level.block.TntBlockMixin", + "world.level.block.TrapDoorBlockMixin", + "world.level.block.TripWireBlockMixin", + "world.level.block.TripWireHookBlockMixin", + "world.level.block.TurtleEggBlockMixin", + "world.level.block.VineBlockMixin", + "world.level.block.WeightedPressurePlateBlockMixin", + "world.level.block.WitherRoseBlockMixin", + "world.level.block.WitherSkullBlockMixin", + "world.level.block.state.BlockBehaviour_BlockStateBaseMixin", + "world.level.block.state.BlockBehaviourMixin", "world.raid.RaidManagerMixin", "world.raid.RaidMixin", "world.server.ChunkHolderMixin", diff --git a/arclight-forge/build.gradle b/arclight-forge/build.gradle index 92557f1a..1d01995c 100644 --- a/arclight-forge/build.gradle +++ b/arclight-forge/build.gradle @@ -26,12 +26,12 @@ arclight { wipeVersion = true reobfVersion = true accessTransformer = project(':arclight-common').file('bukkit.at') - packageName = 'spigot' + // packageName = 'spigot' } archivesBaseName = archivesBaseName + '-' + minecraftVersion -sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' +// sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '11' sourceSets { applaunch { @@ -48,7 +48,7 @@ configurations { } minecraft { - mappings channel: 'snapshot', version: "20210215-1.16.3" + mappings channel: 'official', version: minecraftVersion accessTransformer = project(':arclight-common').file('src/main/resources/META-INF/accesstransformer.cfg') } @@ -145,12 +145,6 @@ remapSpigotJar { includes.add('net/minecraft/tileentity/LecternTileEntity$LecternInventory') } -processMapping { - process { csrg, srg -> - csrg.classes.put('net/minecraft/world/level/ColorResolver', "net/minecraft/server/$bukkitVersion/ColorResolver".toString()) - } -} - mixin { add sourceSets.main, 'mixins.arclight.impl.forge.refmap.json' } diff --git a/build.gradle b/build.gradle index c4a41a23..e0df20ba 100644 --- a/build.gradle +++ b/build.gradle @@ -4,8 +4,8 @@ allprojects { ext { agpVersion = '1.17' - minecraftVersion = '1.16.5' - forgeVersion = '36.2.0' + minecraftVersion = '1.17.1' + forgeVersion = '37.0.1' apiVersion = '1.0.+' toolsVersion = '1.3.+' } diff --git a/forge-installer/build.gradle b/forge-installer/build.gradle index 1f5324ad..c1214ccc 100644 --- a/forge-installer/build.gradle +++ b/forge-installer/build.gradle @@ -12,7 +12,8 @@ repositories { } dependencies { - compile 'com.google.code.gson:gson:2.8.0' - compile "io.izzel.arclight:arclight-api:$apiVersion" - compile project(':i18n-config') + implementation 'com.google.code.gson:gson:2.8.0' + implementation 'com.google.guava:guava:30.1.1-jre' + implementation "io.izzel.arclight:arclight-api:$apiVersion" + implementation project(':i18n-config') } diff --git a/gradle.properties b/gradle.properties index 73d22b51..effc1594 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ org.gradle.jvmargs=-Xmx4g -Dfile.encoding=utf-8 -forge_gradle_version=4.1.4 \ No newline at end of file +forge_gradle_version=5.1.+ \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e11710aa..c79e3a24 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Sun Feb 09 15:27:43 CST 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-7.2-20210702220150+0000-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/i18n-config/build.gradle b/i18n-config/build.gradle index 0caedf54..6a2d5485 100644 --- a/i18n-config/build.gradle +++ b/i18n-config/build.gradle @@ -11,9 +11,9 @@ repositories { } dependencies { - compile 'org.spongepowered:configurate-hocon:3.6.1' + implementation 'org.spongepowered:configurate-hocon:3.6.1' } jar { - from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) + from { configurations.implementation.collect { it.isDirectory() ? it : zipTree(it) } } }