From 8f738a09cd00897b83e6cc59d12257cd9152f52b Mon Sep 17 00:00:00 2001 From: Treetrain1 Date: Fri, 18 Oct 2024 22:53:59 -0500 Subject: [PATCH] More porting work --- .../trailiertales/block/CoffinBlock.java | 14 +++-- .../trailiertales/block/DawntrailBlock.java | 5 +- .../block/entity/coffin/CoffinSpawner.java | 34 +++++------ .../entity/coffin/impl/EntityCoffinData.java | 2 +- .../datagen/loot/TTEntityLootProvider.java | 2 +- .../effect/TransfiguringMobEffect.java | 17 +++--- .../trailiertales/entity/Apparition.java | 56 +++++++++---------- .../entity/ThrownItemProjectile.java | 9 +-- .../entity/ai/apparition/ApparitionAi.java | 21 +++---- .../ApparitionAttackablesSensor.java | 12 ++-- .../ApparitionNearestItemSensor.java | 6 +- .../ai/apparition/ApparitionPlayerSensor.java | 20 +++---- .../render/layer/ApparitionOverlayLayer.java | 23 ++++---- .../entity/render/model/ApparitionModel.java | 22 ++++---- .../render/renderer/ApparitionRenderer.java | 3 +- .../renderer/state/ApparitionRenderState.java | 15 +++++ .../client/brush/ItemInHandLayerMixin.java | 12 +++- .../mixin/client/haunt/GuiMixin.java | 24 ++++---- .../mixin/common/boat/BoatMixin.java | 4 +- .../mixin/common/boat/VehicleEntityMixin.java | 9 +-- .../FallingBlockEntityItemMixin.java | 12 ++-- .../mixin/common/coffin/EntityMixin.java | 8 ++- .../mod_compat/FrozenLibIntegration.java | 8 ++- .../trailiertales/registry/TTEntityTypes.java | 6 +- .../trailiertales/registry/TTPotions.java | 2 +- .../worldgen/structure/RuinsPieces.java | 4 +- .../worldgen/structure/RuinsStructure.java | 4 +- 27 files changed, 195 insertions(+), 159 deletions(-) create mode 100644 src/main/java/net/frozenblock/trailiertales/entity/render/renderer/state/ApparitionRenderState.java diff --git a/src/main/java/net/frozenblock/trailiertales/block/CoffinBlock.java b/src/main/java/net/frozenblock/trailiertales/block/CoffinBlock.java index e55c3d22..c55d3a80 100644 --- a/src/main/java/net/frozenblock/trailiertales/block/CoffinBlock.java +++ b/src/main/java/net/frozenblock/trailiertales/block/CoffinBlock.java @@ -23,7 +23,9 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityEvent; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeInstance; @@ -36,7 +38,9 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.Spawner; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -89,14 +93,14 @@ public static Direction getCoffinOrientation(@NotNull BlockGetter level, BlockPo } @Override - protected @NotNull BlockState updateShape(@NotNull BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) { + protected @NotNull BlockState updateShape(@NotNull BlockState state, LevelReader level, ScheduledTickAccess tickAccess, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { if (direction == getNeighbourDirection(state.getValue(PART), state.getValue(FACING))) { boolean isThisFoot = state.getValue(PART) == CoffinPart.FOOT; return neighborState.is(this) && neighborState.getValue(PART) != state.getValue(PART) ? isThisFoot ? state : state.setValue(STATE, neighborState.getValue(STATE)) : Blocks.AIR.defaultBlockState(); } else { - return super.updateShape(state, direction, neighborState, level, pos, neighborPos); + return super.updateShape(state, level, tickAccess, pos, direction, neighborPos, neighborState, random); } } @@ -236,7 +240,7 @@ public void appendHoverText(ItemStack stack, Item.TooltipContext tooltipContext, Spawner.appendHoverText(stack, tooltip, "SpawnData"); } - public static void onCoffinUntrack(@Nullable Entity entity, @Nullable CoffinSpawner coffinSpawner, boolean remove) { + public static void onCoffinUntrack(ServerLevel level, @Nullable Entity entity, @Nullable CoffinSpawner coffinSpawner, boolean remove) { if (FrozenLibConfig.IS_DEBUG && entity != null && !entity.isRemoved() && entity.level() instanceof ServerLevel serverLevel) { FrozenNetworking.sendPacketToAllPlayers( serverLevel, @@ -259,9 +263,9 @@ public static void onCoffinUntrack(@Nullable Entity entity, @Nullable CoffinSpaw if (entity instanceof Apparition apparition && remove) { apparition.dropItem(); - apparition.level().broadcastEntityEvent(apparition, (byte)60); + apparition.level().broadcastEntityEvent(apparition, EntityEvent.POOF); apparition.discard(); - apparition.dropPreservedEquipment(); + apparition.dropPreservedEquipment(level); if (coffinSpawner != null) { coffinSpawner.onApparitionRemovedOrKilled(entity.level()); } diff --git a/src/main/java/net/frozenblock/trailiertales/block/DawntrailBlock.java b/src/main/java/net/frozenblock/trailiertales/block/DawntrailBlock.java index 1d6812cf..d982a7ee 100644 --- a/src/main/java/net/frozenblock/trailiertales/block/DawntrailBlock.java +++ b/src/main/java/net/frozenblock/trailiertales/block/DawntrailBlock.java @@ -20,6 +20,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.ScheduledTickAccess; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.BonemealableBlock; @@ -62,11 +63,11 @@ public static boolean canAttachTo(BlockGetter world, @NotNull Direction directio } @Override - protected @NotNull BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + protected @NotNull BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess tickAccess, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { if (!hasAnyFace(state)) { return Blocks.AIR.defaultBlockState(); } else { - return hasFace(state, direction) && !canAttachTo(world, direction, neighborPos, neighborState) ? removeFace(state, getFaceProperty(direction)) : state; + return hasFace(state, direction) && !canAttachTo(level, direction, neighborPos, neighborState) ? removeFace(state, getFaceProperty(direction)) : state; } } diff --git a/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/CoffinSpawner.java b/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/CoffinSpawner.java index 5c4cc3c9..9021bbb5 100644 --- a/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/CoffinSpawner.java +++ b/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/CoffinSpawner.java @@ -392,20 +392,20 @@ public boolean isAttemptingToSpawnMob(@NotNull ServerLevel level) { return isPreparing && !finishedSpawningMobs && canSpawnInLevel; } - public void tickServer(ServerLevel world, BlockPos pos, BlockState state, CoffinPart part, boolean ominous) { - if (part == CoffinPart.HEAD || world.isClientSide) { + public void tickServer(ServerLevel level, BlockPos pos, BlockState state, CoffinPart part, boolean ominous) { + if (part == CoffinPart.HEAD) { return; } - Direction coffinOrientation = CoffinBlock.getCoffinOrientation(world, pos); + Direction coffinOrientation = CoffinBlock.getCoffinOrientation(level, pos); if (coffinOrientation != null) { - this.getState().emitParticles(world, pos, coffinOrientation); + this.getState().emitParticles(level, pos, coffinOrientation); if (!this.data.soulsToSpawn.isEmpty()) { IntArrayList newList = new IntArrayList(); this.data.soulsToSpawn.forEach(spawnTime -> { if (spawnTime <= 0) { - CoffinBlock.spawnParticlesFrom(world, TTParticleTypes.COFFIN_SOUL_ENTER, 4, 0D, coffinOrientation, pos, 0.35D); - this.addPower(1, world); + CoffinBlock.spawnParticlesFrom(level, TTParticleTypes.COFFIN_SOUL_ENTER, 4, 0D, coffinOrientation, pos, 0.35D); + this.addPower(1, level); } else { newList.add(spawnTime - 1); } @@ -416,35 +416,35 @@ public void tickServer(ServerLevel world, BlockPos pos, BlockState state, Coffin } this.data.currentMobs.removeIf(uiid -> { - Entity entity = world.getEntity(uiid); - boolean shouldUntrack = shouldMobBeUntracked(world, pos, entity); + Entity entity = level.getEntity(uiid); + boolean shouldUntrack = shouldMobBeUntracked(level, pos, entity); if (shouldUntrack) { - CoffinBlock.onCoffinUntrack(entity, this, false); + CoffinBlock.onCoffinUntrack(level, entity, this, false); } return shouldUntrack; }); this.data.currentApparitions.removeIf(uiid -> { - Entity entity = world.getEntity(uiid); - boolean shouldUntrack = shouldMobBeUntracked(world, pos, entity); + Entity entity = level.getEntity(uiid); + boolean shouldUntrack = shouldMobBeUntracked(level, pos, entity); if (shouldUntrack) { - CoffinBlock.onCoffinUntrack(entity, this, true); + CoffinBlock.onCoffinUntrack(level, entity, this, true); } return shouldUntrack; }); CoffinSpawnerState currentState = this.getState(); - if (!this.canSpawnInLevel(world)) { + if (!this.canSpawnInLevel(level)) { if (currentState.isCapableOfSpawning()) { - this.setState(world, CoffinSpawnerState.INACTIVE); + this.setState(level, CoffinSpawnerState.INACTIVE); } } else { - CoffinSpawnerState nextState = currentState.tickAndGetNext(pos, this, state, world); + CoffinSpawnerState nextState = currentState.tickAndGetNext(pos, this, state, level); if (nextState != currentState) { - this.setState(world, nextState); + this.setState(level, nextState); } } - this.updateAttemptingToSpawn(world); + this.updateAttemptingToSpawn(level); } private static boolean shouldMobBeUntracked(@NotNull ServerLevel level, BlockPos pos, UUID uuid) { diff --git a/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/impl/EntityCoffinData.java b/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/impl/EntityCoffinData.java index 0d49b943..171db547 100644 --- a/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/impl/EntityCoffinData.java +++ b/src/main/java/net/frozenblock/trailiertales/block/entity/coffin/impl/EntityCoffinData.java @@ -45,7 +45,7 @@ public void tick(LivingEntity entity, @NotNull Level level) { boolean canUntrackFromTime = (gameTime - this.lastInteractionAt) > 1800 && !(entity instanceof Apparition); Optional optionalCoffinSpawner = this.getSpawner(level); if (optionalCoffinSpawner.isEmpty() || canUntrackFromTime) { - CoffinBlock.onCoffinUntrack(entity, null, true); + CoffinBlock.onCoffinUntrack(serverLevel, entity, null, true); } else { if (FrozenLibConfig.IS_DEBUG) { FrozenNetworking.sendPacketToAllPlayers( diff --git a/src/main/java/net/frozenblock/trailiertales/datagen/loot/TTEntityLootProvider.java b/src/main/java/net/frozenblock/trailiertales/datagen/loot/TTEntityLootProvider.java index 495c55d9..aec3ae86 100644 --- a/src/main/java/net/frozenblock/trailiertales/datagen/loot/TTEntityLootProvider.java +++ b/src/main/java/net/frozenblock/trailiertales/datagen/loot/TTEntityLootProvider.java @@ -31,7 +31,7 @@ public void generate(@NotNull BiConsumer, LootTable.Build HolderLookup.Provider registryLookup = this.registries.join(); output.accept( - TTEntityTypes.APPARITION.getDefaultLootTable(), + TTEntityTypes.APPARITION.getDefaultLootTable().orElseThrow(), LootTable.lootTable() .withPool( LootPool.lootPool() diff --git a/src/main/java/net/frozenblock/trailiertales/effect/TransfiguringMobEffect.java b/src/main/java/net/frozenblock/trailiertales/effect/TransfiguringMobEffect.java index 598666b3..71a35b64 100644 --- a/src/main/java/net/frozenblock/trailiertales/effect/TransfiguringMobEffect.java +++ b/src/main/java/net/frozenblock/trailiertales/effect/TransfiguringMobEffect.java @@ -9,11 +9,13 @@ import net.frozenblock.trailiertales.registry.TTParticleTypes; import net.frozenblock.trailiertales.registry.TTSounds; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectCategory; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.GameRules; @@ -54,24 +56,23 @@ public void onEffectAdded(LivingEntity entity, int amplifier) { } @Override - public void onMobRemoved(LivingEntity entity, int amplifier, Entity.RemovalReason reason) { + public void onMobRemoved(ServerLevel level, LivingEntity entity, int amplifier, Entity.RemovalReason reason) { if (reason == Entity.RemovalReason.KILLED && entity.getType() != SPAWNED_ENTITY_TYPE) { - Level level = entity.level(); int j = level.getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING); int k = numberOfApparitionsToSpawn(j, NearbyApparitions.closeTo(entity)); for (int l = 0; l < k; l++) { - this.spawnApparitionOffspring(entity.level(), entity.getX(), entity.getY() + 0.5D, entity.getZ()); + this.spawnApparitionOffspring(level, entity.getX(), entity.getY() + 0.5D, entity.getZ()); } } } - private void spawnApparitionOffspring(Level world, double x, double y, double z) { - Apparition apparition = SPAWNED_ENTITY_TYPE.create(world); + private void spawnApparitionOffspring(ServerLevel level, double x, double y, double z) { + Apparition apparition = SPAWNED_ENTITY_TYPE.create(level, EntitySpawnReason.BREEDING); if (apparition != null) { - apparition.moveTo(x, y, z, world.getRandom().nextFloat() * 360F, 0F); - ApparitionAi.rememberHome(apparition, world, BlockPos.containing(x, y, z)); - world.addFreshEntity(apparition); + apparition.moveTo(x, y, z, level.getRandom().nextFloat() * 360F, 0F); + ApparitionAi.rememberHome(apparition, level, BlockPos.containing(x, y, z)); + level.addFreshEntity(apparition); } } diff --git a/src/main/java/net/frozenblock/trailiertales/entity/Apparition.java b/src/main/java/net/frozenblock/trailiertales/entity/Apparition.java index 75fb86c5..42846c3e 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/Apparition.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/Apparition.java @@ -27,6 +27,8 @@ import net.minecraft.tags.DamageTypeTags; import net.minecraft.util.Mth; import net.minecraft.util.Unit; +import net.minecraft.util.profiling.Profiler; +import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.Difficulty; import net.minecraft.world.DifficultyInstance; import net.minecraft.world.SimpleContainer; @@ -152,8 +154,8 @@ public void recreateFromPacket(ClientboundAddEntityPacket packet) { } @Override - public boolean isInvulnerableTo(DamageSource damageSource) { - return super.isInvulnerableTo(damageSource) || this.isHiding(); + public boolean isInvulnerableTo(ServerLevel level, DamageSource damageSource) { + return super.isInvulnerableTo(level, damageSource) || this.isHiding(); } @Override @@ -284,26 +286,26 @@ private boolean isOnPickupCooldown() { return this.getBrain().checkMemory(MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS, MemoryStatus.VALUE_PRESENT); } - public boolean wantsToPickUp(@NotNull ItemEntity itemEntity) { - return this.wantsToPickUp(itemEntity.getItem()) && this.getTarget() != null; + public boolean wantsToPickUp(ServerLevel level, @NotNull ItemEntity item) { + return this.wantsToPickUp(level, item.getItem()) && this.getTarget() != null; } @Override - public boolean wantsToPickUp(ItemStack stack) { + public boolean wantsToPickUp(ServerLevel level, ItemStack stack) { return this.inventory.getItems().getFirst().isEmpty(); } @Override - protected void pickUpItem(@NotNull ItemEntity item) { + protected void pickUpItem(ServerLevel level, ItemEntity item) { ItemEntity newItemEntity = new ItemEntity(this.level(), item.getX(), item.getY(), item.getZ(), item.getItem().split(1)); this.level().addFreshEntity(newItemEntity); - InventoryCarrier.pickUpItem(this, this, newItemEntity); + InventoryCarrier.pickUpItem(level, this, this, newItemEntity); } @Override - protected void dropEquipment() { - super.dropEquipment(); - this.inventory.removeAllItems().forEach(this::spawnAtLocation); + protected void dropEquipment(ServerLevel level) { + super.dropEquipment(level); + this.inventory.removeAllItems().forEach(it -> this.spawnAtLocation(level, it)); } public float getInnerTransparency() { @@ -435,7 +437,7 @@ public boolean canBeHitByProjectile() { } @Override - public boolean hurt(@NotNull DamageSource source, float amount) { + public boolean hurtServer(ServerLevel level, DamageSource source, float amount) { if (source.is(DamageTypeTags.IS_PROJECTILE)) { if (source.getDirectEntity() instanceof Projectile projectile) { if (projectile instanceof AbstractArrow abstractArrow) { @@ -449,14 +451,9 @@ public boolean hurt(@NotNull DamageSource source, float amount) { } } } - boolean bl = super.hurt(source, amount); - if (this.level().isClientSide) { - return false; - } - if (bl) { - if (source.getEntity() instanceof LivingEntity livingEntity) { - ApparitionAi.wasHurtBy(this, livingEntity); - } + boolean bl = super.hurtServer(level, source, amount); + if (bl && source.getEntity() instanceof LivingEntity livingEntity) { + ApparitionAi.wasHurtBy(level, this, livingEntity); } return bl; } @@ -602,14 +599,15 @@ public Brain getBrain() { } @Override - protected void customServerAiStep() { - this.level().getProfiler().push("apparitionBrain"); - this.getBrain().tick((ServerLevel) this.level(), this); - this.level().getProfiler().pop(); - this.level().getProfiler().push("apparitionActivityUpdate"); + protected void customServerAiStep(ServerLevel level) { + ProfilerFiller profiler = Profiler.get(); + profiler.push("apparitionBrain"); + this.getBrain().tick(level, this); + profiler.pop(); + profiler.push("apparitionActivityUpdate"); ApparitionAi.updateActivity(this); - this.level().getProfiler().pop(); - super.customServerAiStep(); + profiler.pop(); + super.customServerAiStep(level); } @Override @@ -619,7 +617,7 @@ protected void sendDebugPackets() { } @Contract("null->false") - public boolean canTargetEntity(@Nullable Entity entity) { + public boolean canTargetEntity(@Nullable Entity entity, ServerLevel level) { return entity instanceof LivingEntity livingEntity && this.level() == livingEntity.level() && !this.level().getDifficulty().equals(Difficulty.PEACEFUL) @@ -665,9 +663,7 @@ public void performRangedAttack(LivingEntity target, float pullProgress) { if (singleItem.getItem() instanceof ProjectileItem projectileItem) { projectile = projectileItem.asProjectile(this.level(), this.getEyePosition(), singleItem, this.getDirection()); } else { - ThrownItemProjectile thrownItem = new ThrownItemProjectile(this.level(), this); - thrownItem.setItem(singleItem); - projectile = thrownItem; + projectile = new ThrownItemProjectile(this.level(), this, singleItem); } projectile.setOwner(this); diff --git a/src/main/java/net/frozenblock/trailiertales/entity/ThrownItemProjectile.java b/src/main/java/net/frozenblock/trailiertales/entity/ThrownItemProjectile.java index 097b2c78..0038c867 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/ThrownItemProjectile.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/ThrownItemProjectile.java @@ -13,6 +13,7 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; @@ -25,12 +26,12 @@ public ThrownItemProjectile(@NotNull EntityType super(entityType, level); } - public ThrownItemProjectile(@NotNull Level level, @NotNull LivingEntity shooter) { - super(TTEntityTypes.THROWN_ITEM_PROJECTILE, shooter, level); + public ThrownItemProjectile(@NotNull Level level, LivingEntity shooter, ItemStack stack) { + super(TTEntityTypes.THROWN_ITEM_PROJECTILE, shooter, level, stack); } - public ThrownItemProjectile(@NotNull Level level, double x, double y, double z) { - super(TTEntityTypes.THROWN_ITEM_PROJECTILE, x, y, z, level); + public ThrownItemProjectile(double x, double y, double z, Level level, @NotNull ItemStack stack) { + super(TTEntityTypes.THROWN_ITEM_PROJECTILE, x, y, z, level, stack); } @Override diff --git a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAi.java b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAi.java index ff514b65..966dc39c 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAi.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAi.java @@ -10,6 +10,7 @@ import net.frozenblock.trailiertales.registry.TTSensorTypes; import net.minecraft.core.BlockPos; import net.minecraft.core.GlobalPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.Brain; @@ -110,7 +111,7 @@ private static void initIdleActivity(@NotNull Brain brain) { Activity.IDLE, 10, ImmutableList.of( - StartAttacking.create(apparition -> true, ApparitionAi::findNearestValidAttackTarget), + StartAttacking.create((level, apparition) -> true, ApparitionAi::findNearestValidAttackTarget), StayCloseToTarget.create(ApparitionAi::getLookTarget, entity -> true, 7, 16, 1F), new RunOne<>( // idle look ImmutableList.of( @@ -134,7 +135,7 @@ private static void initFightActivity(Apparition apparition, @NotNull Brain !apparition.canTargetEntity(entity), ApparitionAi::onTargetInvalid, true), + StopAttackingIfTargetInvalid.create((level, entity) -> !apparition.canTargetEntity(entity, level), ApparitionAi::onTargetInvalid, true), new RunOne<>( ImmutableList.of( Pair.of(SetWalkTargetFromAttackTargetIfTargetOutOfReach.create(1F), 1), @@ -194,7 +195,7 @@ private static BlockPos randomPosAround(@NotNull BlockPos pos, @NotNull Level le return pos.offset(level.random.nextIntBetweenInclusive(-7, 7), level.random.nextIntBetweenInclusive(-7, 7), level.random.nextIntBetweenInclusive(-7, 7)); } - private static void onTargetInvalid(@NotNull Apparition apparition, @NotNull LivingEntity target) { + private static void onTargetInvalid(ServerLevel level, @NotNull Apparition apparition, @NotNull LivingEntity target) { if (apparition.getTarget() == target) { apparition.getBrain().eraseMemory(MemoryModuleType.ATTACK_TARGET); } @@ -205,7 +206,7 @@ public static void updateActivity(@NotNull Apparition apparition) { } @NotNull - private static Optional findNearestValidAttackTarget(@NotNull Apparition apparition) { + private static Optional findNearestValidAttackTarget(ServerLevel level, @NotNull Apparition apparition) { Brain brain = apparition.getBrain(); if (brain.hasMemoryValue(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER)) { return brain.getMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER); @@ -214,21 +215,21 @@ private static Optional findNearestValidAttackTarget(@No } } - public static void wasHurtBy(@NotNull Apparition apparition, LivingEntity target) { - if (apparition.canTargetEntity(target)) { - if (!Sensor.isEntityAttackableIgnoringLineOfSight(apparition, target)) { + public static void wasHurtBy(ServerLevel level, @NotNull Apparition apparition, LivingEntity target) { + if (apparition.canTargetEntity(target, level)) { + if (!Sensor.isEntityAttackableIgnoringLineOfSight(level, apparition, target)) { return; } if (BehaviorUtils.isOtherTargetMuchFurtherAwayThanCurrentAttackTarget(apparition, target, 4D)) { return; } - setAngerTarget(apparition, target); + setAngerTarget(level, apparition, target); } } - public static void setAngerTarget(@NotNull Apparition apparition, LivingEntity target) { - if (!Sensor.isEntityAttackableIgnoringLineOfSight(apparition, target)) { + public static void setAngerTarget(ServerLevel level, @NotNull Apparition apparition, LivingEntity target) { + if (!Sensor.isEntityAttackableIgnoringLineOfSight(level, apparition, target)) { return; } apparition.getBrain().eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); diff --git a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAttackablesSensor.java b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAttackablesSensor.java index 62ae7cca..9eb94bfd 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAttackablesSensor.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionAttackablesSensor.java @@ -15,10 +15,10 @@ public class ApparitionAttackablesSensor extends NearestVisibleLivingEntitySensor { @Override - protected boolean isMatchingEntity(LivingEntity entity, LivingEntity target) { + protected boolean isMatchingEntity(ServerLevel level, LivingEntity entity, LivingEntity target) { return this.isClose(entity, target) && this.isHostileTarget(target) - && Sensor.isEntityAttackableIgnoringLineOfSight(entity, target); + && Sensor.isEntityAttackableIgnoringLineOfSight(level, entity, target); } private boolean isHostileTarget(@NotNull LivingEntity entity) { @@ -30,13 +30,13 @@ private boolean isClose(LivingEntity apparition, @NotNull LivingEntity target) { } @Override - protected void doTick(ServerLevel world, @NotNull LivingEntity entity) { - entity.getBrain().setMemory(this.getMemory(), this.getNearestEntityNoLineOfSight(entity)); + protected void doTick(ServerLevel level, @NotNull LivingEntity entity) { + entity.getBrain().setMemory(this.getMemory(), this.getNearestEntityNoLineOfSight(level, entity)); } - private Optional getNearestEntityNoLineOfSight(@NotNull LivingEntity entity) { + private Optional getNearestEntityNoLineOfSight(ServerLevel level, @NotNull LivingEntity entity) { return entity.getBrain().getMemory(MemoryModuleType.NEAREST_PLAYERS) - .flatMap(livingEntities -> this.findClosest(livingEntities, livingEntity -> this.isMatchingEntity(entity, livingEntity))); + .flatMap(livingEntities -> this.findClosest(livingEntities, livingEntity -> this.isMatchingEntity(level, entity, livingEntity))); } private Optional findClosest(@NotNull List livingEntities, Predicate predicate) { diff --git a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionNearestItemSensor.java b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionNearestItemSensor.java index fc59acaa..b74ec84b 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionNearestItemSensor.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionNearestItemSensor.java @@ -23,12 +23,12 @@ public class ApparitionNearestItemSensor extends Sensor { } @Override - protected void doTick(@NotNull ServerLevel world, @NotNull Apparition apparition) { + protected void doTick(@NotNull ServerLevel level, @NotNull Apparition apparition) { Brain brain = apparition.getBrain(); - List list = world.getEntitiesOfClass(ItemEntity.class, apparition.getBoundingBox().inflate(RADIUS, Y_RANGE, RADIUS), itemEntity -> true); + List list = level.getEntitiesOfClass(ItemEntity.class, apparition.getBoundingBox().inflate(RADIUS, Y_RANGE, RADIUS), itemEntity -> true); list.sort(Comparator.comparingDouble(apparition::distanceToSqr)); Optional optional = list.stream() - .filter(apparition::wantsToPickUp) + .filter(item -> apparition.wantsToPickUp(level, item)) .filter(itemEntity -> itemEntity.closerThan(apparition, RADIUS)) .findFirst(); brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, optional); diff --git a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionPlayerSensor.java b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionPlayerSensor.java index 824277c4..870c3af9 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionPlayerSensor.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/ai/apparition/ApparitionPlayerSensor.java @@ -36,9 +36,9 @@ public class ApparitionPlayerSensor extends Sensor { } @Override - protected void doTick(@NotNull ServerLevel world, @NotNull Apparition apparition) { + protected void doTick(@NotNull ServerLevel level, @NotNull Apparition apparition) { double range = apparition.getAttributeValue(Attributes.FOLLOW_RANGE); - List list = world.players() + List list = level.players() .stream() .filter(EntitySelector.NO_SPECTATORS) .filter(player -> apparition.closerThan(player, range)) @@ -47,21 +47,21 @@ protected void doTick(@NotNull ServerLevel world, @NotNull Apparition apparition Brain brain = apparition.getBrain(); brain.setMemory(MemoryModuleType.NEAREST_PLAYERS, list); - List list2 = list.stream().filter(player -> isEntityTargetable(apparition, player, range)).toList(); + List list2 = list.stream().filter(player -> isEntityTargetable(level, apparition, player, range)).toList(); brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_PLAYER, list2.isEmpty() ? null : list2.getFirst()); - Optional optional = list2.stream().filter(player -> isEntityAttackable(apparition, player, range)).findFirst(); + Optional optional = list2.stream().filter(player -> isEntityAttackable(level, apparition, player, range)).findFirst(); brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, optional); } - public static boolean isEntityTargetable(@NotNull LivingEntity entity, LivingEntity target, double range) { + public static boolean isEntityTargetable(ServerLevel level, @NotNull LivingEntity entity, LivingEntity target, double range) { return entity.getBrain().isMemoryValue(MemoryModuleType.ATTACK_TARGET, target) - ? TARGET_CONDITIONS_IGNORE_INVISIBILITY_TESTING.range(range).test(entity, target) - : TARGET_CONDITIONS.range(range).test(entity, target); + ? TARGET_CONDITIONS_IGNORE_INVISIBILITY_TESTING.range(range).test(level, entity, target) + : TARGET_CONDITIONS.range(range).test(level, entity, target); } - public static boolean isEntityAttackable(@NotNull LivingEntity entity, LivingEntity target, double range) { + public static boolean isEntityAttackable(ServerLevel level, @NotNull LivingEntity entity, LivingEntity target, double range) { return entity.getBrain().isMemoryValue(MemoryModuleType.ATTACK_TARGET, target) - ? ATTACK_TARGET_CONDITIONS_IGNORE_INVISIBILITY.range(range).test(entity, target) - : ATTACK_TARGET_CONDITIONS.range(range).test(entity, target); + ? ATTACK_TARGET_CONDITIONS_IGNORE_INVISIBILITY.range(range).test(level, entity, target) + : ATTACK_TARGET_CONDITIONS.range(range).test(level, entity, target); } } diff --git a/src/main/java/net/frozenblock/trailiertales/entity/render/layer/ApparitionOverlayLayer.java b/src/main/java/net/frozenblock/trailiertales/entity/render/layer/ApparitionOverlayLayer.java index a10884a8..7121e7e8 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/render/layer/ApparitionOverlayLayer.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/render/layer/ApparitionOverlayLayer.java @@ -6,6 +6,7 @@ import net.frozenblock.trailiertales.TrailierTalesClient; import net.frozenblock.trailiertales.entity.Apparition; import net.frozenblock.trailiertales.entity.render.model.ApparitionModel; +import net.frozenblock.trailiertales.entity.render.renderer.state.ApparitionRenderState; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; @@ -15,7 +16,7 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; -public class ApparitionOverlayLayer extends RenderLayer> { +public class ApparitionOverlayLayer extends RenderLayer> { private final RenderType renderType; private final ApparitionModel model; @@ -46,21 +47,17 @@ public void render( PoseStack matrices, @NotNull MultiBufferSource vertexConsumers, int light, - T entity, - float limbAngle, - float limbDistance, - float tickDelta, - float animationProgress, - float headYaw, - float headPitch + T renderState, + float partialTick, + float color ) { - this.model.prepareMobModel(entity, limbAngle, limbDistance, tickDelta); - this.model.setupAnim(entity, limbAngle, limbDistance, animationProgress, headYaw, headPitch); + this.model.prepareMobModel(renderState, renderState.walkAnimationPos, renderState.walkAnimationSpeed, partialTick); + this.model.setupAnim(renderState); VertexConsumer vertexConsumer = vertexConsumers.getBuffer(this.renderType); - this.model.renderToBuffer(matrices, vertexConsumer, 15728640, this.getOverlay(entity, 0F)); + this.model.renderToBuffer(matrices, vertexConsumer, 15728640, this.getOverlay(renderState, 0F)); } - private int getOverlay(@NotNull T entity, float whiteOverlayProgress) { - return OverlayTexture.pack(OverlayTexture.u(whiteOverlayProgress), OverlayTexture.v(entity.hurtTime > 0 || entity.deathTime > 0)); + private int getOverlay(@NotNull T renderState, float whiteOverlayProgress) { + return OverlayTexture.pack(OverlayTexture.u(whiteOverlayProgress), OverlayTexture.v(renderState.hurtTime > 0 || renderState.deathTime > 0)); } } diff --git a/src/main/java/net/frozenblock/trailiertales/entity/render/model/ApparitionModel.java b/src/main/java/net/frozenblock/trailiertales/entity/render/model/ApparitionModel.java index b933de01..e7fd15e7 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/render/model/ApparitionModel.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/render/model/ApparitionModel.java @@ -10,8 +10,8 @@ import net.frozenblock.lib.entity.api.rendering.FrozenRenderType; import net.frozenblock.lib.entity.impl.client.rendering.ModelPartInvertInterface; import net.frozenblock.trailiertales.entity.Apparition; +import net.frozenblock.trailiertales.entity.render.renderer.state.ApparitionRenderState; import net.minecraft.client.model.EntityModel; -import net.minecraft.client.model.HierarchicalModel; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.builders.CubeListBuilder; @@ -24,7 +24,7 @@ import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) -public class ApparitionModel extends HierarchicalModel { +public class ApparitionModel extends EntityModel { private final ModelPart root; public final ModelPart core; public final ModelPart inner; @@ -135,13 +135,13 @@ public void setupAnim(T entity, float limbAngle, float limbDistance, float anima } @Override - public void prepareMobModel(@NotNull T entity, float limbAngle, float limbDistance, float tickDelta) { - this.innerTransparency = this.innerAlphaFunction.apply(entity, tickDelta); - this.outlineTransparency = this.outlineAlphaFunction.apply(entity, tickDelta); - this.outerTransparency = this.outerAlphaFunction.apply(entity, tickDelta); - this.flicker = entity.getFlicker(tickDelta); - this.outer.yRot = entity.getItemYRot(tickDelta); - this.outer.zRot = entity.getItemZRot(tickDelta); + public void prepareMobModel(@NotNull T renderState, float limbAngle, float limbDistance, float tickDelta) { + this.innerTransparency = this.innerAlphaFunction.apply(renderState, tickDelta); + this.outlineTransparency = this.outlineAlphaFunction.apply(renderState, tickDelta); + this.outerTransparency = this.outerAlphaFunction.apply(renderState, tickDelta); + this.flicker = renderState.getFlicker(tickDelta); + this.outer.yRot = renderState.getItemYRot(tickDelta); + this.outer.zRot = renderState.getItemZRot(tickDelta); } @Override @@ -176,12 +176,12 @@ private void resetDrawForAllParts() { @Environment(EnvType.CLIENT) - public interface AlphaFunction { + public interface AlphaFunction { float apply(T apparition, float tickDelta); } @Environment(EnvType.CLIENT) - public interface DrawSelector> { + public interface DrawSelector> { List getPartsToDraw(M entityModel); } } diff --git a/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/ApparitionRenderer.java b/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/ApparitionRenderer.java index b204e598..c4a97995 100644 --- a/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/ApparitionRenderer.java +++ b/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/ApparitionRenderer.java @@ -9,6 +9,7 @@ import net.frozenblock.trailiertales.entity.Apparition; import net.frozenblock.trailiertales.entity.render.layer.ApparitionOverlayLayer; import net.frozenblock.trailiertales.entity.render.model.ApparitionModel; +import net.frozenblock.trailiertales.entity.render.renderer.state.ApparitionRenderState; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.ItemRenderer; @@ -21,7 +22,7 @@ import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) -public class ApparitionRenderer extends MobRenderer> { +public class ApparitionRenderer extends MobRenderer> { private final ItemRenderer itemRenderer; private float itemYaw; diff --git a/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/state/ApparitionRenderState.java b/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/state/ApparitionRenderState.java new file mode 100644 index 00000000..1125a260 --- /dev/null +++ b/src/main/java/net/frozenblock/trailiertales/entity/render/renderer/state/ApparitionRenderState.java @@ -0,0 +1,15 @@ +package net.frozenblock.trailiertales.entity.render.renderer.state; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; + +@Environment(EnvType.CLIENT) +public class ApparitionRenderState extends LivingEntityRenderState { + + public int hurtTime; + public float itemYRot; + public float itemZRot; + public float totalTransparency; + public float flicker; +} diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/client/brush/ItemInHandLayerMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/client/brush/ItemInHandLayerMixin.java index 12e31d00..dee58b0f 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/client/brush/ItemInHandLayerMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/client/brush/ItemInHandLayerMixin.java @@ -7,14 +7,19 @@ import net.fabricmc.api.Environment; import net.frozenblock.trailiertales.config.TTItemConfig; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ArmedModel; +import net.minecraft.client.model.EntityModel; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; +import net.minecraft.client.resources.model.BakedModel; import net.minecraft.util.Mth; import net.minecraft.world.entity.HumanoidArm; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -22,7 +27,7 @@ @Environment(EnvType.CLIENT) @Mixin(ItemInHandLayer.class) -public class ItemInHandLayerMixin{ +public class ItemInHandLayerMixin & ArmedModel> { @Inject( method = "renderArmWithItem", @@ -33,7 +38,8 @@ public class ItemInHandLayerMixin{ ) ) void trailierTales$injectBrushAnim( - LivingEntity livingEntity, + S livingEntity, + @Nullable BakedModel bakedModel, ItemStack itemStack, ItemDisplayContext displayContext, HumanoidArm arm, @@ -45,7 +51,7 @@ public class ItemInHandLayerMixin{ ) { if (itemStack.is(Items.BRUSH) && livingEntity.getUseItem() == itemStack && livingEntity.swingTime == 0 && TTItemConfig.SMOOTH_BRUSH_ANIMATION) { float remainingTicks = livingEntity.getUseItemRemainingTicks() + 1F; - float partialTick = Minecraft.getInstance().getTimer().getGameTimeDeltaTicks() - Minecraft.getInstance().getTimer().getGameTimeDeltaPartialTick(false); + float partialTick = Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaTicks() - Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaPartialTick(false); float brushProgress = remainingTicks + partialTick; float brushRoll = Mth.cos( (brushProgress * Mth.PI) diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/client/haunt/GuiMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/client/haunt/GuiMixin.java index 33387056..c675bced 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/client/haunt/GuiMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/client/haunt/GuiMixin.java @@ -14,6 +14,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; @@ -27,6 +28,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.function.Function; @Environment(EnvType.CLIENT) @Mixin(Gui.class) @@ -229,18 +231,18 @@ public class GuiMixin { method = "renderFood", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V" + target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V" ), slice = @Slice( from = @At( value = "INVOKE", - target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", + target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 0, shift = At.Shift.AFTER ) ) ) - private boolean trailierTales$removeExtraHunger(GuiGraphics instance, ResourceLocation texture, int x, int y, int width, int height) { + private boolean trailierTales$removeExtraHunger(GuiGraphics instance, Function renderType, ResourceLocation texture, int x, int y, int width, int height) { return !trailierTales$isHaunted; } @@ -272,14 +274,14 @@ public class GuiMixin { method = "renderFood", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", + target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 0 ) ) - private void trailierTales$hauntedHunger(GuiGraphics instance, ResourceLocation texture, int x, int y, int width, int height, Operation original) { - original.call(instance, texture, x, y, width, height); + private void trailierTales$hauntedHunger(GuiGraphics instance, Function renderType, ResourceLocation texture, int x, int y, int width, int height, Operation original) { + original.call(instance, renderType, texture, x, y, width, height); if (trailierTales$isHaunted) { - original.call(instance, TRAILIER_TALES$FOOD_HAUNT, x, y, width, height); + original.call(instance, renderType, TRAILIER_TALES$FOOD_HAUNT, x, y, width, height); } } @@ -321,7 +323,7 @@ public class GuiMixin { method = "renderPlayerHealth", at = @At( value = "INVOKE", - target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V" + target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Ljava/util/function/Function;Lnet/minecraft/resources/ResourceLocation;IIII)V" ), slice = @Slice( from = @At( @@ -330,9 +332,9 @@ public class GuiMixin { ) ) ) - private void trailierTales$hauntedAirSupply(GuiGraphics instance, ResourceLocation texture, int x, int y, int width, int height, Operation original) { + private void trailierTales$hauntedAirSupply(GuiGraphics instance, Function renderType, ResourceLocation texture, int x, int y, int width, int height, Operation original) { texture = trailierTales$isHaunted ? TRAILIER_TALES$AIR_HAUNT : texture; - original.call(instance, texture, x, y, width, height); + original.call(instance, renderType, texture, x, y, width, height); } @Unique @@ -343,7 +345,7 @@ public class GuiMixin { @Unique private void trailierTales$renderHauntedHeart(@NotNull GuiGraphics graphics, int x, int y) { RenderSystem.enableBlend(); - graphics.blitSprite(TRAILIER_TALES$HEART_HAUNT, x, y, 9, 9); + graphics.blitSprite(RenderType::guiTextured, TRAILIER_TALES$HEART_HAUNT, x, y, 9, 9); RenderSystem.disableBlend(); } } diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/BoatMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/BoatMixin.java index bc889c7c..82602397 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/BoatMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/BoatMixin.java @@ -111,13 +111,13 @@ public BoatMixin(EntityType entityType, Level world) { this.trailierTales$setBanner(itemStack.split(1)); this.gameEvent(GameEvent.ENTITY_INTERACT, player); } - info.setReturnValue(InteractionResult.sidedSuccess(this.level().isClientSide)); + info.setReturnValue(InteractionResult.SUCCESS); } } else { this.spawnAtLocation(this.trailierTales$getBanner(), 0.6F); this.trailierTales$setBanner(ItemStack.EMPTY); this.gameEvent(GameEvent.ENTITY_INTERACT, player); - info.setReturnValue(InteractionResult.sidedSuccess(this.level().isClientSide)); + info.setReturnValue(InteractionResult.SUCCESS); } } } diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/VehicleEntityMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/VehicleEntityMixin.java index f51fedf7..5a87fac5 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/VehicleEntityMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/common/boat/VehicleEntityMixin.java @@ -1,6 +1,7 @@ package net.frozenblock.trailiertales.mixin.common.boat; import net.frozenblock.trailiertales.impl.BoatBannerInterface; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -20,13 +21,13 @@ public VehicleEntityMixin(EntityType variant, Level world) { super(variant, world); } - @Inject(method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At("HEAD")) - public void trailierTales$destroy(DamageSource damageSource, CallbackInfo info) { + @Inject(method = "destroy(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At("HEAD")) + public void trailierTales$destroy(ServerLevel level, DamageSource damageSource, CallbackInfo info) { if (VehicleEntity.class.cast(this) instanceof BoatBannerInterface bannerInterface) { - if (this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { + if (level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { ItemStack itemStack = bannerInterface.trailierTales$getBanner(); bannerInterface.trailierTales$setBanner(ItemStack.EMPTY); - this.spawnAtLocation(itemStack); + this.spawnAtLocation(level, itemStack); } } } diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/common/brushable_block/FallingBlockEntityItemMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/common/brushable_block/FallingBlockEntityItemMixin.java index 35f94b67..5d0c9ddd 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/common/brushable_block/FallingBlockEntityItemMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/common/brushable_block/FallingBlockEntityItemMixin.java @@ -1,8 +1,10 @@ package net.frozenblock.trailiertales.mixin.common.brushable_block; +import com.llamalad7.mixinextras.sugar.Local; import net.frozenblock.trailiertales.impl.FallingBlockEntityInterface; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; @@ -40,18 +42,18 @@ public class FallingBlockEntityItemMixin implements FallingBlockEntityInterface method = "tick", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;spawnAtLocation(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" ) ) - public void trailierTales$dropItem(CallbackInfo info) { - FallingBlockEntity.class.cast(this).spawnAtLocation(this.trailierTales$itemStack); + public void trailierTales$dropItem(CallbackInfo info, @Local ServerLevel level) { + FallingBlockEntity.class.cast(this).spawnAtLocation(level, this.trailierTales$itemStack); } @Inject(method = "callOnBrokenAfterFall", at = @At("HEAD")) public void trailierTales$spawnCustomItemAfterBroken(Block block, BlockPos pos, CallbackInfo info) { FallingBlockEntity fallingBlockEntity = FallingBlockEntity.class.cast(this); - if (!fallingBlockEntity.level().isClientSide && this.trailierTales$itemStack != ItemStack.EMPTY) { - fallingBlockEntity.spawnAtLocation(this.trailierTales$itemStack.copy()); + if (fallingBlockEntity.level() instanceof ServerLevel level && this.trailierTales$itemStack != ItemStack.EMPTY) { + fallingBlockEntity.spawnAtLocation(level, this.trailierTales$itemStack.copy()); this.trailierTales$itemStack = ItemStack.EMPTY; } } diff --git a/src/main/java/net/frozenblock/trailiertales/mixin/common/coffin/EntityMixin.java b/src/main/java/net/frozenblock/trailiertales/mixin/common/coffin/EntityMixin.java index b02a3ec7..8b51f8bb 100644 --- a/src/main/java/net/frozenblock/trailiertales/mixin/common/coffin/EntityMixin.java +++ b/src/main/java/net/frozenblock/trailiertales/mixin/common/coffin/EntityMixin.java @@ -1,6 +1,8 @@ package net.frozenblock.trailiertales.mixin.common.coffin; +import com.llamalad7.mixinextras.sugar.Local; import net.frozenblock.trailiertales.block.CoffinBlock; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.portal.DimensionTransition; import org.spongepowered.asm.mixin.Mixin; @@ -11,9 +13,9 @@ @Mixin(Entity.class) public class EntityMixin { - @Inject(method = "changeDimension", at = @At(value = "HEAD")) - public void trailierTales$changeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable info) { - CoffinBlock.onCoffinUntrack(Entity.class.cast(this), null, true); + @Inject(method = "changeDimension", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/portal/DimensionTransition;newLevel()Lnet/minecraft/server/level/ServerLevel;")) + public void trailierTales$changeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable info, @Local ServerLevel level) { + CoffinBlock.onCoffinUntrack(level, Entity.class.cast(this), null, true); } } diff --git a/src/main/java/net/frozenblock/trailiertales/mod_compat/FrozenLibIntegration.java b/src/main/java/net/frozenblock/trailiertales/mod_compat/FrozenLibIntegration.java index 9991e0f8..84a86065 100644 --- a/src/main/java/net/frozenblock/trailiertales/mod_compat/FrozenLibIntegration.java +++ b/src/main/java/net/frozenblock/trailiertales/mod_compat/FrozenLibIntegration.java @@ -45,10 +45,13 @@ import net.minecraft.advancements.critereon.MobEffectsPredicate; import net.minecraft.core.Direction; import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.RotatedPillarBlock; @@ -341,12 +344,13 @@ public void init() { } AdvancementEvents.INIT.register((holder, registries) -> { + HolderLookup> entity = registries.lookupOrThrow(Registries.ENTITY_TYPE); Advancement advancement = holder.value(); if (TTMiscConfig.get().modify_advancements) { switch (holder.id().toString()) { case "minecraft:adventure/kill_a_mob" -> { AdvancementAPI.addCriteria(advancement, TTConstants.string("apparition"), CriteriaTriggers.PLAYER_KILLED_ENTITY.createCriterion( - KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().of(TTEntityTypes.APPARITION)).triggerInstance()) + KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().of(entity, TTEntityTypes.APPARITION)).triggerInstance()) ); AdvancementAPI.addRequirementsToList(advancement, List.of( @@ -356,7 +360,7 @@ public void init() { } case "minecraft:adventure/kill_all_mobs" -> { AdvancementAPI.addCriteria(advancement, TTConstants.string("apparition"), CriteriaTriggers.PLAYER_KILLED_ENTITY.createCriterion( - KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().of(TTEntityTypes.APPARITION)).triggerInstance()) + KilledTrigger.TriggerInstance.playerKilledEntity(EntityPredicate.Builder.entity().of(entity, TTEntityTypes.APPARITION)).triggerInstance()) ); AdvancementAPI.addRequirementsAsNewList(advancement, new AdvancementRequirements(List.of( diff --git a/src/main/java/net/frozenblock/trailiertales/registry/TTEntityTypes.java b/src/main/java/net/frozenblock/trailiertales/registry/TTEntityTypes.java index ed03dbd3..5bb7a2eb 100644 --- a/src/main/java/net/frozenblock/trailiertales/registry/TTEntityTypes.java +++ b/src/main/java/net/frozenblock/trailiertales/registry/TTEntityTypes.java @@ -7,6 +7,8 @@ import net.frozenblock.trailiertales.entity.ThrownItemProjectile; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; @@ -19,7 +21,7 @@ public final class TTEntityTypes { .sized(0.98F, 0.98F) .eyeHeight(0.98F * 0.5F) .requiredFeatures(TTFeatureFlags.FEATURE_FLAG) - .build(TTConstants.string("apparition")) + .build(ResourceKey.create(Registries.ENTITY_TYPE, TTConstants.id("apparition"))) ); public static final EntityType THROWN_ITEM_PROJECTILE = register( @@ -29,7 +31,7 @@ public final class TTEntityTypes { .clientTrackingRange(64) .updateInterval(10) .requiredFeatures(TTFeatureFlags.FEATURE_FLAG) - .build(TTConstants.string("thrown_item")) + .build(ResourceKey.create(Registries.ENTITY_TYPE, TTConstants.id("thrown_item"))) ); static { diff --git a/src/main/java/net/frozenblock/trailiertales/registry/TTPotions.java b/src/main/java/net/frozenblock/trailiertales/registry/TTPotions.java index 9d55c464..a1bdbbe1 100644 --- a/src/main/java/net/frozenblock/trailiertales/registry/TTPotions.java +++ b/src/main/java/net/frozenblock/trailiertales/registry/TTPotions.java @@ -14,7 +14,7 @@ public class TTPotions { public static final Holder.Reference TRANSFIGURING = register( - "transfiguring", new Potion(new MobEffectInstance(TTMobEffects.TRANSFIGURING, 3600)) + "transfiguring", new Potion("transfiguring", new MobEffectInstance(TTMobEffects.TRANSFIGURING, 3600)) ); public static void init() { diff --git a/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsPieces.java b/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsPieces.java index a0ea7ddd..b1ae2370 100644 --- a/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsPieces.java +++ b/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsPieces.java @@ -538,7 +538,7 @@ public void postProcess( int yDifference = startHeight - this.templatePosition.getY(); this.boundingBox.move(0, yDifference, 0); } - if (this.boundingBox.minY() <= world.getMinBuildHeight()) { + if (this.boundingBox.minY() <= world.getMinY()) { return; } super.postProcess(world, structureManager, chunkGenerator, random, boundingBox, chunkPos, pos); @@ -566,7 +566,7 @@ private int getFinalHeight(@NotNull BlockPos start, BlockGetter world, BlockPos BlockState blockState = world.getBlockState(mutableBlockPos); for (FluidState fluidState = world.getFluidState(mutableBlockPos); - (blockState.isAir() || fluidState.is(FluidTags.WATER) || blockState.is(BlockTags.ICE)) && o > world.getMinBuildHeight() + 1; + (blockState.isAir() || fluidState.is(FluidTags.WATER) || blockState.is(BlockTags.ICE)) && o > world.getMinY() + 1; fluidState = world.getFluidState(mutableBlockPos) ) { mutableBlockPos.set(m, --o, n); diff --git a/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsStructure.java b/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsStructure.java index f39b8a1e..922db992 100644 --- a/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsStructure.java +++ b/src/main/java/net/frozenblock/trailiertales/worldgen/structure/RuinsStructure.java @@ -131,10 +131,10 @@ public int getHeight( LevelHeightAccessor heightAccessor = context.heightAccessor(); BoundingBox box = new BoundingBox( x - 128, - Math.max(y - 128, heightAccessor.getMinBuildHeight() + 7), + Math.max(y - 128, heightAccessor.getMinY() + 7), z - 128, x + 128 + 1, - Math.min(y + 128 + 1, heightAccessor.getMaxBuildHeight()), + Math.min(y + 128 + 1, heightAccessor.getMaxY()), z + 128 + 1 ); RuinsPieces.addPieces(