Skip to content

Commit

Permalink
Update WeightedPressurePlateBlockMixin.java
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS authored Aug 25, 2020
1 parent eca766d commit b3ee041
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package redstonetweaks.mixin.server;

import static redstonetweaks.setting.Settings.heavyWeightedPressurePlateDelay;
import static redstonetweaks.setting.Settings.heavyWeightedPressurePlateWeight;
import static redstonetweaks.setting.Settings.lightWeightedPressurePlateDelay;
import static redstonetweaks.setting.Settings.lightWeightedPressurePlateWeight;
import static redstonetweaks.setting.SettingsManager.*;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -18,16 +15,16 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.WeightedPressurePlateBlock;
import net.minecraft.entity.EntityContext;
import net.minecraft.state.property.IntProperty;
import net.minecraft.block.ShapeContext;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import redstonetweaks.helper.PressurePlateHelper;

@Mixin(WeightedPressurePlateBlock.class)
public abstract class WeightedPressurePlateBlockMixin extends AbstractPressurePlateBlock {

@Shadow @Final public static IntProperty POWER;
public abstract class WeightedPressurePlateBlockMixin extends AbstractPressurePlateBlock implements PressurePlateHelper {

@Shadow @Final private int weight;

protected WeightedPressurePlateBlockMixin(Settings settings) {
Expand All @@ -36,19 +33,29 @@ protected WeightedPressurePlateBlockMixin(Settings settings) {

@Redirect(method = "getRedstoneOutput", at = @At(value = "FIELD", target = "Lnet/minecraft/block/WeightedPressurePlateBlock;weight:I"))
private int getPlateWeight(WeightedPressurePlateBlock pressurePlate) {
return (Block)(Object)this == Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE ? heavyWeightedPressurePlateWeight.get() : lightWeightedPressurePlateWeight.get();
return (Block)(Object)this == Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE ? HEAVY_WEIGHTED_PRESSURE_PLATE.get(WEIGHT) : LIGHT_WEIGHTED_PRESSURE_PLATE.get(WEIGHT);
}

@ModifyConstant(method = "getTickRate", constant = @Constant(intValue = 10))
private int getWeightedPressurePlateDelay(int oldDelay) {
return (Block)(Object)this == Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE ? heavyWeightedPressurePlateDelay.get() : lightWeightedPressurePlateDelay.get();
return (Block)(Object)this == Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE ? HEAVY_WEIGHTED_PRESSURE_PLATE.get(FALLING_DELAY) : LIGHT_WEIGHTED_PRESSURE_PLATE.get(FALLING_DELAY);
}

// We need to override this function because when the blocks
// are initialized, and this function is called,
// the Redstone Tweaks settings have not yet been initialized.
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
return state.get(POWER) > 0 ? PRESSED_SHAPE : DEFAULT_SHAPE;
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
return state.get(Properties.POWER) > 0 ? PRESSED_SHAPE : DEFAULT_SHAPE;
}

@Override
public int getWeakPower(BlockState state) {
return getRedstoneOutput(state);
}

@Override
public int getStrongPower(BlockState state) {
return getRedstoneOutput(state);
}
}

0 comments on commit b3ee041

Please sign in to comment.