diff --git a/gradle.properties b/gradle.properties index a65a9b79..6a32f158 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings= 6 loader_version= 0.11.6 # Mod Properties -mod_version = 0.2.0 +mod_version = 0.2.1 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index e3bbee16..e0936be0 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -33,7 +33,7 @@ public class BCLib implements ModInitializer { public static boolean isClient() { return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT; } - + public static ResourceLocation makeID(String path) { return new ResourceLocation(MOD_ID, path); } diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 0a1cb7b5..a63db6fd 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -1,10 +1,6 @@ package ru.bclib.api; -import java.util.HashMap; -import java.util.Random; - import com.google.common.collect.Maps; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; 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.world.biomes.BCLBiome; +import java.util.HashMap; +import java.util.Random; + 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. @@ -33,6 +32,7 @@ public class BiomeAPI { /** * Initialize registry for current server. + * * @param server - {@link MinecraftServer} */ 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}). + * * @param biome - {@link BCLBiome}. */ public static void addNetherBiomeToFabricApi(BCLBiome biome) { ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); Random random = new Random(biome.getID().toString().hashCode()); - 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) - ); + 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)); InternalBiomeData.addNetherBiome(key, parameters); } /** * Adds {@link BCLBiome} to FabricAPI biomes as an End land biome (generating on islands). + * * @param biome - {@link BCLBiome}. */ 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). + * * @param biome - {@link BCLBiome}. */ 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. + * * @param biome - {@link Biome} from world. * @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. + * * @param biome - {@link Biome} from client world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -116,6 +115,7 @@ public class BiomeAPI { /** * Get biome {@link ResourceLocation} from given {@link Biome}. + * * @param biome - {@link Biome} from server world. * @return biome {@link ResourceLocation}. */ @@ -123,9 +123,10 @@ public class BiomeAPI { ResourceLocation id = biomeRegistry.getKey(biome); return id == null ? EMPTY_BIOME.getID() : id; } - + /** * Get {@link BCLBiome} from given {@link ResourceLocation}. + * * @param biomeID - biome {@link ResourceLocation}. * @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}. + * * @param biome - {@link BCLBiome}. * @return {@link Biome}. */ @@ -149,6 +151,7 @@ public class BiomeAPI { /** * Check if biome with {@link ResourceLocation} exists in API registry. + * * @param biomeID - biome {@link ResourceLocation}. * @return {@code true} if biome exists in API registry and {@code false} if not. */ diff --git a/src/main/java/ru/bclib/api/BonemealAPI.java b/src/main/java/ru/bclib/api/BonemealAPI.java index 4e9a200f..56276fd3 100644 --- a/src/main/java/ru/bclib/api/BonemealAPI.java +++ b/src/main/java/ru/bclib/api/BonemealAPI.java @@ -1,16 +1,15 @@ 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.Random; 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 { private static final Map>> WATER_GRASS_BIOMES = Maps.newHashMap(); private static final Map>> LAND_GRASS_BIOMES = Maps.newHashMap(); @@ -27,13 +26,13 @@ public class BonemealAPI { } public static void addLandGrass(Block plant, Block... terrain) { - for (Block block: terrain) { + for (Block block : terrain) { addLandGrass(block, plant, 1F); } } public static void addLandGrass(ResourceLocation biome, Block plant, Block... terrain) { - for (Block block: terrain) { + for (Block block : terrain) { addLandGrass(biome, block, plant, 1F); } } @@ -62,13 +61,13 @@ public class BonemealAPI { } public static void addWaterGrass(Block plant, Block... terrain) { - for (Block block: terrain) { + for (Block block : terrain) { addWaterGrass(block, plant, 1F); } } public static void addWaterGrass(ResourceLocation biome, Block plant, Block... terrain) { - for (Block block: terrain) { + for (Block block : terrain) { addWaterGrass(biome, block, plant, 1F); } } diff --git a/src/main/java/ru/bclib/api/DataFixerAPI.java b/src/main/java/ru/bclib/api/DataFixerAPI.java index cf644539..e2eaff5b 100644 --- a/src/main/java/ru/bclib/api/DataFixerAPI.java +++ b/src/main/java/ru/bclib/api/DataFixerAPI.java @@ -1,5 +1,15 @@ 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.DataOutputStream; import java.io.File; @@ -8,17 +18,6 @@ import java.util.List; import java.util.Locale; 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 { private static final Map REPLACEMENT = Maps.newHashMap(); private static final Map FIX_VERSIONS = Maps.newHashMap(); @@ -31,7 +30,7 @@ public class DataFixerAPI { boolean shoudFix = false; Collection mods = FabricLoader.getInstance().getAllMods(); - for (ModContainer mod: mods) { + for (ModContainer mod : mods) { String name = mod.getMetadata().getId(); int preVersion = WorldDataAPI.getIntModVersion(name); int version = getModVersion(mod.getMetadata().getVersion().toString()); @@ -39,7 +38,8 @@ public class DataFixerAPI { int fixVersion = FIX_VERSIONS.getOrDefault(name, version); shoudFix |= fixVersion < version && fixVersion >= preVersion; } - }; + } + ; if (!shoudFix) { 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. - * @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 result - {@link String} new block name; - * @param names - array of {@link String}, old block names to convert. + * @param result - {@link String} new block name; + * @param names - array of {@link String}, old block names to convert. */ protected static void addFix(String modID, String modVersion, String result, String... names) { FIX_VERSIONS.put(modID, getModVersion(modVersion)); - for (String name: names) { + for (String name : names) { REPLACEMENT.put(name, result); } } @@ -106,7 +107,7 @@ public class DataFixerAPI { if (list == null) { list = Lists.newArrayList(); } - for (File file: dir.listFiles()) { + for (File file : dir.listFiles()) { if (file.isDirectory()) { getAllRegions(file, list); } @@ -119,6 +120,7 @@ public class DataFixerAPI { /** * Get mod version from string. String should be in format: %d.%d.%d + * * @param version - {@link String} 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 + * * @param version - mod version in integer form. * @return {@link String} mod version. */ diff --git a/src/main/java/ru/bclib/api/ModIntegrationAPI.java b/src/main/java/ru/bclib/api/ModIntegrationAPI.java index eff311dc..5c6b186c 100644 --- a/src/main/java/ru/bclib/api/ModIntegrationAPI.java +++ b/src/main/java/ru/bclib/api/ModIntegrationAPI.java @@ -1,16 +1,16 @@ package ru.bclib.api; -import java.util.List; - import com.google.common.collect.Lists; - import ru.bclib.integration.ModIntegration; +import java.util.List; + public class ModIntegrationAPI { private static final List INTEGRATIONS = Lists.newArrayList(); /** * Registers mod integration + * * @param integration * @return */ @@ -21,6 +21,7 @@ public class ModIntegrationAPI { /** * Get all registered mod integrations. + * * @return {@link List} of {@link ModIntegration}. */ public static List getIntegrations() { diff --git a/src/main/java/ru/bclib/api/TagAPI.java b/src/main/java/ru/bclib/api/TagAPI.java index 8a4accba..e3491e2a 100644 --- a/src/main/java/ru/bclib/api/TagAPI.java +++ b/src/main/java/ru/bclib/api/TagAPI.java @@ -1,7 +1,5 @@ package ru.bclib.api; -import java.util.function.Supplier; - import net.fabricmc.fabric.api.tag.TagRegistry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; @@ -16,6 +14,8 @@ import net.minecraft.world.level.block.Blocks; import ru.bclib.BCLib; import ru.bclib.util.TagHelper; +import java.util.function.Supplier; + public class TagAPI { // Block Tags public static final Tag.Named BOOKSHELVES = makeCommonBlockTag("bookshelves"); @@ -34,22 +34,24 @@ public class TagAPI { public static final Tag.Named IRON_INGOTS = makeCommonItemTag("iron_ingots"); public static final Tag.Named FURNACES = makeCommonItemTag("furnaces"); public final static Tag.Named HAMMERS = makeItemTag("fabric", "hammers"); - + /** * Get or create {@link Tag.Named}. + * * @param containerSupplier - {@link TagCollection} {@link Supplier} tag collection; - * @param id - {@link ResourceLocation} tag id. + * @param id - {@link ResourceLocation} tag id. * @return {@link Tag.Named}. */ public static Tag.Named makeTag(Supplier> containerSupplier, ResourceLocation id) { Tag tag = containerSupplier.get().getTag(id); return tag == null ? TagRegistry.create(id, containerSupplier) : (Named) tag; } - + /** * Get or create {@link Block} {@link Tag.Named} with mod namespace. + * * @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}. */ public static Tag.Named makeBlockTag(String modID, String name) { @@ -58,8 +60,9 @@ public class TagAPI { /** * Get or create {@link Item} {@link Tag.Named} with mod namespace. + * * @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}. */ public static Tag.Named makeItemTag(String modID, String name) { @@ -68,9 +71,10 @@ public class TagAPI { /** * Get or create {@link Block} {@link Tag.Named}. - * @see Fabric Wiki (Tags) + * * @param name - {@link String} tag name. * @return {@link Block} {@link Tag.Named}. + * @see Fabric Wiki (Tags) */ public static Tag.Named makeCommonBlockTag(String name) { return makeTag(BlockTags::getAllTags, new ResourceLocation("c", name)); @@ -78,9 +82,10 @@ public class TagAPI { /** * Get or create {@link Item} {@link Tag.Named}. - * @see Fabric Wiki (Tags) + * * @param name - {@link String} tag name. * @return {@link Item} {@link Tag.Named}. + * @see Fabric Wiki (Tags) */ public static Tag.Named makeCommonItemTag(String 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}. + * * @param name - {@link String} tag name. * @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. + * * @param block - {@link 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. + * * @param block - {@link Block}. */ public static void addEndGround(Block block) { diff --git a/src/main/java/ru/bclib/api/WorldDataAPI.java b/src/main/java/ru/bclib/api/WorldDataAPI.java index 6927c9ed..842699c5 100644 --- a/src/main/java/ru/bclib/api/WorldDataAPI.java +++ b/src/main/java/ru/bclib/api/WorldDataAPI.java @@ -1,20 +1,19 @@ 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.IOException; import java.util.List; import java.util.Map; 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 { private static final Map TAGS = Maps.newHashMap(); private static final List MODS = Lists.newArrayList(); @@ -52,6 +51,7 @@ public class WorldDataAPI { /** * Register mod cache, world cache is located in world data folder. + * * @param modID - {@link 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. + * * @param modID - {@link String} modID. * @return {@link CompoundTag} */ @@ -74,13 +75,14 @@ public class WorldDataAPI { /** * Get {@link CompoundTag} with specified path from mod cache in world data folder. + * * @param modID - {@link String} path to tag, dot-separated. * @return {@link CompoundTag} */ public static CompoundTag getCompoundTag(String modID, String path) { String[] parts = path.split("\\."); CompoundTag tag = getRootTag(modID); - for (String part: parts) { + for (String part : parts) { if (tag.contains(part)) { tag = tag.getCompound(part); } @@ -95,6 +97,7 @@ public class WorldDataAPI { /** * Forces mod cache file to be saved. + * * @param modID {@link String} mod ID. */ public static void saveFile(String modID) { @@ -108,6 +111,7 @@ public class WorldDataAPI { /** * Get stored mod version (only for mods with registered cache). + * * @return {@link String} mod version. */ 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). + * * @return {@code int} mod version. */ public static int getIntModVersion(String modID) { diff --git a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java index c181a7a7..571fb407 100644 --- a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java @@ -26,25 +26,25 @@ import ru.bclib.registry.BaseBlockEntities; public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { private NonNullList inventory; private int viewerCount; - + private BaseBarrelBlockEntity(BlockEntityType type, BlockPos blockPos, BlockState blockState) { super(type, blockPos, blockState); this.inventory = NonNullList.withSize(27, ItemStack.EMPTY); } - + public BaseBarrelBlockEntity(BlockPos blockPos, BlockState blockState) { this(BaseBlockEntities.BARREL, blockPos, blockState); } - + public CompoundTag save(CompoundTag tag) { super.save(tag); if (!this.trySaveLootTable(tag)) { ContainerHelper.saveAllItems(tag, this.inventory); } - + return tag; } - + public void load(CompoundTag tag) { super.load(tag); this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); @@ -52,56 +52,57 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { ContainerHelper.loadAllItems(tag, this.inventory); } } - + public int getContainerSize() { return 27; } - + protected NonNullList getItems() { return this.inventory; } - + protected void setItems(NonNullList list) { this.inventory = list; } - + protected Component getDefaultName() { return new TranslatableComponent("container.barrel"); } - + protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) { return ChestMenu.threeRows(syncId, playerInventory, this); } - + public void startOpen(Player player) { if (!player.isSpectator()) { if (viewerCount < 0) { viewerCount = 0; } - + ++viewerCount; BlockState blockState = this.getBlockState(); if (!blockState.getValue(BarrelBlock.OPEN)) { playSound(blockState, SoundEvents.BARREL_OPEN); setOpen(blockState, true); } - + if (level != null) { scheduleUpdate(); } } } - + private void scheduleUpdate() { level.getBlockTicks().scheduleTick(getBlockPos(), getBlockState().getBlock(), 5); } - + public void tick() { if (level != null) { viewerCount = ChestBlockEntity.getOpenCount(level, worldPosition); if (viewerCount > 0) { scheduleUpdate(); - } else { + } + else { BlockState blockState = getBlockState(); if (!(blockState.getBlock() instanceof BaseBarrelBlock)) { setRemoved(); @@ -114,27 +115,26 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { } } } - + public void stopOpen(Player player) { if (!player.isSpectator()) { --this.viewerCount; } } - + private void setOpen(BlockState state, boolean open) { if (level != null) { level.setBlock(this.getBlockPos(), state.setValue(BarrelBlock.OPEN, open), 3); } } - + private void playSound(BlockState blockState, SoundEvent soundEvent) { if (level != null) { Vec3i vec3i = blockState.getValue(BarrelBlock.FACING).getNormal(); 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 f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D; - level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, - this.level.random.nextFloat() * 0.1F + 0.9F); + level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F); } } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/blockentities/BaseFurnaceBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseFurnaceBlockEntity.java index fa681007..f6d2f469 100644 --- a/src/main/java/ru/bclib/blockentities/BaseFurnaceBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseFurnaceBlockEntity.java @@ -15,11 +15,11 @@ public class BaseFurnaceBlockEntity extends AbstractFurnaceBlockEntity { public BaseFurnaceBlockEntity(BlockPos blockPos, BlockState blockState) { super(BaseBlockEntities.FURNACE, blockPos, blockState, RecipeType.SMELTING); } - + protected Component getDefaultName() { return new TranslatableComponent("container.furnace"); } - + protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) { return new FurnaceMenu(syncId, playerInventory, this, this.dataAccess); } diff --git a/src/main/java/ru/bclib/blockentities/BaseSignBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseSignBlockEntity.java index 64a9b75f..a2ebfb31 100644 --- a/src/main/java/ru/bclib/blockentities/BaseSignBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseSignBlockEntity.java @@ -10,7 +10,7 @@ public class BaseSignBlockEntity extends SignBlockEntity { public BaseSignBlockEntity(BlockPos blockPos, BlockState blockState) { super(blockPos, blockState); } - + @Override public BlockEntityType getType() { return BaseBlockEntities.SIGN; diff --git a/src/main/java/ru/bclib/blockentities/DynamicBlockEntityType.java b/src/main/java/ru/bclib/blockentities/DynamicBlockEntityType.java index 2f992c86..ad656251 100644 --- a/src/main/java/ru/bclib/blockentities/DynamicBlockEntityType.java +++ b/src/main/java/ru/bclib/blockentities/DynamicBlockEntityType.java @@ -1,11 +1,6 @@ package ru.bclib.blockentities; -import java.util.Collections; -import java.util.Set; -import java.util.function.Supplier; - import com.google.common.collect.Sets; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -13,33 +8,36 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; -public class DynamicBlockEntityType extends BlockEntityType { +import java.util.Collections; +import java.util.Set; +public class DynamicBlockEntityType extends BlockEntityType { + private final Set validBlocks = Sets.newHashSet(); private final BlockEntitySupplier factory; - + public DynamicBlockEntityType(BlockEntitySupplier supplier) { super(null, Collections.emptySet(), null); this.factory = supplier; } - + @Override - @Nullable public T create(BlockPos blockPos, BlockState blockState) { + @Nullable + public T create(BlockPos blockPos, BlockState blockState) { return factory.create(blockPos, blockState); } - + @Override public boolean isValid(BlockState blockState) { return validBlocks.contains(blockState.getBlock()); } - + public void registerBlock(Block block) { validBlocks.add(block); } - + @FunctionalInterface - public - interface BlockEntitySupplier { + public interface BlockEntitySupplier { T create(BlockPos blockPos, BlockState blockState); } } diff --git a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java index 5dafc0d5..192624c2 100644 --- a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java @@ -1,14 +1,7 @@ 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.Maps; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -25,15 +18,20 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; 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 static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION; - + public BaseAnvilBlock(MaterialColor color) { super(FabricBlockSettings.copyOf(Blocks.ANVIL).mapColor(color)); } @@ -43,7 +41,7 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro super.createBlockStateDefinition(builder); builder.add(DESTRUCTION); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -52,7 +50,7 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro dropStack.getOrCreateTag().putInt(BaseAnvilItem.DESTRUCTION, destruction); return Lists.newArrayList(dropStack); } - + protected String getTop(ResourceLocation blockId, String block) { if (block.contains("item")) { return blockId.getPath() + "_top_0"; @@ -60,16 +58,16 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro char last = block.charAt(block.length() - 1); return blockId.getPath() + "_top_" + last; } - + @Override public abstract Item asItem(); - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -82,7 +80,7 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_ANVIL, textures); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { diff --git a/src/main/java/ru/bclib/blocks/BaseAttachedBlock.java b/src/main/java/ru/bclib/blocks/BaseAttachedBlock.java index ecf12d48..a0e2b1af 100644 --- a/src/main/java/ru/bclib/blocks/BaseAttachedBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseAttachedBlock.java @@ -45,14 +45,14 @@ public abstract class BaseAttachedBlock extends BaseBlockNotFull { } return null; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = state.getValue(FACING); BlockPos blockPos = pos.relative(direction.getOpposite()); return canSupportCenter(world, blockPos, direction) || world.getBlockState(blockPos).is(BlockTags.LEAVES); } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { @@ -62,13 +62,13 @@ public abstract class BaseAttachedBlock extends BaseBlockNotFull { return state; } } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } - + @Override public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); diff --git a/src/main/java/ru/bclib/blocks/BaseBarkBlock.java b/src/main/java/ru/bclib/blocks/BaseBarkBlock.java index 743ff0af..7adca093 100644 --- a/src/main/java/ru/bclib/blocks/BaseBarkBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBarkBlock.java @@ -1,23 +1,23 @@ package ru.bclib.blocks; -import java.util.Optional; - import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.PatternsHelper; +import java.util.Optional; + public class BaseBarkBlock extends BaseRotatedPillarBlock { public BaseBarkBlock(Properties settings) { super(settings); } - + @Override protected Optional createBlockPattern(ResourceLocation blockId) { blockId = Registry.BLOCK.getKey(this); return PatternsHelper.createJson(BasePatterns.BLOCK_BASE, replacePath(blockId)); } - + private ResourceLocation replacePath(ResourceLocation blockId) { String newPath = blockId.getPath().replace("_bark", "_log_side"); return new ResourceLocation(blockId.getNamespace(), newPath); diff --git a/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java b/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java index b36f8843..cde83356 100644 --- a/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.player.Player; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BarrelBlock; 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.storage.loot.LootContext; import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; import ru.bclib.blockentities.BaseBarrelBlockEntity; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; @@ -40,16 +33,21 @@ import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; 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 BaseBarrelBlock(Block source) { super(FabricBlockSettings.copyOf(source).noOcclusion()); } - + @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return BaseBlockEntities.BARREL.create(blockPos, blockState); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -57,24 +55,24 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider { drop.add(new ItemStack(this.asItem())); return drop; } - + @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, - BlockHitResult hit) { + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (world.isClientSide) { return InteractionResult.SUCCESS; - } else { + } + else { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BaseBarrelBlockEntity) { player.openMenu((BaseBarrelBlockEntity) blockEntity); player.awardStat(Stats.OPEN_BARREL); PiglinAi.angerNearbyPiglins(player, true); } - + return InteractionResult.CONSUME; } } - + @Override public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { BlockEntity blockEntity = world.getBlockEntity(pos); @@ -82,15 +80,14 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider { ((BaseBarrelBlockEntity) blockEntity).tick(); } } - + @Override public RenderShape getRenderShape(BlockState state) { return RenderShape.MODEL; } - + @Override - public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, - ItemStack itemStack) { + public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { if (itemStack.hasCustomHoverName()) { BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof BaseBarrelBlockEntity) { @@ -98,41 +95,52 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider { } } } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern; if (blockState.getValue(OPEN)) { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BARREL_OPEN, blockId); - } else { + } + else { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BOTTOM_TOP, blockId); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { String open = blockState.getValue(OPEN) ? "_open" : ""; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + open); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + open); registerBlockModel(stateId, modelId, blockState, modelCache); Direction facing = blockState.getValue(FACING); BlockModelRotation rotation = BlockModelRotation.X0_Y0; switch (facing) { - case NORTH: rotation = BlockModelRotation.X90_Y0; break; - case EAST: rotation = BlockModelRotation.X90_Y90; break; - case SOUTH: rotation = BlockModelRotation.X90_Y180; break; - case WEST: rotation = BlockModelRotation.X90_Y270; break; - case DOWN: rotation = BlockModelRotation.X180_Y0; break; - default: break; + case NORTH: + rotation = BlockModelRotation.X90_Y0; + break; + case EAST: + rotation = BlockModelRotation.X90_Y90; + 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); } diff --git a/src/main/java/ru/bclib/blocks/BaseBlock.java b/src/main/java/ru/bclib/blocks/BaseBlock.java index 97878a79..bfb52a10 100644 --- a/src/main/java/ru/bclib/blocks/BaseBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBlock.java @@ -1,8 +1,5 @@ package ru.bclib.blocks; -import java.util.Collections; -import java.util.List; - import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -11,17 +8,20 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import ru.bclib.client.models.BlockModelProvider; +import java.util.Collections; +import java.util.List; + public class BaseBlock extends Block implements BlockModelProvider { public BaseBlock(Properties settings) { super(settings); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); diff --git a/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java b/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java index 6d1a0a38..0ddc700c 100644 --- a/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java +++ b/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java @@ -6,19 +6,19 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; public class BaseBlockNotFull extends BaseBlock { - + public BaseBlockNotFull(Properties settings) { super(settings); } - + public boolean canSuffocate(BlockState state, BlockGetter view, BlockPos pos) { return false; } - + public boolean isSimpleFullBlock(BlockState state, BlockGetter view, BlockPos pos) { return false; } - + public boolean allowsSpawning(BlockState state, BlockGetter view, BlockPos pos, EntityType type) { return false; } diff --git a/src/main/java/ru/bclib/blocks/BaseBlockWithEntity.java b/src/main/java/ru/bclib/blocks/BaseBlockWithEntity.java index 718a58f7..26b9cf22 100644 --- a/src/main/java/ru/bclib/blocks/BaseBlockWithEntity.java +++ b/src/main/java/ru/bclib/blocks/BaseBlockWithEntity.java @@ -1,26 +1,25 @@ package ru.bclib.blocks; -import java.util.Collections; -import java.util.List; - import net.minecraft.core.BlockPos; 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.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import java.util.Collections; +import java.util.List; + public class BaseBlockWithEntity extends BaseEntityBlock { public BaseBlockWithEntity(Properties settings) { super(settings); } - + @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return null; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { diff --git a/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java b/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java index a1b68b1d..68999421 100644 --- a/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java @@ -1,11 +1,5 @@ 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.Environment; 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.storage.loot.LootContext; 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.ModelsHelper; import ru.bclib.client.models.PatternsHelper; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + public class BaseBookshelfBlock extends BaseBlock { public BaseBookshelfBlock(Block source) { super(FabricBlockSettings.copyOf(source)); @@ -39,14 +38,14 @@ public class BaseBookshelfBlock extends BaseBlock { } return Collections.singletonList(new ItemStack(Items.BOOK, 3)); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_BOOKSHELF, replacePath(blockId)); return ModelsHelper.fromPattern(pattern); } - + private ResourceLocation replacePath(ResourceLocation blockId) { String newPath = blockId.getPath().replace("_bookshelf", ""); return new ResourceLocation(blockId.getNamespace(), newPath); diff --git a/src/main/java/ru/bclib/blocks/BaseButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseButtonBlock.java index 5f8642ce..5fbd0d2c 100644 --- a/src/main/java/ru/bclib/blocks/BaseButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseButtonBlock.java @@ -1,12 +1,5 @@ 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.Environment; import net.minecraft.client.renderer.block.model.BlockModel; @@ -20,26 +13,32 @@ import net.minecraft.world.level.block.ButtonBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.AttachFace; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { - + private final Block parent; - + protected BaseButtonBlock(Block parent, Properties properties, boolean sensitive) { super(sensitive, properties); this.parent = parent; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { @@ -47,38 +46,53 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP Optional pattern = PatternsHelper.createJson(BasePatterns.ITEM_BUTTON, parentId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { ResourceLocation parentId = Registry.BLOCK.getKey(parent); - Optional pattern = blockState.getValue(POWERED) ? - PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) : - PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId); + Optional pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { String powered = blockState.getValue(POWERED) ? "_powered" : ""; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + powered); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + powered); registerBlockModel(stateId, modelId, blockState, modelCache); AttachFace face = blockState.getValue(FACE); boolean isCeiling = face == AttachFace.CEILING; int x = 0, y = 0; switch (face) { - case CEILING: x = 180; break; - case WALL: x = 90; break; - default: break; + case CEILING: + x = 180; + break; + case WALL: + x = 90; + break; + default: + break; } switch (blockState.getValue(FACING)) { - case NORTH: if (isCeiling) { y = 180; } break; - case EAST: y = isCeiling ? 270 : 90; break; - case SOUTH: if(!isCeiling) { y = 180; } break; - case WEST: y = isCeiling ? 90 : 270; break; - default: break; + case NORTH: + if (isCeiling) { + y = 180; + } + 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); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL); diff --git a/src/main/java/ru/bclib/blocks/BaseChainBlock.java b/src/main/java/ru/bclib/blocks/BaseChainBlock.java index c2a14fe3..4b3cc0ef 100644 --- a/src/main/java/ru/bclib/blocks/BaseChainBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseChainBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -27,40 +21,44 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; 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 BaseChainBlock(MaterialColor color) { super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color)); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return ModelsHelper.createItemModel(blockId); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CHAIN, blockId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { Direction.Axis axis = blockState.getValue(AXIS); - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath()); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath()); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createRotatedModel(modelId, axis); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; diff --git a/src/main/java/ru/bclib/blocks/BaseChestBlock.java b/src/main/java/ru/bclib/blocks/BaseChestBlock.java index 2b89b5d2..a38d3b28 100644 --- a/src/main/java/ru/bclib/blocks/BaseChestBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseChestBlock.java @@ -1,30 +1,28 @@ 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.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; 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.ChestBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; import ru.bclib.registry.BaseBlockEntities; +import java.util.List; +import java.util.Optional; + public class BaseChestBlock extends ChestBlock implements BlockModelProvider { private final Block parent; @@ -37,23 +35,22 @@ public class BaseChestBlock extends ChestBlock implements BlockModelProvider { public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return BaseBlockEntities.CHEST.create(blockPos, blockState); } - + @Override @SuppressWarnings("deprecation") - public List getDrops(BlockState state, LootContext.Builder builder) - { + public List getDrops(BlockState state, LootContext.Builder builder) { List drop = super.getDrops(state, builder); drop.add(new ItemStack(this.asItem())); return drop; } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { Optional pattern = PatternsHelper.createJson(BasePatterns.ITEM_CHEST, blockId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { diff --git a/src/main/java/ru/bclib/blocks/BaseComposterBlock.java b/src/main/java/ru/bclib/blocks/BaseComposterBlock.java index faecc6e5..b7735daf 100644 --- a/src/main/java/ru/bclib/blocks/BaseComposterBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseComposterBlock.java @@ -1,12 +1,5 @@ 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.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -18,56 +11,63 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; 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 BaseComposterBlock(Block source) { super(FabricBlockSettings.copyOf(source)); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this.asItem())); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_COMPOSTER, blockId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath()); registerBlockModel(stateId, modelId, blockState, modelCache); - + MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition); LEVEL.getPossibleValues().forEach(level -> { if (level > 0) { ResourceLocation contentId; if (level > 7) { contentId = new ResourceLocation("block/composter_contents_ready"); - } else { + } + else { contentId = new ResourceLocation("block/composter_contents" + level); } builder.part(contentId).setCondition(state -> state.getValue(LEVEL).equals(level)).add(); } }); builder.part(modelId).add(); - + return builder.build(); } } diff --git a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java index 570758fe..f4718e40 100644 --- a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java @@ -1,12 +1,5 @@ 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.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -17,34 +10,41 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.CraftingTableBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 BaseCraftingTableBlock(Block source) { super(FabricBlockSettings.copyOf(source)); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this.asItem())); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { String blockName = blockId.getPath(); Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SIDED, new HashMap() { private static final long serialVersionUID = 1L; + { put("%modid%", blockId.getNamespace()); put("%particle%", blockName + "_front"); diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index e395d338..ec0ce04b 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -1,11 +1,6 @@ package ru.bclib.blocks; -import java.util.Collections; -import java.util.List; -import java.util.Random; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.MHelper; +import java.util.Collections; +import java.util.List; +import java.util.Random; + public class BaseCropBlock extends BasePlantBlock { private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); @@ -39,12 +38,7 @@ public class BaseCropBlock extends BasePlantBlock { private final Item drop; public BaseCropBlock(Item drop, Block... terrain) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.HOES) - .breakByHand(true) - .sound(SoundType.GRASS) - .randomTicks() - .noCollission()); + super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission()); this.drop = drop; this.terrain = terrain; this.registerDefaultState(defaultBlockState().setValue(AGE, 0)); @@ -57,7 +51,7 @@ public class BaseCropBlock extends BasePlantBlock { @Override protected boolean isTerrain(BlockState state) { - for (Block block: terrain) { + for (Block block : terrain) { if (state.is(block)) { return true; } @@ -106,7 +100,7 @@ public class BaseCropBlock extends BasePlantBlock { public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return state.getValue(AGE) < 3; } - + @Override @SuppressWarnings("deprecation") public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { diff --git a/src/main/java/ru/bclib/blocks/BaseDoorBlock.java b/src/main/java/ru/bclib/blocks/BaseDoorBlock.java index 1c2c6245..c903f642 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoorBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoorBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.DoubleBlockHalf; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -30,25 +24,29 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; 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 BaseDoorBlock(Block source) { super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { if (state.getValue(HALF) == DoubleBlockHalf.LOWER) return Collections.singletonList(new ItemStack(this.asItem())); - else - return Collections.emptyList(); + else return Collections.emptyList(); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { @@ -64,11 +62,12 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel case TOP: pattern = PatternsHelper.createJson(BasePatterns.BLOCK_DOOR_TOP, resourceLocation); break; - default: break; + default: + break; } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { @@ -81,23 +80,27 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel case EAST: if (hinge && open) { rotation = BlockModelRotation.X0_Y90; - } else if (open) { + } + else if (open) { rotation = BlockModelRotation.X0_Y270; } break; case SOUTH: if (!hinge && !open || hinge && !open) { rotation = BlockModelRotation.X0_Y90; - } else if (hinge) { + } + else if (hinge) { rotation = BlockModelRotation.X0_Y180; } break; case WEST: if (!hinge && !open || hinge && !open) { rotation = BlockModelRotation.X0_Y180; - } else if (hinge) { + } + else if (hinge) { rotation = BlockModelRotation.X0_Y270; - } else { + } + else { rotation = BlockModelRotation.X0_Y90; } break; @@ -105,17 +108,17 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel default: if (!hinge && !open || hinge && !open) { rotation = BlockModelRotation.X0_Y270; - } else if (!hinge) { + } + else if (!hinge) { rotation = BlockModelRotation.X0_Y180; } break; } - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_" + doorType); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + doorType); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); } - + protected DoorType getDoorType(BlockState blockState) { boolean isHinge = isHinge(blockState.getValue(HINGE), blockState.getValue(OPEN)); switch (blockState.getValue(HALF)) { @@ -128,34 +131,30 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel } return DoorType.BOTTOM; } - + private boolean isHinge(DoorHingeSide hingeSide, boolean open) { boolean isHinge = hingeSide == DoorHingeSide.RIGHT; return isHinge && !open || !isHinge && open; } - + protected enum DoorType implements StringRepresentable { - BOTTOM_HINGE("bottom_hinge"), - TOP_HINGE("top_hinge"), - BOTTOM("bottom"), - TOP("top"); - + BOTTOM_HINGE("bottom_hinge"), TOP_HINGE("top_hinge"), BOTTOM("bottom"), TOP("top"); + private final String name; - + DoorType(String name) { this.name = name; } - + public boolean isHinge() { - return this == BOTTOM_HINGE || - this == TOP_HINGE; + return this == BOTTOM_HINGE || this == TOP_HINGE; } - + @Override public String toString() { return getSerializedName(); } - + @Override public String getSerializedName() { return name; diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index 73f0ed6c..05bf1f15 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -1,10 +1,6 @@ package ru.bclib.blocks; -import java.util.List; -import java.util.Random; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; @@ -38,6 +34,9 @@ import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.BlocksHelper; +import java.util.List; +import java.util.Random; + @SuppressWarnings("deprecation") public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { 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 BaseDoublePlantBlock() { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission()); this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); } public BaseDoublePlantBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .lightLevel((state) -> state.getValue(TOP) ? light : 0) - .noCollission()); + super(FabricBlockSettings.of(Material.PLANT).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)); } @@ -67,18 +57,18 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(TOP, ROTATION); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } - + @Override public BlockBehaviour.OffsetType getOffsetType() { return BlockBehaviour.OffsetType.XZ; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); @@ -91,7 +81,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I BlockState up = world.getBlockState(pos.above()); return state.getValue(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getBlock() == this); } - + protected abstract boolean isTerrain(BlockState state); @Override @@ -123,17 +113,17 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } - + @Override public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } - + @Override public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); diff --git a/src/main/java/ru/bclib/blocks/BaseFenceBlock.java b/src/main/java/ru/bclib/blocks/BaseFenceBlock.java index 85adff6e..7c721437 100644 --- a/src/main/java/ru/bclib/blocks/BaseFenceBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseFenceBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; 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 { private final Block parent; @@ -33,13 +32,13 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider { super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { @@ -47,7 +46,7 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider { Optional pattern = PatternsHelper.createJson(BasePatterns.ITEM_FENCE, parentId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -62,27 +61,22 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider { } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { - ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_post"); - ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_side"); + ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post"); + ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side"); registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache); - + MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition); builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add(); - builder.part(sideId).setCondition(state -> state.getValue(EAST)) - .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(WEST)) - .setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); + builder.part(sideId).setCondition(state -> state.getValue(EAST)).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(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); builder.part(postId).add(); - + return builder.build(); } } diff --git a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java index 925a3e45..ac6624ba 100644 --- a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java @@ -41,7 +41,7 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider public BaseFurnaceBlock(Block source) { super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0)); } - + @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return new BaseFurnaceBlockEntity(blockPos, blockState); @@ -55,7 +55,7 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider player.awardStat(Stats.INTERACT_WITH_FURNACE); } } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -69,34 +69,34 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider textures.put("%front%", blockName + "_front_on"); textures.put("%glow%", blockName + "_glow"); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE_LIT, textures); - } else { + } + else { textures.put("%front%", blockName + "_front"); pattern = PatternsHelper.createJson(BasePatterns.BLOCK_FURNACE, textures); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { String lit = blockState.getValue(LIT) ? "_lit" : ""; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + lit); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + lit); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -110,13 +110,13 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider } return drop; } - + @Override @Nullable public BlockEntityTicker getTicker(Level level, BlockState blockState, BlockEntityType blockEntityType) { return createFurnaceTicker(level, blockEntityType, BaseBlockEntities.FURNACE); } - + @Nullable protected static BlockEntityTicker createFurnaceTicker(Level level, BlockEntityType blockEntityType, BlockEntityType blockEntityType2) { return level.isClientSide ? null : createTickerHelper(blockEntityType, blockEntityType2, AbstractFurnaceBlockEntity::serverTick); diff --git a/src/main/java/ru/bclib/blocks/BaseGateBlock.java b/src/main/java/ru/bclib/blocks/BaseGateBlock.java index d765ca2d..7b239a7e 100644 --- a/src/main/java/ru/bclib/blocks/BaseGateBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseGateBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -31,19 +30,19 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -52,23 +51,21 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider ResourceLocation parentId = Registry.BLOCK.getKey(parent); Optional pattern; if (inWall) { - pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : - PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId); - } else { - pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : - PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId); + pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId); + } + else { + pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { boolean inWall = blockState.getValue(IN_WALL); boolean isOpen = blockState.getValue(OPEN); String state = "" + (inWall ? "_wall" : "") + (isOpen ? "_open" : "_closed"); - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + state); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), true, false); } diff --git a/src/main/java/ru/bclib/blocks/BaseLadderBlock.java b/src/main/java/ru/bclib/blocks/BaseLadderBlock.java index 93939d8f..d5020846 100644 --- a/src/main/java/ru/bclib/blocks/BaseLadderBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLadderBlock.java @@ -1,10 +1,5 @@ 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.Environment; 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.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -39,6 +35,9 @@ import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.BlocksHelper; +import java.util.Map; +import java.util.Optional; + @SuppressWarnings("deprecation") public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider { public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; @@ -47,17 +46,17 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B protected static final VoxelShape WEST_SHAPE = Block.box(13.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); protected static final VoxelShape SOUTH_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 3.0D); protected static final VoxelShape NORTH_SHAPE = Block.box(0.0D, 0.0D, 13.0D, 16.0D, 16.0D, 16.0D); - + public BaseLadderBlock(Block block) { super(FabricBlockSettings.copyOf(block).noOcclusion()); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(FACING); stateManager.add(WATERLOGGED); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return switch (state.getValue(FACING)) { @@ -67,32 +66,32 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B default -> NORTH_SHAPE; }; } - + private boolean canPlaceOn(BlockGetter world, BlockPos pos, Direction side) { BlockState blockState = world.getBlockState(pos); return !blockState.isSignalSource() && blockState.isFaceSturdy(world, pos, side); } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = state.getValue(FACING); return canPlaceOn(world, pos.relative(direction.getOpposite()), direction); } - + @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 (facing.getOpposite() == state.getValue(FACING) && !state.canSurvive(world, pos)) { return Blocks.AIR.defaultBlockState(); - } else { + } + else { if (state.getValue(WATERLOGGED)) { world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } - + return super.updateShape(state, facing, neighborState, world, pos, neighborPos); } } - + @Override public BlockState getStateForPlacement(BlockPlaceContext ctx) { BlockState blockState; @@ -102,13 +101,13 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B return null; } } - + blockState = defaultBlockState(); LevelReader worldView = ctx.getLevel(); BlockPos blockPos = ctx.getClickedPos(); FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); Direction[] directions = ctx.getNearestLookingDirections(); - + for (Direction direction : directions) { if (direction.getAxis().isHorizontal()) { blockState = blockState.setValue(FACING, direction.getOpposite()); @@ -117,43 +116,43 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B } } } - + return null; } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } - + @Override public BlockState mirror(BlockState state, Mirror mirror) { return BlocksHelper.mirrorHorizontal(state, mirror, FACING); } - + @Override public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return ModelsHelper.createBlockItem(blockId); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_LADDER, blockId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 4e644f8e..e77d96c5 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -1,10 +1,6 @@ package ru.bclib.blocks; -import java.util.Collections; -import java.util.List; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; @@ -24,38 +20,27 @@ import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.MHelper; +import java.util.Collections; +import java.util.List; + public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped { private final Block sapling; public BaseLeavesBlock(Block sapling, MaterialColor color) { - 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)); + 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)); this.sapling = sapling; } public BaseLeavesBlock(Block sapling, MaterialColor color, int light) { - 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)); + 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)); this.sapling = sapling; } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -72,7 +57,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, } return MHelper.RANDOM.nextInt(16) == 0 ? Lists.newArrayList(new ItemStack(sapling)) : Lists.newArrayList(); } - + @Override public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); diff --git a/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java b/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java index d4ecb9bf..d29ff46d 100644 --- a/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -28,17 +22,22 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; 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 BaseMetalBarsBlock(Block source) { super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + public Optional getModelString(String block) { ResourceLocation blockId = Registry.BLOCK.getKey(this); if (block.contains("item")) { @@ -51,13 +50,13 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi return PatternsHelper.createJson(BasePatterns.BLOCK_BARS_SIDE, blockId); } } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return ModelsHelper.createBlockItem(resourceLocation); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -72,32 +71,25 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { - ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_post"); - ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_side"); + ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post"); + ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side"); registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache); - + ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition); - builder.part(postId).setCondition(state -> - !state.getValue(NORTH) && !state.getValue(EAST) && - !state.getValue(SOUTH) && !state.getValue(WEST)).add(); + builder.part(postId).setCondition(state -> !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(EAST)) - .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(WEST)) - .setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); - + builder.part(sideId).setCondition(state -> state.getValue(EAST)).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(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); + return builder.build(); } - + @Environment(EnvType.CLIENT) public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) { if (direction.getAxis().isVertical() && stateFrom.getBlock() == this && !stateFrom.equals(state)) { @@ -105,7 +97,7 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi } return super.skipRendering(state, stateFrom, direction); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index 9f0bfaf2..ebf88679 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -1,9 +1,5 @@ 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.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; @@ -23,22 +19,21 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.util.MHelper; +import java.util.Collections; +import java.util.List; + public class BaseOreBlock extends OreBlock implements BlockModelProvider { private final Item dropItem; private final int minCount; private final int maxCount; public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) { - super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) - .hardness(3F) - .resistance(9F) - .requiresCorrectToolForDrops() - .sound(SoundType.STONE), UniformInt.of(1, experience)); + super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresCorrectToolForDrops().sound(SoundType.STONE), UniformInt.of(1, experience)); this.dropItem = drop; this.minCount = minCount; this.maxCount = maxCount; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -56,14 +51,15 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { return Collections.singletonList(new ItemStack(dropItem, max)); } count = MHelper.randRange(min, max, MHelper.RANDOM); - } else { + } + else { count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); } return Collections.singletonList(new ItemStack(dropItem, count)); } return Collections.emptyList(); } - + @Override public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); diff --git a/src/main/java/ru/bclib/blocks/BasePathBlock.java b/src/main/java/ru/bclib/blocks/BasePathBlock.java index 75060542..d39e1891 100644 --- a/src/main/java/ru/bclib/blocks/BasePathBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePathBlock.java @@ -1,14 +1,6 @@ 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 net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -28,16 +20,22 @@ import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; + @SuppressWarnings("deprecation") public class BasePathBlock extends BaseBlockNotFull { private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); - + private Block baseBlock; - + public BasePathBlock(Block source) { super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> false)); this.baseBlock = Blocks.DIRT; @@ -72,7 +70,7 @@ public class BasePathBlock extends BaseBlockNotFull { public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -87,7 +85,7 @@ public class BasePathBlock extends BaseBlockNotFull { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PATH, textures); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index b3181e9d..c7818a90 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -1,10 +1,6 @@ package ru.bclib.blocks; -import java.util.List; -import java.util.Random; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.interfaces.IRenderTyped; +import java.util.List; +import java.util.Random; + @SuppressWarnings("deprecation") public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); @@ -46,45 +45,36 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender } public BasePlantBlock(boolean replaceable) { - super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission()); } public BasePlantBlock(boolean replaceable, int light) { - super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.GRASS) - .noCollission()); + super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission()); } public BasePlantBlock(Properties settings) { super(settings); } - + protected abstract boolean isTerrain(BlockState state); - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } - + @Override public BlockBehaviour.OffsetType getOffsetType() { return BlockBehaviour.OffsetType.XZ; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); return isTerrain(down); } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { @@ -110,17 +100,17 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } - + @Override public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } - + @Override public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index e78a0189..89749c6e 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -1,7 +1,5 @@ package ru.bclib.blocks; -import java.util.Random; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.material.Material; +import java.util.Random; + public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; public BasePlantWithAgeBlock() { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .randomTicks() - .noCollission()); + this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission()); } public BasePlantWithAgeBlock(Properties settings) { @@ -53,7 +48,7 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } - + @Override @SuppressWarnings("deprecation") public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { diff --git a/src/main/java/ru/bclib/blocks/BasePressurePlateBlock.java b/src/main/java/ru/bclib/blocks/BasePressurePlateBlock.java index 9cd483f4..dd76e216 100644 --- a/src/main/java/ru/bclib/blocks/BasePressurePlateBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePressurePlateBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -31,19 +30,19 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM super(rule, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().strength(0.5F)); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { @@ -51,18 +50,18 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM Optional pattern; if (blockState.getValue(POWERED)) { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId); - } else { + } + else { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { String state = blockState.getValue(POWERED) ? "_down" : "_up"; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + state); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createBlockSimple(modelId); } diff --git a/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java b/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java index e5d3af50..d866c9d2 100644 --- a/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 BaseRotatedPillarBlock(Properties settings) { super(settings); @@ -30,26 +29,26 @@ public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockM public BaseRotatedPillarBlock(Block block) { super(FabricBlockSettings.copyOf(block)); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { Optional pattern = createBlockPattern(blockId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { @@ -57,7 +56,7 @@ public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockM registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createRotatedModel(modelId, blockState.getValue(AXIS)); } - + protected Optional createBlockPattern(ResourceLocation blockId) { return PatternsHelper.createBlockPillar(blockId); } diff --git a/src/main/java/ru/bclib/blocks/BaseSignBlock.java b/src/main/java/ru/bclib/blocks/BaseSignBlock.java index 5eeb16a0..98ed4864 100644 --- a/src/main/java/ru/bclib/blocks/BaseSignBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSignBlock.java @@ -1,10 +1,5 @@ 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.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -42,23 +37,22 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import ru.bclib.blockentities.BaseSignBlockEntity; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; import ru.bclib.interfaces.ISpetialItem; import ru.bclib.util.BlocksHelper; +import java.util.Collections; +import java.util.List; + @SuppressWarnings("deprecation") public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem { public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; public static final BooleanProperty FLOOR = BooleanProperty.create("floor"); - 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) - }; - + 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)}; + private final Block parent; public BaseSignBlock(Block source) { @@ -66,17 +60,17 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false)); this.parent = source; } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(ROTATION, FLOOR, WATERLOGGED); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return state.getValue(FLOOR) ? SHAPE : WALL_SHAPES[state.getValue(ROTATION) >> 2]; } - + @Override public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) { return new BaseSignBlockEntity(blockPos, blockState); @@ -90,13 +84,14 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe if (!world.isClientSide) { sign.setAllowedPlayerEditor(placer.getUUID()); ((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos)); - } else { + } + else { sign.setEditable(true); } } } } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (state.getValue(WATERLOGGED)) { @@ -107,7 +102,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe } return super.updateShape(state, facing, neighborState, world, pos, neighborPos); } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { if (!state.getValue(FLOOR)) { @@ -118,21 +113,20 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe return world.getBlockState(pos.below()).getMaterial().isSolid(); } } - + @Override public BlockState getStateForPlacement(BlockPlaceContext ctx) { if (ctx.getClickedFace() == Direction.UP) { FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); - 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); - } else if (ctx.getClickedFace() != Direction.DOWN) { + 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); + } + else if (ctx.getClickedFace() != Direction.DOWN) { BlockState blockState = this.defaultBlockState(); FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos()); LevelReader worldView = ctx.getLevel(); BlockPos blockPos = ctx.getClickedPos(); Direction[] directions = ctx.getNearestLookingDirections(); - + for (Direction direction : directions) { if (direction.getAxis().isHorizontal()) { Direction dir = direction.getOpposite(); @@ -144,22 +138,22 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe } } } - + return null; } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { ResourceLocation parentId = Registry.BLOCK.getKey(parent); return ModelsHelper.createBlockEmpty(parentId); } - + @Override public BlockState rotate(BlockState state, Rotation rotation) { return state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16)); } - + @Override public BlockState mirror(BlockState state, Mirror mirror) { return state.setValue(ROTATION, mirror.mirror((Integer) state.getValue(ROTATION), 16)); @@ -169,24 +163,24 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { // TODO Auto-generated method stub return super.canPlaceLiquid(world, pos, state, fluid); } - + @Override public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { // TODO Auto-generated method stub return super.placeLiquid(world, pos, state, fluidState); } - + @Override public int getStackSize() { return 16; } - + @Override public boolean canPlaceOnWater() { return false; diff --git a/src/main/java/ru/bclib/blocks/BaseSlabBlock.java b/src/main/java/ru/bclib/blocks/BaseSlabBlock.java index 73c2e109..4d949ca5 100644 --- a/src/main/java/ru/bclib/blocks/BaseSlabBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSlabBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.properties.SlabType; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -33,19 +32,19 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider { super(FabricBlockSettings.copyOf(source)); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -53,18 +52,18 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider { Optional pattern; if (blockState.getValue(TYPE) == SlabType.DOUBLE) { pattern = PatternsHelper.createBlockSimple(parentId); - } else { + } + else { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_SLAB, parentId); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { SlabType type = blockState.getValue(TYPE); - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_" + type); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + type); registerBlockModel(stateId, modelId, blockState, modelCache); if (type == SlabType.TOP) { return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true); diff --git a/src/main/java/ru/bclib/blocks/BaseStairsBlock.java b/src/main/java/ru/bclib/blocks/BaseStairsBlock.java index 2f057e78..5c0c176c 100644 --- a/src/main/java/ru/bclib/blocks/BaseStairsBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStairsBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.StairsShape; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -41,13 +40,13 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider { public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -68,7 +67,7 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider { } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { @@ -77,21 +76,21 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider { switch (shape) { case INNER_LEFT: case INNER_RIGHT: - state = "_inner"; break; + state = "_inner"; + break; case OUTER_LEFT: case OUTER_RIGHT: - state = "_outer"; break; + state = "_outer"; + break; default: state = ""; } ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state); registerBlockModel(stateId, modelId, blockState, modelCache); - + boolean isTop = blockState.getValue(HALF) == Half.TOP; - boolean isLeft = shape == StairsShape.INNER_LEFT || - shape == StairsShape.OUTER_LEFT; - boolean isRight = shape == StairsShape.INNER_RIGHT || - shape == StairsShape.OUTER_RIGHT; + boolean isLeft = shape == StairsShape.INNER_LEFT || shape == StairsShape.OUTER_LEFT; + boolean isRight = shape == StairsShape.INNER_RIGHT || shape == StairsShape.OUTER_RIGHT; int y = 0; int x = isTop ? 180 : 0; switch (blockState.getValue(FACING)) { diff --git a/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java index aabc865b..6c6bf59b 100644 --- a/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java @@ -6,11 +6,11 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.level.block.Block; public class BaseStoneButtonBlock extends BaseButtonBlock { - + public BaseStoneButtonBlock(Block source) { super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false); } - + @Override protected SoundEvent getSound(boolean clicked) { return clicked ? SoundEvents.STONE_BUTTON_CLICK_ON : SoundEvents.STONE_BUTTON_CLICK_OFF; diff --git a/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java b/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java index fd0537c1..5516246e 100644 --- a/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseTerrainBlock.java @@ -1,15 +1,6 @@ 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 net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -41,14 +32,21 @@ import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; 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") public class BaseTerrainBlock extends BaseBlock { - + private final Block baseBlock; private Block pathBlock; @@ -60,11 +58,11 @@ public class BaseTerrainBlock extends BaseBlock { public void setPathBlock(Block roadBlock) { this.pathBlock = roadBlock; } - + public Block getBaseBlock() { return baseBlock; } - + @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (pathBlock != null && FabricToolTags.SHOVELS.contains(player.getMainHandItem().getItem())) { @@ -95,7 +93,7 @@ public class BaseTerrainBlock extends BaseBlock { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); } } - + public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) { BlockPos blockPos = pos.above(); BlockState blockState = worldView.getBlockState(blockPos); @@ -116,7 +114,7 @@ public class BaseTerrainBlock extends BaseBlock { public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -131,7 +129,7 @@ public class BaseTerrainBlock extends BaseBlock { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TOP_SIDE_BOTTOM, textures); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { diff --git a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java index b0167f0e..fd2c4d5b 100644 --- a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java @@ -1,13 +1,5 @@ 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.Environment; 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.properties.Half; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -28,11 +21,17 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; 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 BaseTrapdoorBlock(Block source) { super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { @@ -43,19 +42,20 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { String name = resourceLocation.getPath(); Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap() { private static final long serialVersionUID = 1L; + { put("%modid%", resourceLocation.getNamespace()); put("%texture%", name); @@ -64,7 +64,7 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl }); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { @@ -87,7 +87,8 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl case WEST: y = (isTop && isOpen) ? 90 : 270; break; - default: break; + default: + break; } BlockModelRotation rotation = BlockModelRotation.by(x, y); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); diff --git a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java index 2254146b..50201937 100644 --- a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java @@ -17,20 +17,11 @@ import net.minecraft.world.level.material.Material; public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer { public BaseUnderwaterWallPlantBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission()); } public BaseUnderwaterWallPlantBlock(int light) { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.WET_GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission()); } public BaseUnderwaterWallPlantBlock(Properties settings) { @@ -41,7 +32,7 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } - + @Override public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 108dc183..3437a49b 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -1,10 +1,6 @@ package ru.bclib.blocks; -import java.util.List; -import java.util.Random; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; @@ -37,6 +33,9 @@ import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; import ru.bclib.util.BlocksHelper; +import java.util.List; +import java.util.Random; + @SuppressWarnings("deprecation") public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock { public static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; @@ -51,12 +50,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon } public BaseVineBlock(int light, boolean bottomOnly) { - 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()); + 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()); this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM)); } @@ -64,13 +58,13 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(SHAPE); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return VOXEL_SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } - + @Override public BlockBehaviour.OffsetType getOffsetType() { return BlockBehaviour.OffsetType.XZ; @@ -79,7 +73,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon public boolean canGenerate(BlockState state, LevelReader world, BlockPos pos) { return isSupport(state, world, pos); } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { return isSupport(state, world, pos); @@ -89,17 +83,15 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon BlockState up = world.getBlockState(pos.above()); return up.is(this) || up.is(BlockTags.LEAVES) || canSupportCenter(world, pos.above(), Direction.DOWN); } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); } else { - if (world.getBlockState(pos.below()).getBlock() != this) - return state.setValue(SHAPE, TripleShape.BOTTOM); - else if (world.getBlockState(pos.above()).getBlock() != this) - return state.setValue(SHAPE, TripleShape.TOP); + if (world.getBlockState(pos.below()).getBlock() != this) return state.setValue(SHAPE, TripleShape.BOTTOM); + else if (world.getBlockState(pos.above()).getBlock() != this) return state.setValue(SHAPE, TripleShape.TOP); return state.setValue(SHAPE, TripleShape.MIDDLE); } } @@ -119,7 +111,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { while (world.getBlockState(pos).getBlock() == this) { @@ -127,7 +119,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon } return world.getBlockState(pos).isAir(); } - + @Override public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { while (world.getBlockState(pos).getBlock() == this) { @@ -135,7 +127,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon } return world.isEmptyBlock(pos); } - + @Override public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { while (world.getBlockState(pos).getBlock() == this) { diff --git a/src/main/java/ru/bclib/blocks/BaseWallBlock.java b/src/main/java/ru/bclib/blocks/BaseWallBlock.java index 031f4d31..682bea1e 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.properties.WallSide; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -34,13 +33,13 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider { super(FabricBlockSettings.copyOf(source).noOcclusion()); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { @@ -48,7 +47,7 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider { Optional pattern = PatternsHelper.createJson(BasePatterns.ITEM_WALL, parentId); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -66,37 +65,28 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider { } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { - ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_post"); - ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_side"); - ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + "_side_tall"); + ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post"); + ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side"); + ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side_tall"); registerBlockModel(postId, postId, blockState, modelCache); registerBlockModel(sideId, sideId, blockState, modelCache); registerBlockModel(sideTallId, sideTallId, blockState, modelCache); - + 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(EAST_WALL) == WallSide.LOW) - .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(WEST_WALL) == WallSide.LOW) - .setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); + builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW).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(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(EAST_WALL) == WallSide.TALL) - .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(WEST_WALL) == WallSide.TALL) - .setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); + builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL).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(WEST_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add(); builder.part(postId).setCondition(state -> state.getValue(UP)).add(); - + return builder.build(); } } diff --git a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java index 9adb0c91..5a398081 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java @@ -1,10 +1,7 @@ package ru.bclib.blocks; -import java.util.EnumMap; - import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; @@ -28,29 +25,18 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.util.BlocksHelper; +import java.util.EnumMap; + public abstract class BaseWallPlantBlock extends BasePlantBlock { - private static final EnumMap 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))); + private static final EnumMap 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))); public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public BaseWallPlantBlock() { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission()); } public BaseWallPlantBlock(int light) { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.GRASS) - .noCollission()); + this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission()); } public BaseWallPlantBlock(Properties settings) { @@ -61,17 +47,17 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(FACING); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPES.get(state.getValue(FACING)); } - + @Override public BlockBehaviour.OffsetType getOffsetType() { return BlockBehaviour.OffsetType.NONE; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { Direction direction = state.getValue(FACING); @@ -101,7 +87,7 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { } return null; } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { @@ -117,7 +103,7 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { public BlockState rotate(BlockState state, Rotation rotation) { return BlocksHelper.rotateHorizontal(state, rotation, FACING); } - + @Override @SuppressWarnings("deprecation") public BlockState mirror(BlockState state, Mirror mirror) { diff --git a/src/main/java/ru/bclib/blocks/BaseWeightedPlateBlock.java b/src/main/java/ru/bclib/blocks/BaseWeightedPlateBlock.java index 28bbe68e..20b2f8f7 100644 --- a/src/main/java/ru/bclib/blocks/BaseWeightedPlateBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWeightedPlateBlock.java @@ -1,12 +1,5 @@ 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.Environment; 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.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; 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 { private final Block parent; @@ -31,19 +30,19 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F)); this.parent = source; } - + @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { @@ -51,18 +50,18 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement Optional pattern; if (blockState.getValue(POWER) > 0) { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_DOWN, parentId); - } else { + } + else { pattern = PatternsHelper.createJson(BasePatterns.BLOCK_PLATE_UP, parentId); } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { String state = blockState.getValue(POWER) > 0 ? "_down" : "_up"; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + state); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createBlockSimple(modelId); } diff --git a/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java index daab12c0..3d92013b 100644 --- a/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java @@ -6,11 +6,11 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.level.block.Block; public class BaseWoodenButtonBlock extends BaseButtonBlock { - + public BaseWoodenButtonBlock(Block source) { super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true); } - + @Override protected SoundEvent getSound(boolean clicked) { return clicked ? SoundEvents.WOODEN_BUTTON_CLICK_ON : SoundEvents.WOODEN_BUTTON_CLICK_OFF; diff --git a/src/main/java/ru/bclib/blocks/BlockProperties.java b/src/main/java/ru/bclib/blocks/BlockProperties.java index 7bf55492..b6a71150 100644 --- a/src/main/java/ru/bclib/blocks/BlockProperties.java +++ b/src/main/java/ru/bclib/blocks/BlockProperties.java @@ -24,9 +24,7 @@ public class BlockProperties { public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); public enum TripleShape implements StringRepresentable { - TOP("top", 0), - MIDDLE("middle", 1), - BOTTOM("bottom", 2); + TOP("top", 0), MIDDLE("middle", 1), BOTTOM("bottom", 2); private final String name; private final int index; @@ -35,7 +33,7 @@ public class BlockProperties { this.name = name; this.index = index; } - + @Override public String getSerializedName() { return name; @@ -56,18 +54,14 @@ public class BlockProperties { } public enum PentaShape implements StringRepresentable { - BOTTOM("bottom"), - PRE_BOTTOM("pre_bottom"), - MIDDLE("middle"), - PRE_TOP("pre_top"), - TOP("top"); + BOTTOM("bottom"), PRE_BOTTOM("pre_bottom"), MIDDLE("middle"), PRE_TOP("pre_top"), TOP("top"); private final String name; PentaShape(String name) { this.name = name; } - + @Override public String getSerializedName() { return name; diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index 38548c2f..42c727b6 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -1,13 +1,5 @@ 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.Environment; 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.state.BlockState; 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.storage.loot.LootContext; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.BlockModelProvider; import ru.bclib.client.models.ModelsHelper; @@ -37,65 +31,57 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Random; + @SuppressWarnings("deprecation") public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); - + public FeatureSaplingBlock() { - super(null, FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) - .collidable(false) - .instabreak() - .sound(SoundType.GRASS) - .randomTicks()); + super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).instabreak().sound(SoundType.GRASS).randomTicks()); } - + public FeatureSaplingBlock(int light) { - super(null, FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) - .collidable(false) - .luminance(light) - .instabreak() - .sound(SoundType.GRASS) - .randomTicks()); + super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).luminance(light).instabreak().sound(SoundType.GRASS).randomTicks()); } - + protected abstract Feature getFeature(); @Override public List getDrops(BlockState state, LootContext.Builder builder) { return Collections.singletonList(new ItemStack(this)); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { - if (!canSurvive(state, world, pos)) - return Blocks.AIR.defaultBlockState(); - else - return state; + if (!canSurvive(state, world, pos)) return Blocks.AIR.defaultBlockState(); + else return state; } - + @Override public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return random.nextInt(16) == 0; } - + @Override public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) { FeaturePlaceContext context = new FeaturePlaceContext(world, world.getChunkSource().getGenerator(), random, pos, null); getFeature().place(context); } - + @Override public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { this.tick(state, world, pos, random); } - + @Override public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { super.tick(state, world, pos, random); @@ -103,18 +89,18 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende performBonemeal(world, random, pos, state); } } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { return ModelsHelper.createBlockItem(resourceLocation); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { diff --git a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java index ac46338c..8fe7c375 100644 --- a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java @@ -9,28 +9,13 @@ import ru.bclib.interfaces.IRenderTyped; public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped { public SimpleLeavesBlock(MaterialColor color) { - 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)); + 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)); } public SimpleLeavesBlock(MaterialColor color, int light) { - 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)); + 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)); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; diff --git a/src/main/java/ru/bclib/blocks/StalactiteBlock.java b/src/main/java/ru/bclib/blocks/StalactiteBlock.java index 50401565..11ae5224 100644 --- a/src/main/java/ru/bclib/blocks/StalactiteBlock.java +++ b/src/main/java/ru/bclib/blocks/StalactiteBlock.java @@ -1,10 +1,5 @@ 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.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; @@ -37,29 +32,33 @@ import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; +import java.util.Map; +import java.util.Optional; + @SuppressWarnings("deprecation") public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped { public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR; public static final IntegerProperty SIZE = BlockProperties.SIZE; private static final VoxelShape[] SHAPES; - + public StalactiteBlock(Block source) { super(FabricBlockSettings.copy(source).noOcclusion()); this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false)); } - + @Override protected void createBlockStateDefinition(StateDefinition.Builder stateManager) { stateManager.add(WATERLOGGED, IS_FLOOR, SIZE); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPES[state.getValue(SIZE)]; @@ -95,7 +94,7 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg } } } - + @Override public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { boolean hasUp = isThis(world, pos.above()); @@ -183,7 +182,7 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg } return state; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { int size = state.getValue(SIZE); @@ -208,22 +207,21 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CROSS_SHADED, resourceLocation); return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - stateId.getPath() + "_" + blockState.getValue(SIZE)); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), stateId.getPath() + "_" + blockState.getValue(SIZE)); registerBlockModel(modelId, modelId, blockState, modelCache); return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false); } - + @Override public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } - + @Override public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; @@ -233,12 +231,12 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); } - + @Override public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + static { float end = 2F / 8F; float start = 5F / 8F; diff --git a/src/main/java/ru/bclib/blocks/TripleTerrainBlock.java b/src/main/java/ru/bclib/blocks/TripleTerrainBlock.java index 252ec776..e04b13c3 100644 --- a/src/main/java/ru/bclib/blocks/TripleTerrainBlock.java +++ b/src/main/java/ru/bclib/blocks/TripleTerrainBlock.java @@ -1,15 +1,7 @@ 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.Maps; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; 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.material.MaterialColor; import net.minecraft.world.phys.BlockHitResult; +import org.jetbrains.annotations.Nullable; import ru.bclib.blocks.BlockProperties.TripleShape; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; 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 static final EnumProperty SHAPE = BlockProperties.TRIPLE_SHAPE; @@ -46,7 +44,7 @@ public class TripleTerrainBlock extends BaseTerrainBlock { super(baseBlock, baseBlock.defaultMaterialColor()); this.registerDefaultState(defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM)); } - + public TripleTerrainBlock(Block baseBlock, MaterialColor color) { super(baseBlock, color); this.registerDefaultState(defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM)); @@ -63,7 +61,7 @@ public class TripleTerrainBlock extends BaseTerrainBlock { TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE; return defaultBlockState().setValue(SHAPE, shape); } - + @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { TripleShape shape = state.getValue(SHAPE); @@ -78,7 +76,8 @@ public class TripleTerrainBlock extends BaseTerrainBlock { TripleShape shape = state.getValue(SHAPE); if (shape == TripleShape.BOTTOM) { super.randomTick(state, world, pos, random); - } else if (random.nextInt(16) == 0) { + } + else if (random.nextInt(16) == 0) { boolean bottom = canStayBottom(world, pos); if (shape == TripleShape.TOP) { if (!bottom) { @@ -89,9 +88,11 @@ public class TripleTerrainBlock extends BaseTerrainBlock { boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above())); if (!top && !bottom) { world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); - } else if (top && !bottom) { + } + else if (top && !bottom) { world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM)); - } else if (!top) { + } + else if (!top) { world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP)); } } @@ -103,19 +104,21 @@ public class TripleTerrainBlock extends BaseTerrainBlock { BlockState blockState = world.getBlockState(blockPos); if (isMiddle(blockState)) { return true; - } else if (blockState.getFluidState().getAmount() == 8) { + } + else if (blockState.getFluidState().getAmount() == 8) { return false; - } else { + } + else { return !blockState.isFaceSturdy(world, blockPos, Direction.UP); } } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation blockId) { return getBlockModel(blockId, defaultBlockState()); } - + @Override @Environment(EnvType.CLIENT) public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) { @@ -124,7 +127,8 @@ public class TripleTerrainBlock extends BaseTerrainBlock { if (isMiddle(blockState)) { ResourceLocation topId = new ResourceLocation(blockId.getNamespace(), path + "_top"); pattern = PatternsHelper.createBlockSimple(topId); - } else { + } + else { Map textures = Maps.newHashMap(); textures.put("%top%", "betterend:block/" + path + "_top"); textures.put("%side%", "betterend:block/" + path + "_side"); @@ -133,14 +137,13 @@ public class TripleTerrainBlock extends BaseTerrainBlock { } return ModelsHelper.fromPattern(pattern); } - + @Override @Environment(EnvType.CLIENT) public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { boolean isMiddle = isMiddle(blockState); String middle = isMiddle ? "_middle" : ""; - ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), - "block/" + stateId.getPath() + middle); + ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + middle); registerBlockModel(stateId, modelId, blockState, modelCache); if (isMiddle) { List variants = Lists.newArrayList(); @@ -148,17 +151,13 @@ public class TripleTerrainBlock extends BaseTerrainBlock { variants.add(new Variant(modelId, rotation.getRotation(), false, 1)); } return new MultiVariant(variants); - } else if (blockState.getValue(SHAPE) == TripleShape.TOP) { - 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) - )); + } + else if (blockState.getValue(SHAPE) == TripleShape.TOP) { + 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))); } return ModelsHelper.createRandomTopModel(modelId); } - + protected boolean isMiddle(BlockState blockState) { return blockState.is(this) && blockState.getValue(SHAPE) == TripleShape.MIDDLE; } diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 4d168107..dd92f183 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -1,10 +1,6 @@ package ru.bclib.blocks; -import java.util.List; -import java.util.Random; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; @@ -37,42 +33,36 @@ import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; +import java.util.List; +import java.util.Random; + @SuppressWarnings("deprecation") public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public UnderwaterPlantBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission()); } public UnderwaterPlantBlock(int light) { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.WET_GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission()); } public UnderwaterPlantBlock(Properties settings) { super(settings); } - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); } - + @Override public BlockBehaviour.OffsetType getOffsetType() { return BlockBehaviour.OffsetType.XZ; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); @@ -81,7 +71,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I } protected abstract boolean isTerrain(BlockState state); - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { @@ -108,28 +98,28 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } - + @Override public boolean isValidBonemealTarget(BlockGetter world, BlockPos pos, BlockState state, boolean isClient) { return true; } - + @Override public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { return true; } - + @Override public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) { ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this)); world.addFreshEntity(item); } - + @Override public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { return false; } - + @Override public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { return false; diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java index 8b6499a2..9855d9d2 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java @@ -1,7 +1,5 @@ package ru.bclib.blocks; -import java.util.Random; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.material.Material; +import java.util.Random; + public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; public UnderwaterPlantWithAgeBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .randomTicks() - .noCollission()); + super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).randomTicks().noCollission()); } @Override diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 0773a45b..92941bbf 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -1,9 +1,6 @@ package ru.bclib.blocks; -import java.util.List; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; @@ -29,25 +26,23 @@ import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.IRenderTyped; +import java.util.List; + @SuppressWarnings("deprecation") public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); public UpDownPlantBlock() { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission()); } - + protected abstract boolean isTerrain(BlockState state); - + @Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } - + @Override public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); @@ -58,7 +53,7 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRend protected boolean isSupport(BlockState state, LevelReader world, BlockPos pos) { return canSupportCenter(world, pos.above(), Direction.UP); } - + @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index 5e910e70..4f483977 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -1,9 +1,6 @@ package ru.bclib.blocks; -import java.util.List; - import com.google.common.collect.Lists; - import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; 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.storage.loot.LootContext; +import java.util.List; + public abstract class WallMushroomBlock extends BaseWallPlantBlock { public WallMushroomBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.AXES) - .breakByHand(true) - .luminance(light) - .hardness(0.2F) - .sound(SoundType.GRASS) - .sound(SoundType.WOOD) - .noCollission()); + super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).breakByHand(true).luminance(light).hardness(0.2F).sound(SoundType.GRASS).sound(SoundType.WOOD).noCollission()); } @Override diff --git a/src/main/java/ru/bclib/client/BCLibClient.java b/src/main/java/ru/bclib/client/BCLibClient.java index 5b6249d6..c281553e 100644 --- a/src/main/java/ru/bclib/client/BCLibClient.java +++ b/src/main/java/ru/bclib/client/BCLibClient.java @@ -23,10 +23,8 @@ public class BCLibClient implements ClientModInitializer { Registry.BLOCK.forEach(block -> { if (block instanceof IRenderTyped) { BCLRenderLayer layer = ((IRenderTyped) block).getRenderLayer(); - if (layer == BCLRenderLayer.CUTOUT) - BlockRenderLayerMap.INSTANCE.putBlock(block, cutout); - else if (layer == BCLRenderLayer.TRANSLUCENT) - BlockRenderLayerMap.INSTANCE.putBlock(block, translucent); + if (layer == BCLRenderLayer.CUTOUT) BlockRenderLayerMap.INSTANCE.putBlock(block, cutout); + else if (layer == BCLRenderLayer.TRANSLUCENT) BlockRenderLayerMap.INSTANCE.putBlock(block, translucent); } }); } diff --git a/src/main/java/ru/bclib/client/gui/BlockSignEditScreen.java b/src/main/java/ru/bclib/client/gui/BlockSignEditScreen.java index 89954126..22121169 100644 --- a/src/main/java/ru/bclib/client/gui/BlockSignEditScreen.java +++ b/src/main/java/ru/bclib/client/gui/BlockSignEditScreen.java @@ -45,109 +45,108 @@ public class BlockSignEditScreen extends Screen { Arrays.fill(strings, ""); }); private SignRenderer.SignModel model; - + public BlockSignEditScreen(BaseSignBlockEntity sign) { super(new TranslatableComponent("sign.edit")); this.sign = sign; } - + protected void init() { //set up a default model model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK))); - + minecraft.keyboardHandler.setSendRepeatsToGui(true); - this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, - (buttonWidget) -> { - this.finishEditing(); - })); + this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, (buttonWidget) -> { + this.finishEditing(); + })); this.sign.setEditable(false); this.selectionManager = new TextFieldHelper(() -> { return this.text[this.currentRow]; }, (string) -> { this.text[this.currentRow] = string; this.sign.setMessage(this.currentRow, new TextComponent(string)); - }, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), - (string) -> { - return this.minecraft.font.width(string) <= 90; - }); + }, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), (string) -> { + return this.minecraft.font.width(string) <= 90; + }); } - + public void removed() { minecraft.keyboardHandler.setSendRepeatsToGui(false); ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection(); if (clientPlayNetworkHandler != null) { - clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], - this.text[2], this.text[3])); + clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], this.text[2], this.text[3])); } - + this.sign.setEditable(true); } - + public void tick() { ++this.ticksSinceOpened; if (!this.sign.getType().isValid(this.sign.getBlockState())) { this.finishEditing(); } } - + private void finishEditing() { this.sign.setChanged(); this.minecraft.setScreen((Screen) null); } - + public boolean charTyped(char chr, int keyCode) { this.selectionManager.charTyped(chr); return true; } - + public void onClose() { this.finishEditing(); } - + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == 265) { this.currentRow = this.currentRow - 1 & 3; this.selectionManager.setCursorToEnd(); 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); - } else { + } + else { this.currentRow = this.currentRow + 1 & 3; this.selectionManager.setCursorToEnd(); return true; } } - + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { Lighting.setupForFlatItems(); this.renderBackground(matrices); GuiComponent.drawCenteredString(matrices, this.font, this.title, this.width / 2, 40, 16777215); matrices.pushPose(); matrices.translate((double) (this.width / 2), 0.0D, 50.0D); - + matrices.scale(93.75F, -93.75F, 93.75F); matrices.translate(0.0D, -1.3125D, 0.0D); BlockState blockState = this.sign.getBlockState(); boolean bl = blockState.getValue(BaseSignBlock.FLOOR); - + if (!bl) { matrices.translate(0.0D, -0.3125D, 0.0D); } - + boolean bl2 = this.ticksSinceOpened / 6 % 2 == 0; - + matrices.pushPose(); matrices.scale(0.6666667F, -0.6666667F, -0.6666667F); MultiBufferSource.BufferSource immediate = minecraft.renderBuffers().bufferSource(); VertexConsumer vertexConsumer = BaseSignBlockEntityRenderer.getConsumer(immediate, blockState.getBlock()); model.root.getChild("sign").render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY); - + if (bl) { model.stick.render(matrices, vertexConsumer, 15728880, OverlayTexture.NO_OVERLAY); } - + matrices.popPose(); - + matrices.translate(0.0D, 0.3333333432674408D, 0.046666666865348816D); matrices.scale(0.010416667F, -0.010416667F, 0.010416667F); int i = this.sign.getColor().getTextColor(); @@ -155,7 +154,7 @@ public class BlockSignEditScreen extends Screen { int k = this.selectionManager.getSelectionPos(); int l = this.currentRow * 10 - this.text.length * 5; Matrix4f matrix4f = matrices.last().pose(); - + int m; String string2; int s; @@ -166,29 +165,25 @@ public class BlockSignEditScreen extends Screen { if (this.font.isBidirectional()) { string2 = this.font.bidirectionalShaping(string2); } - + 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, - immediate, false, 0, 15728880, false); + this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, immediate, false, 0, 15728880, false); if (m == this.currentRow && j >= 0 && bl2) { - s = this.minecraft.font - .width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); + s = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); t = s - this.minecraft.font.width(string2) / 2; if (j >= string2.length()) { - this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, - 0, 15728880, false); + this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, 0, 15728880, false); } } } } - + immediate.endBatch(); - + for (m = 0; m < this.text.length; ++m) { string2 = this.text[m]; if (string2 != null && m == this.currentRow && j >= 0) { - int r = this.minecraft.font - .width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); + int r = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0))); s = r - this.minecraft.font.width(string2) / 2; if (bl2 && j < string2.length()) { int var31 = l - 1; @@ -196,14 +191,12 @@ public class BlockSignEditScreen extends Screen { this.minecraft.font.getClass(); fill(matrices, s, var31, var10003, l + 9, -16777216 | i); } - + if (k != j) { t = Math.min(j, k); int u = Math.max(j, k); - int v = this.minecraft.font.width(string2.substring(0, t)) - - this.minecraft.font.width(string2) / 2; - int w = this.minecraft.font.width(string2.substring(0, u)) - - this.minecraft.font.width(string2) / 2; + int v = this.minecraft.font.width(string2.substring(0, t)) - 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 y = Math.max(v, w); Tesselator tessellator = Tesselator.getInstance(); @@ -225,7 +218,7 @@ public class BlockSignEditScreen extends Screen { } } } - + matrices.popPose(); Lighting.setupFor3DItems(); super.render(matrices, mouseX, mouseY, delta); diff --git a/src/main/java/ru/bclib/client/models/BaseChestBlockModel.java b/src/main/java/ru/bclib/client/models/BaseChestBlockModel.java index ec5bf62d..bdea5197 100644 --- a/src/main/java/ru/bclib/client/models/BaseChestBlockModel.java +++ b/src/main/java/ru/bclib/client/models/BaseChestBlockModel.java @@ -2,90 +2,67 @@ package ru.bclib.client.models; import net.minecraft.client.model.geom.ModelPart; 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 final ModelPart partA; - public final ModelPart partC; - public final ModelPart partB; - public final ModelPart partRightA; - public final ModelPart partRightC; - public final ModelPart partRightB; - public final ModelPart partLeftA; - public final ModelPart partLeftC; - public final ModelPart partLeftB; - - public static LayerDefinition getTexturedModelData() { - MeshDefinition modelData = new MeshDefinition(); - PartDefinition modelPartData = modelData.getRoot(); - CubeDeformation deformation_partC = new CubeDeformation(0.0f); - 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); - - CubeDeformation deformation_partA = new CubeDeformation(0.0f); - 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)); - - CubeDeformation deformation_partB = new CubeDeformation(0.0f); - 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)); - - CubeDeformation deformation_partRightC = new CubeDeformation(0.0f); - 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); - - CubeDeformation deformation_partRightA = new CubeDeformation(0.0f); - 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)); - - CubeDeformation deformation_partRightB = new CubeDeformation(0.0f); - 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)); - - CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f); - 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); - - CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f); - 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)); - - CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f); - 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)); - - return LayerDefinition.create(modelData, 64, 64); - } - - public BaseChestBlockModel(ModelPart modelPart) { - super(); - - partC = modelPart.getChild("partC"); - partA = modelPart.getChild("partA"); - partB = modelPart.getChild("partB"); - partRightC = modelPart.getChild("partRightC"); - partRightA = modelPart.getChild("partRightA"); - partRightB = modelPart.getChild("partRightB"); - partLeftC = modelPart.getChild("partLeftC"); - partLeftA = modelPart.getChild("partLeftA"); - partLeftB = modelPart.getChild("partLeftB"); - } + public final ModelPart partA; + public final ModelPart partC; + public final ModelPart partB; + public final ModelPart partRightA; + public final ModelPart partRightC; + public final ModelPart partRightB; + public final ModelPart partLeftA; + public final ModelPart partLeftC; + public final ModelPart partLeftB; + + public static LayerDefinition getTexturedModelData() { + MeshDefinition modelData = new MeshDefinition(); + PartDefinition modelPartData = modelData.getRoot(); + CubeDeformation deformation_partC = new CubeDeformation(0.0f); + 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); + + CubeDeformation deformation_partA = new CubeDeformation(0.0f); + 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)); + + CubeDeformation deformation_partB = new CubeDeformation(0.0f); + 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)); + + CubeDeformation deformation_partRightC = new CubeDeformation(0.0f); + 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); + + CubeDeformation deformation_partRightA = new CubeDeformation(0.0f); + 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)); + + CubeDeformation deformation_partRightB = new CubeDeformation(0.0f); + 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)); + + CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f); + 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); + + CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f); + 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)); + + CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f); + 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)); + + return LayerDefinition.create(modelData, 64, 64); + } + + public BaseChestBlockModel(ModelPart modelPart) { + super(); + + partC = modelPart.getChild("partC"); + partA = modelPart.getChild("partA"); + partB = modelPart.getChild("partB"); + partRightC = modelPart.getChild("partRightC"); + partRightA = modelPart.getChild("partRightA"); + partRightB = modelPart.getChild("partRightB"); + partLeftC = modelPart.getChild("partLeftC"); + partLeftA = modelPart.getChild("partLeftA"); + partLeftB = modelPart.getChild("partLeftB"); + } } diff --git a/src/main/java/ru/bclib/client/models/BasePatterns.java b/src/main/java/ru/bclib/client/models/BasePatterns.java index 575e3b27..5d3442a8 100644 --- a/src/main/java/ru/bclib/client/models/BasePatterns.java +++ b/src/main/java/ru/bclib/client/models/BasePatterns.java @@ -57,5 +57,5 @@ public class BasePatterns { public final static ResourceLocation ITEM_GENERATED = BCLib.makeID("patterns/item/pattern_item_generated.json"); public final static ResourceLocation ITEM_HANDHELD = BCLib.makeID("patterns/item/pattern_item_handheld.json"); public final static ResourceLocation ITEM_SPAWN_EGG = BCLib.makeID("patterns/item/pattern_item_spawn_egg.json"); - + } diff --git a/src/main/java/ru/bclib/client/models/BlockModelProvider.java b/src/main/java/ru/bclib/client/models/BlockModelProvider.java index e139a923..9c4b2da9 100644 --- a/src/main/java/ru/bclib/client/models/BlockModelProvider.java +++ b/src/main/java/ru/bclib/client/models/BlockModelProvider.java @@ -1,34 +1,33 @@ 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.Environment; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; 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 { @Environment(EnvType.CLIENT) default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { Optional pattern = PatternsHelper.createBlockSimple(resourceLocation); return ModelsHelper.fromPattern(pattern); } - + @Environment(EnvType.CLIENT) default UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map modelCache) { ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath()); registerBlockModel(stateId, modelId, blockState, modelCache); return ModelsHelper.createBlockSimple(modelId); } - + @Environment(EnvType.CLIENT) default void registerBlockModel(ResourceLocation stateId, ResourceLocation modelId, BlockState blockState, Map modelCache) { if (!modelCache.containsKey(modelId)) { @@ -36,7 +35,8 @@ public interface BlockModelProvider extends ItemModelProvider { if (model != null) { model.name = modelId.toString(); modelCache.put(modelId, model); - } else { + } + else { BCLib.LOGGER.warning("Error loading model: {}", modelId); modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION)); } diff --git a/src/main/java/ru/bclib/client/models/ModelsHelper.java b/src/main/java/ru/bclib/client/models/ModelsHelper.java index f7bdec4d..8e9b2382 100644 --- a/src/main/java/ru/bclib/client/models/ModelsHelper.java +++ b/src/main/java/ru/bclib/client/models/ModelsHelper.java @@ -1,12 +1,7 @@ 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.mojang.math.Transformation; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.block.model.BlockModel; @@ -22,39 +17,43 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + @Environment(EnvType.CLIENT) public class ModelsHelper { public static BlockModel fromPattern(Optional pattern) { return pattern.map(BlockModel::fromString).orElse(null); } - + public static BlockModel createItemModel(ResourceLocation resourceLocation) { return fromPattern(PatternsHelper.createItemGenerated(resourceLocation)); } - + public static BlockModel createHandheldItem(ResourceLocation resourceLocation) { return fromPattern(PatternsHelper.createItemHandheld(resourceLocation)); } - + public static BlockModel createBlockItem(ResourceLocation resourceLocation) { Optional pattern = PatternsHelper.createJson(BasePatterns.ITEM_BLOCK, resourceLocation); return fromPattern(pattern); } - + public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) { Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_EMPTY, resourceLocation); return fromPattern(pattern); } - + public static MultiVariant createMultiVariant(ResourceLocation resourceLocation, Transformation transform, boolean uvLock) { Variant variant = new Variant(resourceLocation, transform, uvLock, 1); return new MultiVariant(Lists.newArrayList(variant)); } - + public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) { return createMultiVariant(resourceLocation, Transformation.identity(), false); } - + public static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing, boolean uvLock, boolean inverted) { if (inverted) { facing = facing.getOpposite(); @@ -62,45 +61,45 @@ public class ModelsHelper { BlockModelRotation rotation = BlockModelRotation.by(0, (int) facing.toYRot()); return createMultiVariant(resourceLocation, rotation.getRotation(), uvLock); } - + public static MultiVariant createRotatedModel(ResourceLocation resourceLocation, Direction.Axis axis) { BlockModelRotation rotation = BlockModelRotation.X0_Y0; switch (axis) { - case X: rotation = BlockModelRotation.X90_Y90; break; - case Z: rotation = BlockModelRotation.X90_Y0; break; - default: break; + case X: + rotation = BlockModelRotation.X90_Y90; + break; + case Z: + rotation = BlockModelRotation.X90_Y0; + break; + default: + break; } return createMultiVariant(resourceLocation, rotation.getRotation(), false); } - + public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) { - 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) - )); + 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))); } - + public static class MultiPartBuilder { - + private final static MultiPartBuilder BUILDER = new MultiPartBuilder(); - + public static MultiPartBuilder create(StateDefinition stateDefinition) { BUILDER.stateDefinition = stateDefinition; BUILDER.modelParts.clear(); return BUILDER; } - + private final List modelParts = Lists.newArrayList(); private StateDefinition stateDefinition; - + private MultiPartBuilder() {} - + public ModelPart part(ResourceLocation modelId) { return new ModelPart(modelId); } - + public MultiPart build() { if (modelParts.size() > 0) { List selectors = Lists.newArrayList(); @@ -113,32 +112,32 @@ public class ModelsHelper { } throw new IllegalStateException("At least one model part need to be created."); } - + public class ModelPart { private final ResourceLocation modelId; private Transformation transform = Transformation.identity(); private Condition condition = Condition.TRUE; private boolean uvLock = false; - + private ModelPart(ResourceLocation modelId) { this.modelId = modelId; } - + public ModelPart setCondition(Function condition) { this.condition = stateDefinition -> condition::apply; return this; } - + public ModelPart setTransformation(Transformation transform) { this.transform = transform; return this; } - + public ModelPart setUVLock(boolean value) { this.uvLock = value; return this; } - + public void add() { modelParts.add(this); } diff --git a/src/main/java/ru/bclib/client/models/PatternsHelper.java b/src/main/java/ru/bclib/client/models/PatternsHelper.java index 771b7d80..134e59c9 100644 --- a/src/main/java/ru/bclib/client/models/PatternsHelper.java +++ b/src/main/java/ru/bclib/client/models/PatternsHelper.java @@ -1,5 +1,10 @@ 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.InputStream; import java.io.InputStreamReader; @@ -8,58 +13,52 @@ import java.util.Map; import java.util.Optional; 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 static Optional createItemGenerated(ResourceLocation itemId) { return createJson(BasePatterns.ITEM_GENERATED, itemId); } - + public static Optional createItemHandheld(ResourceLocation itemId) { return createJson(BasePatterns.ITEM_HANDHELD, itemId); } - + public static Optional createBlockSimple(ResourceLocation blockId) { return createJson(BasePatterns.BLOCK_BASE, blockId); } - + public static Optional createBlockEmpty(ResourceLocation blockId) { return createJson(BasePatterns.BLOCK_EMPTY, blockId); } - + public static Optional createBlockPillar(ResourceLocation blockId) { return createJson(BasePatterns.BLOCK_PILLAR, blockId); } - + public static Optional createBlockBottomTop(ResourceLocation blockId) { return createJson(BasePatterns.BLOCK_BOTTOM_TOP, blockId); } - + public static Optional createBlockColored(ResourceLocation blockId) { return createJson(BasePatterns.BLOCK_COLORED, blockId); } - + public static Optional createJson(ResourceLocation patternId, ResourceLocation blockId) { Map textures = Maps.newHashMap(); textures.put("%modid%", blockId.getNamespace()); textures.put("%texture%", blockId.getPath()); return createJson(patternId, textures); } - + public static Optional createJson(ResourceLocation patternId, Map textures) { ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); try (InputStream input = resourceManager.getResource(patternId).getInputStream()) { - String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) - .lines().collect(Collectors.joining()); + String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining()); for (Map.Entry texture : textures.entrySet()) { json = json.replace(texture.getKey(), texture.getValue()); } return Optional.of(json); - } catch (Exception ex) { + } + catch (Exception ex) { return Optional.empty(); } } diff --git a/src/main/java/ru/bclib/client/render/BCLRenderLayer.java b/src/main/java/ru/bclib/client/render/BCLRenderLayer.java index 3846d7d6..796edfa5 100644 --- a/src/main/java/ru/bclib/client/render/BCLRenderLayer.java +++ b/src/main/java/ru/bclib/client/render/BCLRenderLayer.java @@ -1,6 +1,5 @@ package ru.bclib.client.render; public enum BCLRenderLayer { - CUTOUT, - TRANSLUCENT; + CUTOUT, TRANSLUCENT; } diff --git a/src/main/java/ru/bclib/client/render/BaseChestBlockEntityRenderer.java b/src/main/java/ru/bclib/client/render/BaseChestBlockEntityRenderer.java index 96d59f04..ab661e2c 100644 --- a/src/main/java/ru/bclib/client/render/BaseChestBlockEntityRenderer.java +++ b/src/main/java/ru/bclib/client/render/BaseChestBlockEntityRenderer.java @@ -18,7 +18,11 @@ import net.minecraft.core.Direction; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; 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.entity.ChestBlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -32,17 +36,18 @@ import java.util.HashMap; public class BaseChestBlockEntityRenderer implements BlockEntityRenderer { private static final HashMap LAYERS = Maps.newHashMap(); private static final RenderType[] defaultLayer; - + private static final int ID_NORMAL = 0; private static final int ID_LEFT = 1; private static final int ID_RIGHT = 2; - + private final BaseChestBlockModel chestModel; + public BaseChestBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) { super(); chestModel = new BaseChestBlockModel(BaseChestBlockModel.getTexturedModelData().bakeRoot()); } - + public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) { Level world = entity.getLevel(); boolean worldExists = world != null; @@ -54,40 +59,42 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer propertySource; - + matrices.pushPose(); matrices.translate(0.5D, 0.5D, 0.5D); matrices.mulPose(Vector3f.YP.rotationDegrees(-f)); matrices.translate(-0.5D, -0.5D, -0.5D); - + if (worldExists) { propertySource = abstractChestBlock.combine(blockState, world, entity.getBlockPos(), true); - } else { + } + else { propertySource = DoubleBlockCombiner.Combiner::acceptNone; } - + float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta); pitch = 1.0F - pitch; pitch = 1.0F - pitch * pitch * pitch; - @SuppressWarnings({ "unchecked", "rawtypes" }) - int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light); - + @SuppressWarnings({"unchecked", "rawtypes"}) int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light); + VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType); - + if (isDouble) { if (chestType == ChestType.LEFT) { 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); } - } else { + } + else { renderParts(matrices, vertexConsumer, chestModel.partA, chestModel.partB, chestModel.partC, pitch, blockLight, overlay); } - + matrices.popPose(); } } - + private void renderParts(PoseStack matrices, VertexConsumer vertices, ModelPart modelPart, ModelPart modelPart2, ModelPart modelPart3, float pitch, int light, int overlay) { modelPart.xRot = -(pitch * 1.5707964F); modelPart2.xRot = modelPart.xRot; @@ -95,7 +102,7 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer layers[ID_LEFT]; @@ -103,28 +110,20 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer layers[ID_NORMAL]; }; } - + public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) { RenderType[] layers = LAYERS.getOrDefault(block, defaultLayer); return provider.getBuffer(getChestTexture(chestType, layers)); } - + public static void registerRenderLayer(Block block) { ResourceLocation blockId = Registry.BLOCK.getKey(block); String modId = blockId.getNamespace(); String path = blockId.getPath(); - 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")) - }); + 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"))}); } - + static { - 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")) - }; + 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"))}; } } diff --git a/src/main/java/ru/bclib/client/render/BaseSignBlockEntityRenderer.java b/src/main/java/ru/bclib/client/render/BaseSignBlockEntityRenderer.java index 6d26f1d6..3fb6af43 100644 --- a/src/main/java/ru/bclib/client/render/BaseSignBlockEntityRenderer.java +++ b/src/main/java/ru/bclib/client/render/BaseSignBlockEntityRenderer.java @@ -39,42 +39,42 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer { - List list = this.font.split(component, 90); - return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0); - }); + + FormattedCharSequence[] formattedCharSequences = signBlockEntity.getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), (component) -> { + List list = this.font.split(component, 90); + return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0); + }); int drawColor; boolean drawOutlined; int drawLight; @@ -99,57 +98,58 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer { return new ConfigKey(id.getPath(), id.getNamespace(), category); diff --git a/src/main/java/ru/bclib/config/Config.java b/src/main/java/ru/bclib/config/Config.java index 968c45d7..a1df5824 100644 --- a/src/main/java/ru/bclib/config/Config.java +++ b/src/main/java/ru/bclib/config/Config.java @@ -1,7 +1,6 @@ package ru.bclib.config; import org.jetbrains.annotations.Nullable; - import ru.bclib.BCLib; import ru.bclib.config.ConfigKeeper.BooleanEntry; import ru.bclib.config.ConfigKeeper.Entry; @@ -55,14 +54,15 @@ public abstract class Config { if (entry == null) return false; entry.setValue(value); return true; - } catch (NullPointerException ex) { + } + catch (NullPointerException ex) { BCLib.LOGGER.catching(ex); } return false; } protected int getInt(ConfigKey key, int defaultValue) { - Integer val = keeper.getValue(key, IntegerEntry.class); + Integer val = keeper.getValue(key, IntegerEntry.class); if (val == null) { IntegerEntry entry = keeper.registerEntry(key, new IntegerEntry(defaultValue)); return entry.getValue(); @@ -71,7 +71,7 @@ public abstract class Config { } protected int getInt(ConfigKey key) { - Integer val = keeper.getValue(key, IntegerEntry.class); + Integer val = keeper.getValue(key, IntegerEntry.class); return val != null ? val : 0; } @@ -81,7 +81,8 @@ public abstract class Config { if (entry == null) return false; entry.setValue(value); return true; - } catch (NullPointerException ex) { + } + catch (NullPointerException ex) { BCLib.LOGGER.catching(ex); } return false; @@ -93,7 +94,8 @@ public abstract class Config { if (entry == null) return false; entry.setValue(value); return true; - } catch (NullPointerException | ClassCastException ex) { + } + catch (NullPointerException | ClassCastException ex) { BCLib.LOGGER.catching(ex); } return false; @@ -119,7 +121,8 @@ public abstract class Config { if (entry == null) return false; entry.setValue(value); return true; - } catch (NullPointerException ex) { + } + catch (NullPointerException ex) { BCLib.LOGGER.catching(ex); } return false; @@ -145,7 +148,8 @@ public abstract class Config { if (entry == null) return false; entry.setValue(value); return true; - } catch (NullPointerException ex) { + } + catch (NullPointerException ex) { BCLib.LOGGER.catching(ex); } return false; diff --git a/src/main/java/ru/bclib/config/ConfigKeeper.java b/src/main/java/ru/bclib/config/ConfigKeeper.java index 0fc7f049..841e7d27 100644 --- a/src/main/java/ru/bclib/config/ConfigKeeper.java +++ b/src/main/java/ru/bclib/config/ConfigKeeper.java @@ -1,45 +1,43 @@ package ru.bclib.config; +import com.google.common.collect.Maps; +import com.google.common.reflect.TypeToken; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.minecraft.util.GsonHelper; +import org.jetbrains.annotations.Nullable; +import ru.bclib.util.JsonFactory; + 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.reflect.TypeToken; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import net.minecraft.util.GsonHelper; -import ru.bclib.util.JsonFactory; - public final class ConfigKeeper { private final Map> configEntries = Maps.newHashMap(); private final JsonObject configObject; private final ConfigWriter writer; - + private boolean changed = false; - + public ConfigKeeper(String modID, String group) { this.writer = new ConfigWriter(modID, group); this.configObject = writer.load(); } - + public void save() { if (!changed) return; this.writer.save(); this.changed = false; } - + private > void initializeEntry(ConfigKey key, E entry) { if (configObject == null) { return; } String[] path = key.getPath(); JsonObject obj = configObject; - + if (!key.isRoot()) { for (String group : path) { JsonElement element = obj.get(group); @@ -50,13 +48,13 @@ public final class ConfigKeeper { obj = element.getAsJsonObject(); } } - + String paramKey = key.getEntry(); paramKey += " [default: " + entry.getDefault() + "]"; - + this.changed |= entry.setLocation(obj, paramKey); } - + private > void storeValue(E entry, T value) { if (configObject == null) { return; @@ -66,14 +64,14 @@ public final class ConfigKeeper { entry.toJson(value); this.changed = true; } - + private > T getValue(E entry) { if (!entry.hasLocation()) { return entry.getDefault(); } return entry.fromJson(); } - + @Nullable public > E getEntry(ConfigKey key, Class type) { Entry entry = this.configEntries.get(key); @@ -82,7 +80,7 @@ public final class ConfigKeeper { } return null; } - + @Nullable public > T getValue(ConfigKey key, Class type) { Entry entry = this.getEntry(key, type); @@ -91,7 +89,7 @@ public final class ConfigKeeper { } return entry.getValue(); } - + public > E registerEntry(ConfigKey key, E entry) { entry.setWriter(value -> this.storeValue(entry, value)); entry.setReader(() -> { @@ -101,119 +99,119 @@ public final class ConfigKeeper { this.configEntries.put(key, entry); return entry; } - + public static class BooleanEntry extends Entry { - + public BooleanEntry(Boolean defaultValue) { super(defaultValue); } - + @Override public Boolean fromJson() { return GsonHelper.getAsBoolean(location, key, defaultValue); } - + @Override public void toJson(Boolean value) { this.location.addProperty(key, value); } } - + public static class FloatEntry extends Entry { - + public FloatEntry(Float defaultValue) { super(defaultValue); } - + @Override public Float fromJson() { return GsonHelper.getAsFloat(location, key, defaultValue); } - + @Override public void toJson(Float value) { this.location.addProperty(key, value); } } - + public static class FloatRange extends RangeEntry { - + public FloatRange(Float defaultValue, float minVal, float maxVal) { super(defaultValue, minVal, maxVal); } - + @Override public Float fromJson() { return GsonHelper.getAsFloat(location, key, defaultValue); } - + @Override public void toJson(Float value) { this.location.addProperty(key, value); } } - + public static class IntegerEntry extends Entry { - + public IntegerEntry(Integer defaultValue) { super(defaultValue); } - + @Override public Integer getDefault() { return this.defaultValue; } - + @Override public Integer fromJson() { return GsonHelper.getAsInt(location, key, defaultValue); } - + @Override public void toJson(Integer value) { this.location.addProperty(key, value); } } - + public static class IntegerRange extends RangeEntry { - + public IntegerRange(Integer defaultValue, int minVal, int maxVal) { super(defaultValue, minVal, maxVal); } - + @Override public Integer fromJson() { return GsonHelper.getAsInt(location, key, defaultValue); } - + @Override public void toJson(Integer value) { this.location.addProperty(key, value); } } - + public static class StringEntry extends Entry { - + public StringEntry(String defaultValue) { super(defaultValue); } - + @Override public String fromJson() { return GsonHelper.getAsString(location, key, defaultValue); } - + @Override public void toJson(String value) { this.location.addProperty(key, value); } - + } - + public static class EnumEntry> extends Entry { - + private final Type type; - + public EnumEntry(T defaultValue) { super(defaultValue); TypeToken token = new TypeToken() { @@ -221,71 +219,71 @@ public final class ConfigKeeper { }; this.type = token.getType(); } - + @Override public T getDefault() { return this.defaultValue; } - + @Override public T fromJson() { return JsonFactory.GSON.fromJson(location.get(key), type); } - + @Override public void toJson(T value) { location.addProperty(key, JsonFactory.GSON.toJson(value, type)); } } - + public static abstract class RangeEntry> extends Entry { - + private final T min, max; - + public RangeEntry(T defaultValue, T minVal, T maxVal) { super(defaultValue); this.min = minVal; this.max = maxVal; } - + @Override public void setValue(T value) { super.setValue(value.compareTo(min) < 0 ? min : value.compareTo(max) > 0 ? max : value); } - + public T minValue() { return this.min; } - + public T maxValue() { return this.max; } } - + public static abstract class Entry { - + protected final T defaultValue; protected Consumer writer; protected Supplier reader; protected JsonObject location; protected String key; - + public abstract T fromJson(); - + public abstract void toJson(T value); - + public Entry(T defaultValue) { this.defaultValue = defaultValue; } - + protected void setWriter(Consumer writer) { this.writer = writer; } - + protected void setReader(Supplier reader) { this.reader = reader; } - + protected boolean setLocation(JsonObject location, String key) { this.location = location; this.key = key; @@ -295,24 +293,23 @@ public final class ConfigKeeper { } return false; } - + protected boolean hasLocation() { - return this.location != null && - this.key != null; + return this.location != null && this.key != null; } - + public T getValue() { return this.reader.get(); } - + public void setValue(T value) { this.writer.accept(value); } - + public T getDefault() { return this.defaultValue; } - + public void setDefault() { this.setValue(defaultValue); } diff --git a/src/main/java/ru/bclib/config/ConfigKey.java b/src/main/java/ru/bclib/config/ConfigKey.java index ed8b570d..88b2083b 100644 --- a/src/main/java/ru/bclib/config/ConfigKey.java +++ b/src/main/java/ru/bclib/config/ConfigKey.java @@ -17,11 +17,11 @@ public class ConfigKey { public ConfigKey(String entry, ResourceLocation path) { this(entry, path.getNamespace(), path.getPath()); } - + public String[] getPath() { return path; } - + public String getEntry() { return entry; } @@ -29,7 +29,7 @@ public class ConfigKey { public boolean isRoot() { return root; } - + @Override public int hashCode() { final int prime = 31; @@ -38,7 +38,7 @@ public class ConfigKey { result = prime * result + entry.hashCode(); return result; } - + @Override public boolean equals(Object obj) { if (this == obj) { diff --git a/src/main/java/ru/bclib/config/ConfigWriter.java b/src/main/java/ru/bclib/config/ConfigWriter.java index ed4e125b..5884641d 100644 --- a/src/main/java/ru/bclib/config/ConfigWriter.java +++ b/src/main/java/ru/bclib/config/ConfigWriter.java @@ -1,20 +1,19 @@ package ru.bclib.config; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.fabricmc.loader.api.FabricLoader; +import ru.bclib.util.JsonFactory; + import java.io.File; import java.nio.file.Path; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import net.fabricmc.loader.api.FabricLoader; -import ru.bclib.util.JsonFactory; - public class ConfigWriter { private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir(); - + private final File configFile; private JsonObject configObject; - + public ConfigWriter(String modID, String configFile) { this.configFile = new File(new File(GAME_CONFIG_DIR.toFile(), modID), configFile + ".json"); File parent = this.configFile.getParentFile(); @@ -23,38 +22,38 @@ public class ConfigWriter { } this.load(); } - + public JsonObject getConfig() { return configObject; } - + public void save() { if (configObject == null) { return; } save(configFile, configObject); } - + public JsonObject load() { if (configObject == null) { configObject = load(configFile); } return configObject; } - + public void save(JsonElement config) { this.configObject = config.getAsJsonObject(); save(configFile, config); } - + public static JsonObject load(File configFile) { return JsonFactory.getJsonObject(configFile); } - + public static void save(File configFile, JsonElement config) { JsonFactory.storeJson(configFile, config); } - + public static String scrubFileName(String input) { input = input.replaceAll("[/\\ ]+", "_"); input = input.replaceAll("[,:&\"\\|\\<\\>\\?\\*]", "_"); diff --git a/src/main/java/ru/bclib/config/IdConfig.java b/src/main/java/ru/bclib/config/IdConfig.java index 379d8551..cc8f8330 100644 --- a/src/main/java/ru/bclib/config/IdConfig.java +++ b/src/main/java/ru/bclib/config/IdConfig.java @@ -1,14 +1,13 @@ package ru.bclib.config; -import java.util.function.BiFunction; - -import org.jetbrains.annotations.Nullable; - import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; import ru.bclib.config.ConfigKeeper.Entry; import ru.bclib.config.ConfigKeeper.FloatRange; import ru.bclib.config.ConfigKeeper.IntegerRange; +import java.util.function.BiFunction; + public class IdConfig extends Config { protected final BiFunction keyFactory; @@ -16,48 +15,48 @@ public class IdConfig extends Config { super(modID, group); this.keyFactory = keyFactory; } - + @Override protected void registerEntries() {} - + protected ConfigKey createKey(ResourceLocation id, String key) { return this.keyFactory.apply(id, key); } - + @Nullable public > E getEntry(ResourceLocation id, String key, Class type) { return this.getEntry(createKey(id, key), type); } - + @Nullable public > T getDefault(ResourceLocation id, String key, Class type) { return this.getDefault(createKey(id, key), type); } - + public String getString(ResourceLocation id, String key, String defaultValue) { return this.getString(createKey(id, key), defaultValue); } - + public String getString(ResourceLocation id, String key) { return this.getString(createKey(id, key)); } - + public boolean setString(ResourceLocation id, String key, String value) { return this.setString(createKey(id, key), value); } - + public int getInt(ResourceLocation id, String key, int defaultValue) { return this.getInt(createKey(id, key), defaultValue); } - + public int getInt(ResourceLocation id, String key) { return this.getInt(createKey(id, key)); } - + public boolean setInt(ResourceLocation id, String key, int value) { return this.setInt(createKey(id, key), value); } - + public boolean setRangedInt(ResourceLocation id, String key, int value) { return this.setRanged(createKey(id, key), value, IntegerRange.class); } @@ -65,27 +64,27 @@ public class IdConfig extends Config { public boolean setRangedFloat(ResourceLocation id, String key, float value) { return this.setRanged(createKey(id, key), value, FloatRange.class); } - + public float getFloat(ResourceLocation id, String key, float defaultValue) { return this.getFloat(createKey(id, key), defaultValue); } - + public float getFloat(ResourceLocation id, String key) { return this.getFloat(createKey(id, key)); } - + public boolean setFloat(ResourceLocation id, String key, float value) { return this.setFloat(createKey(id, key), value); } - + public boolean getBoolean(ResourceLocation id, String key, boolean defaultValue) { return this.getBoolean(createKey(id, key), defaultValue); } - + public boolean getBoolean(ResourceLocation id, String key) { return this.getBoolean(createKey(id, key)); } - + public boolean setBoolean(ResourceLocation id, String key, boolean value) { return this.setBoolean(createKey(id, key), value); } diff --git a/src/main/java/ru/bclib/config/PathConfig.java b/src/main/java/ru/bclib/config/PathConfig.java index 3f7bc3e9..da3c1d49 100644 --- a/src/main/java/ru/bclib/config/PathConfig.java +++ b/src/main/java/ru/bclib/config/PathConfig.java @@ -1,17 +1,16 @@ package ru.bclib.config; import org.jetbrains.annotations.Nullable; - import ru.bclib.config.ConfigKeeper.Entry; import ru.bclib.config.ConfigKeeper.FloatRange; import ru.bclib.config.ConfigKeeper.IntegerRange; public class PathConfig extends Config { - + public PathConfig(String modID, String group) { super(modID, group); } - + @Override protected void registerEntries() {} @@ -27,36 +26,36 @@ public class PathConfig extends Config { public > E getEntry(String category, String key, Class type) { return this.getEntry(createKey(category, key), type); } - + @Nullable public > T getDefault(String category, String key, Class type) { return this.getDefault(createKey(category, key), type); } - + public String getString(String category, String key, String defaultValue) { return this.getString(createKey(category, key), defaultValue); } - + public String getString(String category, String key) { return this.getString(createKey(category, key)); } - + public boolean setString(String category, String key, String value) { return this.setString(createKey(category, key), value); } - + public int getInt(String category, String key, int defaultValue) { return this.getInt(createKey(category, key), defaultValue); } - + public int getInt(String category, String key) { return this.getInt(createKey(category, key)); } - + public boolean setInt(String category, String key, int value) { return this.setInt(createKey(category, key), value); } - + public boolean setRangedInt(String category, String key, int value) { return this.setRanged(createKey(category, key), value, IntegerRange.class); } @@ -64,27 +63,27 @@ public class PathConfig extends Config { public boolean setRangedFloat(String category, String key, float value) { return this.setRanged(createKey(category, key), value, FloatRange.class); } - + public float getFloat(String category, String key, float defaultValue) { return this.getFloat(createKey(category, key), defaultValue); } - + public float getFloat(String category, String key) { return this.getFloat(createKey(category, key)); } - + public boolean setFloat(String category, String key, float value) { return this.setFloat(createKey(category, key), value); } - + public boolean getBoolean(String category, String key, boolean defaultValue) { return this.getBoolean(createKey(category, key), defaultValue); } - + public boolean getBoolean(String category, String key) { return this.getBoolean(createKey(category, key)); } - + public boolean setBoolean(String category, String key, boolean value) { return this.setBoolean(createKey(category, key), value); } @@ -94,27 +93,27 @@ public class PathConfig extends Config { public String getStringRoot(String key, String defaultValue) { return this.getString(createKey(key), defaultValue); } - + public String getStringRoot(String key) { return this.getString(createKey(key)); } - + public boolean setStringRoot(String key, String value) { return this.setString(createKey(key), value); } - + public int getIntRoot(String key, int defaultValue) { return this.getInt(createKey(key), defaultValue); } - + public int getIntRoot(String key) { return this.getInt(createKey(key)); } - + public boolean setIntRoot(String key, int value) { return this.setInt(createKey(key), value); } - + public boolean setRangedIntRoot(String key, int value) { return this.setRanged(createKey(key), value, IntegerRange.class); } @@ -122,27 +121,27 @@ public class PathConfig extends Config { public boolean setRangedFloatRoot(String key, float value) { return this.setRanged(createKey(key), value, FloatRange.class); } - + public float getFloatRoot(String key, float defaultValue) { return this.getFloat(createKey(key), defaultValue); } - + public float getFloatRoot(String key) { return this.getFloat(createKey(key)); } - + public boolean setFloatRoot(String key, float value) { return this.setFloat(createKey(key), value); } - + public boolean getBooleanRoot(String key, boolean defaultValue) { return this.getBoolean(createKey(key), defaultValue); } - + public boolean getBooleanRoot(String key) { return this.getBoolean(createKey(key)); } - + public boolean setBooleanRoot(String key, boolean value) { return this.setBoolean(createKey(key), value); } diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index 69859df4..869edc61 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -1,10 +1,5 @@ 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.loader.api.FabricLoader; import net.minecraft.core.Registry; @@ -25,6 +20,11 @@ import net.minecraft.world.level.levelgen.feature.Feature; import ru.bclib.BCLib; 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 { private final String modID; @@ -45,7 +45,7 @@ public abstract class ModIntegration { public Item getItem(String name) { return Registry.ITEM.get(getID(name)); } - + public BlockState getDefaultState(String name) { return getBlock(name).defaultBlockState(); } @@ -178,7 +178,7 @@ public abstract class ModIntegration { public Object newInstance(Class cl, Object... args) { if (cl != null) { - for (Constructor constructor: cl.getConstructors()) { + for (Constructor constructor : cl.getConstructors()) { if (constructor.getParameterCount() == args.length) { try { return constructor.newInstance(args); diff --git a/src/main/java/ru/bclib/interfaces/IColorProvider.java b/src/main/java/ru/bclib/interfaces/IColorProvider.java index c9f2f8b6..b10ffe31 100644 --- a/src/main/java/ru/bclib/interfaces/IColorProvider.java +++ b/src/main/java/ru/bclib/interfaces/IColorProvider.java @@ -5,6 +5,6 @@ import net.minecraft.client.color.item.ItemColor; public interface IColorProvider { BlockColor getProvider(); - + ItemColor getItemProvider(); } diff --git a/src/main/java/ru/bclib/interfaces/ISpetialItem.java b/src/main/java/ru/bclib/interfaces/ISpetialItem.java index 33112bf7..e54e5d3c 100644 --- a/src/main/java/ru/bclib/interfaces/ISpetialItem.java +++ b/src/main/java/ru/bclib/interfaces/ISpetialItem.java @@ -2,5 +2,6 @@ package ru.bclib.interfaces; public interface ISpetialItem { boolean canPlaceOnWater(); + int getStackSize(); } diff --git a/src/main/java/ru/bclib/items/BaseAnvilItem.java b/src/main/java/ru/bclib/items/BaseAnvilItem.java index c1b36914..5abab41d 100644 --- a/src/main/java/ru/bclib/items/BaseAnvilItem.java +++ b/src/main/java/ru/bclib/items/BaseAnvilItem.java @@ -1,9 +1,5 @@ package ru.bclib.items; -import java.util.List; - -import org.jetbrains.annotations.Nullable; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.block.model.BlockModel; @@ -18,17 +14,20 @@ import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; import ru.bclib.blocks.BaseAnvilBlock; import ru.bclib.client.models.ItemModelProvider; +import java.util.List; + public class BaseAnvilItem extends BlockItem implements ItemModelProvider { - + public final static String DESTRUCTION = "destruction"; - + public BaseAnvilItem(Block block, Properties properties) { super(block, properties); } - + @Override protected BlockState getPlacementState(BlockPlaceContext blockPlaceContext) { BlockState blockState = super.getPlacementState(blockPlaceContext); @@ -39,7 +38,7 @@ public class BaseAnvilItem extends BlockItem implements ItemModelProvider { } return blockState; } - + @Override @Environment(EnvType.CLIENT) public void appendHoverText(ItemStack itemStack, @Nullable Level level, List list, TooltipFlag tooltipFlag) { @@ -49,7 +48,7 @@ public class BaseAnvilItem extends BlockItem implements ItemModelProvider { list.add(new TranslatableComponent("message.bclib.anvil_damage").append(": " + l)); } } - + @Override @Environment(EnvType.CLIENT) public BlockModel getItemModel(ResourceLocation resourceLocation) { diff --git a/src/main/java/ru/bclib/items/BaseArmorItem.java b/src/main/java/ru/bclib/items/BaseArmorItem.java index 805c2128..39e1cf00 100644 --- a/src/main/java/ru/bclib/items/BaseArmorItem.java +++ b/src/main/java/ru/bclib/items/BaseArmorItem.java @@ -1,10 +1,7 @@ package ru.bclib.items; -import java.util.UUID; - import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; - import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; @@ -13,17 +10,14 @@ import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; import ru.bclib.client.models.ItemModelProvider; +import java.util.UUID; + public class BaseArmorItem extends ArmorItem implements ItemModelProvider { - - 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") - }; - + + 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")}; + protected final Multimap defaultModifiers; - + public BaseArmorItem(ArmorMaterial material, EquipmentSlot equipmentSlot, Properties settings) { super(material, equipmentSlot, settings); this.defaultModifiers = HashMultimap.create(); @@ -34,12 +28,12 @@ public class BaseArmorItem extends ArmorItem implements ItemModelProvider { addAttributeModifier(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(uuid, "Armor knockback resistance", knockbackResistance, AttributeModifier.Operation.ADDITION)); } } - + @Override public Multimap getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) { return equipmentSlot == slot ? defaultModifiers : super.getDefaultAttributeModifiers(equipmentSlot); } - + protected void addAttributeModifier(Attribute attribute, AttributeModifier modifier) { if (defaultModifiers.containsKey(attribute)) { defaultModifiers.removeAll(attribute); diff --git a/src/main/java/ru/bclib/items/BaseDrinkItem.java b/src/main/java/ru/bclib/items/BaseDrinkItem.java index bb2216f2..e50818bd 100644 --- a/src/main/java/ru/bclib/items/BaseDrinkItem.java +++ b/src/main/java/ru/bclib/items/BaseDrinkItem.java @@ -17,22 +17,22 @@ public class BaseDrinkItem extends ModelProviderItem { public BaseDrinkItem(Properties settings) { super(settings); } - + @Override public int getUseDuration(ItemStack stack) { return 32; } - + @Override public UseAnim getUseAnimation(ItemStack stack) { return UseAnim.DRINK; } - + @Override public InteractionResultHolder use(Level world, Player user, InteractionHand hand) { return ItemUtils.startUsingInstantly(world, user, hand); } - + @Override public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity user) { if (this.isEdible()) { @@ -45,15 +45,15 @@ public class BaseDrinkItem extends ModelProviderItem { CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayerEntity, stack); serverPlayerEntity.awardStat(Stats.ITEM_USED.get(this)); } - + if (user instanceof Player && !((Player) user).getAbilities().instabuild) { stack.shrink(1); } - + if (!level.isClientSide) { user.removeAllEffects(); } - + return stack.isEmpty() ? new ItemStack(Items.GLASS_BOTTLE) : stack; } } diff --git a/src/main/java/ru/bclib/items/BaseSpawnEggItem.java b/src/main/java/ru/bclib/items/BaseSpawnEggItem.java index 7badc6f9..6a221400 100644 --- a/src/main/java/ru/bclib/items/BaseSpawnEggItem.java +++ b/src/main/java/ru/bclib/items/BaseSpawnEggItem.java @@ -1,7 +1,5 @@ package ru.bclib.items; -import java.util.Optional; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; 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.PatternsHelper; +import java.util.Optional; + public class BaseSpawnEggItem extends SpawnEggItem implements ItemModelProvider { public BaseSpawnEggItem(EntityType type, int primaryColor, int secondaryColor, Properties settings) { super(type, primaryColor, secondaryColor, settings); diff --git a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java index 3836f161..92099882 100644 --- a/src/main/java/ru/bclib/items/tool/BaseAxeItem.java +++ b/src/main/java/ru/bclib/items/tool/BaseAxeItem.java @@ -20,7 +20,7 @@ public class BaseAxeItem extends AxeItem implements DynamicAttributeTool, ItemMo public BaseAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { super(material, attackDamage, attackSpeed, settings); } - + @Override public int getMiningLevel(Tag tag, BlockState state, ItemStack stack, LivingEntity user) { if (tag.equals(FabricToolTags.AXES)) { diff --git a/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java b/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java index 10495c5a..ec084197 100644 --- a/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java +++ b/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java @@ -1,15 +1,6 @@ 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 net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; 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.level.Level; 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.util.BackgroundInfo; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java b/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java index a78291c5..99fe6e8f 100644 --- a/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java +++ b/src/main/java/ru/bclib/mixin/client/EnchantingTableBlockMixin.java @@ -1,26 +1,25 @@ 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.particles.ParticleTypes; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EnchantmentTableBlock; 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 java.util.Random; + @Mixin(EnchantmentTableBlock.class) public abstract class EnchantingTableBlockMixin extends Block { public EnchantingTableBlockMixin(Properties settings) { super(settings); } - + @Inject(method = "animateTick", at = @At(value = "TAIL")) private void be_onRandomDisplayTick(BlockState state, Level world, BlockPos pos, Random random, CallbackInfo info) { for (int px = -2; px <= 2; ++px) { @@ -41,6 +40,6 @@ public abstract class EnchantingTableBlockMixin extends Block { } } } - + } } diff --git a/src/main/java/ru/bclib/mixin/client/ModelBakeryMixin.java b/src/main/java/ru/bclib/mixin/client/ModelBakeryMixin.java index bcad7100..cee9f054 100644 --- a/src/main/java/ru/bclib/mixin/client/ModelBakeryMixin.java +++ b/src/main/java/ru/bclib/mixin/client/ModelBakeryMixin.java @@ -1,16 +1,5 @@ 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.model.BlockModel; 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.level.block.Block; 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.client.models.BlockModelProvider; import ru.bclib.client.models.ItemModelProvider; +import java.util.List; +import java.util.Map; +import java.util.Optional; + @Mixin(ModelBakery.class) public abstract class ModelBakeryMixin { @Final @@ -36,10 +35,10 @@ public abstract class ModelBakeryMixin { @Final @Shadow private Map unbakedCache; - + @Shadow protected abstract void cacheAndQueueDependencies(ResourceLocation resourceLocation, UnbakedModel unbakedModel); - + @Inject(method = "loadModel", at = @At("HEAD"), cancellable = true) private void bclib_loadModels(ResourceLocation resourceLocation, CallbackInfo info) { if (resourceLocation instanceof ModelResourceLocation) { @@ -55,7 +54,8 @@ public abstract class ModelBakeryMixin { ItemModelProvider modelProvider = null; if (item instanceof ItemModelProvider) { modelProvider = (ItemModelProvider) item; - } else if (item instanceof BlockItem) { + } + else if (item instanceof BlockItem) { Block block = Registry.BLOCK.get(clearLoc); if (block instanceof ItemModelProvider) { modelProvider = (ItemModelProvider) block; @@ -67,21 +67,21 @@ public abstract class ModelBakeryMixin { model.name = itemLoc.toString(); cacheAndQueueDependencies(modelId, model); unbakedCache.put(itemLoc, model); - } else { + } + else { BCLib.LOGGER.warning("Error loading model: {}", itemLoc); } info.cancel(); } } - } else { + } + else { ResourceLocation stateLoc = new ResourceLocation(modId, "blockstates/" + path + ".json"); if (!resourceManager.hasResource(stateLoc)) { Block block = Registry.BLOCK.get(clearLoc); if (block instanceof BlockModelProvider) { List possibleStates = block.getStateDefinition().getPossibleStates(); - Optional possibleState = possibleStates.stream() - .filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state))) - .findFirst(); + Optional possibleState = possibleStates.stream().filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state))).findFirst(); if (possibleState.isPresent()) { UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache); if (modelVariant != null) { @@ -90,10 +90,12 @@ public abstract class ModelBakeryMixin { ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state); cacheAndQueueDependencies(stateId, modelVariant); }); - } else { + } + else { cacheAndQueueDependencies(modelId, modelVariant); } - } else { + } + else { BCLib.LOGGER.warning("Error loading variant: {}", modelId); } info.cancel(); diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 30ca8ef0..2d3a06d0 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -1,10 +1,5 @@ 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.MutableBlockPos; 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.Blocks; 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.BonemealAPI; import ru.bclib.api.TagAPI; @@ -25,7 +24,7 @@ import ru.bclib.util.MHelper; @Mixin(BoneMealItem.class) public class BoneMealItemMixin { private static final MutableBlockPos bclib_BLOCK_POS = new MutableBlockPos(); - + @Inject(method = "useOn", at = @At("HEAD"), cancellable = true) private void bclib_onUse(UseOnContext context, CallbackInfoReturnable info) { Level world = context.getLevel(); @@ -134,7 +133,7 @@ public class BoneMealItemMixin { block = BonemealAPI.getLandGrass(BiomeAPI.getBiomeID(world.getBiome(pos)), block, world.getRandom()); return block == null ? null : block.defaultBlockState(); } - + private BlockState bclib_getNylium(Level world, BlockPos pos) { Vec3i[] offsets = MHelper.getOffsets(world.getRandom()); for (Vec3i dir : offsets) { diff --git a/src/main/java/ru/bclib/mixin/common/ComposterBlockAccessor.java b/src/main/java/ru/bclib/mixin/common/ComposterBlockAccessor.java index 81a2ba6c..9aad31dc 100644 --- a/src/main/java/ru/bclib/mixin/common/ComposterBlockAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/ComposterBlockAccessor.java @@ -1,10 +1,9 @@ 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.block.ComposterBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(ComposterBlock.class) public interface ComposterBlockAccessor { diff --git a/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java b/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java index d0af1dd8..c5595382 100644 --- a/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java +++ b/src/main/java/ru/bclib/mixin/common/EnchantmentMenuMixin.java @@ -1,15 +1,5 @@ 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.world.Container; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -20,42 +10,51 @@ import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; 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 java.util.List; +import java.util.Random; + @Mixin(EnchantmentMenu.class) public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { @Final @Shadow private Container enchantSlots; - + @Final @Shadow private ContainerLevelAccess access; - + @Final @Shadow private Random random; - + @Final @Shadow private DataSlot enchantmentSeed; - + @Shadow @Final public int[] costs; - + @Shadow @Final public int[] enchantClue; - + @Shadow @Final public int[] levelClue; - + protected EnchantmentMenuMixin(MenuType type, int syncId) { super(type, syncId); } - + @Inject(method = "slotsChanged", at = @At("HEAD"), cancellable = true) private void be_slotsChanged(Container inventory, CallbackInfo info) { if (inventory == this.enchantSlots) { @@ -63,7 +62,7 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { if (!itemStack.isEmpty() && itemStack.isEnchantable()) { this.access.execute((world, blockPos) -> { int i = 0; - + int j; for (j = -1; j <= 1; ++j) { for (int k = -1; k <= 1; ++k) { @@ -71,24 +70,24 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { if (world.getBlockState(blockPos.offset(k * 2, 0, j * 2)).is(TagAPI.BOOKSHELVES)) { ++i; } - + if (world.getBlockState(blockPos.offset(k * 2, 1, j * 2)).is(TagAPI.BOOKSHELVES)) { ++i; } - + if (k != 0 && j != 0) { if (world.getBlockState(blockPos.offset(k * 2, 0, j)).is(TagAPI.BOOKSHELVES)) { ++i; } - + if (world.getBlockState(blockPos.offset(k * 2, 1, j)).is(TagAPI.BOOKSHELVES)) { ++i; } - + if (world.getBlockState(blockPos.offset(k, 0, j * 2)).is(TagAPI.BOOKSHELVES)) { ++i; } - + if (world.getBlockState(blockPos.offset(k, 1, j * 2)).is(TagAPI.BOOKSHELVES)) { ++i; } @@ -96,9 +95,9 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { } } } - + random.setSeed(enchantmentSeed.get()); - + for (j = 0; j < 3; ++j) { costs[j] = EnchantmentHelper.getEnchantmentCost(this.random, j, i, itemStack); enchantClue[j] = -1; @@ -107,7 +106,7 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { costs[j] = 0; } } - + for (j = 0; j < 3; ++j) { if (this.costs[j] > 0) { List list = this.getEnchantmentList(itemStack, j, this.costs[j]); @@ -118,7 +117,7 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { } } } - + broadcastChanges(); }); } @@ -132,7 +131,7 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu { info.cancel(); } } - + @Shadow private List getEnchantmentList(ItemStack stack, int slot, int level) { return null; diff --git a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java index d54b39cc..ba18731a 100644 --- a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java @@ -1,16 +1,9 @@ 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 org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import java.util.Map; - @Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators") public interface FeatureDecoratorsAccessor { @Accessor("HEIGHTMAP_SQUARE") diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index 1cf79d29..fe2b5897 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -1,17 +1,5 @@ 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.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -19,9 +7,20 @@ import net.minecraft.server.ServerResources; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; 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.recipes.BCLRecipeManager; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + @Mixin(MinecraftServer.class) public class MinecraftServerMixin { @Shadow @@ -34,18 +33,18 @@ public class MinecraftServerMixin { @Final @Shadow protected WorldData worldData; - + @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) private void bcl_reloadResources(Collection collection, CallbackInfoReturnable> info) { bcl_injectRecipes(); } - + @Inject(method = "loadLevel", at = @At(value = "RETURN"), cancellable = true) private void bcl_loadLevel(CallbackInfo info) { bcl_injectRecipes(); BiomeAPI.initRegistry(MinecraftServer.class.cast(this)); } - + private void bcl_injectRecipes() { if (FabricLoader.getInstance().isModLoaded("kubejs")) { RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager(); diff --git a/src/main/java/ru/bclib/mixin/common/PotionBrewingAccessor.java b/src/main/java/ru/bclib/mixin/common/PotionBrewingAccessor.java index b0c8e3f4..ac5f7d11 100644 --- a/src/main/java/ru/bclib/mixin/common/PotionBrewingAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/PotionBrewingAccessor.java @@ -1,11 +1,10 @@ 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.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionBrewing; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(PotionBrewing.class) public interface PotionBrewingAccessor { diff --git a/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java b/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java index e3dece33..c17bfdfd 100644 --- a/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java @@ -1,20 +1,19 @@ 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.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; 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) public interface RecipeManagerAccessor { @Accessor("recipes") Map, Map>> bcl_getRecipes(); - + @Accessor("recipes") void bcl_setRecipes(Map, Map>> recipes); } \ No newline at end of file diff --git a/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java b/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java index 5c2092f6..07561ff4 100644 --- a/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/RecipeManagerMixin.java @@ -1,20 +1,6 @@ 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 net.minecraft.Util; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; @@ -24,23 +10,35 @@ import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeType; 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 java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; + @Mixin(RecipeManager.class) public abstract class RecipeManagerMixin { @Shadow private Map, Map>> recipes; - + @Inject(method = "apply", at = @At(value = "RETURN")) private void be_apply(Map map, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo info) { recipes = BCLRecipeManager.getMap(recipes); } - + @Shadow private > Map> byType(RecipeType type) { return null; } - + /** * @author paulevs * @reason Remove conflicts with vanilla tags @@ -56,7 +54,7 @@ public abstract class RecipeManagerMixin { boolean b2 = v2.getId().getNamespace().equals("minecraft"); return b1 ^ b2 ? (b1 ? 1 : -1) : 0; }); - + return list.stream().flatMap((recipe) -> { return Util.toStream(type.tryMatch(recipe, world, inventory)); }).findFirst(); diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index ef881e4d..6a62af48 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,15 +1,5 @@ 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.server.MinecraftServer; 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.ServerLevelData; 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.DataFixerAPI; 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) public abstract class ServerLevelMixin extends Level { private static String bcl_lastWorld = null; diff --git a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java index ced2df40..0fa5be52 100644 --- a/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java +++ b/src/main/java/ru/bclib/mixin/common/TagLoaderMixin.java @@ -1,7 +1,5 @@ package ru.bclib.mixin.common; -import java.util.Map; - import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; import net.minecraft.tags.TagLoader; @@ -11,11 +9,13 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; import ru.bclib.util.TagHelper; +import java.util.Map; + @Mixin(TagLoader.class) public class TagLoaderMixin { @Shadow private String directory; - + @ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Lnet/minecraft/tags/TagCollection;")) public Map be_modifyTags(Map tagsMap) { return TagHelper.apply(directory, tagsMap); diff --git a/src/main/java/ru/bclib/noise/OpenSimplexNoise.java b/src/main/java/ru/bclib/noise/OpenSimplexNoise.java index d002334f..0c2ef0dd 100644 --- a/src/main/java/ru/bclib/noise/OpenSimplexNoise.java +++ b/src/main/java/ru/bclib/noise/OpenSimplexNoise.java @@ -3,7 +3,7 @@ package ru.bclib.noise; /* * OpenSimplex Noise in Java. * by Kurt Spencer - * + * * v1.1 (October 5, 2014) * - Added 2D and 4D implementations. * - Proper gradient sets for all dimensions, from a @@ -23,31 +23,31 @@ public class OpenSimplexNoise { private static final double SQUISH_CONSTANT_3D = 1.0 / 3; // (Math.sqrt(3+1)-1)/3; private static final double STRETCH_CONSTANT_4D = -0.138196601125011; // (1/Math.sqrt(4+1)-1)/4; private static final double SQUISH_CONSTANT_4D = 0.309016994374947; // (Math.sqrt(4+1)-1)/4; - + private static final double NORM_CONSTANT_2D = 47; private static final double NORM_CONSTANT_3D = 103; private static final double NORM_CONSTANT_4D = 30; - + private static final long DEFAULT_SEED = 0; - + private short[] perm; private short[] permGradIndex3D; - + public OpenSimplexNoise() { this(DEFAULT_SEED); } - + public OpenSimplexNoise(short[] perm) { this.perm = perm; permGradIndex3D = new short[256]; - + for (int i = 0; i < 256; i++) { // Since 3D has 24 gradients, simple bitmask won't work, so // precompute modulo array. permGradIndex3D[i] = (short) ((perm[i] % (gradients3D.length / 3)) * 3); } } - + // Initializes the class using a permutation array generated from a 64-bit // seed. // Generates a proper permutation (i.e. doesn't merely perform N successive @@ -57,60 +57,60 @@ public class OpenSimplexNoise { perm = new short[256]; permGradIndex3D = new short[256]; short[] source = new short[256]; - for (short i = 0; i < 256; i++) + for (short i = 0; i < 256; i++) { source[i] = i; + } seed = seed * 6364136223846793005l + 1442695040888963407l; seed = seed * 6364136223846793005l + 1442695040888963407l; seed = seed * 6364136223846793005l + 1442695040888963407l; for (int i = 255; i >= 0; i--) { seed = seed * 6364136223846793005l + 1442695040888963407l; int r = (int) ((seed + 31) % (i + 1)); - if (r < 0) - r += (i + 1); + if (r < 0) r += (i + 1); perm[i] = source[r]; permGradIndex3D[i] = (short) ((perm[i] % (gradients3D.length / 3)) * 3); source[r] = source[i]; } } - + // 2D OpenSimplex Noise. public double eval(double x, double y) { - + // Place input coordinates onto grid. double stretchOffset = (x + y) * STRETCH_CONSTANT_2D; double xs = x + stretchOffset; double ys = y + stretchOffset; - + // Floor to get grid coordinates of rhombus (stretched square) // super-cell origin. int xsb = fastFloor(xs); int ysb = fastFloor(ys); - + // Skew out to get actual coordinates of rhombus origin. We'll need // these later. double squishOffset = (xsb + ysb) * SQUISH_CONSTANT_2D; double xb = xsb + squishOffset; double yb = ysb + squishOffset; - + // Compute grid coordinates relative to rhombus origin. double xins = xs - xsb; double yins = ys - ysb; - + // Sum those together to get a value that determines which region we're // in. double inSum = xins + yins; - + // Positions relative to origin point. double dx0 = x - xb; double dy0 = y - yb; - + // We'll be defining these inside the next block and using them // afterwards. double dx_ext, dy_ext; int xsv_ext, ysv_ext; - + double value = 0; - + // Contribution (1,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_2D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_2D; @@ -119,7 +119,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, dx1, dy1); } - + // Contribution (0,1) double dx2 = dx0 - 0 - SQUISH_CONSTANT_2D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_2D; @@ -128,44 +128,49 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, dx2, dy2); } - + if (inSum <= 1) { // We're inside the triangle (2-Simplex) at (0,0) double zins = 1 - inSum; if (zins > xins || zins > yins) { // (0,0) is one of the closest two - // triangular vertices + // triangular vertices if (xins > yins) { xsv_ext = xsb + 1; ysv_ext = ysb - 1; dx_ext = dx0 - 1; dy_ext = dy0 + 1; - } else { + } + else { xsv_ext = xsb - 1; ysv_ext = ysb + 1; dx_ext = dx0 + 1; dy_ext = dy0 - 1; } - } else { // (1,0) and (0,1) are the closest two vertices. + } + else { // (1,0) and (0,1) are the closest two vertices. xsv_ext = xsb + 1; ysv_ext = ysb + 1; dx_ext = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; } - } else { // We're inside the triangle (2-Simplex) at (1,1) + } + else { // We're inside the triangle (2-Simplex) at (1,1) double zins = 2 - inSum; if (zins < xins || zins < yins) { // (0,0) is one of the closest two - // triangular vertices + // triangular vertices if (xins > yins) { xsv_ext = xsb + 2; ysv_ext = ysb + 0; dx_ext = dx0 - 2 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 + 0 - 2 * SQUISH_CONSTANT_2D; - } else { + } + else { xsv_ext = xsb + 0; ysv_ext = ysb + 2; dx_ext = dx0 + 0 - 2 * SQUISH_CONSTANT_2D; dy_ext = dy0 - 2 - 2 * SQUISH_CONSTANT_2D; } - } else { // (1,0) and (0,1) are the closest two vertices. + } + else { // (1,0) and (0,1) are the closest two vertices. dx_ext = dx0; dy_ext = dy0; xsv_ext = xsb; @@ -176,71 +181,71 @@ public class OpenSimplexNoise { dx0 = dx0 - 1 - 2 * SQUISH_CONSTANT_2D; dy0 = dy0 - 1 - 2 * SQUISH_CONSTANT_2D; } - + // Contribution (0,0) or (1,1) double attn0 = 2 - dx0 * dx0 - dy0 * dy0; if (attn0 > 0) { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb, ysb, dx0, dy0); } - + // Extra Vertex double attn_ext = 2 - dx_ext * dx_ext - dy_ext * dy_ext; if (attn_ext > 0) { attn_ext *= attn_ext; value += attn_ext * attn_ext * extrapolate(xsv_ext, ysv_ext, dx_ext, dy_ext); } - + return value / NORM_CONSTANT_2D; } - + // 3D OpenSimplex Noise. public double eval(double x, double y, double z) { - + // Place input coordinates on simplectic honeycomb. double stretchOffset = (x + y + z) * STRETCH_CONSTANT_3D; double xs = x + stretchOffset; double ys = y + stretchOffset; double zs = z + stretchOffset; - + // Floor to get simplectic honeycomb coordinates of rhombohedron // (stretched cube) super-cell origin. int xsb = fastFloor(xs); int ysb = fastFloor(ys); int zsb = fastFloor(zs); - + // Skew out to get actual coordinates of rhombohedron origin. We'll need // these later. double squishOffset = (xsb + ysb + zsb) * SQUISH_CONSTANT_3D; double xb = xsb + squishOffset; double yb = ysb + squishOffset; double zb = zsb + squishOffset; - + // Compute simplectic honeycomb coordinates relative to rhombohedral // origin. double xins = xs - xsb; double yins = ys - ysb; double zins = zs - zsb; - + // Sum those together to get a value that determines which region we're // in. double inSum = xins + yins + zins; - + // Positions relative to origin point. double dx0 = x - xb; double dy0 = y - yb; double dz0 = z - zb; - + // We'll be defining these inside the next block and using them // afterwards. double dx_ext0, dy_ext0, dz_ext0; double dx_ext1, dy_ext1, dz_ext1; int xsv_ext0, ysv_ext0, zsv_ext0; int xsv_ext1, ysv_ext1, zsv_ext1; - + double value = 0; if (inSum <= 1) { // We're inside the tetrahedron (3-Simplex) at (0,0,0) - + // Determine which two of (0,0,1), (0,1,0), (1,0,0) are closest. byte aPoint = 0x01; double aScore = xins; @@ -249,106 +254,115 @@ public class OpenSimplexNoise { if (aScore >= bScore && zins > bScore) { bScore = zins; bPoint = 0x04; - } else if (aScore < bScore && zins > aScore) { + } + else if (aScore < bScore && zins > aScore) { aScore = zins; aPoint = 0x04; } - + // Now we determine the two lattice points not part of the // tetrahedron that may contribute. // This depends on the closest two tetrahedral vertices, including // (0,0,0) double wins = 1 - inSum; if (wins > aScore || wins > bScore) { // (0,0,0) is one of the - // closest two tetrahedral - // vertices. + // closest two tetrahedral + // vertices. byte c = (bScore > aScore ? bPoint : aPoint); // Our other - // closest - // vertex is the - // closest out - // of a and b. - + // closest + // vertex is the + // closest out + // of a and b. + if ((c & 0x01) == 0) { xsv_ext0 = xsb - 1; xsv_ext1 = xsb; dx_ext0 = dx0 + 1; dx_ext1 = dx0; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx_ext1 = dx0 - 1; } - + if ((c & 0x02) == 0) { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0; if ((c & 0x01) == 0) { ysv_ext1 -= 1; dy_ext1 += 1; - } else { + } + else { ysv_ext0 -= 1; dy_ext0 += 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1; } - + if ((c & 0x04) == 0) { zsv_ext0 = zsb; zsv_ext1 = zsb - 1; dz_ext0 = dz0; dz_ext1 = dz0 + 1; - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1; } - } else { // (0,0,0) is not one of the closest two tetrahedral - // vertices. + } + else { // (0,0,0) is not one of the closest two tetrahedral + // vertices. byte c = (byte) (aPoint | bPoint); // Our two extra vertices are - // determined by the closest - // two. - + // determined by the closest + // two. + if ((c & 0x01) == 0) { xsv_ext0 = xsb; xsv_ext1 = xsb - 1; dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; } - + if ((c & 0x02) == 0) { ysv_ext0 = ysb; ysv_ext1 = ysb - 1; dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; } - + if ((c & 0x04) == 0) { zsv_ext0 = zsb; zsv_ext1 = zsb - 1; dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; } } - + // Contribution (0,0,0) double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0; if (attn0 > 0) { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, dx0, dy0, dz0); } - + // Contribution (1,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; @@ -358,7 +372,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); } - + // Contribution (0,1,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; @@ -368,7 +382,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); } - + // Contribution (0,0,1) double dx3 = dx2; double dy3 = dy1; @@ -378,9 +392,10 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); } - } else if (inSum >= 2) { // We're inside the tetrahedron (3-Simplex) at - // (1,1,1) - + } + else if (inSum >= 2) { // We're inside the tetrahedron (3-Simplex) at + // (1,1,1) + // Determine which two tetrahedral vertices are the closest, out of // (1,1,0), (1,0,1), (0,1,1) but not (1,1,1). byte aPoint = 0x06; @@ -390,99 +405,108 @@ public class OpenSimplexNoise { if (aScore <= bScore && zins < bScore) { bScore = zins; bPoint = 0x03; - } else if (aScore > bScore && zins < aScore) { + } + else if (aScore > bScore && zins < aScore) { aScore = zins; aPoint = 0x03; } - + // Now we determine the two lattice points not part of the // tetrahedron that may contribute. // This depends on the closest two tetrahedral vertices, including // (1,1,1) double wins = 3 - inSum; if (wins < aScore || wins < bScore) { // (1,1,1) is one of the - // closest two tetrahedral - // vertices. + // closest two tetrahedral + // vertices. byte c = (bScore < aScore ? bPoint : aPoint); // Our other - // closest - // vertex is the - // closest out - // of a and b. - + // closest + // vertex is the + // closest out + // of a and b. + if ((c & 0x01) != 0) { xsv_ext0 = xsb + 2; xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_3D; } - + if ((c & 0x02) != 0) { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; if ((c & 0x01) != 0) { ysv_ext1 += 1; dy_ext1 -= 1; - } else { + } + else { ysv_ext0 += 1; dy_ext0 -= 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_3D; } - + if ((c & 0x04) != 0) { zsv_ext0 = zsb + 1; zsv_ext1 = zsb + 2; dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 3 * SQUISH_CONSTANT_3D; - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_3D; } - } else { // (1,1,1) is not one of the closest two tetrahedral - // vertices. + } + else { // (1,1,1) is not one of the closest two tetrahedral + // vertices. byte c = (byte) (aPoint & bPoint); // Our two extra vertices are - // determined by the closest - // two. - + // determined by the closest + // two. + if ((c & 0x01) != 0) { xsv_ext0 = xsb + 1; xsv_ext1 = xsb + 2; dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx0 - SQUISH_CONSTANT_3D; dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; } - + if ((c & 0x02) != 0) { ysv_ext0 = ysb + 1; ysv_ext1 = ysb + 2; dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy0 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; } - + if ((c & 0x04) != 0) { zsv_ext0 = zsb + 1; zsv_ext1 = zsb + 2; dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz0 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; } } - + // Contribution (1,1,0) double dx3 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; double dy3 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; @@ -492,7 +516,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx3, dy3, dz3); } - + // Contribution (1,0,1) double dx2 = dx3; double dy2 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; @@ -502,7 +526,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx2, dy2, dz2); } - + // Contribution (0,1,1) double dx1 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; double dy1 = dy3; @@ -512,7 +536,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx1, dy1, dz1); } - + // Contribution (1,1,1) dx0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; dy0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; @@ -522,39 +546,42 @@ public class OpenSimplexNoise { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, dx0, dy0, dz0); } - } else { // We're inside the octahedron (Rectified 3-Simplex) in - // between. + } + else { // We're inside the octahedron (Rectified 3-Simplex) in + // between. double aScore; byte aPoint; boolean aIsFurtherSide; double bScore; byte bPoint; boolean bIsFurtherSide; - + // Decide between point (0,0,1) and (1,1,0) as closest double p1 = xins + yins; if (p1 > 1) { aScore = p1 - 1; aPoint = 0x03; aIsFurtherSide = true; - } else { + } + else { aScore = 1 - p1; aPoint = 0x04; aIsFurtherSide = false; } - + // Decide between point (0,1,0) and (1,0,1) as closest double p2 = xins + zins; if (p2 > 1) { bScore = p2 - 1; bPoint = 0x05; bIsFurtherSide = true; - } else { + } + else { bScore = 1 - p2; bPoint = 0x02; bIsFurtherSide = false; } - + // The closest out of the two (1,0,0) and (0,1,1) will replace the // furthest out of the two decided above, if closer. double p3 = yins + zins; @@ -564,29 +591,32 @@ public class OpenSimplexNoise { aScore = score; aPoint = 0x06; aIsFurtherSide = true; - } else if (aScore > bScore && bScore < score) { + } + else if (aScore > bScore && bScore < score) { bScore = score; bPoint = 0x06; bIsFurtherSide = true; } - } else { + } + else { double score = 1 - p3; if (aScore <= bScore && aScore < score) { aScore = score; aPoint = 0x01; aIsFurtherSide = false; - } else if (aScore > bScore && bScore < score) { + } + else if (aScore > bScore && bScore < score) { bScore = score; bPoint = 0x01; bIsFurtherSide = false; } } - + // Where each of the two closest points are determines how the extra // two vertices are calculated. if (aIsFurtherSide == bIsFurtherSide) { if (aIsFurtherSide) { // Both closest points on (1,1,1) side - + // One of the two extra points is (1,1,1) dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_3D; dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_3D; @@ -594,7 +624,7 @@ public class OpenSimplexNoise { xsv_ext0 = xsb + 1; ysv_ext0 = ysb + 1; zsv_ext0 = zsb + 1; - + // Other extra point is based on the shared axis. byte c = (byte) (aPoint & bPoint); if ((c & 0x01) != 0) { @@ -604,14 +634,16 @@ public class OpenSimplexNoise { xsv_ext1 = xsb + 2; ysv_ext1 = ysb; zsv_ext1 = zsb; - } else if ((c & 0x02) != 0) { + } + else if ((c & 0x02) != 0) { dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 * SQUISH_CONSTANT_3D; xsv_ext1 = xsb; ysv_ext1 = ysb + 2; zsv_ext1 = zsb; - } else { + } + else { dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 2 - 2 * SQUISH_CONSTANT_3D; @@ -619,8 +651,9 @@ public class OpenSimplexNoise { ysv_ext1 = ysb; zsv_ext1 = zsb + 2; } - } else {// Both closest points on (0,0,0) side - + } + else {// Both closest points on (0,0,0) side + // One of the two extra points is (0,0,0) dx_ext0 = dx0; dy_ext0 = dy0; @@ -628,7 +661,7 @@ public class OpenSimplexNoise { xsv_ext0 = xsb; ysv_ext0 = ysb; zsv_ext0 = zsb; - + // Other extra point is based on the omitted axis. byte c = (byte) (aPoint | bPoint); if ((c & 0x01) == 0) { @@ -638,14 +671,16 @@ public class OpenSimplexNoise { xsv_ext1 = xsb - 1; ysv_ext1 = ysb + 1; zsv_ext1 = zsb + 1; - } else if ((c & 0x02) == 0) { + } + else if ((c & 0x02) == 0) { dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 + 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext1 = xsb + 1; ysv_ext1 = ysb - 1; zsv_ext1 = zsb + 1; - } else { + } + else { dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext1 = dz0 + 1 - SQUISH_CONSTANT_3D; @@ -654,16 +689,18 @@ public class OpenSimplexNoise { zsv_ext1 = zsb - 1; } } - } else { // One point on (0,0,0) side, one point on (1,1,1) side + } + else { // One point on (0,0,0) side, one point on (1,1,1) side byte c1, c2; if (aIsFurtherSide) { c1 = aPoint; c2 = bPoint; - } else { + } + else { c1 = bPoint; c2 = aPoint; } - + // One contribution is a permutation of (1,1,-1) if ((c1 & 0x01) == 0) { dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_3D; @@ -672,14 +709,16 @@ public class OpenSimplexNoise { xsv_ext0 = xsb - 1; ysv_ext0 = ysb + 1; zsv_ext0 = zsb + 1; - } else if ((c1 & 0x02) == 0) { + } + else if ((c1 & 0x02) == 0) { dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext0 = dy0 + 1 - SQUISH_CONSTANT_3D; dz_ext0 = dz0 - 1 - SQUISH_CONSTANT_3D; xsv_ext0 = xsb + 1; ysv_ext0 = ysb - 1; zsv_ext0 = zsb + 1; - } else { + } + else { dx_ext0 = dx0 - 1 - SQUISH_CONSTANT_3D; dy_ext0 = dy0 - 1 - SQUISH_CONSTANT_3D; dz_ext0 = dz0 + 1 - SQUISH_CONSTANT_3D; @@ -687,7 +726,7 @@ public class OpenSimplexNoise { ysv_ext0 = ysb + 1; zsv_ext0 = zsb - 1; } - + // One contribution is a permutation of (0,0,2) dx_ext1 = dx0 - 2 * SQUISH_CONSTANT_3D; dy_ext1 = dy0 - 2 * SQUISH_CONSTANT_3D; @@ -698,15 +737,17 @@ public class OpenSimplexNoise { if ((c2 & 0x01) != 0) { dx_ext1 -= 2; xsv_ext1 += 2; - } else if ((c2 & 0x02) != 0) { + } + else if ((c2 & 0x02) != 0) { dy_ext1 -= 2; ysv_ext1 += 2; - } else { + } + else { dz_ext1 -= 2; zsv_ext1 += 2; } } - + // Contribution (1,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_3D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_3D; @@ -716,7 +757,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, dx1, dy1, dz1); } - + // Contribution (0,1,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_3D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_3D; @@ -726,7 +767,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, dx2, dy2, dz2); } - + // Contribution (0,0,1) double dx3 = dx2; double dy3 = dy1; @@ -736,7 +777,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, dx3, dy3, dz3); } - + // Contribution (1,1,0) double dx4 = dx0 - 1 - 2 * SQUISH_CONSTANT_3D; double dy4 = dy0 - 1 - 2 * SQUISH_CONSTANT_3D; @@ -746,7 +787,7 @@ public class OpenSimplexNoise { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 0, dx4, dy4, dz4); } - + // Contribution (1,0,1) double dx5 = dx4; double dy5 = dy0 - 0 - 2 * SQUISH_CONSTANT_3D; @@ -756,7 +797,7 @@ public class OpenSimplexNoise { attn5 *= attn5; value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 0, zsb + 1, dx5, dy5, dz5); } - + // Contribution (0,1,1) double dx6 = dx0 - 0 - 2 * SQUISH_CONSTANT_3D; double dy6 = dy4; @@ -767,41 +808,41 @@ public class OpenSimplexNoise { value += attn6 * attn6 * extrapolate(xsb + 0, ysb + 1, zsb + 1, dx6, dy6, dz6); } } - + // First extra vertex double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0; if (attn_ext0 > 0) { attn_ext0 *= attn_ext0; value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, dx_ext0, dy_ext0, dz_ext0); } - + // Second extra vertex double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1; if (attn_ext1 > 0) { attn_ext1 *= attn_ext1; value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, dx_ext1, dy_ext1, dz_ext1); } - + return value / NORM_CONSTANT_3D; } - + // 4D OpenSimplex Noise. public double eval(double x, double y, double z, double w) { - + // Place input coordinates on simplectic honeycomb. double stretchOffset = (x + y + z + w) * STRETCH_CONSTANT_4D; double xs = x + stretchOffset; double ys = y + stretchOffset; double zs = z + stretchOffset; double ws = w + stretchOffset; - + // Floor to get simplectic honeycomb coordinates of rhombo-hypercube // super-cell origin. int xsb = fastFloor(xs); int ysb = fastFloor(ys); int zsb = fastFloor(zs); int wsb = fastFloor(ws); - + // Skew out to get actual coordinates of stretched rhombo-hypercube // origin. We'll need these later. double squishOffset = (xsb + ysb + zsb + wsb) * SQUISH_CONSTANT_4D; @@ -809,24 +850,24 @@ public class OpenSimplexNoise { double yb = ysb + squishOffset; double zb = zsb + squishOffset; double wb = wsb + squishOffset; - + // Compute simplectic honeycomb coordinates relative to rhombo-hypercube // origin. double xins = xs - xsb; double yins = ys - ysb; double zins = zs - zsb; double wins = ws - wsb; - + // Sum those together to get a value that determines which region we're // in. double inSum = xins + yins + zins + wins; - + // Positions relative to origin point. double dx0 = x - xb; double dy0 = y - yb; double dz0 = z - zb; double dw0 = w - wb; - + // We'll be defining these inside the next block and using them // afterwards. double dx_ext0, dy_ext0, dz_ext0, dw_ext0; @@ -835,11 +876,11 @@ public class OpenSimplexNoise { int xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0; int xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1; int xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2; - + double value = 0; if (inSum <= 1) { // We're inside the pentachoron (4-Simplex) at - // (0,0,0,0) - + // (0,0,0,0) + // Determine which two of (0,0,0,1), (0,0,1,0), (0,1,0,0), (1,0,0,0) // are closest. byte aPoint = 0x01; @@ -849,56 +890,61 @@ public class OpenSimplexNoise { if (aScore >= bScore && zins > bScore) { bScore = zins; bPoint = 0x04; - } else if (aScore < bScore && zins > aScore) { + } + else if (aScore < bScore && zins > aScore) { aScore = zins; aPoint = 0x04; } if (aScore >= bScore && wins > bScore) { bScore = wins; bPoint = 0x08; - } else if (aScore < bScore && wins > aScore) { + } + else if (aScore < bScore && wins > aScore) { aScore = wins; aPoint = 0x08; } - + // Now we determine the three lattice points not part of the // pentachoron that may contribute. // This depends on the closest two pentachoron vertices, including // (0,0,0,0) double uins = 1 - inSum; if (uins > aScore || uins > bScore) { // (0,0,0,0) is one of the - // closest two pentachoron - // vertices. + // closest two pentachoron + // vertices. byte c = (bScore > aScore ? bPoint : aPoint); // Our other - // closest - // vertex is the - // closest out - // of a and b. + // closest + // vertex is the + // closest out + // of a and b. if ((c & 0x01) == 0) { xsv_ext0 = xsb - 1; xsv_ext1 = xsv_ext2 = xsb; dx_ext0 = dx0 + 1; dx_ext1 = dx_ext2 = dx0; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 1; } - + if ((c & 0x02) == 0) { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; dy_ext0 = dy_ext1 = dy_ext2 = dy0; if ((c & 0x01) == 0x01) { ysv_ext0 -= 1; dy_ext0 += 1; - } else { + } + else { ysv_ext1 -= 1; dy_ext1 += 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1; } - + if ((c & 0x04) == 0) { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; dz_ext0 = dz_ext1 = dz_ext2 = dz0; @@ -906,46 +952,52 @@ public class OpenSimplexNoise { if ((c & 0x03) == 0x03) { zsv_ext0 -= 1; dz_ext0 += 1; - } else { + } + else { zsv_ext1 -= 1; dz_ext1 += 1; } - } else { + } + else { zsv_ext2 -= 1; dz_ext2 += 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1; } - + if ((c & 0x08) == 0) { wsv_ext0 = wsv_ext1 = wsb; wsv_ext2 = wsb - 1; dw_ext0 = dw_ext1 = dw0; dw_ext2 = dw0 + 1; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 1; } - } else { // (0,0,0,0) is not one of the closest two pentachoron - // vertices. + } + else { // (0,0,0,0) is not one of the closest two pentachoron + // vertices. byte c = (byte) (aPoint | bPoint); // Our three extra vertices - // are determined by the - // closest two. - + // are determined by the + // closest two. + if ((c & 0x01) == 0) { xsv_ext0 = xsv_ext2 = xsb; xsv_ext1 = xsb - 1; dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 + 1 - SQUISH_CONSTANT_4D; dx_ext2 = dx0 - SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb + 1; dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; dx_ext1 = dx_ext2 = dx0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x02) == 0) { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D; @@ -953,16 +1005,18 @@ public class OpenSimplexNoise { if ((c & 0x01) == 0x01) { ysv_ext1 -= 1; dy_ext1 += 1; - } else { + } + else { ysv_ext2 -= 1; dy_ext2 += 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; dy_ext1 = dy_ext2 = dy0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x04) == 0) { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D; @@ -970,36 +1024,39 @@ public class OpenSimplexNoise { if ((c & 0x03) == 0x03) { zsv_ext1 -= 1; dz_ext1 += 1; - } else { + } + else { zsv_ext2 -= 1; dz_ext2 += 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; dz_ext1 = dz_ext2 = dz0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x08) == 0) { wsv_ext0 = wsv_ext1 = wsb; wsv_ext2 = wsb - 1; dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 - SQUISH_CONSTANT_4D; dw_ext2 = dw0 + 1 - SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb + 1; dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; dw_ext1 = dw_ext2 = dw0 - 1 - SQUISH_CONSTANT_4D; } } - + // Contribution (0,0,0,0) double attn0 = 2 - dx0 * dx0 - dy0 * dy0 - dz0 * dz0 - dw0 * dw0; if (attn0 > 0) { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 0, dx0, dy0, dz0, dw0); } - + // Contribution (1,0,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D; @@ -1010,7 +1067,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); } - + // Contribution (0,1,0,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D; @@ -1021,7 +1078,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); } - + // Contribution (0,0,1,0) double dx3 = dx2; double dy3 = dy1; @@ -1032,7 +1089,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); } - + // Contribution (0,0,0,1) double dx4 = dx2; double dy4 = dy1; @@ -1043,11 +1100,12 @@ public class OpenSimplexNoise { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); } - } else if (inSum >= 3) { // We're inside the pentachoron (4-Simplex) at - // (1,1,1,1) - // Determine which two of (1,1,1,0), - // (1,1,0,1), (1,0,1,1), (0,1,1,1) - // are closest. + } + else if (inSum >= 3) { // We're inside the pentachoron (4-Simplex) at + // (1,1,1,1) + // Determine which two of (1,1,1,0), + // (1,1,0,1), (1,0,1,1), (0,1,1,1) + // are closest. byte aPoint = 0x0E; double aScore = xins; byte bPoint = 0x0D; @@ -1055,57 +1113,62 @@ public class OpenSimplexNoise { if (aScore <= bScore && zins < bScore) { bScore = zins; bPoint = 0x0B; - } else if (aScore > bScore && zins < aScore) { + } + else if (aScore > bScore && zins < aScore) { aScore = zins; aPoint = 0x0B; } if (aScore <= bScore && wins < bScore) { bScore = wins; bPoint = 0x07; - } else if (aScore > bScore && wins < aScore) { + } + else if (aScore > bScore && wins < aScore) { aScore = wins; aPoint = 0x07; } - + // Now we determine the three lattice points not part of the // pentachoron that may contribute. // This depends on the closest two pentachoron vertices, including // (0,0,0,0) double uins = 4 - inSum; if (uins < aScore || uins < bScore) { // (1,1,1,1) is one of the - // closest two pentachoron - // vertices. + // closest two pentachoron + // vertices. byte c = (bScore < aScore ? bPoint : aPoint); // Our other - // closest - // vertex is the - // closest out - // of a and b. - + // closest + // vertex is the + // closest out + // of a and b. + if ((c & 0x01) != 0) { xsv_ext0 = xsb + 2; xsv_ext1 = xsv_ext2 = xsb + 1; dx_ext0 = dx0 - 2 - 4 * SQUISH_CONSTANT_4D; dx_ext1 = dx_ext2 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; dx_ext0 = dx_ext1 = dx_ext2 = dx0 - 4 * SQUISH_CONSTANT_4D; } - + if ((c & 0x02) != 0) { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; if ((c & 0x01) != 0) { ysv_ext1 += 1; dy_ext1 -= 1; - } else { + } + else { ysv_ext0 += 1; dy_ext0 -= 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; dy_ext0 = dy_ext1 = dy_ext2 = dy0 - 4 * SQUISH_CONSTANT_4D; } - + if ((c & 0x04) != 0) { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D; @@ -1113,46 +1176,52 @@ public class OpenSimplexNoise { if ((c & 0x03) == 0) { zsv_ext0 += 1; dz_ext0 -= 1; - } else { + } + else { zsv_ext1 += 1; dz_ext1 -= 1; } - } else { + } + else { zsv_ext2 += 1; dz_ext2 -= 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; dz_ext0 = dz_ext1 = dz_ext2 = dz0 - 4 * SQUISH_CONSTANT_4D; } - + if ((c & 0x08) != 0) { wsv_ext0 = wsv_ext1 = wsb + 1; wsv_ext2 = wsb + 2; dw_ext0 = dw_ext1 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D; dw_ext2 = dw0 - 2 - 4 * SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; dw_ext0 = dw_ext1 = dw_ext2 = dw0 - 4 * SQUISH_CONSTANT_4D; } - } else { // (1,1,1,1) is not one of the closest two pentachoron - // vertices. + } + else { // (1,1,1,1) is not one of the closest two pentachoron + // vertices. byte c = (byte) (aPoint & bPoint); // Our three extra vertices - // are determined by the - // closest two. - + // are determined by the + // closest two. + if ((c & 0x01) != 0) { xsv_ext0 = xsv_ext2 = xsb + 1; xsv_ext1 = xsb + 2; dx_ext0 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; dx_ext2 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsv_ext2 = xsb; dx_ext0 = dx0 - 2 * SQUISH_CONSTANT_4D; dx_ext1 = dx_ext2 = dx0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x02) != 0) { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb + 1; dy_ext0 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -1160,16 +1229,18 @@ public class OpenSimplexNoise { if ((c & 0x01) != 0) { ysv_ext2 += 1; dy_ext2 -= 1; - } else { + } + else { ysv_ext1 += 1; dy_ext1 -= 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysv_ext2 = ysb; dy_ext0 = dy0 - 2 * SQUISH_CONSTANT_4D; dy_ext1 = dy_ext2 = dy0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x04) != 0) { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb + 1; dz_ext0 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -1177,29 +1248,32 @@ public class OpenSimplexNoise { if ((c & 0x03) != 0) { zsv_ext2 += 1; dz_ext2 -= 1; - } else { + } + else { zsv_ext1 += 1; dz_ext1 -= 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsv_ext2 = zsb; dz_ext0 = dz0 - 2 * SQUISH_CONSTANT_4D; dz_ext1 = dz_ext2 = dz0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x08) != 0) { wsv_ext0 = wsv_ext1 = wsb + 1; wsv_ext2 = wsb + 2; dw_ext0 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; dw_ext2 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsv_ext2 = wsb; dw_ext0 = dw0 - 2 * SQUISH_CONSTANT_4D; dw_ext1 = dw_ext2 = dw0 - 3 * SQUISH_CONSTANT_4D; } } - + // Contribution (1,1,1,0) double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; @@ -1210,7 +1284,7 @@ public class OpenSimplexNoise { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); } - + // Contribution (1,1,0,1) double dx3 = dx4; double dy3 = dy4; @@ -1221,7 +1295,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); } - + // Contribution (1,0,1,1) double dx2 = dx4; double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D; @@ -1232,7 +1306,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); } - + // Contribution (0,1,1,1) double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D; double dz1 = dz4; @@ -1243,7 +1317,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); } - + // Contribution (1,1,1,1) dx0 = dx0 - 1 - 4 * SQUISH_CONSTANT_4D; dy0 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; @@ -1254,33 +1328,36 @@ public class OpenSimplexNoise { attn0 *= attn0; value += attn0 * attn0 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 1, dx0, dy0, dz0, dw0); } - } else if (inSum <= 2) { // We're inside the first dispentachoron - // (Rectified 4-Simplex) + } + else if (inSum <= 2) { // We're inside the first dispentachoron + // (Rectified 4-Simplex) double aScore; byte aPoint; boolean aIsBiggerSide = true; double bScore; byte bPoint; boolean bIsBiggerSide = true; - + // Decide between (1,1,0,0) and (0,0,1,1) if (xins + yins > zins + wins) { aScore = xins + yins; aPoint = 0x03; - } else { + } + else { aScore = zins + wins; aPoint = 0x0C; } - + // Decide between (1,0,1,0) and (0,1,0,1) if (xins + zins > yins + wins) { bScore = xins + zins; bPoint = 0x05; - } else { + } + else { bScore = yins + wins; bPoint = 0x0A; } - + // Closer between (1,0,0,1) and (0,1,1,0) will replace the further // of a and b, if closer. if (xins + wins > yins + zins) { @@ -1288,69 +1365,76 @@ public class OpenSimplexNoise { if (aScore >= bScore && score > bScore) { bScore = score; bPoint = 0x09; - } else if (aScore < bScore && score > aScore) { + } + else if (aScore < bScore && score > aScore) { aScore = score; aPoint = 0x09; } - } else { + } + else { double score = yins + zins; if (aScore >= bScore && score > bScore) { bScore = score; bPoint = 0x06; - } else if (aScore < bScore && score > aScore) { + } + else if (aScore < bScore && score > aScore) { aScore = score; aPoint = 0x06; } } - + // Decide if (1,0,0,0) is closer. double p1 = 2 - inSum + xins; if (aScore >= bScore && p1 > bScore) { bScore = p1; bPoint = 0x01; bIsBiggerSide = false; - } else if (aScore < bScore && p1 > aScore) { + } + else if (aScore < bScore && p1 > aScore) { aScore = p1; aPoint = 0x01; aIsBiggerSide = false; } - + // Decide if (0,1,0,0) is closer. double p2 = 2 - inSum + yins; if (aScore >= bScore && p2 > bScore) { bScore = p2; bPoint = 0x02; bIsBiggerSide = false; - } else if (aScore < bScore && p2 > aScore) { + } + else if (aScore < bScore && p2 > aScore) { aScore = p2; aPoint = 0x02; aIsBiggerSide = false; } - + // Decide if (0,0,1,0) is closer. double p3 = 2 - inSum + zins; if (aScore >= bScore && p3 > bScore) { bScore = p3; bPoint = 0x04; bIsBiggerSide = false; - } else if (aScore < bScore && p3 > aScore) { + } + else if (aScore < bScore && p3 > aScore) { aScore = p3; aPoint = 0x04; aIsBiggerSide = false; } - + // Decide if (0,0,0,1) is closer. double p4 = 2 - inSum + wins; if (aScore >= bScore && p4 > bScore) { bScore = p4; bPoint = 0x08; bIsBiggerSide = false; - } else if (aScore < bScore && p4 > aScore) { + } + else if (aScore < bScore && p4 > aScore) { aScore = p4; aPoint = 0x08; aIsBiggerSide = false; } - + // Where each of the two closest points are determines how the extra // three vertices are calculated. if (aIsBiggerSide == bIsBiggerSide) { @@ -1362,45 +1446,49 @@ public class OpenSimplexNoise { xsv_ext1 = xsb - 1; dx_ext0 = dx0 - 3 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 + 1 - 2 * SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x02) == 0) { ysv_ext0 = ysb; ysv_ext1 = ysb - 1; dy_ext0 = dy0 - 3 * SQUISH_CONSTANT_4D; dy_ext1 = dy0 + 1 - 2 * SQUISH_CONSTANT_4D; - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; dy_ext1 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x04) == 0) { zsv_ext0 = zsb; zsv_ext1 = zsb - 1; dz_ext0 = dz0 - 3 * SQUISH_CONSTANT_4D; dz_ext1 = dz0 + 1 - 2 * SQUISH_CONSTANT_4D; - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; dz_ext1 = dz0 - 1 - 2 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x08) == 0) { wsv_ext0 = wsb; wsv_ext1 = wsb - 1; dw_ext0 = dw0 - 3 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 + 1 - 2 * SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsb + 1; dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 - 1 - 2 * SQUISH_CONSTANT_4D; } - + // One combination is a permutation of (0,0,0,2) based on c2 xsv_ext2 = xsb; ysv_ext2 = ysb; @@ -1413,19 +1501,23 @@ public class OpenSimplexNoise { if ((c2 & 0x01) != 0) { xsv_ext2 += 2; dx_ext2 -= 2; - } else if ((c2 & 0x02) != 0) { + } + else if ((c2 & 0x02) != 0) { ysv_ext2 += 2; dy_ext2 -= 2; - } else if ((c2 & 0x04) != 0) { + } + else if ((c2 & 0x04) != 0) { zsv_ext2 += 2; dz_ext2 -= 2; - } else { + } + else { wsv_ext2 += 2; dw_ext2 -= 2; } - - } else { // Both closest points on the smaller side - // One of the two extra points is (0,0,0,0) + + } + else { // Both closest points on the smaller side + // One of the two extra points is (0,0,0,0) xsv_ext2 = xsb; ysv_ext2 = ysb; zsv_ext2 = zsb; @@ -1434,71 +1526,79 @@ public class OpenSimplexNoise { dy_ext2 = dy0; dz_ext2 = dz0; dw_ext2 = dw0; - + // Other two points are based on the omitted axes. byte c = (byte) (aPoint | bPoint); - + if ((c & 0x01) == 0) { xsv_ext0 = xsb - 1; xsv_ext1 = xsb; dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D; dx_ext1 = dx0 - SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x02) == 0) { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D; if ((c & 0x01) == 0x01) { ysv_ext0 -= 1; dy_ext0 += 1; - } else { + } + else { ysv_ext1 -= 1; dy_ext1 += 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x04) == 0) { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D; if ((c & 0x03) == 0x03) { zsv_ext0 -= 1; dz_ext0 += 1; - } else { + } + else { zsv_ext1 -= 1; dz_ext1 += 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c & 0x08) == 0) { wsv_ext0 = wsb; wsv_ext1 = wsb - 1; dw_ext0 = dw0 - SQUISH_CONSTANT_4D; dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsb + 1; dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D; } - + } - } else { // One point on each "side" + } + else { // One point on each "side" byte c1, c2; if (aIsBiggerSide) { c1 = aPoint; c2 = bPoint; - } else { + } + else { c1 = bPoint; c2 = aPoint; } - + // Two contributions are the bigger-sided point with each 0 // replaced with -1. if ((c1 & 0x01) == 0) { @@ -1506,51 +1606,57 @@ public class OpenSimplexNoise { xsv_ext1 = xsb; dx_ext0 = dx0 + 1 - SQUISH_CONSTANT_4D; dx_ext1 = dx0 - SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb + 1; dx_ext0 = dx_ext1 = dx0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c1 & 0x02) == 0) { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - SQUISH_CONSTANT_4D; if ((c1 & 0x01) == 0x01) { ysv_ext0 -= 1; dy_ext0 += 1; - } else { + } + else { ysv_ext1 -= 1; dy_ext1 += 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c1 & 0x04) == 0) { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - SQUISH_CONSTANT_4D; if ((c1 & 0x03) == 0x03) { zsv_ext0 -= 1; dz_ext0 += 1; - } else { + } + else { zsv_ext1 -= 1; dz_ext1 += 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1 - SQUISH_CONSTANT_4D; } - + if ((c1 & 0x08) == 0) { wsv_ext0 = wsb; wsv_ext1 = wsb - 1; dw_ext0 = dw0 - SQUISH_CONSTANT_4D; dw_ext1 = dw0 + 1 - SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsb + 1; dw_ext0 = dw_ext1 = dw0 - 1 - SQUISH_CONSTANT_4D; } - + // One contribution is a permutation of (0,0,0,2) based on the // smaller-sided point xsv_ext2 = xsb; @@ -1564,18 +1670,21 @@ public class OpenSimplexNoise { if ((c2 & 0x01) != 0) { xsv_ext2 += 2; dx_ext2 -= 2; - } else if ((c2 & 0x02) != 0) { + } + else if ((c2 & 0x02) != 0) { ysv_ext2 += 2; dy_ext2 -= 2; - } else if ((c2 & 0x04) != 0) { + } + else if ((c2 & 0x04) != 0) { zsv_ext2 += 2; dz_ext2 -= 2; - } else { + } + else { wsv_ext2 += 2; dw_ext2 -= 2; } } - + // Contribution (1,0,0,0) double dx1 = dx0 - 1 - SQUISH_CONSTANT_4D; double dy1 = dy0 - 0 - SQUISH_CONSTANT_4D; @@ -1586,7 +1695,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 0, dx1, dy1, dz1, dw1); } - + // Contribution (0,1,0,0) double dx2 = dx0 - 0 - SQUISH_CONSTANT_4D; double dy2 = dy0 - 1 - SQUISH_CONSTANT_4D; @@ -1597,7 +1706,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 0, dx2, dy2, dz2, dw2); } - + // Contribution (0,0,1,0) double dx3 = dx2; double dy3 = dy1; @@ -1608,7 +1717,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 0, dx3, dy3, dz3, dw3); } - + // Contribution (0,0,0,1) double dx4 = dx2; double dy4 = dy1; @@ -1619,7 +1728,7 @@ public class OpenSimplexNoise { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 0, ysb + 0, zsb + 0, wsb + 1, dx4, dy4, dz4, dw4); } - + // Contribution (1,1,0,0) double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -1630,7 +1739,7 @@ public class OpenSimplexNoise { attn5 *= attn5; value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); } - + // Contribution (1,0,1,0) double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -1641,7 +1750,7 @@ public class OpenSimplexNoise { attn6 *= attn6; value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); } - + // Contribution (1,0,0,1) double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -1652,7 +1761,7 @@ public class OpenSimplexNoise { attn7 *= attn7; value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); } - + // Contribution (0,1,1,0) double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -1663,7 +1772,7 @@ public class OpenSimplexNoise { attn8 *= attn8; value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); } - + // Contribution (0,1,0,1) double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -1674,7 +1783,7 @@ public class OpenSimplexNoise { attn9 *= attn9; value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); } - + // Contribution (0,0,1,1) double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -1685,32 +1794,35 @@ public class OpenSimplexNoise { attn10 *= attn10; value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); } - } else { // We're inside the second dispentachoron (Rectified 4-Simplex) + } + else { // We're inside the second dispentachoron (Rectified 4-Simplex) double aScore; byte aPoint; boolean aIsBiggerSide = true; double bScore; byte bPoint; boolean bIsBiggerSide = true; - + // Decide between (0,0,1,1) and (1,1,0,0) if (xins + yins < zins + wins) { aScore = xins + yins; aPoint = 0x0C; - } else { + } + else { aScore = zins + wins; aPoint = 0x03; } - + // Decide between (0,1,0,1) and (1,0,1,0) if (xins + zins < yins + wins) { bScore = xins + zins; bPoint = 0x0A; - } else { + } + else { bScore = yins + wins; bPoint = 0x05; } - + // Closer between (0,1,1,0) and (1,0,0,1) will replace the further // of a and b, if closer. if (xins + wins < yins + zins) { @@ -1718,76 +1830,83 @@ public class OpenSimplexNoise { if (aScore <= bScore && score < bScore) { bScore = score; bPoint = 0x06; - } else if (aScore > bScore && score < aScore) { + } + else if (aScore > bScore && score < aScore) { aScore = score; aPoint = 0x06; } - } else { + } + else { double score = yins + zins; if (aScore <= bScore && score < bScore) { bScore = score; bPoint = 0x09; - } else if (aScore > bScore && score < aScore) { + } + else if (aScore > bScore && score < aScore) { aScore = score; aPoint = 0x09; } } - + // Decide if (0,1,1,1) is closer. double p1 = 3 - inSum + xins; if (aScore <= bScore && p1 < bScore) { bScore = p1; bPoint = 0x0E; bIsBiggerSide = false; - } else if (aScore > bScore && p1 < aScore) { + } + else if (aScore > bScore && p1 < aScore) { aScore = p1; aPoint = 0x0E; aIsBiggerSide = false; } - + // Decide if (1,0,1,1) is closer. double p2 = 3 - inSum + yins; if (aScore <= bScore && p2 < bScore) { bScore = p2; bPoint = 0x0D; bIsBiggerSide = false; - } else if (aScore > bScore && p2 < aScore) { + } + else if (aScore > bScore && p2 < aScore) { aScore = p2; aPoint = 0x0D; aIsBiggerSide = false; } - + // Decide if (1,1,0,1) is closer. double p3 = 3 - inSum + zins; if (aScore <= bScore && p3 < bScore) { bScore = p3; bPoint = 0x0B; bIsBiggerSide = false; - } else if (aScore > bScore && p3 < aScore) { + } + else if (aScore > bScore && p3 < aScore) { aScore = p3; aPoint = 0x0B; aIsBiggerSide = false; } - + // Decide if (1,1,1,0) is closer. double p4 = 3 - inSum + wins; if (aScore <= bScore && p4 < bScore) { bScore = p4; bPoint = 0x07; bIsBiggerSide = false; - } else if (aScore > bScore && p4 < aScore) { + } + else if (aScore > bScore && p4 < aScore) { aScore = p4; aPoint = 0x07; aIsBiggerSide = false; } - + // Where each of the two closest points are determines how the extra // three vertices are calculated. if (aIsBiggerSide == bIsBiggerSide) { if (aIsBiggerSide) { // Both closest points on the bigger side byte c1 = (byte) (aPoint & bPoint); byte c2 = (byte) (aPoint | bPoint); - + // Two contributions are permutations of (0,0,0,1) and // (0,0,0,2) based on c1 xsv_ext0 = xsv_ext1 = xsb; @@ -1807,23 +1926,26 @@ public class OpenSimplexNoise { dx_ext0 -= 1; xsv_ext1 += 2; dx_ext1 -= 2; - } else if ((c1 & 0x02) != 0) { + } + else if ((c1 & 0x02) != 0) { ysv_ext0 += 1; dy_ext0 -= 1; ysv_ext1 += 2; dy_ext1 -= 2; - } else if ((c1 & 0x04) != 0) { + } + else if ((c1 & 0x04) != 0) { zsv_ext0 += 1; dz_ext0 -= 1; zsv_ext1 += 2; dz_ext1 -= 2; - } else { + } + else { wsv_ext0 += 1; dw_ext0 -= 1; wsv_ext1 += 2; dw_ext1 -= 2; } - + // One contribution is a permutation of (1,1,1,-1) based on // c2 xsv_ext2 = xsb + 1; @@ -1837,18 +1959,22 @@ public class OpenSimplexNoise { if ((c2 & 0x01) == 0) { xsv_ext2 -= 2; dx_ext2 += 2; - } else if ((c2 & 0x02) == 0) { + } + else if ((c2 & 0x02) == 0) { ysv_ext2 -= 2; dy_ext2 += 2; - } else if ((c2 & 0x04) == 0) { + } + else if ((c2 & 0x04) == 0) { zsv_ext2 -= 2; dz_ext2 += 2; - } else { + } + else { wsv_ext2 -= 2; dw_ext2 += 2; } - } else { // Both closest points on the smaller side - // One of the two extra points is (1,1,1,1) + } + else { // Both closest points on the smaller side + // One of the two extra points is (1,1,1,1) xsv_ext2 = xsb + 1; ysv_ext2 = ysb + 1; zsv_ext2 = zsb + 1; @@ -1857,70 +1983,78 @@ public class OpenSimplexNoise { dy_ext2 = dy0 - 1 - 4 * SQUISH_CONSTANT_4D; dz_ext2 = dz0 - 1 - 4 * SQUISH_CONSTANT_4D; dw_ext2 = dw0 - 1 - 4 * SQUISH_CONSTANT_4D; - + // Other two points are based on the shared axes. byte c = (byte) (aPoint & bPoint); - + if ((c & 0x01) != 0) { xsv_ext0 = xsb + 2; xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x02) != 0) { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; if ((c & 0x01) == 0) { ysv_ext0 += 1; dy_ext0 -= 1; - } else { + } + else { ysv_ext1 += 1; dy_ext1 -= 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x04) != 0) { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; if ((c & 0x03) == 0) { zsv_ext0 += 1; dz_ext0 -= 1; - } else { + } + else { zsv_ext1 += 1; dz_ext1 -= 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c & 0x08) != 0) { wsv_ext0 = wsb + 1; wsv_ext1 = wsb + 2; dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsb; dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D; } } - } else { // One point on each "side" + } + else { // One point on each "side" byte c1, c2; if (aIsBiggerSide) { c1 = aPoint; c2 = bPoint; - } else { + } + else { c1 = bPoint; c2 = aPoint; } - + // Two contributions are the bigger-sided point with each 1 // replaced with 2. if ((c1 & 0x01) != 0) { @@ -1928,51 +2062,57 @@ public class OpenSimplexNoise { xsv_ext1 = xsb + 1; dx_ext0 = dx0 - 2 - 3 * SQUISH_CONSTANT_4D; dx_ext1 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { xsv_ext0 = xsv_ext1 = xsb; dx_ext0 = dx_ext1 = dx0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x02) != 0) { ysv_ext0 = ysv_ext1 = ysb + 1; dy_ext0 = dy_ext1 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; if ((c1 & 0x01) == 0) { ysv_ext0 += 1; dy_ext0 -= 1; - } else { + } + else { ysv_ext1 += 1; dy_ext1 -= 1; } - } else { + } + else { ysv_ext0 = ysv_ext1 = ysb; dy_ext0 = dy_ext1 = dy0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x04) != 0) { zsv_ext0 = zsv_ext1 = zsb + 1; dz_ext0 = dz_ext1 = dz0 - 1 - 3 * SQUISH_CONSTANT_4D; if ((c1 & 0x03) == 0) { zsv_ext0 += 1; dz_ext0 -= 1; - } else { + } + else { zsv_ext1 += 1; dz_ext1 -= 1; } - } else { + } + else { zsv_ext0 = zsv_ext1 = zsb; dz_ext0 = dz_ext1 = dz0 - 3 * SQUISH_CONSTANT_4D; } - + if ((c1 & 0x08) != 0) { wsv_ext0 = wsb + 1; wsv_ext1 = wsb + 2; dw_ext0 = dw0 - 1 - 3 * SQUISH_CONSTANT_4D; dw_ext1 = dw0 - 2 - 3 * SQUISH_CONSTANT_4D; - } else { + } + else { wsv_ext0 = wsv_ext1 = wsb; dw_ext0 = dw_ext1 = dw0 - 3 * SQUISH_CONSTANT_4D; } - + // One contribution is a permutation of (1,1,1,-1) based on the // smaller-sided point xsv_ext2 = xsb + 1; @@ -1986,18 +2126,21 @@ public class OpenSimplexNoise { if ((c2 & 0x01) == 0) { xsv_ext2 -= 2; dx_ext2 += 2; - } else if ((c2 & 0x02) == 0) { + } + else if ((c2 & 0x02) == 0) { ysv_ext2 -= 2; dy_ext2 += 2; - } else if ((c2 & 0x04) == 0) { + } + else if ((c2 & 0x04) == 0) { zsv_ext2 -= 2; dz_ext2 += 2; - } else { + } + else { wsv_ext2 -= 2; dw_ext2 += 2; } } - + // Contribution (1,1,1,0) double dx4 = dx0 - 1 - 3 * SQUISH_CONSTANT_4D; double dy4 = dy0 - 1 - 3 * SQUISH_CONSTANT_4D; @@ -2008,7 +2151,7 @@ public class OpenSimplexNoise { attn4 *= attn4; value += attn4 * attn4 * extrapolate(xsb + 1, ysb + 1, zsb + 1, wsb + 0, dx4, dy4, dz4, dw4); } - + // Contribution (1,1,0,1) double dx3 = dx4; double dy3 = dy4; @@ -2019,7 +2162,7 @@ public class OpenSimplexNoise { attn3 *= attn3; value += attn3 * attn3 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 1, dx3, dy3, dz3, dw3); } - + // Contribution (1,0,1,1) double dx2 = dx4; double dy2 = dy0 - 3 * SQUISH_CONSTANT_4D; @@ -2030,7 +2173,7 @@ public class OpenSimplexNoise { attn2 *= attn2; value += attn2 * attn2 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 1, dx2, dy2, dz2, dw2); } - + // Contribution (0,1,1,1) double dx1 = dx0 - 3 * SQUISH_CONSTANT_4D; double dz1 = dz4; @@ -2041,7 +2184,7 @@ public class OpenSimplexNoise { attn1 *= attn1; value += attn1 * attn1 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 1, dx1, dy1, dz1, dw1); } - + // Contribution (1,1,0,0) double dx5 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy5 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -2052,7 +2195,7 @@ public class OpenSimplexNoise { attn5 *= attn5; value += attn5 * attn5 * extrapolate(xsb + 1, ysb + 1, zsb + 0, wsb + 0, dx5, dy5, dz5, dw5); } - + // Contribution (1,0,1,0) double dx6 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy6 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -2063,7 +2206,7 @@ public class OpenSimplexNoise { attn6 *= attn6; value += attn6 * attn6 * extrapolate(xsb + 1, ysb + 0, zsb + 1, wsb + 0, dx6, dy6, dz6, dw6); } - + // Contribution (1,0,0,1) double dx7 = dx0 - 1 - 2 * SQUISH_CONSTANT_4D; double dy7 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -2074,7 +2217,7 @@ public class OpenSimplexNoise { attn7 *= attn7; value += attn7 * attn7 * extrapolate(xsb + 1, ysb + 0, zsb + 0, wsb + 1, dx7, dy7, dz7, dw7); } - + // Contribution (0,1,1,0) double dx8 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy8 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -2085,7 +2228,7 @@ public class OpenSimplexNoise { attn8 *= attn8; value += attn8 * attn8 * extrapolate(xsb + 0, ysb + 1, zsb + 1, wsb + 0, dx8, dy8, dz8, dw8); } - + // Contribution (0,1,0,1) double dx9 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy9 = dy0 - 1 - 2 * SQUISH_CONSTANT_4D; @@ -2096,7 +2239,7 @@ public class OpenSimplexNoise { attn9 *= attn9; value += attn9 * attn9 * extrapolate(xsb + 0, ysb + 1, zsb + 0, wsb + 1, dx9, dy9, dz9, dw9); } - + // Contribution (0,0,1,1) double dx10 = dx0 - 0 - 2 * SQUISH_CONSTANT_4D; double dy10 = dy0 - 0 - 2 * SQUISH_CONSTANT_4D; @@ -2108,78 +2251,64 @@ public class OpenSimplexNoise { value += attn10 * attn10 * extrapolate(xsb + 0, ysb + 0, zsb + 1, wsb + 1, dx10, dy10, dz10, dw10); } } - + // First extra vertex double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0 - dw_ext0 * dw_ext0; if (attn_ext0 > 0) { attn_ext0 *= attn_ext0; - value += attn_ext0 * attn_ext0 - * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0); + value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0); } - + // Second extra vertex double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1 - dw_ext1 * dw_ext1; if (attn_ext1 > 0) { attn_ext1 *= attn_ext1; - value += attn_ext1 * attn_ext1 - * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1); + value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1); } - + // Third extra vertex double attn_ext2 = 2 - dx_ext2 * dx_ext2 - dy_ext2 * dy_ext2 - dz_ext2 * dz_ext2 - dw_ext2 * dw_ext2; if (attn_ext2 > 0) { attn_ext2 *= attn_ext2; - value += attn_ext2 * attn_ext2 - * extrapolate(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2); + value += attn_ext2 * attn_ext2 * extrapolate(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2); } - + return value / NORM_CONSTANT_4D; } - + private double extrapolate(int xsb, int ysb, double dx, double dy) { int index = perm[(perm[xsb & 0xFF] + ysb) & 0xFF] & 0x0E; return gradients2D[index] * dx + gradients2D[index + 1] * dy; } - + private double extrapolate(int xsb, int ysb, int zsb, double dx, double dy, double dz) { int index = permGradIndex3D[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF]; return gradients3D[index] * dx + gradients3D[index + 1] * dy + gradients3D[index + 2] * dz; } - + private double extrapolate(int xsb, int ysb, int zsb, int wsb, double dx, double dy, double dz, double dw) { int index = perm[(perm[(perm[(perm[xsb & 0xFF] + ysb) & 0xFF] + zsb) & 0xFF] + wsb) & 0xFF] & 0xFC; - return gradients4D[index] * dx + gradients4D[index + 1] * dy + gradients4D[index + 2] * dz - + gradients4D[index + 3] * dw; + return gradients4D[index] * dx + gradients4D[index + 1] * dy + gradients4D[index + 2] * dz + gradients4D[index + 3] * dw; } - + private static int fastFloor(double x) { int xi = (int) x; return x < xi ? xi - 1 : xi; } - + // Gradients for 2D. They approximate the directions to the // vertices of an octagon from the center. - private static byte[] gradients2D = new byte[] { 5, 2, 2, 5, -5, 2, -2, 5, 5, -2, 2, -5, -5, -2, -2, -5, }; - + private static byte[] gradients2D = new byte[] {5, 2, 2, 5, -5, 2, -2, 5, 5, -2, 2, -5, -5, -2, -2, -5,}; + // Gradients for 3D. They approximate the directions to the // vertices of a rhombicuboctahedron from the center, skewed so // that the triangular and square facets can be inscribed inside // circles of the same radius. - private static byte[] gradients3D = new byte[] { -11, 4, 4, -4, 11, 4, -4, 4, 11, 11, 4, 4, 4, 11, 4, 4, 4, 11, -11, - -4, 4, -4, -11, 4, -4, -4, 11, 11, -4, 4, 4, -11, 4, 4, -4, 11, -11, 4, -4, -4, 11, -4, -4, 4, -11, 11, 4, - -4, 4, 11, -4, 4, 4, -11, -11, -4, -4, -4, -11, -4, -4, -4, -11, 11, -4, -4, 4, -11, -4, 4, -4, -11, }; - + private static byte[] gradients3D = new byte[] {-11, 4, 4, -4, 11, 4, -4, 4, 11, 11, 4, 4, 4, 11, 4, 4, 4, 11, -11, -4, 4, -4, -11, 4, -4, -4, 11, 11, -4, 4, 4, -11, 4, 4, -4, 11, -11, 4, -4, -4, 11, -4, -4, 4, -11, 11, 4, -4, 4, 11, -4, 4, 4, -11, -11, -4, -4, -4, -11, -4, -4, -4, -11, 11, -4, -4, 4, -11, -4, 4, -4, -11,}; + // Gradients for 4D. They approximate the directions to the // vertices of a disprismatotesseractihexadecachoron from the center, // skewed so that the tetrahedral and cubic facets can be inscribed inside // spheres of the same radius. - private static byte[] gradients4D = new byte[] { 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, -3, 1, 1, 1, -1, 3, - 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, -3, -1, 1, 1, -1, -3, 1, - 1, -1, -1, 3, 1, -1, -1, 1, 3, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, -3, 1, -1, 1, -1, 3, -1, - 1, -1, 1, -3, 1, -1, 1, -1, 3, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, -3, -1, -1, 1, -1, - -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, -3, 1, 1, -1, - -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, -3, -1, 1, - -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, -3, - 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, - -1, -3, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, }; + private static byte[] gradients4D = new byte[] {3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,}; } \ No newline at end of file diff --git a/src/main/java/ru/bclib/noise/VoronoiNoise.java b/src/main/java/ru/bclib/noise/VoronoiNoise.java index 07bea100..3e1424ec 100644 --- a/src/main/java/ru/bclib/noise/VoronoiNoise.java +++ b/src/main/java/ru/bclib/noise/VoronoiNoise.java @@ -1,10 +1,10 @@ package ru.bclib.noise; -import java.util.Random; - import net.minecraft.core.BlockPos; import ru.bclib.util.MHelper; +import java.util.Random; + public class VoronoiNoise { private static final Random RANDOM = new Random(); final int seed; @@ -12,7 +12,7 @@ public class VoronoiNoise { public VoronoiNoise() { this(0); } - + public VoronoiNoise(int seed) { this.seed = seed; } @@ -22,7 +22,7 @@ public class VoronoiNoise { h = (h ^ (h >> 13)) * 1274126177; return h ^ (h >> 16); } - + public double sample(double x, double y, double z) { int ix = MHelper.floor(x); int iy = MHelper.floor(y); diff --git a/src/main/java/ru/bclib/recipes/BCLRecipeManager.java b/src/main/java/ru/bclib/recipes/BCLRecipeManager.java index 8e2f6e71..0ecacc23 100644 --- a/src/main/java/ru/bclib/recipes/BCLRecipeManager.java +++ b/src/main/java/ru/bclib/recipes/BCLRecipeManager.java @@ -1,10 +1,6 @@ package ru.bclib.recipes; -import java.util.Map; -import java.util.Map.Entry; - import com.google.common.collect.Maps; - import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.crafting.Recipe; @@ -13,9 +9,12 @@ import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; +import java.util.Map; +import java.util.Map.Entry; + public class BCLRecipeManager { private static final Map, Map>> RECIPES = Maps.newHashMap(); - + public static void addRecipe(RecipeType type, Recipe recipe) { Map> list = RECIPES.get(type); if (list == null) { @@ -32,16 +31,16 @@ public class BCLRecipeManager { } return null; } - + public static Map, Map>> getMap(Map, Map>> recipes) { Map, Map>> result = Maps.newHashMap(); - + for (RecipeType type : recipes.keySet()) { Map> typeList = Maps.newHashMap(); typeList.putAll(recipes.get(type)); result.put(type, typeList); } - + for (RecipeType type : RECIPES.keySet()) { Map> list = RECIPES.get(type); if (list != null) { @@ -52,32 +51,32 @@ public class BCLRecipeManager { } for (Entry> entry : list.entrySet()) { ResourceLocation id = entry.getKey(); - if (!typeList.containsKey(id)) - typeList.put(id, entry.getValue()); + if (!typeList.containsKey(id)) typeList.put(id, entry.getValue()); } } } - + return result; } - + public static , T extends Recipe> S registerSerializer(String modID, String id, S serializer) { return Registry.register(Registry.RECIPE_SERIALIZER, modID + ":" + id, serializer); } - + public static > RecipeType registerType(String modID, String type) { ResourceLocation recipeTypeId = new ResourceLocation(modID, type); return Registry.register(Registry.RECIPE_TYPE, recipeTypeId, new RecipeType() { public String toString() { return type; } - }); + }); } public static boolean exists(ItemLike item) { if (item instanceof Block) { return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey(); - } else { + } + else { return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey(); } } diff --git a/src/main/java/ru/bclib/recipes/CraftingRecipes.java b/src/main/java/ru/bclib/recipes/CraftingRecipes.java index d28b5b97..ec9788e5 100644 --- a/src/main/java/ru/bclib/recipes/CraftingRecipes.java +++ b/src/main/java/ru/bclib/recipes/CraftingRecipes.java @@ -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_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) - .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) - .setShape("S", "C", "S") - .addMaterial('S', Items.SHULKER_SHELL) - .addMaterial('C', TagAPI.ITEM_CHEST) - .checkConfig(Configs.RECIPE_CONFIG) - .build(); + 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(); + + 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(); } } diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index bfb9abe7..c74f3117 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -1,10 +1,6 @@ package ru.bclib.recipes; -import java.util.Arrays; -import java.util.Map; - import com.google.common.collect.Maps; - import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; @@ -19,6 +15,9 @@ import net.minecraft.world.level.ItemLike; import ru.bclib.BCLib; import ru.bclib.config.PathConfig; +import java.util.Arrays; +import java.util.Map; + public class GridRecipe { private static final GridRecipe INSTANCE = new GridRecipe(); @@ -55,7 +54,7 @@ public class GridRecipe { exist |= config.getBoolean("grid", id.getPath(), true); return this; } - + public GridRecipe setGroup(String group) { this.group = group; return this; @@ -67,7 +66,7 @@ public class GridRecipe { } public GridRecipe setList(String shape) { - this.shape = new String[] { shape }; + this.shape = new String[] {shape}; this.shaped = false; return this; } @@ -81,7 +80,7 @@ public class GridRecipe { } public GridRecipe addMaterial(char key, ItemLike... values) { - for (ItemLike item: values) { + for (ItemLike item : values) { exist &= BCLRecipeManager.exists(item); } return addMaterial(key, Ingredient.of(values)); @@ -100,11 +99,11 @@ public class GridRecipe { private NonNullList getMaterials(int width, int height) { NonNullList materials = NonNullList.withSize(width * height, Ingredient.EMPTY); int pos = 0; - for (String line: shape) { + for (String line : shape) { for (int i = 0; i < width; i++) { char c = line.charAt(i); Ingredient material = materialKeys.get(c); - materials.set(pos ++, material == null ? Ingredient.EMPTY : material); + materials.set(pos++, material == null ? Ingredient.EMPTY : material); } } 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); BCLRecipeManager.addRecipe(type, recipe); - } else { + } + else { BCLib.LOGGER.debug("Recipe {} couldn't be added", id); } } diff --git a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java index bc6aa702..a74c6184 100644 --- a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java +++ b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java @@ -89,7 +89,7 @@ public class SmithingTableRecipe { BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id); return; } - if(result == null) { + if (result == null) { BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id); return; } diff --git a/src/main/java/ru/bclib/registry/BaseBlockEntities.java b/src/main/java/ru/bclib/registry/BaseBlockEntities.java index 7da1352b..f1170bb8 100644 --- a/src/main/java/ru/bclib/registry/BaseBlockEntities.java +++ b/src/main/java/ru/bclib/registry/BaseBlockEntities.java @@ -1,7 +1,5 @@ package ru.bclib.registry; -import java.util.function.Supplier; - import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.BlockItem; @@ -24,34 +22,26 @@ public class BaseBlockEntities { public static final DynamicBlockEntityType BARREL = registerBlockEntityType(BCLib.makeID("barrel"), BaseBarrelBlockEntity::new); public static final DynamicBlockEntityType SIGN = registerBlockEntityType(BCLib.makeID("sign"), BaseSignBlockEntity::new); public static final DynamicBlockEntityType FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), BaseFurnaceBlockEntity::new); - + public static DynamicBlockEntityType registerBlockEntityType(ResourceLocation typeId, BlockEntitySupplier supplier) { return Registry.register(Registry.BLOCK_ENTITY_TYPE, typeId, new DynamicBlockEntityType<>(supplier)); } public static void register() {} - + public static Block[] getChests() { - return BaseRegistry.getRegisteredBlocks().values().stream() - .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock) - .map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); + return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); } - + public static Block[] getBarrels() { - return BaseRegistry.getRegisteredBlocks().values().stream() - .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock) - .map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); + return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); } - + public static Block[] getSigns() { - return BaseRegistry.getRegisteredBlocks().values().stream() - .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock) - .map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); + return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); } - + public static Block[] getFurnaces() { - return BaseRegistry.getRegisteredBlocks().values().stream() - .filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock) - .map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); + return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new); } } diff --git a/src/main/java/ru/bclib/registry/BaseRegistry.java b/src/main/java/ru/bclib/registry/BaseRegistry.java index cf9796b5..9369bc72 100644 --- a/src/main/java/ru/bclib/registry/BaseRegistry.java +++ b/src/main/java/ru/bclib/registry/BaseRegistry.java @@ -1,11 +1,7 @@ package ru.bclib.registry; -import java.util.List; -import java.util.Map; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; - import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; @@ -14,20 +10,23 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import ru.bclib.BCLib; -public abstract class BaseRegistry { +import java.util.List; +import java.util.Map; +public abstract class BaseRegistry { + private static final List> REGISTRIES = Lists.newArrayList(); private static final Map> MOD_BLOCKS = Maps.newHashMap(); private static final Map> MOD_ITEMS = Maps.newHashMap(); - + public static Map> getRegisteredBlocks() { return MOD_BLOCKS; } - + public static Map> getRegisteredItems() { return MOD_ITEMS; } - + public static List getModBlocks(String modId) { if (MOD_BLOCKS.containsKey(modId)) { return MOD_BLOCKS.get(modId); @@ -36,7 +35,7 @@ public abstract class BaseRegistry { MOD_BLOCKS.put(modId, modBlocks); return modBlocks; } - + public static List getModItems(String modId) { if (MOD_ITEMS.containsKey(modId)) { return MOD_ITEMS.get(modId); @@ -45,39 +44,39 @@ public abstract class BaseRegistry { MOD_ITEMS.put(modId, modBlocks); return modBlocks; } - + public static void register() { REGISTRIES.forEach(BaseRegistry::registerInternal); } - + protected final CreativeModeTab creativeTab; - + protected BaseRegistry(CreativeModeTab creativeTab) { this.creativeTab = creativeTab; REGISTRIES.add(this); } - + public T register(String name, T obj) { return register(createModId(name), obj); } - + public abstract T register(ResourceLocation objId, T obj); - + public ResourceLocation createModId(String name) { return BCLib.makeID(name); } - + public void registerItem(ResourceLocation id, Item item, List registry) { if (item != Items.AIR) { Registry.register(Registry.ITEM, id, item); registry.add(item); } } - + public FabricItemSettings makeItemSettings() { FabricItemSettings properties = new FabricItemSettings(); return (FabricItemSettings) properties.tab(creativeTab); } - + private void registerInternal() {} } diff --git a/src/main/java/ru/bclib/registry/BlocksRegistry.java b/src/main/java/ru/bclib/registry/BlocksRegistry.java index bd663f50..3da2f9c4 100644 --- a/src/main/java/ru/bclib/registry/BlocksRegistry.java +++ b/src/main/java/ru/bclib/registry/BlocksRegistry.java @@ -12,7 +12,7 @@ import net.minecraft.world.level.block.Block; import ru.bclib.interfaces.ISpetialItem; public abstract class BlocksRegistry extends BaseRegistry { - + protected BlocksRegistry(CreativeModeTab creativeTab) { super(creativeTab); } @@ -29,7 +29,8 @@ public abstract class BlocksRegistry extends BaseRegistry { Properties item = makeItemSettings().stacksTo(maxCount); if (placeOnWater) { registerBlockItem(id, new WaterLilyBlockItem(block, item)); - } else { + } + else { registerBlockItem(id, new BlockItem(block, item)); } if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance().get(block).getBurnChance() == 0) { @@ -41,7 +42,7 @@ public abstract class BlocksRegistry extends BaseRegistry { public Block registerBlockOnly(String name, Block block) { return Registry.register(Registry.BLOCK, createModId(name), block); } - + public Item registerBlockItem(ResourceLocation id, Item item) { registerItem(id, item, BaseRegistry.getModBlocks(id.getNamespace())); return item; diff --git a/src/main/java/ru/bclib/registry/ItemsRegistry.java b/src/main/java/ru/bclib/registry/ItemsRegistry.java index 7dcc9744..fd9b728a 100644 --- a/src/main/java/ru/bclib/registry/ItemsRegistry.java +++ b/src/main/java/ru/bclib/registry/ItemsRegistry.java @@ -30,44 +30,48 @@ import ru.bclib.items.tool.BasePickaxeItem; import ru.bclib.util.TagHelper; public abstract class ItemsRegistry extends BaseRegistry { - + protected ItemsRegistry(CreativeModeTab creativeTab) { super(creativeTab); } - + public Item registerDisc(String name, int power, SoundEvent sound) { return register(name, new BaseDiscItem(power, sound, makeItemSettings().stacksTo(1))); } - + public Item registerItem(String name) { return register(name, new ModelProviderItem(makeItemSettings())); } - + @Override public Item register(ResourceLocation itemId, Item item) { registerItem(itemId, item, BaseRegistry.getModItems(itemId.getNamespace())); return item; } - + public TieredItem registerTool(String name, TieredItem item) { ResourceLocation id = createModId(name); registerItem(id, item, BaseRegistry.getModItems(id.getNamespace())); - + if (item instanceof ShovelItem) { TagHelper.addTag((Tag.Named) FabricToolTags.SHOVELS, item); - } else if (item instanceof SwordItem) { + } + else if (item instanceof SwordItem) { TagHelper.addTag((Tag.Named) FabricToolTags.SWORDS, item); - } else if (item instanceof BasePickaxeItem) { + } + else if (item instanceof BasePickaxeItem) { TagHelper.addTag((Tag.Named) FabricToolTags.PICKAXES, item); - } else if (item instanceof BaseAxeItem) { + } + else if (item instanceof BaseAxeItem) { TagHelper.addTag((Tag.Named) FabricToolTags.AXES, item); - } else if (item instanceof BaseHoeItem) { + } + else if (item instanceof BaseHoeItem) { TagHelper.addTag((Tag.Named) FabricToolTags.HOES, item); } - + return item; } - + public Item registerEgg(String name, EntityType type, int background, int dots) { SpawnEggItem item = new BaseSpawnEggItem(type, background, dots, makeItemSettings()); DefaultDispenseItemBehavior behavior = new DefaultDispenseItemBehavior() { @@ -82,27 +86,27 @@ public abstract class ItemsRegistry extends BaseRegistry { DispenserBlock.registerBehavior(item, behavior); return register(name, item); } - + public Item registerFood(String name, int hunger, float saturation, MobEffectInstance... effects) { FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation); - for (MobEffectInstance effect: effects) { + for (MobEffectInstance effect : effects) { builder.effect(effect, 1F); } return registerFood(name, builder.build()); } - + public Item registerFood(String name, FoodProperties foodComponent) { return register(name, new ModelProviderItem(makeItemSettings().food(foodComponent))); } - + public Item registerDrink(String name) { return register(name, new BaseDrinkItem(makeItemSettings().stacksTo(1))); } - + public Item registerDrink(String name, FoodProperties foodComponent) { return register(name, new BaseDrinkItem(makeItemSettings().stacksTo(1).food(foodComponent))); } - + public Item registerDrink(String name, int hunger, float saturation) { FoodProperties.Builder builder = new FoodProperties.Builder().nutrition(hunger).saturationMod(saturation); return registerDrink(name, builder.build()); diff --git a/src/main/java/ru/bclib/sdf/PosInfo.java b/src/main/java/ru/bclib/sdf/PosInfo.java index b8a64c4d..d7e7e0ed 100644 --- a/src/main/java/ru/bclib/sdf/PosInfo.java +++ b/src/main/java/ru/bclib/sdf/PosInfo.java @@ -1,12 +1,12 @@ package ru.bclib.sdf; -import java.util.Map; - import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; +import java.util.Map; + public class PosInfo implements Comparable { private static final BlockState AIR = Blocks.AIR.defaultBlockState(); private final Map blocks; @@ -86,12 +86,12 @@ public class PosInfo implements Comparable { } return pos.equals(((PosInfo) obj).pos); } - + @Override public int compareTo(PosInfo info) { return this.pos.getY() - info.pos.getY(); } - + public BlockPos getPos() { return pos; } diff --git a/src/main/java/ru/bclib/sdf/SDF.java b/src/main/java/ru/bclib/sdf/SDF.java index 396850de..57d7ab31 100644 --- a/src/main/java/ru/bclib/sdf/SDF.java +++ b/src/main/java/ru/bclib/sdf/SDF.java @@ -1,16 +1,8 @@ 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.Maps; import com.google.common.collect.Sets; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -20,12 +12,19 @@ import net.minecraft.world.phys.AABB; import ru.bclib.util.BlocksHelper; 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 { private List> postProcesses = Lists.newArrayList(); private Function canReplace = (state) -> { return state.getMaterial().isReplaceable(); }; - + public abstract float getDistance(float x, float y, float z); public abstract BlockState getBlockState(BlockPos pos); @@ -52,8 +51,8 @@ public abstract class SDF { MutableBlockPos bPos = new MutableBlockPos(); while (run) { - for (BlockPos center: ends) { - for (Direction dir: Direction.values()) { + for (BlockPos center : ends) { + for (Direction dir : Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); @@ -86,7 +85,7 @@ public abstract class SDF { infos.forEach((info) -> { BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState()); }); - + infos.clear(); infos.addAll(addInfo.values()); Collections.sort(infos); @@ -135,7 +134,7 @@ public abstract class SDF { infos.forEach((info) -> { BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState()); }); - + infos.clear(); infos.addAll(addInfo.values()); Collections.sort(infos); @@ -164,8 +163,8 @@ public abstract class SDF { MutableBlockPos bPos = new MutableBlockPos(); while (run) { - for (BlockPos center: ends) { - for (Direction dir: Direction.values()) { + for (BlockPos center : ends) { + for (Direction dir : Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); BlockState state = world.getBlockState(wpos); @@ -198,7 +197,7 @@ public abstract class SDF { infos.forEach((info) -> { BlocksHelper.setWithoutUpdate(world, info.getPos(), info.getState()); }); - + infos.clear(); infos.addAll(addInfo.values()); Collections.sort(infos); @@ -227,8 +226,8 @@ public abstract class SDF { MutableBlockPos bPos = new MutableBlockPos(); while (run) { - for (BlockPos center: ends) { - for (Direction dir: Direction.values()) { + for (BlockPos center : ends) { + for (Direction dir : Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); @@ -284,8 +283,8 @@ public abstract class SDF { MutableBlockPos bPos = new MutableBlockPos(); while (run) { - for (BlockPos center: ends) { - for (Direction dir: Direction.values()) { + for (BlockPos center : ends) { + for (Direction dir : Direction.values()) { bPos.set(center).move(dir); BlockPos wpos = bPos.offset(start); BlockState state = world.getBlockState(wpos); diff --git a/src/main/java/ru/bclib/sdf/operator/SDFBinary.java b/src/main/java/ru/bclib/sdf/operator/SDFBinary.java index 0e223e54..056aba3f 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFBinary.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFBinary.java @@ -27,7 +27,8 @@ public abstract class SDFBinary extends SDF { public BlockState getBlockState(BlockPos pos) { if (firstValue) { return sourceA.getBlockState(pos); - } else { + } + else { return sourceB.getBlockState(pos); } } diff --git a/src/main/java/ru/bclib/sdf/operator/SDFCoordModify.java b/src/main/java/ru/bclib/sdf/operator/SDFCoordModify.java index 1b096f5e..d0c01c3e 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFCoordModify.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFCoordModify.java @@ -1,9 +1,9 @@ package ru.bclib.sdf.operator; -import java.util.function.Consumer; - import com.mojang.math.Vector3f; +import java.util.function.Consumer; + public class SDFCoordModify extends SDFUnary { private static final Vector3f POS = new Vector3f(); private Consumer function; diff --git a/src/main/java/ru/bclib/sdf/operator/SDFDisplacement.java b/src/main/java/ru/bclib/sdf/operator/SDFDisplacement.java index 5ca88dee..c25bbae2 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFDisplacement.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFDisplacement.java @@ -1,9 +1,9 @@ package ru.bclib.sdf.operator; -import java.util.function.Function; - import com.mojang.math.Vector3f; +import java.util.function.Function; + public class SDFDisplacement extends SDFUnary { private static final Vector3f POS = new Vector3f(); private Function displace; diff --git a/src/main/java/ru/bclib/sdf/operator/SDFHeightmap.java b/src/main/java/ru/bclib/sdf/operator/SDFHeightmap.java index 5629607a..b5233d51 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFHeightmap.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFHeightmap.java @@ -1,7 +1,6 @@ package ru.bclib.sdf.operator; import com.mojang.blaze3d.platform.NativeImage; - import net.minecraft.util.Mth; public class SDFHeightmap extends SDFDisplacement { diff --git a/src/main/java/ru/bclib/sdf/operator/SDFSmoothIntersection.java b/src/main/java/ru/bclib/sdf/operator/SDFSmoothIntersection.java index 393d66d2..5770d25b 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFSmoothIntersection.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFSmoothIntersection.java @@ -4,7 +4,7 @@ import net.minecraft.util.Mth; public class SDFSmoothIntersection extends SDFBinary { private float radius; - + public SDFSmoothIntersection setRadius(float radius) { this.radius = radius; return this; diff --git a/src/main/java/ru/bclib/sdf/operator/SDFSmoothSubtraction.java b/src/main/java/ru/bclib/sdf/operator/SDFSmoothSubtraction.java index 020b8590..c7ac6e73 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFSmoothSubtraction.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFSmoothSubtraction.java @@ -4,7 +4,7 @@ import net.minecraft.util.Mth; public class SDFSmoothSubtraction extends SDFBinary { private float radius; - + public SDFSmoothSubtraction setRadius(float radius) { this.radius = radius; return this; diff --git a/src/main/java/ru/bclib/sdf/operator/SDFSmoothUnion.java b/src/main/java/ru/bclib/sdf/operator/SDFSmoothUnion.java index 493c1c9b..e7034e75 100644 --- a/src/main/java/ru/bclib/sdf/operator/SDFSmoothUnion.java +++ b/src/main/java/ru/bclib/sdf/operator/SDFSmoothUnion.java @@ -4,12 +4,12 @@ import net.minecraft.util.Mth; public class SDFSmoothUnion extends SDFBinary { private float radius; - + public SDFSmoothUnion setRadius(float radius) { this.radius = radius; return this; } - + @Override public float getDistance(float x, float y, float z) { float a = this.sourceA.getDistance(x, y, z); diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFCappedCone.java b/src/main/java/ru/bclib/sdf/primitive/SDFCappedCone.java index 891253da..d66e0f46 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFCappedCone.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFCappedCone.java @@ -22,7 +22,7 @@ public class SDFCappedCone extends SDFPrimitive { this.height = height; return this; } - + @Override public float getDistance(float x, float y, float z) { float qx = MHelper.length(x, z); diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFFlatland.java b/src/main/java/ru/bclib/sdf/primitive/SDFFlatland.java index 1f06cbf5..586aaf73 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFFlatland.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFFlatland.java @@ -3,6 +3,6 @@ package ru.bclib.sdf.primitive; public class SDFFlatland extends SDFPrimitive { @Override public float getDistance(float x, float y, float z) { - return y; + return y; } } diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFHexPrism.java b/src/main/java/ru/bclib/sdf/primitive/SDFHexPrism.java index 23a5b55c..a2e28a83 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFHexPrism.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFHexPrism.java @@ -15,7 +15,7 @@ public class SDFHexPrism extends SDFPrimitive { this.height = height; return this; } - + @Override public float getDistance(float x, float y, float z) { float px = Math.abs(x); diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFLine.java b/src/main/java/ru/bclib/sdf/primitive/SDFLine.java index 9fd316d7..0c166a91 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFLine.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFLine.java @@ -30,17 +30,17 @@ public class SDFLine extends SDFPrimitive { this.z2 = z; return this; } - + @Override public float getDistance(float x, float y, float z) { float pax = x - x1; float pay = y - y1; float paz = z - z1; - + float bax = x2 - x1; float bay = y2 - y1; float baz = z2 - z1; - + float dpb = MHelper.dot(pax, pay, paz, bax, bay, baz); float dbb = MHelper.dot(bax, bay, baz, bax, bay, baz); float h = Mth.clamp(dpb / dbb, 0F, 1F); diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFPie.java b/src/main/java/ru/bclib/sdf/primitive/SDFPie.java index 0ad180f4..6bff34ea 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFPie.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFPie.java @@ -22,10 +22,10 @@ public class SDFPie extends SDFPrimitive { @Override public float getDistance(float x, float y, float z) { float px = Math.abs(x); - float l = MHelper.length(px, y, z) - radius; - float m = MHelper.dot(px, z, sin, cos); - m = Mth.clamp(m, 0, radius); + float l = MHelper.length(px, y, z) - radius; + float m = MHelper.dot(px, z, sin, cos); + m = Mth.clamp(m, 0, radius); m = MHelper.length(px - sin * m, z - cos * m); - return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z)); + return MHelper.max(l, m * (float) Math.signum(cos * px - sin * z)); } } diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFPrimitive.java b/src/main/java/ru/bclib/sdf/primitive/SDFPrimitive.java index e40b61ab..4e3b527f 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFPrimitive.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFPrimitive.java @@ -1,12 +1,12 @@ package ru.bclib.sdf.primitive; -import java.util.function.Function; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import ru.bclib.sdf.SDF; +import java.util.function.Function; + public abstract class SDFPrimitive extends SDF { protected Function placerFunction; diff --git a/src/main/java/ru/bclib/sdf/primitive/SDFSphere.java b/src/main/java/ru/bclib/sdf/primitive/SDFSphere.java index c8ff092b..edeb8ea2 100644 --- a/src/main/java/ru/bclib/sdf/primitive/SDFSphere.java +++ b/src/main/java/ru/bclib/sdf/primitive/SDFSphere.java @@ -6,7 +6,7 @@ public class SDFSphere extends SDFPrimitive { private float radius; public SDFSphere setRadius(float radius) { - this.radius = radius; + this.radius = radius; return this; } diff --git a/src/main/java/ru/bclib/util/BlocksHelper.java b/src/main/java/ru/bclib/util/BlocksHelper.java index 21b974f9..1ba8952a 100644 --- a/src/main/java/ru/bclib/util/BlocksHelper.java +++ b/src/main/java/ru/bclib/util/BlocksHelper.java @@ -1,10 +1,6 @@ package ru.bclib.util; -import java.util.Map; -import java.util.Random; - import com.google.common.collect.Maps; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -18,48 +14,51 @@ import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Property; +import java.util.Map; +import java.util.Random; + public class BlocksHelper { private static final Map COLOR_BY_BLOCK = Maps.newHashMap(); - + public static final int FLAG_UPDATE_BLOCK = 1; public static final int FLAG_SEND_CLIENT_CHANGES = 2; public static final int FLAG_NO_RERENDER = 4; public static final int FORSE_RERENDER = 8; public static final int FLAG_IGNORE_OBSERVERS = 16; - + public static final int SET_SILENT = FLAG_UPDATE_BLOCK | FLAG_IGNORE_OBSERVERS | FLAG_SEND_CLIENT_CHANGES; public static final int SET_OBSERV = FLAG_UPDATE_BLOCK | FLAG_SEND_CLIENT_CHANGES; public static final Direction[] HORIZONTAL = makeHorizontal(); public static final Direction[] DIRECTIONS = Direction.values(); - + private static final MutableBlockPos POS = new MutableBlockPos(); protected static final BlockState AIR = Blocks.AIR.defaultBlockState(); protected static final BlockState WATER = Blocks.WATER.defaultBlockState(); - + public static void addBlockColor(Block block, int color) { COLOR_BY_BLOCK.put(block, color); } - + public static int getBlockColor(Block block) { return COLOR_BY_BLOCK.getOrDefault(block, 0xFF000000); } - + public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, BlockState state) { world.setBlock(pos, state, SET_SILENT); } - + public static void setWithoutUpdate(LevelAccessor world, BlockPos pos, Block block) { world.setBlock(pos, block.defaultBlockState(), SET_SILENT); } - + public static void setWithUpdate(LevelAccessor world, BlockPos pos, BlockState state) { world.setBlock(pos, state, SET_OBSERV); } - + public static void setWithUpdate(LevelAccessor world, BlockPos pos, Block block) { world.setBlock(pos, block.defaultBlockState(), SET_OBSERV); } - + public static int upRay(LevelAccessor world, BlockPos pos, int maxDist) { int length = 0; for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.above(j))); j++) { @@ -67,7 +66,7 @@ public class BlocksHelper { } return length; } - + public static int downRay(LevelAccessor world, BlockPos pos, int maxDist) { int length = 0; for (int j = 1; j < maxDist && (world.isEmptyBlock(pos.below(j))); j++) { @@ -75,7 +74,7 @@ public class BlocksHelper { } return length; } - + public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) { POS.set(pos); for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { @@ -83,7 +82,7 @@ public class BlocksHelper { } return pos.getY() - POS.getY(); } - + public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) { POS.set(pos); for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) { @@ -91,21 +90,23 @@ public class BlocksHelper { } return (int) pos.distSqr(POS); } - + /** * Rotates {@link BlockState} horizontally. Used in block classes with {@link Direction} {@link Property} in rotate function. - * @param state - {@link BlockState} to mirror; + * + * @param state - {@link BlockState} to mirror; * @param rotation - {@link Rotation}; - * @param facing - Block {@link Direction} {@link Property}. + * @param facing - Block {@link Direction} {@link Property}. * @return Rotated {@link BlockState}. */ public static BlockState rotateHorizontal(BlockState state, Rotation rotation, Property facing) { return state.setValue(facing, rotation.rotate(state.getValue(facing))); } - + /** * Mirrors {@link BlockState} horizontally. Used in block classes with {@link Direction} {@link Property} in mirror function. - * @param state - {@link BlockState} to mirror; + * + * @param state - {@link BlockState} to mirror; * @param mirror - {@link Mirror}; * @param facing - Block {@link Direction} {@link Property}. * @return Mirrored {@link BlockState}. @@ -113,11 +114,12 @@ public class BlocksHelper { public static BlockState mirrorHorizontal(BlockState state, Mirror mirror, Property facing) { return state.rotate(mirror.getRotation(state.getValue(facing))); } - + /** * Counts the amount of same block down. + * * @param world - {@link LevelAccessor} world; - * @param pos - {@link BlockPos} start position; + * @param pos - {@link BlockPos} start position; * @param block - {@link Block} to count. * @return Integer amount of blocks. */ @@ -128,36 +130,40 @@ public class BlocksHelper { } return count; } - + /** * Creates a new {@link Direction} array with clockwise order: * NORTH, EAST, SOUTH, WEST + * * @return Array of {@link Direction}. */ public static Direction[] makeHorizontal() { - return new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST }; + return new Direction[] {Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST}; } - + /** * Get any random horizontal {@link Direction}. + * * @param random - {@link Random}. * @return {@link Direction}. */ public static Direction randomHorizontal(Random random) { return HORIZONTAL[random.nextInt(4)]; } - + /** * Get any random {@link Direction} including vertical and horizontal. + * * @param random - {@link Random}. * @return {@link Direction}. */ public static Direction randomDirection(Random random) { return DIRECTIONS[random.nextInt(6)]; } - + /** * Check if block is {@link Fluid} or not. + * * @param state - {@link BlockState} to check. * @return {@code true} if block is fluid and {@code false} if not. */ @@ -167,9 +173,10 @@ public class BlocksHelper { /** * Check if block is "invulnerable" like Bedrock. + * * @param state - {@link BlockState} to check; * @param world - {@link BlockGetter} world where BlockState exist; - * @param pos - {@link BlockPos} where BlockState is. + * @param pos - {@link BlockPos} where BlockState is. * @return {@code true} if block is "invulnerable" and {@code false} if not. */ public static boolean isInvulnerable(BlockState state, BlockGetter world, BlockPos pos) { @@ -178,6 +185,7 @@ public class BlocksHelper { /** * Check if block is "invulnerable" like Bedrock. Unlike safe function will pass world and position parameters as {@code null}. + * * @param state - {@link BlockState} to check. * @return {@code true} if block is "invulnerable" and {@code false} if not. */ diff --git a/src/main/java/ru/bclib/util/ColorExtractor.java b/src/main/java/ru/bclib/util/ColorExtractor.java index 9614345d..e383a5d3 100644 --- a/src/main/java/ru/bclib/util/ColorExtractor.java +++ b/src/main/java/ru/bclib/util/ColorExtractor.java @@ -9,7 +9,7 @@ public class ColorExtractor { private List
centers = new ArrayList<>(); private List colors; private Integer result; - + public ColorExtractor(List colors) { this.colors = colors; Random rnd = new Random(); @@ -19,7 +19,7 @@ public class ColorExtractor { this.centers.add(new Center(color)); } } - + public int analize() { boolean moved = true; while (moved) { @@ -41,10 +41,10 @@ public class ColorExtractor { toClear.forEach(clear -> centers.remove(clear)); } this.centers.sort(Center.COMPARATOR); - + return this.getResult(); } - + public int getResult() { if (result == null) { double weights = 0; @@ -59,19 +59,20 @@ public class ColorExtractor { red += center.r * weight; green += center.g * weight; blue += center.b * weight; - } ; - + } + ; + int a = (int) Math.round(alpha / weights); int r = (int) Math.round(red / weights); int g = (int) Math.round(green / weights); int b = (int) Math.round(blue / weights); - + this.result = a << 24 | r << 16 | g << 8 | b; } - + return this.result; } - + private void remap() { this.centers.forEach(entry -> entry.colors.clear()); this.colors.forEach(color -> { @@ -89,7 +90,7 @@ public class ColorExtractor { this.centers.get(id).colors.add(color); }); } - + private static class Center { static final Comparator
COMPARATOR = new Comparator
() { @Override @@ -97,24 +98,24 @@ public class ColorExtractor { return Integer.compare(c1.getColor(), c2.getColor()); } }; - + List colors = new ArrayList<>(); double a, r, g, b; - + Center(int color) { this.a = (color >> 24) & 255; this.r = (color >> 16) & 255; this.g = (color >> 8) & 255; this.b = color & 255; } - + private void update(double a, double r, double g, double b) { this.a = a; this.r = r; this.g = g; this.b = b; } - + public int getColor() { int a = (int) Math.round(this.a); int r = (int) Math.round(this.r); @@ -122,7 +123,7 @@ public class ColorExtractor { int b = (int) Math.round(this.b); return a << 24 | r << 16 | g << 8 | b; } - + public boolean move() { double or = r; double og = g; @@ -139,9 +140,9 @@ public class ColorExtractor { r /= size; g /= size; b /= size; - + this.update(a, r, g, b); - + return Math.abs(r - or) > 0.1 || Math.abs(g - og) > 0.1 || Math.abs(b - ob) > 0.1; } } diff --git a/src/main/java/ru/bclib/util/ColorUtil.java b/src/main/java/ru/bclib/util/ColorUtil.java index 179dff9e..d091e83d 100644 --- a/src/main/java/ru/bclib/util/ColorUtil.java +++ b/src/main/java/ru/bclib/util/ColorUtil.java @@ -1,13 +1,7 @@ package ru.bclib.util; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - import com.google.common.collect.Maps; import com.mojang.blaze3d.platform.NativeImage; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.client.indigo.renderer.helper.ColorHelper; @@ -21,39 +15,39 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import ru.bclib.BCLib; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + public class ColorUtil { private static final float[] FLOAT_BUFFER = new float[4]; private static final int ALPHA = 255 << 24; - + public static int color(int r, int g, int b) { return ALPHA | (r << 16) | (g << 8) | b; } - + public static int color(String hex) { int r = Integer.parseInt(hex.substring(0, 2), 16); int g = Integer.parseInt(hex.substring(2, 4), 16); int b = Integer.parseInt(hex.substring(4, 6), 16); return color(r, g, b); } - + public static int[] toIntArray(int color) { - return new int[] { - (color >> 24) & 255, - (color >> 16) & 255, - (color >> 8) & 255, - color & 255 - }; + return new int[] {(color >> 24) & 255, (color >> 16) & 255, (color >> 8) & 255, color & 255}; } - + public static float[] toFloatArray(int color) { FLOAT_BUFFER[0] = ((color >> 16 & 255) / 255.0F); FLOAT_BUFFER[1] = ((color >> 8 & 255) / 255.0F); FLOAT_BUFFER[2] = ((color & 255) / 255.0F); FLOAT_BUFFER[3] = ((color >> 24 & 255) / 255.0F); - + return FLOAT_BUFFER; } - + public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) { float hue, saturation, brightness; if (hsbvals == null) { @@ -63,34 +57,27 @@ public class ColorUtil { if (b > cmax) cmax = b; int cmin = (r < g) ? r : g; if (b < cmin) cmin = b; - + brightness = ((float) cmax) / 255.0F; - if (cmax != 0) - saturation = ((float) (cmax - cmin)) / ((float) cmax); - else - saturation = 0; - if (saturation == 0) - hue = 0; + if (cmax != 0) saturation = ((float) (cmax - cmin)) / ((float) cmax); + else saturation = 0; + if (saturation == 0) hue = 0; else { float redc = ((float) (cmax - r)) / ((float) (cmax - cmin)); float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin)); float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin)); - if (r == cmax) - hue = bluec - greenc; - else if (g == cmax) - hue = 2.0F + redc - bluec; - else - hue = 4.0F + greenc - redc; + if (r == cmax) hue = bluec - greenc; + else if (g == cmax) hue = 2.0F + redc - bluec; + else hue = 4.0F + greenc - redc; hue = hue / 6.0F; - if (hue < 0) - hue = hue + 1.0F; + if (hue < 0) hue = hue + 1.0F; } hsbvals[0] = hue; hsbvals[1] = saturation; hsbvals[2] = brightness; return hsbvals; } - + public static int HSBtoRGB(float hue, float saturation, float brightness) { int r = 0, g = 0, b = 0; if (saturation == 0) { @@ -137,13 +124,13 @@ public class ColorUtil { } return 0xFF000000 | (r << 16) | (g << 8) | (b << 0); } - + public static int parseHex(String hexColor) { int len = hexColor.length(); if (len < 6 || len > 8 || len % 2 > 0) { return -1; } - + int color, shift; if (len == 6) { color = 0xFF000000; @@ -153,7 +140,7 @@ public class ColorUtil { color = 0; shift = 24; } - + try { String[] splited = hexColor.split("(?<=\\G.{2})"); for (String digit : splited) { @@ -165,17 +152,17 @@ public class ColorUtil { BCLib.LOGGER.catching(ex); return -1; } - + return color; } - + public static int toABGR(int color) { int r = (color >> 16) & 255; int g = (color >> 8) & 255; int b = color & 255; return 0xFF000000 | b << 16 | g << 8 | r; } - + public static int ABGRtoARGB(int color) { int a = (color >> 24) & 255; int b = (color >> 16) & 255; @@ -183,18 +170,18 @@ public class ColorUtil { int r = color & 255; return a << 24 | r << 16 | g << 8 | b; } - + public static int colorBrigtness(int color, float val) { RGBtoHSB((color >> 16) & 255, (color >> 8) & 255, color & 255, FLOAT_BUFFER); FLOAT_BUFFER[2] += val / 10.0F; FLOAT_BUFFER[2] = Mth.clamp(FLOAT_BUFFER[2], 0.0F, 1.0F); return HSBtoRGB(FLOAT_BUFFER[0], FLOAT_BUFFER[1], FLOAT_BUFFER[2]); } - + public static int applyTint(int color, int tint) { return colorBrigtness(ColorHelper.multiplyColor(color, tint), 1.5F); } - + public static int colorDistance(int color1, int color2) { int r1 = (color1 >> 16) & 255; int g1 = (color1 >> 8) & 255; @@ -204,9 +191,9 @@ public class ColorUtil { int b2 = color2 & 255; return MHelper.sqr(r1 - r2) + MHelper.sqr(g1 - g2) + MHelper.sqr(b1 - b2); } - + private static Map colorPalette = Maps.newHashMap(); - + @Environment(EnvType.CLIENT) public static int extractColor(Item item) { ResourceLocation id = Registry.ITEM.getKey(item); @@ -232,16 +219,16 @@ public class ColorUtil { } } image.close(); - + if (colors.size() == 0) return -1; - + ColorExtractor extractor = new ColorExtractor(colors); int color = extractor.analize(); colorPalette.put(id, color); - + return color; } - + @Environment(EnvType.CLIENT) public static NativeImage loadImage(ResourceLocation image, int w, int h) { Minecraft minecraft = Minecraft.getInstance(); diff --git a/src/main/java/ru/bclib/util/JsonFactory.java b/src/main/java/ru/bclib/util/JsonFactory.java index 9397f32c..72df3a38 100644 --- a/src/main/java/ru/bclib/util/JsonFactory.java +++ b/src/main/java/ru/bclib/util/JsonFactory.java @@ -1,5 +1,11 @@ package ru.bclib.util; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import ru.bclib.BCLib; + import java.io.File; import java.io.FileReader; import java.io.FileWriter; @@ -8,16 +14,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; - -import ru.bclib.BCLib; - public class JsonFactory { public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - + public static JsonObject getJsonObject(InputStream stream) { try { Reader reader = new InputStreamReader(stream); @@ -32,7 +31,7 @@ public class JsonFactory { } return new JsonObject(); } - + public static JsonObject getJsonObject(File jsonFile) { if (jsonFile.exists()) { JsonElement json = loadJson(jsonFile); @@ -43,7 +42,7 @@ public class JsonFactory { } return new JsonObject(); } - + public static JsonElement loadJson(File jsonFile) { if (jsonFile.exists()) { try (Reader reader = new FileReader(jsonFile)) { @@ -55,11 +54,11 @@ public class JsonFactory { } return null; } - + public static JsonElement loadJson(Reader reader) { return GSON.fromJson(reader, JsonElement.class); } - + public static void storeJson(File jsonFile, JsonElement jsonObject) { try (FileWriter writer = new FileWriter(jsonFile)) { String json = GSON.toJson(jsonObject); @@ -70,22 +69,22 @@ public class JsonFactory { BCLib.LOGGER.catching(ex); } } - + public static int getInt(JsonObject object, String member, int def) { JsonElement elem = object.get(member); return elem == null ? def : elem.getAsInt(); } - + public static float getFloat(JsonObject object, String member, float def) { JsonElement elem = object.get(member); return elem == null ? def : elem.getAsFloat(); } - + public static boolean getBoolean(JsonObject object, String member, boolean def) { JsonElement elem = object.get(member); return elem == null ? def : elem.getAsBoolean(); } - + public static String getString(JsonObject object, String member, String def) { JsonElement elem = object.get(member); return elem == null ? def : elem.getAsString(); diff --git a/src/main/java/ru/bclib/util/Logger.java b/src/main/java/ru/bclib/util/Logger.java index 52721bac..68cce157 100644 --- a/src/main/java/ru/bclib/util/Logger.java +++ b/src/main/java/ru/bclib/util/Logger.java @@ -6,56 +6,56 @@ import org.apache.logging.log4j.LogManager; public final class Logger { private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(); private final String modPref; - + public Logger(String modID) { this.modPref = "[" + modID + "] "; } - + public void log(Level level, String message) { LOGGER.log(level, modPref + message); } - + public void log(Level level, String message, Object... params) { LOGGER.log(level, modPref + message, params); } - + public void debug(Object message) { this.log(Level.DEBUG, message.toString()); } - + public void debug(Object message, Object... params) { this.log(Level.DEBUG, message.toString(), params); } - + public void catching(Throwable ex) { this.error(ex.getLocalizedMessage()); LOGGER.catching(ex); } - + public void info(String message) { this.log(Level.INFO, message); } - + public void info(String message, Object... params) { this.log(Level.INFO, message, params); } - + public void warning(String message, Object... params) { this.log(Level.WARN, message, params); } - + public void warning(String message, Object obj, Exception ex) { LOGGER.warn(modPref + message, obj, ex); } - + public void error(String message) { this.log(Level.ERROR, message); } - + public void error(String message, Object obj, Exception ex) { LOGGER.error(modPref + message, obj, ex); } - + public void error(String message, Exception ex) { LOGGER.error(modPref + message, ex); } diff --git a/src/main/java/ru/bclib/util/MHelper.java b/src/main/java/ru/bclib/util/MHelper.java index b7d53913..95bb8853 100644 --- a/src/main/java/ru/bclib/util/MHelper.java +++ b/src/main/java/ru/bclib/util/MHelper.java @@ -1,18 +1,17 @@ package ru.bclib.util; -import java.util.Random; - import com.mojang.math.Vector3f; - import net.minecraft.core.Vec3i; +import java.util.Random; + public class MHelper { private static final Vec3i[] RANDOM_OFFSETS = new Vec3i[3 * 3 * 3 - 1]; private static final float RAD_TO_DEG = 57.295779513082320876798154814105F; public static final float PHI = (float) (Math.PI * (3 - Math.sqrt(5))); public static final float PI2 = (float) (Math.PI * 2); public static final Random RANDOM = new Random(); - + public static int randRange(int min, int max, Random random) { return min + random.nextInt(max - min + 1); } @@ -20,37 +19,37 @@ public class MHelper { public static double randRange(double min, double max, Random random) { return min + random.nextDouble() * (max - min); } - + public static float randRange(float min, float max, Random random) { return min + random.nextFloat() * (max - min); } - + public static byte setBit(byte source, int pos, boolean value) { return value ? setBitTrue(source, pos) : setBitFalse(source, pos); } - + public static byte setBitTrue(byte source, int pos) { source |= 1 << pos; return source; } - + public static byte setBitFalse(byte source, int pos) { source &= ~(1 << pos); return source; } - + public static boolean getBit(byte source, int pos) { return ((source >> pos) & 1) == 1; } - + public static float wrap(float x, float side) { return x - floor(x / side) * side; } - + public static int floor(double x) { return x < 0 ? (int) (x - 1) : (int) x; } - + public static int min(int a, int b) { return a < b ? a : b; } @@ -134,7 +133,7 @@ public class MHelper { h = (h ^ (h >> 13)) * 1274126177; return h ^ (h >> 16); } - + public static int getSeed(int seed, int x, int y, int z) { int h = seed + x * 374761393 + y * 668265263 + z; h = (h ^ (h >> 13)) * 1274126177; @@ -149,7 +148,7 @@ public class MHelper { array[i2] = element; } } - + public static int sqr(int i) { return i * i; } @@ -170,8 +169,7 @@ public class MHelper { return value / RAD_TO_DEG; } - public static Vector3f cross(Vector3f vec1, Vector3f vec2) - { + public static Vector3f cross(Vector3f vec1, Vector3f vec2) { float cx = vec1.y() * vec2.z() - vec1.z() * vec2.y(); float cy = vec1.z() * vec2.x() - vec1.x() * vec2.z(); float cz = vec1.x() * vec2.y() - vec1.y() * vec2.x(); diff --git a/src/main/java/ru/bclib/util/SplineHelper.java b/src/main/java/ru/bclib/util/SplineHelper.java index 0b1e8a75..844e357a 100644 --- a/src/main/java/ru/bclib/util/SplineHelper.java +++ b/src/main/java/ru/bclib/util/SplineHelper.java @@ -1,13 +1,7 @@ package ru.bclib.util; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.function.Function; - import com.google.common.collect.Lists; import com.mojang.math.Vector3f; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.util.Mth; @@ -17,6 +11,11 @@ import ru.bclib.sdf.SDF; import ru.bclib.sdf.operator.SDFUnion; import ru.bclib.sdf.primitive.SDFLine; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.function.Function; + public class SplineHelper { public static List makeSpline(float x1, float y1, float z1, float x2, float y2, float z2, int points) { List spline = Lists.newArrayList(); @@ -86,11 +85,7 @@ public class SplineHelper { for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); float delta = (float) (i - 1) / max; - SDF line = new SDFLine() - .setRadius(Mth.lerp(delta, radius1, radius2)) - .setStart(start.x(), start.y(), start.z()) - .setEnd(pos.x(), pos.y(), pos.z()) - .setBlock(placerFunction); + SDF line = new SDFLine().setRadius(Mth.lerp(delta, radius1, radius2)).setStart(start.x(), start.y(), start.z()).setEnd(pos.x(), pos.y(), pos.z()).setBlock(placerFunction); result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line); start = pos; } @@ -105,11 +100,7 @@ public class SplineHelper { for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); float delta = (float) (i - 1) / max; - SDF line = new SDFLine() - .setRadius(radiusFunction.apply(delta)) - .setStart(start.x(), start.y(), start.z()) - .setEnd(pos.x(), pos.y(), pos.z()) - .setBlock(placerFunction); + SDF line = new SDFLine().setRadius(radiusFunction.apply(delta)).setStart(start.x(), start.y(), start.z()).setEnd(pos.x(), pos.y(), pos.z()).setBlock(placerFunction); result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line); start = pos; } @@ -309,7 +300,7 @@ public class SplineHelper { } public static void rotateSpline(List spline, float angle) { - for (Vector3f v: spline) { + for (Vector3f v : spline) { float sin = (float) Math.sin(angle); float cos = (float) Math.cos(angle); float x = v.x() * cos + v.z() * sin; @@ -320,7 +311,7 @@ public class SplineHelper { public static List copySpline(List spline) { List result = new ArrayList(spline.size()); - for (Vector3f v: spline) { + for (Vector3f v : spline) { result.add(new Vector3f(v.x(), v.y(), v.z())); } return result; @@ -331,13 +322,13 @@ public class SplineHelper { } public static void scale(List spline, float x, float y, float z) { - for (Vector3f v: spline) { + for (Vector3f v : spline) { v.set(v.x() * x, v.y() * y, v.z() * z); } } public static void offset(List spline, Vector3f offset) { - for (Vector3f v: spline) { + for (Vector3f v : spline) { v.set(offset.x() + v.x(), offset.y() + v.y(), offset.z() + v.z()); } } diff --git a/src/main/java/ru/bclib/util/StructureHelper.java b/src/main/java/ru/bclib/util/StructureHelper.java index 9d724ac8..aed50005 100644 --- a/src/main/java/ru/bclib/util/StructureHelper.java +++ b/src/main/java/ru/bclib/util/StructureHelper.java @@ -1,16 +1,6 @@ package ru.bclib.util; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Random; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - import com.google.common.collect.Sets; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -31,6 +21,15 @@ import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.Vec3; import ru.bclib.api.TagAPI; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Random; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + public class StructureHelper { private static final Direction[] DIR = BlocksHelper.makeHorizontal(); @@ -54,7 +53,7 @@ public class StructureHelper { long compressedSize = entry.getCompressedSize(); long normalSize = entry.getSize(); String type = entry.isDirectory() ? "DIR" : "FILE"; - + System.out.println(name); System.out.format("\t %s - %d - %d\n", type, compressedSize, normalSize); } @@ -80,10 +79,10 @@ public class StructureHelper { private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException { CompoundTag nbttagcompound = NbtIo.readCompressed(stream); - + StructureTemplate template = new StructureTemplate(); template.load(nbttagcompound); - + return template; } @@ -181,7 +180,7 @@ public class StructureHelper { } if (!state.isAir() && random.nextBoolean()) { MHelper.shuffle(DIR, random); - for (Direction dir: DIR) { + for (Direction dir : DIR) { if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below().relative(dir))) { BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR); mut.move(dir).move(Direction.DOWN); @@ -226,7 +225,7 @@ public class StructureHelper { } } } - + public static void erodeIntense(WorldGenLevel world, BoundingBox bounds, Random random) { MutableBlockPos mut = new MutableBlockPos(); MutableBlockPos mut2 = new MutableBlockPos(); @@ -261,12 +260,12 @@ public class StructureHelper { } } } - + drop(world, bounds); } private static boolean isTerrainNear(WorldGenLevel world, BlockPos pos) { - for (Direction dir: BlocksHelper.DIRECTIONS) { + for (Direction dir : BlocksHelper.DIRECTIONS) { if (world.getBlockState(pos.relative(dir)).is(TagAPI.GEN_TERRAIN)) { return true; } @@ -300,8 +299,8 @@ public class StructureHelper { } while (!edge.isEmpty()) { - for (BlockPos center: edge) { - for (Direction dir: BlocksHelper.DIRECTIONS) { + for (BlockPos center : edge) { + for (Direction dir : BlocksHelper.DIRECTIONS) { BlockState state = world.getBlockState(center); if (state.isCollisionShapeFullBlock(world, center)) { mut.set(center).move(dir); @@ -343,16 +342,9 @@ public class StructureHelper { } } } - + private static boolean ignore(BlockState state, WorldGenLevel world, BlockPos pos) { - return state.getMaterial().isReplaceable() || - !state.getFluidState().isEmpty() || - state.is(TagAPI.END_GROUND) || - state.is(BlockTags.LOGS) || - state.is(BlockTags.LEAVES) || - state.getMaterial().equals(Material.PLANT) || - state.getMaterial().equals(Material.LEAVES) || - BlocksHelper.isInvulnerable(state, world, pos); + return state.getMaterial().isReplaceable() || !state.getFluidState().isEmpty() || state.is(TagAPI.END_GROUND) || state.is(BlockTags.LOGS) || state.is(BlockTags.LEAVES) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES) || BlocksHelper.isInvulnerable(state, world, pos); } public static void cover(WorldGenLevel world, BoundingBox bounds, Random random) { diff --git a/src/main/java/ru/bclib/util/TagHelper.java b/src/main/java/ru/bclib/util/TagHelper.java index dae193d0..29126662 100644 --- a/src/main/java/ru/bclib/util/TagHelper.java +++ b/src/main/java/ru/bclib/util/TagHelper.java @@ -1,11 +1,7 @@ package ru.bclib.util; -import java.util.Map; -import java.util.Set; - import com.google.common.collect.Maps; import com.google.common.collect.Sets; - import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; @@ -13,6 +9,9 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; +import java.util.Map; +import java.util.Set; + public class TagHelper { private static final Map> TAGS_BLOCK = Maps.newConcurrentMap(); private static final Map> TAGS_ITEM = Maps.newConcurrentMap(); @@ -20,7 +19,7 @@ public class TagHelper { public static void addTag(Tag.Named tag, Block... blocks) { ResourceLocation tagID = tag.getName(); Set set = TAGS_BLOCK.computeIfAbsent(tagID, k -> Sets.newHashSet()); - for (Block block: blocks) { + for (Block block : blocks) { ResourceLocation id = Registry.BLOCK.getKey(block); if (id != Registry.BLOCK.getDefaultKey()) { set.add(id); @@ -31,7 +30,7 @@ public class TagHelper { public static void addTag(Tag.Named tag, ItemLike... items) { ResourceLocation tagID = tag.getName(); Set set = TAGS_ITEM.computeIfAbsent(tagID, k -> Sets.newHashSet()); - for (ItemLike item: items) { + for (ItemLike item : items) { ResourceLocation id = Registry.ITEM.getKey(item.asItem()); if (id != Registry.ITEM.getDefaultKey()) { set.add(id); @@ -41,14 +40,14 @@ public class TagHelper { @SafeVarargs public static void addTags(ItemLike item, Tag.Named... tags) { - for (Tag.Named tag: tags) { + for (Tag.Named tag : tags) { addTag(tag, item); } } @SafeVarargs public static void addTags(Block block, Tag.Named... tags) { - for (Tag.Named tag: tags) { + for (Tag.Named tag : tags) { addTag(tag, block); } } @@ -62,7 +61,8 @@ public class TagHelper { Map> endTags = null; if ("tags/blocks".equals(directory)) { endTags = TAGS_BLOCK; - } else if ("tags/items".equals(directory)) { + } + else if ("tags/items".equals(directory)) { endTags = TAGS_ITEM; } if (endTags != null) { diff --git a/src/main/java/ru/bclib/util/TranslationHelper.java b/src/main/java/ru/bclib/util/TranslationHelper.java index 68ad5412..3540a39a 100644 --- a/src/main/java/ru/bclib/util/TranslationHelper.java +++ b/src/main/java/ru/bclib/util/TranslationHelper.java @@ -1,18 +1,17 @@ package ru.bclib.util; +import com.google.common.collect.Lists; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.resources.ResourceLocation; + import java.io.InputStream; import java.io.InputStreamReader; import java.util.Collections; import java.util.List; -import com.google.common.collect.Lists; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import net.minecraft.core.Registry; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.resources.ResourceLocation; - public class TranslationHelper { public static void printMissingNames(String modID) { List missingNamesEn = Lists.newArrayList(); diff --git a/src/main/java/ru/bclib/util/WeighTree.java b/src/main/java/ru/bclib/util/WeighTree.java index 096747c4..8aca4f5f 100644 --- a/src/main/java/ru/bclib/util/WeighTree.java +++ b/src/main/java/ru/bclib/util/WeighTree.java @@ -14,6 +14,7 @@ public class WeighTree { /** * Get eandom value from tree. + * * @param random - {@link Random}. * @return {@link T} value. */ @@ -53,7 +54,7 @@ public class WeighTree { this.min = min; this.max = max; } - + @Override T get(float value) { return value < separator ? min.get(value) : max.get(value); @@ -71,7 +72,7 @@ public class WeighTree { Leaf(T value) { this.biome = value; } - + @Override T get(float value) { return biome; diff --git a/src/main/java/ru/bclib/util/WeightedList.java b/src/main/java/ru/bclib/util/WeightedList.java index 5455dd39..3a7f3680 100644 --- a/src/main/java/ru/bclib/util/WeightedList.java +++ b/src/main/java/ru/bclib/util/WeightedList.java @@ -12,6 +12,7 @@ public class WeightedList { /** * Adds value with specified weight to the list + * * @param value * @param weight */ @@ -23,6 +24,7 @@ public class WeightedList { /** * Get random value. + * * @param random - {@link Random}. * @return {@link T} value. */ @@ -41,6 +43,7 @@ public class WeightedList { /** * Get value by index. + * * @param index - {@code int} index. * @return {@link T} value. */ @@ -50,33 +53,37 @@ public class WeightedList { /** * Get value weight. Weight is summed with all previous values weights. + * * @param index - {@code int} index. * @return {@code float} weight. */ public float getWeight(int index) { return weights.get(index); } - + /** * Chech if the list is empty. + * * @return {@code true} if list is empty and {@code false} if not. */ public boolean isEmpty() { return maxWeight == 0; } - + /** * Get the list size. + * * @return {@code int} list size. */ public int size() { return values.size(); } - + /** * Makes a sublist of this list with same weights. Used only in {@link WeighTree} + * * @param start - {@code int} start index (inclusive). - * @param end - {@code int} end index (exclusive). + * @param end - {@code int} end index (exclusive). * @return {@link WeightedList}. */ protected WeightedList subList(int start, int end) { @@ -87,26 +94,29 @@ public class WeightedList { } return list; } - + /** * Check if list contains certain value. + * * @param value - {@link T} value. * @return {@code true} if value is in list and {@code false} if not. */ public boolean contains(T value) { return values.contains(value); } - + /** * Applies {@link Consumer} to all values in list. + * * @param function - {@link Consumer}. */ public void forEach(Consumer function) { values.forEach(function); } - + /** * Get the maximum weight of the tree. + * * @return {@code float} maximum weight. */ public float getMaxWeight() { diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index d6326ebe..dcae78c1 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -1,15 +1,9 @@ package ru.bclib.world.biomes; -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import java.util.Random; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; @@ -21,23 +15,28 @@ import ru.bclib.world.features.ListFeature; import ru.bclib.world.features.ListFeature.StructureInfo; import ru.bclib.world.features.NBTStructureFeature.TerrainMerge; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Random; + public class BCLBiome { protected WeightedList subbiomes = new WeightedList(); - + protected final Biome biome; protected final ResourceLocation mcID; protected BCLBiome edge; protected int edgeSize; - + protected BCLBiome biomeParent; protected float maxSubBiomeChance = 1; protected final float genChance; - + private final Map customData; private final float fogDensity; private BCLFeature structuresFeature; private Biome actualBiome; - + public BCLBiome(BCLBiomeDef definition) { this.mcID = definition.getID(); this.readStructureList(); @@ -49,7 +48,7 @@ public class BCLBiome { this.fogDensity = definition.getFodDensity(); this.customData = definition.getCustomData(); } - + public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) { this.mcID = id; this.biome = biome; @@ -58,24 +57,24 @@ public class BCLBiome { this.readStructureList(); this.customData = Maps.newHashMap(); } - + public BCLBiome getEdge() { return edge == null ? this : edge; } - + public void setEdge(BCLBiome edge) { this.edge = edge; edge.biomeParent = this; } - + public int getEdgeSize() { return edgeSize; } - + public void setEdgeSize(int size) { edgeSize = size; } - + public void addSubBiome(BCLBiome biome) { biome.biomeParent = this; subbiomes.add(biome, biome.getGenChance()); @@ -84,41 +83,41 @@ public class BCLBiome { public boolean containsSubBiome(BCLBiome biome) { return subbiomes.contains(biome); } - + public BCLBiome getSubBiome(Random random) { BCLBiome biome = subbiomes.get(random); return biome == null ? this : biome; } - + public BCLBiome getParentBiome() { return this.biomeParent; } - + public boolean hasEdge() { return edge != null; } - + public boolean hasParentBiome() { return biomeParent != null; } - + public boolean isSame(BCLBiome biome) { return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this); } - + public Biome getBiome() { return biome; } - + @Override public String toString() { return mcID.toString(); } - + public ResourceLocation getID() { return mcID; } - + public float getFogDensity() { return fogDensity; } @@ -126,7 +125,7 @@ public class BCLBiome { protected void readStructureList() { String ns = mcID.getNamespace(); String nm = mcID.getPath(); - + String path = "/data/" + ns + "/structures/biome/" + nm + "/"; InputStream inputstream = StructureHelper.class.getResourceAsStream(path + "structures.json"); if (inputstream != null) { @@ -155,7 +154,7 @@ public class BCLBiome { public Biome getActualBiome() { return this.actualBiome; } - + public float getGenChance() { return this.genChance; } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 1d77c26d..3c5e6013 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -1,11 +1,7 @@ package ru.bclib.world.biomes; -import java.util.List; -import java.util.Map; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; - import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.resources.ResourceLocation; @@ -32,7 +28,6 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.feature.configurations.ProbabilityFeatureConfiguration; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; @@ -42,6 +37,9 @@ import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; import ru.bclib.world.surface.DoubleBlockSurfaceBuilder; +import java.util.List; +import java.util.Map; + public class BCLBiomeDef { public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64); public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); @@ -55,13 +53,13 @@ public class BCLBiomeDef { private final Map customData = Maps.newHashMap(); private final ResourceLocation id; - + private AmbientParticleSettings particleConfig; private AmbientAdditionsSettings additions; private AmbientMoodSettings mood; private SoundEvent music; private SoundEvent loop; - + private int foliageColor = DEF_FOLIAGE_OVERWORLD; private int grassColor = DEF_FOLIAGE_OVERWORLD; private int waterFogColor = 329011; @@ -78,17 +76,19 @@ public class BCLBiomeDef { private int edgeSize = 32; private ConfiguredSurfaceBuilder surface; - + /** * Custom biome definition. Can be extended with new parameters. + * * @param id - Biome {@link ResourceLocation} (identifier). */ public BCLBiomeDef(ResourceLocation id) { this.id = id; } - /** + /** * Create default definition for The Nether biome. + * * @return {@link BCLBiomeDef}. */ public BCLBiomeDef netherBiome() { @@ -98,8 +98,9 @@ public class BCLBiomeDef { return this; } - /** + /** * Create default definition for The End biome. + * * @return {@link BCLBiomeDef}. */ public BCLBiomeDef endBiome() { @@ -111,6 +112,7 @@ public class BCLBiomeDef { /** * Used to load biome settings from config. + * * @param config - {@link IdConfig}. * @return this {@link BCLBiomeDef}. */ @@ -123,6 +125,7 @@ public class BCLBiomeDef { /** * Set category of the biome. + * * @param category - {@link BiomeCategory}. * @return this {@link BCLBiomeDef}. */ @@ -137,11 +140,7 @@ public class BCLBiomeDef { } public BCLBiomeDef setSurface(Block block) { - setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration( - block.defaultBlockState(), - Blocks.END_STONE.defaultBlockState(), - Blocks.END_STONE.defaultBlockState() - ))); + setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), Blocks.END_STONE.defaultBlockState(), Blocks.END_STONE.defaultBlockState()))); return this; } @@ -154,7 +153,7 @@ public class BCLBiomeDef { this.surface = builder; return this; } - + public BCLBiomeDef setParticles(ParticleOptions particle, float probability) { this.particleConfig = new AmbientParticleSettings(particle, probability); return this; @@ -184,7 +183,7 @@ public class BCLBiomeDef { this.edgeSize = edgeSize; return this; } - + public BCLBiomeDef addMobSpawn(EntityType type, int weight, int minGroupSize, int maxGroupSize) { ResourceLocation eID = Registry.ENTITY_TYPE.getKey(type); if (eID != Registry.ENTITY_TYPE.getDefaultKey()) { @@ -202,7 +201,7 @@ public class BCLBiomeDef { spawns.add(entry); return this; } - + public BCLBiomeDef addStructureFeature(ConfiguredStructureFeature feature) { structures.add(feature); return this; @@ -220,7 +219,7 @@ public class BCLBiomeDef { features.add(info); return this; } - + public BCLBiomeDef addFeature(Decoration featureStep, ConfiguredFeature feature) { FeatureInfo info = new FeatureInfo(); info.featureStep = featureStep; @@ -235,22 +234,22 @@ public class BCLBiomeDef { b = Mth.clamp(b, 0, 255); return ColorUtil.color(r, g, b); } - + public BCLBiomeDef setFogColor(int r, int g, int b) { this.fogColor = getColor(r, g, b); return this; } - + public BCLBiomeDef setFogDensity(float density) { this.fogDensity = density; return this; } - + public BCLBiomeDef setWaterColor(int r, int g, int b) { this.waterColor = getColor(r, g, b); return this; } - + public BCLBiomeDef setWaterFogColor(int r, int g, int b) { this.waterFogColor = getColor(r, g, b); return this; @@ -273,32 +272,32 @@ public class BCLBiomeDef { public BCLBiomeDef setPlantsColor(int r, int g, int b) { return this.setFoliageColor(r, g, b).setGrassColor(r, g, b); } - + public BCLBiomeDef setLoop(SoundEvent loop) { this.loop = loop; return this; } - + public BCLBiomeDef setMood(SoundEvent mood) { this.mood = new AmbientMoodSettings(mood, 6000, 8, 2.0D); return this; } - + public BCLBiomeDef setAdditions(SoundEvent additions) { this.additions = new AmbientAdditionsSettings(additions, 0.0111); return this; } - + public BCLBiomeDef setMusic(SoundEvent music) { this.music = music; return this; } - + public Biome build() { MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder(); Builder effects = new Builder(); - + mobs.forEach((spawn) -> { spawnSettings.addSpawn(spawn.type.getCategory(), new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize)); }); @@ -311,34 +310,24 @@ public class BCLBiomeDef { structures.forEach((structure) -> generationSettings.addStructureStart(structure)); features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); - + effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor).foliageColorOverride(foliageColor).grassColorOverride(grassColor); if (loop != null) effects.ambientLoopSound(loop); if (mood != null) effects.ambientMoodSound(mood); if (additions != null) effects.ambientAdditionsSound(additions); if (particleConfig != null) effects.ambientParticle(particleConfig); effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - - return new Biome.BiomeBuilder() - .precipitation(precipitation) - .biomeCategory(category) - .depth(depth) - .scale(0.2F) - .temperature(temperature) - .downfall(downfall) - .specialEffects(effects.build()) - .mobSpawnSettings(spawnSettings.build()) - .generationSettings(generationSettings.build()) - .build(); + + return new Biome.BiomeBuilder().precipitation(precipitation).biomeCategory(category).depth(depth).scale(0.2F).temperature(temperature).downfall(downfall).specialEffects(effects.build()).mobSpawnSettings(spawnSettings.build()).generationSettings(generationSettings.build()).build(); } - + private static final class SpawnInfo { EntityType type; int weight; int minGroupSize; int maxGroupSize; } - + private static final class FeatureInfo { Decoration featureStep; ConfiguredFeature feature; @@ -348,7 +337,7 @@ public class BCLBiomeDef { Carving carverStep; ConfiguredWorldCarver carver; } - + public ResourceLocation getID() { return id; } @@ -356,7 +345,7 @@ public class BCLBiomeDef { public float getFodDensity() { return fogDensity; } - + public float getGenChance() { return genChance; } @@ -364,7 +353,7 @@ public class BCLBiomeDef { public int getEdgeSize() { return edgeSize; } - + public BCLBiomeDef addCarver(Carving carverStep, ConfiguredWorldCarver carver) { CarverInfo info = new CarverInfo(); info.carverStep = carverStep; diff --git a/src/main/java/ru/bclib/world/features/BCLDecorators.java b/src/main/java/ru/bclib/world/features/BCLDecorators.java index d037c5f6..ee5b60b2 100644 --- a/src/main/java/ru/bclib/world/features/BCLDecorators.java +++ b/src/main/java/ru/bclib/world/features/BCLDecorators.java @@ -8,7 +8,7 @@ import java.lang.reflect.Field; public class BCLDecorators { public static final ConfiguredDecorator HEIGHTMAP_SQUARE; - + private static final ConfiguredDecorator getDecorator(Field[] fields, int index) { try { return (ConfiguredDecorator) fields[index].get(null); @@ -18,7 +18,7 @@ public class BCLDecorators { return null; } } - + static { Class[] classes = Features.class.getDeclaredClasses(); Field[] fields = classes[1].getDeclaredFields(); // Decorators class diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 2227cddd..df27a021 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -2,9 +2,7 @@ package ru.bclib.world.features; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; -import net.minecraft.data.worldgen.Features; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.BlockTags; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.levelgen.GenerationStep; @@ -15,7 +13,6 @@ import net.minecraft.world.level.levelgen.feature.configurations.CountConfigurat import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; -import net.minecraft.world.level.levelgen.feature.configurations.RangeDecoratorConfiguration; import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration; import net.minecraft.world.level.levelgen.placement.FeatureDecorator; import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; @@ -28,7 +25,7 @@ public class BCLFeature { private ConfiguredFeature featureConfigured; private GenerationStep.Decoration featureStep; private Feature feature; - + public BCLFeature(Feature feature, ConfiguredFeature configuredFeature, GenerationStep.Decoration featureStep) { this.featureConfigured = configuredFeature; this.featureStep = featureStep; @@ -59,10 +56,7 @@ public class BCLFeature { public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, int veins, int veinSize, int offset, int minY, int maxY) { OreConfiguration featureConfig = new OreConfiguration(new BlockMatchTest(Blocks.END_STONE), blockOre.defaultBlockState(), veinSize); OreConfiguration config = new OreConfiguration(ANY_TERRAIN, blockOre.defaultBlockState(), 33); - ConfiguredFeature oreFeature = Feature.ORE.configured(featureConfig) - .rangeUniform(VerticalAnchor.absolute(minY), VerticalAnchor.absolute(maxY)) - .squared() - .count(veins); + ConfiguredFeature oreFeature = Feature.ORE.configured(featureConfig).rangeUniform(VerticalAnchor.absolute(minY), VerticalAnchor.absolute(maxY)).squared().count(veins); return new BCLFeature(Feature.ORE, Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature), GenerationStep.Decoration.UNDERGROUND_ORES); } @@ -89,11 +83,11 @@ public class BCLFeature { public Feature getFeature() { return feature; } - + public ConfiguredFeature getFeatureConfigured() { return featureConfigured; } - + public GenerationStep.Decoration getFeatureStep() { return featureStep; } diff --git a/src/main/java/ru/bclib/world/features/ListFeature.java b/src/main/java/ru/bclib/world/features/ListFeature.java index 8f00c087..a6990896 100644 --- a/src/main/java/ru/bclib/world/features/ListFeature.java +++ b/src/main/java/ru/bclib/world/features/ListFeature.java @@ -1,8 +1,5 @@ package ru.bclib.world.features; -import java.util.List; -import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.Mirror; @@ -11,6 +8,9 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlac import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import ru.bclib.util.StructureHelper; +import java.util.List; +import java.util.Random; + public class ListFeature extends NBTStructureFeature { private final List list; private StructureInfo selected; @@ -24,29 +24,29 @@ public class ListFeature extends NBTStructureFeature { selected = list.get(random.nextInt(list.size())); return selected.getStructure(); } - + @Override protected boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random) { int cx = pos.getX() >> 4; int cz = pos.getZ() >> 4; return ((cx + cz) & 1) == 0 && pos.getY() > 58;// && world.getBlockState(pos.below()).is(EndTags.GEN_TERRAIN); } - + @Override protected Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random) { return Rotation.getRandom(random); } - + @Override protected Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random) { return Mirror.values()[random.nextInt(3)]; } - + @Override protected int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random) { return selected.offsetY; } - + @Override protected TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random) { return selected.terrainMerge; diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index e48bfb5a..afbad417 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -1,9 +1,5 @@ package ru.bclib.world.features; -import java.io.IOException; -import java.io.InputStream; -import java.util.Random; - import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; @@ -17,36 +13,38 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; -import net.minecraft.world.phys.Vec3; import ru.bclib.api.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.world.processors.DestructionStructureProcessor; +import java.io.IOException; +import java.io.InputStream; +import java.util.Random; + public abstract class NBTStructureFeature extends DefaultFeature { protected static final DestructionStructureProcessor DESTRUCTION = new DestructionStructureProcessor(); - + protected abstract StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, Random random); - + protected abstract boolean canSpawn(WorldGenLevel world, BlockPos pos, Random random); - + protected abstract Rotation getRotation(WorldGenLevel world, BlockPos pos, Random random); - + protected abstract Mirror getMirror(WorldGenLevel world, BlockPos pos, Random random); - + protected abstract int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, Random random); - + protected abstract TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, Random random); - + protected abstract void addStructureData(StructurePlaceSettings data); - + protected BlockPos getGround(WorldGenLevel world, BlockPos center) { Biome biome = world.getBiome(center); ResourceLocation id = BiomeAPI.getBiomeID(biome); @@ -59,7 +57,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { return new BlockPos(center.getX(), y, center.getZ()); } } - + protected int getAverageY(WorldGenLevel world, BlockPos center) { int y = getYOnSurface(world, center.getX(), center.getZ()); y += getYOnSurface(world, center.getX() - 2, center.getZ() - 2); @@ -68,7 +66,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { y += getYOnSurface(world, center.getX() + 2, center.getZ() + 2); return y / 5; } - + protected int getAverageYWG(WorldGenLevel world, BlockPos center) { int y = getYOnSurfaceWG(world, center.getX(), center.getZ()); y += getYOnSurfaceWG(world, center.getX() - 2, center.getZ() - 2); @@ -77,33 +75,33 @@ public abstract class NBTStructureFeature extends DefaultFeature { y += getYOnSurfaceWG(world, center.getX() + 2, center.getZ() + 2); return y / 5; } - + @Override public boolean place(FeaturePlaceContext context) { WorldGenLevel world = context.level(); Random random = context.random(); BlockPos center = context.origin(); - + center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8); center = getGround(world, center); - + if (!canSpawn(world, center, random)) { return false; } - + int posY = center.getY() + 1; StructureTemplate structure = getStructure(world, center, random); Rotation rotation = getRotation(world, center, random); Mirror mirror = getMirror(world, center, random); BlockPos offset = StructureTemplate.transform(new BlockPos(structure.getSize()), mirror, rotation, BlockPos.ZERO); center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0); - + BoundingBox bounds = makeBox(center); StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds); addStructureData(placementData); center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5); structure.placeInWorld(world, center, center, placementData, random, 4); - + TerrainMerge merge = getTerrainMerge(world, center, random); int x1 = center.getX(); int z1 = center.getZ(); @@ -111,19 +109,19 @@ public abstract class NBTStructureFeature extends DefaultFeature { int z2 = z1 + offset.getZ(); if (merge != TerrainMerge.NONE) { MutableBlockPos mut = new MutableBlockPos(); - + if (x2 < x1) { int a = x1; x1 = x2; x2 = a; } - + if (z2 < z1) { int a = z1; z1 = z2; z2 = a; } - + int surfMax = posY - 1; for (int x = x1; x <= x2; x++) { mut.setX(x); @@ -149,8 +147,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { else { if (stateSt.is(TagAPI.END_GROUND) && state.getMaterial().isSolidBlocking()) { if (merge == TerrainMerge.SURFACE) { - SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings() - .getSurfaceBuilderConfig(); + SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig(); BlocksHelper.setWithoutUpdate(world, mut, config.getUnderMaterial()); } else { @@ -165,10 +162,10 @@ public abstract class NBTStructureFeature extends DefaultFeature { } } //BlocksHelper.fixBlocks(world, new BlockPos(x1, center.getY(), z1), new BlockPos(x2, center.getY() + offset.getY(), z2)); - + return true; } - + protected BoundingBox makeBox(BlockPos pos) { int sx = ((pos.getX() >> 4) << 4) - 16; int sz = ((pos.getZ() >> 4) << 4) - 16; @@ -176,35 +173,34 @@ public abstract class NBTStructureFeature extends DefaultFeature { int ez = sz + 47; return BoundingBox.fromCorners(new Vec3i(sx, 0, sz), new Vec3i(ex, 255, ez)); } - + protected static StructureTemplate readStructure(ResourceLocation resource) { String ns = resource.getNamespace(); String nm = resource.getPath(); - + try { - InputStream inputstream = MinecraftServer.class - .getResourceAsStream("/data/" + ns + "/structures/" + nm + ".nbt"); + InputStream inputstream = MinecraftServer.class.getResourceAsStream("/data/" + ns + "/structures/" + nm + ".nbt"); return readStructureFromStream(inputstream); } catch (IOException e) { e.printStackTrace(); } - + return null; } - + private static StructureTemplate readStructureFromStream(InputStream stream) throws IOException { CompoundTag nbttagcompound = NbtIo.readCompressed(stream); - + StructureTemplate template = new StructureTemplate(); template.load(nbttagcompound); - + return template; } - + public static enum TerrainMerge { NONE, SURFACE, OBJECT; - + public static TerrainMerge getFromString(String type) { if (type.equals("surface")) { return SURFACE; diff --git a/src/main/java/ru/bclib/world/generator/BiomeChunk.java b/src/main/java/ru/bclib/world/generator/BiomeChunk.java index 3fdb6358..93a5e9df 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/BiomeChunk.java @@ -1,34 +1,38 @@ package ru.bclib.world.generator; -import java.util.Random; - import ru.bclib.world.biomes.BCLBiome; +import java.util.Random; + public class BiomeChunk { protected static final int WIDTH = 16; private static final int SM_WIDTH = WIDTH >> 1; private static final int MASK_OFFSET = SM_WIDTH - 1; protected static final int MASK_WIDTH = WIDTH - 1; - + private final BCLBiome[][] biomes; - + public BiomeChunk(BiomeMap map, Random random, BiomePicker picker) { BCLBiome[][] PreBio = new BCLBiome[SM_WIDTH][SM_WIDTH]; biomes = new BCLBiome[WIDTH][WIDTH]; - - for (int x = 0; x < SM_WIDTH; x++) - for (int z = 0; z < SM_WIDTH; z++) + + for (int x = 0; x < SM_WIDTH; x++) { + for (int z = 0; z < SM_WIDTH; z++) { PreBio[x][z] = picker.getBiome(random); - - for (int x = 0; x < WIDTH; x++) - for (int z = 0; z < WIDTH; z++) + } + } + + for (int x = 0; x < WIDTH; x++) { + for (int z = 0; z < WIDTH; z++) { biomes[x][z] = PreBio[offsetXZ(x, random)][offsetXZ(z, random)].getSubBiome(random); + } + } } - + public BCLBiome getBiome(int x, int z) { return biomes[x & MASK_WIDTH][z & MASK_WIDTH]; } - + private int offsetXZ(int x, Random random) { return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET; } diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index 088fda63..9de76325 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -1,15 +1,14 @@ package ru.bclib.world.generator; -import java.util.Map; - import com.google.common.collect.Maps; - import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.levelgen.WorldgenRandom; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; +import java.util.Map; + public class BiomeMap { private static final WorldgenRandom RANDOM = new WorldgenRandom(); diff --git a/src/main/java/ru/bclib/world/generator/BiomePicker.java b/src/main/java/ru/bclib/world/generator/BiomePicker.java index 57eb36dd..bfdb5faf 100644 --- a/src/main/java/ru/bclib/world/generator/BiomePicker.java +++ b/src/main/java/ru/bclib/world/generator/BiomePicker.java @@ -1,17 +1,16 @@ package ru.bclib.world.generator; -import java.util.List; -import java.util.Random; -import java.util.Set; - import com.google.common.collect.Lists; import com.google.common.collect.Sets; - import net.minecraft.resources.ResourceLocation; import ru.bclib.util.WeighTree; import ru.bclib.util.WeightedList; import ru.bclib.world.biomes.BCLBiome; +import java.util.List; +import java.util.Random; +import java.util.Set; + public class BiomePicker { private final Set immutableIDs = Sets.newHashSet(); private final List biomes = Lists.newArrayList(); @@ -21,7 +20,7 @@ public class BiomePicker { public void addBiome(BCLBiome biome) { immutableIDs.add(biome.getID()); biomes.add(biome); - biomeCount ++; + biomeCount++; } public void addBiomeMutable(BCLBiome biome) { diff --git a/src/main/java/ru/bclib/world/generator/BiomeType.java b/src/main/java/ru/bclib/world/generator/BiomeType.java index 6e40eb2c..7556894d 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeType.java +++ b/src/main/java/ru/bclib/world/generator/BiomeType.java @@ -1,6 +1,5 @@ package ru.bclib.world.generator; public enum BiomeType { - LAND, - VOID; + LAND, VOID; } diff --git a/src/main/java/ru/bclib/world/processors/DestructionStructureProcessor.java b/src/main/java/ru/bclib/world/processors/DestructionStructureProcessor.java index 3d12057a..4c63a7e7 100644 --- a/src/main/java/ru/bclib/world/processors/DestructionStructureProcessor.java +++ b/src/main/java/ru/bclib/world/processors/DestructionStructureProcessor.java @@ -23,7 +23,7 @@ public class DestructionStructureProcessor extends StructureProcessor { } return structureBlockInfo2; } - + @Override protected StructureProcessorType getType() { return StructureProcessorType.RULE; diff --git a/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java b/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java index dceb0ee1..8231cde8 100644 --- a/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java +++ b/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java @@ -19,7 +19,7 @@ public class TerrainStructureProcessor extends StructureProcessor { } return structureBlockInfo2; } - + @Override protected StructureProcessorType getType() { return StructureProcessorType.RULE; diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 581f0b60..3db8e57b 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,8 +1,7 @@ package ru.bclib.world.structures; -import java.util.Random; - import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; +import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; @@ -10,6 +9,8 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import java.util.Random; + public class BCLStructureFeature { private static final Random RANDOM = new Random(354); private final StructureFeature structure; @@ -18,24 +19,22 @@ public class BCLStructureFeature { public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { this.featureStep = step; - this.structure = FabricStructureBuilder.create(id, structure) - .step(step) - .defaultConfig(spacing, separation, RANDOM.nextInt(8192)) - .register(); - - this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); + this.structure = FabricStructureBuilder.create(id, structure).step(step).defaultConfig(spacing, separation, RANDOM.nextInt(8192)).register(); + + this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); + FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); } - + public StructureFeature getStructure() { return structure; } - + public ConfiguredStructureFeature getFeatureConfigured() { return featureConfigured; } - + public GenerationStep.Decoration getFeatureStep() { return featureStep; } diff --git a/src/main/java/ru/bclib/world/structures/StructureWorld.java b/src/main/java/ru/bclib/world/structures/StructureWorld.java index 8f3c80d5..48c2ea30 100644 --- a/src/main/java/ru/bclib/world/structures/StructureWorld.java +++ b/src/main/java/ru/bclib/world/structures/StructureWorld.java @@ -1,9 +1,6 @@ package ru.bclib.world.structures; -import java.util.Map; - import com.google.common.collect.Maps; - import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -15,6 +12,8 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.levelgen.structure.BoundingBox; +import java.util.Map; + public class StructureWorld { private Map parts = Maps.newHashMap(); private ChunkPos lastPos; @@ -153,7 +152,7 @@ public class StructureWorld { blocks.forEach((pos, state) -> { int stateID = states.getOrDefault(states, -1); if (stateID < 0) { - stateID = id[0] ++; + stateID = id[0]++; states.put(state, stateID); stateMap.add(NbtUtils.writeBlockState(state)); } diff --git a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java index 14e6bba4..9e78a08c 100644 --- a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java +++ b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java @@ -1,7 +1,5 @@ package ru.bclib.world.surface; -import java.util.Random; - import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; @@ -14,6 +12,8 @@ import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConf import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; +import java.util.Random; + public class DoubleBlockSurfaceBuilder extends SurfaceBuilder { private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141); private SurfaceBuilderBaseConfiguration config1; @@ -43,7 +43,7 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder