Jump to content

Making single vanilla items have lower max durability (maybe using enchantment)


KoadMaster

Recommended Posts

So, in general, I am trying to make something that increases the rate at which am vanilla item runs out of durability. My first thought was to somehow decrease the max durability of only the particular item that the player has (I don't want to make all items of that type have less durability, only the ones that are debuffed). However, this is either really hard, or I am missing something simple. Therefor I thought that it would certainly be possible to make a new enchantment that works essentially the same way as unbreaking, but with the opposite effect (it would remove durability instead of preserve it). I am pretty sure forge has event hooks that could be used to accomplish this, bt I have essentially no knowledge of how to use them. Any help would be appreciated.

-Thank You-

Link to comment
Share on other sites

Durability is stored inside ItemStack of given Item instance (there is only one Item). That data is stack's itemDamage and can be accessed from reference.

 

Stack you can get from player.inventory#something (you should find right method).

Accessing it can be done when you are crafting or inside any method/event that has Player/ ItemStack reference.

 

Tell me - when do you want your faster-degradation debuff applied? On item crafting or in ench table or maybe by some itdk.. spell?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Well, actually it is a furnace like device that repairs tools, however, I want it to give the tool a stacking debuff that will cause it to break faster, therefor making it unrepairble at a certain point (that I have not determined yet). Generally speaking, I worked on it quite a bit since posting and have something that "works" it checks for the NBTT tag called repairCost (used in the anvil) and uses it to keep track of the amount of times it has been repaired, and then simply sets that duration of the item repaired to be less each time. However, I realize that it is probably not the greatest way to go about things as it does potentially cause some incompatibility with the anvil (which in some ways is ok, but if Icould avoid it that would probably be better). So the trouble I have is actually setting a stacking debuff on an item that can be referenced by the repairing process. As far as your last line, I was thinking it would be coolest if it just broke faster while still looking like it was full, but I think just making it set the current durability to less is simpler and perhaps more user friendly. So basically I want the durability to go down in a crafting type situation, but I have figured out how to do that.

Link to comment
Share on other sites

ItemStack has 3 props:

Item reference it uses, damage and NBT.

 

Trying to improve your system will bring you probably nothing since this: (ItemStack)

public boolean isItemStackDamageable()
    {
        return this.item.getMaxDamage(this) <= 0 ? false : !this.hasTagCompound() || !this.getTagCompound().getBoolean("Unbreakable");
    }

It's hardcoded for only one type of special effect (unbreakable).

 

You can't set maxDamage for one item since it's stored inside Item instance.

 

What you can do is only and only add new NBT or use "repairCost" to affect price/maxRepairValue. Still - it will never work well with anvil, not without ASM or replacing whole Anvil with your own CustomAnvil that will be able to read your system.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I am thinking along the same lines, currently is does work, and having it so that repairing it with my method makes it more expensive to repair on an anvil does sort of make sense (though it is likely that if someone tried to use my repair method on an object that had been repaired in the anvil before hand the object would likely just break, due to how I have it coded, but I guess that is fine). In general, I think I will just be using what I have, hopefully in the future it can be improved, but it works fine enough now. Thank you for you help :)

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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