From 98e8d33fff21eac1a75224f620ba2fcdb7dc29a0 Mon Sep 17 00:00:00 2001 From: i509vcb <30619168+i509VCB@users.noreply.github.com> Date: Thu, 6 Feb 2020 22:09:10 -0600 Subject: [PATCH] Start moving some simpler things to new tracker package. --- .../world/end/DragonFightManagerMixin.java | 167 ------------------ .../item/BoneMealItemMixin_Tracker.java} | 10 +- .../end/DragonFightManagerMixin_Tracker.java | 39 ++++ src/main/resources/mixins.common.core.json | 2 - src/main/resources/mixins.common.tracker.json | 7 +- 5 files changed, 50 insertions(+), 175 deletions(-) delete mode 100644 src/main/java/org/spongepowered/common/mixin/core/world/end/DragonFightManagerMixin.java rename src/main/java/org/spongepowered/common/mixin/{core/item/DyeItemMixin.java => tracker/item/BoneMealItemMixin_Tracker.java} (95%) create mode 100644 src/main/java/org/spongepowered/common/mixin/tracker/world/end/DragonFightManagerMixin_Tracker.java diff --git a/src/main/java/org/spongepowered/common/mixin/core/world/end/DragonFightManagerMixin.java b/src/main/java/org/spongepowered/common/mixin/core/world/end/DragonFightManagerMixin.java deleted file mode 100644 index 9c610fc84e8..00000000000 --- a/src/main/java/org/spongepowered/common/mixin/core/world/end/DragonFightManagerMixin.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * This file is part of Sponge, licensed under the MIT License (MIT). - * - * Copyright (c) SpongePowered - * Copyright (c) contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.spongepowered.common.mixin.core.world.end; - -import net.minecraft.entity.boss.dragon.EnderDragonEntity; -import net.minecraft.entity.item.EnderCrystalEntity; -import net.minecraft.util.EntityPredicates; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ServerBossInfo; -import net.minecraft.world.end.DragonFightManager; -import net.minecraft.world.end.DragonSpawnState; -import net.minecraft.world.server.ServerWorld; -import org.apache.logging.log4j.Logger; -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.common.event.tracking.PhaseTracker; -import org.spongepowered.common.event.tracking.context.GeneralizedContext; -import org.spongepowered.common.event.tracking.phase.world.dragon.DragonPhase; - -import java.util.List; -import java.util.UUID; - -@Mixin(DragonFightManager.class) -public abstract class DragonFightManagerMixin { - - @Shadow @Final private static Logger LOGGER; - @Shadow @Final private ServerBossInfo bossInfo; - @Shadow @Final private ServerWorld world; - @Shadow private int ticksSinceDragonSeen; - @Shadow private int ticksSinceCrystalsScanned; - @Shadow private int ticksSinceLastPlayerScan; - @Shadow private boolean dragonKilled; - @Shadow private boolean previouslyKilled; - @Shadow private UUID dragonUniqueId; - @Shadow private boolean scanForLegacyFight; - @Shadow private BlockPos exitPortalLocation; - @Shadow private DragonSpawnState respawnState; - @Shadow private int respawnStateTicks; - @Shadow private List crystals; - - @Shadow public abstract void respawnDragon(); - @Shadow private boolean hasDragonBeenKilled() { - return false; // Shadowed - } - @Shadow private void updatePlayers() { } - @Shadow private void findAliveCrystals() { } - @Shadow private void loadChunks() { } - @Shadow private void generatePortal(final boolean flag) { } - @Shadow private EnderDragonEntity createNewDragon() { - return null; // Shadowed - } - - /** - * @author gabizou - January 22nd, 2017 - * @reason Injects Sponge necessary phase state switches - */ - @Overwrite - public void tick() { - this.bossInfo.setVisible(!this.dragonKilled); - - if (++this.ticksSinceLastPlayerScan >= 20) { - this.updatePlayers(); - this.ticksSinceLastPlayerScan = 0; - } - - if (!this.bossInfo.getPlayers().isEmpty()) { - if (this.scanForLegacyFight) { - LOGGER.info("Scanning for legacy world dragon fight..."); - this.loadChunks(); - this.scanForLegacyFight = false; - final boolean flag = this.hasDragonBeenKilled(); - - if (flag) { - LOGGER.info("Found that the dragon has been killed in this world already."); - this.previouslyKilled = true; - } else { - LOGGER.info("Found that the dragon has not yet been killed in this world."); - this.previouslyKilled = false; - this.generatePortal(false); - } - - final List list = this.world.getEntities(EnderDragonEntity.class, EntityPredicates.IS_ALIVE); - - if (list.isEmpty()) { - this.dragonKilled = true; - } else { - final EnderDragonEntity entitydragon = list.get(0); - this.dragonUniqueId = entitydragon.getUniqueID(); - LOGGER.info("Found that there\'s a dragon still alive ({})", entitydragon); - this.dragonKilled = false; - - if (!flag) { - LOGGER.info("But we didn\'t have a portal, let\'s remove it."); - entitydragon.remove(); - this.dragonUniqueId = null; - } - } - - if (!this.previouslyKilled && this.dragonKilled) { - this.dragonKilled = false; - } - } - - if (this.respawnState != null) { - if (this.crystals == null) { - this.respawnState = null; - this.respawnDragon(); - } - - // Sponge Start - Cause tracker - todo: do more logistical configuration of how this all works. - try (final GeneralizedContext context = DragonPhase.State.RESPAWN_DRAGON.createPhaseContext(PhaseTracker.SERVER)) { - context.buildAndSwitch(); - // Sponge End - this.respawnState - .process(this.world, (DragonFightManager) (Object) this, this.crystals, this.respawnStateTicks++, this.exitPortalLocation); - }// Sponge - Complete cause tracker - } - - if (!this.dragonKilled) { - if (this.dragonUniqueId == null || ++this.ticksSinceDragonSeen >= 1200) { - this.loadChunks(); - final List list1 = this.world.getEntities(EnderDragonEntity.class, EntityPredicates.IS_ALIVE); - - if (list1.isEmpty()) { - LOGGER.debug("Haven\'t seen the dragon, respawning it"); - this.createNewDragon(); - } else { - LOGGER.debug("Haven\'t seen our dragon, but found another one to use."); - this.dragonUniqueId = list1.get(0).getUniqueID(); - } - - this.ticksSinceDragonSeen = 0; - } - - if (++this.ticksSinceCrystalsScanned >= 100) { - this.findAliveCrystals(); - this.ticksSinceCrystalsScanned = 0; - } - } - } - } - -} diff --git a/src/main/java/org/spongepowered/common/mixin/core/item/DyeItemMixin.java b/src/main/java/org/spongepowered/common/mixin/tracker/item/BoneMealItemMixin_Tracker.java similarity index 95% rename from src/main/java/org/spongepowered/common/mixin/core/item/DyeItemMixin.java rename to src/main/java/org/spongepowered/common/mixin/tracker/item/BoneMealItemMixin_Tracker.java index 63446f36b76..ce900dcecfd 100644 --- a/src/main/java/org/spongepowered/common/mixin/core/item/DyeItemMixin.java +++ b/src/main/java/org/spongepowered/common/mixin/tracker/item/BoneMealItemMixin_Tracker.java @@ -22,11 +22,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package org.spongepowered.common.mixin.core.item; +package org.spongepowered.common.mixin.tracker.item; import net.minecraft.block.BlockState; import net.minecraft.block.IGrowable; -import net.minecraft.item.DyeItem; +import net.minecraft.item.BoneMealItem; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -44,8 +44,8 @@ import java.util.Random; -@Mixin(DyeItem.class) -public abstract class DyeItemMixin extends ItemMixin { +@Mixin(BoneMealItem.class) +public abstract class BoneMealItemMixin_Tracker { /** * @author gabizou - March 20th, 2019 - 1.12.2 @@ -74,7 +74,7 @@ public abstract class DyeItemMixin extends ItemMixin { method = "applyBonemeal", at = @At( value = "INVOKE", - target = "Lnet/minecraft/block/IGrowable;grow(Lnet/minecraft/world/World;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)V" + target = "Lnet/minecraft/block/IGrowable;grow(Lnet/minecraft/world/World;Ljava/util/Random;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V" ), require = 0, // Will be removed once the above github issue is resolved with a proper solution // Even though we're in a group, expecting this to succeed in forge environments will not work since there is a different mixin diff --git a/src/main/java/org/spongepowered/common/mixin/tracker/world/end/DragonFightManagerMixin_Tracker.java b/src/main/java/org/spongepowered/common/mixin/tracker/world/end/DragonFightManagerMixin_Tracker.java new file mode 100644 index 00000000000..1ca6a6efb89 --- /dev/null +++ b/src/main/java/org/spongepowered/common/mixin/tracker/world/end/DragonFightManagerMixin_Tracker.java @@ -0,0 +1,39 @@ +package org.spongepowered.common.mixin.tracker.world.end; + +import net.minecraft.entity.item.EnderCrystalEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.end.DragonFightManager; +import net.minecraft.world.end.DragonSpawnState; +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.Redirect; +import org.spongepowered.common.event.tracking.PhaseTracker; +import org.spongepowered.common.event.tracking.context.GeneralizedContext; +import org.spongepowered.common.event.tracking.phase.world.dragon.DragonPhase; + +import java.util.List; + +@Mixin(DragonFightManager.class) +public abstract class DragonFightManagerMixin_Tracker { + + /** + * @author i509vcb - February 6th 2020 + * @reason Add sponge necessary phase state switches + * + * @param dragonSpawnState The dragon spawn state. + * @param worldIn The world this respawnState is occuring in. + * @param manager The current DragonFightManager. + * @param crystals List of all currently present end crystals. + * @param respawnStateTicks The amount of this this respawn state has been running for. + * @param exitPortalLocation The position of the exit portal. + */ + @Redirect(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/end/DragonSpawnState;process(Lnet/minecraft/world/server/ServerWorld;Lnet/minecraft/world/end/DragonFightManager;Ljava/util/List;ILnet/minecraft/util/math/BlockPos;)V")) + private void trackDragonRespawn(DragonSpawnState dragonSpawnState, ServerWorld worldIn, DragonFightManager manager, List crystals, int respawnStateTicks, BlockPos exitPortalLocation) { + try (final GeneralizedContext context = DragonPhase.State.RESPAWN_DRAGON.createPhaseContext(PhaseTracker.SERVER)) { + context.buildAndSwitch(); + ++respawnStateTicks; + dragonSpawnState.process(worldIn, manager, crystals, respawnStateTicks, exitPortalLocation); + } + } +} diff --git a/src/main/resources/mixins.common.core.json b/src/main/resources/mixins.common.core.json index 59938ed4fce..82786c794ee 100644 --- a/src/main/resources/mixins.common.core.json +++ b/src/main/resources/mixins.common.core.json @@ -113,7 +113,6 @@ "entity.projectile.SnowballEntityMixin", "entity.projectile.ThrowableEntityMixin", "entity.projectile.WitherSkullEntityMixin", - "item.DyeItemMixin", "item.EnderEyeItemMixin", "item.FilledMapItemMixin", "item.FishingRodItemMixin", @@ -225,7 +224,6 @@ "world.dimension.DimensionMixin", "world.dimension.DimensionTypeMixin", "world.dimension.NetherDimensionMixin", - "world.end.DragonFightManagerMixin", "world.raid.RaidMixin", "world.server.ChunkManager_EntityTrackerMixin", "world.server.ChunkManagerMixin", diff --git a/src/main/resources/mixins.common.tracker.json b/src/main/resources/mixins.common.tracker.json index 415a547c9bc..575d43a8d18 100644 --- a/src/main/resources/mixins.common.tracker.json +++ b/src/main/resources/mixins.common.tracker.json @@ -5,8 +5,13 @@ "plugin": "org.spongepowered.common.mixin.plugin.TrackerPlugin", "mixinPriority" : 1111, "mixins": [ + "block.BlockMixin_Tracker", + "block.DispenserBlockMixin_Tracker", + "block.LeavesBlockMixin_Tracker", + "item.BoneMealItemMixin_Tracker", "world.chunk.ChunkMixin_OwnershipTracked", - "world.WorldMixin_OwnershipTracked", + "world.end.DragonFightManagerMixin_Tracker", + "world.WorldMixin_OwnershipTracked", "OwnershipTrackedMixin_Tracker" ], "server": [