Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

1 hour ago, immortalcatz said:

How would I add that into the class file and which one would that be in?

the class for the block you want to make stripabble

  • Author

Ya but I'm not sure how I would actually add/implement it into the class correctly, and then registering the block correctly in my register class.

? Registering the block and overriding a function inside the class are two completely different things

Edited by Turtledove

  • Author

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

  • Author

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

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

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

  • Author

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

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?

  • Author

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.