Skip to content

Commit

Permalink
Pushed latest stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
Waterpicker committed Nov 28, 2023
1 parent e7f899a commit 61bd9f5
Show file tree
Hide file tree
Showing 36 changed files with 431 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.cobblemon.mod.common.api.storage.player.PlayerDataExtensionRegistry;
import com.mojang.logging.LogUtils;
import dev.architectury.event.events.common.InteractionEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.registries.RegistrarManager;
import generations.gg.generations.core.generationscore.api.data.GenerationsCoreEntityDataSerializers;
import generations.gg.generations.core.generationscore.api.player.AccountInfo;
import generations.gg.generations.core.generationscore.api.player.BiomesVisited;
Expand All @@ -30,19 +32,25 @@
import generations.gg.generations.core.generationscore.world.item.legends.EnchantableItem;
import generations.gg.generations.core.generationscore.world.level.block.*;
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.MutableBlockEntityType;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericModelBlock;
import generations.gg.generations.core.generationscore.world.recipe.GenerationsCoreRecipeSerializers;
import generations.gg.generations.core.generationscore.world.recipe.GenerationsCoreRecipeTypes;
import generations.gg.generations.core.generationscore.world.sound.GenerationsSounds;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import org.apache.logging.log4j.util.TriConsumer;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.function.IntConsumer;

Expand Down Expand Up @@ -113,6 +121,14 @@ public static void init(GenerationsImplementation implementation) {
if(result.interruptsFurtherEvaluation() && stack.getItem() instanceof PixelmonInteractions.PixelmonInteraction interaction && interaction.isConsumed()) stack.shrink(1);
return result;
});

LifecycleEvent.SETUP.register(() -> MutableBlockEntityType.blocksToAdd.forEach(genericModelBlock -> {
if(genericModelBlock.getBlockEntityType() instanceof MutableBlockEntityType<?> mutableBlockEntityType) {
mutableBlockEntityType.addBlock(genericModelBlock);
}
}));


}

public static void initBuiltinPacks(TriConsumer<PackType, ResourceLocation, MutableComponent> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericChestBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericChestBlock;
import gg.generations.rarecandy.pokeutils.reader.TextureReference;
import gg.generations.rarecandy.renderer.loading.ITexture;
import gg.generations.rarecandy.tools.TextureLoader;
import kotlin.Unit;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -74,6 +77,8 @@
import org.joml.Vector4f;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

Expand Down Expand Up @@ -110,6 +115,38 @@ private static void setupClient(Minecraft event) {
addWoodType(GenerationsWoodTypes.ULTRA_DARK);
addWoodType(GenerationsWoodTypes.GHOST);
Pipelines.REGISTER.register(Pipelines::initGenerationsPipelines);

TextureLoader.setInstance(new gg.generations.rarecandy.pokeutils.reader.TextureLoader() {
final Map<String, ResourceLocation> MAP = new HashMap<>();

@Override
public ITexture getTexture(String s) {
return (ITexture) Minecraft.getInstance().getTextureManager().getTexture(MAP.get(s));
}

@Override
public void register(String s, TextureReference textureReference) {
var location = Minecraft.getInstance().getTextureManager().register(s, new generations.gg.generations.core.generationscore.client.render.rarecandy.Texture(textureReference));
MAP.putIfAbsent(s, location);
}

@Override
public void remove(String s) {
Minecraft.getInstance().getTextureManager().release(MAP.get(s));
}

@Override
public void clear() {
var manager = Minecraft.getInstance().getTextureManager();

for (var entry : MAP.keySet()) {
manager.release(MAP.get(entry));
}

MAP.clear();
}
});

Pipelines.onInitialize(event.getResourceManager());
registerScreens();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void renderModelProvider(PoseStack stack, ModelProvidingBlockEntity bl
blockEntity.objectInstance[i] = new BlockObjectInstance(new Matrix4f(), new Matrix4f(), null);
}

String variant = blockEntity instanceof ModelContextProviders.VariantProvider provider ? provider.getVariant() : null;
String variant = blockEntity.getVariant();

for (var instance : blockEntity.objectInstance) {
if (!Objects.equals(instance.materialId(), variant)) {
Expand Down Expand Up @@ -83,7 +83,7 @@ protected void renderModelFrameProvider(PoseStack stack, ModelProvidingBlockEnti
blockEntity.objectInstance = new ObjectInstance[amount];

for (int i = 0; i < amount; i++) {
blockEntity.objectInstance[i] = new BlockAnimatedObjectInstance(new Matrix4f(), new Matrix4f(), blockEntity instanceof ModelContextProviders.VariantProvider variantProvider ? variantProvider.getVariant() : null);
blockEntity.objectInstance[i] = new BlockAnimatedObjectInstance(new Matrix4f(), new Matrix4f(), blockEntity.getVariant());
}

var primeInstance = blockEntity.objectInstance[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class ModelRegistry {
public @NotNull CompiledModel load(@NotNull Pair<ResourceLocation, String> pair) {
try {
var resourceManager = Minecraft.getInstance().getResourceManager();
var is = resourceManager.getResource(pair.a()).orElseGet(() -> resourceManager.getResource(GenerationsCore.id("models/pokemon/substitute.pk")).orElseThrow()).open();
var is = resourceManager.getResource(pair.a()).orElseGet(() -> {
System.out.println("Oh No: " + pair.a + "/" + pair.b);
return resourceManager.getResource(GenerationsCore.id("models/pokemon/substitute.pk")).orElseThrow();
}).open();
return new CompiledModel(pair.a, is, Pipelines.getPipeline(pair.b()), MESH_OBJECT_SUPPLIER);
} catch (Exception e) {
var path = pair.a().toString();
Expand All @@ -60,21 +63,21 @@ public static CompiledModel get(ResourceLocation location, String pipeline) {

public static void prepForBER(PoseStack stack, ModelContextProviders.AngleProvider supplier) {

stack.mulPose(Axis.YN.rotationDegrees(supplier.getAngle()));

if(supplier instanceof ModelProvidingBlockEntity blockEntity && blockEntity.getBlockState().getBlock() instanceof GenericRotatableModelBlock<?> block) {
var dir = blockEntity.getBlockState().getValue(GenericRotatableModelBlock.FACING);
var opposite = dir.getOpposite();
var counterClockwise = dir.getCounterClockWise();

var displaceX = block.width() / 2f;
var dispalceZ = block.length() / 2f;
var displaceX = (block.width()+1) / 2f;
var dispalceZ = (block.length()+1) / 2f;


stack.translate((opposite.getStepX() + counterClockwise.getStepX()) * displaceX, 0.0f, (opposite.getStepZ() + counterClockwise.getStepZ()) * dispalceZ);
stack.translate(counterClockwise.getStepX() * displaceX, 0.0f, opposite.getStepZ() * dispalceZ);
}

stack.translate(0.5f, 0.0f, 0.5f);
stack.mulPose(Axis.YN.rotationDegrees(supplier.getAngle()));
// stack.translate(0.5f, 0.0f, 0.5f);
}

private record Pair<A, B>(A a, B b) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package generations.gg.generations.core.generationscore.client.render.rarecandy;

import com.mojang.blaze3d.platform.NativeImage;
import gg.generations.rarecandy.pokeutils.reader.TextureReference;
import gg.generations.rarecandy.renderer.loading.ITexture;
import it.unimi.dsi.fastutil.io.FastByteArrayInputStream;
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
import net.minecraft.client.renderer.texture.DynamicTexture;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

public class Texture extends DynamicTexture implements ITexture {
public Texture(TextureReference pixels) {
super(getFromBuffered(pixels.data()));
}

private static NativeImage getFromBuffered(BufferedImage image) {
try (FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream()) {
ImageIO.write(image, "PNG", outputStream);
return NativeImage.read(new FastByteArrayInputStream(outputStream.array));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public void bind(int slot) {
assert slot >= 0 && slot <= 31;

GL13C.glActiveTexture('蓀' + slot);
bind();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package generations.gg.generations.core.generationscore.mixin;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Set;

@Mixin(BlockEntityType.class)
public interface BlockEntityTypeAccessor {
@Accessor("validBlocks")
Set<Block> getBlocks();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import generations.gg.generations.core.generationscore.world.level.block.entities.ModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.entities.MutableBlockEntityType;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericModelBlock;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
Expand All @@ -17,6 +23,7 @@
import net.minecraft.world.Containers;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;

Expand All @@ -28,6 +35,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Supplier;

public class GenerationsUtils {

Expand Down Expand Up @@ -122,6 +130,22 @@ public static void giveItem(ServerPlayer player, ItemStack stack) {
}
}

public static <T extends Block> RegistrySupplier<T> registerBlock(DeferredRegister<Block> deferredRegister, String name, Supplier<T> blockSupplier) {
return deferredRegister.register(name, applyMutable(name, blockSupplier));
}

private static <T extends Block> Supplier<T> applyMutable(String name, Supplier<T> blockSupplier) {
return () -> {
var block = blockSupplier.get();

if(block instanceof GenericModelBlock<?> genericModelBlock) {
MutableBlockEntityType.blocksToAdd.add(genericModelBlock);
}

return block;
};
}

public record Serializer<T>(Codec<T> codec) implements JsonSerializer<T>, JsonDeserializer<T> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package generations.gg.generations.core.generationscore.world.level.block;

import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntityModels;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericRotatableModelBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class BenchBlock extends GenericRotatableModelBlock<GenericModelProvidingBlockEntity> {
public BenchBlock(BlockBehaviour.Properties properties) {
super(properties, GenerationsBlockEntities.GENERIC_MODEL_PROVIDING, GenerationsBlockEntityModels.BENCH, 1, 0, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package generations.gg.generations.core.generationscore.world.level.block;

import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntityModels;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericRotatableModelBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class BushBlock extends GenericRotatableModelBlock<GenericModelProvidingBlockEntity> {
public BushBlock(BlockBehaviour.Properties properties) {
super(properties, GenerationsBlockEntities.GENERIC_MODEL_PROVIDING, GenerationsBlockEntityModels.BUSH, 0, 1, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package generations.gg.generations.core.generationscore.world.level.block;

import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntityModels;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericRotatableModelBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class DeskBlock extends GenericRotatableModelBlock<GenericModelProvidingBlockEntity> {
public DeskBlock(BlockBehaviour.Properties properties) {
super(properties, GenerationsBlockEntities.GENERIC_MODEL_PROVIDING, GenerationsBlockEntityModels.DESK, 2, 1, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package generations.gg.generations.core.generationscore.world.level.block;

import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntities;
import generations.gg.generations.core.generationscore.world.level.block.entities.GenerationsBlockEntityModels;
import generations.gg.generations.core.generationscore.world.level.block.entities.generic.GenericModelProvidingBlockEntity;
import generations.gg.generations.core.generationscore.world.level.block.generic.GenericRotatableModelBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class FridgeBlock extends GenericRotatableModelBlock<GenericModelProvidingBlockEntity> {
public FridgeBlock(BlockBehaviour.Properties properties) {
super(properties, GenerationsBlockEntities.GENERIC_MODEL_PROVIDING, GenerationsBlockEntityModels.FRIDGE, 0, 1, 0);
}
}
Loading

0 comments on commit 61bd9f5

Please sign in to comment.