-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mixin refactoring and TextContents in translation files
- Loading branch information
Showing
33 changed files
with
615 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 25 additions & 12 deletions
37
specter-block/src/main/java/dev/spiritstudios/specter/mixin/block/FireBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
package dev.spiritstudios.specter.mixin.block; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import dev.spiritstudios.specter.api.block.BlockMetatags; | ||
import dev.spiritstudios.specter.api.block.FlammableBlockData; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.FireBlock; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(FireBlock.class) | ||
public class FireBlockMixin { | ||
@Inject(method = "getBurnChance(Lnet/minecraft/block/BlockState;)I", at = @At("HEAD"), cancellable = true) | ||
private void getBurnChanceFromMetatag(BlockState state, CallbackInfoReturnable<Integer> cir) { | ||
Optional<FlammableBlockData> data = BlockMetatags.FLAMMABLE.get(state.getBlock()); | ||
data.ifPresent(flammableBlockData -> cir.setReturnValue(flammableBlockData.burn())); | ||
@WrapOperation(method = "getBurnChance(Lnet/minecraft/block/BlockState;)I", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/Object2IntMap;getInt(Ljava/lang/Object;)I", remap = false)) | ||
private int getBurnChanceFromMetatag( | ||
Object2IntMap<Block> instance, | ||
Object value, | ||
Operation<Integer> original, | ||
@Local(argsOnly = true) BlockState state | ||
) { | ||
return BlockMetatags.FLAMMABLE.get((state).getBlock()) | ||
.map(FlammableBlockData::burn) | ||
.orElse(original.call(instance, value)); | ||
} | ||
|
||
@Inject(method = "getSpreadChance(Lnet/minecraft/block/BlockState;)I", at = @At("HEAD"), cancellable = true) | ||
private void getSpreadChanceFromMetatag(BlockState state, CallbackInfoReturnable<Integer> cir) { | ||
Optional<FlammableBlockData> data = BlockMetatags.FLAMMABLE.get(state.getBlock()); | ||
data.ifPresent(flammableBlockData -> cir.setReturnValue(flammableBlockData.spread())); | ||
@WrapOperation(method = "getSpreadChance(Lnet/minecraft/block/BlockState;)I", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/Object2IntMap;getInt(Ljava/lang/Object;)I", remap = false)) | ||
private int getSpreadChanceFromMetatag( | ||
Object2IntMap<Block> instance, | ||
Object value, | ||
Operation<Integer> original, | ||
@Local(argsOnly = true) BlockState state | ||
) { | ||
return BlockMetatags.FLAMMABLE.get((state).getBlock()) | ||
.map(FlammableBlockData::spread) | ||
.orElse(original.call(instance, value)); | ||
} | ||
} |
18 changes: 12 additions & 6 deletions
18
specter-block/src/main/java/dev/spiritstudios/specter/mixin/block/HoneycombItemMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package dev.spiritstudios.specter.mixin.block; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import dev.spiritstudios.specter.impl.block.SpecterBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.item.HoneycombItem; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(HoneycombItem.class) | ||
public class HoneycombItemMixin { | ||
@Inject(method = "getWaxedState", at = @At("HEAD"), cancellable = true) | ||
private static void getWaxedState(BlockState state, CallbackInfoReturnable<Optional<BlockState>> cir) { | ||
Optional<BlockState> waxedBlockState = Optional.ofNullable(SpecterBlock.UNWAXED_TO_WAXED_BLOCKS.get(state.getBlock())).map(block -> block.getStateWithProperties(state)); | ||
if (waxedBlockState.isPresent()) cir.setReturnValue(waxedBlockState); | ||
@WrapOperation(method = "getWaxedState", at = @At(value = "INVOKE", target = "Ljava/util/Optional;ofNullable(Ljava/lang/Object;)Ljava/util/Optional;")) | ||
private static Optional<Object> getWaxedState( | ||
Object value, | ||
Operation<Optional<Object>> original, | ||
@Local(argsOnly = true) BlockState state | ||
) { | ||
Optional<Object> waxedBlockState = Optional.ofNullable(SpecterBlock.UNWAXED_TO_WAXED_BLOCKS.get(state.getBlock())); | ||
|
||
return waxedBlockState.or(() -> original.call(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,5 +74,4 @@ public void testOxidizableMetatag(TestContext context) { | |
|
||
context.complete(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
moduleDependencies(project, "specter-core", "specter-registry", "specter-item", "specter-block") | ||
moduleDependencies( | ||
project, | ||
"specter-core", | ||
"specter-registry", | ||
"specter-item", | ||
"specter-block", | ||
"specter-serialization", | ||
"specter-render" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.