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

Armor damage with random


Cris16228
 Share

Recommended Posts

Hello guys,

I was trying to create a "Revival" status effect with a debuff on it, basically, if you wear the armor it set your health to 0.5 (Half hearth), it adds a regen effect and it damages the armor

this is my revival class:

Spoiler

@EventBusSubscriber
public class EventHandler {

	private static Random random = new Random();

	@SubscribeEvent
	public static void onDeath(LivingDeathEvent event) {
		if (event.getEntityLiving() instanceof EntityPlayer) {
			EntityPlayer player = (EntityPlayer) event.getEntityLiving();
			boolean isActive = false;
			boolean damageArmor = false;
			int min = Config.revivaldamagemin;
			int max = Config.revivaldamagemax;
			int randomDamage = random.nextInt(max - min + 1) + min;
			if (player.isPotionActive(InitPotions.REVIVAL_EFFECT))
				isActive = true;
			if (Config.revivaldamagearmor == true)
				damageArmor = true;

			if (isActive) {
				event.setCanceled(true);
				player.setHealth(0.5F);
				player.addPotionEffect(new PotionEffect(Potion.getPotionById(10),
						10 * 20, 3));

				if (damageArmor) {
					if (player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(1) != null
							&& player.inventory.armorItemInSlot(2) != null
							&& player.inventory.armorItemInSlot(3) != null) {
						player.inventory.damageArmor(randomDamage);
						player.sendMessage(new TextComponentString("Danno: " + String.valueOf(randomDamage)));
					}
				}
			}
		}
	}
}

 

 

I tried to debug it with a send message with the random number (Sorry for the String "Danno:  " but I'm Italian) and in chat it gives me random damage from 5 (min in config) to 13 (max in config) but the armor takes only a bit of damage and not full.

Does

player.inventory.damageArmor(randomDamage);

make an addition of the random and does it as damage to armor pieces?

Do I have to use something else? I want to damage all the armor with the random int given by the random and if I can ask how can I kill ( /kill {player} ) someone if he has the revival effect?

2019-02-17_14.19.52.png

2019-02-17_14.20.21.png

Link to comment
Share on other sites

1. 

47 minutes ago, Cris16228 said:

if (player.inventory.armorItemInSlot(0) != null && player.inventory.armorItemInSlot(1) != null && player.inventory.armorItemInSlot(2) != null && player.inventory.armorItemInSlot(3) != null)

ItemStack does not support null. Use ItemStack#isEmpty instead.

 

2. You are not doing anything to make the armor take randomized damage, so of course it will only take one damage at a time.

 

3. 

47 minutes ago, Cris16228 said:

Does


player.inventory.damageArmor(randomDamage);

make an addition of the random and does it as damage to armor pieces?

No (and I don't see why it should). You have to implement the randomized damage part yourself.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

2 hours ago, DavidM said:

1. 

ItemStack does not support null. Use ItemStack#isEmpty instead.

That's why if I wear an armor with a custom effect Minecraft crashes saying that the error is in the check line?????

(No, keep crash)

 

Thanks, I fixed it

Edited by Cris16228
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

    • Unknown module securejarhandler implies that some libraries were missed during the installation. I suggest you redownload the latest installer and run it again.
    • Forge Version: 38.0.6 Minecraft Version: 1.18 Downloads: Changelog: (Direct) Installer: (AdFocus) (Direct) MDK: (AdFocus) (Direct) However, as this is the start of a new version, it is recommended that you check the Downloads Page and use the latest version to receive any bug fixes. Intro: 1.17 was a stepping stone, and 1.18 is the real target. The culmination of the Caves & Cliffs update, with few real code changes from 1.17 except those required to plug in the new biome system. This is our new Latest version. As we had some time before the release, we handled some refactors beforehand. Those will be listed here. Changelog: Refactors (not comprehensive): 99% of the fmllegacy package. Most classes were simply moved from x.y.fmllegacy.z to x.y.z. All instances of Gui -> Screen (GuiOpenEvent -> ScreenOpenEvent, for example) GuiScreenEvent -> ScreenEvent, GuiOverlayDebugForge -> ForgeDebugScreenOverlay All instances of GameMode -> GameType (ClientPlayerChangeGameModeEvent -> ClientPlayerChangedGameTypeEvent, for example) All instances of MatrixStack -> PoseStack (DrawSelectionEvent.matrix -> DrawSelectionEvent.poseStack, for example All instances of KeyBinding -> KeyMapping (ClickInputEvent.keyBinding -> ClickInputEvent.keyMapping, for example All instances of World -> Level All instances of WorldType -> WorldPreset (ForgeHooksClient.getDefaultWorldType -> ForgeHooksClient.getDefaultWorldPreset, for example All instances of NBT -> Tag (BlockSnapshot.getNbt -> BlockSnapshot.getTag, for example) All instances of Container -> Menu (IForgeContainerType -> IForgeMenuType, for example) PlaySoundEvent.sound -> PlaySoundEvent.originalSound PlaySoundEvent.result -> PlaySoundEvent.sound SoundEvent.manager -> SoundEvent.engine SoundEvent.SoundSourceEvent.source -> SoundEvent.SoundSourceEvent.channel FOVUpdateEvent -> FOVModifierEvent EntityViewRenderEvent.FOVModiier -> EntityViewRenderEvent.FieldOfView InputUpdateEvent -> MovementInputUpdateEvent InitScreenEvent.{...Widget...} -> {...Listener...} ForgeItemTagsProvider.func_240521_a_Colored -> copyColored MobSpawnInfoBuilder -> MobSpawnSettingBuilder BasicTrade -> BasicItemListing ModelLoader -> ForgeModelBakery ForgeWorldTypeScreens -> ForgeWorldPresetEditors StackList -> MultItemValue Removals: Entire Animation API IForgeTextureAtlasSprite IForgeItem.{showDurabiityBar, getDurabilityForDisplay, getRGBDurabilityForDisplay} ForgeHooksClient.refreshResources ModelBuilder.gui3d BlockInfo.{updateShift, getShx, getShy, getShz} CapabilityInject CapabilityManager.register ConditionalAdvancement.processConditions IForgeItem.isShield IForgeStructureFeature.{getDefaultSpawnList, getDefaultCreatureSpawnList} Forge's Constants class VanillaResourceType ForgeHooksClient.worldRenderPass (+ accessor) ForgeHooksClient.{preDraw, postDraw, getColorIndex} ScrollPanel.drawBackground Screen.{RenderToolTip, RenderComponentToolTip} ResourceManager.getResourceType LootPool.bonusRolls ForgeConfig - selectiveResourceReload PotionEvent.PotionAddedEvent ClientHooks ModFileResourcePack ResourcePackLoader.getResourcePackFor ResourcePackLoader.IPackInfoFinder ServerLifecycleHooks.buildPackFinder IResourceType ReloadRequirements CommandSetDimension
    • This is the error that I'm getting. WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-exports WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-opens Exception in thread "main" java.lang.module.FindException: Module org.objectweb.asm.util not found, required by org.openjdk.nashorn at java.base/java.lang.module.Resolver.findFail(Resolver.java:893) at java.base/java.lang.module.Resolver.resolve(Resolver.java:192) at java.base/java.lang.module.Resolver.resolve(Resolver.java:141) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:492) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:298) at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:83)   Tried various java versions,   8 and 16 to no avail. even tried bellsoft liberica full jre  and openjre   No clue what is going on and why there are such problems with Java now, seems like Oracle took their ball and wants to go home with the Java project. So many issues with various versions of it.  Any advice? Thanks,.
    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • I was whanting to play the classic crashlanding modpack but...: Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker 2021-12-01 18:40:14 [INFORMAÇÕES] [ForgeModLoader] Forge Mod Loader version 6.4.50.1,345 for Minecraft 1.6.4 loading 2021-12-01 18:40:14 [INFORMAÇÕES] [ForgeModLoader] Java is Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_311, running on Windows 7:amd64:6.1, installed at C:\Program Files\Java\jre1.8.0_311 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod net.minecraftforge.lex.sortfix.CorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod appeng.transformer.AppEngCore does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] [AppEng] Core Init 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod codechicken.core.launch.DepLoader does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod invtweaks.forge.asm.FMLPlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod codechicken.nei.asm.NEICorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod openblocks.OpenBlocksCorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod openmods.OpenModsCorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:15 [INFORMAÇÕES] [STDOUT] Loaded 40 rules from AccessTransformer config file fml_at.cfg 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Found valid fingerprint for Minecraft Forge. Certificate fingerprint e3c3d50c7c986df74c645c0ac54639741c90a557 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Found valid fingerprint for Minecraft. Certificate fingerprint cd99959656f753dc28d863b46769f7f8fbaefcfc 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDOUT] Loaded 110 rules from AccessTransformer config file forge_at.cfg 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Warning: version of CodeChickenLib-universal-1.6.4-, 1.0.0.62 is newer than request 1.0.0.43 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Exception in thread "main" java.lang.NoClassDefFoundError: codechicken/core/launch/CodeChickenCorePlugin 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at codechicken.nei.asm.NEICorePlugin.getASMTransformerClass(NEICorePlugin.java:18) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper.injectIntoClassLoader(CoreModManager.java:97) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.Launch.launch(Launch.java:111) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Caused by: java.lang.ClassNotFoundException: codechicken.core.launch.CodeChickenCorePlugin 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at java.lang.ClassLoader.loadClass(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at java.lang.ClassLoader.loadClass(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     ... 4 more 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Caused by: java.lang.NullPointerException 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at org.objectweb.asm.ClassReader.<init>(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at invtweaks.forge.asm.ContainerTransformer.transform(ContainerTransformer.java:116) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     ... 6 more How do i fix this?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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