Server mixin & biome source init, cleanup

This commit is contained in:
paulevsGitch 2021-06-01 10:43:38 +03:00
parent b7eab022fb
commit 1d91f8473e
25 changed files with 107 additions and 40 deletions

View file

@ -4,11 +4,11 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resources.ResourceLocation;
import ru.bclib.api.TagAPI;
import ru.bclib.registry.BaseBlockEntities;
import ru.bclib.registry.BaseRegistry;
import ru.bclib.util.Logger;
import ru.bclib.world.surface.BCLSurfaceBuilders;
import ru.bclib.api.TagAPI;
public class BCLib implements ModInitializer {
public static final String MOD_ID = "bclib";

View file

@ -32,13 +32,11 @@ public class BiomeAPI {
private static Registry<Biome> biomeRegistry;
/**
* Initialize registry if it was not initialized in world generation (when using mods/datapacks, that overrides the End generation)
* Initialize registry for current server.
* @param server - {@link MinecraftServer}
*/
public static void initRegistry(MinecraftServer server) {
if (biomeRegistry == null || biomeRegistry == BuiltinRegistries.BIOME) {
biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
}
biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
}
public static void registerBiomeDirectly(BCLBiome biome) {

View file

@ -91,7 +91,6 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
}
}
@SuppressWarnings("ConstantConditions")
private void scheduleUpdate() {
level.getBlockTicks().scheduleTick(getBlockPos(), getBlockState().getBlock(), 5);
}

View file

@ -65,12 +65,14 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
switch (face) {
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;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL);

View file

@ -60,6 +60,7 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
case TOP:
pattern = PatternsHelper.createJson(BasePatterns.BLOCK_DOOR_TOP, resourceLocation);
break;
default: break;
}
return ModelsHelper.fromPattern(pattern);
}

View file

@ -29,11 +29,11 @@ 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 ru.bclib.client.render.ERenderLayer;
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.client.render.ERenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper;

View file

@ -5,7 +5,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.minecraft.core.Registry;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps;
@ -14,6 +13,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
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.item.enchantment.EnchantmentHelper;

View file

@ -6,7 +6,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Random;
import net.minecraft.core.Registry;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps;
@ -17,6 +16,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;

View file

@ -80,6 +80,7 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
case WEST:
y = (isTop && isOpen) ? 90 : 270;
break;
default: break;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);

View file

@ -1,5 +1,7 @@
package ru.bclib.client;
import java.util.Arrays;
import net.fabricmc.api.ClientModInitializer;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseSignBlock;
@ -8,8 +10,6 @@ import ru.bclib.client.render.BaseSignBlockEntityRenderer;
import ru.bclib.registry.BaseBlockEntities;
import ru.bclib.registry.BaseBlockEntityRenders;
import java.util.Arrays;
public class BCLibClient implements ClientModInitializer {
@Override
public void onInitializeClient() {

View file

@ -1,10 +1,18 @@
package ru.bclib.client.gui;
import java.util.Arrays;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Lighting;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.Util;
@ -25,8 +33,6 @@ import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.client.render.BaseSignBlockEntityRenderer;
import java.util.Arrays;
@Environment(EnvType.CLIENT)
public class BlockSignEditScreen extends Screen {
private final SignModel model = new SignModel();

View file

@ -24,7 +24,6 @@ import net.minecraft.world.level.block.state.StateDefinition;
@Environment(EnvType.CLIENT)
public class ModelsHelper {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static BlockModel fromPattern(Optional<String> pattern) {
return pattern.map(BlockModel::fromString).orElse(null);
}

View file

@ -1,10 +1,5 @@
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;
@ -13,6 +8,12 @@ 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<String> createItemGenerated(ResourceLocation itemId) {
return createJson(BasePatterns.ITEM_GENERATED, itemId);

View file

@ -20,7 +20,6 @@ import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractChestBlock;
import net.minecraft.world.level.block.Block;
@ -34,7 +33,6 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.ChestType;
import ru.bclib.blockentities.BaseChestBlockEntity;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.registry.BaseRegistry;
@Environment(EnvType.CLIENT)
public class BaseChestBlockEntityRenderer extends BlockEntityRenderer<BaseChestBlockEntity> {

View file

@ -21,16 +21,13 @@ import net.minecraft.client.resources.model.Material;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SignBlock;
import net.minecraft.world.level.block.StandingSignBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.WoodType;
import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.registry.BaseRegistry;
public class BaseSignBlockEntityRenderer extends BlockEntityRenderer<BaseSignBlockEntity> {
private static final HashMap<Block, RenderType> LAYERS = Maps.newHashMap();

View file

@ -9,7 +9,6 @@ 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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.renderer.block.BlockModelShaper;

View file

@ -16,9 +16,9 @@ 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 ru.bclib.api.TagAPI;
import ru.bclib.api.BiomeAPI;
import ru.bclib.api.BonemealAPI;
import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper;
import ru.bclib.util.MHelper;

View file

@ -0,0 +1,55 @@
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;
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 ru.bclib.api.BiomeAPI;
import ru.bclib.recipes.BCLRecipeManager;
@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
@Shadow
private ServerResources resources;
@Final
@Shadow
private Map<ResourceKey<Level>, ServerLevel> levels;
@Final
@Shadow
protected WorldData worldData;
@Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true)
private void bcl_reloadResources(Collection<String> collection, CallbackInfoReturnable<CompletableFuture<Void>> 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();
accessor.bcl_setRecipes(BCLRecipeManager.getMap(accessor.bcl_getRecipes()));
}
}
}

View file

@ -13,8 +13,8 @@ import net.minecraft.world.item.crafting.RecipeType;
@Mixin(RecipeManager.class)
public interface RecipeManagerAccessor {
@Accessor("recipes")
Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> be_getRecipes();
Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> bcl_getRecipes();
@Accessor("recipes")
void be_setRecipes(Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes);
void bcl_setRecipes(Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes);
}

View file

@ -9,6 +9,7 @@ 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;

View file

@ -1,16 +1,19 @@
package ru.bclib.registry;
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;
import net.minecraft.world.item.*;
import ru.bclib.BCLib;
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;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import ru.bclib.BCLib;
public abstract class BaseRegistry<T> {
private static final List<BaseRegistry<?>> REGISTRIES = Lists.newArrayList();

View file

@ -11,7 +11,13 @@ import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.*;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.level.block.DispenserBlock;
import ru.bclib.items.BaseDrinkItem;
import ru.bclib.items.BaseSpawnEggItem;

View file

@ -12,8 +12,8 @@ import java.util.zip.ZipFile;
import com.google.common.collect.Sets;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;

View file

@ -22,8 +22,8 @@ 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 ru.bclib.api.TagAPI;
import ru.bclib.api.BiomeAPI;
import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper;
import ru.bclib.world.processors.DestructionStructureProcessor;

View file

@ -8,6 +8,7 @@
"PotionBrewingAccessor",
"RecipeManagerAccessor",
"EnchantmentMenuMixin",
"MinecraftServerMixin",
"RecipeManagerMixin",
"BoneMealItemMixin",
"ServerLevelMixin",