Skip to content

Commit

Permalink
update to 1.19.4, add wall functionality to hacksaw
Browse files Browse the repository at this point in the history
  • Loading branch information
deli73 committed Aug 23, 2023
1 parent f0c5671 commit 6d05cc6
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 30 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.22

# Mod Properties
mod_version = 0.2.4
mod_version = 0.2.4-1.19.4
maven_group = xyz.sunrose
archives_base_name = matchbox

# Dependencies
fabric_version=0.47.8+1.18.2
fabric_version=0.87.0+1.19.4
7 changes: 5 additions & 2 deletions src/main/java/xyz/sunrose/matchbox/Matchbox.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package xyz.sunrose.matchbox;

import net.fabricmc.api.ModInitializer;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.sunrose.matchbox.blocks.MatchboxBlocks;
Expand All @@ -15,7 +18,7 @@ public class Matchbox implements ModInitializer {

public static final Identifier SAW_SOUND_ID = new Identifier(MODID, "saw");
public static SoundEvent SAW_SOUND = Registry.register(
Registry.SOUND_EVENT, SAW_SOUND_ID, new SoundEvent(SAW_SOUND_ID)
Registries.SOUND_EVENT, SAW_SOUND_ID, SoundEvent.of(SAW_SOUND_ID)
);

@Override
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/xyz/sunrose/matchbox/blocks/MatchboxBlocks.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
package xyz.sunrose.matchbox.blocks;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import xyz.sunrose.matchbox.Matchbox;

public class MatchboxBlocks {
private static final Identifier MESH_ID = new Identifier(Matchbox.MODID, "mesh");
public static final Block MESH = Registry.register(
Registry.BLOCK, MESH_ID,
Registries.BLOCK, MESH_ID,
new MeshBlock(FabricBlockSettings.copyOf(Blocks.CHAIN).strength(4,6).nonOpaque())
);
public static final Item MESH_ITEM = Registry.register(
Registry.ITEM, MESH_ID,
new BlockItem(MESH, new FabricItemSettings().group(ItemGroup.REDSTONE))
Registries.ITEM, MESH_ID,
new BlockItem(MESH, new FabricItemSettings())
);

public static void init() {
ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register(entries -> entries.add(MESH_ITEM));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(entries -> entries.add(MESH_ITEM));
}

public static void clientInit() {
Expand Down
62 changes: 57 additions & 5 deletions src/main/java/xyz/sunrose/matchbox/items/DetacherToolItem.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package xyz.sunrose.matchbox.items;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.HorizontalConnectingBlock;
import net.minecraft.block.*;
import net.minecraft.block.enums.WallShape;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -28,7 +27,7 @@ public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos blockPos = context.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
if(blockState.getBlock() instanceof HorizontalConnectingBlock block) { // TODO maybe check for side properties instead of this
if(blockState.getBlock() instanceof HorizontalConnectingBlock) { // TODO maybe check for side properties instead of this
Direction side = hitSide(context);
if ( blockState.get(ConnectingBlock.FACING_PROPERTIES.get(side)) ) { // only execute if the relevant side has a connection
//detach the relevant side
Expand All @@ -45,6 +44,31 @@ public ActionResult useOnBlock(ItemUsageContext context) {
}
}

else if(blockState.getBlock() instanceof WallBlock) {
Direction side = hitSide(context);
EnumProperty<WallShape> sideToCheck = null;
switch (side) {
case DOWN, UP -> throw new IllegalArgumentException("Matchbox getting invalid side input in wall's useOnBlock");
case NORTH -> sideToCheck = WallBlock.NORTH_SHAPE;
case SOUTH -> sideToCheck = WallBlock.SOUTH_SHAPE;
case WEST -> sideToCheck = WallBlock.WEST_SHAPE;
case EAST -> sideToCheck = WallBlock.EAST_SHAPE;
}
if ( blockState.get(sideToCheck) != WallShape.NONE) { // only execute if the relevant side has a connection
//detach the relevant side
BlockState finalState = detachWallSide(world, blockState, blockPos, side, sideToCheck);
world.setBlockState(blockPos, finalState, Block.NOTIFY_LISTENERS | Block.FORCE_STATE); //flags to not update neighbors

world.playSound(
player, blockPos, Matchbox.SAW_SOUND,
SoundCategory.BLOCKS, 1f, 0.8f + 0.01f * world.random.nextFloat()
);

world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, blockPos);
return ActionResult.success(world.isClient());
}
}

return super.useOnBlock(context);
}

Expand All @@ -60,6 +84,34 @@ private BlockState detachSide(World world, BlockState state, BlockPos pos, Direc
return newState;
}

private BlockState detachWallSide(World world, BlockState state, BlockPos pos, Direction dir, EnumProperty<WallShape> side) {
// disconnect the wall on our side...
BlockState newState = state.with(side, WallShape.NONE).with(WallBlock.UP, true);
BlockState neighbor = world.getBlockState(pos.offset(dir));
if (neighbor.getBlock() instanceof WallBlock) {
world.setBlockState(pos.offset(dir), neighbor.with(oppositeSide(dir), WallShape.NONE).with(WallBlock.UP, true), Block.NOTIFY_LISTENERS | Block.FORCE_STATE);
}
return newState;
}

private EnumProperty<WallShape> oppositeSide(Direction side) {
switch (side) {
case NORTH -> {
return WallBlock.SOUTH_SHAPE;
}
case SOUTH -> {
return WallBlock.NORTH_SHAPE;
}
case WEST -> {
return WallBlock.EAST_SHAPE;
}
case EAST -> {
return WallBlock.WEST_SHAPE;
}
default -> throw new IllegalArgumentException("Matchbox getting invalid input to oppositeSide");
}
}

private Direction hitSide(ItemUsageContext context) {
Vec3d pos = context.getHitPos();
//position relative to center of block
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/xyz/sunrose/matchbox/items/MatchboxItems.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package xyz.sunrose.matchbox.items;

import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import xyz.sunrose.matchbox.Matchbox;

public class MatchboxItems {
public static Item MATCHBOX = Registry.register(
Registry.ITEM, new Identifier(Matchbox.MODID, "matchbox"),
new MatchboxToolItem(new FabricItemSettings().maxDamage(64).group(ItemGroup.TOOLS))
Registries.ITEM, new Identifier(Matchbox.MODID, "matchbox"),
new MatchboxToolItem(new FabricItemSettings().maxDamage(64))
);

public static Item DETACHER = Registry.register(
Registry.ITEM, new Identifier(Matchbox.MODID, "detacher"),
new DetacherToolItem(new FabricItemSettings().maxCount(1).group(ItemGroup.TOOLS))
Registries.ITEM, new Identifier(Matchbox.MODID, "detacher"),
new DetacherToolItem(new FabricItemSettings().maxCount(1))
);

public static Item WOOD_GLUE = Registry.register(
Registry.ITEM, new Identifier(Matchbox.MODID, "wood_glue"),
new WoodGlueItem(new FabricItemSettings().maxDamage(64).group(ItemGroup.TOOLS))
Registries.ITEM, new Identifier(Matchbox.MODID, "wood_glue"),
new WoodGlueItem(new FabricItemSettings().maxDamage(64))
);

/*public static Item REDSTONE_TOOL = Registry.register(
Expand All @@ -29,6 +31,10 @@ Registry.ITEM, new Identifier(Matchbox.MODID, "redstone_tool"),
);*/

public static void init () {

ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(entries -> {
entries.add(MATCHBOX);
entries.add(DETACHER);
entries.add(WOOD_GLUE);
});
}
}
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
],

"depends": {
"fabricloader": ">=0.13.3",
"fabricloader": ">=0.14",
"fabric": "*",
"minecraft": "1.18.x",
"minecraft": "1.19.x",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit 6d05cc6

Please sign in to comment.