4545import net .minecraft .world .level .storage .loot .LootTable ;
4646import org .jetbrains .annotations .Contract ;
4747import org .jetbrains .annotations .Nullable ;
48- import org .objectweb .asm .Opcodes ;
4948import org .spongepowered .asm .mixin .Mixin ;
5049import org .spongepowered .asm .mixin .Shadow ;
5150import org .spongepowered .asm .mixin .Unique ;
@@ -63,11 +62,11 @@ public abstract class BrushableBlockEntityMixin extends BlockEntity implements B
6362 @ Unique
6463 private float trailierTales$prevXLerp = 0.5F ;
6564 @ Unique
66- private float trailierTales$targetYLerp = 0. 0F ;
65+ private float trailierTales$targetYLerp = 0F ;
6766 @ Unique
68- private float trailierTales$yLerp = 0. 0F ;
67+ private float trailierTales$yLerp = 0F ;
6968 @ Unique
70- private float trailierTales$prevYLerp = 0. 0F ;
69+ private float trailierTales$prevYLerp = 0F ;
7170 @ Unique
7271 private float trailierTales$targetZLerp = 0.5F ;
7372 @ Unique
@@ -144,41 +143,29 @@ public BrushableBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockSta
144143 public void trailierTales$saveAdditional (ValueOutput output , CallbackInfo info ) {
145144 this .trailierTales$saveTT (output );
146145 if (this .trailierTales$rebrushed ) output .putBoolean ("Rebrushed" , this .trailierTales$rebrushed );
147- if (this .trailierTales$storedLootTable != null && this .trailierTales$storedLootTable != this .lootTable ) {
148- output .putString ("TrailierTalesStoredLootTable" , this .trailierTales$storedLootTable .identifier ().toString ());
149- }
146+ if (this .trailierTales$storedLootTable != null ) output .store ("TrailierTalesStoredLootTable" , LootTable .KEY_CODEC , this .trailierTales$storedLootTable );
150147 }
151148
152- @ Unique
153- private boolean trailierTales$runRebrush ;
154-
155- @ Inject (
156- method = "brush" ,
149+ @ WrapOperation (
150+ method = "brushingCompleted" ,
157151 at = @ At (
158152 value = "INVOKE" ,
159- target = "Lnet/minecraft/world/level/block/entity/BrushableBlockEntity;brushingCompleted(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;)V" ,
160- shift = At .Shift .BEFORE
153+ target = "Lnet/minecraft/world/level/block/BrushableBlock;getTurnsInto()Lnet/minecraft/world/level/block/Block;"
161154 )
162155 )
163- public void trailierTales$rebrushA (long ticks , ServerLevel level , LivingEntity entity , Direction direction , ItemStack stack , CallbackInfoReturnable <Boolean > info ) {
164- if (this .trailierTales$hasCustomItem ) return ;
156+ private Block trailierTales$runRebrush (
157+ BrushableBlock instance , Operation <Block > original ,
158+ ServerLevel level , LivingEntity entity , ItemStack stack
159+ ) {
160+ if (this .trailierTales$hasCustomItem ) return original .call (instance );
165161
166162 final int rebrushLevel = stack .getEnchantments ().getLevel (entity .level ().registryAccess ().lookupOrThrow (Registries .ENCHANTMENT ).getOrThrow (TTEnchantments .REBRUSH ));
167- if (rebrushLevel <= 0 ) return ;
163+ if (rebrushLevel <= 0 ) return original . call ( instance ) ;
168164
169165 final float rebrushChance = this .trailierTales$rebrushed ? 0.05F * rebrushLevel : 0.1F * rebrushLevel ;
170- if ( entity .getRandom ().nextFloat () < rebrushChance ) this . trailierTales$runRebrush = true ;
171- }
166+ final boolean rebrush = entity .getRandom ().nextFloat () < rebrushChance ;
167+ if ( this . trailierTales$hasCustomItem || ! rebrush ) return original . call ( instance );
172168
173- @ WrapOperation (
174- method = "brushingCompleted" ,
175- at = @ At (
176- value = "INVOKE" ,
177- target = "Lnet/minecraft/world/level/block/BrushableBlock;getTurnsInto()Lnet/minecraft/world/level/block/Block;"
178- )
179- )
180- private Block trailierTales$runRebrush (BrushableBlock instance , Operation <Block > original ) {
181- if (!this .trailierTales$runRebrush ) return original .call (instance );
182169 this .trailierTales$rebrushed = true ;
183170 this .lootTable = this .trailierTales$storedLootTable ;
184171 this .brushCount = 0 ;
@@ -197,28 +184,18 @@ public BrushableBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockSta
197184 this .trailierTales$targetItemScale = 0F ;
198185 this .trailierTales$itemScale = 0F ;
199186 this .trailierTales$prevItemScale = 0F ;
200- this .trailierTales$runRebrush = false ;
201- this .item = ItemStack .EMPTY ;
202187 this .lootTableSeed = 0L ;
203188 return instance ;
204189 }
205190
206- @ Inject (
207- method = "tryLoadLootTable" ,
208- at = @ At (
209- value = "FIELD" ,
210- target = "Lnet/minecraft/world/level/block/entity/BrushableBlockEntity;lootTable:Lnet/minecraft/resources/ResourceKey;" ,
211- opcode = Opcodes .PUTFIELD ,
212- shift = At .Shift .AFTER
213- )
214- )
191+ @ Inject (method = "tryLoadLootTable" , at = @ At (value = "RETURN" ))
215192 private void trailierTales$storeLootTable (ValueInput valueInput , CallbackInfoReturnable <Boolean > info ) {
216193 this .trailierTales$storedLootTable = this .lootTable ;
217194 }
218195
219196 @ Inject (method = "setLootTable" , at = @ At ("HEAD" ))
220197 public void trailierTales$setLootTable (ResourceKey <LootTable > lootTable , long lootTableSeed , CallbackInfo info ) {
221- if (lootTable != null ) this .trailierTales$storedLootTable = lootTable ;;
198+ if (lootTable != null ) this .trailierTales$storedLootTable = lootTable ;
222199 }
223200
224201 @ Unique
@@ -308,20 +285,20 @@ public BrushableBlockEntityMixin(BlockEntityType<?> type, BlockPos pos, BlockSta
308285 @ Unique
309286 public void trailierTales$readTT (ValueInput input ) {
310287 this .trailierTales$hitDirection = Direction .byName (input .getStringOr ("TTHitDirection" , "" ));
311- this .trailierTales$targetXLerp = input .getFloatOr ("TargetXLerp" , 0 );
312- this .trailierTales$targetYLerp = input .getFloatOr ("TargetYLerp" , 0 );
313- this .trailierTales$targetZLerp = input .getFloatOr ("TargetZLerp" , 0 );
314- this .trailierTales$xLerp = input .getFloatOr ("XLerp" , 0 );
315- this .trailierTales$yLerp = input .getFloatOr ("YLerp" , 0 );
316- this .trailierTales$zLerp = input .getFloatOr ("ZLerp" , 0 );
317- this .trailierTales$prevXLerp = input .getFloatOr ("PrevXLerp" , 0 );
318- this .trailierTales$prevYLerp = input .getFloatOr ("PrevYLerp" , 0 );
319- this .trailierTales$prevZLerp = input .getFloatOr ("PrevZLerp" , 0 );
320- this .trailierTales$targetItemScale = input .getFloatOr ("TargetItemScale" , 0 );
321- this .trailierTales$itemScale = input .getFloatOr ("ItemScale" , 0 );
322- this .trailierTales$prevItemScale = input .getFloatOr ("PrevItemScale" , 0 );
323- this .trailierTales$rotation = input .getFloatOr ("Rotation" , 0 );
324- this .trailierTales$prevRotation = input .getFloatOr ("PrevRotation" , 0 );
288+ this .trailierTales$targetXLerp = input .getFloatOr ("TargetXLerp" , 0.5F );
289+ this .trailierTales$targetYLerp = input .getFloatOr ("TargetYLerp" , 0F );
290+ this .trailierTales$targetZLerp = input .getFloatOr ("TargetZLerp" , 0.5F );
291+ this .trailierTales$xLerp = input .getFloatOr ("XLerp" , 0.5F );
292+ this .trailierTales$yLerp = input .getFloatOr ("YLerp" , 0F );
293+ this .trailierTales$zLerp = input .getFloatOr ("ZLerp" , 0.5F );
294+ this .trailierTales$prevXLerp = input .getFloatOr ("PrevXLerp" , 0.5F );
295+ this .trailierTales$prevYLerp = input .getFloatOr ("PrevYLerp" , 0F );
296+ this .trailierTales$prevZLerp = input .getFloatOr ("PrevZLerp" , 0.5F );
297+ this .trailierTales$targetItemScale = input .getFloatOr ("TargetItemScale" , 0F );
298+ this .trailierTales$itemScale = input .getFloatOr ("ItemScale" , 0F );
299+ this .trailierTales$prevItemScale = input .getFloatOr ("PrevItemScale" , 0F );
300+ this .trailierTales$rotation = input .getFloatOr ("Rotation" , 0F );
301+ this .trailierTales$prevRotation = input .getFloatOr ("PrevRotation" , 0F );
325302 this .trailierTales$hasCustomItem = input .getBooleanOr ("HasCustomItem" , false );
326303 this .brushCount = input .getIntOr ("BrushCount" , 0 );
327304 }
0 commit comments