2020-02-04 14:48:21 +01:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
|
|
|
import static net.minecraft.state.properties.BlockStateProperties.HORIZONTAL_FACING;
|
|
|
|
|
2020-06-15 19:14:03 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2020-02-04 14:48:21 +01:00
|
|
|
import java.util.Map;
|
|
|
|
|
2020-04-05 03:54:24 +02:00
|
|
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
2020-02-04 14:48:21 +01:00
|
|
|
import com.simibubi.create.foundation.utility.AngleHelper;
|
2020-06-15 19:14:03 +02:00
|
|
|
import com.simibubi.create.foundation.utility.Iterate;
|
2020-05-25 23:09:36 +02:00
|
|
|
import com.simibubi.create.foundation.utility.MatrixStacker;
|
2020-02-04 14:48:21 +01:00
|
|
|
import com.simibubi.create.foundation.utility.SuperByteBuffer;
|
|
|
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.client.renderer.model.IBakedModel;
|
|
|
|
import net.minecraft.util.Direction;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
|
|
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
|
|
|
|
2020-06-15 19:14:03 +02:00
|
|
|
public class AllBlockPartials {
|
|
|
|
|
2020-07-12 14:54:03 +02:00
|
|
|
private static final List<AllBlockPartials> all = new ArrayList<>();
|
2020-07-12 13:13:43 +02:00
|
|
|
|
|
|
|
public static final AllBlockPartials SCHEMATICANNON_CONNECTOR = get("schematicannon/connector"),
|
2020-06-15 19:14:03 +02:00
|
|
|
SCHEMATICANNON_PIPE = get("schematicannon/pipe"),
|
|
|
|
|
2020-07-12 14:54:03 +02:00
|
|
|
SHAFTLESS_COGWHEEL = get("cogwheel_shaftless"),
|
2020-06-15 19:14:03 +02:00
|
|
|
SHAFT_HALF = get("shaft_half"),
|
2020-07-12 02:05:29 +02:00
|
|
|
|
|
|
|
BELT_PULLEY = get("belt_pulley"),
|
|
|
|
BELT_START = get("belt/start"),
|
|
|
|
BELT_MIDDLE = get("belt/middle"),
|
|
|
|
BELT_END = get("belt/end"),
|
|
|
|
BELT_START_BOTTOM = get("belt/start_bottom"),
|
|
|
|
BELT_MIDDLE_BOTTOM = get("belt/middle_bottom"),
|
|
|
|
BELT_END_BOTTOM = get("belt/end_bottom"),
|
|
|
|
BELT_DIAGONAL_START = get("belt/diagonal_start"),
|
|
|
|
BELT_DIAGONAL_MIDDLE = get("belt/diagonal_middle"),
|
|
|
|
BELT_DIAGONAL_END = get("belt/diagonal_end"),
|
2020-06-15 19:14:03 +02:00
|
|
|
|
2020-07-12 13:13:43 +02:00
|
|
|
ENCASED_FAN_INNER = get("encased_fan/propeller"), HAND_CRANK_HANDLE = get("hand_crank/handle"),
|
|
|
|
MECHANICAL_PRESS_HEAD = get("mechanical_press/head"), MECHANICAL_MIXER_POLE = get("mechanical_mixer/pole"),
|
|
|
|
MECHANICAL_MIXER_HEAD = get("mechanical_mixer/head"), BLAZE_HEATER_BLAZE_ONE = get("blaze_heater/blaze/one"),
|
|
|
|
BLAZE_HEATER_BLAZE_TWO = get("blaze_heater/blaze/two"),
|
|
|
|
BLAZE_HEATER_BLAZE_THREE = get("blaze_heater/blaze/three"),
|
|
|
|
BLAZE_HEATER_BLAZE_FOUR = get("blaze_heater/blaze/four"),
|
2020-06-15 19:14:03 +02:00
|
|
|
MECHANICAL_CRAFTER_LID = get("mechanical_crafter/lid"),
|
|
|
|
MECHANICAL_CRAFTER_ARROW = get("mechanical_crafter/arrow"),
|
|
|
|
MECHANICAL_CRAFTER_BELT_FRAME = get("mechanical_crafter/belt"),
|
|
|
|
MECHANICAL_CRAFTER_BELT = get("mechanical_crafter/belt_animated"),
|
|
|
|
GAUGE_DIAL = get("gauge/dial"),
|
|
|
|
GAUGE_INDICATOR = get("gauge/indicator"),
|
|
|
|
GAUGE_HEAD_SPEED = get("gauge/speedometer/head"),
|
|
|
|
GAUGE_HEAD_STRESS = get("gauge/stressometer/head"),
|
|
|
|
BEARING_TOP = get("bearing/top"),
|
|
|
|
DRILL_HEAD = get("mechanical_drill/head"),
|
|
|
|
HARVESTER_BLADE = get("mechanical_harvester/blade"),
|
|
|
|
DEPLOYER_POLE = get("deployer/pole"),
|
|
|
|
DEPLOYER_HAND_POINTING = get("deployer/hand_pointing"),
|
|
|
|
DEPLOYER_HAND_PUNCHING = get("deployer/hand_punching"),
|
|
|
|
DEPLOYER_HAND_HOLDING = get("deployer/hand_holding"),
|
|
|
|
ANALOG_LEVER_HANDLE = get("analog_lever/handle"),
|
|
|
|
ANALOG_LEVER_INDICATOR = get("analog_lever/indicator"),
|
2020-06-28 18:16:46 +02:00
|
|
|
BELT_FUNNEL_FLAP = get("belt_funnel/flap"),
|
2020-06-15 19:14:03 +02:00
|
|
|
BELT_TUNNEL_FLAP = get("belt_tunnel/flap"),
|
|
|
|
FLEXPEATER_INDICATOR = get("diodes/indicator"),
|
|
|
|
FLYWHEEL = get("flywheel/wheel"),
|
|
|
|
FLYWHEEL_UPPER_ROTATING = get("flywheel/upper_rotating_connector"),
|
2020-07-12 14:54:03 +02:00
|
|
|
|
2020-06-15 19:14:03 +02:00
|
|
|
FLYWHEEL_LOWER_ROTATING = get("flywheel/lower_rotating_connector"),
|
|
|
|
FLYWHEEL_UPPER_SLIDING = get("flywheel/upper_sliding_connector"),
|
|
|
|
FLYWHEEL_LOWER_SLIDING = get("flywheel/lower_sliding_connector"),
|
2020-07-12 13:13:43 +02:00
|
|
|
FURNACE_GENERATOR_FRAME = get("furnace_engine/frame"), CUCKOO_MINUTE_HAND = get("cuckoo_clock/minute_hand"),
|
|
|
|
CUCKOO_HOUR_HAND = get("cuckoo_clock/hour_hand"), CUCKOO_LEFT_DOOR = get("cuckoo_clock/left_door"),
|
|
|
|
CUCKOO_RIGHT_DOOR = get("cuckoo_clock/right_door"), CUCKOO_PIG = get("cuckoo_clock/pig"),
|
|
|
|
CUCKOO_CREEPER = get("cuckoo_clock/creeper"), ROPE_COIL = get("rope_pulley/rope_coil"),
|
|
|
|
ROPE_HALF = get("rope_pulley/rope_half"), ROPE_HALF_MAGNET = get("rope_pulley/rope_half_magnet"),
|
|
|
|
MILLSTONE_COG = get("millstone/inner"), PACKAGER_SEALER = get("packager/sealer"),
|
|
|
|
|
|
|
|
SYMMETRY_PLANE = get("symmetry_effect/plane"), SYMMETRY_CROSSPLANE = get("symmetry_effect/crossplane"),
|
2020-06-15 19:14:03 +02:00
|
|
|
SYMMETRY_TRIPLEPLANE = get("symmetry_effect/tripleplane"),
|
|
|
|
|
2020-07-12 13:13:43 +02:00
|
|
|
ARM_COG = get("mechanical_arm/cog"), ARM_BASE = get("mechanical_arm/base"),
|
|
|
|
ARM_LOWER_BODY = get("mechanical_arm/lower_body"), ARM_UPPER_BODY = get("mechanical_arm/upper_body"),
|
|
|
|
ARM_HEAD = get("mechanical_arm/head"), ARM_CLAW_BASE = get("mechanical_arm/claw_base"),
|
|
|
|
ARM_CLAW_GRIP = get("mechanical_arm/claw_grip"),
|
|
|
|
|
|
|
|
FLAG_SHORT_IN = get("mechanical_arm/flag/short_in"), FLAG_SHORT_OUT = get("mechanical_arm/flag/short_out"),
|
|
|
|
FLAG_LONG_IN = get("mechanical_arm/flag/long_in"), FLAG_LONG_OUT = get("mechanical_arm/flag/long_out"),
|
|
|
|
|
|
|
|
MECHANICAL_PUMP_ARROW = get("mechanical_pump/arrow"), MECHANICAL_PUMP_COG = get("mechanical_pump/cog"),
|
2020-06-15 19:14:03 +02:00
|
|
|
FLUID_PIPE_CASING = get("fluid_pipe/casing");
|
|
|
|
|
|
|
|
public static final Map<Direction, AllBlockPartials> PIPE_RIMS = map();
|
|
|
|
|
|
|
|
static {
|
|
|
|
populateMaps();
|
|
|
|
}
|
2020-05-25 23:09:36 +02:00
|
|
|
|
2020-02-04 14:48:21 +01:00
|
|
|
;
|
2020-06-15 19:14:03 +02:00
|
|
|
|
2020-02-04 14:48:21 +01:00
|
|
|
private ResourceLocation modelLocation;
|
|
|
|
private IBakedModel bakedModel;
|
|
|
|
|
2020-07-12 13:13:43 +02:00
|
|
|
private AllBlockPartials() {}
|
2020-06-15 19:14:03 +02:00
|
|
|
|
|
|
|
private static void populateMaps() {
|
|
|
|
for (Direction d : Iterate.directions) {
|
2020-07-22 06:57:59 +02:00
|
|
|
PIPE_RIMS.put(d, get("fluid_pipe/rim/" + d.getString()));
|
2020-06-15 19:14:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static <T, U> Map<T, U> map() {
|
|
|
|
return new HashMap<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static AllBlockPartials get(String path) {
|
|
|
|
AllBlockPartials partials = new AllBlockPartials();
|
|
|
|
partials.modelLocation = new ResourceLocation(Create.ID, "block/" + path);
|
|
|
|
all.add(partials);
|
|
|
|
return partials;
|
2020-02-04 14:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void onModelRegistry(ModelRegistryEvent event) {
|
2020-06-15 19:14:03 +02:00
|
|
|
for (AllBlockPartials partial : all)
|
2020-02-04 14:48:21 +01:00
|
|
|
ModelLoader.addSpecialModel(partial.modelLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onModelBake(ModelBakeEvent event) {
|
|
|
|
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
|
2020-06-15 19:14:03 +02:00
|
|
|
for (AllBlockPartials partial : all)
|
2020-02-04 14:48:21 +01:00
|
|
|
partial.bakedModel = modelRegistry.get(partial.modelLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IBakedModel get() {
|
|
|
|
return bakedModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SuperByteBuffer renderOn(BlockState referenceState) {
|
|
|
|
return CreateClient.bufferCache.renderPartial(this, referenceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SuperByteBuffer renderOnDirectional(BlockState referenceState) {
|
|
|
|
Direction facing = referenceState.get(FACING);
|
|
|
|
return renderOnDirectional(referenceState, facing);
|
|
|
|
}
|
2020-05-25 23:09:36 +02:00
|
|
|
|
2020-02-04 14:48:21 +01:00
|
|
|
public SuperByteBuffer renderOnHorizontal(BlockState referenceState) {
|
|
|
|
Direction facing = referenceState.get(HORIZONTAL_FACING);
|
|
|
|
return renderOnDirectional(referenceState, facing);
|
|
|
|
}
|
2020-05-25 23:09:36 +02:00
|
|
|
|
2020-02-04 14:48:21 +01:00
|
|
|
public SuperByteBuffer renderOnDirectional(BlockState referenceState, Direction facing) {
|
2020-04-05 03:54:24 +02:00
|
|
|
MatrixStack ms = new MatrixStack();
|
|
|
|
// TODO 1.15 find a way to cache this model matrix computation
|
2020-05-25 23:09:36 +02:00
|
|
|
MatrixStacker.of(ms)
|
|
|
|
.centre()
|
|
|
|
.rotateY(AngleHelper.horizontalAngle(facing))
|
|
|
|
.rotateX(AngleHelper.verticalAngle(facing))
|
|
|
|
.unCentre();
|
2020-07-12 14:54:03 +02:00
|
|
|
return CreateClient.bufferCache.renderDirectionalPartial(this, referenceState, facing, ms);
|
2020-02-04 14:48:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|