Skip to content

Commit

Permalink
Rewrite misc lib classes in Java
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 24, 2024
1 parent b7443ba commit 361ba8f
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ public void registerDisplays(DisplayRegistry registry) {

@Override
public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) {
add(registry, AdornTags.INSTANCE.getSOFAS().getItem());
add(registry, AdornTags.INSTANCE.getCHAIRS().getItem());
add(registry, AdornTags.INSTANCE.getTABLES().getItem());
add(registry, AdornTags.INSTANCE.getDRAWERS().getItem());
add(registry, AdornTags.INSTANCE.getKITCHEN_COUNTERS().getItem());
add(registry, AdornTags.INSTANCE.getKITCHEN_CUPBOARDS().getItem());
add(registry, AdornTags.INSTANCE.getKITCHEN_SINKS().getItem());
add(registry, AdornTags.INSTANCE.getPOSTS().getItem());
add(registry, AdornTags.INSTANCE.getPLATFORMS().getItem());
add(registry, AdornTags.INSTANCE.getSTEPS().getItem());
add(registry, AdornTags.INSTANCE.getSHELVES().getItem());
add(registry, AdornTags.INSTANCE.getCHIMNEYS().getItem());
add(registry, AdornTags.INSTANCE.getCOFFEE_TABLES().getItem());
add(registry, AdornTags.INSTANCE.getBENCHES().getItem());
add(registry, AdornTags.INSTANCE.getCRATES().getItem());
add(registry, AdornTags.INSTANCE.getTABLE_LAMPS().getItem());
add(registry, AdornTags.INSTANCE.getCANDLELIT_LANTERNS().getItem());
add(registry, AdornTags.SOFAS.item());
add(registry, AdornTags.CHAIRS.item());
add(registry, AdornTags.TABLES.item());
add(registry, AdornTags.DRAWERS.item());
add(registry, AdornTags.KITCHEN_COUNTERS.item());
add(registry, AdornTags.KITCHEN_CUPBOARDS.item());
add(registry, AdornTags.KITCHEN_SINKS.item());
add(registry, AdornTags.POSTS.item());
add(registry, AdornTags.PLATFORMS.item());
add(registry, AdornTags.STEPS.item());
add(registry, AdornTags.SHELVES.item());
add(registry, AdornTags.CHIMNEYS.item());
add(registry, AdornTags.COFFEE_TABLES.item());
add(registry, AdornTags.BENCHES.item());
add(registry, AdornTags.CRATES.item());
add(registry, AdornTags.TABLE_LAMPS.item());
add(registry, AdornTags.CANDLELIT_LANTERNS.item());
}

private static void add(CollapsibleEntryRegistry registry, TagKey<Item> tag) {
Expand Down
33 changes: 33 additions & 0 deletions common/src/main/java/juuxel/adorn/lib/AdornGameRules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package juuxel.adorn.lib;

import juuxel.adorn.AdornCommon;
import juuxel.adorn.config.Config;
import juuxel.adorn.config.ConfigManager;
import net.minecraft.world.GameRules;
import net.minecraft.world.GameRules.BooleanRule;
import net.minecraft.world.GameRules.Category;
import net.minecraft.world.GameRules.Key;
import net.minecraft.world.GameRules.Rule;
import net.minecraft.world.GameRules.Type;

import java.util.function.Predicate;

public final class AdornGameRules {
public static final Key<BooleanRule> SKIP_NIGHT_ON_SOFAS =
register("skipNightOnSofas", Category.PLAYER, createBooleanRule(defaults -> defaults.skipNightOnSofas));
public static final Key<BooleanRule> INFINITE_KITCHEN_SINKS =
register("infiniteKitchenSinks", Category.MISC, createBooleanRule(defaults -> defaults.infiniteKitchenSinks));
public static final Key<BooleanRule> DROP_LOCKED_TRADING_STATIONS =
register("dropLockedTradingStations", Category.DROPS, createBooleanRule(defaults -> defaults.dropLockedTradingStations));

public static void init() {
}

private static Type<BooleanRule> createBooleanRule(Predicate<Config.GameRuleDefaults> defaultGetter) {
return BooleanRule.create(defaultGetter.test(ConfigManager.Companion.config().gameRuleDefaults));
}

private static <T extends Rule<T>> Key<T> register(String name, Category category, Type<T> type) {
return GameRules.register(AdornCommon.NAMESPACE + ':' + name, category, type);
}
}
89 changes: 89 additions & 0 deletions common/src/main/java/juuxel/adorn/lib/AdornSounds.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package juuxel.adorn.lib;

import juuxel.adorn.AdornCommon;
import juuxel.adorn.lib.registry.Registered;
import juuxel.adorn.lib.registry.Registrar;
import juuxel.adorn.lib.registry.RegistrarFactory;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvent;

import java.util.function.Supplier;

public final class AdornSounds {
public static final Registrar<SoundEvent> SOUNDS = RegistrarFactory.get().create(RegistryKeys.SOUND_EVENT);

public static final Registered<SoundEvent> BLOCK_CHAIN_LINK_FENCE_BREAK = register("block.adorn.chain_link_fence.break");
public static final Registered<SoundEvent> BLOCK_CHAIN_LINK_FENCE_STEP = register("block.adorn.chain_link_fence.step");
public static final Registered<SoundEvent> BLOCK_CHAIN_LINK_FENCE_PLACE = register("block.adorn.chain_link_fence.place");
public static final Registered<SoundEvent> BLOCK_CHAIN_LINK_FENCE_HIT = register("block.adorn.chain_link_fence.hit");
public static final Registered<SoundEvent> BLOCK_CHAIN_LINK_FENCE_FALL = register("block.adorn.chain_link_fence.fall");
public static final Registered<SoundEvent> ITEM_WATERING_CAN_WATER = register("item.adorn.watering_can.water");

public static final BlockSoundGroup CHAIN_LINK_FENCE = new LazyBlockSoundGroup(
1.0F,
1.5F,
BLOCK_CHAIN_LINK_FENCE_BREAK,
BLOCK_CHAIN_LINK_FENCE_STEP,
BLOCK_CHAIN_LINK_FENCE_PLACE,
BLOCK_CHAIN_LINK_FENCE_HIT,
BLOCK_CHAIN_LINK_FENCE_FALL
);

public static void init() {
}

private static Registered<SoundEvent> register(String name) {
return SOUNDS.register(name, () -> SoundEvent.of(AdornCommon.id(name)));
}

private static final class LazyBlockSoundGroup extends BlockSoundGroup {
private final Supplier<SoundEvent> breakSound;
private final Supplier<SoundEvent> stepSound;
private final Supplier<SoundEvent> placeSound;
private final Supplier<SoundEvent> hitSound;
private final Supplier<SoundEvent> fallSound;

LazyBlockSoundGroup(
float volume,
float pitch,
Supplier<SoundEvent> breakSound,
Supplier<SoundEvent> stepSound,
Supplier<SoundEvent> placeSound,
Supplier<SoundEvent> hitSound,
Supplier<SoundEvent> fallSound
) {
super(volume, pitch, null, null, null, null, null);
this.breakSound = breakSound;
this.stepSound = stepSound;
this.placeSound = placeSound;
this.hitSound = hitSound;
this.fallSound = fallSound;
}

@Override
public SoundEvent getBreakSound() {
return breakSound.get();
}

@Override
public SoundEvent getStepSound() {
return stepSound.get();
}

@Override
public SoundEvent getPlaceSound() {
return placeSound.get();
}

@Override
public SoundEvent getHitSound() {
return hitSound.get();
}

@Override
public SoundEvent getFallSound() {
return fallSound.get();
}
}
}
27 changes: 27 additions & 0 deletions common/src/main/java/juuxel/adorn/lib/AdornStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package juuxel.adorn.lib;

import juuxel.adorn.AdornCommon;
import net.minecraft.stat.StatFormatter;
import net.minecraft.stat.Stats;
import net.minecraft.util.Identifier;

public final class AdornStats {
public static final Identifier OPEN_BREWER = register("open_brewer", StatFormatter.DEFAULT);
public static final Identifier OPEN_DRAWER = register("open_drawer", StatFormatter.DEFAULT);
public static final Identifier OPEN_KITCHEN_CUPBOARD = register("open_kitchen_cupboard", StatFormatter.DEFAULT);
public static final Identifier INTERACT_WITH_SHELF = register("interact_with_shelf", StatFormatter.DEFAULT);
public static final Identifier INTERACT_WITH_TABLE_LAMP = register("interact_with_table_lamp", StatFormatter.DEFAULT);
public static final Identifier INTERACT_WITH_TRADING_STATION = register("interact_with_trading_station", StatFormatter.DEFAULT);
public static final Identifier DYE_TABLE_LAMP = register("dye_table_lamp", StatFormatter.DEFAULT);
public static final Identifier DYE_SOFA = register("dye_sofa", StatFormatter.DEFAULT);
public static final Identifier SIT_ON_CHAIR = register("sit_on_chair", StatFormatter.DEFAULT);
public static final Identifier SIT_ON_SOFA = register("sit_on_sofa", StatFormatter.DEFAULT);
public static final Identifier SIT_ON_BENCH = register("sit_on_bench", StatFormatter.DEFAULT);

private static Identifier register(String id, StatFormatter formatter) {
return Stats.register(AdornCommon.NAMESPACE + ':' + id, formatter);
}

public static void init() {
}
}
56 changes: 56 additions & 0 deletions common/src/main/java/juuxel/adorn/lib/AdornTags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package juuxel.adorn.lib;

import juuxel.adorn.AdornCommon;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;

public final class AdornTags {
public static final TagPair CHAIRS = blockAndItem("chairs");
public static final TagPair TABLES = blockAndItem("tables");
public static final TagPair DRAWERS = blockAndItem("drawers");
public static final TagPair BENCHES = blockAndItem("benches");
public static final TagPair KITCHEN_COUNTERS = blockAndItem("kitchen_counters");
public static final TagPair KITCHEN_CUPBOARDS = blockAndItem("kitchen_cupboards");
public static final TagPair KITCHEN_SINKS = blockAndItem("kitchen_sinks");
public static final TagPair KITCHEN_BLOCKS = blockAndItem("kitchen_blocks");
public static final TagPair SOFAS = blockAndItem("sofas");
public static final TagPair POSTS = blockAndItem("posts");
public static final TagPair PLATFORMS = blockAndItem("platforms");
public static final TagPair STEPS = blockAndItem("steps");
public static final TagPair WOODEN_POSTS = blockAndItem("wooden_posts");
public static final TagPair WOODEN_PLATFORMS = blockAndItem("wooden_platforms");
public static final TagPair WOODEN_STEPS = blockAndItem("wooden_steps");
public static final TagPair STONE_POSTS = blockAndItem("stone_posts");
public static final TagPair STONE_PLATFORMS = blockAndItem("stone_platforms");
public static final TagPair STONE_STEPS = blockAndItem("stone_steps");
public static final TagPair SHELVES = blockAndItem("shelves");
public static final TagPair WOODEN_SHELVES = blockAndItem("wooden_shelves");
public static final TagPair CHIMNEYS = blockAndItem("chimneys");
public static final TagPair CRATES = blockAndItem("crates");
public static final TagPair COFFEE_TABLES = blockAndItem("coffee_tables");
public static final TagPair TABLE_LAMPS = blockAndItem("table_lamps");
public static final TagPair CANDLELIT_LANTERNS = blockAndItem("candlelit_lanterns");
public static final TagPair COPPER_PIPES = blockAndItem("copper_pipes");
public static final TagKey<Block> COPPER_PIPES_CONNECT_TO = block("copper_pipes_connect_to");
public static final TagKey<Item> WATERING_CAN_FERTILIZERS = item("watering_can_fertilizers");

public static void init() {
}

private static TagKey<Block> block(String path) {
return TagKey.of(RegistryKeys.BLOCK, AdornCommon.id(path));
}

private static TagKey<Item> item(String path) {
return TagKey.of(RegistryKeys.ITEM, AdornCommon.id(path));
}

private static TagPair blockAndItem(String path) {
return new TagPair(block(path), item(path));
}

public record TagPair(TagKey<Block> block, TagKey<Item> item) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ItemStack craft(RecipeInputInventory inventory, DynamicRegistryManager re
return null;
}
} else if (!stack.isEmpty()) {
if (stack.isIn(AdornTags.INSTANCE.getWATERING_CAN_FERTILIZERS())) {
if (stack.isIn(AdornTags.WATERING_CAN_FERTILIZERS)) {
fertilizers++;
} else {
// Unwanted item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WateringCanItem(settings: Settings) : ItemWithDescription(settings) {
waterLevel--
nbt.putInt(NBT_WATER_LEVEL, waterLevel)
world.emitGameEvent(user, GameEvent.ITEM_INTERACT_FINISH, pos)
world.playSound(user, pos, AdornSounds.ITEM_WATERING_CAN_WATER, SoundCategory.PLAYERS)
world.playSound(user, pos, AdornSounds.ITEM_WATERING_CAN_WATER.get(), SoundCategory.PLAYERS)
user.itemCooldownManager.set(this, 10)

val mut = BlockPos.Mutable()
Expand Down
33 changes: 0 additions & 33 deletions common/src/main/kotlin/juuxel/adorn/lib/AdornGameRules.kt

This file was deleted.

51 changes: 0 additions & 51 deletions common/src/main/kotlin/juuxel/adorn/lib/AdornSounds.kt

This file was deleted.

26 changes: 0 additions & 26 deletions common/src/main/kotlin/juuxel/adorn/lib/AdornStats.kt

This file was deleted.

Loading

0 comments on commit 361ba8f

Please sign in to comment.