Skip to content

Commit

Permalink
Fix some long-standing sign bugs.
Browse files Browse the repository at this point in the history
- Fix signs dropping as the wrong item
- Fix breaking signs using the wrong particles
* Make block and item registration immediate
  • Loading branch information
gniftygnome committed Jun 15, 2023
1 parent 4b41564 commit cc1e146
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"variants": {
"": { "model": "block/oak_sign" }
"": { "model": "traverse:block/fir_sign" }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"variants": {
"": { "model": "block/oak_sign" }
"": { "model": "traverse:block/fir_sign" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.terraformersmc.traverse.feature.TraversePlacedFeatures;
import com.terraformersmc.traverse.feature.placer.TraversePlacerTypes;
import com.terraformersmc.traverse.item.TraverseBoatTypes;
import com.terraformersmc.traverse.item.TraverseItems;
import com.terraformersmc.traverse.villager.TraverseVillagerTypes;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
Expand All @@ -30,6 +31,7 @@ public class Traverse implements ModInitializer {

private static void register() {
TraverseBlocks.register();
TraverseItems.register();
TraverseBoatTypes.register();
TraversePlacedFeatures.init();
TraverseBiomes.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import com.terraformersmc.traverse.Traverse;
import com.terraformersmc.traverse.block.sapling.TraverseSaplingGenerator;
import com.terraformersmc.traverse.feature.TraverseConfiguredFeatures;
import com.terraformersmc.traverse.item.TraverseItems;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.fabricmc.fabric.api.registry.StrippableBlockRegistry;
import net.minecraft.block.*;
import net.minecraft.entity.EntityType;
import net.minecraft.item.*;
Expand All @@ -19,84 +21,60 @@
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;

import java.util.HashMap;
import java.util.Map;

public class TraverseBlocks {

private static final Map<Identifier, BlockItem> ITEMS = new HashMap<>();
private static final Map<Identifier, Block> BLOCKS = new HashMap<>();

public static final Block RED_AUTUMNAL_LEAVES = add("red_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block RED_AUTUMNAL_SAPLING = add("red_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.RED_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);
public static final Block BROWN_AUTUMNAL_LEAVES = add("brown_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block BROWN_AUTUMNAL_SAPLING = add("brown_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.BROWN_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);
public static final Block ORANGE_AUTUMNAL_LEAVES = add("orange_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block ORANGE_AUTUMNAL_SAPLING = add("orange_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.ORANGE_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);
public static final Block YELLOW_AUTUMNAL_LEAVES = add("yellow_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block YELLOW_AUTUMNAL_SAPLING = add("yellow_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.YELLOW_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);

public static final Block FIR_PLANKS = add("fir_planks", new Block(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_SAPLING = add("fir_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.FIR_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);

public static final Block STRIPPED_FIR_LOG = add("stripped_fir_log", createLog(MapColor.BROWN, MapColor.OAK_TAN), ItemGroup.BUILDING_BLOCKS);
public static final Block STRIPPED_FIR_WOOD = add("stripped_fir_wood", createLog(MapColor.OAK_TAN, MapColor.OAK_TAN), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_LOG = add("fir_log", new StrippableLogBlock(() -> STRIPPED_FIR_LOG, MapColor.BROWN, FabricBlockSettings.copyOf(Blocks.DARK_OAK_LOG)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_WOOD = add("fir_wood", new StrippableLogBlock(() -> STRIPPED_FIR_WOOD, MapColor.BROWN, FabricBlockSettings.copyOf(Blocks.DARK_OAK_LOG)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_LEAVES = add("fir_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block FIR_SLAB = add("fir_slab", new SlabBlock(FabricBlockSettings.copyOf(Blocks.OAK_SLAB)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_PRESSURE_PLATE = add("fir_pressure_plate", new PressurePlateBlock(PressurePlateBlock.ActivationRule.EVERYTHING, FabricBlockSettings.copyOf(Blocks.OAK_PRESSURE_PLATE)), ItemGroup.REDSTONE);
public static final Block FIR_FENCE = add("fir_fence", new FenceBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE)), ItemGroup.DECORATIONS);
public static final Block FIR_TRAPDOOR = add("fir_trapdoor", new TrapdoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_TRAPDOOR)), ItemGroup.REDSTONE);
public static final Block FIR_FENCE_GATE = add("fir_fence_gate", new FenceGateBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE_GATE)), ItemGroup.REDSTONE);
public static final Block FIR_STAIRS = add("fir_stairs", new StairsBlock(FIR_PLANKS.getDefaultState(), FabricBlockSettings.copyOf(Blocks.OAK_STAIRS)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_BUTTON = add("fir_button", new WoodenButtonBlock(FabricBlockSettings.copyOf(Blocks.OAK_BUTTON)), ItemGroup.REDSTONE);
public static final Block FIR_DOOR = add("fir_door", new DoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_DOOR)), ItemGroup.REDSTONE);
public static final Block RED_AUTUMNAL_LEAVES = withItem("red_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(MapColor.TERRACOTTA_RED).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block RED_AUTUMNAL_SAPLING = withItem("red_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.RED_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING).mapColor(MapColor.TERRACOTTA_RED)), ItemGroup.DECORATIONS);
public static final Block BROWN_AUTUMNAL_LEAVES = withItem("brown_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(MapColor.TERRACOTTA_BROWN).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block BROWN_AUTUMNAL_SAPLING = withItem("brown_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.BROWN_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING).mapColor(MapColor.TERRACOTTA_BROWN)), ItemGroup.DECORATIONS);
public static final Block ORANGE_AUTUMNAL_LEAVES = withItem("orange_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(MapColor.TERRACOTTA_ORANGE).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block ORANGE_AUTUMNAL_SAPLING = withItem("orange_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.ORANGE_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING).mapColor(MapColor.TERRACOTTA_ORANGE)), ItemGroup.DECORATIONS);
public static final Block YELLOW_AUTUMNAL_LEAVES = withItem("yellow_autumnal_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(MapColor.TERRACOTTA_YELLOW).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block YELLOW_AUTUMNAL_SAPLING = withItem("yellow_autumnal_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.YELLOW_AUTUMNAL_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING).mapColor(MapColor.TERRACOTTA_YELLOW)), ItemGroup.DECORATIONS);

public static final Block FIR_PLANKS = withItem("fir_planks", new Block(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_SAPLING = withItem("fir_sapling", new SaplingBlock(new TraverseSaplingGenerator(() -> TraverseConfiguredFeatures.FIR_TREE), SaplingBlock.Settings.copy(Blocks.OAK_SAPLING)), ItemGroup.DECORATIONS);

public static final Block STRIPPED_FIR_LOG = withItem("stripped_fir_log", createLog(MapColor.BROWN, MapColor.OAK_TAN), ItemGroup.BUILDING_BLOCKS);
public static final Block STRIPPED_FIR_WOOD = withItem("stripped_fir_wood", createLog(MapColor.OAK_TAN, MapColor.OAK_TAN), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_LOG = withItem("fir_log", new StrippableLogBlock(() -> STRIPPED_FIR_LOG, MapColor.BROWN, FabricBlockSettings.copyOf(Blocks.DARK_OAK_LOG)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_WOOD = withItem("fir_wood", new StrippableLogBlock(() -> STRIPPED_FIR_WOOD, MapColor.BROWN, FabricBlockSettings.copyOf(Blocks.DARK_OAK_LOG)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_LEAVES = withItem("fir_leaves", new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).allowsSpawning(TraverseBlocks::canSpawnOnLeaves).suffocates(TraverseBlocks::never).blockVision(TraverseBlocks::never)), ItemGroup.DECORATIONS);
public static final Block FIR_SLAB = withItem("fir_slab", new SlabBlock(FabricBlockSettings.copyOf(Blocks.OAK_SLAB)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_PRESSURE_PLATE = withItem("fir_pressure_plate", new PressurePlateBlock(PressurePlateBlock.ActivationRule.EVERYTHING, FabricBlockSettings.copyOf(Blocks.OAK_PRESSURE_PLATE)), ItemGroup.REDSTONE);
public static final Block FIR_FENCE = withItem("fir_fence", new FenceBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE)), ItemGroup.DECORATIONS);
public static final Block FIR_TRAPDOOR = withItem("fir_trapdoor", new TrapdoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_TRAPDOOR)), ItemGroup.REDSTONE);
public static final Block FIR_FENCE_GATE = withItem("fir_fence_gate", new FenceGateBlock(FabricBlockSettings.copyOf(Blocks.OAK_FENCE_GATE)), ItemGroup.REDSTONE);
public static final Block FIR_STAIRS = withItem("fir_stairs", new StairsBlock(FIR_PLANKS.getDefaultState(), FabricBlockSettings.copyOf(Blocks.OAK_STAIRS)), ItemGroup.BUILDING_BLOCKS);
public static final Block FIR_BUTTON = withItem("fir_button", new WoodenButtonBlock(FabricBlockSettings.copyOf(Blocks.OAK_BUTTON)), ItemGroup.REDSTONE);
public static final Block FIR_DOOR = withItem("fir_door", new DoorBlock(FabricBlockSettings.copyOf(Blocks.OAK_DOOR)), ItemGroup.REDSTONE);
private static final Identifier FIR_SIGN_TEXTURE = new Identifier(Traverse.MOD_ID, "entity/sign/fir");
public static final TerraformSignBlock FIR_SIGN = add("fir_sign", new TerraformSignBlock(FIR_SIGN_TEXTURE, FabricBlockSettings.copyOf(Blocks.OAK_SIGN)));
public static final Block FIR_WALL_SIGN = add("fir_wall_sign", new TerraformWallSignBlock(FIR_SIGN_TEXTURE, FabricBlockSettings.copyOf(Blocks.OAK_WALL_SIGN)));
public static final Item FIR_SIGN_ITEM = add("fir_sign", new SignItem(new Item.Settings().maxCount(16).group(ItemGroup.DECORATIONS), FIR_SIGN, FIR_WALL_SIGN));
public static final Block FIR_WALL_SIGN = add("fir_wall_sign", new TerraformWallSignBlock(FIR_SIGN_TEXTURE, FabricBlockSettings.copyOf(Blocks.OAK_WALL_SIGN).dropsLike(FIR_SIGN)));
public static final Item FIR_SIGN_ITEM = TraverseItems.add("fir_sign", new SignItem(new Item.Settings().maxCount(16).group(ItemGroup.DECORATIONS), FIR_SIGN, FIR_WALL_SIGN));

public static final Block POTTED_RED_AUTUMNAL_SAPLING = add("potted_red_autumnal_sapling", new FlowerPotBlock(RED_AUTUMNAL_SAPLING, FabricBlockSettings.copyOf(Blocks.POTTED_OAK_SAPLING)));
public static final Block POTTED_BROWN_AUTUMNAL_SAPLING = add("potted_brown_autumnal_sapling", new FlowerPotBlock(BROWN_AUTUMNAL_SAPLING, FabricBlockSettings.copyOf(Blocks.POTTED_OAK_SAPLING)));
public static final Block POTTED_ORANGE_AUTUMNAL_SAPLING = add("potted_orange_autumnal_sapling", new FlowerPotBlock(ORANGE_AUTUMNAL_SAPLING, FabricBlockSettings.copyOf(Blocks.POTTED_OAK_SAPLING)));
public static final Block POTTED_YELLOW_AUTUMNAL_SAPLING = add("potted_yellow_autumnal_sapling", new FlowerPotBlock(YELLOW_AUTUMNAL_SAPLING, FabricBlockSettings.copyOf(Blocks.POTTED_OAK_SAPLING)));
public static final Block POTTED_FIR_SAPLING = add("potted_fir_sapling", new FlowerPotBlock(FIR_SAPLING, FabricBlockSettings.copyOf(Blocks.POTTED_OAK_SAPLING)));

private static <B extends Block> B add(String name, B block, ItemGroup tab) {
return add(name, block, new BlockItem(block, new Item.Settings().group(tab)));
}
private static <B extends Block> B withItem(String name, B block, ItemGroup tab) {
TraverseItems.add(name, new BlockItem(block, new Item.Settings().group(tab)));

private static <B extends Block> B add(String name, B block, BlockItem item) {
add(name, block);
if (item != null) {
item.appendBlocks(Item.BLOCK_ITEMS, item);
ITEMS.put(new Identifier(Traverse.MOD_ID, name), item);
}
return block;
return add(name, block);
}

private static <B extends Block> B add(String name, B block) {
BLOCKS.put(new Identifier(Traverse.MOD_ID, name), block);
return block;
}
Registry.register(Registry.BLOCK, Identifier.of(Traverse.MOD_ID, name), block);

private static <I extends BlockItem> I add(String name, I item) {
item.appendBlocks(Item.BLOCK_ITEMS, item);
ITEMS.put(new Identifier(Traverse.MOD_ID, name), item);
return item;
return block;
}

public static void register() {
for (Identifier id : ITEMS.keySet()) {
Registry.register(Registry.ITEM, id, ITEMS.get(id));
}
for (Identifier id : BLOCKS.keySet()) {
Registry.register(Registry.BLOCK, id, BLOCKS.get(id));
}
addFuels();
addFlammables();
addCompostables();
addFlammables();
addFuels();
addStrippables();
}

private static void addCompostables() {
Expand All @@ -118,6 +96,7 @@ private static void addCompostables() {

private static void addFlammables() {
FlammableBlockRegistry flammableRegistry = FlammableBlockRegistry.getDefaultInstance();

flammableRegistry.add(FIR_PLANKS, 5, 20);
flammableRegistry.add(FIR_SLAB, 5, 20);
flammableRegistry.add(FIR_FENCE_GATE, 5, 20);
Expand All @@ -136,10 +115,16 @@ private static void addFlammables() {

private static void addFuels() {
FuelRegistry fuelRegistry = FuelRegistry.INSTANCE;

fuelRegistry.add(FIR_FENCE, 300);
fuelRegistry.add(FIR_FENCE_GATE, 300);
}

private static void addStrippables() {
StrippableBlockRegistry.register(FIR_LOG, STRIPPED_FIR_LOG);
StrippableBlockRegistry.register(FIR_WOOD, STRIPPED_FIR_WOOD);
}

// Todo: fix when Fabric API supports `of(Material material, Function<BlockState, MapColor> mapColor)`
private static PillarBlock createLog(MapColor topColor, MapColor sideColor) {
return new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_LOG).strength(2.0F).sounds(BlockSoundGroup.WOOD));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.terraformersmc.traverse.item;

import com.terraformersmc.traverse.Traverse;
import net.minecraft.item.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class TraverseItems {
public static <I extends Item> I add(String name, I item) {
if (item instanceof BlockItem blockItem) {
blockItem.appendBlocks(Item.BLOCK_ITEMS, item);
}

return Registry.register(Registry.ITEM, Identifier.of(Traverse.MOD_ID, name), item);
}

public static void register() { }
}

0 comments on commit cc1e146

Please sign in to comment.