Skip to content

Commit

Permalink
feat: wip parachest
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Oct 25, 2023
1 parent eb8df65 commit 254c67b
Show file tree
Hide file tree
Showing 66 changed files with 3,607 additions and 35 deletions.
1,220 changes: 1,220 additions & 0 deletions src/main/generated/assets/galacticraft/blockstates/parachest.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "galacticraft:parachest"
}
],
"rolls": 1.0
}
]
}
1 change: 1 addition & 0 deletions src/main/java/dev/galacticraft/mod/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ interface Menu {
String AIR_LOCK_CONTROLLER_MENU = "air_lock_menu";
String ROCKET_WORKBENCH_MENU = "rocket_workbench_menu";
String ROCKET = "rocket";
String PARACHEST = "parachest";
}

interface LootTable {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/galacticraft/mod/Galacticraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void onInitialize() {
GCMachineStatuses.register();
GCBannerPatterns.register();
GCTeleporterTypes.register();
GCStats.register();
GCEventHandlers.init();
Constant.LOGGER.info("Initialization complete. (Took {}ms.)", System.currentTimeMillis() - startInitTime);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/galacticraft/mod/GalacticraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.fabricmc.fabric.api.client.model.loading.v1.PreparableModelLoadingPlugin;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
Expand Down Expand Up @@ -109,6 +111,7 @@ public void onInitializeClient() {
MenuScreens.register(GCMenuTypes.AIRLOCK_CONTROLLER_MENU, AirlockControllerScreen::new);
MenuScreens.register(GCMenuTypes.ROCKET_WORKBENCH, RocketWorkbenchScreen::new);
MenuScreens.register(GCMenuTypes.ROCKET, RocketInventoryScreen::new);
MenuScreens.register(GCMenuTypes.PARACHEST, ParachestScreen::new);

EntityRendererRegistry.register(GCEntityTypes.EVOLVED_ZOMBIE, EvolvedZombieRenderer::new);
EntityRendererRegistry.register(GCEntityTypes.EVOLVED_CREEPER, EvolvedCreeperEntityRenderer::new);
Expand Down Expand Up @@ -182,6 +185,8 @@ public void onInitializeClient() {
return null;
});

ModelLoadingPlugin.register(GCModelLoader.INSTANCE);

DimensionRenderingRegistry.registerDimensionEffects(GCDimensions.MOON.location(), MoonDimensionEffects.INSTANCE);
DimensionRenderingRegistry.registerCloudRenderer(GCDimensions.MOON, EmptyCloudRenderer.INSTANCE);
DimensionRenderingRegistry.registerWeatherRenderer(GCDimensions.MOON, EmptyWeatherRenderer.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2019-2023 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.gui.screen.ingame;

import com.mojang.blaze3d.systems.RenderSystem;
import dev.galacticraft.mod.Constant;
import dev.galacticraft.mod.screen.ParachestMenu;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class ParachestScreen extends AbstractContainerScreen<ParachestMenu> {
private static ResourceLocation[] parachestTexture = new ResourceLocation[4];

static {
for (int i = 0; i < 4; i++) {
parachestTexture[i] = Constant.id("textures/gui/chest_" + i * 18 + ".png");
}
}

private int inventorySlots = 0;

public ParachestScreen(ParachestMenu abstractContainerMenu, Inventory inventory, Component component) {
super(abstractContainerMenu, inventory, component);
this.inventorySlots = abstractContainerMenu.getBlockEntity().getContainerSize();
this.imageHeight = 146 + this.inventorySlots * 2;
this.titleLabelX = 8;
this.titleLabelY = 6;
this.inventoryLabelX = 8;
this.inventoryLabelY = this.imageHeight - 103 + (this.inventorySlots == 3 ? 2 : 4);
}

@Override
protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
ResourceLocation texture = parachestTexture[(this.inventorySlots - 3) / 18];
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int k = (this.width - this.imageWidth) / 2;
int l = (this.height - this.imageHeight) / 2;
guiGraphics.blit(texture, k, l, 0, 0, this.imageWidth, this.imageHeight);

var tank = getMenu().getBlockEntity().tank;

final double amount = tank.getAmount();

int fuelLevel = (int) (amount * 28 / tank.getCapacity());
guiGraphics.blit(texture, k + 17, l + (this.inventorySlots == 3 ? 40 : 42) - fuelLevel + this.inventorySlots * 2, 176, 28 - fuelLevel, 34, fuelLevel);
}

@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
renderBackground(guiGraphics);
super.render(guiGraphics, i, j, f);
renderTooltip(guiGraphics, i, j);
}
}
52 changes: 52 additions & 0 deletions src/main/java/dev/galacticraft/mod/client/model/GCModelLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2019-2023 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.model;

import dev.galacticraft.mod.Constant;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;

import java.util.HashMap;
import java.util.Map;

public class GCModelLoader implements ModelLoadingPlugin {
public static final GCModelLoader INSTANCE = new GCModelLoader();
private static final ResourceLocation PARACHEST_ITEM = new ResourceLocation(Constant.MOD_ID, "item/parachest");

@Override
public void onInitializeModelLoader(Context pluginContext) {

pluginContext.resolveModel().register(context -> {
if (context.id().equals(PARACHEST_ITEM)) {
Map<DyeColor, UnbakedModel> chutes = new HashMap<>();
for (DyeColor color : DyeColor.values()) {
chutes.put(color, context.getOrLoadModel(Constant.id("block/parachest/" + color.getName() + "_chute")));
}
return new ParachestUnbakedModel(context.getOrLoadModel(Constant.id("block/parachest/parachest")), chutes);
}
return null;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (c) 2019-2023 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.model;

import dev.galacticraft.mod.content.GCBlocks;
import dev.galacticraft.mod.content.block.special.ParaChestBlock;
import net.fabricmc.fabric.api.renderer.v1.model.WrapperBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelBaker;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.Property;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public record ParaChestBakedModel(BakedModel parent, Map<DyeColor, BakedModel> bakedChutes) implements BakedModel, WrapperBakedModel {
@Override
public List<BakedQuad> getQuads(@Nullable BlockState blockState, @Nullable Direction direction, RandomSource randomSource) {
List<BakedQuad> quads = new ArrayList<>(parent.getQuads(blockState, direction, randomSource));
if (blockState != null)
quads.addAll(bakedChutes.get(blockState.getValue(ParaChestBlock.COLOR)).getQuads(blockState, direction, randomSource));
return quads;
}

@Override
public void emitItemQuads(ItemStack stack, Supplier<RandomSource> randomSupplier, RenderContext context) {
BakedModel.super.emitItemQuads(stack, randomSupplier, context);
CompoundTag compoundTag = stack.getTag();
if (compoundTag != null) {
CompoundTag blockStateTag = compoundTag.getCompound("BlockStateTag");
StateDefinition<Block, BlockState> stateDefinition = GCBlocks.PARACHEST.getStateDefinition();


Property<?> property = stateDefinition.getProperty("color");
if (property != null) {
bakedChutes.get(property.getValue(blockStateTag.getString("color")).get()).emitItemQuads(stack, randomSupplier, context);
}
} else {
bakedChutes.get(DyeColor.WHITE).emitItemQuads(stack, randomSupplier, context);
}
}

@Override
public boolean isVanillaAdapter() {
return false;
}

@Override
public boolean useAmbientOcclusion() {
return parent.usesBlockLight();
}

@Override
public boolean isGui3d() {
return parent.isGui3d();
}

@Override
public boolean usesBlockLight() {
return parent.usesBlockLight();
}

@Override
public boolean isCustomRenderer() {
return parent.isCustomRenderer();
}

@Override
public TextureAtlasSprite getParticleIcon() {
return parent.getParticleIcon();
}

@Override
public ItemTransforms getTransforms() {
return parent.getTransforms();
}

@Override
public ItemOverrides getOverrides() {
return parent.getOverrides();
}

@Override
public BakedModel getWrappedModel() {
return parent;
}

public class ParaChestOverride extends ItemOverrides {

public ParaChestOverride(ModelBaker modelBaker, BlockModel blockModel, List<ItemOverride> list) {
super(modelBaker, blockModel, list);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2019-2023 Team Galacticraft
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.galacticraft.mod.client.model;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Function;

public record ParachestUnbakedModel(UnbakedModel parentModel, Map<DyeColor, UnbakedModel> chutes) implements UnbakedModel {

@Override
public Collection<ResourceLocation> getDependencies() {
List<ResourceLocation> depends = new ArrayList<>(parentModel.getDependencies());
chutes.forEach((color, unbakedModel) -> {
depends.addAll(unbakedModel.getDependencies());
});
return depends;
}

@Override
public void resolveParents(Function<ResourceLocation, UnbakedModel> function) {
parentModel.resolveParents(function);
chutes.forEach((color, unbakedModel) -> {
unbakedModel.resolveParents(function);
});
}

@Nullable
@Override
public BakedModel bake(ModelBaker modelBaker, Function<Material, TextureAtlasSprite> function, ModelState modelState, ResourceLocation resourceLocation) {
Map<DyeColor, BakedModel> bakedChutes = new HashMap<>();
chutes.forEach((color, unbakedModel) -> {
bakedChutes.put(color, unbakedModel.bake(modelBaker, function, modelState, resourceLocation));
});
return new ParaChestBakedModel(parentModel.bake(modelBaker, function, modelState, resourceLocation), bakedChutes);
}
}
Loading

0 comments on commit 254c67b

Please sign in to comment.