Jump to content

[1.11.2] HarvestDropsEvent specifying block metadata


Recommended Posts

Posted

Hi again, (seems like I'm coming here every day with a new problem, thanks for the all the help so far everyone!)

 

My current eventhandler stops stone from dropping cobblestone and instead drops my mod item Stone Fragment, but in practice I've noticed that this has also accidentally overridden diorite/granite/andesite drops, and I can't specify metadata like I have in other classes. 

Here's my current code: 

 

public class extvanillaeventhandler {
	
	@SubscribeEvent
	public void onHarvestBlock(BlockEvent.HarvestDropsEvent event) {
		
		if (event.getState().getBlock() == Blocks.STONE) {
			event.getDrops().clear();
			event.getDrops().add(new ItemStack(moditems.fragmentStone, 1));
		}
    }
}

 

I've tried anything I could really think of (I've programmed forge for about 20 hours now) involving how to specify the data of Blocks.STONE but nothing has worked, but knowing Forge the answer won't be as simple as a 1 line change ;P and knowing my luck it will be a 1 line change I didn't think of 

 

Thanks in advance for any help 

Posted (edited)

you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever.

Something like

if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE)

Edit: Here is a documentation that explains blockstates.

Edited by V0idWa1k3r
  • Like 1
Posted
5 minutes ago, V0idWa1k3r said:

you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever.

Something like


if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE)

Edit: Here is a documentation that explains blockstates.

Ah, one of my attempts involved:

if (event.getState().getBlock() == BlockStone.EnumType.STONE)

I was so close! Thanks again Voidwalker!

Posted
25 minutes ago, V0idWa1k3r said:

you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever.

Something like


if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE)

Edit: Here is a documentation that explains blockstates.

Well, it works, but there's a minor error, it disabled drops from every single block in the game that isn't BlockStone hahahahahah

Error: 

Quote

[23:34:46] [Server thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockStone$EnumType, values=[stone, granite, smooth_granite, diorite, smooth_diorite, andesite, smooth_andesite]} as it does not exist in BlockStateContainer{block=minecraft:dirt, properties=[snowy, variant]}
    at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_131]
    at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_131]
    at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:754) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Caused by: java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockStone$EnumType, values=[stone, granite, smooth_granite, diorite, smooth_diorite, andesite, smooth_andesite]} as it does not exist in BlockStateContainer{block=minecraft:dirt, properties=[snowy, variant]}
    at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:204) ~[BlockStateContainer$StateImplementation.class:?]
    at com.kayfour.extvanilla.events.extvanillaeventhandler.onHarvestBlock(extvanillaeventhandler.java:23) ~[extvanillaeventhandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_extvanillaeventhandler_onHarvestBlock_HarvestDropsEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) ~[EventBus.class:?]
    at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:271) ~[ForgeEventFactory.class:?]
    at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:693) ~[Block.class:?]
    at net.minecraft.block.Block.dropBlockAsItem(Block.java:681) ~[Block.class:?]
    at net.minecraft.block.Block.harvestBlock(Block.java:893) ~[Block.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:356) ~[PlayerInteractionManager.class:?]
    at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:264) ~[PlayerInteractionManager.class:?]
    at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:675) ~[NetHandlerPlayServer.class:?]
    at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) ~[CPacketPlayerDigging.class:?]
    at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) ~[CPacketPlayerDigging.class:?]
    at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_131]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_131]
    at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?]
    ... 5 more

By the way it presents itself it looks like a bug in Minecraft itself? 

Quote

Cannot get property PropertyEnum{} as it does not exist in BlockStateContainer{} at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

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