diff --git a/.gitignore b/.gitignore index c2fb66e1e33..423e503213e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ thumbs.db *.war *.ear *.txt +*.ase # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/src/main/java/gregtech/api/GregTechAPI.java b/src/main/java/gregtech/api/GregTechAPI.java index 4e3bc8bc69c..79a5716ea7b 100644 --- a/src/main/java/gregtech/api/GregTechAPI.java +++ b/src/main/java/gregtech/api/GregTechAPI.java @@ -3,6 +3,7 @@ import gregtech.api.advancement.IAdvancementManager; import gregtech.api.block.ICleanroomFilter; import gregtech.api.block.IHeatingCoilBlockStats; +import gregtech.api.block.coil.CoilManager; import gregtech.api.command.ICommandManager; import gregtech.api.cover.CoverDefinition; import gregtech.api.event.HighTierEvent; @@ -55,6 +56,8 @@ public class GregTechAPI { public static MarkerMaterialRegistry markerMaterialRegistry; /** Will be available at the Pre-Initialization stage */ public static MTEManager mteManager; + /** Will be available at the Pre-Initialization stage */ + public static CoilManager coilManager; /** GT's data migrations API */ public static final MigrationAPI MIGRATIONS = new MigrationAPI(); public static final RecipePropertyRegistry RECIPE_PROPERTIES = new RecipePropertyRegistry(); diff --git a/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java b/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java index 0e2b7427591..4bbd66e90ed 100644 --- a/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java +++ b/src/main/java/gregtech/api/block/IHeatingCoilBlockStats.java @@ -2,10 +2,13 @@ import gregtech.api.recipes.properties.impl.TemperatureProperty; import gregtech.api.unification.material.Material; +import gregtech.client.model.ActiveVariantBlockBakedModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.BooleanSupplier; + /** * Implement this interface on the Block Enum for your Heating Coil block * @@ -52,4 +55,12 @@ public interface IHeatingCoilBlockStats { */ @Nullable Material getMaterial(); + + default int getColor() { + return getMaterial() == null ? 0xFFFFFFFF : getMaterial().getMaterialRGB(); + } + + default ActiveVariantBlockBakedModel createModel(BooleanSupplier bloomConfig) { + return null; + } } diff --git a/src/main/java/gregtech/api/block/VariantActiveBlock.java b/src/main/java/gregtech/api/block/VariantActiveBlock.java index ba4ac712a03..becc8fb40ce 100644 --- a/src/main/java/gregtech/api/block/VariantActiveBlock.java +++ b/src/main/java/gregtech/api/block/VariantActiveBlock.java @@ -8,7 +8,6 @@ import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; -import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -25,6 +24,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; @@ -32,14 +32,12 @@ import org.jetbrains.annotations.NotNull; import team.chisel.ctm.client.state.CTMExtendedState; -import java.util.EnumMap; -import java.util.Map; import java.util.Objects; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.stream.Collectors; -public class VariantActiveBlock & IStringSerializable> extends VariantBlock { +public abstract class VariantActiveBlock> extends VariantBlock { private static final Int2ObjectMap> ACTIVE_BLOCKS = new Int2ObjectOpenHashMap<>(); private static final ReadWriteLock ACTIVE_BLOCKS_LOCK = new ReentrantReadWriteLock(); @@ -92,12 +90,17 @@ protected boolean canSilkHarvest() { @NotNull @Override public BlockRenderLayer getRenderLayer() { + return getRenderLayer(VALUES[0]); + } + + @NotNull + public BlockRenderLayer getRenderLayer(T value) { return BlockRenderLayer.CUTOUT; } @Override public boolean canRenderInLayer(@NotNull IBlockState state, @NotNull BlockRenderLayer layer) { - return layer == getRenderLayer() || + return layer == getRenderLayer(getState(state)) || layer == BloomEffectUtil.getEffectiveBloomLayer(isBloomEnabled(getState(state))); } @@ -113,16 +116,15 @@ public int getMetaFromState(IBlockState state) { if (state.getValue(ACTIVE_DEPRECATED)) { meta += 8; } - return meta + state.getValue(VARIANT).ordinal(); + return meta + state.getValue(VARIANT); } @NotNull @Override protected BlockStateContainer createBlockState() { - Class enumClass = getActualTypeParameter(getClass(), VariantActiveBlock.class); - this.VARIANT = PropertyEnum.create("variant", enumClass); - this.VALUES = enumClass.getEnumConstants(); - return new ExtendedBlockState(this, new IProperty[] { VARIANT, ACTIVE_DEPRECATED }, + super.createBlockState(); + return new ExtendedBlockState(this, + new IProperty[] { VARIANT, ACTIVE_DEPRECATED }, new IUnlistedProperty[] { ACTIVE }); } @@ -144,17 +146,18 @@ public IExtendedBlockState getExtendedState(@NotNull IBlockState state, @NotNull @SideOnly(Side.CLIENT) public void onModelRegister() { - Map models = new EnumMap<>(VALUES[0].getDeclaringClass()); + Int2ObjectMap models = new Int2ObjectArrayMap<>(); for (T value : VALUES) { + int index = VARIANT.getIndexOf(value); ModelResourceLocation inactiveModel = model(false, value); ModelResourceLocation activeModel = model(true, value); ActiveVariantBlockBakedModel model = new ActiveVariantBlockBakedModel(inactiveModel, activeModel, () -> isBloomEnabled(value)); - models.put(value, model.getModelLocation()); + models.put(index, model.getModelLocation()); Item item = Item.getItemFromBlock(this); - ModelLoader.setCustomModelResourceLocation(item, value.ordinal(), inactiveModel); + ModelLoader.setCustomModelResourceLocation(item, index, inactiveModel); ModelLoader.registerItemVariants(item, activeModel); } ModelLoader.setCustomStateMapper(this, @@ -166,11 +169,11 @@ public void onModelRegister() { private ModelResourceLocation model(boolean active, T variant) { return new ModelResourceLocation( Objects.requireNonNull(getRegistryName()), - "active=" + active + ",variant=" + VARIANT.getName(variant)); + "active=" + active + ",variant=" + variant.getName()); } @SideOnly(Side.CLIENT) - protected boolean isBloomEnabled(T value) { + public boolean isBloomEnabled(T value) { return ConfigHolder.client.machinesEmissiveTextures; } } diff --git a/src/main/java/gregtech/api/block/VariantBlock.java b/src/main/java/gregtech/api/block/VariantBlock.java index f50823b8cfc..dbd418ee1c5 100644 --- a/src/main/java/gregtech/api/block/VariantBlock.java +++ b/src/main/java/gregtech/api/block/VariantBlock.java @@ -5,7 +5,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.properties.PropertyHelper; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; @@ -18,31 +18,42 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import com.google.common.base.Optional; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2IntArrayMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Array; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; -public class VariantBlock & IStringSerializable> extends Block { +public abstract class VariantBlock> extends Block { - protected PropertyEnum VARIANT; + protected PropertyIntMap VARIANT; protected T[] VALUES; public VariantBlock(@NotNull Material materialIn) { super(materialIn); - if (VALUES.length > 0 && VALUES[0] instanceof IStateHarvestLevel) { + updateHarvestLevels(); + setCreativeTab(GTCreativeTabs.TAB_GREGTECH); + setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, 0)); + } + + protected void updateHarvestLevels() { + if (VALUES.length > 0 && VALUES[0] instanceof IStateHarvestLevel stateHarvestLevel) { for (T t : VALUES) { - IStateHarvestLevel stateHarvestLevel = (IStateHarvestLevel) t; IBlockState state = getState(t); - setHarvestLevel(stateHarvestLevel.getHarvestTool(state), stateHarvestLevel.getHarvestLevel(state), - state); + setHarvestLevel(stateHarvestLevel.getHarvestTool(state), + stateHarvestLevel.getHarvestLevel(state), state); } } - setCreativeTab(GTCreativeTabs.TAB_GREGTECH); - setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, VALUES[0])); } @Override @@ -53,11 +64,11 @@ public void getSubBlocks(@NotNull CreativeTabs tab, @NotNull NonNullList enumClass = getActualTypeParameter(getClass(), VariantBlock.class); - this.VARIANT = PropertyEnum.create("variant", enumClass); - this.VALUES = enumClass.getEnumConstants(); + this.VARIANT = new PropertyIntMap<>("variant", computeVariants()); + this.VALUES = VARIANT.getValues(); return new BlockStateContainer(this, VARIANT); } + @NotNull + protected Collection computeVariants() { + Class enumClass = null; + for (Class innerClazz : getClass().getClasses()) { + var enums = innerClazz.getEnumConstants(); + if (enums != null && enums[0] instanceof IStringSerializable) { + // noinspection unchecked + enumClass = (Class) innerClazz; + break; + } + } + if (enumClass == null) { + enumClass = getActualTypeParameter(getClass(), VariantBlock.class);; + } + return Arrays.asList(enumClass.getEnumConstants()); + } + @Override @SideOnly(Side.CLIENT) public void addInformation(@NotNull ItemStack stack, @Nullable World player, @NotNull List tooltip, @@ -104,12 +131,12 @@ public int damageDropped(@NotNull IBlockState state) { @Override @SuppressWarnings("deprecation") public IBlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(VARIANT, VALUES[meta % VALUES.length]); + return getDefaultState().withProperty(VARIANT, meta % VALUES.length); } @Override public int getMetaFromState(IBlockState state) { - return state.getValue(VARIANT).ordinal(); + return state.getValue(VARIANT); } // magic is here @@ -117,13 +144,87 @@ public int getMetaFromState(IBlockState state) { protected static Class getActualTypeParameter(Class thisClass, Class declaringClass) { Type type = thisClass.getGenericSuperclass(); - while (!(type instanceof ParameterizedType) || ((ParameterizedType) type).getRawType() != declaringClass) { + while (!(type instanceof ParameterizedType pType) || pType.getRawType() != declaringClass) { if (type instanceof ParameterizedType) { type = ((Class) ((ParameterizedType) type).getRawType()).getGenericSuperclass(); } else { type = ((Class) type).getGenericSuperclass(); } } - return (Class) ((ParameterizedType) type).getActualTypeArguments()[0]; + var arg = pType.getActualTypeArguments()[0]; + if (!(arg instanceof Class)) { + throw new ClassCastException(String.format("cannot cast %s to a class!", arg)); + } + return (Class) pType.getActualTypeArguments()[0]; + } + + protected static class PropertyIntMap & IStringSerializable> + extends PropertyHelper { + + private final Int2ObjectMap intMap; + private final Object2IntMap reverse; + private final O[] allowedObjects; + + @SuppressWarnings("unchecked") + protected PropertyIntMap(String name, Collection values) { + super(name, Integer.class); + if (values.isEmpty()) throw new IllegalArgumentException("values are empty!"); + if (values.size() > 16) throw new IllegalArgumentException("values cannot be greater than 16!"); + + this.intMap = new Int2ObjectArrayMap<>(values.size()); + this.reverse = new Object2IntArrayMap<>(values.size()); + + O first = values.iterator().next(); + this.allowedObjects = (O[]) Array.newInstance(first.getClass(), values.size()); + + for (O value : values) { + int size = this.intMap.size(); + this.allowedObjects[size] = value; + this.intMap.put(size, value); + this.reverse.put(value, size); + } + } + + @Override + public @NotNull Collection getAllowedValues() { + return this.intMap.keySet(); + } + + public @NotNull O[] getValues() { + return this.allowedObjects; + } + + @Override + @Deprecated + public @NotNull String getName(@NotNull Integer value) { + return getNameByInt(value); + } + + public @NotNull String getNameByInt(int value) { + return getValue(value).getName(); + } + + @Override + public @NotNull Optional parseValue(@NotNull String value) { + for (O object : reverse.keySet()) { + if (object.getName().equals(value)) { + return Optional.of(getIndexOf(object)); + } + } + return Optional.absent(); + } + + @Override + public int hashCode() { + return 31 * super.hashCode() + this.allowedObjects.hashCode(); + } + + public int getIndexOf(O value) { + return this.reverse.getInt(value); + } + + public O getValue(int index) { + return this.intMap.get(index); + } } } diff --git a/src/main/java/gregtech/api/block/VariantItemBlock.java b/src/main/java/gregtech/api/block/VariantItemBlock.java index 62bf5a561a2..47bfa90a68e 100644 --- a/src/main/java/gregtech/api/block/VariantItemBlock.java +++ b/src/main/java/gregtech/api/block/VariantItemBlock.java @@ -7,7 +7,8 @@ import org.jetbrains.annotations.NotNull; -public class VariantItemBlock & IStringSerializable, T extends VariantBlock> extends ItemBlock { +public class VariantItemBlock, T extends VariantBlock> + extends ItemBlock { private final T genericBlock; diff --git a/src/main/java/gregtech/api/block/coil/BuilderFactory.java b/src/main/java/gregtech/api/block/coil/BuilderFactory.java new file mode 100644 index 00000000000..e697382375d --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/BuilderFactory.java @@ -0,0 +1,6 @@ +package gregtech.api.block.coil; + +public interface BuilderFactory { + + CoilBlockBuilder makeBuilder(int id, String name); +} diff --git a/src/main/java/gregtech/api/block/coil/CoilBlockBuilder.java b/src/main/java/gregtech/api/block/coil/CoilBlockBuilder.java new file mode 100644 index 00000000000..6fb787db6df --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CoilBlockBuilder.java @@ -0,0 +1,43 @@ +package gregtech.api.block.coil; + +import gregtech.api.GregTechAPI; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.UnaryOperator; + +public class CoilBlockBuilder { + + public static final int ACTIVE_META_LIMIT = 8; + + private final List stats = new ArrayList<>(ACTIVE_META_LIMIT); + private final String modid; + private final Consumer onBuild; + + CoilBlockBuilder(String modid, Consumer onBuild) { + this.modid = modid; + this.onBuild = onBuild; + } + + public CoilBlockBuilder addCoilType(UnaryOperator builder) { + if (stats.size() >= ACTIVE_META_LIMIT) { + throw new IllegalStateException("Cannot exceed active meta limit!"); + } + stats.add(builder.apply(new CoilStatBuilder(this.modid)).build()); + return this; + } + + public CustomCoilBlock build() { + if (this.stats.isEmpty()) + throw new IllegalArgumentException("Variants is empty!"); + var block = new CustomCoilBlock(this.stats); + for (var stat : this.stats) { + GregTechAPI.HEATING_COILS.put(block.getState(stat), stat); + } + + this.onBuild.accept(block); + + return block; + } +} diff --git a/src/main/java/gregtech/api/block/coil/CoilManager.java b/src/main/java/gregtech/api/block/coil/CoilManager.java new file mode 100644 index 00000000000..a770a8b81ad --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CoilManager.java @@ -0,0 +1,62 @@ +package gregtech.api.block.coil; + +import gregtech.api.GTValues; + +import net.minecraftforge.fml.common.eventhandler.Event; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; + +import java.util.Collection; + +public class CoilManager { + + private static CoilManager instance; + private static int networkId; + private static BuilderFactory internal; + + private final Object2ObjectMap registryMap = new Object2ObjectOpenHashMap<>(); + private final Int2ObjectMap networkMap = new Int2ObjectOpenHashMap<>(); + + public static CoilManager getInstance() { + if (instance == null) { + instance = new CoilManager(); + internal = instance.createRegistry(GTValues.MODID); + } + return instance; + } + + private CoilManager() {} + + public BuilderFactory getRegistry(String modid) { + CoilRegistry coilRegistry = registryMap.get(modid); + if (coilRegistry == null) { + throw new IllegalArgumentException("No MTE registry exists for modid \"" + modid + "\""); + } + return coilRegistry; + } + + public BuilderFactory createRegistry(String modid) { + if (registryMap.containsKey(modid)) { + throw new IllegalArgumentException("MTE Registry for modid \"" + modid + "\" is already registered"); + } + CoilRegistry registry = new CoilRegistry(modid, ++networkId); + registryMap.put(modid, registry); + networkMap.put(networkId, registry); + return registry; + } + + public BuilderFactory getRegistry(int networkId) { + CoilRegistry coilRegistry = networkMap.get(networkId); + return coilRegistry == null ? internal : coilRegistry; + } + + public Collection getRegistries() { + return registryMap.values(); + } + + // event class + public static class CoilRegistryEvent extends Event {} +} diff --git a/src/main/java/gregtech/api/block/coil/CoilRegistry.java b/src/main/java/gregtech/api/block/coil/CoilRegistry.java new file mode 100644 index 00000000000..30ff7efcf30 --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CoilRegistry.java @@ -0,0 +1,42 @@ +package gregtech.api.block.coil; + +import gregtech.api.util.GTControlledRegistry; + +import net.minecraft.util.ResourceLocation; + +import org.jetbrains.annotations.NotNull; + +public class CoilRegistry extends GTControlledRegistry implements BuilderFactory { + + private final String modid; + private final int networkId; + + public CoilRegistry(String modId, int networkId) { + super(Short.MAX_VALUE); + this.modid = modId; + this.networkId = networkId; + } + + @Override + public CoilBlockBuilder makeBuilder(int id, String name) { + ResourceLocation loc = new ResourceLocation(this.modid, name); + return new CoilBlockBuilder(this.modid, b -> register(id, loc, b)); + } + + @Override + public void register(int id, @NotNull ResourceLocation key, @NotNull CustomCoilBlock value) { + if (!canRegister(key.getNamespace())) { + throw new IllegalArgumentException("Cannot register CoilBlock to another mod's registry"); + } + value.setRegistryName(key); + super.register(id, key, value); + } + + /** + * @param modid the modid to test + * @return if the mod is allowed to be registered to this registry + */ + private boolean canRegister(@NotNull String modid) { + return this.modid.equals(modid); + } +} diff --git a/src/main/java/gregtech/api/block/coil/CoilStatBuilder.java b/src/main/java/gregtech/api/block/coil/CoilStatBuilder.java new file mode 100644 index 00000000000..fcd69c1fba3 --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CoilStatBuilder.java @@ -0,0 +1,167 @@ +package gregtech.api.block.coil; + +import gregtech.api.GTValues; +import gregtech.api.recipes.properties.impl.TemperatureProperty; +import gregtech.api.unification.material.Material; +import gregtech.api.unification.material.Materials; +import gregtech.api.util.GTUtility; +import gregtech.api.util.function.QuadConsumer; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import java.util.List; + +public class CoilStatBuilder { + + private final String modid; + + private String name; + + // electric blast furnace properties + private int coilTemperature = -1; + + // multi smelter properties + private int level = -1; + private int energyDiscount = 0; + + // voltage tier + private int tier = GTValues.ULV; + + private Material material = Materials.Iron; + private ResourceLocation textureLocation; + private boolean isGeneric; + private QuadConsumer, Boolean> additionalTooltips; + + CoilStatBuilder(String modid) { + this.modid = modid; + } + + /** + * @param material Material that this coil should be based off of. Used for + * {@link TemperatureProperty#registerCoilType(int, Material, String)}. + * @return this + */ + public CoilStatBuilder material(Material material) { + return material(material, material.getName()); + } + + /** + * @param material Material that this coil should be based off of. Used for + * {@link TemperatureProperty#registerCoilType(int, Material, String)}. + * @param name Name of the variant to look for in the model json (typically the name of the material). + * @return this + */ + public CoilStatBuilder material(Material material, String name) { + this.material = material; + this.name = name; + return this; + } + + public CoilStatBuilder coilTemp(int coilTemperature) { + this.coilTemperature = coilTemperature; + return this; + } + + /** + * @param tier The voltage tier of this coil variant, used for the energy discount in the cracking unit and pyrolyse + * oven + * @return this + */ + public CoilStatBuilder tier(int tier) { + this.tier = Math.max(0, tier); + return this; + } + + /** + * @param level This is used for the amount of parallel recipes in the multi smelter. Multiplied by 32. + * @param energyDiscount This is used for the energy discount in the multi smelter + * @return this + */ + public CoilStatBuilder multiSmelter(int level, int energyDiscount) { + this.level = level; + this.energyDiscount = energyDiscount; + return this; + } + + /** + * @param location Location of the block model json + * @return this + */ + public CoilStatBuilder texture(String location) { + this.textureLocation = new ResourceLocation(this.modid, location); + return this; + } + + /** + * @param location Location of the block model json + * @param generic If true, the coil will use a grayscale texture to tint based off of the materials color. + * Otherwise, it will look for a texture specifically for this variant. + * @return this + */ + public CoilStatBuilder texture(String location, boolean generic) { + return texture(location).generic(generic); + } + + /** + * @param generic If true, the coil will use a grayscale texture to tint based off of the materials color. + * Otherwise, it will look for a texture specifically for this variant. + * @return this + */ + public CoilStatBuilder generic(boolean generic) { + this.isGeneric = generic; + return this; + } + + /** + * Marks this variant as generic, it will look for a grayscale texture and tint based on material color. + * + * @return this + */ + public CoilStatBuilder generic() { + return generic(true); + } + + /** + * @param additionalTooltips Used for adding additional tooltips for this variant + * @return this + */ + public CoilStatBuilder tooltip(QuadConsumer, Boolean> additionalTooltips) { + this.additionalTooltips = additionalTooltips; + return this; + } + + CustomCoilStats build() { + if (this.textureLocation == null) { + this.textureLocation = GTUtility.gregtechId("wire_coil"); + } + + String variant; + ModelResourceLocation inactive; + ModelResourceLocation active; + if (this.isGeneric) { + variant = "%s"; + inactive = new ModelResourceLocation(this.textureLocation, String.format(variant, "normal")); + active = new ModelResourceLocation(this.textureLocation, String.format(variant, "active")); + } else { + variant = "active=%s,variant=%s"; + inactive = new ModelResourceLocation(this.textureLocation, + String.format(variant, false, this.name)); + active = new ModelResourceLocation(this.textureLocation, + String.format(variant, true, this.name)); + } + return new CustomCoilStats( + this.name, + this.coilTemperature, + this.level, + this.energyDiscount, + this.tier, + this.material, + active, + inactive, + this.isGeneric, + this.additionalTooltips); + } +} diff --git a/src/main/java/gregtech/api/block/coil/CustomCoilBlock.java b/src/main/java/gregtech/api/block/coil/CustomCoilBlock.java new file mode 100644 index 00000000000..02f5f8296f5 --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CustomCoilBlock.java @@ -0,0 +1,155 @@ +package gregtech.api.block.coil; + +import gregtech.api.GTValues; +import gregtech.api.block.VariantActiveBlock; +import gregtech.api.block.VariantItemBlock; +import gregtech.api.items.toolitem.ToolClasses; +import gregtech.client.utils.TooltipHelper; +import gregtech.common.metatileentities.multi.electric.MetaTileEntityMultiSmelter; + +import net.minecraft.block.SoundType; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.color.BlockColors; +import net.minecraft.client.renderer.color.ItemColors; +import net.minecraft.client.resources.I18n; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.EntityLiving; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; + +public final class CustomCoilBlock extends VariantActiveBlock { + + private static final AtomicReference> activeSublist = new AtomicReference<>(); + + // called in constructor to handle super constructor nonsense + private static net.minecraft.block.material.Material setActiveList(List sublist) { + activeSublist.set(sublist); + return net.minecraft.block.material.Material.IRON; + } + + private static void clearActiveList() { + activeSublist.set(null); + } + + public CustomCoilBlock(List stats) { + super(setActiveList(stats)); + setTranslationKey("wire_coil"); + setHardness(5.0f); + setResistance(10.0f); + setSoundType(SoundType.METAL); + setHarvestLevel(ToolClasses.WRENCH, 2); + setDefaultState(getState(VALUES[0])); + } + + @NotNull + @Override + public BlockRenderLayer getRenderLayer(CustomCoilStats value) { + return value.isGeneric() ? BlockRenderLayer.CUTOUT : BlockRenderLayer.SOLID; + } + + @Override + protected @NotNull Collection computeVariants() { + List stats = activeSublist.get(); + clearActiveList(); + return stats; + } + + @Override + public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, + @NotNull EntityLiving.SpawnPlacementType type) { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn, @NotNull List lines, + @NotNull ITooltipFlag tooltipFlag) { + super.addInformation(itemStack, worldIn, lines, tooltipFlag); + + // noinspection unchecked + var itemBlock = (VariantItemBlock) itemStack.getItem(); + IBlockState stackState = itemBlock.getBlockState(itemStack); + CustomCoilStats coilType = getState(stackState); + + lines.add(I18n.format("tile.wire_coil.tooltip_heat", coilType.getCoilTemperature())); + + if (TooltipHelper.isShiftDown()) { + int coilTier = coilType.getTier(); + lines.add(I18n.format("tile.wire_coil.tooltip_smelter")); + lines.add(I18n.format("tile.wire_coil.tooltip_parallel_smelter", coilType.getLevel() * 32)); + int EUt = MetaTileEntityMultiSmelter.getEUtForParallel( + MetaTileEntityMultiSmelter.getMaxParallel(coilType.getLevel()), coilType.getEnergyDiscount()); + lines.add(I18n.format("tile.wire_coil.tooltip_energy_smelter", EUt)); + lines.add(I18n.format("tile.wire_coil.tooltip_pyro")); + lines.add( + I18n.format("tile.wire_coil.tooltip_speed_pyro", coilTier == GTValues.LV ? 75 : 50 * coilTier)); + lines.add(I18n.format("tile.wire_coil.tooltip_cracking")); + lines.add(I18n.format("tile.wire_coil.tooltip_energy_cracking", 100 - 10 * (coilTier - 1))); + } else { + lines.add(I18n.format("tile.wire_coil.tooltip_extended_info")); + } + + coilType.addInformation(itemStack, worldIn, lines, tooltipFlag); + } + + @SideOnly(Side.CLIENT) + public void onModelRegister() { + Item item = Item.getItemFromBlock(this); + Int2ObjectMap modelMap = new Int2ObjectArrayMap<>(); + + for (CustomCoilStats value : VALUES) { + var model = value.createModel(() -> isBloomEnabled(value)); + modelMap.put(VARIANT.getIndexOf(value), model.getModelLocation()); + + // inactive + ModelLoader.setCustomModelResourceLocation(item, VARIANT.getIndexOf(value), + model.getInactiveModelLocation()); + + // active + ModelLoader.registerItemVariants(item, model.getActiveModelLocation()); + } + + ModelLoader.setCustomStateMapper(this, b -> { + Map map = new HashMap<>(); + for (IBlockState s : b.getBlockState().getValidStates()) { + map.put(s, modelMap.get(s.getValue(VARIANT))); + } + return map; + }); + } + + public void onColorRegister(BlockColors blockColors, ItemColors itemColors) { + Int2IntMap colorMap = new Int2IntArrayMap(); + Item item = Item.getItemFromBlock(this); + + for (CustomCoilStats value : VALUES) { + colorMap.put(VARIANT.getIndexOf(value), value.getColor()); + } + + blockColors.registerBlockColorHandler((state, worldIn, pos, tintIndex) -> colorMap.get(state.getValue(VARIANT)), + this); + + itemColors.registerItemColorHandler((stack, tintIndex) -> colorMap.get(item.getMetadata(stack)), item); + } +} diff --git a/src/main/java/gregtech/api/block/coil/CustomCoilStats.java b/src/main/java/gregtech/api/block/coil/CustomCoilStats.java new file mode 100644 index 00000000000..9634dac83f0 --- /dev/null +++ b/src/main/java/gregtech/api/block/coil/CustomCoilStats.java @@ -0,0 +1,117 @@ +package gregtech.api.block.coil; + +import gregtech.api.block.IHeatingCoilBlockStats; +import gregtech.api.unification.material.Material; +import gregtech.api.util.function.QuadConsumer; +import gregtech.client.model.ActiveVariantBlockBakedModel; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.BooleanSupplier; + +public final class CustomCoilStats implements IHeatingCoilBlockStats, Comparable, + IStringSerializable { + + private final String name; + + // electric blast furnace properties + private final int coilTemperature; + + // multi smelter properties + private final int level; + private final int energyDiscount; + + // voltage tier + private final int tier; + + private final Material material; + private final ModelResourceLocation active; + private final ModelResourceLocation inactive; + private final boolean isGeneric; + private final QuadConsumer, Boolean> additionalTooltips; + + CustomCoilStats(String name, + int coilTemperature, + int level, + int energyDiscount, + int tier, + Material material, + ModelResourceLocation active, + ModelResourceLocation inactive, + boolean isGeneric, + QuadConsumer, Boolean> additionalTooltips) { + this.name = name; + this.coilTemperature = coilTemperature; + this.level = level; + this.energyDiscount = energyDiscount; + this.tier = tier; + this.material = material; + this.active = active; + this.inactive = inactive; + this.isGeneric = isGeneric; + this.additionalTooltips = additionalTooltips; + } + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public int getCoilTemperature() { + return coilTemperature; + } + + @Override + public int getLevel() { + return level; + } + + @Override + public int getEnergyDiscount() { + return energyDiscount; + } + + @Override + public int getTier() { + return tier; + } + + @Override + public @Nullable Material getMaterial() { + return material; + } + + @Override + public ActiveVariantBlockBakedModel createModel(BooleanSupplier bloomConfig) { + return new ActiveVariantBlockBakedModel(inactive, active, bloomConfig); + } + + @Override + public int compareTo(@NotNull CustomCoilStats o) { + // todo add more comparisons? + return Integer.compare(o.getTier(), this.getTier()); + } + + @SideOnly(Side.CLIENT) + public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn, @NotNull List lines, + @NotNull ITooltipFlag tooltipFlag) { + if (this.additionalTooltips != null) { + this.additionalTooltips.accept(itemStack, worldIn, lines, tooltipFlag.isAdvanced()); + } + } + + public boolean isGeneric() { + return isGeneric; + } +} diff --git a/src/main/java/gregtech/api/util/function/QuadConsumer.java b/src/main/java/gregtech/api/util/function/QuadConsumer.java new file mode 100644 index 00000000000..cbe51d8c5db --- /dev/null +++ b/src/main/java/gregtech/api/util/function/QuadConsumer.java @@ -0,0 +1,7 @@ +package gregtech.api.util.function; + +@FunctionalInterface +public interface QuadConsumer { + + void accept(P p, S s, T t, Q q); +} diff --git a/src/main/java/gregtech/client/model/ActiveVariantBlockBakedModel.java b/src/main/java/gregtech/client/model/ActiveVariantBlockBakedModel.java index 8a17399f9a0..ba6aa69be46 100644 --- a/src/main/java/gregtech/client/model/ActiveVariantBlockBakedModel.java +++ b/src/main/java/gregtech/client/model/ActiveVariantBlockBakedModel.java @@ -63,6 +63,14 @@ public ModelResourceLocation getModelLocation() { return modelLocation; } + public ModelResourceLocation getActiveModelLocation() { + return activeModelLocation; + } + + public ModelResourceLocation getInactiveModelLocation() { + return inactiveModelLocation; + } + protected boolean getBloomConfig() { return bloomConfig == null || bloomConfig.getAsBoolean(); } diff --git a/src/main/java/gregtech/common/CommonProxy.java b/src/main/java/gregtech/common/CommonProxy.java index 59055bb74e1..1bc41e8f630 100644 --- a/src/main/java/gregtech/common/CommonProxy.java +++ b/src/main/java/gregtech/common/CommonProxy.java @@ -3,6 +3,8 @@ import gregtech.api.GTValues; import gregtech.api.GregTechAPI; import gregtech.api.block.VariantItemBlock; +import gregtech.api.block.coil.CoilRegistry; +import gregtech.api.block.coil.CustomCoilBlock; import gregtech.api.block.machines.MachineItemBlock; import gregtech.api.items.metaitem.MetaItem; import gregtech.api.items.toolitem.IGTTool; @@ -91,6 +93,12 @@ public static void registerBlocks(RegistryEvent.Register event) { registry.register(r.getBlock()); } + for (CoilRegistry r : GregTechAPI.coilManager.getRegistries()) { + for (CustomCoilBlock block : r) { + registry.register(block); + } + } + StoneType.init(); for (MaterialRegistry materialRegistry : GregTechAPI.materialManager.getRegistries()) { @@ -263,6 +271,13 @@ public static void registerItems(RegistryEvent.Register event) { registry.register(createItemBlock(STEAM_CASING, VariantItemBlock::new)); registry.register(createItemBlock(MULTIBLOCK_CASING, VariantItemBlock::new)); registry.register(createItemBlock(TRANSPARENT_CASING, VariantItemBlock::new)); + + for (CoilRegistry coilRegistry : GregTechAPI.coilManager.getRegistries()) { + for (CustomCoilBlock block : coilRegistry) { + registry.register(createItemBlock(block, VariantItemBlock::new)); + } + } + registry.register(createItemBlock(WIRE_COIL, VariantItemBlock::new)); registry.register(createItemBlock(FUSION_CASING, VariantItemBlock::new)); registry.register(createItemBlock(WARNING_SIGN, VariantItemBlock::new)); diff --git a/src/main/java/gregtech/common/blocks/BlockWireCoil.java b/src/main/java/gregtech/common/blocks/BlockWireCoil.java index 2496bba9267..6f5851e6894 100644 --- a/src/main/java/gregtech/common/blocks/BlockWireCoil.java +++ b/src/main/java/gregtech/common/blocks/BlockWireCoil.java @@ -1,33 +1,51 @@ package gregtech.common.blocks; +import gregtech.api.GTValues; import gregtech.api.block.IHeatingCoilBlockStats; import gregtech.api.block.VariantActiveBlock; import gregtech.api.block.VariantItemBlock; import gregtech.api.items.toolitem.ToolClasses; import gregtech.api.unification.material.Material; import gregtech.api.unification.material.Materials; +import gregtech.api.util.GTUtility; +import gregtech.client.model.ActiveVariantBlockBakedModel; import gregtech.client.utils.TooltipHelper; -import gregtech.common.ConfigHolder; import gregtech.common.metatileentities.multi.electric.MetaTileEntityMultiSmelter; import net.minecraft.block.SoundType; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.color.BlockColors; +import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.resources.I18n; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.EntityLiving.SpawnPlacementType; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.IStringSerializable; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import it.unimi.dsi.fastutil.ints.Int2IntArrayMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.function.BooleanSupplier; public class BlockWireCoil extends VariantActiveBlock { @@ -41,10 +59,9 @@ public BlockWireCoil() { setDefaultState(getState(CoilType.CUPRONICKEL)); } - @NotNull @Override - public BlockRenderLayer getRenderLayer() { - return BlockRenderLayer.SOLID; + protected @NotNull Collection computeVariants() { + return getCoilTypes(); } @Override @@ -58,12 +75,12 @@ public void addInformation(@NotNull ItemStack itemStack, @Nullable World worldIn IBlockState stackState = itemBlock.getBlockState(itemStack); CoilType coilType = getState(stackState); - lines.add(I18n.format("tile.wire_coil.tooltip_heat", coilType.coilTemperature)); + lines.add(I18n.format("tile.wire_coil.tooltip_heat", coilType.getCoilTemperature())); if (TooltipHelper.isShiftDown()) { - int coilTier = coilType.ordinal(); + int coilTier = coilType.getTier(); lines.add(I18n.format("tile.wire_coil.tooltip_smelter")); - lines.add(I18n.format("tile.wire_coil.tooltip_parallel_smelter", coilType.level * 32)); + lines.add(I18n.format("tile.wire_coil.tooltip_parallel_smelter", coilType.getLevel() * 32)); int EUt = MetaTileEntityMultiSmelter.getEUtForParallel( MetaTileEntityMultiSmelter.getMaxParallel(coilType.getLevel()), coilType.getEnergyDiscount()); lines.add(I18n.format("tile.wire_coil.tooltip_energy_smelter", EUt)); @@ -83,73 +100,210 @@ public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAcces } @Override - protected boolean isBloomEnabled(CoilType value) { - return ConfigHolder.client.coilsActiveEmissiveTextures; + public @NotNull BlockRenderLayer getRenderLayer(CoilType value) { + return BlockRenderLayer.SOLID; } - public enum CoilType implements IStringSerializable, IHeatingCoilBlockStats { + @SideOnly(Side.CLIENT) + public void onModelRegister() { + Item item = Item.getItemFromBlock(this); + Int2ObjectMap modelMap = new Int2ObjectArrayMap<>(); - CUPRONICKEL("cupronickel", 1800, 1, 1, Materials.Cupronickel), - KANTHAL("kanthal", 2700, 2, 1, Materials.Kanthal), - NICHROME("nichrome", 3600, 2, 2, Materials.Nichrome), - RTM_ALLOY("rtm_alloy", 4500, 4, 2, Materials.RTMAlloy), - HSS_G("hss_g", 5400, 4, 4, Materials.HSSG), - NAQUADAH("naquadah", 7200, 8, 4, Materials.Naquadah), - TRINIUM("trinium", 9001, 8, 8, Materials.Trinium), - TRITANIUM("tritanium", 10800, 16, 8, Materials.Tritanium); + for (CoilType value : VALUES) { + var model = value.createModel(() -> isBloomEnabled(value)); + modelMap.put(VARIANT.getIndexOf(value), model.getModelLocation()); - private final String name; - // electric blast furnace properties - private final int coilTemperature; - // multi smelter properties - private final int level; - private final int energyDiscount; - private final Material material; + // inactive + ModelLoader.setCustomModelResourceLocation(item, VARIANT.getIndexOf(value), + model.getInactiveModelLocation()); - CoilType(String name, int coilTemperature, int level, int energyDiscount, Material material) { - this.name = name; - this.coilTemperature = coilTemperature; - this.level = level; - this.energyDiscount = energyDiscount; - this.material = material; + // active + ModelLoader.registerItemVariants(item, model.getActiveModelLocation()); } - @NotNull - @Override - public String getName() { - return this.name; + ModelLoader.setCustomStateMapper(this, b -> { + Map map = new HashMap<>(); + for (IBlockState s : b.getBlockState().getValidStates()) { + map.put(s, modelMap.get(s.getValue(VARIANT))); + } + return map; + }); + } + + public void onColorRegister(BlockColors blockColors, ItemColors itemColors) { + Int2IntMap colorMap = new Int2IntArrayMap(); + Item item = Item.getItemFromBlock(this); + + for (CoilType value : VALUES) { + colorMap.put(VARIANT.getIndexOf(value), value.getColor()); } - @Override - public int getCoilTemperature() { - return coilTemperature; + blockColors.registerBlockColorHandler((state, worldIn, pos, tintIndex) -> colorMap.get(state.getValue(VARIANT)), + this); + + itemColors.registerItemColorHandler((stack, tintIndex) -> colorMap.get(item.getMetadata(stack)), item); + } + + public static List getCoilTypes() { + return Collections.unmodifiableList(CoilType.COIL_TYPES); + } + + public abstract static class CoilType implements IStringSerializable, IHeatingCoilBlockStats, Comparable { + + private static final List COIL_TYPES = new ArrayList<>(); + + public static CoilType CUPRONICKEL; + public static CoilType KANTHAL; + public static CoilType NICHROME; + public static CoilType RTM_ALLOY; + public static CoilType HSS_G; + public static CoilType NAQUADAH; + public static CoilType TRINIUM; + public static CoilType TRITANIUM; + + static { + CUPRONICKEL = coilType(Materials.Cupronickel) + .tier(GTValues.LV) + .coilTemp(1800) + .multiSmelter(1, 1) + .build(); + KANTHAL = coilType(Materials.Kanthal) + .tier(GTValues.MV) + .coilTemp(2700) + .multiSmelter(2, 1) + .build(); + NICHROME = coilType(Materials.Nichrome) + .tier(GTValues.HV) + .coilTemp(3600) + .multiSmelter(2, 2) + .build(); + RTM_ALLOY = coilType(Materials.RTMAlloy) + .tier(GTValues.EV) + .coilTemp(4500) + .multiSmelter(4, 2) + .build(); + // material path is "hssg" but texture needs "hss_g" + HSS_G = coilType("hss_g", Materials.HSSG) + .tier(GTValues.IV) + .coilTemp(5400) + .multiSmelter(4, 4) + .build(); + NAQUADAH = coilType(Materials.Naquadah) + .tier(GTValues.LuV) + .coilTemp(7200) + .multiSmelter(8, 8) + .build(); + TRINIUM = coilType(Materials.Trinium) + .tier(GTValues.ZPM) + .coilTemp(9001) + .multiSmelter(8, 8) + .build(); + TRITANIUM = coilType(Materials.Tritanium) + .tier(GTValues.UV) + .coilTemp(10800) + .multiSmelter(16, 8) + .build(); } - @Override - public int getLevel() { - return level; + private static Builder coilType(Material material) { + return coilType(material.getResourceLocation().getPath(), material); } - @Override - public int getEnergyDiscount() { - return energyDiscount; + private static Builder coilType(String name, Material material) { + return new Builder(name, material); } - @Override - public int getTier() { - return this.ordinal(); + private CoilType() { + COIL_TYPES.add(this); } - @Nullable @Override - public Material getMaterial() { - return material; + public int compareTo(@NotNull BlockWireCoil.CoilType o) { + return Integer.compare(o.getTier(), getTier()); } - @NotNull @Override public String toString() { return getName(); } } + + private static class Builder { + + private final String name; + // electric blast furnace properties + private int coilTemperature; + // multi smelter properties + private int level; + private int energyDiscount; + private int tier; + private final Material material; + private ModelResourceLocation inactive; + private ModelResourceLocation active; + + private Builder(String name, Material material) { + this.material = material; + this.name = name; + } + + public Builder coilTemp(int coilTemperature) { + this.coilTemperature = coilTemperature; + return this; + } + + public Builder tier(int tier) { + this.tier = Math.max(0, tier); + return this; + } + + public Builder multiSmelter(int level, int energyDiscount) { + this.level = level; + this.energyDiscount = energyDiscount; + return this; + } + + public CoilType build() { + ResourceLocation loc = GTUtility.gregtechId("wire_coil"); + String variant = "active=%s,variant=%s"; + this.inactive = new ModelResourceLocation(loc, String.format(variant, false, name)); + this.active = new ModelResourceLocation(loc, String.format(variant, true, name)); + return new CoilType() { + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public int getCoilTemperature() { + return coilTemperature; + } + + @Override + public int getLevel() { + return level; + } + + @Override + public int getEnergyDiscount() { + return energyDiscount; + } + + @Override + public int getTier() { + return tier; + } + + @Override + public @Nullable Material getMaterial() { + return material; + } + + @Override + public ActiveVariantBlockBakedModel createModel(BooleanSupplier bloomConfig) { + return new ActiveVariantBlockBakedModel(inactive, active, bloomConfig); + } + }; + } + } } diff --git a/src/main/java/gregtech/common/blocks/MetaBlocks.java b/src/main/java/gregtech/common/blocks/MetaBlocks.java index ed353717832..56c10a73c3f 100644 --- a/src/main/java/gregtech/common/blocks/MetaBlocks.java +++ b/src/main/java/gregtech/common/blocks/MetaBlocks.java @@ -1,6 +1,8 @@ package gregtech.common.blocks; import gregtech.api.GregTechAPI; +import gregtech.api.block.coil.CoilRegistry; +import gregtech.api.block.coil.CustomCoilBlock; import gregtech.api.block.machines.BlockMachine; import gregtech.api.metatileentity.MetaTileEntityHolder; import gregtech.api.metatileentity.registry.MTERegistry; @@ -508,6 +510,12 @@ public static void registerItemModels() { MULTIBLOCK_CASING.onModelRegister(); TRANSPARENT_CASING.onModelRegister(); + for (CoilRegistry r : GregTechAPI.coilManager.getRegistries()) { + for (CustomCoilBlock block : r) { + block.onModelRegister(); + } + } + for (BlockLamp lamp : LAMPS.values()) lamp.onModelRegister(); for (BlockLamp lamp : BORDERLESS_LAMPS.values()) lamp.onModelRegister(); @@ -644,6 +652,14 @@ public static void registerColors() { blockColors.registerBlockColorHandler((s, w, p, i) -> ConfigHolder.client.defaultPaintingColor, HERMETIC_CASING); itemColors.registerItemColorHandler((s, i) -> ConfigHolder.client.defaultPaintingColor, HERMETIC_CASING); + + WIRE_COIL.onColorRegister(blockColors, itemColors); + + for (CoilRegistry r : GregTechAPI.coilManager.getRegistries()) { + for (CustomCoilBlock block : r) { + block.onColorRegister(blockColors, itemColors); + } + } } public static void registerWalkingSpeedBonus() { diff --git a/src/main/java/gregtech/common/blocks/StoneVariantBlock.java b/src/main/java/gregtech/common/blocks/StoneVariantBlock.java index 72fcb6d5180..aa970497383 100644 --- a/src/main/java/gregtech/common/blocks/StoneVariantBlock.java +++ b/src/main/java/gregtech/common/blocks/StoneVariantBlock.java @@ -9,8 +9,6 @@ import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; -import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLiving; import net.minecraft.item.Item; @@ -25,9 +23,6 @@ @SuppressWarnings("deprecation") public class StoneVariantBlock extends VariantBlock { - // shared property instance - private static final PropertyEnum PROPERTY = PropertyEnum.create("variant", StoneType.class); - private final StoneVariant stoneVariant; public StoneVariantBlock(@NotNull StoneVariant stoneVariant) { @@ -43,14 +38,6 @@ public StoneVariantBlock(@NotNull StoneVariant stoneVariant) { setCreativeTab(GTCreativeTabs.TAB_GREGTECH_DECORATIONS); } - @NotNull - @Override - protected BlockStateContainer createBlockState() { - this.VARIANT = PROPERTY; - this.VALUES = StoneType.values(); - return new BlockStateContainer(this, VARIANT); - } - @Override public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos, @NotNull EntityLiving.SpawnPlacementType type) { diff --git a/src/main/java/gregtech/core/CoreModule.java b/src/main/java/gregtech/core/CoreModule.java index 6ea9f2a3d94..7c6272c9a94 100644 --- a/src/main/java/gregtech/core/CoreModule.java +++ b/src/main/java/gregtech/core/CoreModule.java @@ -4,6 +4,7 @@ import gregtech.api.GregTechAPI; import gregtech.api.GregTechAPIInternal; import gregtech.api.block.IHeatingCoilBlockStats; +import gregtech.api.block.coil.CoilManager; import gregtech.api.capability.SimpleCapabilityManager; import gregtech.api.cover.CoverDefinition; import gregtech.api.cover.CoverUIFactory; @@ -193,12 +194,16 @@ public void preInit(FMLPreInitializationEvent event) { // need to do this before MetaBlocks runs, to make sure all addons get their own BlockMachine /* Start MTE Registry Addition */ GregTechAPI.mteManager = MTEManager.getInstance(); + GregTechAPI.coilManager = CoilManager.getInstance(); MinecraftForge.EVENT_BUS.post(new MTEManager.MTERegistryEvent()); /* End MTE Registry Addition */ OreDictUnifier.init(); MetaBlocks.init(); + logger.info("Registering Coils"); + MinecraftForge.EVENT_BUS.post(new CoilManager.CoilRegistryEvent()); + MetaItems.init(); ToolItems.init(); GTFluidRegistration.INSTANCE.register(); @@ -215,7 +220,7 @@ public void preInit(FMLPreInitializationEvent event) { MetaEntities.init(); /* Start API Block Registration */ - for (BlockWireCoil.CoilType type : BlockWireCoil.CoilType.values()) { + for (BlockWireCoil.CoilType type : BlockWireCoil.getCoilTypes()) { HEATING_COILS.put(MetaBlocks.WIRE_COIL.getState(type), type); } for (BlockBatteryPart.BatteryPartType type : BlockBatteryPart.BatteryPartType.values()) { diff --git a/src/main/resources/assets/gregtech/blockstates/wire_coil.json b/src/main/resources/assets/gregtech/blockstates/wire_coil.json index ff29e674dab..1bf3858650a 100644 --- a/src/main/resources/assets/gregtech/blockstates/wire_coil.json +++ b/src/main/resources/assets/gregtech/blockstates/wire_coil.json @@ -1,109 +1,124 @@ { "forge_marker": 1, "variants": { + "normal": { + "model": "gregtech:cube_2_layer_all_tint", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_generic_base", + "top_all": "gregtech:blocks/casings/coils/machine_coil_generic" + } + }, + "active": { + "model": "gregtech:cube_3_layer_all_tint", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_generic_base", + "mid_all": "gregtech:blocks/casings/coils/machine_coil_generic", + "top_all": "gregtech:blocks/casings/coils/machine_coil_generic_bloom" + } + }, "active=false,variant=cupronickel": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_cupronickel" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_cupronickel" + } }, "active=true,variant=cupronickel": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_cupronickel", - "top_all":"gregtech:blocks/casings/coils/machine_coil_cupronickel_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_cupronickel", + "top_all":"gregtech:blocks/casings/coils/machine_coil_cupronickel_bloom" + } }, "active=false,variant=kanthal": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_kanthal" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_kanthal" + } }, "active=true,variant=kanthal": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_kanthal", - "top_all":"gregtech:blocks/casings/coils/machine_coil_kanthal_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_kanthal", + "top_all":"gregtech:blocks/casings/coils/machine_coil_kanthal_bloom" + } }, "active=false,variant=nichrome": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_nichrome" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_nichrome" + } }, "active=true,variant=nichrome": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_nichrome", - "top_all":"gregtech:blocks/casings/coils/machine_coil_nichrome_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_nichrome", + "top_all":"gregtech:blocks/casings/coils/machine_coil_nichrome_bloom" + } }, "active=false,variant=rtm_alloy": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_rtm_alloy" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_rtm_alloy" + } }, "active=true,variant=rtm_alloy": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_rtm_alloy", - "top_all":"gregtech:blocks/casings/coils/machine_coil_rtm_alloy_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_rtm_alloy", + "top_all":"gregtech:blocks/casings/coils/machine_coil_rtm_alloy_bloom" + } }, "active=false,variant=hss_g": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_hssg" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_hssg" + } }, "active=true,variant=hss_g": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_hssg", - "top_all":"gregtech:blocks/casings/coils/machine_coil_hssg_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_hssg", + "top_all":"gregtech:blocks/casings/coils/machine_coil_hssg_bloom" + } }, "active=false,variant=naquadah": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_naquadah" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_naquadah" + } }, "active=true,variant=naquadah": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_naquadah", - "top_all":"gregtech:blocks/casings/coils/machine_coil_naquadah_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_naquadah", + "top_all":"gregtech:blocks/casings/coils/machine_coil_naquadah_bloom" + } }, "active=false,variant=trinium": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_trinium" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_trinium" + } }, "active=true,variant=trinium": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_trinium", - "top_all":"gregtech:blocks/casings/coils/machine_coil_trinium_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_trinium", + "top_all":"gregtech:blocks/casings/coils/machine_coil_trinium_bloom" + } }, "active=false,variant=tritanium": { - "model": "minecraft:cube_all", - "textures": { - "all": "gregtech:blocks/casings/coils/machine_coil_tritanium" - } + "model": "minecraft:cube_all", + "textures": { + "all": "gregtech:blocks/casings/coils/machine_coil_tritanium" + } }, "active=true,variant=tritanium": { - "model": "gregtech:cube_2_layer_all", - "textures": { - "bot_all": "gregtech:blocks/casings/coils/machine_coil_tritanium", - "top_all":"gregtech:blocks/casings/coils/machine_coil_tritanium_bloom" - } + "model": "gregtech:cube_2_layer_all", + "textures": { + "bot_all": "gregtech:blocks/casings/coils/machine_coil_tritanium", + "top_all":"gregtech:blocks/casings/coils/machine_coil_tritanium_bloom" + } } } } diff --git a/src/main/resources/assets/gregtech/models/block/cube_2_layer_all_tint.json b/src/main/resources/assets/gregtech/models/block/cube_2_layer_all_tint.json new file mode 100644 index 00000000000..636fa1228ed --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/cube_2_layer_all_tint.json @@ -0,0 +1,18 @@ +{ + "parent": "gregtech:block/cube_2_layer_tint", + "textures": { + "particle": "#bot_all", + "bot_down": "#bot_all", + "bot_up": "#bot_all", + "bot_north": "#bot_all", + "bot_east": "#bot_all", + "bot_south": "#bot_all", + "bot_west": "#bot_all", + "top_down": "#top_all", + "top_up": "#top_all", + "top_north": "#top_all", + "top_east": "#top_all", + "top_south": "#top_all", + "top_west": "#top_all" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/cube_2_layer_tint.json b/src/main/resources/assets/gregtech/models/block/cube_2_layer_tint.json new file mode 100644 index 00000000000..311dcbf7e23 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/cube_2_layer_tint.json @@ -0,0 +1,29 @@ +{ + "parent": "block/block", + "elements": [ + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#bot_down", "cullface": "down" }, + "up": { "texture": "#bot_up", "cullface": "up" }, + "north": { "texture": "#bot_north", "cullface": "north" }, + "south": { "texture": "#bot_south", "cullface": "south" }, + "west": { "texture": "#bot_west", "cullface": "west" }, + "east": { "texture": "#bot_east", "cullface": "east" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#top_down", "cullface": "down", "tintindex": 0 }, + "up": { "texture": "#top_up", "cullface": "up", "tintindex": 0 }, + "north": { "texture": "#top_north", "cullface": "north", "tintindex": 0 }, + "south": { "texture": "#top_south", "cullface": "south", "tintindex": 0 }, + "west": { "texture": "#top_west", "cullface": "west", "tintindex": 0 }, + "east": { "texture": "#top_east", "cullface": "east", "tintindex": 0 } + } + } + ] +} diff --git a/src/main/resources/assets/gregtech/models/block/cube_3_layer_all_tint.json b/src/main/resources/assets/gregtech/models/block/cube_3_layer_all_tint.json new file mode 100644 index 00000000000..f4d16e6101c --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/cube_3_layer_all_tint.json @@ -0,0 +1,24 @@ +{ + "parent": "gregtech:block/cube_3_layer_tint", + "textures": { + "particle": "#bot_all", + "bot_down": "#bot_all", + "bot_up": "#bot_all", + "bot_north": "#bot_all", + "bot_east": "#bot_all", + "bot_south": "#bot_all", + "bot_west": "#bot_all", + "mid_down": "#mid_all", + "mid_up": "#mid_all", + "mid_north": "#mid_all", + "mid_east": "#mid_all", + "mid_south": "#mid_all", + "mid_west": "#mid_all", + "top_down": "#top_all", + "top_up": "#top_all", + "top_north": "#top_all", + "top_east": "#top_all", + "top_south": "#top_all", + "top_west": "#top_all" + } +} diff --git a/src/main/resources/assets/gregtech/models/block/cube_3_layer_tint.json b/src/main/resources/assets/gregtech/models/block/cube_3_layer_tint.json new file mode 100644 index 00000000000..31449c3a250 --- /dev/null +++ b/src/main/resources/assets/gregtech/models/block/cube_3_layer_tint.json @@ -0,0 +1,41 @@ +{ + "parent": "block/block", + "elements": [ + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#bot_down", "cullface": "down" }, + "up": { "texture": "#bot_up", "cullface": "up" }, + "north": { "texture": "#bot_north", "cullface": "north" }, + "south": { "texture": "#bot_south", "cullface": "south" }, + "west": { "texture": "#bot_west", "cullface": "west" }, + "east": { "texture": "#bot_east", "cullface": "east" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#mid_down", "cullface": "down" }, + "up": { "texture": "#mid_up", "cullface": "up" }, + "north": { "texture": "#mid_north", "cullface": "north" }, + "south": { "texture": "#mid_south", "cullface": "south" }, + "west": { "texture": "#mid_west", "cullface": "west" }, + "east": { "texture": "#mid_east", "cullface": "east" } + } + }, + { + "from": [ 0, 0, 0 ], + "to": [ 16, 16, 16 ], + "faces": { + "down": { "texture": "#top_down", "cullface": "down", "tintindex": 0 }, + "up": { "texture": "#top_up", "cullface": "up", "tintindex": 0 }, + "north": { "texture": "#top_north", "cullface": "north", "tintindex": 0 }, + "south": { "texture": "#top_south", "cullface": "south", "tintindex": 0 }, + "west": { "texture": "#top_west", "cullface": "west", "tintindex": 0 }, + "east": { "texture": "#top_east", "cullface": "east", "tintindex": 0 } + } + } + ] +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png new file mode 100644 index 00000000000..24998ec7ae8 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png.mcmeta new file mode 100644 index 00000000000..9eb46676f53 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic.png.mcmeta @@ -0,0 +1,13 @@ +{ + "ctm": { + "ctm_version": 1, + "type": "CTM", + "layer": "CUTOUT", + "textures": [ + "gregtech:blocks/casings/coils/machine_coil_generic_ctm" + ], + "extra": { + "connect_inside": true + } + } +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png new file mode 100644 index 00000000000..56e1c31f69b Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png.mcmeta new file mode 100644 index 00000000000..df287f690b6 --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base.png.mcmeta @@ -0,0 +1,13 @@ +{ + "ctm": { + "ctm_version": 1, + "type": "CTM", + "layer": "CUTOUT", + "textures": [ + "gregtech:blocks/casings/coils/machine_coil_generic_base_ctm" + ], + "extra": { + "connect_inside": true + } + } +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base_ctm.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base_ctm.png new file mode 100644 index 00000000000..f8d6d795a7f Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_base_ctm.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png new file mode 100644 index 00000000000..046e97ca8c6 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png.mcmeta b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png.mcmeta new file mode 100644 index 00000000000..8008403463d --- /dev/null +++ b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom.png.mcmeta @@ -0,0 +1,15 @@ +{ + "ctm": { + "ctm_version": 1, + "type": "CTM", + "layer": "BLOOM", + "gregtech": true, + "textures": [ + "gregtech:blocks/casings/coils/machine_coil_generic_bloom_ctm" + ], + "extra": { + "connect_inside": true, + "light": 5 + } + } +} diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom_ctm.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom_ctm.png new file mode 100644 index 00000000000..d4d7af05cb9 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_bloom_ctm.png differ diff --git a/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_ctm.png b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_ctm.png new file mode 100644 index 00000000000..1356386fbc9 Binary files /dev/null and b/src/main/resources/assets/gregtech/textures/blocks/casings/coils/machine_coil_generic_ctm.png differ