Skip to content

Commit

Permalink
1.7.0
Browse files Browse the repository at this point in the history
- Added Rotator - rotates the block in front of it when receiving a redstone signal. Emits a comparator signal based on the direction said block is currently facing (if property is supported). Can be right clicked to switch from Clockwise to Counter Clockwise
- Inverter can now be uninverted to act as simply a one way gate that sends the same signal level as it is receiving
- Slightly tweaked appearance of Resistor
- Added an alternate recipe for the Analog Redstone Lamp to convert from regular Redstone Lamps
- Fixed Copper Button clicks not having subtitles
- Fixed crashes related to Breaker ( fixes #21 )
- Appearance of cracks on blocks being broken by Breaker should be more consistent and less janky
- We do a little cleanup
  • Loading branch information
Shnupbups committed Feb 25, 2022
1 parent d342f44 commit f6b962a
Show file tree
Hide file tree
Showing 60 changed files with 743 additions and 382 deletions.
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
# check these on https://fabricmc.net/develop/
minecraft_version=1.18.1
yarn_mappings=12
yarn_mappings=22
tiny_version=2
loader_version=0.12.12
loader_version=0.13.3

# Mod Properties
mod_version = 1.6.2
mod_version = 1.7.0
maven_group = com.shnupbups
mod_name = redstone-bits
version_meta = fabric-mc1.18

# Dependencies
# check on https://modmuss50.me/fabric.html
fapi_version=0.45.0+1.18
# check on https://fabricmc.net/develop/
fapi_version=0.46.4+1.18

# Other Stuff
# check on maven at https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version = 7.1.357
rei_version = 7.2.425

# check on maven at https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/
modmenu_version = 3.0.1
5 changes: 5 additions & 0 deletions src/main/java/com/shnupbups/redstonebits/RedstoneBits.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import net.fabricmc.api.ModInitializer;

import com.shnupbups.redstonebits.init.ModBlockEntities;
import com.shnupbups.redstonebits.init.ModBlocks;
import com.shnupbups.redstonebits.init.ModScreenHandlers;
import com.shnupbups.redstonebits.init.ModSoundEvents;

public class RedstoneBits implements ModInitializer {

public static Identifier id(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.shnupbups.redstonebits.container.screen.BreakerHandledScreen;
import com.shnupbups.redstonebits.container.screen.CheckerHandledScreen;
import com.shnupbups.redstonebits.init.ModBlocks;
import com.shnupbups.redstonebits.init.ModScreenHandlers;

@SuppressWarnings("unused")
public class RedstoneBitsClient implements ClientModInitializer {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/shnupbups/redstonebits/block/AdderBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;

import com.shnupbups.redstonebits.ModSoundEvents;
import com.shnupbups.redstonebits.init.ModSoundEvents;
import com.shnupbups.redstonebits.properties.ModProperties;

public class AdderBlock extends AbstractRedstoneGateBlock implements AdvancedRedstoneConnector {
Expand Down Expand Up @@ -82,9 +82,9 @@ public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Ran
world.setBlockState(pos, state.with(POWERED, false), Block.NOTIFY_LISTENERS);
} else if (!powered) {
int newPower = power;
int recievedPower = this.getPower(world, pos, state);
if (backwards) newPower -= recievedPower;
else newPower += recievedPower;
int receivedPower = this.getPower(world, pos, state);
if (backwards) newPower -= receivedPower;
else newPower += receivedPower;
if (newPower > 15) newPower -= 15;
else if (newPower < 0) newPower += 15;
world.setBlockState(pos, state.with(POWERED, true).with(POWER, newPower), Block.NOTIFY_LISTENERS);
Expand All @@ -103,8 +103,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
boolean backwards = state.get(BACKWARDS);
float pitch = backwards ? 0.55F : 0.5F;
world.playSound(player, pos, ModSoundEvents.BLOCK_ADDER_CLICK, SoundCategory.BLOCKS, 0.3F, pitch);
world.setBlockState(pos, state.with(BACKWARDS, !backwards), 2);
return ActionResult.SUCCESS;
world.setBlockState(pos, state.with(BACKWARDS, !backwards), Block.NOTIFY_ALL);
return ActionResult.success(world.isClient());
}
}

Expand All @@ -114,7 +114,7 @@ public boolean connectsToRedstoneInDirection(BlockState state, Direction directi
Direction facing = state.get(FACING);
return direction == facing || direction.getOpposite() == facing;
}
return true;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class AnalogRedstoneRecieverBlock extends Block {
public class AnalogRedstoneReceiverBlock extends Block {
public static final IntProperty POWER = Properties.POWER;

public AnalogRedstoneRecieverBlock(Settings settings) {
public AnalogRedstoneReceiverBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(POWER, 0));
}
Expand All @@ -29,9 +29,9 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
if (!world.isClient) {
int power = state.get(POWER);
int recievedPower = world.getReceivedRedstonePower(pos);
if (power != recievedPower) {
if (power > 0 && recievedPower == 0) {
int receivedPower = world.getReceivedRedstonePower(pos);
if (power != receivedPower) {
if (power > 0 && receivedPower == 0) {
world.createAndScheduleBlockTick(pos, this, 4);
} else {
world.setBlockState(pos, state.with(POWER, world.getReceivedRedstonePower(pos)), 2);
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/shnupbups/redstonebits/block/BreakerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;

import com.shnupbups.redstonebits.ModBlockEntities;
import com.shnupbups.redstonebits.init.ModBlockEntities;
import com.shnupbups.redstonebits.blockentity.BreakerBlockEntity;
import com.shnupbups.redstonebits.container.BreakerScreenHandler;
import com.shnupbups.redstonebits.properties.ModProperties;
Expand All @@ -60,7 +60,7 @@ public BreakerBlock(Settings settings) {
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return checkType(type, ModBlockEntities.BREAKER, world.isClient ? BreakerBlockEntity::clientTick : BreakerBlockEntity::serverTick);
return checkType(type, ModBlockEntities.BREAKER, world.isClient ? null : BreakerBlockEntity::serverTick);
}

@Override
Expand Down Expand Up @@ -173,7 +173,6 @@ public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity p
((BreakerBlockEntity) blockEntity).setCustomName(itemStack.getName());
}
}

}

@Override
Expand All @@ -196,7 +195,11 @@ public boolean hasComparatorOutput(BlockState state) {

@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return ScreenHandler.calculateComparatorOutput(world.getBlockEntity(pos));
BlockEntity blockEntity = world.getBlockEntity(pos);
if(blockEntity instanceof BreakerBlockEntity breakerBlockEntity) {
return (int) (breakerBlockEntity.getBreakPercentage() / (100f / 15f));
}
return 0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;

import com.shnupbups.redstonebits.ModBlockEntities;
import com.shnupbups.redstonebits.init.ModBlockEntities;
import com.shnupbups.redstonebits.blockentity.CheckerBlockEntity;
import com.shnupbups.redstonebits.container.CheckerScreenHandler;

Expand Down Expand Up @@ -175,7 +175,7 @@ public boolean connectsToRedstoneInDirection(BlockState state, Direction directi
Direction facing = state.get(FACING);
return direction == facing;
}
return true;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import net.minecraft.block.BlockState;
import net.minecraft.block.Oxidizable;
import net.minecraft.block.WeightedPressurePlateBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;

public class CopperPressurePlateBlock extends ModWeightedPressurePlateBlock implements Oxidizable {
public class CopperPressurePlateBlock extends WeightedPressurePlateBlock implements Oxidizable {
private final Oxidizable.OxidationLevel oxidationLevel;

public CopperPressurePlateBlock(Oxidizable.OxidationLevel oxidationLevel, int weight, Settings settings) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/shnupbups/redstonebits/block/CounterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;

import com.shnupbups.redstonebits.ModSoundEvents;
import com.shnupbups.redstonebits.init.ModSoundEvents;
import com.shnupbups.redstonebits.properties.ModProperties;

public class CounterBlock extends AbstractRedstoneGateBlock implements AdvancedRedstoneConnector {
Expand Down Expand Up @@ -52,8 +52,8 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
}

@Override
public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction facing) {
return state.get(FACING) == facing ? this.getOutputLevel(view, pos, state) : 0;
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction facing) {
return state.get(FACING) == facing ? this.getOutputLevel(world, pos, state) : 0;
}

@Override
Expand Down Expand Up @@ -98,8 +98,8 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
boolean backwards = state.get(BACKWARDS);
float pitch = backwards ? 0.55F : 0.5F;
world.playSound(player, pos, ModSoundEvents.BLOCK_COUNTER_CLICK, SoundCategory.BLOCKS, 0.3F, pitch);
world.setBlockState(pos, state.with(BACKWARDS, !backwards), 2);
return ActionResult.SUCCESS;
world.setBlockState(pos, state.with(BACKWARDS, !backwards), Block.NOTIFY_ALL);
return ActionResult.success(world.isClient());
}
}

Expand All @@ -109,7 +109,7 @@ public boolean connectsToRedstoneInDirection(BlockState state, Direction directi
Direction facing = state.get(FACING);
return direction == facing || direction.getOpposite() == facing;
}
return true;
return false;
}

@Override
Expand Down
60 changes: 44 additions & 16 deletions src/main/java/com/shnupbups/redstonebits/block/InverterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
Expand All @@ -20,14 +27,36 @@
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;

import com.shnupbups.redstonebits.init.ModSoundEvents;
import com.shnupbups.redstonebits.blockentity.RedstoneGateBlockEntity;

public class InverterBlock extends AbstractRedstoneGateBlock implements AdvancedRedstoneConnector, BlockEntityProvider {
public static final BooleanProperty LOCKED = Properties.LOCKED;
public static final BooleanProperty INVERTED = Properties.INVERTED;

public InverterBlock(Settings settings) {
super(settings);
this.setDefaultState(this.getDefaultState().with(POWERED, false).with(LOCKED, false));
this.setDefaultState(this.getDefaultState().with(POWERED, false).with(LOCKED, false).with(INVERTED, true));
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
world.createAndScheduleBlockTick(pos, this, 1);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!player.getAbilities().allowModifyWorld) {
return ActionResult.PASS;
} else {
boolean inverted = state.get(INVERTED);
float pitch = inverted ? 0.55F : 0.5F;
world.playSound(player, pos, ModSoundEvents.BLOCK_INVERTER_CLICK, SoundCategory.BLOCKS, 0.3F, pitch);
BlockState newState = state.with(INVERTED, !inverted);
world.setBlockState(pos, newState, Block.NOTIFY_ALL);
this.update(world, pos, newState);
return ActionResult.success(world.isClient());
}
}

@Override
Expand All @@ -46,8 +75,7 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio

@Override
protected int getOutputLevel(BlockView world, BlockPos pos, BlockState state) {
BlockEntity blockEntity = world.getBlockEntity(pos);
return blockEntity instanceof RedstoneGateBlockEntity ? ((RedstoneGateBlockEntity) blockEntity).getOutputSignal() : 0;
return world.getBlockEntity(pos) instanceof RedstoneGateBlockEntity redstoneGateBlockEntity ? redstoneGateBlockEntity.getOutputSignal() : 0;
}

@Override
Expand All @@ -57,7 +85,7 @@ protected int getUpdateDelayInternal(BlockState state) {

@Override
public void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING, POWERED, LOCKED);
builder.add(FACING, POWERED, LOCKED, INVERTED);
}

@Override
Expand All @@ -66,14 +94,14 @@ public boolean connectsToRedstoneInDirection(BlockState state, Direction directi
Direction facing = state.get(FACING);
return direction == facing || direction.getOpposite() == facing;
}
return true;
return false;
}

@Override
protected void updatePowered(World world, BlockPos pos, BlockState state) {
if (!world.getBlockTickScheduler().isTicking(pos, this)) {
TickPriority tickPriority = this.isTargetNotAligned(world, pos, state) ? TickPriority.HIGH : TickPriority.NORMAL;
world.createAndScheduleBlockTick(pos, this, 2, tickPriority);
TickPriority tickPriority = this.isTargetNotAligned(world, pos, state) ? TickPriority.EXTREMELY_HIGH : state.get(POWERED) ? TickPriority.VERY_HIGH : TickPriority.HIGH;
world.createAndScheduleBlockTick(pos, this, this.getUpdateDelayInternal(state), tickPriority);
}
}

Expand All @@ -99,9 +127,9 @@ private void update(World world, BlockPos pos, BlockState state) {
int output = this.calculateOutputSignal(world, pos, state);
BlockEntity blockEntity = world.getBlockEntity(pos);
int currentOutput = 0;
if (blockEntity instanceof RedstoneGateBlockEntity resistorBlockEntity) {
currentOutput = resistorBlockEntity.getOutputSignal();
resistorBlockEntity.setOutputSignal(output);
if (blockEntity instanceof RedstoneGateBlockEntity gateBlockEntity) {
currentOutput = gateBlockEntity.getOutputSignal();
gateBlockEntity.setOutputSignal(output);
}

if (currentOutput != output) {
Expand All @@ -111,6 +139,8 @@ private void update(World world, BlockPos pos, BlockState state) {
world.setBlockState(pos, state.with(POWERED, false), Block.NOTIFY_LISTENERS);
} else if (!bl2 && bl) {
world.setBlockState(pos, state.with(POWERED, true), Block.NOTIFY_LISTENERS);
} else {
world.setBlockState(pos, state, Block.NOTIFY_LISTENERS);
}

this.updateTarget(world, pos, state);
Expand All @@ -119,7 +149,8 @@ private void update(World world, BlockPos pos, BlockState state) {
}

public int calculateOutputSignal(World world, BlockPos pos, BlockState state) {
return 15 - getPower(world, pos, state);
int power = getPower(world, pos, state);
return state.get(INVERTED) ? 15 - power : power;
}

@Override
Expand All @@ -133,10 +164,7 @@ protected boolean isValidInput(BlockState state) {
}

@Override
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
if (state.get(FACING) == direction) {
return this.getOutputLevel(world, pos, state);
}
return 0;
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction facing) {
return state.get(FACING) == facing ? this.getOutputLevel(world, pos, state) : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import com.shnupbups.redstonebits.ModSoundEvents;
import com.shnupbups.redstonebits.init.ModSoundEvents;

public class ModButtonBlock extends AbstractButtonBlock {
private final int pressTicks;
Expand Down

This file was deleted.

Loading

0 comments on commit f6b962a

Please sign in to comment.