Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
more work on window rendering of nuclear reactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 11, 2024
1 parent 5883a26 commit 747ec34
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public void onUnregisterPost() {
@Override
public Function<Direction, Texture> getMultiTexture() {
return direction -> {
Direction direction1 = coverHandler.map(c -> c.get(direction).isEmpty() ? direction : Direction.UP).orElse(direction);
return type.getBaseTexture(this.tier, direction1, this.machineState);
return type.getBaseTexture(this.tier, UP, this.machineState);
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package muramasa.gregtech.client;

import com.google.common.collect.ImmutableMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import muramasa.antimatter.AntimatterProperties;
import muramasa.antimatter.Ref;
import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.client.ModelUtils;
import muramasa.antimatter.client.baked.MachineBakedModel;
import muramasa.antimatter.cover.ICover;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.texture.Texture;
import muramasa.gregtech.blockentity.single.BlockEntityNuclearReactorCore;
import muramasa.gregtech.data.GregTechCovers;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -22,6 +28,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.function.Function;

public class ReactorBakedModel extends MachineBakedModel {
private final BakedModel[] rodModels;
Expand All @@ -32,19 +39,45 @@ public ReactorBakedModel(TextureAtlasSprite particle, ImmutableMap<MachineState,

@Override
public List<BakedQuad> getBlockQuads(BlockState state, Direction side, Random rand, BlockAndTintGetter level, @NotNull BlockPos pos) {
List<BakedQuad> superBlockQuads = super.getBlockQuads(state, side, rand, level, pos);
if (side == null) {
return Collections.emptyList();
}
BlockEntity tile = level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityNuclearReactorCore core)) return Collections.emptyList();
AntimatterProperties.MachineProperties props = getMachineProperty(core);
if (props == null) return Collections.emptyList();
List<BakedQuad> superBlockQuads = new ObjectArrayList<>(20);
List<BakedQuad> coverQuads = getCoverQuads(state, side, rand, props, core, level, pos);
ICover cover = props.covers[side.get3DDataValue()];
boolean isOutputCover = cover.getFactory() == GregTechCovers.COVER_REACTOR_OUTPUT || cover.getFactory() == GregTechCovers.COVER_REACTOR_OUTPUT_SECONDARY;
if (!coverQuads.isEmpty()) {
if (isOutputCover) {
return coverQuads;
}
Function<Direction, Texture> ft = core.getMultiTexture();
List<BakedQuad> machineQuads = props.machineTexturer.getQuads("machine", new ObjectArrayList<>(), state, props.type, new BlockEntityMachine.DynamicKey(new ResourceLocation(props.type.getId()), ft.apply(side), side, props.state, props), side.get3DDataValue(), level, pos);
for (int i = 0; i < 2; i++) {
BakedQuad quad = machineQuads.get(i);
if (quad.getDirection() == side.getOpposite())
coverQuads.add(quad);
}
return coverQuads;
}
BakedModel model = getModel(state, side, props.state, props.type);
for (Direction dir : Ref.DIRS) {
superBlockQuads.addAll(ModelUtils.getQuadsFromBaked(model, state, dir, rand, level, pos));
}
superBlockQuads.addAll(ModelUtils.getQuadsFromBaked(model, state, null, rand, level, pos));
if (side == Direction.UP){
List<BakedQuad> list = new ArrayList<>();
BlockEntity tile = level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityNuclearReactorCore core)) return Collections.emptyList();
for (int i = 0; i < 4; i++) {
ItemStack rod = core.getRod(i);
if (rod.isEmpty()) continue;
BakedModel model = rodModels[i];
BakedModel rodModel = rodModels[i];
for (Direction dir : Ref.DIRS) {
list.addAll(ModelUtils.getQuadsFromBaked(model, state, dir, rand, level, pos));
list.addAll(ModelUtils.getQuadsFromBaked(rodModel, state, dir, rand, level, pos));
}
list.addAll(ModelUtils.getQuadsFromBaked(model, state, null, rand, level, pos));
list.addAll(ModelUtils.getQuadsFromBaked(rodModel, state, null, rand, level, pos));
}
list.addAll(superBlockQuads);
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import muramasa.antimatter.cover.CoverOutput;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.Tier;
import muramasa.gregtech.GTIRef;
import muramasa.gregtech.blockentity.single.BlockEntityNuclearReactorCore;
import muramasa.gregtech.blockentity.single.BlockEntitySteamMachine;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -39,7 +40,7 @@ public boolean canPlace() {
@Override
public ResourceLocation getModel(String type, Direction dir) {
if (type.equals("pipe")) return PIPE_COVER_MODEL;
return getBasicModel();
return new ResourceLocation(GTIRef.ID + ":block/cover/nuclear");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import earth.terrarium.botarium.common.fluid.base.FluidHolder;
import earth.terrarium.botarium.common.fluid.base.PlatformFluidHandler;
import muramasa.antimatter.Ref;
import muramasa.antimatter.blockentity.BlockEntityCache;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.capability.machine.MachineFluidHandler;
Expand All @@ -10,6 +11,7 @@
import muramasa.antimatter.cover.CoverOutput;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.GTIRef;
import muramasa.gregtech.blockentity.single.BlockEntityNuclearReactorCore;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -30,7 +32,7 @@ public boolean canPlace() {
@Override
public ResourceLocation getModel(String type, Direction dir) {
if (type.equals("pipe")) return PIPE_COVER_MODEL;
return getBasicModel();
return new ResourceLocation(GTIRef.ID + ":block/cover/nuclear");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 14],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"south": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 14],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"south": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 0],
"to": [16, 0, 16],
"to": [16, 2, 16],
"faces": {
"up": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"down": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 0],
"to": [16, 0, 16],
"to": [16, 2, 16],
"faces": {
"down": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"up": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"down": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [16, 0, 0],
"from": [14, 0, 0],
"to": [16, 16, 16],
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
"east": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"west": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [16, 0, 0],
"from": [14, 0, 0],
"to": [16, 16, 16],
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"east": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"west": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 0],
"to": [16, 16, 0],
"to": [16, 16, 2],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
"north": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"south": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 0],
"to": [16, 16, 0],
"to": [16, 16, 2],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"north": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"south": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 16],
"from": [0, 0, 14],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"south": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 16],
"from": [0, 0, 14],
"to": [16, 16, 16],
"faces": {
"south": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"north": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"south": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 16, 0],
"from": [0, 14, 0],
"to": [16, 16, 16],
"faces": {
"up": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
"up": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"down": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 16, 0],
"from": [0, 14, 0],
"to": [16, 16, 16],
"faces": {
"up": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"up": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"down": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"credit": "Made with Blockbench",
"elements": [
{
"from": [0, 0, 0],
"to": [0, 16, 16],
"to": [2, 16, 16],
"faces": {
"east": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0},
"west": {"uv": [0, 0, 16, 16], "texture": "#base", "tintindex": 0}
}
},
{
"from": [0, 0, 0],
"to": [0, 16, 16],
"to": [2, 16, 16],
"faces": {
"west": {"uv": [0, 0, 16, 16], "texture": "#overlay", "tintindex": -1}
"east": {"uv": [0, 0, 16, 16], "texture": "#overlay"},
"west": {"uv": [0, 0, 16, 16], "texture": "#overlay"}
}
}
]
Expand Down

0 comments on commit 747ec34

Please sign in to comment.