Skip to content

Commit

Permalink
Switch to Mixin Accessor
Browse files Browse the repository at this point in the history
Lily should be happy now
  • Loading branch information
andi-makes committed Oct 22, 2023
1 parent fcd5754 commit 9b955b7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package dev.schmarrn.schnowy.common.blocks;

import dev.schmarrn.schnowy.mixin.BlockPropertiesMixin;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockBehaviour;

public interface SchnowyBlockInterface {
/**
* @return whether the block can currently be snow logged
*/
boolean canLog(LevelReader level, BlockPos pos);

static BlockBehaviour.Properties notReplaceableHack(BlockBehaviour.Properties properties) {
((BlockPropertiesMixin) properties).setReplaceable(false);
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.schmarrn.schnowy.common.blocks;

import dev.schmarrn.schnowy.common.duck.BlockPropertiesDuck;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -36,11 +35,10 @@ public class SnowedDeadBush extends DeadBushBlock implements SchnowyBlockInterfa
});

public SnowedDeadBush() {
super(((BlockPropertiesDuck) (Properties.copy(Blocks.SNOW)
super(SchnowyBlockInterface.notReplaceableHack(Properties.copy(Blocks.SNOW)
.requiresCorrectToolForDrops()
.strength(Blocks.SNOW.defaultDestroyTime(), Blocks.SNOW.getExplosionResistance())
.sound(SoundType.SNOW)))
.nonReplaceable());
.sound(SoundType.SNOW)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.schmarrn.schnowy.common.blocks;

import dev.schmarrn.schnowy.common.duck.BlockPropertiesDuck;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -42,11 +41,10 @@ public SnowedFlower(FlowerBlock parent) {
super(
parent.getSuspiciousEffect(),
parent.getEffectDuration(),
((BlockPropertiesDuck) (Properties.copy(Blocks.SNOW)
SchnowyBlockInterface.notReplaceableHack(Properties.copy(Blocks.SNOW)
.requiresCorrectToolForDrops()
.strength(Blocks.SNOW.defaultDestroyTime(), Blocks.SNOW.getExplosionResistance())
.sound(SoundType.SNOW)))
.nonReplaceable()
.sound(SoundType.SNOW))
);
this.parent = parent;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.schmarrn.schnowy.common.blocks;

import dev.schmarrn.schnowy.common.duck.BlockPropertiesDuck;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -41,11 +40,10 @@ public class SnowedGrass extends TallGrassBlock implements SchnowyBlockInterface
public final TallGrassBlock parent;

public SnowedGrass(TallGrassBlock parent) {
super(((BlockPropertiesDuck) (Properties.copy(Blocks.SNOW)
.requiresCorrectToolForDrops()
.strength(Blocks.SNOW.defaultDestroyTime(), Blocks.SNOW.getExplosionResistance())
.sound(SoundType.SNOW)))
.nonReplaceable()
super(SchnowyBlockInterface.notReplaceableHack(Properties.copy(Blocks.SNOW)
.requiresCorrectToolForDrops()
.strength(Blocks.SNOW.defaultDestroyTime(), Blocks.SNOW.getExplosionResistance())
.sound(SoundType.SNOW))
);
this.parent = parent;
}
Expand Down

This file was deleted.

15 changes: 4 additions & 11 deletions src/main/java/dev/schmarrn/schnowy/mixin/BlockPropertiesMixin.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package dev.schmarrn.schnowy.mixin;

import dev.schmarrn.schnowy.common.duck.BlockPropertiesDuck;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(BlockBehaviour.Properties.class)
public class BlockPropertiesMixin implements BlockPropertiesDuck {
@Shadow
boolean replaceable;

@Override
public BlockBehaviour.Properties nonReplaceable() {
this.replaceable = false;
return (BlockBehaviour.Properties) (Object) this;
}
public interface BlockPropertiesMixin {
@Accessor("replaceable")
void setReplaceable(boolean bla);
}

0 comments on commit 9b955b7

Please sign in to comment.