11package huix .infinity .common .world .block ;
22
3+ import huix .infinity .attachment .IFWAttachment ;
34import huix .infinity .common .world .block .entity .AnvilBlockEntity ;
4- import huix .infinity .common .world .block .entity .IFWFurnaceBlockEntity ;
5- import huix .infinity .common .world .inventory .IFWAnvilMenu ;
65import huix .infinity .common .world .inventory .IFWCopperAnvilMenu ;
76import huix .infinity .common .world .item .tier .IFWTiers ;
87import huix .infinity .util .DurabilityHelper ;
1716import net .minecraft .world .entity .item .FallingBlockEntity ;
1817import net .minecraft .world .inventory .ContainerLevelAccess ;
1918import net .minecraft .world .item .ItemStack ;
19+ import net .minecraft .world .item .alchemy .PotionContents ;
20+ import net .minecraft .world .item .alchemy .Potions ;
2021import net .minecraft .world .level .Level ;
2122import net .minecraft .world .level .block .AnvilBlock ;
2223import net .minecraft .world .level .block .EntityBlock ;
23- import net .minecraft .world .level .block .FallingBlock ;
2424import net .minecraft .world .level .block .entity .BlockEntity ;
2525import net .minecraft .world .level .block .state .BlockState ;
2626
@@ -44,12 +44,12 @@ public IFWAnvilBlock(Properties properties, IFWTiers tier, int stage) {
4444 @ Override
4545 protected void onPlace (BlockState state , Level level , BlockPos pos , BlockState oldState , boolean isMoving ) {
4646 if (canPlace (state , level , pos , oldState )) {
47- ServerLevel worldIn = (ServerLevel ) level ;
48- int durability = (( AnvilBlockEntity ) worldIn . getBlockEntity ( pos )). durability ( );
49- if (durability < this .maxDurability ()) {
47+ AnvilBlockEntity blockEntity = (AnvilBlockEntity ) level . getBlockEntity ( pos ) ;
48+ int damage = blockEntity . getData ( IFWAttachment . anvil_damage . get () );
49+ if (damage < this .maxDurability ()) {
5050 ItemStack result = new ItemStack (this .asItem ());
51- result .set (DataComponents .DAMAGE , durability );
52- popResource (worldIn , pos , result );
51+ result .set (DataComponents .DAMAGE , damage );
52+ popResource (level , pos , result );
5353 }
5454 }
5555 super .onPlace (state , level , pos , oldState , isMoving );
@@ -60,14 +60,19 @@ private boolean canPlace(BlockState state, Level level, BlockPos pos, BlockState
6060 && !(state .getBlock () instanceof AnvilBlock );
6161 }
6262
63+ @ Override
64+ public ItemStack ifw_defaultInstance () {
65+ ItemStack itemstack = super .ifw_defaultInstance ();
66+ itemstack .set (DataComponents .MAX_DAMAGE , this .maxDurability ());
67+ itemstack .set (DataComponents .DAMAGE , this .initalDurability ());
68+ return itemstack ;
69+ }
70+
6371 @ Override
6472 protected void tick (BlockState state , ServerLevel level , BlockPos pos , RandomSource random ) {
6573 if (isFree (level .getBlockState (pos .below ())) && pos .getY () >= level .getMinBuildHeight ()) {
66- CompoundTag nbtCompound = new CompoundTag ();
67- nbtCompound .putInt ("Durability" , ((AnvilBlockEntity )level .getBlockEntity (pos )).durability ());
68- FallingBlockEntity fallingblockentity = FallingBlockEntity .fall (level , pos , state );
69- fallingblockentity .blockData = nbtCompound ;
70- this .configureFallingBlockEntity (fallingblockentity );
74+ AnvilBlockEntity blockEntity = (AnvilBlockEntity ) level .getBlockEntity (pos );
75+ blockEntity .setData (IFWAttachment .anvil_damage .get (), blockEntity .damage ());
7176 }
7277
7378 super .tick (state , level , pos , random );
@@ -78,10 +83,10 @@ protected void configureFallingBlockEntity(FallingBlockEntity entity) {
7883 }
7984
8085 @ Nullable
81- public BlockState damage (int value , BlockEntity tileEntityAnvil ) {
86+ public BlockState ifw_damage (int value , BlockEntity tileEntityAnvil ) {
8287 if (tileEntityAnvil instanceof AnvilBlockEntity anvilBlockEntity ) {
83- anvilBlockEntity .durability (anvilBlockEntity .durability () + value );
84- return this .getBrokeState (anvilBlockEntity .durability ());
88+ anvilBlockEntity .damage (anvilBlockEntity .damage () + value );
89+ return this .getBrokeState (anvilBlockEntity .damage ());
8590 } else {
8691 return null ;
8792 }
@@ -91,9 +96,9 @@ public BlockState damage(int value, BlockEntity tileEntityAnvil) {
9196 public BlockState getBrokeState (int currentDamage ) {
9297 if (currentDamage > this .maxDurability ())
9398 throw new IllegalArgumentException ("IFWAnvilBlock.GetBrokeState error" );
94-
95- if (currentDamage <= this .maxDurability () * 0.5F ) return this .getDamagedState ();
96- else if (currentDamage >= this .maxDurability () * 0.8F ) return this .defaultBlockState ();
99+ int currentDurability = this . maxDurability () - currentDamage ;
100+ if (currentDurability <= this .maxDurability () * 0.5F ) return this .getDamagedState ();
101+ else if (currentDurability >= this .maxDurability () * 0.8F ) return this .defaultBlockState ();
97102 else return this .getChippedState ();
98103 }
99104
0 commit comments