Jump to content

How to make Blocks "waterloggable"


MrNoodles75

Recommended Posts

18 hours ago, MrNoodles75 said:

surly you would just overwrite a method in Blocks.java, right?

 

What? What are you trying to do? Create your own block or edit vanilla blocks?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

10 hours ago, kaydogz said:

you can use the interface IWaterLoggable

This is only true for creating your own blocks, the OP seems to be looking for something else. Also this is not sufficient. You also have to add the WATERLOGGED property to your block's blockstatecontainer.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

On 9/22/2019 at 10:10 AM, Draco18s said:

This is only true for creating your own blocks, the OP seems to be looking for something else. Also this is not sufficient. You also have to add the WATERLOGGED property to your block's blockstatecontainer.

@Draco18s sorry that I couldn't say earlier as I was away for the weekend and couldn't look at my posts.

but I am trying to create my own blocks and I want to make them waterloggable

Link to comment
Share on other sites

I had to ask because of the portion I bolded earlier.

 

Water logged blocks are easy. Implement the interface and add the property to the blockstatecontainer.

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/block/SluiceOutput.java#L22

 

Note that blocks can only contain water sources currently, even though they can return any fluid state:

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/block/SluiceOutput.java#L40

Returning anything else results in a block that is not waterlogged.

 

(Do note that my block there is always waterlogged and can't exist in a non-waterlogged state, as I'm using that property to fake a water source block without it actually *being* a water source block.)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Here is what happens:

1111098521_ScreenShot2019-09-23at10_56_09AM.png.ab269366f45d70a819b4942210daf756.png

and here is my code so far i don't know what is wrong:

 
 
0
 Advanced issues found
 
 
Spoiler

package com.runningmanstudios.extrablocks.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.network.NetworkHooks;

import javax.annotation.Nullable;

public class NautilusStatue extends Block implements IWaterLoggable {
    public static AxisAlignedBB blocksize = new AxisAlignedBB(1 - 0.125, 0.600, 1 - 0.125, 0.125, 0, 0.125);


    public NautilusStatue() {
        super(Properties.create(Material.WATER)
                .sound(SoundType.WOOD)
                .hardnessAndResistance(20.0f)
                .lightValue(10)
                .harvestTool(ToolType.PICKAXE)
        );
        setDefaultState(stateContainer.getBaseState().with(BlockStateProperties.WATERLOGGED, true));
    }

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
        if (entity != null) {
            world.setBlockState(pos, state.with(BlockStateProperties.FACING, getFacingFromEntity(pos, entity)), 2);
        }
    }

    @Override
    public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult result) {
        if (!world.isRemote) {
            TileEntity tileEntity = world.getTileEntity(pos);
            if (tileEntity instanceof INamedContainerProvider) {
                NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
            } else {
                throw new IllegalStateException("Our named container provider is missing!");
            }
            return true;
        }
        return super.onBlockActivated(state, world, pos, player, hand, result);
    }

    public static Direction getFacingFromEntity(BlockPos clickedBlock, LivingEntity entity) {
        return Direction.getFacingFromVector((float) (entity.posX - clickedBlock.getX()), (float) (entity.posY - clickedBlock.getY()), (float) (entity.posZ - clickedBlock.getZ()));
    }

    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(BlockStateProperties.WATERLOGGED, BlockStateProperties.FACING);
    }

    @Override
    @Deprecated
    public BlockRenderLayer getRenderLayer() {
        return BlockRenderLayer.CUTOUT;
    }

    public IFluidState getFluidState(BlockState state) {
        return Fluids.WATER.getStillFluidState(false);
    }

    public boolean receiveFluid(IWorld worldIn, BlockPos pos, BlockState state, IFluidState fluidStateIn) {
        return IWaterLoggable.super.receiveFluid(worldIn, pos, state, fluidStateIn);
    }

    public boolean canContainFluid(IBlockReader worldIn, BlockPos pos, BlockState state, Fluid fluidIn) {
        return true;//state.get(TYPE) != SlabType.DOUBLE ? IWaterLoggable.super.canContainFluid(worldIn, pos, state, fluidIn) : false;
    }

    @Deprecated
    public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
        if (!stateIn.get(BlockStateProperties.WATERLOGGED)) {
            this.receiveFluid(worldIn, currentPos, stateIn, Fluids.WATER.getStillFluidState(false));
        }
        worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
        return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
    }
    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        return VoxelShapes.create(blocksize);
    }

    public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
        worldIn.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
    }

    public Fluid pickupFluid(IWorld worldIn, BlockPos pos, BlockState state) {
        return Fluids.EMPTY;
    }

   /*@Override
   @Deprecated
   public boolean isReplaceable(BlockState state, BlockItemUseContext useContext) {
      return true;
   }*/
}

 

Edited by MrNoodles75
Link to comment
Share on other sites

1) What does the log say about the error?

2) Looks like you just copied my entire class without regards to what I said regarding what I was using it for that is entirely non-standard.

3) You haven't shown your registration code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

1) What does the log say about the error?

2) Looks like you just copied my entire class without regards to what I said regarding what I was using it for that is entirely non-standard.

3) You haven't shown your registration code.

@Draco18s

 

1) I don't know I didn't check, sorry

2) Yes, I did because you said just add it your blockstatecontainer but in your class that you showed and from what I could find from vanilla classes is that they all had stuff like onBlockActivated, canContainFluid and updatePostPlacement and I became unsure.

3) if you mean setRegistryName then I saw that and I added it and now it works and the game opens. and I may seem stupid scince I don't know if you said this already so I'll say sorry in advance, but now it's always waterlogged.

Edited by MrNoodles75
Link to comment
Share on other sites

2 hours ago, MrNoodles75 said:

2) Yes, I did because you said just add it your blockstatecontainer but in your class that you showed and from what I could find from vanilla classes is that they all had stuff like onBlockActivated, canContainFluid and updatePostPlacement and I became unsure.

Look at the vanilla blocks for standard implementation.

 

2 hours ago, MrNoodles75 said:

but now it's always waterlogged.

...yes:

6 hours ago, Draco18s said:

my block there is always waterlogged

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.