Jump to content

Recommended Posts

Posted

What do I add to this exact code to make it so that the pig will only drop a "pig soul" when holding (a.k.a killing the pig with) a certain sword?

 

//Pig Soul
@SubscribeEvent
public void addEntityDrop5 (LivingDropsEvent event) {
	if (event.entity instanceof EntityPig) {
		ItemStack itemstack = new ItemStack(MASouls.PigSoul, 1);
		event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
	}
}

Posted

What do I add to this exact code to make it so that the pig will only drop a "pig soul" when holding (a.k.a killing the pig with) a certain sword?

 

//Pig Soul
@SubscribeEvent
public void addEntityDrop5 (LivingDropsEvent event) {
	if (event.entity instanceof EntityPig) {
		ItemStack itemstack = new ItemStack(MASouls.PigSoul, 1);
		event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
	}
}

Posted

  • Do not add to
    event.drops

    directly, simply use the

    Entity#entityDropItem

    method.

 

Unless I'm mistaken, that won't add to the event's drops list.

Entity#entityDropItem

only captures the drop when

Entity#captureDrops

is

true

, this is set to

true

before the entity's loot is dropped and then set back to

false

before

LivingDropsEvent

is fired.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

  • Do not add to
    event.drops

    directly, simply use the

    Entity#entityDropItem

    method.

 

Unless I'm mistaken, that won't add to the event's drops list.

Entity#entityDropItem

only captures the drop when

Entity#captureDrops

is

true

, this is set to

true

before the entity's loot is dropped and then set back to

false

before

LivingDropsEvent

is fired.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I have this code for a pickaxe where I mine the block and it removes the current drops and adds in another, and this only works if using the specific pickaxe, this is what I want to do for the sword against mobs but can't figure it out?

 

//Blaze Pickaxe Blocks
//Cobblestone Into Stone
@SubscribeEvent
public void addBlockDrop1 (HarvestDropsEvent event) {
	if (event.state.getBlock() == Blocks.cobblestone) {

		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {
			event.drops.clear();
			event.drops.add(new ItemStack(Blocks.stone));
		}
	}
}

Posted

I have this code for a pickaxe where I mine the block and it removes the current drops and adds in another, and this only works if using the specific pickaxe, this is what I want to do for the sword against mobs but can't figure it out?

 

//Blaze Pickaxe Blocks
//Cobblestone Into Stone
@SubscribeEvent
public void addBlockDrop1 (HarvestDropsEvent event) {
	if (event.state.getBlock() == Blocks.cobblestone) {

		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {
			event.drops.clear();
			event.drops.add(new ItemStack(Blocks.stone));
		}
	}
}

Posted

Your prior code should work. I don't see anything wrong with it.

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.

Posted

Your prior code should work. I don't see anything wrong with it.

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.

Posted

Oh you didn't check what sword the player is holding.  This line equivalent:

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

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.

Posted

Oh you didn't check what sword the player is holding.  This line equivalent:

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

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.

Posted

So is that all I have to do is add this in:

 

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

but change "MABlazePickaxeTool" to the swords class? And that's literally it? Because I can see this going towards me trying it like that then it not working asking a stupid question and people moan at me? xD

Posted

So is that all I have to do is add this in:

 

if (holding != null && holding.getItem() instanceof MABlazePickaxeTool) {

but change "MABlazePickaxeTool" to the swords class? And that's literally it? Because I can see this going towards me trying it like that then it not working asking a stupid question and people moan at me? xD

Posted

Yep

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.

Posted

Yep

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.

Posted

Okay what about the "holding" variable? What would I set that to?

 

New current code:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			if (holding != null && holding.getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

Posted

Okay what about the "holding" variable? What would I set that to?

 

New current code:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			if (holding != null && holding.getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

Posted

Never mind I figured it outs, thanks a lot :D

 

Edit: Actually there's on more question, I'm now using this as my code for the specific sword:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			Object holding = new ItemStack(MAItems.SoulHarvester);
			if (holding  != null && ((ItemStack) holding).getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

 

What code do I add, and where do I add it for a drop chance? So like if I wanted the soul to only drop 10% of the time how would I do this?

Posted

Never mind I figured it outs, thanks a lot :D

 

Edit: Actually there's on more question, I'm now using this as my code for the specific sword:

 

//Cow Soul
	@SubscribeEvent
	public void addEntityDrop50 (LivingDropsEvent event) {
		if (event.entity instanceof EntityCow) {
			Object holding = new ItemStack(MAItems.SoulHarvester);
			if (holding  != null && ((ItemStack) holding).getItem() instanceof MASoulHarvester) {
			ItemStack itemstack = new ItemStack(MASouls.CowSoul, 1);
			event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, itemstack));
		}
	}
}

 

What code do I add, and where do I add it for a drop chance? So like if I wanted the soul to only drop 10% of the time how would I do this?

Posted

Do you actually understand what your code is doing?

 

You're creating a new

ItemStack

of

MAItems.SoulHarvester

and then immediately checking if it's an

ItemStack

of

MAItems.SoulHarvester

. This will always be

true

, so it's completely pointless.

 

You need to get the entity that did the killing from the

DamageSource

and then check its held item (like diesieben07 told you in the first reply).

 

For random chances, use

Random#nextInt

to generate a random number, then check if it's in a specific range; e.g.

random.nextInt(100) < 10

will be

true

10% of the time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Do you actually understand what your code is doing?

 

You're creating a new

ItemStack

of

MAItems.SoulHarvester

and then immediately checking if it's an

ItemStack

of

MAItems.SoulHarvester

. This will always be

true

, so it's completely pointless.

 

You need to get the entity that did the killing from the

DamageSource

and then check its held item (like diesieben07 told you in the first reply).

 

For random chances, use

Random#nextInt

to generate a random number, then check if it's in a specific range; e.g.

random.nextInt(100) < 10

will be

true

10% of the time.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Guest
This topic is now closed to further replies.

Announcements




  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Oh I forgot to update the title. I figured out the issue and I'm rather embarrassed to say that it was a file path issue. The game already knew I was accessing the achievements so I wasn't suppose to include advancements in the file path. Minecraft file paths have always confused me a little bit... ResourceLocation advancementId = new ResourceLocation( TheDeadRise.MODID,"adventure/spawntrigger");
    • Can someone help my with this? My forge server won't open and I'm not that good with this stuff. It gave me this error message:   C:\Users\apbeu\Desktop\Forge server>java -Xmx4G -Xms1G -jar server.jar nogui 2024-12-11 18:21:01,054 main WARN Advanced terminal features are not available in this environment [18:21:01] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.34, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [18:21:01] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.1.3+8.1.3+main-8.1.x.c94d18ec starting: java version 21.0.4 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x402e37bc) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x402e37bc         at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:45)         at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95)         at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:45)         at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55)         at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52)         at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47)         at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62)         at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55)         at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)         at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63)         at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60)         at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) C:\Users\apbeu\Desktop\Forge server>pause
    • Here is the url for the crash report if anyone can help me, please. https://mclo.gs/KGn5LWy  
    • Every single time I try and open my modpack it crashes before the game fully opens and I don't know what is wrong. I open the crash logs but I don't understand what any of it means. What do I do?
    • Hey, sorry I haven't said anything in a while. I was banned on here for sending you straight up crash logs and they banned me for spam... but I learned that these forums are for forge only and I was working with neoforge... but thank you for all the help.
  • Topics

×
×
  • Create New...

Important Information

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