Skip to content

Commit

Permalink
1.7.1
Browse files Browse the repository at this point in the history
updated to 1.18.2
also more tweaks to the breaker to make comparator output and cracks more consistent
  • Loading branch information
Shnupbups committed Mar 5, 2022
1 parent f6b962a commit 2ab5f30
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 50 deletions.
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -10,9 +10,6 @@ archivesBaseName = project.mod_name
version = project.mod_version + "+" + project.version_meta
group = project.maven_group

minecraft {
}

loom {
accessWidenerPath = file("src/main/resources/redstonebits.accesswidener")
}
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.18.1
yarn_mappings=22
minecraft_version=1.18.2
yarn_mappings=1
tiny_version=2
loader_version=0.13.3

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

# Dependencies
# check on https://fabricmc.net/develop/
fapi_version=0.46.4+1.18
fapi_version=0.47.9+1.18.2

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

# check on maven at https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu/
modmenu_version = 3.0.1
modmenu_version = 3.1.0
18 changes: 9 additions & 9 deletions src/main/java/com/shnupbups/redstonebits/block/BreakerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,23 @@ public boolean startBreak(World world, BlockPos pos) {
}
BlockState breakState = world.getBlockState(pos.add(state.get(FACING).getVector()));
boolean isBreakable = !(breakState.getHardness(world, pos) < 0);
if (be instanceof BreakerBlockEntity && isBreakable) {
((BreakerBlockEntity) be).startBreak();
if (be instanceof BreakerBlockEntity breaker && isBreakable) {
breaker.startBreak();
}
return isBreakable;
}

public void cancelBreak(World world, BlockPos pos) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof BreakerBlockEntity) {
((BreakerBlockEntity) be).cancelBreak();
if (be instanceof BreakerBlockEntity breaker) {
breaker.cancelBreak();
}
}

public boolean isBreaking(World world, BlockPos pos) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof BreakerBlockEntity) {
return ((BreakerBlockEntity) be).isBreaking();
if (be instanceof BreakerBlockEntity breaker) {
return breaker.isBreaking();
}
return false;
}
Expand All @@ -153,9 +153,9 @@ public BlockPos getBreakPos(World world, BlockPos pos) {
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (this.isBreaking(world, pos)) this.cancelBreak(world, pos);
else this.startBreak(world, pos);
boolean boolean_2 = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(pos.up());
boolean boolean_3 = state.get(TRIGGERED);
if (!boolean_2 && boolean_3) {
boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(pos.up());
boolean triggered = state.get(TRIGGERED);
if (!powered && triggered) {
world.setBlockState(pos, state.with(TRIGGERED, false), Block.NO_REDRAW);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Oxidizable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
Expand All @@ -14,8 +15,6 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;

public class CopperButtonBlock extends ModButtonBlock implements Oxidizable {
private final Oxidizable.OxidationLevel oxidationLevel;

Expand All @@ -41,7 +40,7 @@ public OxidationLevel getDegradationLevel() {

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if ((player.getStackInHand(hand).isOf(Items.HONEYCOMB) || player.getStackInHand(hand).isIn(FabricToolTags.AXES)) && !state.get(POWERED))
if ((player.getStackInHand(hand).isOf(Items.HONEYCOMB) || player.getStackInHand(hand).getItem() instanceof AxeItem) && !state.get(POWERED))
return ActionResult.PASS;
return super.onUse(state, world, pos, player, hand, hit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
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.world.World;

import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;

public class WaxedCopperButtonBlock extends ModButtonBlock {

public WaxedCopperButtonBlock(int pressTicks, AbstractBlock.Settings settings) {
Expand All @@ -19,7 +18,7 @@ public WaxedCopperButtonBlock(int pressTicks, AbstractBlock.Settings settings) {

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (player.getStackInHand(hand).isIn(FabricToolTags.AXES) && !state.get(POWERED)) return ActionResult.PASS;
if (player.getStackInHand(hand).getItem() instanceof AxeItem && !state.get(POWERED)) return ActionResult.PASS;
return super.onUse(state, world, pos, player, hand, hit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

import com.shnupbups.redstonebits.FakePlayerEntity;
import com.shnupbups.redstonebits.init.ModBlockEntities;
import com.shnupbups.redstonebits.container.BreakerScreenHandler;
Expand All @@ -50,12 +47,10 @@ public BreakerBlockEntity(BlockPos pos, BlockState state) {

public static void serverTick(World world, BlockPos pos, BlockState state, BreakerBlockEntity blockEntity) {
BlockState currentBreakState = world.getBlockState(blockEntity.getBreakPos());
int prevBreakPercentage = blockEntity.getBreakPercentage();
boolean dirty = false;
if (blockEntity.isBreaking()) {
BlockState breakState = blockEntity.getBreakState();
if (breakState == null) blockEntity.startBreak();
if (!blockEntity.getBreakStack().equals(blockEntity.getTool()) || !breakState.equals(currentBreakState) || currentBreakState.isAir() || currentBreakState.getHardness(world, pos) < 0) {
if (breakState == null || (!blockEntity.getBreakStack().equals(blockEntity.getTool()) || !breakState.equals(currentBreakState) || currentBreakState.isAir() || currentBreakState.getHardness(world, pos) < 0)) {
//System.out.println("cancel");
blockEntity.cancelBreak();
} else if (blockEntity.getBreakProgress() >= blockEntity.getBreakTime()) {
Expand All @@ -64,32 +59,25 @@ public static void serverTick(World world, BlockPos pos, BlockState state, Break
} else {
blockEntity.continueBreak();
}

int newBreakPercentage = blockEntity.getBreakPercentage();

if (newBreakPercentage != prevBreakPercentage) {
dirty = true;
world.updateComparators(pos, world.getBlockState(pos).getBlock());

if (newBreakPercentage <= 0 || newBreakPercentage >= 100) {
world.setBlockBreakingInfo(blockEntity.getFakePlayer().getId(), blockEntity.getBreakPos(), -1);
} else {
world.setBlockBreakingInfo(blockEntity.getFakePlayer().getId(), blockEntity.getBreakPos(), blockEntity.getBreakPercentage() / 10);
}
}
}

if (blockEntity.isBreaking() != world.getBlockState(pos).get(ModProperties.BREAKING)) {
world.setBlockState(pos, world.getBlockState(pos).with(ModProperties.BREAKING, blockEntity.isBreaking()));
dirty = true;
}

if (dirty) {
((ServerChunkManager) world.getChunkManager()).markForUpdate(pos);
blockEntity.markDirty();
}
}

public void updateCracksAndComparators() {
if(this.getWorld() == null) return;
this.getWorld().updateComparators(getPos(), this.getWorld().getBlockState(getPos()).getBlock());

int breakPercentage = getBreakPercentage();
int crackProgress = breakPercentage <= 0 || breakPercentage >= 100 ? -1 : breakPercentage / 10;

this.getWorld().setBlockBreakingInfo(getFakePlayer().getId(), getBreakPos(), crackProgress);
}

public static int getBreakPercentage(int breakProgress, int breakTime) {
if (breakTime > 0) {
float div = ((float) breakProgress / (float) breakTime);
Expand Down Expand Up @@ -123,6 +111,7 @@ public void setBreakProgress(int breakProgress) {

public void incrementBreakProgress() {
this.breakProgress++;
this.updateCracksAndComparators();
}

public void resetBreakProgress() {
Expand Down Expand Up @@ -178,13 +167,15 @@ public void cancelBreak() {
this.setBreakState(null);
this.setBreakStack(ItemStack.EMPTY);
this.resetBreakProgress();
this.updateCracksAndComparators();
this.markDirty();
}

public void finishBreak() {
//System.out.println("finish break at "+getBreakPos().toString());
this.breakBlock();
this.cancelBreak();
this.updateCracksAndComparators();
this.markDirty();
}

Expand Down Expand Up @@ -322,6 +313,7 @@ public void clear() {
}

public int getBreakPercentage() {
if(breakStack == null || breakState == null) return -1;
return getBreakPercentage(this.getBreakProgress(), this.getBreakTime());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"depends": {
"fabricloader": ">=0.12.0",
"fabric": ">=0.43.0",
"minecraft": "1.18.x",
"minecraft": "1.18.2",
"java": ">=17"
}
}

0 comments on commit 2ab5f30

Please sign in to comment.