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

[1.13.2][Solved]Generating lava when breaking a block?


aquila_zyy
 Share

Recommended Posts

Hi, thanks for the help! I'm trying to make a block which if you mine it without silk touch or are not using a proper tool, it will leave a block of lava. I overridden the harvestBlock method in my block's class, and here is the code:

@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
    player.addStat(StatList.BLOCK_MINED.get(this));
    player.addExhaustion(0.005F);
    if (this.canSilkHarvest(state, worldIn, pos, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        NonNullList<ItemStack> items = NonNullList.create();
        ItemStack itemstack = this.getSilkTouchDrop(state);
        if (!itemstack.isEmpty()) items.add(itemstack);
        net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
        items.forEach(e -> spawnAsEntity(worldIn, pos, e));
    } else {
        harvesters.set(player);
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
        state.dropBlockAsItem(worldIn, pos, i);
        harvesters.set(null);
        worldIn.setBlockState(pos, Blocks.LAVA.getDefaultState());
    }

    if (!player.canHarvestBlock(state))
    {
        worldIn.setBlockState(pos, Blocks.LAVA.getDefaultState());
    }
}

Now the silk touch part is working fine (it probably should because I just copied them from Block class), but when I mine it with an iron pickaxe, nothing happens. I think I misused the method canHarvestBlock. 

By the way, this block's material is ROCK, and required harvestLevel 3 or higher.

Edited by aquila_zyy
Problem solved
Link to comment
Share on other sites

Just now, aquila_zyy said:

Oh I see. Did not expect such a quick reply, thanks. I’m kinda busy right now, any suggestions on which method I should use? I’ll look into it later.

 

4 hours ago, V0idWa1k3r said:

Block#harvestBlock isn't called if the block isn't actually harvested(broken by the right tool). You need to use a different method.

 

And sorry for the slow reply. I had 502 problem for several hours connecting forge forum.

Link to comment
Share on other sites

I get it now. Here's the working code:

@Override
public void onPlayerDestroy(IWorld worldIn, BlockPos pos, IBlockState state)
{
    ((World)worldIn).setBlockState(pos, Blocks.LAVA.getDefaultState());
}

@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
    player.addStat(StatList.BLOCK_MINED.get(this));
    player.addExhaustion(0.005F);
    if (this.canSilkHarvest(state, worldIn, pos, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        NonNullList<ItemStack> items = NonNullList.create();
        ItemStack itemstack = this.getSilkTouchDrop(state);
        if (!itemstack.isEmpty()) items.add(itemstack);
        net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
        items.forEach(e -> spawnAsEntity(worldIn, pos, e));
        worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
    } else {
        harvesters.set(player);
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
        state.dropBlockAsItem(worldIn, pos, i);
        harvesters.set(null);
    }
}

 

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Basically a backpack, I would like to know how to store this type of variable inside my Item. What should I use? Item Nbt and json serialize? how?
    • Hey Guys, my Server crashed randomly when my friend clicked on the wandering Traider. Similar Cras happend when he placed multiple Backpacks next to each other. I think its the End Remastered Mod but i could never just remove it cuz of the Progress we've made there. Can someone help me i would be very thankful. Thats the Crash Log:   java.lang.NoSuchMethodError: 'net.minecraft.util.text.ITextComponent net.minecraft.util.text.ITextComponent.func_244388_a(java.lang.String)'     at com.teamremastered.endrem.items.ERMap.createMap(ERMap.java:43) ~[endrem:5.0-R-1.16.5] {re:classloading}     at com.teamremastered.endrem.items.ERMap$ERMapTrade.func_221182_a(ERMap.java:54) ~[endrem:5.0-R-1.16.5] {re:classloading}     at net.minecraft.entity.merchant.villager.AbstractVillagerEntity.func_213717_a(AbstractVillagerEntity.java:235) ~[?:?] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:mixin:APP:supplementaries.mixins.json:AbstractVillagerEntityMixin,pl:mixin:APP:survive.mixins.json:AbstractVillagerEntityMixin,pl:mixin:APP:architectury-common.mixins.json:AbstractVillagerMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.entity.merchant.villager.WanderingTraderEntity.func_213712_ef(SourceFile:129) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:architectury-common.mixins.json:WanderingTraderMixin,pl:mixin:A}     at net.minecraft.entity.merchant.villager.AbstractVillagerEntity.func_213706_dY(AbstractVillagerEntity.java:99) ~[?:?] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:mixin:APP:supplementaries.mixins.json:AbstractVillagerEntityMixin,pl:mixin:APP:survive.mixins.json:AbstractVillagerEntityMixin,pl:mixin:APP:architectury-common.mixins.json:AbstractVillagerMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.entity.merchant.villager.WanderingTraderEntity.func_230254_b_(SourceFile:105) ~[?:?] {re:mixin,re:classloading,pl:mixin:APP:architectury-common.mixins.json:WanderingTraderMixin,pl:mixin:A}     at net.minecraft.entity.MobEntity.func_184230_a(MobEntity.java:1049) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:pehkui.mixins.json:MobEntityMixin,pl:mixin:APP:library_of_exile-mixins.json:MobEntityMixin,pl:mixin:APP:environmental.mixins.json:MobEntityMixin,pl:mixin:APP:buzzier_bees.mixins.json:MobEntityMixin,pl:mixin:APP:charm.mixins.json:accessor.MobEntityAccessor,pl:mixin:APP:pehkui.mixins.json:compat116plus.MobEntityMixin,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.entity.player.PlayerEntity.func_190775_a(PlayerEntity.java:940) ~[?:?] {re:computing_frames,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:PlayerEntityMixin,pl:mixin:APP:origins.mixins.json:PlayerEntityMixin,pl:mixin:APP:mixins.adorn.json:PlayerEntityMixin,pl:mixin:APP:dungeons_gear.mixins.json:PlayerEntityMixin,pl:mixin:APP:pehkui.mixins.json:EntityVehicleHeightOffsetMixin,pl:mixin:APP:pehkui.mixins.json:PlayerEntityMixin,pl:mixin:APP:pehkui.mixins.json:compat115plus.PlayerEntityMixin,pl:mixin:APP:pehkui.mixins.json:compat116minus.PlayerEntityMixin,pl:mixin:APP:pehkui.mixins.json:reach.PlayerEntityMixin,pl:mixin:APP:caelus.mixins.json:PlayerEntityMixin,pl:mixin:APP:tetra.mixins.json:MixinPlayerEntity,pl:mixin:APP:blue_skies.mixins.json:PlayerEntityMixin,pl:mixin:APP:unionlib.mixins.json:PlayerEntityMixin,pl:mixin:APP:ars_nouveau.mixins.json:ElytraPlayerMixin,pl:mixin:APP:survive.mixins.json:PlayerEntityMixin,pl:mixin:APP:environmental.mixins.json:PlayerEntityMixin,pl:mixin:APP:endergetic.mixins.json:PlayerEntityMixin,pl:mixin:APP:personality.mixins.json:PlayerEntityMixin,pl:mixin:APP:charm.mixins.json:PlayerEntityMixin,pl:mixin:APP:charm.mixins.json:accessor.PlayerEntityAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.network.play.ServerPlayNetHandler.func_147340_a(ServerPlayNetHandler.java:1194) ~[?:?] {re:mixin,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B,pl:mixin:APP:randompatches.mixins.json:ServerPlayNetHandlerPlayerSpeedLimitsMixin,pl:mixin:APP:randompatches.mixins.json:timeouts.ServerPlayNetHandlerKeepAliveMixin,pl:mixin:APP:betterendforge.mixins.json:ServerPlayNetHandlerMixin,pl:mixin:APP:origins.mixins.json:ServerPlayNetworkHandlerMixin,pl:mixin:APP:graveyard.mixins.json:ServerPlayNetworkHandlerMixin,pl:mixin:APP:pehkui.mixins.json:ServerPlayNetworkHandlerMixin,pl:mixin:APP:pehkui.mixins.json:reach.ServerPlayNetworkHandlerMixin,pl:mixin:APP:tetra.mixins.json:MixinServerPlayNetHandler,pl:mixin:APP:endergetic.mixins.json:ServerPlayNetHandlerMixin,pl:mixin:A}     at net.minecraft.network.play.client.CUseEntityPacket.func_148833_a(SourceFile:74) ~[?:?] {re:classloading}     at net.minecraft.network.play.client.CUseEntityPacket.func_148833_a(SourceFile:13) ~[?:?] {re:classloading}     at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21) ~[?:?] {re:mixin,re:classloading}     at net.minecraft.util.concurrent.TickDelayedTask.run(SourceFile:18) ~[?:?] {re:classloading}     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144) ~[?:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}     at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23) ~[?:?] {re:mixin,re:computing_frames,re:classloading}     at net.minecraft.server.MinecraftServer.func_213166_h(MinecraftServer.java:734) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.server.MinecraftServer.func_213166_h(MinecraftServer.java:159) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118) ~[?:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.func_213205_aW(MinecraftServer.java:717) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.server.MinecraftServer.func_213168_p(MinecraftServer.java:711) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103) ~[?:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}     at net.minecraft.server.MinecraftServer.func_213202_o(MinecraftServer.java:696) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:646) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at net.minecraft.server.MinecraftServer.func_240783_a_(MinecraftServer.java:232) ~[?:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:betterendforge.mixins.json:MinecraftServerMixin,pl:mixin:APP:structure_gel.mixins.json:MinecraftServerMixin,pl:mixin:APP:paxi.mixins.json:MixinMinecraftServer,pl:mixin:APP:byg.mixins.json:server.MixinMinecraftServer,pl:mixin:APP:mixins.shrines.json:MixinMinecraftServer,pl:mixin:APP:roadrunner.mixins.json:world.light_batching.MinecraftServerMixin,pl:mixin:APP:charm.mixins.json:accessor.MinecraftServerAccessor,pl:mixin:A,pl:runtimedistcleaner:A}     at java.lang.Thread.run(Thread.java:832) [?:?] {}  
    • now I have this issue https://gist.github.com/xquao/34697afb553a8c4b75d61995b7602aa1  
    • alredy passed this issue, problem was with one of mods, now trying to find it
  • Topics

×
×
  • Create New...

Important Information

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