Registries n stuff.

- Added registries for Electrodes and Cable Types.
- Winding Machines now tint the main spool instead of requiring partial models for each spool.
- Electrode Holders now render the item model of the electrode instead of requiring partial models for each electrode.
- Added Resistivity config for Cable Types.
- Updated classes to handle the new registries instead of enums.
- Moved the ChemicalVatCategory's recipe sprite to a separate method so mixins can target the sprites specifically.
This commit is contained in:
PouffyDev
2025-06-26 22:49:39 +01:00
parent ef7755fc21
commit 6f34a44e29
42 changed files with 928 additions and 195 deletions

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

5
gradlew vendored
View File

@@ -86,8 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -206,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

View File

@@ -1,9 +1,6 @@
package com.drmangotea.tfmg;
import com.drmangotea.tfmg.base.TFMGBoilerHeaters;
import com.drmangotea.tfmg.base.TFMGContraptions;
import com.drmangotea.tfmg.base.TFMGCreativeTabs;
import com.drmangotea.tfmg.base.TFMGRegistrate;
import com.drmangotea.tfmg.base.*;
import com.drmangotea.tfmg.content.electricity.base.ElectricNetworkManager;
import com.drmangotea.tfmg.content.engines.fuels.BaseFuelTypes;
import com.drmangotea.tfmg.content.items.weapons.explosives.thermite_grenades.fire.TFMGColoredFires;
@@ -15,7 +12,10 @@ import com.drmangotea.tfmg.content.decoration.pipes.TFMGPipes;
import com.drmangotea.tfmg.registry.*;
import com.drmangotea.tfmg.worldgen.TFMGFeatures;
import com.mojang.logging.LogUtils;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.foundation.item.ItemDescription;
import com.simibubi.create.foundation.item.KineticStats;
import com.simibubi.create.foundation.item.TooltipModifier;
import net.createmod.catnip.lang.FontHelper;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
@@ -32,6 +32,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.RegisterEvent;
import org.slf4j.Logger;
import static net.createmod.catnip.lang.FontHelper.styleFromColor;
@SuppressWarnings("removal")
@@ -48,17 +49,27 @@ public class TFMG {
public static final TFMGRegistrate REGISTRATE = TFMGRegistrate.create();
public static final FontHelper.Palette TFMG_PALETTE = new FontHelper.Palette(styleFromColor(0x4c5155), styleFromColor(0x838c8a));
static {
REGISTRATE.setTooltipModifierFactory((item) -> (new ItemDescription.Modifier(item, TFMG_PALETTE)).andThen(TooltipModifier.mapNull(KineticStats.create(item))));
//.andThen(TooltipModifier.mapNull(CableTypeStats.create(item))) (save this for whenever the fuck I figure out what resistivity is meant to do)
}
public TFMG() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
REGISTRATE.registerEventListeners(modEventBus);
TFMGRegistries.register();
TFMGSoundEvents.prepare();
TFMGPipes.init();
TFMGBlocks.init();
TFMGBlockEntities.init();
TFMGItems.init();
TFMGElectrodes.register();
TFMGCableTypes.register();
TFMGEntityTypes.init();
TFMGPartialModels.init();

View File

@@ -2,6 +2,10 @@ package com.drmangotea.tfmg.base;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.fluid.GasFluidType;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableTypeBuilder;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.ElectrodeBuilder;
import com.simibubi.create.content.fluids.VirtualFluid;
import com.simibubi.create.foundation.data.CreateRegistrate;
import com.simibubi.create.foundation.data.VirtualFluidBuilder;
@@ -9,8 +13,8 @@ import com.simibubi.create.foundation.item.ItemDescription;
import com.simibubi.create.foundation.item.KineticStats;
import com.simibubi.create.foundation.item.TooltipModifier;
import com.tterrag.registrate.builders.FluidBuilder;
import com.tterrag.registrate.util.nullness.NonNullFunction;
import net.createmod.catnip.lang.FontHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.*;
import net.minecraftforge.registries.ForgeRegistries;
@@ -60,4 +64,35 @@ public class TFMGRegistrate extends CreateRegistrate {
return TFMG.REGISTRATE.get(name+"_bucket", ForgeRegistries.ITEMS.getRegistryKey()).get();
}
public <T extends CableType> CableTypeBuilder<T, TFMGRegistrate> cableType(NonNullFunction<CableType.Properties, T> factory) {
return cableType((TFMGRegistrate) self(), factory);
}
public <T extends CableType> CableTypeBuilder<T, TFMGRegistrate> cableType(String name, NonNullFunction<CableType.Properties, T> factory) {
return cableType((TFMGRegistrate) self(), name, factory);
}
public <T extends CableType, P> CableTypeBuilder<T, P> cableType(P parent, NonNullFunction<CableType.Properties, T> factory) {
return cableType(parent, currentName(), factory);
}
public <T extends CableType, P> CableTypeBuilder<T, P> cableType(P parent, String name, NonNullFunction<CableType.Properties, T> factory) {
return entry(name, callback -> CableTypeBuilder.create(this, parent, name, callback, factory));
}
public <T extends Electrode> ElectrodeBuilder<T, TFMGRegistrate> electrode(NonNullFunction<Electrode.Properties, T> factory) {
return electrode((TFMGRegistrate) self(), factory);
}
public <T extends Electrode> ElectrodeBuilder<T, TFMGRegistrate> electrode(String name, NonNullFunction<Electrode.Properties, T> factory) {
return electrode((TFMGRegistrate) self(), name, factory);
}
public <T extends Electrode, P> ElectrodeBuilder<T, P> electrode(P parent, NonNullFunction<Electrode.Properties, T> factory) {
return electrode(parent, currentName(), factory);
}
public <T extends Electrode, P> ElectrodeBuilder<T, P> electrode(P parent, String name, NonNullFunction<Electrode.Properties, T> factory) {
return entry(name, callback -> ElectrodeBuilder.create(this, parent, name, callback, factory));
}
}

View File

@@ -0,0 +1,23 @@
package com.drmangotea.tfmg.base;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.RegistryBuilder;
import java.util.HashMap;
import java.util.Map;
public class TFMGRegistries {
public static final Map<ResourceLocation, CableType> registeredCableTypes = new HashMap<>();
public static final Map<ResourceLocation, Electrode> registeredElectrodes = new HashMap<>();
public static final ResourceKey<Registry<CableType>> CABLE_TYPE = TFMG.REGISTRATE.makeRegistry("cable_type", () -> new RegistryBuilder<CableType>().hasTags().allowModification().setDefaultKey(TFMG.asResource("empty")));
public static final ResourceKey<Registry<Electrode>> ELECTRODE = TFMG.REGISTRATE.makeRegistry("electrode", () -> new RegistryBuilder<Electrode>().hasTags().allowModification().setDefaultKey(TFMG.asResource("none")));
public static void register() {
}
}

View File

@@ -4,7 +4,9 @@ package com.drmangotea.tfmg.base;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.spark.ElectricSparkParticle;
import com.drmangotea.tfmg.base.spark.Spark;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cables.CablePos;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import com.drmangotea.tfmg.registry.TFMGEntityTypes;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
@@ -22,6 +24,7 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
@@ -381,5 +384,11 @@ public class TFMGUtils {
vertexConsumer.vertex(matrix4f, x + p_174319_, y + thickness - p_174318_ + pain, z - p_174320_).color(red, green, blue, 1.0F).uv2(k).endVertex();
}
public static Electrode getElectrode(ResourceLocation name) {
return TFMGRegistries.registeredElectrodes.get(name);
}
public static CableType getCableType(ResourceLocation name) {
return TFMGRegistries.registeredCableTypes.get(name);
}
}

View File

@@ -1,7 +1,7 @@
package com.drmangotea.tfmg.config;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.ResistivityValues;
import com.simibubi.create.api.stress.BlockStressValues;
import com.simibubi.create.infrastructure.config.CCommon;
import net.createmod.catnip.config.ConfigBase;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -58,6 +58,8 @@ public class TFMGConfigs {
TFMGStress stress = TFMGConfigs.server().stressValues;
BlockStressValues.IMPACTS.registerProvider(stress::getImpact);
BlockStressValues.CAPACITIES.registerProvider(stress::getCapacity);
TFMGResistivity resistivity = server().resistivityValues;
ResistivityValues.RESISTIVITIES.registerProvider(resistivity::getResistivity);
}
@SubscribeEvent

View File

@@ -0,0 +1,63 @@
package com.drmangotea.tfmg.config;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableTypeBuilder;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
import net.createmod.catnip.config.ConfigBase;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.DoubleSupplier;
public class TFMGResistivity extends ConfigBase {
// bump this version to reset configured values.
private static final int VERSION = 2;
// IDs need to be used since configs load before registration
private static final Object2DoubleMap<ResourceLocation> DEFAULT_RESISTIVITIES = new Object2DoubleOpenHashMap<>();
protected final Map<ResourceLocation, ForgeConfigSpec.ConfigValue<Double>> resistivities = new HashMap<>();
@Override
public void registerAll(ForgeConfigSpec.Builder builder) {
builder.comment(".", Comments.resistivity).push("resistivity");
DEFAULT_RESISTIVITIES.forEach((id, value) -> this.resistivities.put(id, builder.define(id.getPath(), value)));
builder.pop();
}
@Override
public String getName() {
return "resistivityValues.v" + VERSION;
}
@Nullable
public DoubleSupplier getResistivity(CableType cableType) {
ResourceLocation id = cableType.getKey();
ForgeConfigSpec.ConfigValue<Double> value = this.resistivities.get(id);
return value == null ? null : value::get;
}
public static <B extends CableType, P> NonNullUnaryOperator<CableTypeBuilder<B, P>> setNoResistivity() {
return setResistivity(0);
}
public static <B extends CableType, P> NonNullUnaryOperator<CableTypeBuilder<B, P>> setResistivity(double value) {
return builder -> {
//assertFromCreate(builder);
ResourceLocation id = TFMG.asResource(builder.getName());
DEFAULT_RESISTIVITIES.put(id, value);
return builder;
};
}
private static class Comments {
static String resistivity = "Configure the individual resistivity of cable types.";
}
}

View File

@@ -7,7 +7,8 @@ public class TFMGServerConfig extends ConfigBase {
public final TFMGStress stressValues = nested(0, TFMGStress::new, "Fine tune the kinetic stats of individual components");
public final TFMGStress stressValues = nested(1, TFMGStress::new, "Fine tune the kinetic stats of individual components");
public final TFMGResistivity resistivityValues = nested(0, TFMGResistivity::new, "Fine tune the resistivity stats of individual cable types");
@Override
public String getName() {

View File

@@ -0,0 +1,69 @@
package com.drmangotea.tfmg.content.electricity.connection.cable_type;
import com.drmangotea.tfmg.registry.TFMGItems;
import com.tterrag.registrate.util.entry.ItemEntry;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
public class CableType {
private String descriptionId;
private final ResourceLocation id;
private final int color;
private final ItemEntry<?> spool;
public CableType(Properties properties) {
this.id = properties.id;
this.color = properties.color;
this.spool = properties.spool;
}
public int getColor() {
return this.color;
}
public ItemEntry<?> getSpool() {
return this.spool;
}
public String getOrCreateDescriptionId() {
if (this.descriptionId == null) {
this.descriptionId = Util.makeDescriptionId("cable_type", getKey());
}
return this.descriptionId;
}
public String getDescriptionId() {
return this.getOrCreateDescriptionId();
}
public Component getDisplayName() {
return Component.translatable(this.getOrCreateDescriptionId());
}
public ResourceLocation getKey() {
return this.id;
}
public static class Properties {
private ResourceLocation id;
int color = 0xffffff;
ItemEntry<?> spool = TFMGItems.COPPER_SPOOL;
public Properties color(int color) {
this.color = color;
return this;
}
public Properties spool(ItemEntry<?> spool) {
this.spool = spool;
return this;
}
public Properties(ResourceLocation id) {
this.id = id;
}
}
}

View File

@@ -0,0 +1,66 @@
package com.drmangotea.tfmg.content.electricity.connection.cable_type;
import com.drmangotea.tfmg.base.TFMGRegistries;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.builders.AbstractBuilder;
import com.tterrag.registrate.builders.BuilderCallback;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullFunction;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import com.tterrag.registrate.util.nullness.NonnullType;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.RegistryObject;
public class CableTypeBuilder<T extends CableType, P> extends AbstractBuilder<CableType, T, P, CableTypeBuilder<T, P>> {
public static <T extends CableType, P> CableTypeBuilder<T, P> create(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, NonNullFunction<CableType.Properties, T> factory) {
return new CableTypeBuilder<>(owner, parent, name, callback, factory);
}
private final NonNullFunction<CableType.Properties, T> factory;
private NonNullSupplier<CableType.Properties> initialProperties = () -> new CableType.Properties(new ResourceLocation(getOwner().getModid(), getName()));
private NonNullFunction<CableType.Properties, CableType.Properties> propertiesCallback = NonNullUnaryOperator.identity();
public CableTypeBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, NonNullFunction<CableType.Properties, T> factory) {
super(owner, parent, name, callback, TFMGRegistries.CABLE_TYPE);
this.factory = factory;
}
public CableTypeBuilder<T, P> properties(NonNullUnaryOperator<CableType.Properties> func) {
propertiesCallback = propertiesCallback.andThen(func);
return this;
}
public CableTypeBuilder<T, P> initialProperties(NonNullSupplier<CableType.Properties> properties) {
initialProperties = properties;
return this;
}
public CableTypeBuilder<T, P> defaultLang() {
return lang(CableType::getDescriptionId);
}
public CableTypeBuilder<T, P> lang(String name) {
return lang(CableType::getDescriptionId, name);
}
@Override
protected @NonnullType T createEntry() {
CableType.Properties properties = this.initialProperties.get();
properties = propertiesCallback.apply(properties);
return factory.apply(properties);
}
@Override
protected RegistryEntry<T> createEntryWrapper(RegistryObject<T> delegate) {
return new CableTypeEntry<>(getOwner(), delegate);
}
@Override
public CableTypeEntry<T> register() {
TFMGRegistries.registeredCableTypes.put(new ResourceLocation(getOwner().getModid(), getName()), createEntry());
return (CableTypeEntry<T>) super.register();
}
}

View File

@@ -0,0 +1,15 @@
package com.drmangotea.tfmg.content.electricity.connection.cable_type;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraftforge.registries.RegistryObject;
public class CableTypeEntry<T extends CableType> extends RegistryEntry<T> {
public CableTypeEntry(AbstractRegistrate<?> owner, RegistryObject<T> delegate) {
super(owner, delegate);
}
public static <T extends CableType> CableTypeEntry<T> cast(RegistryEntry<T> entry) {
return RegistryEntry.cast(CableTypeEntry.class, entry);
}
}

View File

@@ -0,0 +1,94 @@
package com.drmangotea.tfmg.content.electricity.connection.cable_type;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.config.TFMGConfigs;
import com.drmangotea.tfmg.config.TFMGServerConfig;
import com.drmangotea.tfmg.content.machinery.misc.winding_machine.SpoolItem;
import com.simibubi.create.content.equipment.goggles.GogglesItem;
import com.simibubi.create.foundation.item.TooltipModifier;
import com.simibubi.create.foundation.utility.CreateLang;
import net.createmod.catnip.lang.LangBuilder;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static net.minecraft.ChatFormatting.GRAY;
public class CableTypeStats implements TooltipModifier {
protected final SpoolItem cableItem;
public CableTypeStats(SpoolItem cableItem) {
this.cableItem = cableItem;
}
@Nullable
public static CableTypeStats create(Item item) {
if (item instanceof SpoolItem cableItem) {
if (Objects.equals(cableItem.cableTypeKey, TFMG.asResource("empty"))) return null;
return new CableTypeStats(cableItem);
}
return null;
}
@Override
public void modify(ItemTooltipEvent context) {
List<Component> conductorStats = getCableTypeStats(cableItem, context.getEntity());
if (!conductorStats.isEmpty()) {
List<Component> tooltip = context.getToolTip();
tooltip.add(CommonComponents.EMPTY);
tooltip.addAll(conductorStats);
}
}
public static List<Component> getCableTypeStats(SpoolItem spoolItem, Player player) {
List<Component> list = new ArrayList<>();
TFMGServerConfig config = TFMGConfigs.server();
boolean hasGoggles = GogglesItem.isWearingGoggles(player);
CreateLang.translate("tooltip.resistivity")
.style(GRAY)
.addTo(list);
double resistivity = ResistivityValues.getResistivity(TFMGUtils.getCableType(spoolItem.cableTypeKey));
LangBuilder builder = CreateLang.builder();
builder.space().add(CreateLang.text(resistivity + "Ω")).style(ChatFormatting.GOLD).addTo(list);
return list;
}
enum Resistivity {
VERY_LOW(ChatFormatting.RED, ChatFormatting.GOLD),
LOW(ChatFormatting.GOLD, ChatFormatting.YELLOW),
MEDIUM(ChatFormatting.YELLOW, ChatFormatting.GREEN),
HIGH(ChatFormatting.GREEN, ChatFormatting.DARK_GREEN)
;
private final ChatFormatting absoluteColor;
private final ChatFormatting relativeColor;
Resistivity(ChatFormatting absoluteColor, ChatFormatting relativeColor) {
this.absoluteColor = absoluteColor;
this.relativeColor = relativeColor;
}
public ChatFormatting getAbsoluteColor() {
return absoluteColor;
}
public ChatFormatting getRelativeColor() {
return relativeColor;
}
}
}

View File

@@ -0,0 +1,14 @@
package com.drmangotea.tfmg.content.electricity.connection.cable_type;
import com.simibubi.create.api.registry.SimpleRegistry;
import java.util.function.DoubleSupplier;
public class ResistivityValues {
public static final SimpleRegistry<CableType, DoubleSupplier> RESISTIVITIES = SimpleRegistry.create();
public static double getResistivity(CableType conductor) {
DoubleSupplier supplier = RESISTIVITIES.get(conductor);
return supplier == null ? 0 : supplier.getAsDouble();
}
}

View File

@@ -1,13 +1,10 @@
package com.drmangotea.tfmg.content.electricity.connection.cables;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.registry.TFMGItems;
import com.tterrag.registrate.util.entry.ItemEntry;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import org.checkerframework.checker.units.qual.C;
import net.minecraft.resources.ResourceLocation;
public class CableConnection {
@@ -46,7 +43,7 @@ public class CableConnection {
compoundTag.putBoolean("Visible", visible);
compoundTag.putString("CableType", type.toString());
compoundTag.putString("CableType", type.getKey().toString());
return compoundTag;
}
@@ -63,7 +60,7 @@ public class CableConnection {
BlockPos blockPos1 = BlockPos.of(compoundTag.getLong("Pos"));
boolean visible = compoundTag.getBoolean("Visible");
CableType type = CableType.valueOf(compoundTag.getString("CableType"));
CableType type = TFMGUtils.getCableType(new ResourceLocation(compoundTag.getString("CableType")));
return new CableConnection(pos1,pos2,blockPos1,type,visible);
}
public float getLength(){
@@ -72,20 +69,20 @@ public class CableConnection {
public enum CableType{
NONE(TFMGItems.COPPER_WIRE, 0,0xffffff),
COPPER(TFMGItems.COPPER_WIRE, 0.00188f,0xD8735A),
ALUMINUM(TFMGItems.ALUMINUM_WIRE, 0.0027f,0xEDEFEF),
CONSTANTAN(TFMGItems.CONSTANTAN_WIRE, 1f,0xEDEFEF),
STEEL_REINFORCED_ALUMINUM(TFMGItems.COPPER_WIRE, 0.0027f,0xB8A08D)
;
public final ItemEntry<?> wire;
public final float resistivity;
public final int color;
CableType(ItemEntry<?> wire, float resistivity, int color){
this.wire = wire;
this.resistivity = resistivity;
this.color = color;
}
}
//public enum CableType{
// NONE(TFMGItems.COPPER_WIRE, 0,0xffffff),
// COPPER(TFMGItems.COPPER_WIRE, 0.00188f,0xD8735A),
// ALUMINUM(TFMGItems.ALUMINUM_WIRE, 0.0027f,0xEDEFEF),
// CONSTANTAN(TFMGItems.CONSTANTAN_WIRE, 1f,0xEDEFEF),
// STEEL_REINFORCED_ALUMINUM(TFMGItems.COPPER_WIRE, 0.0027f,0xB8A08D)
// ;
// public final ItemEntry<?> wire;
// public final float resistivity;
// public final int color;
// CableType(ItemEntry<?> wire, float resistivity, int color){
// this.wire = wire;
// this.resistivity = resistivity;
// this.color = color;
// }
//}
}

View File

@@ -71,7 +71,7 @@ public class CableConnectorBlockEntity extends ElectricBlockEntity implements IH
return;
for (CableConnection connection : connections) {
ItemEntity itemToDrop = new ItemEntity(level, getBlockPos().getX() + 0.5f, getBlockPos().getY() + 0.5f, getBlockPos().getZ() + 0.5f, new ItemStack(connection.type.wire.get(), (int) (connection.getLength()/8)));
ItemEntity itemToDrop = new ItemEntity(level, getBlockPos().getX() + 0.5f, getBlockPos().getY() + 0.5f, getBlockPos().getZ() + 0.5f, new ItemStack(connection.type.getSpool().get(), (int) (connection.getLength()/8)));
if (itemToDrop.getItem().getCount() > 0) {
level.addFreshEntity(itemToDrop);
}

View File

@@ -35,7 +35,7 @@ public class CableConnectorRenderer extends SafeBlockEntityRenderer<CableConnect
for (CableConnection connection : be.connections) {
if (connection.visible)
TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, connection.pos2, connection.pos1, connection.getLength() / 4500, new Color(connection.type.color).getRed(), new Color(connection.type.color).getGreen(), new Color(connection.type.color).getBlue());
TFMGUtils.renderWire(be.getLevel(), ms, bufferSource, connection.pos2, connection.pos1, connection.getLength() / 4500, new Color(connection.type.getColor()).getRed(), new Color(connection.type.getColor()).getGreen(), new Color(connection.type.getColor()).getBlue());
}
//for (BlockPos connection : be.connections) {

View File

@@ -1,19 +1,18 @@
package com.drmangotea.tfmg.content.machinery.misc.winding_machine;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGRegistries;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnection;
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnectorBlockEntity;
import com.drmangotea.tfmg.content.electricity.connection.cables.CablePos;
import com.drmangotea.tfmg.registry.TFMGItems;
import com.simibubi.create.foundation.utility.CreateLang;
import dev.engine_room.flywheel.lib.model.baked.PartialModel;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
@@ -21,7 +20,6 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
@@ -29,20 +27,17 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.List;
import static com.simibubi.create.foundation.utility.Debug.debugMessage;
import java.util.Objects;
public class SpoolItem extends Item {
public final PartialModel model;
public final int barColor;
public final CableConnection.CableType type;
public final ResourceLocation cableTypeKey;
public SpoolItem(Properties properties, PartialModel model, int barColor, CableConnection.CableType type) {
public SpoolItem(Properties properties, int barColor, ResourceLocation type) {
super(properties);
this.model = model;
this.barColor = barColor;
this.type = type;
this.cableTypeKey = type;
}
@@ -98,13 +93,13 @@ public class SpoolItem extends Item {
if(level.isClientSide)
return InteractionResult.SUCCESS;
if(type == CableConnection.CableType.NONE)
if(Objects.equals(cableTypeKey, TFMG.asResource("empty")))
return InteractionResult.PASS;
if(level.getBlockEntity(pos) instanceof CableConnectorBlockEntity be){
if(stack.getOrCreateTag().getLong("Position")!=0){
BlockPos posToConnect = BlockPos.of(stack.getOrCreateTag().getLong("Position"));
if(posToConnect == pos){
if(posToConnect.equals(pos)){
stack.getOrCreateTag().putLong("Position",0);
if (level.isClientSide)
player.displayClientMessage(CreateLang.translateDirect("wires.cant_connect_itself")
@@ -118,9 +113,10 @@ public class SpoolItem extends Item {
if(level.getBlockEntity(posToConnect) instanceof CableConnectorBlockEntity otherBE) {
//CableConnectorBlockEntity connectedBe1 = pos.asLong()>posToConnect.asLong() ? otherBE : be;
//CableConnectorBlockEntity connectedBe2= pos.asLong()>posToConnect.asLong() ? be : otherBE;
CableType cableType = TFMGUtils.getCableType(cableTypeKey);
//
CableConnection connection1 = new CableConnection(be.getCablePosition(), otherBE.getCablePosition(), otherBE.getBlockPos(),type,true);
CableConnection connection2 = new CableConnection(otherBE.getCablePosition(), be.getCablePosition(), be.getBlockPos(),type,false);
CableConnection connection1 = new CableConnection(be.getCablePosition(), otherBE.getCablePosition(), otherBE.getBlockPos(),cableType,true);
CableConnection connection2 = new CableConnection(otherBE.getCablePosition(), be.getCablePosition(), be.getBlockPos(),cableType,false);
float wireCost = (connection1.getLength()/8);
@@ -211,7 +207,7 @@ public class SpoolItem extends Item {
@Override
public boolean isBarVisible(ItemStack stack) {
return model != null;
return !Objects.equals(cableTypeKey, TFMG.asResource("empty")) && TFMGRegistries.registeredCableTypes.containsKey(cableTypeKey);
}
@Override

View File

@@ -13,6 +13,7 @@ import com.simibubi.create.content.processing.sequenced.SequencedAssemblyRecipe;
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
import com.simibubi.create.foundation.blockEntity.behaviour.ValueBoxTransform;
import com.simibubi.create.foundation.blockEntity.behaviour.scrollValue.ScrollValueBehaviour;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.item.SmartInventory;
import com.simibubi.create.foundation.utility.CreateLang;
@@ -23,6 +24,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Containers;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
@@ -264,5 +266,9 @@ public class WindingMachineBlockEntity extends KineticBlockEntity implements IHa
}
}
public void destroy() {
super.destroy();
ItemHelper.dropContents(level, worldPosition, inventory);
Containers.dropItemStack(getLevel(), getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ(), spool);
}
}

View File

@@ -51,30 +51,30 @@ public class WindingMachineRenderer extends KineticBlockEntityRenderer<WindingMa
.rotateXDegrees(be.angle)
.uncenter()
.renderInto(ms, bufferSource.getBuffer(RenderType.cutoutMipped()));
if (((SpoolItem) be.spool.getItem()).model != null) {
CachedBuffers.partial(((SpoolItem) be.spool.getItem()).model, blockState)
CachedBuffers.partial(TFMGPartialModels.SPOOL_WIRE, blockState)
.light(light)
.center()
.rotateYDegrees(blockState.getValue(HORIZONTAL_FACING).getAxis() == Direction.Axis.Z ? Math.abs(blockState.getValue(FACING).toYRot() - 180) : blockState.getValue(FACING).toYRot())
.translateZ(-0.4f)
.translateY(0.4f)
.color(be.spool.getBarColor())
.rotateXDegrees(be.angle)
.uncenter()
.renderInto(ms, vb);
if (!be.inventory.isEmpty()) {
CachedBuffers.partial(be.getSpeed() != 0 ? TFMGPartialModels.CONNNECTING_WIRE_ANIMATED : TFMGPartialModels.CONNNECTING_WIRE, blockState)
.light(light)
.center()
.rotateYDegrees(blockState.getValue(HORIZONTAL_FACING).getAxis() == Direction.Axis.Z ? Math.abs(blockState.getValue(FACING).toYRot() - 180) : blockState.getValue(FACING).toYRot())
.translateZ(-0.4f)
.translateY(0.4f)
.rotateXDegrees(be.angle)
.translateZ(0.1f)
.color(be.spool.getBarColor())
.rotateXDegrees(12)
.uncenter()
.renderInto(ms, vb);
if (!be.inventory.isEmpty()) {
CachedBuffers.partial(be.getSpeed() != 0 ? TFMGPartialModels.CONNNECTING_WIRE_ANIMATED : TFMGPartialModels.CONNNECTING_WIRE, blockState)
.light(light)
.center()
.rotateYDegrees(blockState.getValue(HORIZONTAL_FACING).getAxis() == Direction.Axis.Z ? Math.abs(blockState.getValue(FACING).toYRot() - 180) : blockState.getValue(FACING).toYRot())
.translateY(0.4f)
.translateZ(0.1f)
.color(be.spool.getBarColor())
.rotateXDegrees(12)
.uncenter()
.renderInto(ms, vb);
}
}
}
if (!be.inventory.isEmpty()) {
ItemStack item = be.inventory.getItem(0);

View File

@@ -1,6 +1,9 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.content.electricity.base.IElectric;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import com.drmangotea.tfmg.registry.TFMGBlockEntities;
import com.simibubi.create.foundation.block.IBE;
import net.minecraft.core.BlockPos;
@@ -24,15 +27,21 @@ public class ElectrodeHolderBlock extends Block implements IBE<ElectrodeHolderBl
return InteractionResult.PASS;
if(level.getBlockEntity(pos) instanceof ElectrodeHolderBlockEntity be){
ItemStack stack = player.getItemInHand(hand);
ElectrodeHolderBlockEntity.ElectrodeType electrodeType = be.electrodeType;
ItemStack stackInside = electrodeType.item;
Electrode electrode = be.electrode;
ItemStack stackInside = electrode.getStack();
if(stack.is(stackInside.getItem()))
return InteractionResult.PASS;
if(be.setElectrode(stack, true)) {
player.setItemInHand(hand, electrodeType.item);
player.setItemInHand(hand, electrode.getStack());
be.setElectrode(stack, false);
return InteractionResult.SUCCESS;
}
if (player.isShiftKeyDown() && player.getItemInHand(hand).isEmpty()) {
if (be.electrode == TFMGUtils.getElectrode(TFMG.asResource("none"))) return InteractionResult.PASS;
player.setItemInHand(hand, electrode.getStack());
be.setElectrode(TFMGUtils.getElectrode(TFMG.asResource("none")), false);
return InteractionResult.SUCCESS;
}
}
return InteractionResult.PASS;
}

View File

@@ -1,30 +1,32 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGRegistries;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.drmangotea.tfmg.config.TFMGConfigs;
import com.drmangotea.tfmg.content.electricity.base.ElectricBlockEntity;
import com.drmangotea.tfmg.content.machinery.vat.base.IVatMachine;
import com.drmangotea.tfmg.content.machinery.vat.base.VatBlock;
import com.drmangotea.tfmg.content.machinery.vat.base.VatBlockEntity;
import com.drmangotea.tfmg.registry.TFMGItems;
import com.drmangotea.tfmg.registry.TFMGPartialModels;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import com.simibubi.create.foundation.utility.CreateLang;
import dev.engine_room.flywheel.lib.model.baked.PartialModel;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Containers;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import java.util.List;
import java.util.Objects;
public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements IVatMachine {
ElectrodeType electrodeType = ElectrodeType.NONE;
Electrode electrode = TFMGUtils.getElectrode(TFMG.asResource("none"));
boolean isTallEnough = true;
public ElectrodeHolderBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
@@ -39,10 +41,12 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
public boolean setElectrode(ItemStack modeItem, boolean simulate) {
for (ElectrodeType type : ElectrodeType.values()) {
if (type.item.is(modeItem.getItem())) {
if (level == null) return false;
for (Electrode electrode : level.registryAccess().registryOrThrow(TFMGRegistries.ELECTRODE)) {
if (electrode.getStack().isEmpty()) continue;
if (modeItem.is(electrode.getStack().getItem())) {
if (!simulate) {
electrodeType = type;
this.electrode = electrode;
} else return true;
}
}
@@ -67,14 +71,7 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
@Override
public float resistance() {
if (electrodeType != ElectrodeType.NONE) {
if (electrodeType == ElectrodeType.GRAPHITE) {
return 300;
} else return 100;
}
return 0;
return this.electrode.getResistance();
}
@Override
@@ -82,13 +79,11 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
return true;
}
public boolean setElectrode(String name, boolean simulate) {
for (ElectrodeType type : ElectrodeType.values()) {
if (Objects.equals(type.name, name)) {
if (!simulate) {
electrodeType = type;
} else return true;
}
public boolean setElectrode(Electrode electrode, boolean simulate) {
if (electrode != null) {
if (!simulate) {
this.electrode = electrode;
} else return true;
}
if (!simulate && hasLevel())
VatBlock.updateVatState(getBlockState(), getLevel(), getBlockPos().relative(Direction.DOWN));
@@ -114,32 +109,31 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
@Override
public void write(CompoundTag compound, boolean clientPacket) {
for (ElectrodeType electrode : ElectrodeType.values()) {
if (electrode == electrodeType) {
compound.putString("Electrode", electrode.name);
}
}
compound.putString("Electrode", electrode.getKey().toString());
super.write(compound, clientPacket);
}
@Override
protected void read(CompoundTag compound, boolean clientPacket) {
super.read(compound, clientPacket);
setElectrode(TFMGUtils.getElectrode(new ResourceLocation(compound.getString("Electrode"))), false);
}
setElectrode(compound.getString("Electrode"), false);
public void destroy() {
ItemStack electrodeItem = electrode.getStack();
Containers.dropItemStack(getLevel(), getBlockPos().getX(), getBlockPos().getY(), getBlockPos().getZ(), electrodeItem);
}
@Override
public String getOperationId() {
return isOperational() ? electrode.getOperationId() : "";
return switch (electrodeType) {
case NONE -> "";
case COPPER, ZINC -> isOperational() ? "tfmg:electrode" : "";
case GRAPHITE -> isOperational() ? "tfmg:graphite_electrode" : "";
};
//return switch (electrodeType) {
//
// case NONE -> "";
// case COPPER, ZINC -> isOperational() ? "tfmg:electrode" : "";
// case GRAPHITE -> isOperational() ? "tfmg:graphite_electrode" : "";
//};
}
@Override
@@ -153,22 +147,22 @@ public class ElectrodeHolderBlockEntity extends ElectricBlockEntity implements I
}
enum ElectrodeType {
NONE("none", ItemStack.EMPTY, null),
COPPER("copper", TFMGItems.COPPER_ELECTRODE.asStack(), TFMGPartialModels.COPPER_ELECTRODE),
ZINC("zinc", TFMGItems.ZINC_ELECTRODE.asStack(), TFMGPartialModels.ZINC_ELECTRODE),
GRAPHITE("graphite", TFMGItems.GRAPHITE_ELECTRODE.asStack(), TFMGPartialModels.GRAPHITE_ELECTRODE);
public final String name;
public final ItemStack item;
public final PartialModel model;
ElectrodeType(String name, ItemStack stack, PartialModel model) {
this.name = name;
this.item = stack;
this.model = model;
}
}
//enum ElectrodeType {
//
// NONE("none", ItemStack.EMPTY, null),
// COPPER("copper", TFMGItems.COPPER_ELECTRODE.asStack(), TFMGPartialModels.COPPER_ELECTRODE),
// ZINC("zinc", TFMGItems.ZINC_ELECTRODE.asStack(), TFMGPartialModels.ZINC_ELECTRODE),
// GRAPHITE("graphite", TFMGItems.GRAPHITE_ELECTRODE.asStack(), TFMGPartialModels.GRAPHITE_ELECTRODE);
//
// public final String name;
// public final ItemStack item;
// public final PartialModel model;
//
// ElectrodeType(String name, ItemStack stack, PartialModel model) {
// this.name = name;
// this.item = stack;
// this.model = model;
// }
//
//}
}

View File

@@ -1,19 +1,23 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder;
import com.drmangotea.tfmg.registry.TFMGPartialModels;
import com.drmangotea.tfmg.TFMG;
import com.drmangotea.tfmg.base.TFMGUtils;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import com.simibubi.create.foundation.blockEntity.renderer.SafeBlockEntityRenderer;
import net.createmod.catnip.render.CachedBuffers;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.block.state.BlockState;
public class ElectrodeHolderRenderer extends SafeBlockEntityRenderer<ElectrodeHolderBlockEntity> {
private final ItemRenderer itemRenderer;
public ElectrodeHolderRenderer(BlockEntityRendererProvider.Context context) {
itemRenderer = context.getItemRenderer();
}
@Override
@@ -24,16 +28,17 @@ public class ElectrodeHolderRenderer extends SafeBlockEntityRenderer<ElectrodeHo
BlockState blockState = be.getBlockState();
if (be.electrodeType == ElectrodeHolderBlockEntity.ElectrodeType.NONE)
if (be.electrode == TFMGUtils.getElectrode(TFMG.asResource("none")))
return;
if (be.electrodeType.model == null)
if (be.electrode.getStack().isEmpty())
return;
CachedBuffers.partial(be.electrodeType.model, blockState)
.light(LevelRenderer.getLightColor(be.getLevel(), be.getBlockPos().below()))
.translateY(-1)
.renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped()));
ms.pushPose();
ms.mulPose(Axis.XP.rotationDegrees(0));
ms.translate(0.5, -1.4369, 0.5);
ms.scale(3.33f, 3.33f, 3.33f);
itemRenderer.renderStatic(be.electrode.getStack(), ItemDisplayContext.GROUND, LevelRenderer.getLightColor(be.getLevel(), be.getBlockPos().below()), OverlayTexture.NO_OVERLAY, ms, buffer, be.getLevel(), 0);
ms.popPose();
}
}

View File

@@ -0,0 +1,85 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode;
import com.tterrag.registrate.util.entry.ItemEntry;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
public class Electrode {
private String descriptionId;
private final ResourceLocation id;
private final ItemEntry<?> item;
private final int resistance;
private final String operationId;
public Electrode(Properties properties) {
this.id = properties.id;
this.item = properties.item;
this.resistance = properties.resistance;
this.operationId = properties.operationId;
}
public ItemEntry<?> getItem() {
return this.item;
}
public ItemStack getStack() {
return getItem() != null ? getItem().asStack() : ItemStack.EMPTY;
}
public int getResistance() {
return this.resistance;
}
public String getOperationId() {
return this.operationId;
}
public String getOrCreateDescriptionId() {
if (this.descriptionId == null) {
this.descriptionId = Util.makeDescriptionId("electrode", getKey());
}
return this.descriptionId;
}
public String getDescriptionId() {
return this.getOrCreateDescriptionId();
}
public Component getDisplayName() {
return Component.translatable(this.getOrCreateDescriptionId());
}
public ResourceLocation getKey() {
return this.id;
}
public static class Properties {
private ResourceLocation id;
ItemEntry<?> item;
int resistance = 0;
String operationId = "";
public Properties item(ItemEntry<?> item) {
this.item = item;
return this;
}
public Properties resistance(int resistance) {
this.resistance = resistance;
return this;
}
public Properties operationId(String operationId) {
this.operationId = operationId;
return this;
}
public Properties(ResourceLocation id) {
this.id = id;
}
}
}

View File

@@ -0,0 +1,66 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode;
import com.drmangotea.tfmg.base.TFMGRegistries;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.builders.AbstractBuilder;
import com.tterrag.registrate.builders.BuilderCallback;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullFunction;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import com.tterrag.registrate.util.nullness.NonnullType;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.RegistryObject;
public class ElectrodeBuilder<T extends Electrode, P> extends AbstractBuilder<Electrode, T, P, ElectrodeBuilder<T, P>> {
public static <T extends Electrode, P> ElectrodeBuilder<T, P> create(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, NonNullFunction<Electrode.Properties, T> factory) {
return new ElectrodeBuilder<>(owner, parent, name, callback, factory);
}
private final NonNullFunction<Electrode.Properties, T> factory;
private NonNullSupplier<Electrode.Properties> initialProperties = () -> new Electrode.Properties(new ResourceLocation(getOwner().getModid(), getName()));
private NonNullFunction<Electrode.Properties, Electrode.Properties> propertiesCallback = NonNullUnaryOperator.identity();
public ElectrodeBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, NonNullFunction<Electrode.Properties, T> factory) {
super(owner, parent, name, callback, TFMGRegistries.ELECTRODE);
this.factory = factory;
}
public ElectrodeBuilder<T, P> properties(NonNullUnaryOperator<Electrode.Properties> func) {
propertiesCallback = propertiesCallback.andThen(func);
return this;
}
public ElectrodeBuilder<T, P> initialProperties(NonNullSupplier<Electrode.Properties> properties) {
initialProperties = properties;
return this;
}
public ElectrodeBuilder<T, P> defaultLang() {
return lang(Electrode::getDescriptionId);
}
public ElectrodeBuilder<T, P> lang(String name) {
return lang(Electrode::getDescriptionId, name);
}
@Override
protected @NonnullType T createEntry() {
Electrode.Properties properties = this.initialProperties.get();
properties = propertiesCallback.apply(properties);
return factory.apply(properties);
}
@Override
protected RegistryEntry<T> createEntryWrapper(RegistryObject<T> delegate) {
return new ElectrodeEntry<>(getOwner(), delegate);
}
@Override
public ElectrodeEntry<T> register() {
TFMGRegistries.registeredElectrodes.put(new ResourceLocation(getOwner().getModid(), getName()), createEntry());
return (ElectrodeEntry<T>) super.register();
}
}

View File

@@ -0,0 +1,17 @@
package com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableTypeEntry;
import com.tterrag.registrate.AbstractRegistrate;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraftforge.registries.RegistryObject;
public class ElectrodeEntry<T extends Electrode> extends RegistryEntry<T> {
public ElectrodeEntry(AbstractRegistrate<?> owner, RegistryObject<T> delegate) {
super(owner, delegate);
}
public static <T extends Electrode> ElectrodeEntry<T> cast(RegistryEntry<T> entry) {
return RegistryEntry.cast(ElectrodeEntry.class, entry);
}
}

View File

@@ -88,31 +88,10 @@ public class ChemicalVatCategory extends CreateRecipeCategory<VatMachineRecipe>
TFMGGuiTextures.VAT.render(graphics, 0, 24);
if (allowedVatTypes.contains("firebrick_lined_vat") && allowedVatTypes.size() == 1) {
TFMGGuiTextures.FIREPROOF_BRICK_OVERLAY.render(graphics, 55 - 48, 32);
}
drawVatTypes(allowedVatTypes, graphics);
if (machines.contains("tfmg:mixing")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12, 0);
TFMGGuiTextures.MIXER.render(graphics, 55 - 19, 32);
}
if (machines.contains("tfmg:electrode")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 - 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 + 32, 0);
TFMGGuiTextures.ELECTRODE.render(graphics, 55 - 3 - 32, 32);
TFMGGuiTextures.ELECTRODE.render(graphics, 55 - 3 + 32, 32);
}
if (machines.contains("tfmg:graphite_electrode")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 - 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 + 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12, 0);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4 - 32, 32);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4 + 32, 32);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4, 32);
}
if (recipe.getRequiredHeat() == HeatCondition.HEATED){
TFMGGuiTextures.VAT_HEATER.render(graphics, 55 - 10, 109);
}
drawSprites(machines, graphics);
renderHeated(recipe.getRequiredHeat(), graphics);
int pos = 55;
int width = ((recipe.getFluidIngredients().size()) * 21) / 2;
for (int i = 0; i < recipe.getFluidIngredients().size(); i++) {
@@ -137,5 +116,41 @@ public class ChemicalVatCategory extends CreateRecipeCategory<VatMachineRecipe>
}
private void renderHeated(HeatCondition heatCondition, GuiGraphics graphics) {
if (heatCondition == HeatCondition.HEATED)
TFMGGuiTextures.VAT_HEATER.render(graphics, 55 - 10, 109);
if (heatCondition == HeatCondition.SUPERHEATED)
TFMGGuiTextures.VAT_SUPERHEATER.render(graphics, 55 - 10, 109);
}
//Can be overridden with mixins for easily adding different stuff - Krystal
//Might consider a better way of doing this but idk.
private void drawVatTypes(List<String> allowedVatTypes, GuiGraphics graphics) {
if (allowedVatTypes.contains("firebrick_lined_vat") && allowedVatTypes.size() == 1) {
TFMGGuiTextures.FIREPROOF_BRICK_OVERLAY.render(graphics, 55 - 48, 32);
}
}
//Can be overridden with mixins for easily adding different stuff - Krystal
//Might consider a better way of doing this but idk.
private void drawSprites(List<String> machines, GuiGraphics graphics) {
if (machines.contains("tfmg:mixing")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12, 0);
TFMGGuiTextures.MIXER.render(graphics, 55 - 19, 32);
}
if (machines.contains("tfmg:electrode")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 - 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 + 32, 0);
TFMGGuiTextures.ELECTRODE.render(graphics, 55 - 3 - 32, 32);
TFMGGuiTextures.ELECTRODE.render(graphics, 55 - 3 + 32, 32);
}
if (machines.contains("tfmg:graphite_electrode")) {
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 - 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12 + 32, 0);
TFMGGuiTextures.VAT_MACHINE.render(graphics, 55 - 12, 0);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4 - 32, 32);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4 + 32, 32);
TFMGGuiTextures.GRAPHITE_ELECTRODE.render(graphics, 55 - 4, 32);
}
}
}

View File

@@ -48,14 +48,12 @@ public class WindingCategory extends CreateRecipeCategory<WindingRecipe> {
AllGuiTextures.JEI_ARROW.render(graphics, 85, 32);
AllGuiTextures.JEI_DOWN_ARROW.render(graphics, 43, 4);
PartialModel coil = null;
int coilColor = 0;
if (recipe.getIngredients().get(1).getItems()[0].getItem() instanceof SpoolItem) {
coil = ((SpoolItem)recipe.getIngredients().get(1).getItems()[0].getItem()).model;
coilColor = recipe.getIngredients().get(1).getItems()[0].getBarColor();
}
this.windingMachine.draw(graphics, 48, 27,coil,true);
this.windingMachine.draw(graphics, 48, 27,coilColor,true);
graphics.drawString(Minecraft.getInstance().font, recipe.getProcessingDuration() + " Turns", 86.0F, 9.0F, 4210752, false);
}
@@ -76,18 +74,16 @@ public class WindingCategory extends CreateRecipeCategory<WindingRecipe> {
PoseStack ms = graphics.pose();
PartialModel coil = null;
int coilColor = 0;
if (recipe.getRecipe().getIngredients().get(1).getItems()[0].getItem() instanceof SpoolItem) {
coil = ((SpoolItem)recipe.getRecipe().getIngredients().get(1).getItems()[0].getItem()).model;
coilColor = recipe.getRecipe().getIngredients().get(1).getItems()[0].getBarColor();
}
windingMachine.offset = index;
ms.pushPose();
ms.translate(0.0, 67, 0.0);
ms.scale(0.7F, 0.7F, 0.7F);
this.windingMachine.draw(graphics, this.getWidth() / 2, 0,coil,false);
this.windingMachine.draw(graphics, this.getWidth() / 2, 0,coilColor,false);
ms.popPose();

View File

@@ -17,7 +17,7 @@ public class WindingMachine extends AnimatedKinetics {
public WindingMachine() {
}
public void draw(GuiGraphics graphics, int xOffset, int yOffset, PartialModel coil, boolean shadow) {
public void draw(GuiGraphics graphics, int xOffset, int yOffset, int coilColor, boolean shadow) {
PoseStack matrixStack = graphics.pose();
@@ -42,12 +42,13 @@ public class WindingMachine extends AnimatedKinetics {
.atLocal(-0.15, -0.4, -0.23)
.scale(scale)
.render(graphics);
if (coil != null)
blockElement(coil)
.rotateBlock(22.5, 22.5, 0)
.atLocal(-0.15, -0.4, -0.23)
.scale(scale)
.render(graphics);
blockElement(TFMGPartialModels.SPOOL_WIRE)
.rotateBlock(22.5, 22.5, 0)
.atLocal(-0.15, -0.4, -0.23)
.color(coilColor)
.scale(scale)
.render(graphics);
matrixStack.popPose();
}

View File

@@ -0,0 +1,59 @@
package com.drmangotea.tfmg.registry;
import com.drmangotea.tfmg.config.TFMGResistivity;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableType;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableTypeEntry;
import static com.drmangotea.tfmg.TFMG.REGISTRATE;
public class TFMGCableTypes {
public static final CableTypeEntry<CableType> empty = REGISTRATE.cableType("empty", CableType::new)
.properties((p) -> p.spool(TFMGItems.COPPER_SPOOL))
.register();
public static final CableTypeEntry<CableType> copper = REGISTRATE.cableType("copper", CableType::new)
.properties((p) -> p.color(0xD8735A).spool(TFMGItems.COPPER_SPOOL))
.transform(TFMGResistivity.setResistivity(0.00188f))
.register();
public static final CableTypeEntry<CableType> aluminum = REGISTRATE.cableType("aluminum", CableType::new)
.properties((p) -> p.color(0xEDEFEF).spool(TFMGItems.ALUMINUM_SPOOL))
.transform(TFMGResistivity.setResistivity(0.0027f))
.register();
public static final CableTypeEntry<CableType> constantan = REGISTRATE.cableType("constantan", CableType::new)
.properties((p) -> p.color(0xCFC2A8).spool(TFMGItems.CONSTANTAN_SPOOL))
.transform(TFMGResistivity.setResistivity(1f))
.register();
// Why is this a thing? I'll leave it her in case you do need it. - Krystal
//public static final CableTypeEntry<CableType> steelReinforcedAluminum = REGISTRATE.cableType("steel_reinforced_aluminum", CableType::new)
// .properties((p) -> p.color(0xB8A08D).spool(TFMGItems.COPPER_SPOOL))
// .transform(TFMGResistivity.setResistivity(0.0027f))
// .register();
public static void register() {
}
//static {
// register("empty", new CableType(new CableType.Properties(TFMG.asResource("empty"))));
// register("copper", 0.00188f, 0xD8735A, TFMGItems.COPPER_SPOOL);
// register("aluminum", 0.0027f, 0xEDEFEF, TFMGItems.ALUMINUM_SPOOL);
// register("constantan", 1f, 0xCFC2A8, TFMGItems.CONSTANTAN_SPOOL);
//}
//
//private static <T extends CableType> void register(String name, float resistivity, int color, ItemEntry<?> spool) {
// ResourceLocation key = TFMG.asResource(name);
// CableType cableType = new CableType(new CableType.Properties(key).color(color).spool(spool).resistivity(resistivity));
// register(name, cableType);
//}
//
//private static <T extends CableType> void register(String name, T type) {
// Registry.register(TFMGBuiltinRegistries.CABLE_TYPE, TFMG.asResource(name), type);
//}
//
//public static void init() {
//}
}

View File

@@ -0,0 +1,58 @@
package com.drmangotea.tfmg.registry;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.Electrode;
import com.drmangotea.tfmg.content.machinery.vat.electrode_holder.electrode.ElectrodeEntry;
import static com.drmangotea.tfmg.TFMG.REGISTRATE;
public class TFMGElectrodes {
public static final ElectrodeEntry<Electrode> none = REGISTRATE.electrode("none", Electrode::new)
.properties((p) -> p)
.register();
public static final ElectrodeEntry<Electrode> copper = REGISTRATE.electrode("copper", Electrode::new)
.properties((p) -> p
.resistance(100)
.item(TFMGItems.COPPER_ELECTRODE)
.operationId("tfmg:electrode")
)
.register();
public static final ElectrodeEntry<Electrode> zinc = REGISTRATE.electrode("zinc", Electrode::new)
.properties((p) -> p
.resistance(100)
.item(TFMGItems.ZINC_ELECTRODE)
.operationId("tfmg:electrode")
)
.register();
public static final ElectrodeEntry<Electrode> graphite = REGISTRATE.electrode("graphite", Electrode::new)
.properties((p) -> p
.resistance(300)
.item(TFMGItems.GRAPHITE_ELECTRODE)
.operationId("tfmg:graphite_electrode")
)
.register();
//static {
// register("none", new Electrode(new Electrode.Properties(TFMG.asResource("none"))));
// register("copper", 100, TFMGItems.COPPER_ELECTRODE, "tfmg:electrode");
// register("zinc", 100, TFMGItems.ZINC_ELECTRODE, "tfmg:electrode");
// register("graphite", 300, TFMGItems.GRAPHITE_ELECTRODE, "tfmg:graphite_electrode");
//}
//
//private static <T extends Electrode> void register(String name, int resistance, ItemEntry<?> item, String operationId) {
// ResourceLocation key = TFMG.asResource(name);
// Electrode electrode = new Electrode(new Electrode.Properties(key).resistance(resistance).item(item).operationId(operationId));
// register(name, electrode);
//}
//
//private static <T extends Electrode> void register(String name, T type) {
// Registry.register(TFMGBuiltinRegistries.ELECTRODE, TFMG.asResource(name), type);
//}
public static void register() {
}
}

View File

@@ -31,6 +31,7 @@ public enum TFMGGuiTextures implements ScreenElement {
GRAPHITE_ELECTRODE("chemical_vat", 176, 0, 8, 29),
FIREPROOF_BRICK_OVERLAY("chemical_vat", 0, 84, 96, 72),
VAT_HEATER("chemical_vat", 112, 44, 20, 14),
VAT_SUPERHEATER("chemical_vat", 112, 58, 20, 14)
;

View File

@@ -5,7 +5,7 @@ import com.drmangotea.tfmg.base.TFMGArmorMaterials;
import com.drmangotea.tfmg.base.TFMGTiers;
import com.drmangotea.tfmg.content.decoration.gearbox.SteelVerticalGearboxItem;
import com.drmangotea.tfmg.content.electricity.configuration_wrench.ElectriciansWrenchItem;
import com.drmangotea.tfmg.content.electricity.connection.cables.CableConnection;
import com.drmangotea.tfmg.content.electricity.connection.cable_type.CableTypeEntry;
import com.drmangotea.tfmg.content.electricity.debug.DebugCinderBlockItem;
import com.drmangotea.tfmg.content.electricity.measurement.MultimeterItem;
import com.drmangotea.tfmg.content.electricity.utilities.polarizer.MagnetItem;
@@ -37,8 +37,8 @@ import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.DataIngredient;
import com.tterrag.registrate.util.entry.ItemEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import dev.engine_room.flywheel.lib.model.baked.PartialModel;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Blocks;
@@ -188,14 +188,14 @@ public class TFMGItems {
ENGINE_CYLINDER = REGISTRATE.item("engine_cylinder", CylinderItem::new).register(),
TURBINE_BLADE = REGISTRATE.item("turbine_blade", CylinderItem::new).register();
public static final ItemEntry<SpoolItem>
EMPTY_SPOOL = spoolItem("empty", null, 0x000000, CableConnection.CableType.NONE)
.recipe((c, p) -> p.stonecutting(DataIngredient.items(TFMGBlocks.HARDENED_PLANKS.asItem()), RecipeCategory.BUILDING_BLOCKS, c::get, 1))
EMPTY_SPOOL = spoolItem("empty", 0x000000, TFMG.asResource("empty"))
.recipe((c, p) -> p.stonecutting(DataIngredient.items(TFMGBlocks.HARDENED_PLANKS.asItem()), RecipeCategory.BUILDING_BLOCKS, c, 1))
.register(),
COPPER_SPOOL = spoolItem("copper", TFMGPartialModels.COPPER_SPOOL, 0xD8735A, CableConnection.CableType.COPPER)
COPPER_SPOOL = spoolItem("copper", 0xD8735A, TFMG.asResource("copper"))
.register(),
ALUMINUM_SPOOL = spoolItem("aluminum", TFMGPartialModels.ALUMINUM_SPOOL, 0xEDEFEF, CableConnection.CableType.ALUMINUM)
ALUMINUM_SPOOL = spoolItem("aluminum", 0xEDEFEF, TFMG.asResource("aluminum"))
.register(),
CONSTANTAN_SPOOL = spoolItem("constantan", TFMGPartialModels.CONSTANTAN_SPOOL, 0xCFC2A8, CableConnection.CableType.CONSTANTAN)
CONSTANTAN_SPOOL = spoolItem("constantan", 0xCFC2A8, TFMG.asResource("constantan"))
.register();
public static final ItemEntry<ElectromagneticCoilItem> ELECTROMAGNETIC_COIL =
@@ -432,8 +432,8 @@ public class TFMGItems {
return map;
}
public static ItemBuilder<SpoolItem, CreateRegistrate> spoolItem(String name, PartialModel model, int barColor, CableConnection.CableType type) {
return REGISTRATE.item(name + "_spool", p -> new SpoolItem(p, model, barColor, type))
public static ItemBuilder<SpoolItem, CreateRegistrate> spoolItem(String name, int barColor, ResourceLocation type) {
return REGISTRATE.item(name + "_spool", p -> new SpoolItem(p, barColor, type))
.tag(TFMGTags.TFMGItemTags.SPOOLS.tag)
.properties(p -> p.stacksTo(1));

View File

@@ -75,6 +75,7 @@ public class TFMGPartialModels {
SHAFTLESS_LARGE_ALUMINUM_COGHWEEL = block("large_aluminum_cogwheel_shaftless"),
SHAFTLESS_LARGE_STEEL_COGHWEEL = block("large_steel_cogwheel_shaftless"),
SPOOL = block("winding_machine/spool"),
SPOOL_WIRE = block("winding_machine/spool_wire"),
COPPER_SPOOL = block("winding_machine/copper_spool"),
ALUMINUM_SPOOL = block("winding_machine/aluminum_spool"),
CONSTANTAN_SPOOL = block("winding_machine/constantan_spool"),

View File

@@ -256,9 +256,9 @@ public class TFMGTags {
public static void init() {
TFMGBlockTags.init();
// TFMGItemTags.init();
// TFMGItemTags.register();
TFMGFluidTags.init();
//TFMGEntityTags.init();
//TFMGRecipeSerializerTags.init();
//TFMGEntityTags.register();
//TFMGRecipeSerializerTags.register();
}
}

View File

@@ -0,0 +1,20 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "tfmg:block/spool_wire",
"particle": "tfmg:block/spool_wire"
},
"elements": [
{
"from": [4, 6, 6],
"to": [11, 10, 10],
"rotation": {"angle": 0, "axis": "y", "origin": [4, 7, 7]},
"faces": {
"north": {"uv": [0, 0, 4, 7], "rotation": 90, "texture": "#0"},
"south": {"uv": [0, 0, 4, 7], "rotation": 90, "texture": "#0"},
"up": {"uv": [0, 0, 4, 7], "rotation": 90, "texture": "#0"},
"down": {"uv": [0, 0, 4, 7], "rotation": 90, "texture": "#0"}
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 193 B

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 B

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -7,10 +7,9 @@
"mixins": [
"FluidPipeBlockMixin",
"FluidPropagatorMixin",
"FluidTankBlockEntityMixin",
"GoggleOverlayRendererMixin",
"PipeAttachmentModelMixin",
"FluidTankBlockEntityMixin",
"accessor.FluidTankBlockEntityAccessor",
"accessor.TankSegmentAccessor"
],