Fixed structure features and code style

This commit is contained in:
paulevsGitch 2021-07-10 16:07:44 +03:00
parent d431f2555c
commit 5a9365e2bb
153 changed files with 2304 additions and 2459 deletions

View file

@ -8,7 +8,7 @@ yarn_mappings= 6
loader_version= 0.11.6 loader_version= 0.11.6
# Mod Properties # Mod Properties
mod_version = 0.2.0 mod_version = 0.2.1
maven_group = ru.bclib maven_group = ru.bclib
archives_base_name = bclib archives_base_name = bclib

View file

@ -1,10 +1,6 @@
package ru.bclib.api; package ru.bclib.api;
import java.util.HashMap;
import java.util.Random;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.impl.biome.InternalBiomeData; import net.fabricmc.fabric.impl.biome.InternalBiomeData;
@ -20,6 +16,9 @@ import net.minecraft.world.level.biome.Biomes;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import java.util.HashMap;
import java.util.Random;
public class BiomeAPI { public class BiomeAPI {
/** /**
* Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs. * Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs.
@ -33,6 +32,7 @@ public class BiomeAPI {
/** /**
* Initialize registry for current server. * Initialize registry for current server.
*
* @param server - {@link MinecraftServer} * @param server - {@link MinecraftServer}
*/ */
public static void initRegistry(MinecraftServer server) { public static void initRegistry(MinecraftServer server) {
@ -49,23 +49,19 @@ public class BiomeAPI {
/** /**
* Adds {@link BCLBiome} to FabricAPI biomes as the Nether biome (with random {@link ClimateParameters}). * Adds {@link BCLBiome} to FabricAPI biomes as the Nether biome (with random {@link ClimateParameters}).
*
* @param biome - {@link BCLBiome}. * @param biome - {@link BCLBiome}.
*/ */
public static void addNetherBiomeToFabricApi(BCLBiome biome) { public static void addNetherBiomeToFabricApi(BCLBiome biome) {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
Random random = new Random(biome.getID().toString().hashCode()); Random random = new Random(biome.getID().toString().hashCode());
ClimateParameters parameters = new ClimateParameters( ClimateParameters parameters = new ClimateParameters(MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random));
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random)
);
InternalBiomeData.addNetherBiome(key, parameters); InternalBiomeData.addNetherBiome(key, parameters);
} }
/** /**
* Adds {@link BCLBiome} to FabricAPI biomes as an End land biome (generating on islands). * Adds {@link BCLBiome} to FabricAPI biomes as an End land biome (generating on islands).
*
* @param biome - {@link BCLBiome}. * @param biome - {@link BCLBiome}.
*/ */
public static void addEndLandBiomeToFabricApi(BCLBiome biome) { public static void addEndLandBiomeToFabricApi(BCLBiome biome) {
@ -77,6 +73,7 @@ public class BiomeAPI {
/** /**
* Adds {@link BCLBiome} to FabricAPI biomes as an End void biome (generating between islands in the void). * Adds {@link BCLBiome} to FabricAPI biomes as an End void biome (generating between islands in the void).
*
* @param biome - {@link BCLBiome}. * @param biome - {@link BCLBiome}.
*/ */
public static void addEndVoidBiomeToFabricApi(BCLBiome biome) { public static void addEndVoidBiomeToFabricApi(BCLBiome biome) {
@ -87,6 +84,7 @@ public class BiomeAPI {
/** /**
* Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes.
*
* @param biome - {@link Biome} from world. * @param biome - {@link Biome} from world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
@ -99,6 +97,7 @@ public class BiomeAPI {
/** /**
* Get {@link BCLBiome} from biome on client. Used in fog rendering. * Get {@link BCLBiome} from biome on client. Used in fog rendering.
*
* @param biome - {@link Biome} from client world. * @param biome - {@link Biome} from client world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
@ -116,6 +115,7 @@ public class BiomeAPI {
/** /**
* Get biome {@link ResourceLocation} from given {@link Biome}. * Get biome {@link ResourceLocation} from given {@link Biome}.
*
* @param biome - {@link Biome} from server world. * @param biome - {@link Biome} from server world.
* @return biome {@link ResourceLocation}. * @return biome {@link ResourceLocation}.
*/ */
@ -126,6 +126,7 @@ public class BiomeAPI {
/** /**
* Get {@link BCLBiome} from given {@link ResourceLocation}. * Get {@link BCLBiome} from given {@link ResourceLocation}.
*
* @param biomeID - biome {@link ResourceLocation}. * @param biomeID - biome {@link ResourceLocation}.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
@ -135,6 +136,7 @@ public class BiomeAPI {
/** /**
* Get actual {@link Biome} from given {@link BCLBiome}. If it is null it will request it from current {@link Registry}. * Get actual {@link Biome} from given {@link BCLBiome}. If it is null it will request it from current {@link Registry}.
*
* @param biome - {@link BCLBiome}. * @param biome - {@link BCLBiome}.
* @return {@link Biome}. * @return {@link Biome}.
*/ */
@ -149,6 +151,7 @@ public class BiomeAPI {
/** /**
* Check if biome with {@link ResourceLocation} exists in API registry. * Check if biome with {@link ResourceLocation} exists in API registry.
*
* @param biomeID - biome {@link ResourceLocation}. * @param biomeID - biome {@link ResourceLocation}.
* @return {@code true} if biome exists in API registry and {@code false} if not. * @return {@code true} if biome exists in API registry and {@code false} if not.
*/ */

View file

@ -1,16 +1,15 @@
package ru.bclib.api; package ru.bclib.api;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import ru.bclib.util.WeightedList;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import ru.bclib.util.WeightedList;
public class BonemealAPI { public class BonemealAPI {
private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> WATER_GRASS_BIOMES = Maps.newHashMap(); private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> WATER_GRASS_BIOMES = Maps.newHashMap();
private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> LAND_GRASS_BIOMES = Maps.newHashMap(); private static final Map<ResourceLocation, Map<Block, WeightedList<Block>>> LAND_GRASS_BIOMES = Maps.newHashMap();
@ -27,13 +26,13 @@ public class BonemealAPI {
} }
public static void addLandGrass(Block plant, Block... terrain) { public static void addLandGrass(Block plant, Block... terrain) {
for (Block block: terrain) { for (Block block : terrain) {
addLandGrass(block, plant, 1F); addLandGrass(block, plant, 1F);
} }
} }
public static void addLandGrass(ResourceLocation biome, Block plant, Block... terrain) { public static void addLandGrass(ResourceLocation biome, Block plant, Block... terrain) {
for (Block block: terrain) { for (Block block : terrain) {
addLandGrass(biome, block, plant, 1F); addLandGrass(biome, block, plant, 1F);
} }
} }
@ -62,13 +61,13 @@ public class BonemealAPI {
} }
public static void addWaterGrass(Block plant, Block... terrain) { public static void addWaterGrass(Block plant, Block... terrain) {
for (Block block: terrain) { for (Block block : terrain) {
addWaterGrass(block, plant, 1F); addWaterGrass(block, plant, 1F);
} }
} }
public static void addWaterGrass(ResourceLocation biome, Block plant, Block... terrain) { public static void addWaterGrass(ResourceLocation biome, Block plant, Block... terrain) {
for (Block block: terrain) { for (Block block : terrain) {
addWaterGrass(biome, block, plant, 1F); addWaterGrass(biome, block, plant, 1F);
} }
} }

View file

@ -1,5 +1,15 @@
package ru.bclib.api; package ru.bclib.api;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.storage.RegionFile;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
@ -8,17 +18,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.storage.RegionFile;
public class DataFixerAPI { public class DataFixerAPI {
private static final Map<String, String> REPLACEMENT = Maps.newHashMap(); private static final Map<String, String> REPLACEMENT = Maps.newHashMap();
private static final Map<String, Integer> FIX_VERSIONS = Maps.newHashMap(); private static final Map<String, Integer> FIX_VERSIONS = Maps.newHashMap();
@ -31,7 +30,7 @@ public class DataFixerAPI {
boolean shoudFix = false; boolean shoudFix = false;
Collection<ModContainer> mods = FabricLoader.getInstance().getAllMods(); Collection<ModContainer> mods = FabricLoader.getInstance().getAllMods();
for (ModContainer mod: mods) { for (ModContainer mod : mods) {
String name = mod.getMetadata().getId(); String name = mod.getMetadata().getId();
int preVersion = WorldDataAPI.getIntModVersion(name); int preVersion = WorldDataAPI.getIntModVersion(name);
int version = getModVersion(mod.getMetadata().getVersion().toString()); int version = getModVersion(mod.getMetadata().getVersion().toString());
@ -39,7 +38,8 @@ public class DataFixerAPI {
int fixVersion = FIX_VERSIONS.getOrDefault(name, version); int fixVersion = FIX_VERSIONS.getOrDefault(name, version);
shoudFix |= fixVersion < version && fixVersion >= preVersion; shoudFix |= fixVersion < version && fixVersion >= preVersion;
} }
}; }
;
if (!shoudFix) { if (!shoudFix) {
return; return;
} }
@ -90,14 +90,15 @@ public class DataFixerAPI {
/** /**
* Register block data fix. Fix will be applied on world load if current mod version will be newer than specified one. * Register block data fix. Fix will be applied on world load if current mod version will be newer than specified one.
* @param modID - {@link String} mod id; *
* @param modID - {@link String} mod id;
* @param modVersion - {@link String} mod version, should be in format: %d.%d.%d * @param modVersion - {@link String} mod version, should be in format: %d.%d.%d
* @param result - {@link String} new block name; * @param result - {@link String} new block name;
* @param names - array of {@link String}, old block names to convert. * @param names - array of {@link String}, old block names to convert.
*/ */
protected static void addFix(String modID, String modVersion, String result, String... names) { protected static void addFix(String modID, String modVersion, String result, String... names) {
FIX_VERSIONS.put(modID, getModVersion(modVersion)); FIX_VERSIONS.put(modID, getModVersion(modVersion));
for (String name: names) { for (String name : names) {
REPLACEMENT.put(name, result); REPLACEMENT.put(name, result);
} }
} }
@ -106,7 +107,7 @@ public class DataFixerAPI {
if (list == null) { if (list == null) {
list = Lists.newArrayList(); list = Lists.newArrayList();
} }
for (File file: dir.listFiles()) { for (File file : dir.listFiles()) {
if (file.isDirectory()) { if (file.isDirectory()) {
getAllRegions(file, list); getAllRegions(file, list);
} }
@ -119,6 +120,7 @@ public class DataFixerAPI {
/** /**
* Get mod version from string. String should be in format: %d.%d.%d * Get mod version from string. String should be in format: %d.%d.%d
*
* @param version - {@link String} mod version. * @param version - {@link String} mod version.
* @return int mod version. * @return int mod version.
*/ */
@ -137,6 +139,7 @@ public class DataFixerAPI {
/** /**
* Get mod version from integer. String will be in format %d.%d.%d * Get mod version from integer. String will be in format %d.%d.%d
*
* @param version - mod version in integer form. * @param version - mod version in integer form.
* @return {@link String} mod version. * @return {@link String} mod version.
*/ */

View file

@ -1,16 +1,16 @@
package ru.bclib.api; package ru.bclib.api;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import ru.bclib.integration.ModIntegration; import ru.bclib.integration.ModIntegration;
import java.util.List;
public class ModIntegrationAPI { public class ModIntegrationAPI {
private static final List<ModIntegration> INTEGRATIONS = Lists.newArrayList(); private static final List<ModIntegration> INTEGRATIONS = Lists.newArrayList();
/** /**
* Registers mod integration * Registers mod integration
*
* @param integration * @param integration
* @return * @return
*/ */
@ -21,6 +21,7 @@ public class ModIntegrationAPI {
/** /**
* Get all registered mod integrations. * Get all registered mod integrations.
*
* @return {@link List} of {@link ModIntegration}. * @return {@link List} of {@link ModIntegration}.
*/ */
public static List<ModIntegration> getIntegrations() { public static List<ModIntegration> getIntegrations() {

View file

@ -1,7 +1,5 @@
package ru.bclib.api; package ru.bclib.api;
import java.util.function.Supplier;
import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.fabric.api.tag.TagRegistry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
@ -16,6 +14,8 @@ import net.minecraft.world.level.block.Blocks;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.util.TagHelper; import ru.bclib.util.TagHelper;
import java.util.function.Supplier;
public class TagAPI { public class TagAPI {
// Block Tags // Block Tags
public static final Tag.Named<Block> BOOKSHELVES = makeCommonBlockTag("bookshelves"); public static final Tag.Named<Block> BOOKSHELVES = makeCommonBlockTag("bookshelves");
@ -37,8 +37,9 @@ public class TagAPI {
/** /**
* Get or create {@link Tag.Named}. * Get or create {@link Tag.Named}.
*
* @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection; * @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection;
* @param id - {@link ResourceLocation} tag id. * @param id - {@link ResourceLocation} tag id.
* @return {@link Tag.Named}. * @return {@link Tag.Named}.
*/ */
public static <T> Tag.Named<T> makeTag(Supplier<TagCollection<T>> containerSupplier, ResourceLocation id) { public static <T> Tag.Named<T> makeTag(Supplier<TagCollection<T>> containerSupplier, ResourceLocation id) {
@ -48,8 +49,9 @@ public class TagAPI {
/** /**
* Get or create {@link Block} {@link Tag.Named} with mod namespace. * Get or create {@link Block} {@link Tag.Named} with mod namespace.
*
* @param modID - {@link String} mod namespace (mod id); * @param modID - {@link String} mod namespace (mod id);
* @param name - {@link String} tag name. * @param name - {@link String} tag name.
* @return {@link Block} {@link Tag.Named}. * @return {@link Block} {@link Tag.Named}.
*/ */
public static Tag.Named<Block> makeBlockTag(String modID, String name) { public static Tag.Named<Block> makeBlockTag(String modID, String name) {
@ -58,8 +60,9 @@ public class TagAPI {
/** /**
* Get or create {@link Item} {@link Tag.Named} with mod namespace. * Get or create {@link Item} {@link Tag.Named} with mod namespace.
*
* @param modID - {@link String} mod namespace (mod id); * @param modID - {@link String} mod namespace (mod id);
* @param name - {@link String} tag name. * @param name - {@link String} tag name.
* @return {@link Item} {@link Tag.Named}. * @return {@link Item} {@link Tag.Named}.
*/ */
public static Tag.Named<Item> makeItemTag(String modID, String name) { public static Tag.Named<Item> makeItemTag(String modID, String name) {
@ -68,9 +71,10 @@ public class TagAPI {
/** /**
* Get or create {@link Block} {@link Tag.Named}. * Get or create {@link Block} {@link Tag.Named}.
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a> *
* @param name - {@link String} tag name. * @param name - {@link String} tag name.
* @return {@link Block} {@link Tag.Named}. * @return {@link Block} {@link Tag.Named}.
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
*/ */
public static Tag.Named<Block> makeCommonBlockTag(String name) { public static Tag.Named<Block> makeCommonBlockTag(String name) {
return makeTag(BlockTags::getAllTags, new ResourceLocation("c", name)); return makeTag(BlockTags::getAllTags, new ResourceLocation("c", name));
@ -78,9 +82,10 @@ public class TagAPI {
/** /**
* Get or create {@link Item} {@link Tag.Named}. * Get or create {@link Item} {@link Tag.Named}.
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a> *
* @param name - {@link String} tag name. * @param name - {@link String} tag name.
* @return {@link Item} {@link Tag.Named}. * @return {@link Item} {@link Tag.Named}.
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
*/ */
public static Tag.Named<Item> makeCommonItemTag(String name) { public static Tag.Named<Item> makeCommonItemTag(String name) {
return makeTag(ItemTags::getAllTags, new ResourceLocation("c", name)); return makeTag(ItemTags::getAllTags, new ResourceLocation("c", name));
@ -88,6 +93,7 @@ public class TagAPI {
/** /**
* Get or create Minecraft {@link Block} {@link Tag.Named}. * Get or create Minecraft {@link Block} {@link Tag.Named}.
*
* @param name - {@link String} tag name. * @param name - {@link String} tag name.
* @return {@link Block} {@link Tag.Named}. * @return {@link Block} {@link Tag.Named}.
*/ */
@ -99,6 +105,7 @@ public class TagAPI {
/** /**
* Adds {@link Block} to NETHER_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic. * Adds {@link Block} to NETHER_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic.
*
* @param block - {@link Block}. * @param block - {@link Block}.
*/ */
public static void addNetherGround(Block block) { public static void addNetherGround(Block block) {
@ -108,6 +115,7 @@ public class TagAPI {
/** /**
* Adds {@link Block} to END_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic. * Adds {@link Block} to END_GROUND and GEN_TERRAIN tags to process it properly in terrain generators and block logic.
*
* @param block - {@link Block}. * @param block - {@link Block}.
*/ */
public static void addEndGround(Block block) { public static void addEndGround(Block block) {

View file

@ -1,20 +1,19 @@
package ru.bclib.api; package ru.bclib.api;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import ru.bclib.BCLib;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import ru.bclib.BCLib;
public class WorldDataAPI { public class WorldDataAPI {
private static final Map<String, CompoundTag> TAGS = Maps.newHashMap(); private static final Map<String, CompoundTag> TAGS = Maps.newHashMap();
private static final List<String> MODS = Lists.newArrayList(); private static final List<String> MODS = Lists.newArrayList();
@ -52,6 +51,7 @@ public class WorldDataAPI {
/** /**
* Register mod cache, world cache is located in world data folder. * Register mod cache, world cache is located in world data folder.
*
* @param modID - {@link String} modID. * @param modID - {@link String} modID.
*/ */
public static void registerModCache(String modID) { public static void registerModCache(String modID) {
@ -60,6 +60,7 @@ public class WorldDataAPI {
/** /**
* Get root {@link CompoundTag} for mod cache in world data folder. * Get root {@link CompoundTag} for mod cache in world data folder.
*
* @param modID - {@link String} modID. * @param modID - {@link String} modID.
* @return {@link CompoundTag} * @return {@link CompoundTag}
*/ */
@ -74,13 +75,14 @@ public class WorldDataAPI {
/** /**
* Get {@link CompoundTag} with specified path from mod cache in world data folder. * Get {@link CompoundTag} with specified path from mod cache in world data folder.
*
* @param modID - {@link String} path to tag, dot-separated. * @param modID - {@link String} path to tag, dot-separated.
* @return {@link CompoundTag} * @return {@link CompoundTag}
*/ */
public static CompoundTag getCompoundTag(String modID, String path) { public static CompoundTag getCompoundTag(String modID, String path) {
String[] parts = path.split("\\."); String[] parts = path.split("\\.");
CompoundTag tag = getRootTag(modID); CompoundTag tag = getRootTag(modID);
for (String part: parts) { for (String part : parts) {
if (tag.contains(part)) { if (tag.contains(part)) {
tag = tag.getCompound(part); tag = tag.getCompound(part);
} }
@ -95,6 +97,7 @@ public class WorldDataAPI {
/** /**
* Forces mod cache file to be saved. * Forces mod cache file to be saved.
*
* @param modID {@link String} mod ID. * @param modID {@link String} mod ID.
*/ */
public static void saveFile(String modID) { public static void saveFile(String modID) {
@ -108,6 +111,7 @@ public class WorldDataAPI {
/** /**
* Get stored mod version (only for mods with registered cache). * Get stored mod version (only for mods with registered cache).
*
* @return {@link String} mod version. * @return {@link String} mod version.
*/ */
public static String getModVersion(String modID) { public static String getModVersion(String modID) {
@ -116,6 +120,7 @@ public class WorldDataAPI {
/** /**
* Get stored mod version as integer (only for mods with registered cache). * Get stored mod version as integer (only for mods with registered cache).
*
* @return {@code int} mod version. * @return {@code int} mod version.
*/ */
public static int getIntModVersion(String modID) { public static int getIntModVersion(String modID) {

View file

@ -101,7 +101,8 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
viewerCount = ChestBlockEntity.getOpenCount(level, worldPosition); viewerCount = ChestBlockEntity.getOpenCount(level, worldPosition);
if (viewerCount > 0) { if (viewerCount > 0) {
scheduleUpdate(); scheduleUpdate();
} else { }
else {
BlockState blockState = getBlockState(); BlockState blockState = getBlockState();
if (!(blockState.getBlock() instanceof BaseBarrelBlock)) { if (!(blockState.getBlock() instanceof BaseBarrelBlock)) {
setRemoved(); setRemoved();
@ -133,8 +134,7 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D; double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D; double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D; double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
this.level.random.nextFloat() * 0.1F + 0.9F);
} }
} }
} }

View file

@ -1,11 +1,6 @@
package ru.bclib.blockentities; package ru.bclib.blockentities;
import java.util.Collections;
import java.util.Set;
import java.util.function.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
@ -13,6 +8,9 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.Set;
public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityType<T> { public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityType<T> {
private final Set<Block> validBlocks = Sets.newHashSet(); private final Set<Block> validBlocks = Sets.newHashSet();
@ -24,7 +22,8 @@ public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityTy
} }
@Override @Override
@Nullable public T create(BlockPos blockPos, BlockState blockState) { @Nullable
public T create(BlockPos blockPos, BlockState blockState) {
return factory.create(blockPos, blockState); return factory.create(blockPos, blockState);
} }
@ -38,8 +37,7 @@ public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityTy
} }
@FunctionalInterface @FunctionalInterface
public public interface BlockEntitySupplier<T extends BlockEntity> {
interface BlockEntitySupplier<T extends BlockEntity> {
T create(BlockPos blockPos, BlockState blockState); T create(BlockPos blockPos, BlockState blockState);
} }
} }

View file

@ -1,14 +1,7 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -25,12 +18,17 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import ru.bclib.items.BaseAnvilItem; import ru.bclib.items.BaseAnvilItem;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider { public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION; public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;

View file

@ -1,12 +1,12 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Optional;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Optional;
public class BaseBarkBlock extends BaseRotatedPillarBlock { public class BaseBarkBlock extends BaseRotatedPillarBlock {
public BaseBarkBlock(Properties settings) { public BaseBarkBlock(Properties settings) {
super(settings); super(settings);

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -24,7 +17,6 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.piglin.PiglinAi; import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BarrelBlock; import net.minecraft.world.level.block.BarrelBlock;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
@ -33,6 +25,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseBarrelBlockEntity; import ru.bclib.blockentities.BaseBarrelBlockEntity;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
@ -40,6 +33,11 @@ import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import ru.bclib.registry.BaseBlockEntities; import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider { public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
public BaseBarrelBlock(Block source) { public BaseBarrelBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noOcclusion()); super(FabricBlockSettings.copyOf(source).noOcclusion());
@ -59,11 +57,11 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
} }
@Override @Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
BlockHitResult hit) {
if (world.isClientSide) { if (world.isClientSide) {
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} else { }
else {
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BaseBarrelBlockEntity) { if (blockEntity instanceof BaseBarrelBlockEntity) {
player.openMenu((BaseBarrelBlockEntity) blockEntity); player.openMenu((BaseBarrelBlockEntity) blockEntity);
@ -89,8 +87,7 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
} }
@Override @Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
ItemStack itemStack) {
if (itemStack.hasCustomHoverName()) { if (itemStack.hasCustomHoverName()) {
BlockEntity blockEntity = world.getBlockEntity(pos); BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof BaseBarrelBlockEntity) { if (blockEntity instanceof BaseBarrelBlockEntity) {
@ -111,7 +108,8 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
Optional<String> pattern; Optional<String> pattern;
if (blockState.getValue(OPEN)) { if (blockState.getValue(OPEN)) {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BARREL_OPEN, blockId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BARREL_OPEN, blockId);
} else { }
else {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BOTTOM_TOP, blockId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BOTTOM_TOP, blockId);
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
@ -121,18 +119,28 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String open = blockState.getValue(OPEN) ? "_open" : ""; String open = blockState.getValue(OPEN) ? "_open" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + open);
"block/" + stateId.getPath() + open);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
Direction facing = blockState.getValue(FACING); Direction facing = blockState.getValue(FACING);
BlockModelRotation rotation = BlockModelRotation.X0_Y0; BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (facing) { switch (facing) {
case NORTH: rotation = BlockModelRotation.X90_Y0; break; case NORTH:
case EAST: rotation = BlockModelRotation.X90_Y90; break; rotation = BlockModelRotation.X90_Y0;
case SOUTH: rotation = BlockModelRotation.X90_Y180; break; break;
case WEST: rotation = BlockModelRotation.X90_Y270; break; case EAST:
case DOWN: rotation = BlockModelRotation.X180_Y0; break; rotation = BlockModelRotation.X90_Y90;
default: break; break;
case SOUTH:
rotation = BlockModelRotation.X90_Y180;
break;
case WEST:
rotation = BlockModelRotation.X90_Y270;
break;
case DOWN:
rotation = BlockModelRotation.X180_Y0;
break;
default:
break;
} }
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }

View file

@ -1,8 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -11,6 +8,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import java.util.Collections;
import java.util.List;
public class BaseBlock extends Block implements BlockModelProvider { public class BaseBlock extends Block implements BlockModelProvider {
public BaseBlock(Properties settings) { public BaseBlock(Properties settings) {
super(settings); super(settings);

View file

@ -1,16 +1,15 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import java.util.Collections;
import java.util.List;
public class BaseBlockWithEntity extends BaseEntityBlock { public class BaseBlockWithEntity extends BaseEntityBlock {
public BaseBlockWithEntity(Properties settings) { public BaseBlockWithEntity(Properties settings) {
super(settings); super(settings);

View file

@ -1,11 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -19,10 +13,15 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public class BaseBookshelfBlock extends BaseBlock { public class BaseBookshelfBlock extends BaseBlock {
public BaseBookshelfBlock(Block source) { public BaseBookshelfBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -20,11 +13,17 @@ import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.AttachFace; import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelProvider { public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -52,9 +51,7 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ? Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) :
PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
} }
@ -62,23 +59,40 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String powered = blockState.getValue(POWERED) ? "_powered" : ""; String powered = blockState.getValue(POWERED) ? "_powered" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + powered);
"block/" + stateId.getPath() + powered);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
AttachFace face = blockState.getValue(FACE); AttachFace face = blockState.getValue(FACE);
boolean isCeiling = face == AttachFace.CEILING; boolean isCeiling = face == AttachFace.CEILING;
int x = 0, y = 0; int x = 0, y = 0;
switch (face) { switch (face) {
case CEILING: x = 180; break; case CEILING:
case WALL: x = 90; break; x = 180;
default: break; break;
case WALL:
x = 90;
break;
default:
break;
} }
switch (blockState.getValue(FACING)) { switch (blockState.getValue(FACING)) {
case NORTH: if (isCeiling) { y = 180; } break; case NORTH:
case EAST: y = isCeiling ? 270 : 90; break; if (isCeiling) {
case SOUTH: if(!isCeiling) { y = 180; } break; y = 180;
case WEST: y = isCeiling ? 90 : 270; break; }
default: break; break;
case EAST:
y = isCeiling ? 270 : 90;
break;
case SOUTH:
if (!isCeiling) {
y = 180;
}
break;
case WEST:
y = isCeiling ? 90 : 270;
break;
default:
break;
} }
BlockModelRotation rotation = BlockModelRotation.by(x, y); BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL);

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -20,6 +13,7 @@ import net.minecraft.world.level.block.ChainBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -27,6 +21,11 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IRenderTyped { public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IRenderTyped {
public BaseChainBlock(MaterialColor color) { public BaseChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color)); super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color));
@ -55,8 +54,7 @@ public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IR
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
Direction.Axis axis = blockState.getValue(AXIS); Direction.Axis axis = blockState.getValue(AXIS);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
"block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createRotatedModel(modelId, axis); return ModelsHelper.createRotatedModel(modelId, axis);
} }

View file

@ -1,30 +1,28 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ChestBlock; import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import ru.bclib.registry.BaseBlockEntities; import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
import java.util.Optional;
public class BaseChestBlock extends ChestBlock implements BlockModelProvider { public class BaseChestBlock extends ChestBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -40,8 +38,7 @@ public class BaseChestBlock extends ChestBlock implements BlockModelProvider {
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
{
List<ItemStack> drop = super.getDrops(state, builder); List<ItemStack> drop = super.getDrops(state, builder);
drop.add(new ItemStack(this.asItem())); drop.add(new ItemStack(this.asItem()));
return drop; return drop;

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -18,12 +11,18 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseComposterBlock extends ComposterBlock implements BlockModelProvider { public class BaseComposterBlock extends ComposterBlock implements BlockModelProvider {
public BaseComposterBlock(Block source) { public BaseComposterBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));
@ -60,7 +59,8 @@ public class BaseComposterBlock extends ComposterBlock implements BlockModelProv
ResourceLocation contentId; ResourceLocation contentId;
if (level > 7) { if (level > 7) {
contentId = new ResourceLocation("block/composter_contents_ready"); contentId = new ResourceLocation("block/composter_contents_ready");
} else { }
else {
contentId = new ResourceLocation("block/composter_contents" + level); contentId = new ResourceLocation("block/composter_contents" + level);
} }
builder.part(contentId).setCondition(state -> state.getValue(LEVEL).equals(level)).add(); builder.part(contentId).setCondition(state -> state.getValue(LEVEL).equals(level)).add();

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -17,11 +10,17 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CraftingTableBlock; import net.minecraft.world.level.block.CraftingTableBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider { public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
public BaseCraftingTableBlock(Block source) { public BaseCraftingTableBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));
@ -45,6 +44,7 @@ public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockM
String blockName = blockId.getPath(); String blockName = blockId.getPath();
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap<String, String>() { Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%modid%", blockId.getNamespace()); put("%modid%", blockId.getNamespace());
put("%particle%", blockName + "_front"); put("%particle%", blockName + "_front");

View file

@ -1,11 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -31,6 +26,10 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class BaseCropBlock extends BasePlantBlock { public class BaseCropBlock extends BasePlantBlock {
private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14);
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
@ -39,12 +38,7 @@ public class BaseCropBlock extends BasePlantBlock {
private final Item drop; private final Item drop;
public BaseCropBlock(Item drop, Block... terrain) { public BaseCropBlock(Item drop, Block... terrain) {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
.breakByTool(FabricToolTags.HOES)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
this.drop = drop; this.drop = drop;
this.terrain = terrain; this.terrain = terrain;
this.registerDefaultState(defaultBlockState().setValue(AGE, 0)); this.registerDefaultState(defaultBlockState().setValue(AGE, 0));
@ -57,7 +51,7 @@ public class BaseCropBlock extends BasePlantBlock {
@Override @Override
protected boolean isTerrain(BlockState state) { protected boolean isTerrain(BlockState state) {
for (Block block: terrain) { for (Block block : terrain) {
if (state.is(block)) { if (state.is(block)) {
return true; return true;
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -23,6 +16,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoorHingeSide; import net.minecraft.world.level.block.state.properties.DoorHingeSide;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -30,6 +24,11 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModelProvider { public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModelProvider {
public BaseDoorBlock(Block source) { public BaseDoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion());
@ -40,8 +39,7 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(HALF) == DoubleBlockHalf.LOWER) if (state.getValue(HALF) == DoubleBlockHalf.LOWER)
return Collections.singletonList(new ItemStack(this.asItem())); return Collections.singletonList(new ItemStack(this.asItem()));
else else return Collections.emptyList();
return Collections.emptyList();
} }
@Override @Override
@ -64,7 +62,8 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
case TOP: case TOP:
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_DOOR_TOP, resourceLocation); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_DOOR_TOP, resourceLocation);
break; break;
default: break; default:
break;
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
} }
@ -81,23 +80,27 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
case EAST: case EAST:
if (hinge && open) { if (hinge && open) {
rotation = BlockModelRotation.X0_Y90; rotation = BlockModelRotation.X0_Y90;
} else if (open) { }
else if (open) {
rotation = BlockModelRotation.X0_Y270; rotation = BlockModelRotation.X0_Y270;
} }
break; break;
case SOUTH: case SOUTH:
if (!hinge && !open || hinge && !open) { if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y90; rotation = BlockModelRotation.X0_Y90;
} else if (hinge) { }
else if (hinge) {
rotation = BlockModelRotation.X0_Y180; rotation = BlockModelRotation.X0_Y180;
} }
break; break;
case WEST: case WEST:
if (!hinge && !open || hinge && !open) { if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y180; rotation = BlockModelRotation.X0_Y180;
} else if (hinge) { }
else if (hinge) {
rotation = BlockModelRotation.X0_Y270; rotation = BlockModelRotation.X0_Y270;
} else { }
else {
rotation = BlockModelRotation.X0_Y90; rotation = BlockModelRotation.X0_Y90;
} }
break; break;
@ -105,13 +108,13 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
default: default:
if (!hinge && !open || hinge && !open) { if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y270; rotation = BlockModelRotation.X0_Y270;
} else if (!hinge) { }
else if (!hinge) {
rotation = BlockModelRotation.X0_Y180; rotation = BlockModelRotation.X0_Y180;
} }
break; break;
} }
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + doorType);
"block/" + stateId.getPath() + "_" + doorType);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }
@ -135,10 +138,7 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
} }
protected enum DoorType implements StringRepresentable { protected enum DoorType implements StringRepresentable {
BOTTOM_HINGE("bottom_hinge"), BOTTOM_HINGE("bottom_hinge"), TOP_HINGE("top_hinge"), BOTTOM("bottom"), TOP("top");
TOP_HINGE("top_hinge"),
BOTTOM("bottom"),
TOP("top");
private final String name; private final String name;
@ -147,8 +147,7 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
} }
public boolean isHinge() { public boolean isHinge() {
return this == BOTTOM_HINGE || return this == BOTTOM_HINGE || this == TOP_HINGE;
this == TOP_HINGE;
} }
@Override @Override

View file

@ -1,10 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -38,6 +34,9 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
@ -45,21 +44,12 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
public static final BooleanProperty TOP = BooleanProperty.create("top"); public static final BooleanProperty TOP = BooleanProperty.create("top");
public BaseDoublePlantBlock() { public BaseDoublePlantBlock() {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
} }
public BaseDoublePlantBlock(int light) { public BaseDoublePlantBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).lightLevel((state) -> state.getValue(TOP) ? light : 0).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -20,12 +13,18 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock; import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseFenceBlock extends FenceBlock implements BlockModelProvider { public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -66,21 +65,16 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post");
"block/" + stateId.getPath() + "_post"); ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side");
registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache);
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition); MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)) builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)) builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(postId).add(); builder.part(postId).add();
return builder.build(); return builder.build();

View file

@ -69,7 +69,8 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
textures.put("%front%", blockName + "_front_on"); textures.put("%front%", blockName + "_front_on");
textures.put("%glow%", blockName + "_glow"); textures.put("%glow%", blockName + "_glow");
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE_LIT, textures); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE_LIT, textures);
} else { }
else {
textures.put("%front%", blockName + "_front"); textures.put("%front%", blockName + "_front");
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE, textures); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE, textures);
} }
@ -86,8 +87,7 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String lit = blockState.getValue(LIT) ? "_lit" : ""; String lit = blockState.getValue(LIT) ? "_lit" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + lit);
"block/" + stateId.getPath() + lit);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true); return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -19,11 +12,17 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceGateBlock; import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider { public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -52,11 +51,10 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern; Optional<String> pattern;
if (inWall) { if (inWall) {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId);
PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId); }
} else { else {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
} }
@ -67,8 +65,7 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
boolean inWall = blockState.getValue(IN_WALL); boolean inWall = blockState.getValue(IN_WALL);
boolean isOpen = blockState.getValue(OPEN); boolean isOpen = blockState.getValue(OPEN);
String state = "" + (inWall ? "_wall" : "") + (isOpen ? "_open" : "_closed"); String state = "" + (inWall ? "_wall" : "") + (isOpen ? "_open" : "_closed");
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state);
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), true, false); return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), true, false);
} }

View file

@ -1,10 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -31,6 +26,7 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -39,6 +35,9 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider { public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
@ -80,11 +79,11 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B
} }
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(world, pos)) { if (facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} else { }
else {
if (state.getValue(WATERLOGGED)) { if (state.getValue(WATERLOGGED)) {
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
} }

View file

@ -1,10 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -24,30 +20,19 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped { public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped {
private final Block sapling; private final Block sapling;
public BaseLeavesBlock(Block sapling, MaterialColor color) { public BaseLeavesBlock(Block sapling, MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true).isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
.mapColor(color)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
this.sapling = sapling; this.sapling = sapling;
} }
public BaseLeavesBlock(Block sapling, MaterialColor color, int light) { public BaseLeavesBlock(Block sapling, MaterialColor color, int light) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).luminance(light).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
.mapColor(color)
.luminance(light)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
this.sapling = sapling; this.sapling = sapling;
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -21,6 +14,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.IronBarsBlock; import net.minecraft.world.level.block.IronBarsBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -28,6 +22,11 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, IRenderTyped { public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, IRenderTyped {
public BaseMetalBarsBlock(Block source) { public BaseMetalBarsBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion());
@ -76,24 +75,17 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post");
"block/" + stateId.getPath() + "_post"); ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side");
registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition); ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(postId).setCondition(state -> builder.part(postId).setCondition(state -> !state.getValue(NORTH) && !state.getValue(EAST) && !state.getValue(SOUTH) && !state.getValue(WEST)).add();
!state.getValue(NORTH) && !state.getValue(EAST) &&
!state.getValue(SOUTH) && !state.getValue(WEST)).add();
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)) builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)) builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
return builder.build(); return builder.build();
} }

View file

@ -1,9 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -23,17 +19,16 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
public class BaseOreBlock extends OreBlock implements BlockModelProvider { public class BaseOreBlock extends OreBlock implements BlockModelProvider {
private final Item dropItem; private final Item dropItem;
private final int minCount; private final int minCount;
private final int maxCount; private final int maxCount;
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) { public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresCorrectToolForDrops().sound(SoundType.STONE), UniformInt.of(1, experience));
.hardness(3F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE), UniformInt.of(1, experience));
this.dropItem = drop; this.dropItem = drop;
this.minCount = minCount; this.minCount = minCount;
this.maxCount = maxCount; this.maxCount = maxCount;
@ -56,7 +51,8 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider {
return Collections.singletonList(new ItemStack(dropItem, max)); return Collections.singletonList(new ItemStack(dropItem, max));
} }
count = MHelper.randRange(min, max, MHelper.RANDOM); count = MHelper.randRange(min, max, MHelper.RANDOM);
} else { }
else {
count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM);
} }
return Collections.singletonList(new ItemStack(dropItem, count)); return Collections.singletonList(new ItemStack(dropItem, count));

View file

@ -1,14 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -28,10 +20,16 @@ import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BasePathBlock extends BaseBlockNotFull { public class BasePathBlock extends BaseBlockNotFull {
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);

View file

@ -1,10 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -33,6 +29,9 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
@ -46,20 +45,11 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
} }
public BasePlantBlock(boolean replaceable) { public BasePlantBlock(boolean replaceable) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
} }
public BasePlantBlock(boolean replaceable, int light) { public BasePlantBlock(boolean replaceable, int light) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
} }
public BasePlantBlock(Properties settings) { public BasePlantBlock(Properties settings) {

View file

@ -1,7 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -15,16 +13,13 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import java.util.Random;
public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public BasePlantWithAgeBlock() { public BasePlantWithAgeBlock() {
this(FabricBlockSettings.of(Material.PLANT) this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
} }
public BasePlantWithAgeBlock(Properties settings) { public BasePlantWithAgeBlock(Properties settings) {

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -19,11 +12,17 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PressurePlateBlock; import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BasePressurePlateBlock extends PressurePlateBlock implements BlockModelProvider { public class BasePressurePlateBlock extends PressurePlateBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -51,7 +50,8 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM
Optional<String> pattern; Optional<String> pattern;
if (blockState.getValue(POWERED)) { if (blockState.getValue(POWERED)) {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId);
} else { }
else {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId);
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
@ -61,8 +61,7 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String state = blockState.getValue(POWERED) ? "_down" : "_up"; String state = blockState.getValue(POWERED) ? "_down" : "_up";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state);
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId); return ModelsHelper.createBlockSimple(modelId);
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -18,10 +11,16 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockModelProvider { public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
public BaseRotatedPillarBlock(Properties settings) { public BaseRotatedPillarBlock(Properties settings) {
super(settings); super(settings);

View file

@ -1,10 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -42,22 +37,21 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseSignBlockEntity; import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ISpetialItem; import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.Collections;
import java.util.List;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem { public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("floor"); public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] { private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D), Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)};
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
};
private final Block parent; private final Block parent;
@ -90,7 +84,8 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
if (!world.isClientSide) { if (!world.isClientSide) {
sign.setAllowedPlayerEditor(placer.getUUID()); sign.setAllowedPlayerEditor(placer.getUUID());
((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos)); ((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos));
} else { }
else {
sign.setEditable(true); sign.setEditable(true);
} }
} }
@ -123,10 +118,9 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
public BlockState getStateForPlacement(BlockPlaceContext ctx) { public BlockState getStateForPlacement(BlockPlaceContext ctx) {
if (ctx.getClickedFace() == Direction.UP) { if (ctx.getClickedFace() == Direction.UP) {
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
return this.defaultBlockState().setValue(FLOOR, true) return this.defaultBlockState().setValue(FLOOR, true).setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15) }
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER); else if (ctx.getClickedFace() != Direction.DOWN) {
} else if (ctx.getClickedFace() != Direction.DOWN) {
BlockState blockState = this.defaultBlockState(); BlockState blockState = this.defaultBlockState();
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
LevelReader worldView = ctx.getLevel(); LevelReader worldView = ctx.getLevel();

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -21,11 +14,17 @@ import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.SlabType; import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseSlabBlock extends SlabBlock implements BlockModelProvider { public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -53,7 +52,8 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
Optional<String> pattern; Optional<String> pattern;
if (blockState.getValue(TYPE) == SlabType.DOUBLE) { if (blockState.getValue(TYPE) == SlabType.DOUBLE) {
pattern = PatternsHelper.createBlockSimple(parentId); pattern = PatternsHelper.createBlockSimple(parentId);
} else { }
else {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SLAB, parentId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SLAB, parentId);
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
@ -63,8 +63,7 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
SlabType type = blockState.getValue(TYPE); SlabType type = blockState.getValue(TYPE);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + type);
"block/" + stateId.getPath() + "_" + type);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
if (type == SlabType.TOP) { if (type == SlabType.TOP) {
return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true); return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true);

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -22,11 +15,17 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half; import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.block.state.properties.StairsShape; import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseStairsBlock extends StairBlock implements BlockModelProvider { public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -77,10 +76,12 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
switch (shape) { switch (shape) {
case INNER_LEFT: case INNER_LEFT:
case INNER_RIGHT: case INNER_RIGHT:
state = "_inner"; break; state = "_inner";
break;
case OUTER_LEFT: case OUTER_LEFT:
case OUTER_RIGHT: case OUTER_RIGHT:
state = "_outer"; break; state = "_outer";
break;
default: default:
state = ""; state = "";
} }
@ -88,10 +89,8 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
boolean isTop = blockState.getValue(HALF) == Half.TOP; boolean isTop = blockState.getValue(HALF) == Half.TOP;
boolean isLeft = shape == StairsShape.INNER_LEFT || boolean isLeft = shape == StairsShape.INNER_LEFT || shape == StairsShape.OUTER_LEFT;
shape == StairsShape.OUTER_LEFT; boolean isRight = shape == StairsShape.INNER_RIGHT || shape == StairsShape.OUTER_RIGHT;
boolean isRight = shape == StairsShape.INNER_RIGHT ||
shape == StairsShape.OUTER_RIGHT;
int y = 0; int y = 0;
int x = isTop ? 180 : 0; int x = isTop ? 180 : 0;
switch (blockState.getValue(FACING)) { switch (blockState.getValue(FACING)) {

View file

@ -1,15 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -41,11 +32,18 @@ import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.sound.BlockSounds; import ru.bclib.client.sound.BlockSounds;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BaseTerrainBlock extends BaseBlock { public class BaseTerrainBlock extends BaseBlock {

View file

@ -1,13 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -21,6 +13,7 @@ import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half; import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -28,6 +21,12 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider { public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider {
public BaseTrapdoorBlock(Block source) { public BaseTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
@ -56,6 +55,7 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
String name = resourceLocation.getPath(); String name = resourceLocation.getPath();
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap<String, String>() { Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%modid%", resourceLocation.getNamespace()); put("%modid%", resourceLocation.getNamespace());
put("%texture%", name); put("%texture%", name);
@ -87,7 +87,8 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
case WEST: case WEST:
y = (isTop && isOpen) ? 90 : 270; y = (isTop && isOpen) ? 90 : 270;
break; break;
default: break; default:
break;
} }
BlockModelRotation rotation = BlockModelRotation.by(x, y); BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);

View file

@ -17,20 +17,11 @@ import net.minecraft.world.level.material.Material;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer { public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer {
public BaseUnderwaterWallPlantBlock() { public BaseUnderwaterWallPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
} }
public BaseUnderwaterWallPlantBlock(int light) { public BaseUnderwaterWallPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
} }
public BaseUnderwaterWallPlantBlock(Properties settings) { public BaseUnderwaterWallPlantBlock(Properties settings) {

View file

@ -1,10 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -37,6 +33,9 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
@ -51,12 +50,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
} }
public BaseVineBlock(int light, boolean bottomOnly) { public BaseVineBlock(int light, boolean bottomOnly) {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM)); this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM));
} }
@ -96,10 +90,8 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();
} }
else { else {
if (world.getBlockState(pos.below()).getBlock() != this) if (world.getBlockState(pos.below()).getBlock() != this) return state.setValue(SHAPE, TripleShape.BOTTOM);
return state.setValue(SHAPE, TripleShape.BOTTOM); else if (world.getBlockState(pos.above()).getBlock() != this) return state.setValue(SHAPE, TripleShape.TOP);
else if (world.getBlockState(pos.above()).getBlock() != this)
return state.setValue(SHAPE, TripleShape.TOP);
return state.setValue(SHAPE, TripleShape.MIDDLE); return state.setValue(SHAPE, TripleShape.MIDDLE);
} }
} }

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -21,11 +14,17 @@ import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.WallSide; import net.minecraft.world.level.block.state.properties.WallSide;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseWallBlock extends WallBlock implements BlockModelProvider { public class BaseWallBlock extends WallBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -70,31 +69,22 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider {
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post");
"block/" + stateId.getPath() + "_post"); ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side_tall");
"block/" + stateId.getPath() + "_side");
ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side_tall");
registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache);
registerBlockModel(sideTallId, sideTallId, blockState, modelCache); registerBlockModel(sideTallId, sideTallId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition); ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.LOW).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.LOW).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW) builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add(); builder.part(sideId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW) builder.part(sideId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL).setUVLock(true).add(); builder.part(sideTallId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL) builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add(); builder.part(sideTallId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL) builder.part(sideTallId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(postId).setCondition(state -> state.getValue(UP)).add(); builder.part(postId).setCondition(state -> state.getValue(UP)).add();
return builder.build(); return builder.build();

View file

@ -1,10 +1,7 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.EnumMap;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -28,29 +25,18 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.EnumMap;
public abstract class BaseWallPlantBlock extends BasePlantBlock { public abstract class BaseWallPlantBlock extends BasePlantBlock {
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of( private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8), Direction.WEST, Block.box(8, 1, 1, 16, 15, 15), Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16),
Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8),
Direction.WEST, Block.box(8, 1, 1, 16, 15, 15),
Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() { public BaseWallPlantBlock() {
this(FabricBlockSettings.of(Material.PLANT) this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
} }
public BaseWallPlantBlock(int light) { public BaseWallPlantBlock(int light) {
this(FabricBlockSettings.of(Material.PLANT) this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
} }
public BaseWallPlantBlock(Properties settings) { public BaseWallPlantBlock(Properties settings) {

View file

@ -1,12 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -19,11 +12,17 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeightedPressurePlateBlock; import net.minecraft.world.level.block.WeightedPressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implements BlockModelProvider { public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -51,7 +50,8 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement
Optional<String> pattern; Optional<String> pattern;
if (blockState.getValue(POWER) > 0) { if (blockState.getValue(POWER) > 0) {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId);
} else { }
else {
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId);
} }
return ModelsHelper.fromPattern(pattern); return ModelsHelper.fromPattern(pattern);
@ -61,8 +61,7 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String state = blockState.getValue(POWER) > 0 ? "_down" : "_up"; String state = blockState.getValue(POWER) > 0 ? "_down" : "_up";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state);
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId); return ModelsHelper.createBlockSimple(modelId);
} }

View file

@ -24,9 +24,7 @@ public class BlockProperties {
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
public enum TripleShape implements StringRepresentable { public enum TripleShape implements StringRepresentable {
TOP("top", 0), TOP("top", 0), MIDDLE("middle", 1), BOTTOM("bottom", 2);
MIDDLE("middle", 1),
BOTTOM("bottom", 2);
private final String name; private final String name;
private final int index; private final int index;
@ -56,11 +54,7 @@ public class BlockProperties {
} }
public enum PentaShape implements StringRepresentable { public enum PentaShape implements StringRepresentable {
BOTTOM("bottom"), BOTTOM("bottom"), PRE_BOTTOM("pre_bottom"), MIDDLE("middle"), PRE_TOP("pre_top"), TOP("top");
PRE_BOTTOM("pre_bottom"),
MIDDLE("middle"),
PRE_TOP("pre_top"),
TOP("top");
private final String name; private final String name;

View file

@ -1,13 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -26,10 +18,12 @@ import net.minecraft.world.level.block.SaplingBlock;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
@ -37,27 +31,21 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider { public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public FeatureSaplingBlock() { public FeatureSaplingBlock() {
super(null, FabricBlockSettings.of(Material.PLANT) super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).instabreak().sound(SoundType.GRASS).randomTicks());
.breakByHand(true)
.collidable(false)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks());
} }
public FeatureSaplingBlock(int light) { public FeatureSaplingBlock(int light) {
super(null, FabricBlockSettings.of(Material.PLANT) super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).luminance(light).instabreak().sound(SoundType.GRASS).randomTicks());
.breakByHand(true)
.collidable(false)
.luminance(light)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks());
} }
protected abstract Feature<?> getFeature(); protected abstract Feature<?> getFeature();
@ -74,10 +62,8 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
@Override @Override
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) if (!canSurvive(state, world, pos)) return Blocks.AIR.defaultBlockState();
return Blocks.AIR.defaultBlockState(); else return state;
else
return state;
} }
@Override @Override

View file

@ -9,26 +9,11 @@ import ru.bclib.interfaces.IRenderTyped;
public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped { public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped {
public SimpleLeavesBlock(MaterialColor color) { public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES) super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).mapColor(color).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
.strength(0.2F)
.mapColor(color)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
} }
public SimpleLeavesBlock(MaterialColor color, int light) { public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES) super(FabricBlockSettings.of(Material.LEAVES).luminance(light).mapColor(color).strength(0.2F).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
.luminance(light)
.mapColor(color)
.strength(0.2F)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
} }
@Override @Override

View file

@ -1,10 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -37,12 +32,16 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped { public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
@ -213,8 +212,7 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0; BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0;
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), stateId.getPath() + "_" + blockState.getValue(SIZE));
stateId.getPath() + "_" + blockState.getValue(SIZE));
registerBlockModel(modelId, modelId, blockState, modelCache); registerBlockModel(modelId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }

View file

@ -1,15 +1,7 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -34,11 +26,17 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blocks.BlockProperties.TripleShape; import ru.bclib.blocks.BlockProperties.TripleShape;
import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
public class TripleTerrainBlock extends BaseTerrainBlock { public class TripleTerrainBlock extends BaseTerrainBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
@ -78,7 +76,8 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) { if (shape == TripleShape.BOTTOM) {
super.randomTick(state, world, pos, random); super.randomTick(state, world, pos, random);
} else if (random.nextInt(16) == 0) { }
else if (random.nextInt(16) == 0) {
boolean bottom = canStayBottom(world, pos); boolean bottom = canStayBottom(world, pos);
if (shape == TripleShape.TOP) { if (shape == TripleShape.TOP) {
if (!bottom) { if (!bottom) {
@ -89,9 +88,11 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above())); boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above()));
if (!top && !bottom) { if (!top && !bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
} else if (top && !bottom) { }
else if (top && !bottom) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM)); world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM));
} else if (!top) { }
else if (!top) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP)); world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP));
} }
} }
@ -103,9 +104,11 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
BlockState blockState = world.getBlockState(blockPos); BlockState blockState = world.getBlockState(blockPos);
if (isMiddle(blockState)) { if (isMiddle(blockState)) {
return true; return true;
} else if (blockState.getFluidState().getAmount() == 8) { }
else if (blockState.getFluidState().getAmount() == 8) {
return false; return false;
} else { }
else {
return !blockState.isFaceSturdy(world, blockPos, Direction.UP); return !blockState.isFaceSturdy(world, blockPos, Direction.UP);
} }
} }
@ -124,7 +127,8 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
if (isMiddle(blockState)) { if (isMiddle(blockState)) {
ResourceLocation topId = new ResourceLocation(blockId.getNamespace(), path + "_top"); ResourceLocation topId = new ResourceLocation(blockId.getNamespace(), path + "_top");
pattern = PatternsHelper.createBlockSimple(topId); pattern = PatternsHelper.createBlockSimple(topId);
} else { }
else {
Map<String, String> textures = Maps.newHashMap(); Map<String, String> textures = Maps.newHashMap();
textures.put("%top%", "betterend:block/" + path + "_top"); textures.put("%top%", "betterend:block/" + path + "_top");
textures.put("%side%", "betterend:block/" + path + "_side"); textures.put("%side%", "betterend:block/" + path + "_side");
@ -139,8 +143,7 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
boolean isMiddle = isMiddle(blockState); boolean isMiddle = isMiddle(blockState);
String middle = isMiddle ? "_middle" : ""; String middle = isMiddle ? "_middle" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + middle);
"block/" + stateId.getPath() + middle);
registerBlockModel(stateId, modelId, blockState, modelCache); registerBlockModel(stateId, modelId, blockState, modelCache);
if (isMiddle) { if (isMiddle) {
List<Variant> variants = Lists.newArrayList(); List<Variant> variants = Lists.newArrayList();
@ -148,13 +151,9 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
variants.add(new Variant(modelId, rotation.getRotation(), false, 1)); variants.add(new Variant(modelId, rotation.getRotation(), false, 1));
} }
return new MultiVariant(variants); return new MultiVariant(variants);
} else if (blockState.getValue(SHAPE) == TripleShape.TOP) { }
return new MultiVariant(Lists.newArrayList( else if (blockState.getValue(SHAPE) == TripleShape.TOP) {
new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1), return new MultiVariant(Lists.newArrayList(new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)));
new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)
));
} }
return ModelsHelper.createRandomTopModel(modelId); return ModelsHelper.createRandomTopModel(modelId);
} }

View file

@ -1,10 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -37,25 +33,19 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer { public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() { public UnderwaterPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
} }
public UnderwaterPlantBlock(int light) { public UnderwaterPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
} }
public UnderwaterPlantBlock(Properties settings) { public UnderwaterPlantBlock(Properties settings) {

View file

@ -1,7 +1,5 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -14,16 +12,13 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import java.util.Random;
public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() { public UnderwaterPlantWithAgeBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).randomTicks().noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.randomTicks()
.noCollission());
} }
@Override @Override

View file

@ -1,9 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -29,16 +26,14 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import java.util.List;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped { public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() { public UpDownPlantBlock() {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
} }
protected abstract boolean isTerrain(BlockState state); protected abstract boolean isTerrain(BlockState state);

View file

@ -1,9 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -15,16 +12,11 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import java.util.List;
public abstract class WallMushroomBlock extends BaseWallPlantBlock { public abstract class WallMushroomBlock extends BaseWallPlantBlock {
public WallMushroomBlock(int light) { public WallMushroomBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT) super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).breakByHand(true).luminance(light).hardness(0.2F).sound(SoundType.GRASS).sound(SoundType.WOOD).noCollission());
.breakByTool(FabricToolTags.AXES)
.breakByHand(true)
.luminance(light)
.hardness(0.2F)
.sound(SoundType.GRASS)
.sound(SoundType.WOOD)
.noCollission());
} }
@Override @Override

View file

@ -23,10 +23,8 @@ public class BCLibClient implements ClientModInitializer {
Registry.BLOCK.forEach(block -> { Registry.BLOCK.forEach(block -> {
if (block instanceof IRenderTyped) { if (block instanceof IRenderTyped) {
BCLRenderLayer layer = ((IRenderTyped) block).getRenderLayer(); BCLRenderLayer layer = ((IRenderTyped) block).getRenderLayer();
if (layer == BCLRenderLayer.CUTOUT) if (layer == BCLRenderLayer.CUTOUT) BlockRenderLayerMap.INSTANCE.putBlock(block, cutout);
BlockRenderLayerMap.INSTANCE.putBlock(block, cutout); else if (layer == BCLRenderLayer.TRANSLUCENT) BlockRenderLayerMap.INSTANCE.putBlock(block, translucent);
else if (layer == BCLRenderLayer.TRANSLUCENT)
BlockRenderLayerMap.INSTANCE.putBlock(block, translucent);
} }
}); });
} }

View file

@ -56,28 +56,25 @@ public class BlockSignEditScreen extends Screen {
model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK))); model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
minecraft.keyboardHandler.setSendRepeatsToGui(true); minecraft.keyboardHandler.setSendRepeatsToGui(true);
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, (buttonWidget) -> {
(buttonWidget) -> { this.finishEditing();
this.finishEditing(); }));
}));
this.sign.setEditable(false); this.sign.setEditable(false);
this.selectionManager = new TextFieldHelper(() -> { this.selectionManager = new TextFieldHelper(() -> {
return this.text[this.currentRow]; return this.text[this.currentRow];
}, (string) -> { }, (string) -> {
this.text[this.currentRow] = string; this.text[this.currentRow] = string;
this.sign.setMessage(this.currentRow, new TextComponent(string)); this.sign.setMessage(this.currentRow, new TextComponent(string));
}, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), }, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), (string) -> {
(string) -> { return this.minecraft.font.width(string) <= 90;
return this.minecraft.font.width(string) <= 90; });
});
} }
public void removed() { public void removed() {
minecraft.keyboardHandler.setSendRepeatsToGui(false); minecraft.keyboardHandler.setSendRepeatsToGui(false);
ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection(); ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection();
if (clientPlayNetworkHandler != null) { if (clientPlayNetworkHandler != null) {
clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], this.text[2], this.text[3]));
this.text[2], this.text[3]));
} }
this.sign.setEditable(true); this.sign.setEditable(true);
@ -109,9 +106,11 @@ public class BlockSignEditScreen extends Screen {
this.currentRow = this.currentRow - 1 & 3; this.currentRow = this.currentRow - 1 & 3;
this.selectionManager.setCursorToEnd(); this.selectionManager.setCursorToEnd();
return true; return true;
} else if (keyCode != 264 && keyCode != 257 && keyCode != 335) { }
else if (keyCode != 264 && keyCode != 257 && keyCode != 335) {
return selectionManager.keyPressed(keyCode) || super.keyPressed(keyCode, scanCode, modifiers); return selectionManager.keyPressed(keyCode) || super.keyPressed(keyCode, scanCode, modifiers);
} else { }
else {
this.currentRow = this.currentRow + 1 & 3; this.currentRow = this.currentRow + 1 & 3;
this.selectionManager.setCursorToEnd(); this.selectionManager.setCursorToEnd();
return true; return true;
@ -168,15 +167,12 @@ public class BlockSignEditScreen extends Screen {
} }
float n = (float) (-this.minecraft.font.width(string2) / 2); float n = (float) (-this.minecraft.font.width(string2) / 2);
this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, immediate, false, 0, 15728880, false);
immediate, false, 0, 15728880, false);
if (m == this.currentRow && j >= 0 && bl2) { if (m == this.currentRow && j >= 0 && bl2) {
s = this.minecraft.font s = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
t = s - this.minecraft.font.width(string2) / 2; t = s - this.minecraft.font.width(string2) / 2;
if (j >= string2.length()) { if (j >= string2.length()) {
this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, 0, 15728880, false);
0, 15728880, false);
} }
} }
} }
@ -187,8 +183,7 @@ public class BlockSignEditScreen extends Screen {
for (m = 0; m < this.text.length; ++m) { for (m = 0; m < this.text.length; ++m) {
string2 = this.text[m]; string2 = this.text[m];
if (string2 != null && m == this.currentRow && j >= 0) { if (string2 != null && m == this.currentRow && j >= 0) {
int r = this.minecraft.font int r = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
s = r - this.minecraft.font.width(string2) / 2; s = r - this.minecraft.font.width(string2) / 2;
if (bl2 && j < string2.length()) { if (bl2 && j < string2.length()) {
int var31 = l - 1; int var31 = l - 1;
@ -200,10 +195,8 @@ public class BlockSignEditScreen extends Screen {
if (k != j) { if (k != j) {
t = Math.min(j, k); t = Math.min(j, k);
int u = Math.max(j, k); int u = Math.max(j, k);
int v = this.minecraft.font.width(string2.substring(0, t)) int v = this.minecraft.font.width(string2.substring(0, t)) - this.minecraft.font.width(string2) / 2;
- this.minecraft.font.width(string2) / 2; int w = this.minecraft.font.width(string2.substring(0, u)) - this.minecraft.font.width(string2) / 2;
int w = this.minecraft.font.width(string2.substring(0, u))
- this.minecraft.font.width(string2) / 2;
int x = Math.min(v, w); int x = Math.min(v, w);
int y = Math.max(v, w); int y = Math.max(v, w);
Tesselator tessellator = Tesselator.getInstance(); Tesselator tessellator = Tesselator.getInstance();

View file

@ -2,90 +2,67 @@ package ru.bclib.client.models;
import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose; import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*; import net.minecraft.client.model.geom.builders.CubeDeformation;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
public class BaseChestBlockModel { public class BaseChestBlockModel {
public final ModelPart partA; public final ModelPart partA;
public final ModelPart partC; public final ModelPart partC;
public final ModelPart partB; public final ModelPart partB;
public final ModelPart partRightA; public final ModelPart partRightA;
public final ModelPart partRightC; public final ModelPart partRightC;
public final ModelPart partRightB; public final ModelPart partRightB;
public final ModelPart partLeftA; public final ModelPart partLeftA;
public final ModelPart partLeftC; public final ModelPart partLeftC;
public final ModelPart partLeftB; public final ModelPart partLeftB;
public static LayerDefinition getTexturedModelData() { public static LayerDefinition getTexturedModelData() {
MeshDefinition modelData = new MeshDefinition(); MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot(); PartDefinition modelPartData = modelData.getRoot();
CubeDeformation deformation_partC = new CubeDeformation(0.0f); CubeDeformation deformation_partC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partC", CubeListBuilder.create() modelPartData.addOrReplaceChild("partC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC), PartPose.ZERO);
.texOffs(0, 19)
.addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC),
PartPose.ZERO);
CubeDeformation deformation_partA = new CubeDeformation(0.0f); CubeDeformation deformation_partA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partA", CubeListBuilder.create() modelPartData.addOrReplaceChild("partA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA), PartPose.offset(0.0f, 9.0f, 1.0f));
.texOffs(0, 0)
.addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partB = new CubeDeformation(0.0f); CubeDeformation deformation_partB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partB", CubeListBuilder.create() modelPartData.addOrReplaceChild("partB", CubeListBuilder.create().texOffs(0, 0).addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB), PartPose.offset(0.0f, 8.0f, 0.0f));
.texOffs(0, 0)
.addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB),
PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partRightC = new CubeDeformation(0.0f); CubeDeformation deformation_partRightC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightC", CubeListBuilder.create() modelPartData.addOrReplaceChild("partRightC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC), PartPose.ZERO);
.texOffs(0, 19)
.addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC),
PartPose.ZERO);
CubeDeformation deformation_partRightA = new CubeDeformation(0.0f); CubeDeformation deformation_partRightA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightA", CubeListBuilder.create() modelPartData.addOrReplaceChild("partRightA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA), PartPose.offset(0.0f, 9.0f, 1.0f));
.texOffs(0, 0)
.addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partRightB = new CubeDeformation(0.0f); CubeDeformation deformation_partRightB = new CubeDeformation(0.0f);
PartDefinition partRightB = modelPartData.addOrReplaceChild("partRightB", CubeListBuilder.create() PartDefinition partRightB = modelPartData.addOrReplaceChild("partRightB", CubeListBuilder.create().texOffs(0, 0).addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB), PartPose.offset(0.0f, 8.0f, 0.0f));
.texOffs(0, 0)
.addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB),
PartPose.offset(0.0f, 8.0f, 0.0f));
CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f); CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftC", CubeListBuilder.create() modelPartData.addOrReplaceChild("partLeftC", CubeListBuilder.create().texOffs(0, 19).addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC), PartPose.ZERO);
.texOffs(0, 19)
.addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC),
PartPose.ZERO);
CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f); CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftA", CubeListBuilder.create() modelPartData.addOrReplaceChild("partLeftA", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA), PartPose.offset(0.0f, 9.0f, 1.0f));
.texOffs(0, 0)
.addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA),
PartPose.offset(0.0f, 9.0f, 1.0f));
CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f); CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftB", CubeListBuilder.create() modelPartData.addOrReplaceChild("partLeftB", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB), PartPose.offset(0.0f, 8.0f, 0.0f));
.texOffs(0, 0)
.addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB),
PartPose.offset(0.0f, 8.0f, 0.0f));
return LayerDefinition.create(modelData, 64, 64); return LayerDefinition.create(modelData, 64, 64);
} }
public BaseChestBlockModel(ModelPart modelPart) { public BaseChestBlockModel(ModelPart modelPart) {
super(); super();
partC = modelPart.getChild("partC"); partC = modelPart.getChild("partC");
partA = modelPart.getChild("partA"); partA = modelPart.getChild("partA");
partB = modelPart.getChild("partB"); partB = modelPart.getChild("partB");
partRightC = modelPart.getChild("partRightC"); partRightC = modelPart.getChild("partRightC");
partRightA = modelPart.getChild("partRightA"); partRightA = modelPart.getChild("partRightA");
partRightB = modelPart.getChild("partRightB"); partRightB = modelPart.getChild("partRightB");
partLeftC = modelPart.getChild("partLeftC"); partLeftC = modelPart.getChild("partLeftC");
partLeftA = modelPart.getChild("partLeftA"); partLeftA = modelPart.getChild("partLeftA");
partLeftB = modelPart.getChild("partLeftB"); partLeftB = modelPart.getChild("partLeftB");
} }
} }

View file

@ -1,20 +1,19 @@
package ru.bclib.client.models; package ru.bclib.client.models;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import java.util.Map;
import java.util.Optional;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ItemModelProvider { public interface BlockModelProvider extends ItemModelProvider {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
@ -36,7 +35,8 @@ public interface BlockModelProvider extends ItemModelProvider {
if (model != null) { if (model != null) {
model.name = modelId.toString(); model.name = modelId.toString();
modelCache.put(modelId, model); modelCache.put(modelId, model);
} else { }
else {
BCLib.LOGGER.warning("Error loading model: {}", modelId); BCLib.LOGGER.warning("Error loading model: {}", modelId);
modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION)); modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION));
} }

View file

@ -1,12 +1,7 @@
package ru.bclib.client.models; package ru.bclib.client.models;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.math.Transformation; import com.mojang.math.Transformation;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -22,6 +17,10 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class ModelsHelper { public class ModelsHelper {
public static BlockModel fromPattern(Optional<String> pattern) { public static BlockModel fromPattern(Optional<String> pattern) {
@ -66,20 +65,20 @@ public class ModelsHelper {
public static MultiVariant createRotatedModel(ResourceLocation resourceLocation, Direction.Axis axis) { public static MultiVariant createRotatedModel(ResourceLocation resourceLocation, Direction.Axis axis) {
BlockModelRotation rotation = BlockModelRotation.X0_Y0; BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (axis) { switch (axis) {
case X: rotation = BlockModelRotation.X90_Y90; break; case X:
case Z: rotation = BlockModelRotation.X90_Y0; break; rotation = BlockModelRotation.X90_Y90;
default: break; break;
case Z:
rotation = BlockModelRotation.X90_Y0;
break;
default:
break;
} }
return createMultiVariant(resourceLocation, rotation.getRotation(), false); return createMultiVariant(resourceLocation, rotation.getRotation(), false);
} }
public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) { public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) {
return new MultiVariant(Lists.newArrayList( return new MultiVariant(Lists.newArrayList(new Variant(resourceLocation, Transformation.identity(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)));
new Variant(resourceLocation, Transformation.identity(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)
));
} }
public static class MultiPartBuilder { public static class MultiPartBuilder {

View file

@ -1,5 +1,10 @@
package ru.bclib.client.models; package ru.bclib.client.models;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -8,12 +13,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
public class PatternsHelper { public class PatternsHelper {
public static Optional<String> createItemGenerated(ResourceLocation itemId) { public static Optional<String> createItemGenerated(ResourceLocation itemId) {
return createJson(BasePatterns.ITEM_GENERATED, itemId); return createJson(BasePatterns.ITEM_GENERATED, itemId);
@ -53,13 +52,13 @@ public class PatternsHelper {
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) { public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) { try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
.lines().collect(Collectors.joining());
for (Map.Entry<String, String> texture : textures.entrySet()) { for (Map.Entry<String, String> texture : textures.entrySet()) {
json = json.replace(texture.getKey(), texture.getValue()); json = json.replace(texture.getKey(), texture.getValue());
} }
return Optional.of(json); return Optional.of(json);
} catch (Exception ex) { }
catch (Exception ex) {
return Optional.empty(); return Optional.empty();
} }
} }

View file

@ -1,6 +1,5 @@
package ru.bclib.client.render; package ru.bclib.client.render;
public enum BCLRenderLayer { public enum BCLRenderLayer {
CUTOUT, CUTOUT, TRANSLUCENT;
TRANSLUCENT;
} }

View file

@ -18,7 +18,11 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*; import net.minecraft.world.level.block.AbstractChestBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult; import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
import net.minecraft.world.level.block.entity.ChestBlockEntity; import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -38,6 +42,7 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
private static final int ID_RIGHT = 2; private static final int ID_RIGHT = 2;
private final BaseChestBlockModel chestModel; private final BaseChestBlockModel chestModel;
public BaseChestBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) { public BaseChestBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {
super(); super();
chestModel = new BaseChestBlockModel(BaseChestBlockModel.getTexturedModelData().bakeRoot()); chestModel = new BaseChestBlockModel(BaseChestBlockModel.getTexturedModelData().bakeRoot());
@ -62,25 +67,27 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
if (worldExists) { if (worldExists) {
propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true); propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true);
} else { }
else {
propertySource = DoubleBlockCombiner.Combiner::acceptNone; propertySource = DoubleBlockCombiner.Combiner::acceptNone;
} }
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta); float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta);
pitch = 1.0F - pitch; pitch = 1.0F - pitch;
pitch = 1.0F - pitch * pitch * pitch; pitch = 1.0F - pitch * pitch * pitch;
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({"unchecked", "rawtypes"}) int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType); VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
if (isDouble) { if (isDouble) {
if (chestType == ChestType.LEFT) { if (chestType == ChestType.LEFT) {
renderParts(matrices, vertexConsumer, chestModel.partLeftA, chestModel.partLeftB, chestModel.partLeftC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, chestModel.partLeftA, chestModel.partLeftB, chestModel.partLeftC, pitch, blockLight, overlay);
} else { }
else {
renderParts(matrices, vertexConsumer, chestModel.partRightA, chestModel.partRightB, chestModel.partRightC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, chestModel.partRightA, chestModel.partRightB, chestModel.partRightC, pitch, blockLight, overlay);
} }
} else { }
else {
renderParts(matrices, vertexConsumer, chestModel.partA, chestModel.partB, chestModel.partC, pitch, blockLight, overlay); renderParts(matrices, vertexConsumer, chestModel.partA, chestModel.partB, chestModel.partC, pitch, blockLight, overlay);
} }
@ -113,18 +120,10 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
ResourceLocation blockId = Registry.BLOCK.getKey(block); ResourceLocation blockId = Registry.BLOCK.getKey(block);
String modId = blockId.getNamespace(); String modId = blockId.getNamespace();
String path = blockId.getPath(); String path = blockId.getPath();
LAYERS.put(block, new RenderType[] { LAYERS.put(block, new RenderType[] {RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))});
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))
});
} }
static { static {
defaultLayer = new RenderType[] { defaultLayer = new RenderType[] {RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))};
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
};
} }
} }

View file

@ -51,8 +51,7 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
model = new SignRenderer.SignModel(ctx.bakeLayer(ModelLayers.createSignModelName(WoodType.OAK))); model = new SignRenderer.SignModel(ctx.bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
} }
public void render(BaseSignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack, public void render(BaseSignBlockEntity signBlockEntity, float tickDelta, PoseStack matrixStack, MultiBufferSource provider, int light, int overlay) {
MultiBufferSource provider, int light, int overlay) {
BlockState state = signBlockEntity.getBlockState(); BlockState state = signBlockEntity.getBlockState();
matrixStack.pushPose(); matrixStack.pushPose();
@ -65,7 +64,8 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
if (blockState.getValue(BaseSignBlock.FLOOR)) { if (blockState.getValue(BaseSignBlock.FLOOR)) {
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle)); matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
model.stick.visible = true; model.stick.visible = true;
} else { }
else {
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180)); matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle + 180));
matrixStack.translate(0.0D, -0.3125D, -0.4375D); matrixStack.translate(0.0D, -0.3125D, -0.4375D);
model.stick.visible = false; model.stick.visible = false;
@ -87,11 +87,10 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
int p = (int) (NativeImage.getB(m) * 0.4D); int p = (int) (NativeImage.getB(m) * 0.4D);
int q = NativeImage.combine(0, p, o, n); int q = NativeImage.combine(0, p, o, n);
FormattedCharSequence[] formattedCharSequences = signBlockEntity FormattedCharSequence[] formattedCharSequences = signBlockEntity.getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), (component) -> {
.getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), (component) -> { List<FormattedCharSequence> list = this.font.split(component, 90);
List<FormattedCharSequence> list = this.font.split(component, 90); return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0);
return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0); });
});
int drawColor; int drawColor;
boolean drawOutlined; boolean drawOutlined;
int drawLight; int drawLight;
@ -99,7 +98,8 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
drawColor = signBlockEntity.getColor().getTextColor(); drawColor = signBlockEntity.getColor().getTextColor();
drawOutlined = isOutlineVisible(signBlockEntity, drawColor); drawOutlined = isOutlineVisible(signBlockEntity, drawColor);
drawLight = 15728880; drawLight = 15728880;
} else { }
else {
drawColor = m; drawColor = m;
drawOutlined = false; drawOutlined = false;
drawLight = light; drawLight = light;
@ -109,11 +109,10 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
FormattedCharSequence formattedCharSequence = formattedCharSequences[s]; FormattedCharSequence formattedCharSequence = formattedCharSequences[s];
float t = (float) (-this.font.width(formattedCharSequence) / 2); float t = (float) (-this.font.width(formattedCharSequence) / 2);
if (drawOutlined) { if (drawOutlined) {
this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m, this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m, matrixStack.last().pose(), provider, drawLight);
matrixStack.last().pose(), provider, drawLight); }
} else { else {
this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false, this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false, matrixStack.last().pose(), provider, false, 0, drawLight);
matrixStack.last().pose(), provider, false, 0, drawLight);
} }
} }
@ -122,19 +121,19 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
} }
private static boolean isOutlineVisible(BaseSignBlockEntity signBlockEntity, int i) { private static boolean isOutlineVisible(BaseSignBlockEntity signBlockEntity, int i) {
if (i == DyeColor.BLACK.getTextColor()) { if (i == DyeColor.BLACK.getTextColor()) {
return true; return true;
} else { }
else {
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
LocalPlayer localPlayer = minecraft.player; LocalPlayer localPlayer = minecraft.player;
if (localPlayer != null && minecraft.options.getCameraType().isFirstPerson() && localPlayer.isScoping()) { if (localPlayer != null && minecraft.options.getCameraType().isFirstPerson() && localPlayer.isScoping()) {
return true; return true;
} else { }
else {
Entity entity = minecraft.getCameraEntity(); Entity entity = minecraft.getCameraEntity();
return entity != null && entity.distanceToSqr( return entity != null && entity.distanceToSqr(Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
Vec3.atCenterOf(signBlockEntity.getBlockPos())) < (double) OUTLINE_RENDER_DISTANCE;
} }
} }
} }
@ -143,7 +142,8 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
WoodType signType2; WoodType signType2;
if (block instanceof SignBlock) { if (block instanceof SignBlock) {
signType2 = ((SignBlock) block).type(); signType2 = ((SignBlock) block).type();
} else { }
else {
signType2 = WoodType.OAK; signType2 = WoodType.OAK;
} }
@ -160,8 +160,7 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
public static void registerRenderLayer(Block block) { public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block); ResourceLocation blockId = Registry.BLOCK.getKey(block);
RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(), RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(), "textures/entity/sign/" + blockId.getPath() + ".png"));
"textures/entity/sign/" + blockId.getPath() + ".png"));
LAYERS.put(block, layer); LAYERS.put(block, layer);
} }

View file

@ -4,10 +4,5 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
public class BlockSounds { public class BlockSounds {
public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, SoundEvents.STONE_BREAK, SoundEvents.WART_BLOCK_STEP, SoundEvents.STONE_PLACE, SoundEvents.STONE_HIT, SoundEvents.STONE_FALL);
SoundEvents.STONE_BREAK,
SoundEvents.WART_BLOCK_STEP,
SoundEvents.STONE_PLACE,
SoundEvents.STONE_HIT,
SoundEvents.STONE_FALL);
} }

View file

@ -1,7 +1,6 @@
package ru.bclib.config; package ru.bclib.config;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.config.ConfigKeeper.BooleanEntry; import ru.bclib.config.ConfigKeeper.BooleanEntry;
import ru.bclib.config.ConfigKeeper.Entry; import ru.bclib.config.ConfigKeeper.Entry;
@ -55,7 +54,8 @@ public abstract class Config {
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
return true; return true;
} catch (NullPointerException ex) { }
catch (NullPointerException ex) {
BCLib.LOGGER.catching(ex); BCLib.LOGGER.catching(ex);
} }
return false; return false;
@ -81,7 +81,8 @@ public abstract class Config {
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
return true; return true;
} catch (NullPointerException ex) { }
catch (NullPointerException ex) {
BCLib.LOGGER.catching(ex); BCLib.LOGGER.catching(ex);
} }
return false; return false;
@ -93,7 +94,8 @@ public abstract class Config {
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
return true; return true;
} catch (NullPointerException | ClassCastException ex) { }
catch (NullPointerException | ClassCastException ex) {
BCLib.LOGGER.catching(ex); BCLib.LOGGER.catching(ex);
} }
return false; return false;
@ -119,7 +121,8 @@ public abstract class Config {
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
return true; return true;
} catch (NullPointerException ex) { }
catch (NullPointerException ex) {
BCLib.LOGGER.catching(ex); BCLib.LOGGER.catching(ex);
} }
return false; return false;
@ -145,7 +148,8 @@ public abstract class Config {
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
return true; return true;
} catch (NullPointerException ex) { }
catch (NullPointerException ex) {
BCLib.LOGGER.catching(ex); BCLib.LOGGER.catching(ex);
} }
return false; return false;

View file

@ -1,20 +1,18 @@
package ru.bclib.config; package ru.bclib.config;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.util.GsonHelper; import net.minecraft.util.GsonHelper;
import org.jetbrains.annotations.Nullable;
import ru.bclib.util.JsonFactory; import ru.bclib.util.JsonFactory;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
public final class ConfigKeeper { public final class ConfigKeeper {
private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap(); private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
private final JsonObject configObject; private final JsonObject configObject;
@ -297,8 +295,7 @@ public final class ConfigKeeper {
} }
protected boolean hasLocation() { protected boolean hasLocation() {
return this.location != null && return this.location != null && this.key != null;
this.key != null;
} }
public T getValue() { public T getValue() {

View file

@ -1,14 +1,13 @@
package ru.bclib.config; package ru.bclib.config;
import java.io.File;
import java.nio.file.Path;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import ru.bclib.util.JsonFactory; import ru.bclib.util.JsonFactory;
import java.io.File;
import java.nio.file.Path;
public class ConfigWriter { public class ConfigWriter {
private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir(); private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir();

View file

@ -1,14 +1,13 @@
package ru.bclib.config; package ru.bclib.config;
import java.util.function.BiFunction;
import org.jetbrains.annotations.Nullable;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import ru.bclib.config.ConfigKeeper.Entry; import ru.bclib.config.ConfigKeeper.Entry;
import ru.bclib.config.ConfigKeeper.FloatRange; import ru.bclib.config.ConfigKeeper.FloatRange;
import ru.bclib.config.ConfigKeeper.IntegerRange; import ru.bclib.config.ConfigKeeper.IntegerRange;
import java.util.function.BiFunction;
public class IdConfig extends Config { public class IdConfig extends Config {
protected final BiFunction<ResourceLocation, String, ConfigKey> keyFactory; protected final BiFunction<ResourceLocation, String, ConfigKey> keyFactory;

View file

@ -1,7 +1,6 @@
package ru.bclib.config; package ru.bclib.config;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import ru.bclib.config.ConfigKeeper.Entry; import ru.bclib.config.ConfigKeeper.Entry;
import ru.bclib.config.ConfigKeeper.FloatRange; import ru.bclib.config.ConfigKeeper.FloatRange;
import ru.bclib.config.ConfigKeeper.IntegerRange; import ru.bclib.config.ConfigKeeper.IntegerRange;

View file

@ -1,10 +1,5 @@
package ru.bclib.integration; package ru.bclib.integration;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.fabric.api.tag.TagRegistry;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
@ -25,6 +20,11 @@ import net.minecraft.world.level.levelgen.feature.Feature;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public abstract class ModIntegration { public abstract class ModIntegration {
private final String modID; private final String modID;
@ -178,7 +178,7 @@ public abstract class ModIntegration {
public Object newInstance(Class<?> cl, Object... args) { public Object newInstance(Class<?> cl, Object... args) {
if (cl != null) { if (cl != null) {
for (Constructor<?> constructor: cl.getConstructors()) { for (Constructor<?> constructor : cl.getConstructors()) {
if (constructor.getParameterCount() == args.length) { if (constructor.getParameterCount() == args.length) {
try { try {
return constructor.newInstance(args); return constructor.newInstance(args);

View file

@ -2,5 +2,6 @@ package ru.bclib.interfaces;
public interface ISpetialItem { public interface ISpetialItem {
boolean canPlaceOnWater(); boolean canPlaceOnWater();
int getStackSize(); int getStackSize();
} }

View file

@ -1,9 +1,5 @@
package ru.bclib.items; package ru.bclib.items;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -18,9 +14,12 @@ import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blocks.BaseAnvilBlock; import ru.bclib.blocks.BaseAnvilBlock;
import ru.bclib.client.models.ItemModelProvider; import ru.bclib.client.models.ItemModelProvider;
import java.util.List;
public class BaseAnvilItem extends BlockItem implements ItemModelProvider { public class BaseAnvilItem extends BlockItem implements ItemModelProvider {
public final static String DESTRUCTION = "destruction"; public final static String DESTRUCTION = "destruction";

View file

@ -1,10 +1,7 @@
package ru.bclib.items; package ru.bclib.items;
import java.util.UUID;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.AttributeModifier;
@ -13,14 +10,11 @@ import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ArmorMaterial;
import ru.bclib.client.models.ItemModelProvider; import ru.bclib.client.models.ItemModelProvider;
import java.util.UUID;
public class BaseArmorItem extends ArmorItem implements ItemModelProvider { public class BaseArmorItem extends ArmorItem implements ItemModelProvider {
protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] { protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] {UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")};
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"),
UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"),
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
protected final Multimap<Attribute, AttributeModifier> defaultModifiers; protected final Multimap<Attribute, AttributeModifier> defaultModifiers;

View file

@ -1,7 +1,5 @@
package ru.bclib.items; package ru.bclib.items;
import java.util.Optional;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
@ -14,6 +12,8 @@ import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.models.PatternsHelper;
import java.util.Optional;
public class BaseSpawnEggItem extends SpawnEggItem implements ItemModelProvider { public class BaseSpawnEggItem extends SpawnEggItem implements ItemModelProvider {
public BaseSpawnEggItem(EntityType<? extends Mob> type, int primaryColor, int secondaryColor, Properties settings) { public BaseSpawnEggItem(EntityType<? extends Mob> type, int primaryColor, int secondaryColor, Properties settings) {
super(type, primaryColor, secondaryColor, settings); super(type, primaryColor, secondaryColor, settings);

View file

@ -1,15 +1,6 @@
package ru.bclib.mixin.client; package ru.bclib.mixin.client;
import net.minecraft.world.level.material.FogType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.FogRenderer;
@ -21,7 +12,12 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FogType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.util.BackgroundInfo; import ru.bclib.util.BackgroundInfo;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;

View file

@ -1,20 +1,19 @@
package ru.bclib.mixin.client; package ru.bclib.mixin.client;
import java.util.Random;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EnchantmentTableBlock; import net.minecraft.world.level.block.EnchantmentTableBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
import java.util.Random;
@Mixin(EnchantmentTableBlock.class) @Mixin(EnchantmentTableBlock.class)
public abstract class EnchantingTableBlockMixin extends Block { public abstract class EnchantingTableBlockMixin extends Block {
public EnchantingTableBlockMixin(Properties settings) { public EnchantingTableBlockMixin(Properties settings) {

View file

@ -1,16 +1,5 @@
package ru.bclib.mixin.client; package ru.bclib.mixin.client;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.renderer.block.BlockModelShaper; import net.minecraft.client.renderer.block.BlockModelShaper;
import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.multipart.MultiPart; import net.minecraft.client.renderer.block.model.multipart.MultiPart;
@ -24,10 +13,20 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ItemModelProvider; import ru.bclib.client.models.ItemModelProvider;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Mixin(ModelBakery.class) @Mixin(ModelBakery.class)
public abstract class ModelBakeryMixin { public abstract class ModelBakeryMixin {
@Final @Final
@ -55,7 +54,8 @@ public abstract class ModelBakeryMixin {
ItemModelProvider modelProvider = null; ItemModelProvider modelProvider = null;
if (item instanceof ItemModelProvider) { if (item instanceof ItemModelProvider) {
modelProvider = (ItemModelProvider) item; modelProvider = (ItemModelProvider) item;
} else if (item instanceof BlockItem) { }
else if (item instanceof BlockItem) {
Block block = Registry.BLOCK.get(clearLoc); Block block = Registry.BLOCK.get(clearLoc);
if (block instanceof ItemModelProvider) { if (block instanceof ItemModelProvider) {
modelProvider = (ItemModelProvider) block; modelProvider = (ItemModelProvider) block;
@ -67,21 +67,21 @@ public abstract class ModelBakeryMixin {
model.name = itemLoc.toString(); model.name = itemLoc.toString();
cacheAndQueueDependencies(modelId, model); cacheAndQueueDependencies(modelId, model);
unbakedCache.put(itemLoc, model); unbakedCache.put(itemLoc, model);
} else { }
else {
BCLib.LOGGER.warning("Error loading model: {}", itemLoc); BCLib.LOGGER.warning("Error loading model: {}", itemLoc);
} }
info.cancel(); info.cancel();
} }
} }
} else { }
else {
ResourceLocation stateLoc = new ResourceLocation(modId, "blockstates/" + path + ".json"); ResourceLocation stateLoc = new ResourceLocation(modId, "blockstates/" + path + ".json");
if (!resourceManager.hasResource(stateLoc)) { if (!resourceManager.hasResource(stateLoc)) {
Block block = Registry.BLOCK.get(clearLoc); Block block = Registry.BLOCK.get(clearLoc);
if (block instanceof BlockModelProvider) { if (block instanceof BlockModelProvider) {
List<BlockState> possibleStates = block.getStateDefinition().getPossibleStates(); List<BlockState> possibleStates = block.getStateDefinition().getPossibleStates();
Optional<BlockState> possibleState = possibleStates.stream() Optional<BlockState> possibleState = possibleStates.stream().filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state))).findFirst();
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
.findFirst();
if (possibleState.isPresent()) { if (possibleState.isPresent()) {
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache); UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache);
if (modelVariant != null) { if (modelVariant != null) {
@ -90,10 +90,12 @@ public abstract class ModelBakeryMixin {
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state); ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
cacheAndQueueDependencies(stateId, modelVariant); cacheAndQueueDependencies(stateId, modelVariant);
}); });
} else { }
else {
cacheAndQueueDependencies(modelId, modelVariant); cacheAndQueueDependencies(modelId, modelVariant);
} }
} else { }
else {
BCLib.LOGGER.warning("Error loading variant: {}", modelId); BCLib.LOGGER.warning("Error loading variant: {}", modelId);
} }
info.cancel(); info.cancel();

View file

@ -1,10 +1,5 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
@ -16,6 +11,10 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.api.BonemealAPI; import ru.bclib.api.BonemealAPI;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;

View file

@ -1,10 +1,9 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.ComposterBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(ComposterBlock.class) @Mixin(ComposterBlock.class)
public interface ComposterBlockAccessor { public interface ComposterBlockAccessor {

View file

@ -1,15 +1,5 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.util.List;
import java.util.Random;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.world.Container; import net.minecraft.world.Container;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
@ -20,8 +10,17 @@ import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.EnchantmentInstance; import net.minecraft.world.item.enchantment.EnchantmentInstance;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
import java.util.List;
import java.util.Random;
@Mixin(EnchantmentMenu.class) @Mixin(EnchantmentMenu.class)
public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { public abstract class EnchantmentMenuMixin extends AbstractContainerMenu {
@Final @Final

View file

@ -1,16 +1,9 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import net.minecraft.data.worldgen.Features;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator; import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators") @Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators")
public interface FeatureDecoratorsAccessor { public interface FeatureDecoratorsAccessor {
@Accessor("HEIGHTMAP_SQUARE") @Accessor("HEIGHTMAP_SQUARE")

View file

@ -1,17 +1,5 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -19,9 +7,20 @@ import net.minecraft.server.ServerResources;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.WorldData; import net.minecraft.world.level.storage.WorldData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.recipes.BCLRecipeManager; import ru.bclib.recipes.BCLRecipeManager;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@Mixin(MinecraftServer.class) @Mixin(MinecraftServer.class)
public class MinecraftServerMixin { public class MinecraftServerMixin {
@Shadow @Shadow

View file

@ -1,11 +1,10 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing; import net.minecraft.world.item.alchemy.PotionBrewing;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(PotionBrewing.class) @Mixin(PotionBrewing.class)
public interface PotionBrewingAccessor { public interface PotionBrewingAccessor {

View file

@ -1,14 +1,13 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.util.Map;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(RecipeManager.class) @Mixin(RecipeManager.class)
public interface RecipeManagerAccessor { public interface RecipeManagerAccessor {

View file

@ -1,20 +1,6 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
@ -24,8 +10,20 @@ import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.recipes.BCLRecipeManager; import ru.bclib.recipes.BCLRecipeManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Mixin(RecipeManager.class) @Mixin(RecipeManager.class)
public abstract class RecipeManagerMixin { public abstract class RecipeManagerMixin {
@Shadow @Shadow

View file

@ -1,15 +1,5 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.io.File;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -22,10 +12,19 @@ import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WritableLevelData; import net.minecraft.world.level.storage.WritableLevelData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.api.DataFixerAPI; import ru.bclib.api.DataFixerAPI;
import ru.bclib.api.WorldDataAPI; import ru.bclib.api.WorldDataAPI;
import java.io.File;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.function.Supplier;
@Mixin(ServerLevel.class) @Mixin(ServerLevel.class)
public abstract class ServerLevelMixin extends Level { public abstract class ServerLevelMixin extends Level {
private static String bcl_lastWorld = null; private static String bcl_lastWorld = null;

View file

@ -1,7 +1,5 @@
package ru.bclib.mixin.common; package ru.bclib.mixin.common;
import java.util.Map;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.tags.TagLoader; import net.minecraft.tags.TagLoader;
@ -11,6 +9,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyArg;
import ru.bclib.util.TagHelper; import ru.bclib.util.TagHelper;
import java.util.Map;
@Mixin(TagLoader.class) @Mixin(TagLoader.class)
public class TagLoaderMixin { public class TagLoaderMixin {
@Shadow @Shadow

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
package ru.bclib.noise; package ru.bclib.noise;
import java.util.Random;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import java.util.Random;
public class VoronoiNoise { public class VoronoiNoise {
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
final int seed; final int seed;

View file

@ -1,10 +1,6 @@
package ru.bclib.recipes; package ru.bclib.recipes;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.Recipe;
@ -13,6 +9,9 @@ import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import java.util.Map;
import java.util.Map.Entry;
public class BCLRecipeManager { public class BCLRecipeManager {
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap(); private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
@ -52,8 +51,7 @@ public class BCLRecipeManager {
} }
for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) { for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) {
ResourceLocation id = entry.getKey(); ResourceLocation id = entry.getKey();
if (!typeList.containsKey(id)) if (!typeList.containsKey(id)) typeList.put(id, entry.getValue());
typeList.put(id, entry.getValue());
} }
} }
} }
@ -71,13 +69,14 @@ public class BCLRecipeManager {
public String toString() { public String toString() {
return type; return type;
} }
}); });
} }
public static boolean exists(ItemLike item) { public static boolean exists(ItemLike item) {
if (item instanceof Block) { if (item instanceof Block) {
return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey(); return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey();
} else { }
else {
return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey(); return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey();
} }
} }

View file

@ -20,18 +20,8 @@ public class CraftingRecipes {
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART).setShape("I I", "III").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build(); GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART).setShape("I I", "III").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD).setShape("WIW", "WWW", " W ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('W', ItemTags.PLANKS).checkConfig(Configs.RECIPE_CONFIG).build(); GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD).setShape("WIW", "WWW", " W ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('W', ItemTags.PLANKS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER) GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER).setShape("I I", "ICI", " I ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
.setShape("I I", "ICI", " I ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('C', TagAPI.ITEM_CHEST)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX) GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX).setShape("S", "C", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
.setShape("S", "C", "S")
.addMaterial('S', Items.SHULKER_SHELL)
.addMaterial('C', TagAPI.ITEM_CHEST)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
} }
} }

View file

@ -1,10 +1,6 @@
package ru.bclib.recipes; package ru.bclib.recipes;
import java.util.Arrays;
import java.util.Map;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.minecraft.core.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
@ -19,6 +15,9 @@ import net.minecraft.world.level.ItemLike;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.config.PathConfig; import ru.bclib.config.PathConfig;
import java.util.Arrays;
import java.util.Map;
public class GridRecipe { public class GridRecipe {
private static final GridRecipe INSTANCE = new GridRecipe(); private static final GridRecipe INSTANCE = new GridRecipe();
@ -67,7 +66,7 @@ public class GridRecipe {
} }
public GridRecipe setList(String shape) { public GridRecipe setList(String shape) {
this.shape = new String[] { shape }; this.shape = new String[] {shape};
this.shaped = false; this.shaped = false;
return this; return this;
} }
@ -81,7 +80,7 @@ public class GridRecipe {
} }
public GridRecipe addMaterial(char key, ItemLike... values) { public GridRecipe addMaterial(char key, ItemLike... values) {
for (ItemLike item: values) { for (ItemLike item : values) {
exist &= BCLRecipeManager.exists(item); exist &= BCLRecipeManager.exists(item);
} }
return addMaterial(key, Ingredient.of(values)); return addMaterial(key, Ingredient.of(values));
@ -100,11 +99,11 @@ public class GridRecipe {
private NonNullList<Ingredient> getMaterials(int width, int height) { private NonNullList<Ingredient> getMaterials(int width, int height) {
NonNullList<Ingredient> materials = NonNullList.withSize(width * height, Ingredient.EMPTY); NonNullList<Ingredient> materials = NonNullList.withSize(width * height, Ingredient.EMPTY);
int pos = 0; int pos = 0;
for (String line: shape) { for (String line : shape) {
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
char c = line.charAt(i); char c = line.charAt(i);
Ingredient material = materialKeys.get(c); Ingredient material = materialKeys.get(c);
materials.set(pos ++, material == null ? Ingredient.EMPTY : material); materials.set(pos++, material == null ? Ingredient.EMPTY : material);
} }
} }
return materials; return materials;
@ -119,7 +118,8 @@ public class GridRecipe {
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials); CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
BCLRecipeManager.addRecipe(type, recipe); BCLRecipeManager.addRecipe(type, recipe);
} else { }
else {
BCLib.LOGGER.debug("Recipe {} couldn't be added", id); BCLib.LOGGER.debug("Recipe {} couldn't be added", id);
} }
} }

View file

@ -89,7 +89,7 @@ public class SmithingTableRecipe {
BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
return; return;
} }
if(result == null) { if (result == null) {
BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id); BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
return; return;
} }

View file

@ -1,7 +1,5 @@
package ru.bclib.registry; package ru.bclib.registry;
import java.util.function.Supplier;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
@ -32,26 +30,18 @@ public class BaseBlockEntities {
public static void register() {} public static void register() {}
public static Block[] getChests() { public static Block[] getChests() {
return BaseRegistry.getRegisteredBlocks().values().stream() return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
} }
public static Block[] getBarrels() { public static Block[] getBarrels() {
return BaseRegistry.getRegisteredBlocks().values().stream() return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
} }
public static Block[] getSigns() { public static Block[] getSigns() {
return BaseRegistry.getRegisteredBlocks().values().stream() return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
} }
public static Block[] getFurnaces() { public static Block[] getFurnaces() {
return BaseRegistry.getRegisteredBlocks().values().stream() return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock)
.map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
} }
} }

View file

@ -1,11 +1,7 @@
package ru.bclib.registry; package ru.bclib.registry;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -14,6 +10,9 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import java.util.List;
import java.util.Map;
public abstract class BaseRegistry<T> { public abstract class BaseRegistry<T> {
private static final List<BaseRegistry<?>> REGISTRIES = Lists.newArrayList(); private static final List<BaseRegistry<?>> REGISTRIES = Lists.newArrayList();

View file

@ -29,7 +29,8 @@ public abstract class BlocksRegistry extends BaseRegistry<Block> {
Properties item = makeItemSettings().stacksTo(maxCount); Properties item = makeItemSettings().stacksTo(maxCount);
if (placeOnWater) { if (placeOnWater) {
registerBlockItem(id, new WaterLilyBlockItem(block, item)); registerBlockItem(id, new WaterLilyBlockItem(block, item));
} else { }
else {
registerBlockItem(id, new BlockItem(block, item)); registerBlockItem(id, new BlockItem(block, item));
} }
if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance().get(block).getBurnChance() == 0) { if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance().get(block).getBurnChance() == 0) {

View file

@ -55,13 +55,17 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
if (item instanceof ShovelItem) { if (item instanceof ShovelItem) {
TagHelper.addTag((Tag.Named<Item>) FabricToolTags.SHOVELS, item); TagHelper.addTag((Tag.Named<Item>) FabricToolTags.SHOVELS, item);
} else if (item instanceof SwordItem) { }
else if (item instanceof SwordItem) {
TagHelper.addTag((Tag.Named<Item>) FabricToolTags.SWORDS, item); TagHelper.addTag((Tag.Named<Item>) FabricToolTags.SWORDS, item);
} else if (item instanceof BasePickaxeItem) { }
else if (item instanceof BasePickaxeItem) {
TagHelper.addTag((Tag.Named<Item>) FabricToolTags.PICKAXES, item); TagHelper.addTag((Tag.Named<Item>) FabricToolTags.PICKAXES, item);
} else if (item instanceof BaseAxeItem) { }
else if (item instanceof BaseAxeItem) {
TagHelper.addTag((Tag.Named<Item>) FabricToolTags.AXES, item); TagHelper.addTag((Tag.Named<Item>) FabricToolTags.AXES, item);
} else if (item instanceof BaseHoeItem) { }
else if (item instanceof BaseHoeItem) {
TagHelper.addTag((Tag.Named<Item>) FabricToolTags.HOES, item); TagHelper.addTag((Tag.Named<Item>) FabricToolTags.HOES, item);
} }
@ -85,7 +89,7 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
public Item registerFood(String name, int hunger, float saturation, MobEffectInstance... effects) { public Item registerFood(String name, int hunger, float saturation, MobEffectInstance... effects) {
FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation); FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation);
for (MobEffectInstance effect: effects) { for (MobEffectInstance effect : effects) {
builder.effect(effect, 1F); builder.effect(effect, 1F);
} }
return registerFood(name, builder.build()); return registerFood(name, builder.build());

View file

@ -1,12 +1,12 @@
package ru.bclib.sdf; package ru.bclib.sdf;
import java.util.Map;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import java.util.Map;
public class PosInfo implements Comparable<PosInfo> { public class PosInfo implements Comparable<PosInfo> {
private static final BlockState AIR = Blocks.AIR.defaultBlockState(); private static final BlockState AIR = Blocks.AIR.defaultBlockState();
private final Map<BlockPos, PosInfo> blocks; private final Map<BlockPos, PosInfo> blocks;

View file

@ -1,16 +1,8 @@
package ru.bclib.sdf; package ru.bclib.sdf;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -20,6 +12,13 @@ import net.minecraft.world.phys.AABB;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.bclib.world.structures.StructureWorld; import ru.bclib.world.structures.StructureWorld;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
public abstract class SDF { public abstract class SDF {
private List<Function<PosInfo, BlockState>> postProcesses = Lists.newArrayList(); private List<Function<PosInfo, BlockState>> postProcesses = Lists.newArrayList();
private Function<BlockState, Boolean> canReplace = (state) -> { private Function<BlockState, Boolean> canReplace = (state) -> {
@ -52,8 +51,8 @@ public abstract class SDF {
MutableBlockPos bPos = new MutableBlockPos(); MutableBlockPos bPos = new MutableBlockPos();
while (run) { while (run) {
for (BlockPos center: ends) { for (BlockPos center : ends) {
for (Direction dir: Direction.values()) { for (Direction dir : Direction.values()) {
bPos.set(center).move(dir); bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start); BlockPos wpos = bPos.offset(start);
@ -164,8 +163,8 @@ public abstract class SDF {
MutableBlockPos bPos = new MutableBlockPos(); MutableBlockPos bPos = new MutableBlockPos();
while (run) { while (run) {
for (BlockPos center: ends) { for (BlockPos center : ends) {
for (Direction dir: Direction.values()) { for (Direction dir : Direction.values()) {
bPos.set(center).move(dir); bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start); BlockPos wpos = bPos.offset(start);
BlockState state = world.getBlockState(wpos); BlockState state = world.getBlockState(wpos);
@ -227,8 +226,8 @@ public abstract class SDF {
MutableBlockPos bPos = new MutableBlockPos(); MutableBlockPos bPos = new MutableBlockPos();
while (run) { while (run) {
for (BlockPos center: ends) { for (BlockPos center : ends) {
for (Direction dir: Direction.values()) { for (Direction dir : Direction.values()) {
bPos.set(center).move(dir); bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start); BlockPos wpos = bPos.offset(start);
@ -284,8 +283,8 @@ public abstract class SDF {
MutableBlockPos bPos = new MutableBlockPos(); MutableBlockPos bPos = new MutableBlockPos();
while (run) { while (run) {
for (BlockPos center: ends) { for (BlockPos center : ends) {
for (Direction dir: Direction.values()) { for (Direction dir : Direction.values()) {
bPos.set(center).move(dir); bPos.set(center).move(dir);
BlockPos wpos = bPos.offset(start); BlockPos wpos = bPos.offset(start);
BlockState state = world.getBlockState(wpos); BlockState state = world.getBlockState(wpos);

View file

@ -27,7 +27,8 @@ public abstract class SDFBinary extends SDF {
public BlockState getBlockState(BlockPos pos) { public BlockState getBlockState(BlockPos pos) {
if (firstValue) { if (firstValue) {
return sourceA.getBlockState(pos); return sourceA.getBlockState(pos);
} else { }
else {
return sourceB.getBlockState(pos); return sourceB.getBlockState(pos);
} }
} }

Some files were not shown because too many files have changed in this diff Show more