Skip to content

Commit

Permalink
Better oxidizable mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Oct 2, 2024
1 parent a38fb14 commit 3a9133b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LightningEntityMixin(EntityType<?> type, World world) {
if (blockState.isIn(FriendsAndFoesTags.LIGHTNING_RODS)) {
this.getWorld().setBlockState(
blockPos,
Oxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos))
FriendsAndFoesOxidizable.getUnaffectedOxidationState(this.getWorld().getBlockState(blockPos))
);

((LightningRodBlock) this.getWorld().getBlockState(blockPos).getBlock()).setPowered(blockState, this.getWorld(), blockPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = AbstractBlock.class, priority = 10000)
@Mixin(value = AbstractBlock.class, priority = 1001)
public abstract class LightningRodAbstractBlockMixin
{
@Inject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = Block.class, priority = 10000)
@Mixin(value = Block.class, priority = 1001)
public abstract class LightningRodBlockBlockMixin extends LightningRodAbstractBlockMixin
{
@Inject(
method = "hasRandomTicks",
at = @At("TAIL"),
at = @At("HEAD"),
cancellable = true
)
public void friendsandfoes_hasRandomTicks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.minecraft.block.Oxidizable;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = LightningRodBlock.class, priority = 10000)
@Mixin(value = LightningRodBlock.class, priority = 1003)
public abstract class LightningRodBlockDegradableMixin implements Degradable
{
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faboslav.friendsandfoes.common.mixin;

import com.faboslav.friendsandfoes.common.FriendsAndFoes;
import com.faboslav.friendsandfoes.common.block.FriendsAndFoesOxidizable;
import com.faboslav.friendsandfoes.common.block.OnUseOxidizable;
import com.faboslav.friendsandfoes.common.client.render.entity.animation.KeyframeAnimation;
import com.faboslav.friendsandfoes.common.entity.CopperGolemEntity;
Expand Down Expand Up @@ -33,7 +34,7 @@

import java.util.ArrayList;

@Mixin(value = LightningRodBlock.class, priority = 10000)
@Mixin(value = LightningRodBlock.class, priority = 1001)
public abstract class LightningRodBlockMixin extends LightningRodBlockBlockMixin
{
@Nullable
Expand Down Expand Up @@ -205,7 +206,7 @@ private boolean friendsandfoes_isCopperBlockWaxed(
public void friendsandfoes_hasRandomTicks(
BlockState state, CallbackInfoReturnable<Boolean> cir
) {
cir.setReturnValue(Oxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent());
cir.setReturnValue(FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).isPresent());
}

@Override
Expand All @@ -216,7 +217,8 @@ public void friendsandfoes_randomTick(
Random random,
CallbackInfo ci
) {
((Degradable) this).tickDegradation(state, world, pos, random);
((Degradable)this).tickDegradation(state, world, pos, random);
ci.cancel();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.faboslav.friendsandfoes.common.mixin;

import com.faboslav.friendsandfoes.common.block.FriendsAndFoesOxidizable;
import net.minecraft.block.BlockState;
import net.minecraft.block.LightningRodBlock;
import net.minecraft.block.Oxidizable;
import net.minecraft.block.RodBlock;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = LightningRodBlock.class, priority = 10000)
import java.util.Optional;

@Mixin(value = LightningRodBlock.class, priority = 1002)
public abstract class LightningRodBlockOxidizableMixin extends RodBlock implements Oxidizable
{
public LightningRodBlockOxidizableMixin(Settings settings) {
super(settings);
}

@Override
public Optional<BlockState> getDegradationResult(BlockState state) {
return FriendsAndFoesOxidizable.getIncreasedOxidationBlock(state.getBlock()).map((block) -> block.getStateWithProperties(state));
}
}

0 comments on commit 3a9133b

Please sign in to comment.