diff --git a/src/main/java/quimufu/colourful_portals/ColourfulPortalsMod.java b/src/main/java/quimufu/colourful_portals/ColourfulPortalsMod.java index add62c8..de4ed30 100644 --- a/src/main/java/quimufu/colourful_portals/ColourfulPortalsMod.java +++ b/src/main/java/quimufu/colourful_portals/ColourfulPortalsMod.java @@ -38,14 +38,12 @@ import quimufu.colourful_portals.portal_fluid.PortalFluidBucketItem; import java.util.HashSet; public class ColourfulPortalsMod implements ModInitializer, ClientModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger("colourful_portals"); + public static final String MOD_ID = "colourful_portals"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final HashSet PORTAL_BLOCKS = new HashSet<>(); - public static final PortalBlock PORTAL_BLOCK = new PortalBlock(FabricBlockSettings.of(Material.GLASS).strength(-1.0f, 3600000.8f).dropsNothing().nonOpaque().luminance(15).allowsSpawning(ColourfulPortalsMod::never).solidBlock(ColourfulPortalsMod::never).suffocates(ColourfulPortalsMod::never).blockVision(ColourfulPortalsMod::never)); + public static final PortalBlock PORTAL_BLOCK = new PortalBlock(FabricBlockSettings.of(Material.GLASS).strength(-1.0f, 3600000.8f).dropsNothing().nonOpaque().luminance(15).allowsSpawning(ColourfulPortalsMod::never).solidBlock(ColourfulPortalsMod::never).suffocates(ColourfulPortalsMod::never).blockVision(ColourfulPortalsMod::never).ticksRandomly()); public static final BlockItem PORTAL_BLOCK_ITEM = new BlockItem(PORTAL_BLOCK, new FabricItemSettings().rarity(Rarity.EPIC)); public static final Item BLOB_DARK = new Item(new FabricItemSettings()); public static final Item BLOB_BRIGHT = new Item(new FabricItemSettings()); @@ -64,10 +62,7 @@ public class ColourfulPortalsMod implements ModInitializer, ClientModInitializer @Override public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - LOGGER.info("Hello Fabric world!"); + LOGGER.info("Colourizing Portals..."); for (String id : ColourfulPortalConfig.portalBlocks.keySet()) { PORTAL_BLOCKS.add(Identifier.tryParse(id)); @@ -91,6 +86,7 @@ public class ColourfulPortalsMod implements ModInitializer, ClientModInitializer ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS) .register(ColourfulPortalsMod::addTtTools); + LOGGER.info("Portals Colourful!"); } private static void addTtTools(FabricItemGroupEntries entries) { diff --git a/src/main/java/quimufu/colourful_portals/PortalBlock.java b/src/main/java/quimufu/colourful_portals/PortalBlock.java index 01fb569..2ec0d11 100644 --- a/src/main/java/quimufu/colourful_portals/PortalBlock.java +++ b/src/main/java/quimufu/colourful_portals/PortalBlock.java @@ -2,9 +2,13 @@ package quimufu.colourful_portals; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.FluidFillable; import net.minecraft.block.ShapeContext; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.Items; +import net.minecraft.server.world.ServerWorld; import net.minecraft.state.StateManager; import net.minecraft.state.property.EnumProperty; import net.minecraft.state.property.Properties; @@ -15,9 +19,12 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import quimufu.colourful_portals.portal.PortalManager; -public class PortalBlock extends Block { +public class PortalBlock extends Block implements FluidFillable { public static final EnumProperty AXIS = Properties.AXIS; public static final EnumProperty DYE_COLOR = EnumProperty.of("colour", DyeColor.class);; @@ -56,7 +63,8 @@ public class PortalBlock extends Block { BlockState state, BlockView world, BlockPos blockPos, ShapeContext shapeContext ) { if(shapeContext.isHolding(Items.DEBUG_STICK) - || shapeContext.isHolding(ColourfulPortalsMod.PORTAL_BLOCK_ITEM)){ + || shapeContext.isHolding(ColourfulPortalsMod.PORTAL_BLOCK_ITEM) + || shapeContext.isHolding(ColourfulPortalsMod.PORTAL_FLUID_BUCKET_ITEM)){ return switch (state.get(AXIS)) { case Z -> Z_AABB; case Y -> Y_AABB; @@ -112,4 +120,23 @@ public class PortalBlock extends Block { return true; } + @Override + public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { + if(((World)world).isClient() && fluid == ColourfulPortalsMod.PORTAL_FLUID){ + return true; + } + return fluid == ColourfulPortalsMod.PORTAL_FLUID + && (world instanceof ServerWorld) + && PortalManager.canExtend((ServerWorld) world, pos); + } + + @Override + public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) { + if(((World)world).isClient() && fluidState.isOf(ColourfulPortalsMod.PORTAL_FLUID)){ + return true; + } + return fluidState.isOf(ColourfulPortalsMod.PORTAL_FLUID) + && (world instanceof ServerWorld) + && PortalManager.extend((ServerWorld) world, pos); + } } diff --git a/src/main/java/quimufu/colourful_portals/client/PortalFluidRenderHandler.java b/src/main/java/quimufu/colourful_portals/client/PortalFluidRenderHandler.java index a7a2e80..fe7bcad 100644 --- a/src/main/java/quimufu/colourful_portals/client/PortalFluidRenderHandler.java +++ b/src/main/java/quimufu/colourful_portals/client/PortalFluidRenderHandler.java @@ -21,10 +21,10 @@ public class PortalFluidRenderHandler implements FluidRenderHandler, CommonPorta private final CommonPortalFluidRenderer commonPortalFluidRenderer = new CommonPortalFluidRenderer(); private Sprite sprite = null; - private VertexConsumer vertexConsumer; - private int i; + private final ThreadLocal vertexConsumer = new ThreadLocal<>(); + private final ThreadLocal i = new ThreadLocal<>(); - private final float[][] vertices = new float[4][5]; + private final ThreadLocal vertices = new ThreadLocal<>(); @Override public Sprite[] getFluidSprites(@Nullable BlockRenderView view, @Nullable BlockPos pos, FluidState state) { @@ -38,12 +38,12 @@ public class PortalFluidRenderHandler implements FluidRenderHandler, CommonPorta @Override public void renderFluid(BlockPos pos, BlockRenderView world, VertexConsumer vertexConsumer, BlockState blockState, FluidState fluidState) { - this.vertexConsumer = vertexConsumer; + this.vertexConsumer.set(vertexConsumer); BlockPos offset = new BlockPos(pos.getX() & 0xF, pos.getY() & 0xF, pos.getZ() & 0xF); - + if (vertices.get() == null) { + vertices.set(new float[4][5]); + } commonPortalFluidRenderer.render(world, fluidState, pos, offset, this); - - } @@ -60,12 +60,14 @@ public class PortalFluidRenderHandler implements FluidRenderHandler, CommonPorta @Override public void eatVertex(float x, float y, float z, float u, float v) { - vertices[i][0] = x; - vertices[i][1] = y; - vertices[i][2] = z; - vertices[i][3] = u; - vertices[i][4] = v; - i = (i + 1) % 4; + float[][] floats = vertices.get(); + int idx = i.get() == null ? 0 : i.get(); + floats[idx][0] = x; + floats[idx][1] = y; + floats[idx][2] = z; + floats[idx][3] = u; + floats[idx][4] = v; + i.set((idx + 1) % 4); } @Override @@ -73,12 +75,12 @@ public class PortalFluidRenderHandler implements FluidRenderHandler, CommonPorta float offX = offset.getX(); float offY = offset.getY(); float offZ = offset.getZ(); - for (float[] v : vertices) { + for (float[] v : vertices.get()) { - vertexConsumer + vertexConsumer.get() .vertex(offX + v[0], offY + v[1], offZ + v[2]) .color(1f, 1f, 1f, 1.0f) - .texture( v[3], v[4]) + .texture(v[3], v[4]) .light(16) .normal(0.0f, 1.0f, 0.0f) .next(); diff --git a/src/main/java/quimufu/colourful_portals/mixin/BlockChangeMixin.java b/src/main/java/quimufu/colourful_portals/mixin/BlockChangeMixin.java index 4708326..449b979 100644 --- a/src/main/java/quimufu/colourful_portals/mixin/BlockChangeMixin.java +++ b/src/main/java/quimufu/colourful_portals/mixin/BlockChangeMixin.java @@ -26,16 +26,14 @@ public class BlockChangeMixin { // This code is injected into the end of ServerWorld.onBlockChanged()V if (oldBlock.getBlock() != newBlock.getBlock()) { if (PORTAL_BLOCKS.contains(Registries.BLOCK.getId(newBlock.getBlock()))) { - LOGGER.info("onBlockNew {} -> {}", oldBlock, newBlock); + LOGGER.debug("onBlockNew {} -> {}", oldBlock, newBlock); Identifier blockId = Registries.BLOCK.getId(newBlock.getBlock()); - ColourfulPortalsMod.LOGGER.info("Block change, new portal block: " + blockId); PortalManager.onPortalBlockPlaced(world, pos, blockId); } if (PORTAL_BLOCKS.contains(Registries.BLOCK.getId(oldBlock.getBlock()))) { - LOGGER.info("onBlockOld {} -> {}", oldBlock, newBlock); + LOGGER.debug("onBlockOld {} -> {}", oldBlock, newBlock); Identifier blockId = Registries.BLOCK.getId(oldBlock.getBlock()); - ColourfulPortalsMod.LOGGER.info("Block change, removed portal block: " + blockId); PortalManager.onPortalBlockBroken(world, pos, blockId); } } diff --git a/src/main/java/quimufu/colourful_portals/portal/PortalHelper.java b/src/main/java/quimufu/colourful_portals/portal/PortalHelper.java index 1f76a58..92634e8 100644 --- a/src/main/java/quimufu/colourful_portals/portal/PortalHelper.java +++ b/src/main/java/quimufu/colourful_portals/portal/PortalHelper.java @@ -34,16 +34,16 @@ public class PortalHelper { } static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId) { - return isValidPortal(world, portal, blockId, true); + return isValidPortal(world, portal, blockId, true, false); } static boolean isValidCandidate(ServerWorld world, BlockBox portal, Identifier blockId) { - return isValidPortal(world, portal, blockId, false); + return isValidPortal(world, portal, blockId, false, false); } - private static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId, boolean empty) { + private static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId, boolean empty, boolean placementCheck) { Direction axisW = getAxisW(portal); - return isValidPortal(world, Registries.BLOCK.get(blockId), new BlockPos(portal.getMinX(), portal.getMinY(), portal.getMinZ()), empty, axisW); + return isValidPortal(world, Registries.BLOCK.get(blockId), new BlockPos(portal.getMinX(), portal.getMinY(), portal.getMinZ()), empty, axisW, placementCheck); } static Direction getAxisW(BlockBox fromPortalBox) { @@ -167,13 +167,17 @@ public class PortalHelper { private static Optional getPortalStartingAt(ServerWorld world, Block block, BlockPos lowerCorner, Direction direction) { Vec3i sidewardsOffset = direction.getVector().multiply(3); Vec3i upwardsOffset = Direction.UP.getVector().multiply(4); - if (isValidPortal(world, block, lowerCorner, false, direction)) { + if (isValidPortal(world, block, lowerCorner, false, direction, false)) { return Optional.of(BlockBox.create(lowerCorner, lowerCorner.add(sidewardsOffset).add(upwardsOffset))); } return Optional.empty(); } - private static boolean isValidPortal(ServerWorld world, Block block, BlockPos lowerCorner, boolean hasToBeFilledCorrectly, Direction direction) { + public static boolean isPortalPlaceable(ServerWorld world, BlockBox portal, Identifier blockId) { + return isValidPortal(world, portal, blockId, false, true); + } + + private static boolean isValidPortal(ServerWorld world, Block block, BlockPos lowerCorner, boolean hasToBeFilledCorrectly, Direction direction, boolean placementCheck) { //maybe use BlockPosIterator, but make sure Performance is OK for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) { @@ -194,6 +198,9 @@ public class PortalHelper { if (hasToBeFilledCorrectly && !(blockState.getFluidState().isOf(PORTAL_FLUID) || blockState.getBlock().equals(PORTAL_BLOCK))) { return false; } + if(placementCheck && !(blockState.isReplaceable() || blockState.getFluidState().isOf(PORTAL_FLUID) || blockState.getBlock().equals(PORTAL_BLOCK))){ + return false; + } if (blockState.isOf(block)) { return false; } @@ -205,6 +212,7 @@ public class PortalHelper { return true; } + private static class BlockPosIterator implements Iterator { private final BlockPos startPos; private final Vec3i dir; diff --git a/src/main/java/quimufu/colourful_portals/portal/PortalListComponent.java b/src/main/java/quimufu/colourful_portals/portal/PortalListComponent.java index 7ded3ad..0c2dc95 100644 --- a/src/main/java/quimufu/colourful_portals/portal/PortalListComponent.java +++ b/src/main/java/quimufu/colourful_portals/portal/PortalListComponent.java @@ -70,7 +70,7 @@ public class PortalListComponent implements Component { } } - LOGGER.info("portals {}", tag.toString()); + LOGGER.debug("portals {}", tag.toString()); } @@ -120,4 +120,9 @@ public class PortalListComponent implements Component { List> portals = portalsPerPortalBlock.computeIfAbsent(blockId, (i) -> new ArrayList<>()); return portals.contains(portal); } + + public Pair getLast(Identifier blockId) { + List> portals = portalsPerPortalBlock.computeIfAbsent(blockId, (i) -> new ArrayList<>()); + return portals.get(portals.size()-1); + } } diff --git a/src/main/java/quimufu/colourful_portals/portal/PortalManager.java b/src/main/java/quimufu/colourful_portals/portal/PortalManager.java index acb4cf0..3f24b94 100644 --- a/src/main/java/quimufu/colourful_portals/portal/PortalManager.java +++ b/src/main/java/quimufu/colourful_portals/portal/PortalManager.java @@ -161,6 +161,9 @@ public class PortalManager { BlockState blockState = portalWorld.getBlockState(blockPos); if (blockState.isAir() || blockState.getFluidState().isOf(PORTAL_FLUID)) { portalWorld.setBlockState(blockPos, portalBlockState); + } else if (blockState.isReplaceable()) { + portalWorld.breakBlock(blockPos,true); + portalWorld.setBlockState(blockPos, portalBlockState); } }); } @@ -254,14 +257,75 @@ public class PortalManager { List portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dim); for (BlockBox portalCandidate : portalCandidates) { if (PortalHelper.isValidPortal(world, portalCandidate, blockId)) { - Pair next = portalCandidateList.getNext(blockId, portalCandidate, dim); Pair current = Pair.of(portalCandidate, dim); + Pair next = portalCandidateList.getNext(blockId, portalCandidate, dim); + ServerWorld nextWorld = world.getServer().getWorld(RegistryKey.of(RegistryKeys.WORLD, next.second)); if (!next.equals(current) - && (!portalList.containsPortal(blockId, current) || !portalList.containsPortal(blockId, next))) { + && (!portalList.containsPortal(blockId, current) || !portalList.containsPortal(blockId, next)) + && PortalHelper.isPortalPlaceable(nextWorld, next.first, blockId)) { portalList.createPortal(blockId, current); portalList.createPortal(blockId, next); ret = true; + } + fixPortalGroup(blockId, portalList, world.getServer()); + } + } + } + world.getProfiler().pop(); + return ret; + } + public static boolean canExtend(ServerWorld world, BlockPos pos) { + world.getProfiler().push("portal extension check"); + PortalListComponent portalCandidateList = PORTAL_CANDIDATE_LIST.get(world.getLevelProperties()); + PortalListComponent portalList = PORTAL_LIST.get(world.getLevelProperties()); + Set blockIds = portalList.getBlockIds(); + Identifier dim = world.getDimensionKey().getValue(); + + for (Identifier blockId : blockIds) { + List portals = portalList.getContainingPortals(blockId, pos, dim); + for (BlockBox portal : portals) { + if (PortalHelper.isValidPortal(world, portal, blockId)) { + Pair last = portalList.getLast(blockId); + Pair next = portalCandidateList.getNext(blockId, last.first, last.second); + ServerWorld nextWorld = world.getServer().getWorld(RegistryKey.of(RegistryKeys.WORLD, next.second)); + + if(!portalList.containsPortal(blockId, next) + && PortalHelper.isValidPortal(world, portal, blockId) + && PortalHelper.isPortalPlaceable(nextWorld, next.first, blockId)){ + world.getProfiler().pop(); + return true; + } + } + } + + } + + world.getProfiler().pop(); + return false; + } + + public static boolean extend(ServerWorld world, BlockPos pos) { + world.getProfiler().push("portal extension"); + PortalListComponent portalCandidateList = PORTAL_CANDIDATE_LIST.get(world.getLevelProperties()); + PortalListComponent portalList = PORTAL_LIST.get(world.getLevelProperties()); + Set blockIds = portalList.getBlockIds(); + Identifier dim = world.getDimensionKey().getValue(); + + boolean ret = false; + for (Identifier blockId : blockIds) { + List portals = portalList.getContainingPortals(blockId, pos, dim); + for (BlockBox portal : portals) { + if (PortalHelper.isValidPortal(world, portal, blockId)) { + Pair last = portalList.getLast(blockId); + Pair next = portalCandidateList.getNext(blockId, last.first, last.second); + ServerWorld nextWorld = world.getServer().getWorld(RegistryKey.of(RegistryKeys.WORLD, next.second)); + + if(!portalList.containsPortal(blockId, next) + && PortalHelper.isValidPortal(world, portal, blockId) + && PortalHelper.isPortalPlaceable(nextWorld, next.first, blockId)){ + portalList.createPortal(blockId, next); + ret = true; } fixPortalGroup(blockId, portalList, world.getServer()); } diff --git a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluid.java b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluid.java index bdc8c12..04b5bcc 100644 --- a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluid.java +++ b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluid.java @@ -63,7 +63,7 @@ public class PortalFluid extends Fluid { @Override protected void onRandomTick(World world, BlockPos pos, FluidState state, Random random) { if (!world.isClient && !world.getFluidTickScheduler().isQueued(pos, this)) { - //world.scheduleFluidTick(pos, this, this.getTickRate(world)); + world.scheduleFluidTick(pos, this, this.getTickRate(world)); } } @@ -137,7 +137,7 @@ public class PortalFluid extends Fluid { newStateMe = state.with(AXIS, NullableAxis.of(currentAxis)); } - if (amount == 0 || (amount <= 14 && targetDir != null)) { + if (amount <= 14) { //*might* change my state in world, returned value is what new state should be newStateMe = steal(world, pos, newStateMe, currentAxis); } @@ -147,7 +147,6 @@ public class PortalFluid extends Fluid { if (amount == 0) { //we couldn't steal anything to keep ourselves alive. This ?should? not happen. world.setBlockState(pos, Blocks.AIR.getDefaultState()); - world.updateNeighborsAlways(pos, ColourfulPortalsMod.PORTAL_FLUID_BLOCk); world.getProfiler().pop(); return; } @@ -177,14 +176,15 @@ public class PortalFluid extends Fluid { } - if (world.getBlockState(pos).getFluidState() != newStateMe) { - BlockState blockState = newStateMe.getBlockState(); + FluidState actual = world.getBlockState(pos).getFluidState(); + BlockState blockState = newStateMe.getBlockState(); + if (actual != newStateMe) { world.setBlockState(pos, blockState); world.updateNeighborsAlways(pos, blockState.getBlock()); world.scheduleFluidTick(pos, this, getTickRate(world)); - } else if (world.getBlockState(pos).getFluidState() != state) { - //we changed, so we schedule an update for ourselves - world.scheduleFluidTick(pos, this, getTickRate(world)); + } else if (actual != state && Math.abs(state.get(AMOUNT) - actual.get(AMOUNT)) > 1) { + //we changed by more than one, informing Neighbors, so they can steal as well + world.updateNeighborsAlways(pos, blockState.getBlock()); } world.getProfiler().pop(); } @@ -507,10 +507,11 @@ public class PortalFluid extends Fluid { if (!world.isClient()) { for (Map.Entry update : updated.entrySet()) { world.setBlockState(update.getKey(), update.getValue().getBlockState(), Block.NOTIFY_LISTENERS); - if (!world.getFluidTickScheduler().isQueued(update.getKey(), this)) { world.scheduleFluidTick(update.getKey(), this, this.getTickRate(world)); } + world.updateNeighbors(update.getKey(), update.getValue().getBlockState().getBlock()); + } } return true; diff --git a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBlock.java b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBlock.java index 08acedd..a286423 100644 --- a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBlock.java +++ b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBlock.java @@ -19,6 +19,7 @@ import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; +import quimufu.colourful_portals.ColourfulPortalsMod; import java.util.Collections; import java.util.List; @@ -58,14 +59,14 @@ public class PortalFluidBlock @Override public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) { - if (!world.getFluidTickScheduler().isQueued(pos, fluid)) { + if (oldState.getFluidState().getFluid() != fluid && !world.getFluidTickScheduler().isQueued(pos, fluid)) { world.scheduleFluidTick(pos, fluid, this.fluid.getTickRate(world)); } } @Override public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { - if (!world.getFluidTickScheduler().isQueued(pos, fluid)) { + if (!neighborState.getFluidState().isOf(fluid) && !world.getFluidTickScheduler().isQueued(pos, fluid)) { world.scheduleFluidTick(pos, fluid, this.fluid.getTickRate(world)); } return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); diff --git a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBucketItem.java b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBucketItem.java index 16fcf02..9668f37 100644 --- a/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBucketItem.java +++ b/src/main/java/quimufu/colourful_portals/portal_fluid/PortalFluidBucketItem.java @@ -30,13 +30,31 @@ public class PortalFluidBucketItem extends BucketItem { @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { - BlockHitResult blockHitResult = BucketItem.raycast(world, user, RaycastContext.FluidHandling.ANY); + BlockHitResult blockHitResult = BucketItem.raycast(world, user, RaycastContext.FluidHandling.NONE); + ItemStack itemStack = user.getStackInHand(hand); if (blockHitResult.getType() == HitResult.Type.BLOCK) { BlockPos pos = blockHitResult.getBlockPos(); - if (world.getBlockState(pos).getFluidState().isOf(fluid)) { - placeFluid(user, world, pos, blockHitResult); + BlockState blockState = world.getBlockState(pos); + Block block = blockState.getBlock(); + if (block instanceof FluidFillable && ((FluidFillable) block).canFillWithFluid(world, pos, blockState, fluid)) { + if (placeFluid(user, world, pos, blockHitResult)) { + return TypedActionResult.success(BucketItem.getEmptiedStack(itemStack, user), world.isClient()); + } } } + + blockHitResult = BucketItem.raycast(world, user, RaycastContext.FluidHandling.ANY); + itemStack = user.getStackInHand(hand); + if (blockHitResult.getType() == HitResult.Type.BLOCK) { + BlockPos pos = blockHitResult.getBlockPos(); + BlockState blockState = world.getBlockState(pos); + if (blockState.getFluidState().isOf(fluid)) { + if (placeFluid(user, world, pos, blockHitResult)) { + return TypedActionResult.success(BucketItem.getEmptiedStack(itemStack, user), world.isClient()); + } + } + } + return super.use(world, user, hand); } diff --git a/src/main/resources/assets/colourful_portals/models/block/portal_block.json b/src/main/resources/assets/colourful_portals/models/block/portal_block.json index f6502ab..beeb0b8 100644 --- a/src/main/resources/assets/colourful_portals/models/block/portal_block.json +++ b/src/main/resources/assets/colourful_portals/models/block/portal_block.json @@ -13,5 +13,8 @@ } } } - ] + ], + "textures": { + "particle": "#pane" + } } \ No newline at end of file