Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] How To Make A Strippable Log Block.


Recommended Posts

Can't seem to find much about how to make this work and trying to use code from open source mods doesn't help, Tried using AxeItem.Strippables but that doesn't work either. I'm wondering if there's an easy vanilla way to do this. Googling it doesn't seem to help me either.

Link to post
Share on other sites
Posted (edited)

Okay, I got it working correctly now, but I'm not sure how to make it work with multiple blocks.

 

My Block Code:

 

package expanded.blocks;

import javax.annotation.Nullable;

import expanded.VanillaBuildingBlocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;

public class CustomLog extends RotatedPillarBlock {
      
    public CustomLog(Properties properties) {
        super(properties);
    }
  
  @Override
    @Nullable
    public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {
        return toolType == ToolType.AXE ? VanillaBuildingBlocks.acacia_log.defaultBlockState() : null;

    }
}

Edited by immortalcatz
Link to post
Share on other sites
Posted (edited)

whenever i add more then one log type and i right click it turns into the acacia log, not it's own stripped version.... I'm using vanilla blocks to test it with so I know it's working.

 

*edit: like if I make a spruce and right click with an axe, the spruce log turns into the acacia log, not the stripped version, but the acacia log turns into stripped acacia.

Edited by immortalcatz
Link to post
Share on other sites
4 minutes ago, immortalcatz said:

whenever i add more then one log type and i right click it turns into the acacia log, not it's own stripped version.... I'm using vanilla blocks to test it with so I know it's working.

 

*edit: like if I make a spruce and right click with an axe, the spruce log turns into the acacia log, not the stripped version, but the acacia log turns into stripped acacia.

of course, because you're registering the same class, and in the class you harcoded it to return acacia

what you can do is to write one class per log block

or make a StrippableLog class, which takes a supplier of the block you want to return in the constructor

Edited by kiou.23
Link to post
Share on other sites
2 minutes ago, immortalcatz said:

how would I do that with the Strippable Log class?

the first way I thought of is to take a supplier of the stripped block in the constructor, and then return that in the proper method

Link to post
Share on other sites
Just now, immortalcatz said:

Not sure how I would do that, should I just make the stripped block extend Block or use something else like RotatdPillarBlock?

yes? you already have the class you called CustomLog, it's the same thing isn't it?

Link to post
Share on other sites

Found a version of what I was trying to do on github, had to tweak it a bit to make it updated to 1.16.5 tho....

 

package expanded.blocks;

import javax.annotation.Nullable;

import expanded.VanillaBuildingBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;

public class CustomLog extends RotatedPillarBlock {
      
    public CustomLog(Properties properties) {
        super(properties);
    }
  
    @Override
    @Nullable
    public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {
          Block block = state.getBlock();
          if (block == VanillaBuildingBlocks.acacia_log) {
              return VanillaBuildingBlocks.stripped_acacia_log.defaultBlockState();
          } else if (block == VanillaBuildingBlocks.spruce_log) {
              return VanillaBuildingBlocks.stripped_spruce_log.defaultBlockState();
          } else {
              return super.getToolModifiedState(state, world, pos, player, stack, toolType);
          }
          
    }
}

 

in case anyone else needs it.... This is solved now, thanks for all the help. ^^

Link to post
Share on other sites
6 minutes ago, immortalcatz said:

Found a version of what I was trying to do on github, had to tweak it a bit to make it updated to 1.16.5 tho....

 

package expanded.blocks;

import javax.annotation.Nullable;

import expanded.VanillaBuildingBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.RotatedPillarBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;

public class CustomLog extends RotatedPillarBlock {
      
    public CustomLog(Properties properties) {
        super(properties);
    }
  
    @Override
    @Nullable
    public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {
          Block block = state.getBlock();
          if (block == VanillaBuildingBlocks.acacia_log) {
              return VanillaBuildingBlocks.stripped_acacia_log.defaultBlockState();
          } else if (block == VanillaBuildingBlocks.spruce_log) {
              return VanillaBuildingBlocks.stripped_spruce_log.defaultBlockState();
          } else {
              return super.getToolModifiedState(state, world, pos, player, stack, toolType);
          }
          
    }
}

 

in case anyone else needs it.... This is solved now, thanks for all the help. ^^

that works... but makes the code really hard to mantain and expand upon, imagine you add 50 logs, you'd have 50 else-if statements?

the best solution I already told you 2 times, and now the 3rd: simply pass the stripped block to the constructor, and return it in the getToolModifiedState

also, you're not checking if the tool is an axe, so any tool would be able to strip the log block

EDIT: also, if you need to look up something this basic on github, maybe you should take some time to learn programming beforehand, that'll really make your life modding easier

Edited by kiou.23
Link to post
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.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.