From 32c246fa6c1a0be76d6034bd071456de9b91dac2 Mon Sep 17 00:00:00 2001 From: "yrsegal@gmail.com" Date: Wed, 27 Apr 2022 17:08:33 -0400 Subject: [PATCH] create water and create lava now insert into containers --- .../hexcasting/client/gui/GuiSpellcasting.kt | 2 +- .../casting/operators/spells/OpCreateWater.kt | 26 ++++++++++++++----- .../operators/spells/great/OpCreateLava.kt | 25 +++++++++++++----- .../hexcasting/xplat/IXplatAbstractions.java | 4 +++ .../fabric/xplat/FabricXplatImpl.java | 7 +++++ .../forge/xplat/ForgeXplatImpl.java | 12 +++++++++ 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt index 1abb3691..45b4478c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt +++ b/Common/src/main/java/at/petrak/hexcasting/client/gui/GuiSpellcasting.kt @@ -142,7 +142,7 @@ class GuiSpellcasting( val delta = mouse.add(anchor.negated()) val angle = atan2(delta.y, delta.x) // 0 is right, increases clockwise(?) - val snappedAngle = angle.div(TAU.toFloat()).mod(6.0f) + val snappedAngle = angle.div(Mth.TWO_PI).mod(6.0f) val newdir = HexDir.values()[(snappedAngle.times(6).roundToInt() + 1).mod(6)] // The player might have a lousy aim, so set the new anchor point to the "ideal" // location as if they had hit it exactly on the nose. diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt index 6428d0ec..41909097 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt @@ -7,9 +7,15 @@ import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos import net.minecraft.world.item.BucketItem +import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items +import net.minecraft.world.level.block.AbstractCauldronBlock +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.LayeredCauldronBlock +import net.minecraft.world.level.material.Fluids import net.minecraft.world.phys.Vec3 object OpCreateWater : SpellOperator { @@ -34,13 +40,19 @@ object OpCreateWater : SpellOperator { if (!ctx.world.mayInteract(ctx.caster, pos)) return - // Just steal bucket code lmao - val charlie = Items.WATER_BUCKET - if (charlie is BucketItem) { - // make the player null so we don't give them a usage statistic for example - charlie.emptyContents(null, ctx.world, pos, null) - } else { - HexAPI.LOGGER.warn("Items.WATER_BUCKET wasn't a BucketItem?") + val state = ctx.world.getBlockState(pos) + + if (state.block is AbstractCauldronBlock) + ctx.world.setBlock(pos, Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), 3) + else if (IXplatAbstractions.INSTANCE.tryPlaceFluid(ctx.world, ctx.castingHand, pos, ItemStack(Items.WATER_BUCKET), Fluids.WATER)) { + // Just steal bucket code lmao + val charlie = Items.WATER_BUCKET + if (charlie is BucketItem) { + // make the player null so we don't give them a usage statistic for example + charlie.emptyContents(null, ctx.world, pos, null) + } else { + HexAPI.LOGGER.warn("Items.WATER_BUCKET wasn't a BucketItem?") + } } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt index 1da29944..14e93ac1 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt @@ -7,9 +7,14 @@ import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos import net.minecraft.world.item.BucketItem +import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items +import net.minecraft.world.level.block.AbstractCauldronBlock +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.material.Fluids import net.minecraft.world.phys.Vec3 object OpCreateLava : SpellOperator { @@ -36,13 +41,19 @@ object OpCreateLava : SpellOperator { if (!ctx.world.mayInteract(ctx.caster, pos)) return - // Just steal bucket code lmao - val charlie = Items.LAVA_BUCKET - if (charlie is BucketItem) { - // make the player null so we don't give them a usage statistic for example - charlie.emptyContents(null, ctx.world, pos, null) - } else { - HexAPI.LOGGER.warn("Items.LAVA_BUCKET wasn't a BucketItem?") + val state = ctx.world.getBlockState(pos) + + if (state.block is AbstractCauldronBlock) + ctx.world.setBlock(pos, Blocks.LAVA_CAULDRON.defaultBlockState(), 3) + else if (!IXplatAbstractions.INSTANCE.tryPlaceFluid(ctx.world, ctx.castingHand, pos, ItemStack(Items.LAVA_BUCKET), Fluids.LAVA)) { + // Just steal bucket code lmao + val charlie = Items.LAVA_BUCKET + if (charlie is BucketItem) { + // make the player null so we don't give them a usage statistic for example + charlie.emptyContents(null, ctx.world, pos, null) + } else { + HexAPI.LOGGER.warn("Items.LAVA_BUCKET wasn't a BucketItem?") + } } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java index cf3db43c..979354bd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java +++ b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java @@ -24,10 +24,12 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @@ -105,6 +107,8 @@ public interface IXplatAbstractions { BlockEntityType createBlockEntityType(BiFunction func, Block... blocks); + boolean tryPlaceFluid(Level level, InteractionHand hand, BlockPos pos, ItemStack stack, Fluid fluid); + // misc diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java index ce19c541..8ea1639a 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java @@ -34,10 +34,12 @@ import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; @@ -194,6 +196,11 @@ public class FabricXplatImpl implements IXplatAbstractions { return FabricBlockEntityTypeBuilder.create(func::apply, blocks).build(); } + @Override + public boolean tryPlaceFluid(Level level, InteractionHand hand, BlockPos pos, ItemStack stack, Fluid fluid) { + return false; + } + @Override public ResourceLocation getID(Block block) { return Registry.BLOCK.getKey(block); diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java index eb095622..c96bc406 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java @@ -41,14 +41,20 @@ import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.TierSortingRegistry; +import net.minecraftforge.fluids.FluidActionResult; +import net.minecraftforge.fluids.FluidAttributes; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.network.PacketDistributor; import org.jetbrains.annotations.Nullable; @@ -265,6 +271,12 @@ public class ForgeXplatImpl implements IXplatAbstractions { return BlockEntityType.Builder.of(func::apply, blocks).build(null); } + @Override + public boolean tryPlaceFluid(Level level, InteractionHand hand, BlockPos pos, ItemStack stack, Fluid fluid) { + return FluidUtil.tryPlaceFluid(null, level, hand, pos, stack, new FluidStack( + fluid, FluidAttributes.BUCKET_VOLUME)) != FluidActionResult.FAILURE; + } + @Override public ResourceLocation getID(Block block) { return block.getRegistryName();