mirror of
https://github.com/TeamMidnightDust/Puddles.git
synced 2025-12-16 20:15:10 +01:00
Backport 2.0.0 to 1.20.1
This commit is contained in:
@@ -3,13 +3,13 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
|
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/use
|
# check these on https://fabricmc.net/use
|
||||||
minecraft_version=1.21
|
minecraft_version=1.20.1
|
||||||
supported_versions=1.21.1
|
supported_versions=1.20
|
||||||
yarn_mappings=1.21+build.9
|
yarn_mappings=1.20.1+build.10
|
||||||
loader_version=0.15.11
|
loader_version=0.16.5
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 2.0.0
|
mod_version = 2.0.0+1.20.1
|
||||||
maven_group = eu.midnightdust
|
maven_group = eu.midnightdust
|
||||||
archives_base_name = puddles
|
archives_base_name = puddles
|
||||||
release_type=release
|
release_type=release
|
||||||
@@ -17,7 +17,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
modrinth_id=535D1YoA
|
modrinth_id=535D1YoA
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.100.7+1.21
|
fabric_version=0.92.2+1.20.1
|
||||||
midnightlib_version=1.5.8-fabric
|
midnightlib_version=1.4.1-fabric
|
||||||
polymer_version=0.9.6+1.21
|
polymer_version=0.5.19+1.20.1
|
||||||
server_translation_version=2.3.1+1.21-pre2
|
server_translation_version=2.0.0+1.20
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import eu.midnightdust.puddles.config.PuddlesConfig;
|
|||||||
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||||
@@ -21,7 +20,6 @@ import net.minecraft.util.Identifier;
|
|||||||
public class Puddles implements ModInitializer {
|
public class Puddles implements ModInitializer {
|
||||||
public static final String MOD_ID = "puddles";
|
public static final String MOD_ID = "puddles";
|
||||||
public static final PuddleBlock Puddle = new PuddleBlock();
|
public static final PuddleBlock Puddle = new PuddleBlock();
|
||||||
private final static EntityAttributeModifier entityAttributeModifier = new EntityAttributeModifier(id("puddle_speed"), 100, EntityAttributeModifier.Operation.ADD_VALUE);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
@@ -29,16 +27,10 @@ public class Puddles implements ModInitializer {
|
|||||||
Registry.register(Registries.BLOCK, id("puddle"), Puddle);
|
Registry.register(Registries.BLOCK, id("puddle"), Puddle);
|
||||||
Registry.register(Registries.ITEM, id("puddle"), new PolymerBlockItem(Puddle, new Item.Settings(), Items.POTION));
|
Registry.register(Registries.ITEM, id("puddle"), new PolymerBlockItem(Puddle, new Item.Settings(), Items.POTION));
|
||||||
ServerTickEvents.END_WORLD_TICK.register(world -> world.getPlayers().forEach(player -> {
|
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 (player.getBlockStateAtPos().getBlock() instanceof PuddleBlock) {
|
||||||
if (entityAttributeInstance != null) {
|
player.addStatusEffect(new StatusEffectInstance(StatusEffects.DOLPHINS_GRACE, 5, 255, true, false, true));
|
||||||
entityAttributeInstance.removeModifier(entityAttributeModifier);
|
if (world.random.nextInt(30) == 0) player.playSound(SoundEvents.ENTITY_PLAYER_SWIM, SoundCategory.BLOCKS, 0.5f, 1.2f);
|
||||||
entityAttributeInstance.addTemporaryModifier(entityAttributeModifier);
|
|
||||||
}
|
|
||||||
if (world.random.nextInt(30) == 0) player.playSoundToPlayer(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));
|
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);
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,23 +12,20 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.FluidBlock;
|
import net.minecraft.block.FluidBlock;
|
||||||
import net.minecraft.block.ShapeContext;
|
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.ai.pathing.NavigationType;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
|
import net.minecraft.potion.PotionUtil;
|
||||||
import net.minecraft.potion.Potions;
|
import net.minecraft.potion.Potions;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.stat.Stats;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.ItemActionResult;
|
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
@@ -43,20 +40,20 @@ import net.minecraft.world.WorldView;
|
|||||||
|
|
||||||
public class PuddleBlock extends Block implements PolymerBlock, BlockWithElementHolder {
|
public class PuddleBlock extends Block implements PolymerBlock, BlockWithElementHolder {
|
||||||
public PuddleBlock() {
|
public PuddleBlock() {
|
||||||
super(AbstractBlock.Settings.copy(Blocks.SHORT_GRASS));
|
super(AbstractBlock.Settings.copy(Blocks.GRASS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
ItemStack itemStack = player.getStackInHand(hand);
|
||||||
if (itemStack.isEmpty()) {
|
if (itemStack.isEmpty()) {
|
||||||
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
return ActionResult.PASS;
|
||||||
} else {
|
} else {
|
||||||
if (itemStack.getItem() == Items.GLASS_BOTTLE) {
|
if (itemStack.getItem() == Items.GLASS_BOTTLE) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
ItemStack waterBottleStack = new ItemStack(Items.POTION);
|
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);
|
itemStack.decrement(1);
|
||||||
if (itemStack.isEmpty()) {
|
if (itemStack.isEmpty()) {
|
||||||
player.setStackInHand(hand, waterBottleStack);
|
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.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
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
|
@Override
|
||||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||||
return true;
|
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);
|
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
|
@Override
|
||||||
public BlockState getPolymerBlockState(BlockState state) {
|
public BlockState getPolymerBlockState(BlockState state) {
|
||||||
return Blocks.WATER.getDefaultState().with(FluidBlock.LEVEL, 7);
|
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() {
|
var interactionElement = new InteractionElement(new VirtualElement.InteractionHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void interact(ServerPlayerEntity player, Hand hand) {
|
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
|
@Override
|
||||||
public void attack(ServerPlayerEntity player) {
|
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));
|
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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user