create water and create lava now insert into containers

This commit is contained in:
yrsegal@gmail.com 2022-04-27 17:08:33 -04:00
parent 120c43b4b2
commit 32c246fa6c
6 changed files with 61 additions and 15 deletions

View file

@ -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.

View file

@ -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,6 +40,11 @@ object OpCreateWater : SpellOperator {
if (!ctx.world.mayInteract(ctx.caster, pos))
return
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) {
@ -45,3 +56,4 @@ object OpCreateWater : SpellOperator {
}
}
}
}

View file

@ -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,6 +41,11 @@ object OpCreateLava : SpellOperator {
if (!ctx.world.mayInteract(ctx.caster, pos))
return
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) {
@ -47,3 +57,4 @@ object OpCreateLava : SpellOperator {
}
}
}
}

View file

@ -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 {
<T extends BlockEntity> BlockEntityType<T> createBlockEntityType(BiFunction<BlockPos, BlockState, T> func,
Block... blocks);
boolean tryPlaceFluid(Level level, InteractionHand hand, BlockPos pos, ItemStack stack, Fluid fluid);
// misc

View file

@ -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);

View file

@ -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();