From b01bcbfb0a77e25c783befb586df118179876d58 Mon Sep 17 00:00:00 2001 From: Martin Prokoph Date: Tue, 17 Sep 2024 14:13:34 +0200 Subject: [PATCH] Backport 2.0.0 to 1.20.1 --- gradle.properties | 30 +++++++++---------- .../java/eu/midnightdust/puddles/Puddles.java | 16 +++------- .../puddles/block/PuddleBlock.java | 30 ++++++++++--------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/gradle.properties b/gradle.properties index ab8470c..03ccdd0 100755 --- a/gradle.properties +++ b/gradle.properties @@ -2,22 +2,22 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties - # check these on https://fabricmc.net/use - minecraft_version=1.21 - supported_versions=1.21.1 - yarn_mappings=1.21+build.9 - loader_version=0.15.11 +# check these on https://fabricmc.net/use +minecraft_version=1.20.1 +supported_versions=1.20 +yarn_mappings=1.20.1+build.10 +loader_version=0.16.5 # Mod Properties - mod_version = 2.0.0 - maven_group = eu.midnightdust - archives_base_name = puddles - release_type=release - curseforge_id=463169 - modrinth_id=535D1YoA +mod_version = 2.0.0+1.20.1 +maven_group = eu.midnightdust +archives_base_name = puddles +release_type=release +curseforge_id=463169 +modrinth_id=535D1YoA # Dependencies - fabric_version=0.100.7+1.21 - midnightlib_version=1.5.8-fabric - polymer_version=0.9.6+1.21 - server_translation_version=2.3.1+1.21-pre2 +fabric_version=0.92.2+1.20.1 +midnightlib_version=1.4.1-fabric +polymer_version=0.5.19+1.20.1 +server_translation_version=2.0.0+1.20 diff --git a/src/main/java/eu/midnightdust/puddles/Puddles.java b/src/main/java/eu/midnightdust/puddles/Puddles.java index c404a04..31ffa47 100755 --- a/src/main/java/eu/midnightdust/puddles/Puddles.java +++ b/src/main/java/eu/midnightdust/puddles/Puddles.java @@ -5,9 +5,8 @@ import eu.midnightdust.puddles.config.PuddlesConfig; import eu.pb4.polymer.core.api.item.PolymerBlockItem; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; -import net.minecraft.entity.attribute.EntityAttributeInstance; -import net.minecraft.entity.attribute.EntityAttributeModifier; -import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; @@ -21,7 +20,6 @@ import net.minecraft.util.Identifier; public class Puddles implements ModInitializer { public static final String MOD_ID = "puddles"; public static final PuddleBlock Puddle = new PuddleBlock(); - private final static EntityAttributeModifier entityAttributeModifier = new EntityAttributeModifier(id("puddle_speed"), 100, EntityAttributeModifier.Operation.ADD_VALUE); @Override public void onInitialize() { @@ -29,16 +27,10 @@ public class Puddles implements ModInitializer { Registry.register(Registries.BLOCK, id("puddle"), Puddle); Registry.register(Registries.ITEM, id("puddle"), new PolymerBlockItem(Puddle, new Item.Settings(), Items.POTION)); ServerTickEvents.END_WORLD_TICK.register(world -> world.getPlayers().forEach(player -> { - EntityAttributeInstance entityAttributeInstance = player.getAttributes().getCustomInstance(EntityAttributes.GENERIC_WATER_MOVEMENT_EFFICIENCY); if (player.getBlockStateAtPos().getBlock() instanceof PuddleBlock) { - if (entityAttributeInstance != null) { - entityAttributeInstance.removeModifier(entityAttributeModifier); - entityAttributeInstance.addTemporaryModifier(entityAttributeModifier); - } - if (world.random.nextInt(30) == 0) player.playSoundToPlayer(SoundEvents.ENTITY_PLAYER_SWIM, SoundCategory.BLOCKS, 0.5f, 1.2f); + player.addStatusEffect(new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, 5, 255, true, false, true)); + if (world.random.nextInt(30) == 0) player.playSound(SoundEvents.ENTITY_PLAYER_SWIM, SoundCategory.BLOCKS, 0.5f, 1.2f); player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleTypes.SPLASH, false, player.getBlockX() + 0.5f, player.getBlockY() + 0.1f, player.getBlockZ() + 0.5f, 0.5f, 0.1f, 0.5f, 1, 2)); - } else if (player.isInFluid()) { - if (entityAttributeInstance != null) entityAttributeInstance.removeModifier(entityAttributeModifier); } })); } diff --git a/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java b/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java index e352c5c..f41b049 100755 --- a/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java +++ b/src/main/java/eu/midnightdust/puddles/block/PuddleBlock.java @@ -12,23 +12,20 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FluidBlock; import net.minecraft.block.ShapeContext; -import net.minecraft.component.ComponentMap; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.PotionContentsComponent; import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; import net.minecraft.particle.ParticleTypes; +import net.minecraft.potion.PotionUtil; import net.minecraft.potion.Potions; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; -import net.minecraft.stat.Stats; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -43,20 +40,20 @@ import net.minecraft.world.WorldView; public class PuddleBlock extends Block implements PolymerBlock, BlockWithElementHolder { public PuddleBlock() { - super(AbstractBlock.Settings.copy(Blocks.SHORT_GRASS)); + super(AbstractBlock.Settings.copy(Blocks.GRASS)); } @Override - public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { ItemStack itemStack = player.getStackInHand(hand); if (itemStack.isEmpty()) { - return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + return ActionResult.PASS; } else { if (itemStack.getItem() == Items.GLASS_BOTTLE) { if (!world.isClient) { if (!player.isCreative()) { ItemStack waterBottleStack = new ItemStack(Items.POTION); - waterBottleStack.applyComponentsFrom(ComponentMap.builder().add(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT.with(Potions.WATER)).build()); + PotionUtil.setPotion(waterBottleStack, Potions.WATER); itemStack.decrement(1); if (itemStack.isEmpty()) { player.setStackInHand(hand, waterBottleStack); @@ -70,9 +67,9 @@ public class PuddleBlock extends Block implements PolymerBlock, BlockWithElement world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F); world.setBlockState(pos, Blocks.AIR.getDefaultState()); } - return ItemActionResult.success(world.isClient); + return ActionResult.success(world.isClient); } - else return ItemActionResult.FAIL; + else return ActionResult.FAIL; } } @@ -101,7 +98,7 @@ public class PuddleBlock extends Block implements PolymerBlock, BlockWithElement } @Override - public boolean canPathfindThrough(BlockState state, NavigationType type) { + public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { return true; } @@ -133,6 +130,11 @@ public class PuddleBlock extends Block implements PolymerBlock, BlockWithElement return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom); } + @Override + public Block getPolymerBlock(BlockState state) { + return Blocks.WATER; + } + @Override public BlockState getPolymerBlockState(BlockState state) { return Blocks.WATER.getDefaultState().with(FluidBlock.LEVEL, 7); @@ -143,11 +145,11 @@ public class PuddleBlock extends Block implements PolymerBlock, BlockWithElement var interactionElement = new InteractionElement(new VirtualElement.InteractionHandler() { @Override public void interact(ServerPlayerEntity player, Hand hand) { - world.getBlockState(pos).onUseWithItem(player.getStackInHand(hand), world, player, hand, new BlockHitResult(pos.toCenterPos(), Direction.UP, pos, false)); + world.getBlockState(pos).onUse(world, player, hand, new BlockHitResult(pos.toCenterPos(), Direction.UP, pos, false)); } @Override public void attack(ServerPlayerEntity player) { - player.playSoundToPlayer(SoundEvents.ENTITY_PLAYER_SPLASH, SoundCategory.BLOCKS, 0.8f, 1.3f); + player.playSound(SoundEvents.ENTITY_PLAYER_SPLASH, SoundCategory.BLOCKS, 0.8f, 1.3f); player.networkHandler.sendPacket(new ParticleS2CPacket(ParticleTypes.SPLASH, false, pos.getX() + 0.5f, pos.getY() + 0.1f, pos.getZ() + 0.5f, 0.5f, 0.1f, 0.5f, 1, 2)); } });