get reducer working on forge; todo why the mixin doesn't fire on fabric
This commit is contained in:
parent
ee3f34878e
commit
d901b83732
6 changed files with 51 additions and 10 deletions
|
@ -37,7 +37,7 @@ public class BlockConjuredLight extends BlockConjured implements SimpleWaterlogg
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.@NotNull Builder<Block, BlockState> builder) {
|
||||
protected void createBlockStateDefinition(@NotNull StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(WATERLOGGED);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,8 @@ public class BlockConjuredLight extends BlockConjured implements SimpleWaterlogg
|
|||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, @Nonnull Direction facing, @Nonnull BlockState facingState, @Nonnull LevelAccessor level, @Nonnull BlockPos pos, @Nonnull BlockPos facingPos) {
|
||||
public BlockState updateShape(BlockState state, @Nonnull Direction facing, @Nonnull BlockState facingState,
|
||||
@Nonnull LevelAccessor level, @Nonnull BlockPos pos, @Nonnull BlockPos facingPos) {
|
||||
if (state.getValue(WATERLOGGED)) {
|
||||
level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
|
||||
}
|
||||
|
|
|
@ -22,10 +22,8 @@ public class AmethystReducerFunc extends LootItemConditionalFunction {
|
|||
|
||||
@Override
|
||||
protected ItemStack run(ItemStack stack, LootContext ctx) {
|
||||
if (stack.getItem() == Items.AMETHYST_SHARD) {
|
||||
if (stack.is(Items.AMETHYST_SHARD)) {
|
||||
stack.setCount((int) (stack.getCount() * (1 + delta)));
|
||||
}
|
||||
if (stack.is(Items.AMETHYST_SHARD)) {
|
||||
stack.setCount((int) (stack.getCount() * (1 + delta)));
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package at.petrak.hexcasting.mixin;
|
||||
|
||||
import at.petrak.hexcasting.api.HexAPI;
|
||||
import at.petrak.hexcasting.common.loot.HexLootHandler;
|
||||
import at.petrak.hexcasting.mixin.accessor.AccessorLootTable;
|
||||
import net.minecraft.server.ReloadableServerResources;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.storage.loot.functions.LootItemFunctions;
|
||||
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.Arrays;
|
||||
|
||||
@Mixin(ReloadableServerResources.class)
|
||||
public class MixinReloadableServerResources {
|
||||
@Inject(method = "lambda$loadResources$0", at = @At("RETURN"))
|
||||
private static void onLoadResources(ReloadableServerResources rsr, Object whoKnows,
|
||||
CallbackInfoReturnable<ReloadableServerResources> cir) {
|
||||
var amethystTable = rsr.getLootTables().get(Blocks.AMETHYST_CLUSTER.getLootTable());
|
||||
var theCoolerAmethystTable = (AccessorLootTable) amethystTable;
|
||||
var oldFuncs = theCoolerAmethystTable.hex$getFunctions();
|
||||
var newFuncs = Arrays.copyOf(oldFuncs, oldFuncs.length + 1);
|
||||
var shardReducer = rsr.getItemModifierManager().get(HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
|
||||
if (shardReducer != null) {
|
||||
newFuncs[newFuncs.length - 1] = shardReducer;
|
||||
theCoolerAmethystTable.hex$setFunctions(newFuncs);
|
||||
theCoolerAmethystTable.hex$setCompositeFunction(LootItemFunctions.compose(newFuncs));
|
||||
} else {
|
||||
HexAPI.LOGGER.warn("{} was not found?", HexLootHandler.FUNC_AMETHYST_SHARD_REDUCER);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package at.petrak.hexcasting.mixin.accessor;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Mixin(LootTable.class)
|
||||
public interface AccessorLootTable {
|
||||
@Accessor("functions")
|
||||
|
@ -14,4 +18,8 @@ public interface AccessorLootTable {
|
|||
@Accessor("functions")
|
||||
@Mutable
|
||||
void hex$setFunctions(LootItemFunction[] lifs);
|
||||
|
||||
@Accessor("compositeFunction")
|
||||
@Mutable
|
||||
void hex$setCompositeFunction(BiFunction<ItemStack, LootContext, ItemStack> bf);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"function": "hexcasting:amethyst_shard_reducer",
|
||||
"delta": -2
|
||||
"delta": -0.5
|
||||
}
|
|
@ -5,8 +5,8 @@
|
|||
"refmap": "hexcasting.mixins.refmap.json",
|
||||
"package": "at.petrak.hexcasting.mixin",
|
||||
"mixins": [
|
||||
"AccessorTagsProvider", "MixinMob", "MixinRaider", "MixinVillager", "MixinWitch", "accessor.AccessorLivingEntity",
|
||||
"accessor.AccessorLootTable", "accessor.AccessorRecipeProvider", "accessor.AccessorUseOnContext",
|
||||
"accessor.CriteriaTriggersAccessor"
|
||||
"AccessorTagsProvider", "MixinMob", "MixinRaider", "MixinReloadableServerResources", "MixinVillager", "MixinWitch",
|
||||
"accessor.AccessorLivingEntity", "accessor.AccessorLootTable", "accessor.AccessorRecipeProvider",
|
||||
"accessor.AccessorUseOnContext", "accessor.CriteriaTriggersAccessor"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue