Skip to content

Commit

Permalink
feat: mixin stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 15, 2024
1 parent c8f23e5 commit a84655c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.google.common.collect.Maps;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.util.Lazy;
import net.neoforged.neoforge.common.util.Lazy;
import net.zepalesque.redux.block.ReduxBlocks;
import net.zepalesque.redux.config.ReduxConfig;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod.EventBusSubscriber;
import net.neoforged.neoforge.common.ToolAction;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.level.BlockEvent;
import net.zepalesque.redux.Redux;
import net.zepalesque.redux.event.hook.BlockBreakHooks;
import net.zepalesque.redux.event.hook.ToolActionHooks;

@EventBusSubscriber(modid = Redux.MODID)
public class ToolActionListener {
public class ToolsListener {

@SubscribeEvent
public static void setupToolModifications(BlockEvent.BlockToolModificationEvent event) {
Expand All @@ -24,4 +26,12 @@ public static void setupToolModifications(BlockEvent.BlockToolModificationEvent
event.setFinalState(newState);
}
}

@SubscribeEvent
public static void modifyMiningSpeed(PlayerEvent.BreakSpeed event) {
float modifiedSpeed = BlockBreakHooks.modify(event.getState().getBlock(), event.getNewSpeed());
if (modifiedSpeed != event.getNewSpeed()) {
event.setNewSpeed(modifiedSpeed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class AetherColorResolversMixin {
@Inject(at = @At("HEAD"), method = "registerBlockColor", cancellable = true, remap = false)
private static void stupidMixinBlackMagic(RegisterColorHandlersEvent.Block event, CallbackInfo ci) {
// Cancel the aether's override of the grass color stuff
// Cancel the aether's override of the grass color stuff, I don't like doing it this way but it does what it's meant to
ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@Mixin(BlockBehaviour.class)
public class BlockBehaviorMixin {

// Maybe PR a neoforge event? idk
@Inject(method = "isPathfindable", at = @At("HEAD"), cancellable = true)
public void redux$pathFindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type, CallbackInfoReturnable<Boolean> cir) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@

import com.aetherteam.aether.block.AetherBlocks;
import com.aetherteam.aether.entity.monster.dungeon.boss.Slider;
import com.google.common.collect.ImmutableMap;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.common.util.Lazy;
import net.zepalesque.redux.block.ReduxBlocks;
import net.zepalesque.redux.blockset.stone.ReduxStoneSets;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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.Map;

@Mixin(Slider.class)
public class SliderMixin {

@Inject(method = "convertBlock", at = @At("TAIL"))
@Unique
private static final Lazy<Map<Block, Block>> REDUX$CONVERSIONS = Lazy.of(() -> new ImmutableMap.Builder<Block, Block>()
.put(ReduxBlocks.LOCKED_CARVED_BASE.get(), ReduxBlocks.CARVED_BASE.get())
.put(ReduxBlocks.LOCKED_SENTRY_BASE.get(), ReduxBlocks.SENTRY_BASE.get())
.put(ReduxBlocks.LOCKED_CARVED_PILLAR.get(), ReduxBlocks.CARVED_PILLAR.get())
.put(ReduxBlocks.LOCKED_RUNELIGHT.get(), ReduxBlocks.RUNELIGHT.get())
.put(ReduxBlocks.LOCKED_SENTRITE_BRICKS.get(), ReduxStoneSets.SENTRITE_BRICKS.block().get())
.build()
);

// TODO: Pull request for a system for this in the base mod
@Inject(method = "convertBlock", at = @At("HEAD"), cancellable = true, remap = false)
protected void redux$convertBlock(BlockState state, CallbackInfoReturnable<BlockState> cir) {
// TODO
// if (state.is(AetherBlocks.LOCKED_CARVED_STONE.get())) {
// return AetherBlocks.CARVED_STONE.get().defaultBlockState();
// }
if (REDUX$CONVERSIONS.get().containsKey(state.getBlock())) {
cir.setReturnValue(REDUX$CONVERSIONS.get().get(state.getBlock()).withPropertiesOf(state));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Mixin(PickaxeItem.class)
public class PickaxeItemMixin extends DiggerItemMixin {

// Can't really do much about this one unfortunately
@Override
protected void hurtEnemy(ItemStack pStack, LivingEntity pTarget, LivingEntity pAttacker, CallbackInfoReturnable<Boolean> cir) {
pStack.hurtAndBreak(pTarget.getType().is(Entities.VALID_PICKAXE_TARGETS) && pStack.is(AetherTags.Items.SLIDER_DAMAGING_ITEMS) ? 1 : 2, pAttacker, (consumer) -> consumer.broadcastBreakEvent(EquipmentSlot.MAINHAND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Mixin(BronzeBossRoom.class)
public class BronzeBossMixin {

// TODO: PR to make this possible without mixins
@WrapOperation(method = "makeSettings", at = @At(value = "NEW", target = "()Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;"))
private static StructurePlaceSettings redux$makeSettings(Operation<StructurePlaceSettings> original) {
return original.call().addProcessor(ReduxDungeonProcessors.BRONZE_LOCKED).addProcessor(ReduxDungeonProcessors.BRONZE_BLOCKS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Mixin(BronzeDungeonRoom.class)
public class BronzeDungeonMixin {

// TODO: PR to make this possible without mixins
@WrapOperation(method = "makeSettings", at = @At(value = "NEW", target = "()Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;"))
private static StructurePlaceSettings redux$makeSettings(Operation<StructurePlaceSettings> original) {
return original.call().addProcessor(ReduxDungeonProcessors.BRONZE_BLOCKS).addProcessor(ReduxDungeonProcessors.BRONZE_TRAPS);
Expand Down

0 comments on commit a84655c

Please sign in to comment.