Skip to content

Commit

Permalink
Convert interpolation to mixin
Browse files Browse the repository at this point in the history
This is so ANY texture can have this without needing special code, good for texture packs and stuff and easier to work with
  • Loading branch information
Roadhog360 committed Dec 2, 2023
1 parent 4bfac3f commit b3fc4a0
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 100 deletions.
4 changes: 4 additions & 0 deletions src/main/java/ganymedes01/etfuturum/EtFuturumMixinPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public List<String> getMixins() {
if (ConfigMixins.flowerPotFixes) {
mixins.add("flowerpotfix.client.MixinRenderBlocks");
}

if (ConfigMixins.interpolatedTextures) {
mixins.add("interpolatedtexturemap.MixinTextureMap");
}
}

return mixins;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ganymedes01/etfuturum/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public enum ModBlocks {
STONE(ConfigBlocksItems.enableStones, new BlockBountifulStone()),
PRISMARINE_BLOCK(ConfigBlocksItems.enablePrismarine, new BaseSubtypesBlock(Material.rock, "prismarine$i", "prismarine_bricks", "dark_prismarine")
PRISMARINE_BLOCK(ConfigBlocksItems.enablePrismarine, new BaseSubtypesBlock(Material.rock, "prismarine", "prismarine_bricks", "dark_prismarine")
.setHardness(1.5F).setResistance(10.0F)),
SEA_LANTERN(ConfigBlocksItems.enablePrismarine, new BlockSeaLantern()),
DAYLIGHT_DETECTOR_INVERTED(ConfigBlocksItems.enableInvertedDaylightSensor, new BlockInvertedDaylightDetector(), null),
Expand Down Expand Up @@ -290,9 +290,9 @@ public enum ModBlocks {
//new wood logs
CRIMSON_STEM(ConfigBlocksItems.enableCrimsonBlocks, new BlockNetherStem("crimson")),
WARPED_STEM(ConfigBlocksItems.enableWarpedBlocks, new BlockNetherStem("warped")),
MANGROVE_LOG(ConfigBlocksItems.enableMangroveBlocks, new BlockModernLog("mangrove")),
CHERRY_LOG(ConfigBlocksItems.enableCherryBlocks, new BlockModernLog("cherry", ModSounds.soundCherryWood)),
BAMBOO_BLOCK(ConfigBlocksItems.enableBambooBlocks, new BlockBambooBlock("bamboo", ModSounds.soundBambooWood)),
MANGROVE_LOG(ConfigBlocksItems.enableMangroveBlocks, new BaseLog("mangrove")),
CHERRY_LOG(ConfigBlocksItems.enableCherryBlocks, new BaseLog("cherry").setBlockSound(ModSounds.soundCherryWood)),
BAMBOO_BLOCK(ConfigBlocksItems.enableBambooBlocks, new BlockBambooBlock("bamboo").setBlockSound(ModSounds.soundBambooWood)),

//new wood stairs
CRIMSON_STAIRS(ConfigBlocksItems.enableCrimsonBlocks, new BaseStairs(WOOD_PLANKS.get(), 0).setBlockSound(ModSounds.soundNetherWood).setUnlocalizedNameWithPrefix("crimson")),
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/ganymedes01/etfuturum/blocks/BaseBlock.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package ganymedes01.etfuturum.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.client.InterpolatedIcon;
import ganymedes01.etfuturum.core.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;

/**
* Because the standard block constructor is protected...
Expand All @@ -18,7 +13,6 @@
public class BaseBlock extends Block {

private Block mapColorBase;
private boolean interpolatedIcon;

public BaseBlock(Material p_i45394_1_) {
super(p_i45394_1_);
Expand All @@ -32,18 +26,10 @@ public BaseBlock setUnlocalizedNameWithPrefix(String name) {

@Override
public Block setBlockTextureName(String name) {
if (name.endsWith("$i")) {
interpolatedIcon = true;
name = name.substring(0, name.length() - 2);
}
return super.setBlockTextureName(name);
}

public BaseBlock setNames(String name) {
if (name.endsWith("$i")) {
interpolatedIcon = true;
name = name.substring(0, name.length() - 2);
}
setUnlocalizedNameWithPrefix(name);
setBlockTextureName(name);
return this;
Expand Down Expand Up @@ -75,17 +61,4 @@ public BaseBlock setMapColorBaseBlock(Block block) {
public MapColor getMapColor(int p_149728_1_) {
return mapColorBase == null ? super.getMapColor(p_149728_1_) : mapColorBase.getMapColor(p_149728_1_);
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister p_149651_1_) {
if (interpolatedIcon) {
blockIcon = new InterpolatedIcon(textureName);
if (p_149651_1_ instanceof TextureMap) {
((TextureMap) p_149651_1_).setTextureEntry(textureName, (InterpolatedIcon) blockIcon);
}
} else {
super.registerBlockIcons(p_149651_1_);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/ganymedes01/etfuturum/blocks/BaseFlower.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.lib.RenderIDs;
import net.minecraft.block.BlockFlower;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.client.InterpolatedIcon;
import ganymedes01.etfuturum.configuration.configs.ConfigBlocksItems;
import ganymedes01.etfuturum.core.utils.Utils;
import net.minecraft.block.BlockLog;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -18,12 +16,12 @@

import java.util.List;

public class BlockModernLog extends BlockLog implements ISubBlocksBlock {
public class BaseLog extends BlockLog implements ISubBlocksBlock {

protected final String type;
protected String[] types;

public BlockModernLog(String type) {
public BaseLog(String type) {
super();
this.type = type;
types = new String[]{type + "_log", type + "_wood", "stripped_" + type + "_log", "stripped_" + type + "_wood"};
Expand All @@ -32,9 +30,9 @@ public BlockModernLog(String type) {
setCreativeTab(EtFuturum.creativeTabBlocks);
}

public BlockModernLog(String type, SoundType sound) {
this(type);
Utils.setBlockSound(this, sound);
public BaseLog setBlockSound(SoundType type) {
Utils.setBlockSound(this, type);
return this;
}

@Override
Expand All @@ -43,16 +41,6 @@ public void registerBlockIcons(IIconRegister iconRegister) {
field_150167_a = new IIcon[types.length];
field_150166_b = new IIcon[types.length];

if (types[0].contains("stem")) {
InterpolatedIcon animatedStem = new InterpolatedIcon(getTypes()[0]);
if (iconRegister instanceof TextureMap) {
((TextureMap) iconRegister).setTextureEntry(getTypes()[0], animatedStem);
}
blockIcon = field_150166_b[1] = field_150167_a[0] = field_150167_a[1] = animatedStem;
} else {
blockIcon = field_150166_b[1] = field_150167_a[0] = field_150167_a[1] = iconRegister.registerIcon(types[0]);
}

blockIcon = field_150166_b[1] = field_150167_a[0] = field_150167_a[1] = iconRegister.registerIcon(types[0]);
field_150166_b[3] = field_150167_a[2] = field_150167_a[3] = iconRegister.registerIcon(types[2]);
field_150166_b[0] = iconRegister.registerIcon(types[0] + "_top");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.client.InterpolatedIcon;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -16,7 +14,6 @@
public class BaseSubtypesBlock extends BaseBlock implements ISubBlocksBlock {
@SideOnly(Side.CLIENT)
private IIcon[] icons;
private final boolean[] interpolatedIcons;
private final String[] types;

private final int startMeta;
Expand All @@ -28,13 +25,6 @@ public BaseSubtypesBlock(Material material, String... types) {
public BaseSubtypesBlock(Material material, int startMeta, String... types) {
super(material);
this.startMeta = startMeta;
interpolatedIcons = new boolean[types.length];
for (int i = 0; i < types.length; i++) {
if (types[i].endsWith("$i")) {
interpolatedIcons[i] = true;
types[i] = types[i].substring(0, types[i].length() - 2);
}
}
this.types = types;
if (!"".equals(types[0])) {
setNames(types[0]);
Expand Down Expand Up @@ -86,13 +76,7 @@ public IIcon getIcon(int side, int meta) {
public void registerBlockIcons(IIconRegister reg) {
setIcons(new IIcon[getTypes().length]);
for (int i = 0; i < getIcons().length; i++) {
if (interpolatedIcons[i] && reg instanceof TextureMap) {
InterpolatedIcon icon = new InterpolatedIcon(getTypes()[i]);
((TextureMap) reg).setTextureEntry(getTypes()[i], icon);
getIcons()[i] = icon;
} else {
getIcons()[i] = "".equals(getTypes()[i]) ? reg.registerIcon(getTextureName()) : reg.registerIcon((getTextureDomain().isEmpty() ? "" : getTextureDomain() + ":") + getTypes()[i]);
}
getIcons()[i] = "".equals(getTypes()[i]) ? reg.registerIcon(getTextureName()) : reg.registerIcon((getTextureDomain().isEmpty() ? "" : getTextureDomain() + ":") + getTypes()[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.client.sound.ModSounds;
import ganymedes01.etfuturum.configuration.configs.ConfigBlocksItems;
import ganymedes01.etfuturum.core.utils.Utils;
import net.minecraft.client.renderer.texture.IIconRegister;
Expand All @@ -13,12 +14,13 @@

import java.util.List;

public class BlockBambooBlock extends BlockModernLog implements ISubBlocksBlock {
public class BlockBambooBlock extends BaseLog {

public BlockBambooBlock(String type, SoundType soundBambooWood) {
super(type, soundBambooWood);
public BlockBambooBlock(String type) {
super(type);
types = new String[]{type + "_block", "stripped_" + type + "_block"};
setBlockName(Utils.getUnlocalisedName(type + "_block"));
setBlockSound(ModSounds.soundBambooWood);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.ModBlocks;
import ganymedes01.etfuturum.client.InterpolatedIcon;
import ganymedes01.etfuturum.configuration.configs.ConfigSounds;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.lib.GUIIDs;
Expand All @@ -13,7 +12,6 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -74,10 +72,7 @@ public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3
public void registerBlockIcons(IIconRegister p_149651_1_) {
this.blockIcon = p_149651_1_.registerIcon("blast_furnace_side");
if (isCooking) {
blockFront = new InterpolatedIcon("blast_furnace_front_on");
if (p_149651_1_ instanceof TextureMap) {
((TextureMap) p_149651_1_).setTextureEntry("blast_furnace_front_on", (InterpolatedIcon) blockFront);
}
this.blockIcon = p_149651_1_.registerIcon("blast_furnace_front_on");
} else {
this.blockFront = p_149651_1_.registerIcon("blast_furnace_front");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ganymedes01/etfuturum/blocks/BlockMagma.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BlockMagma() {
setHardness(0.5F);
setResistance(0.5F);
setLightLevel(0.2F);
setNames("magma$i");
setNames("magma");
setCreativeTab(EtFuturum.creativeTabBlocks);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.client.sound.ModSounds;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.lib.RenderIDs;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.init.Blocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockNetherStem extends BlockModernLog implements ISubBlocksBlock {
public class BlockNetherStem extends BaseLog {

public BlockNetherStem(String type) {
super(type, ModSounds.soundStem);
setBlockName(Utils.getUnlocalisedName(type + "_stem"));
super(type);
for (int i = 0; i < getTypes().length; i++) {
getTypes()[i] = getTypes()[i].replace("log", "stem").replace("wood", "hyphae");
}
setBlockName(Utils.getUnlocalisedName(type + "_stem"));
setBlockSound(ModSounds.soundStem);
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ganymedes01/etfuturum/blocks/BlockOldRose.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package ganymedes01.etfuturum.blocks;

import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.lib.Reference;
import ganymedes01.etfuturum.lib.RenderIDs;

public class BlockOldRose extends BaseFlower {

Expand Down
11 changes: 0 additions & 11 deletions src/main/java/ganymedes01/etfuturum/blocks/BlockPackedMud.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
package ganymedes01.etfuturum.blocks;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ganymedes01.etfuturum.EtFuturum;
import ganymedes01.etfuturum.client.sound.ModSounds;
import ganymedes01.etfuturum.configuration.configs.ConfigSounds;
import ganymedes01.etfuturum.core.utils.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.Random;

public class BlockPackedMud extends BaseSubtypesBlock {

public BlockPackedMud() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ganymedes01.etfuturum.ModBlocks;
import ganymedes01.etfuturum.core.utils.Utils;
import net.minecraft.block.BlockButtonStone;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;

public class BlockPolishedBlackstoneButton extends BlockButtonStone {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ganymedes01/etfuturum/blocks/BlockSculk.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class BlockSculk extends BaseBlock {
public BlockSculk() {
super(Material.ground);
setNames("sculk$i");
setNames("sculk");
setHardness(.6F);
setResistance(.2F);
setBlockSound(ModSounds.soundSculk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.ArrayList;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.ArrayList;
import java.util.Random;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ConfigMixins extends ConfigBase {
public static boolean betterPistons;
public static boolean flowerPotFixes;
public static boolean soulFire;
public static boolean interpolatedTextures;

static final String catBackport = "backported features";
static final String catOptimization = "optimizations";
Expand All @@ -62,10 +63,11 @@ public ConfigMixins(File file) {
protected void syncConfigOptions() {
if (EtFuturumMixinPlugin.side == MixinEnvironment.Side.CLIENT) {
furnaceCrackle = getBoolean("furnaceCrackle", catBackport, true, "Allows vanilla furnaces to have crackling sounds.\nModified Client Classes: net.minecraft.block.BlockFurnace");
boundedBlockBreakingParticles = getBoolean("boundedBlockBreakingParticles", catBackport, true, "In 1.14+, when breaking a block the block break particles stay within the outline, instead of always occupying the whole block space.\nMofified Classes: net.minecraft.client.particle.EffectRenderer");
adjustedAttenuation = getBoolean("adjustedAttenuation", catBackport, true, "Adjusts the attenuation distance of certain sounds. This needs to be a separate mixin due to the way it works.\nCurrently changes portal abience, and beacon ambience to have an attenuation distance of 8 blocks away, instead of 16.\nModified Classes: net.minecraft.client.audio.SoundManager");
boundedBlockBreakingParticles = getBoolean("boundedBlockBreakingParticles", catBackport, true, "In 1.14+, when breaking a block, the block break particles stay within the outline, instead of always occupying the whole block space.\nMofified Client Classes: net.minecraft.client.particle.EffectRenderer");
adjustedAttenuation = getBoolean("adjustedAttenuation", catBackport, true, "Adjusts the attenuation distance of certain sounds. This needs to be a separate mixin due to the way it works.\nCurrently changes portal abience, and beacon ambience to have an attenuation distance of 8 blocks away, instead of 16.\nModified Client Classes: net.minecraft.client.audio.SoundManager");
interpolatedTextures = getBoolean("interpolatedTextures", catBackport, true, "Adds support for the \"interpolate\" flag in .mcmeta files. If turned off, stuff like Nether stems, magma etc will not have smooth texture animations! Modified Client Classes: net.minecraft.client.renderer.texture.TextureMap");

flowerPotFixes = getBoolean("flowerPotFixes", catFixes, true, "Fixes flower pots having several restrictions limiting what they'll render inside of them. Required for crimson roots or azalea to render correctly in the flower pot.\nModified Classes: net.minecraft.client.renderer.RenderBlock");
flowerPotFixes = getBoolean("flowerPotFixes", catFixes, true, "Fixes flower pots having several restrictions limiting what they'll render inside of them. Required for crimson roots or azalea to render correctly in the flower pot.\nModified Client Classes: net.minecraft.client.renderer.RenderBlock");
}

endPortalFix = getBoolean("endPortalFix", catBackport, true, "Makes the End Portal block (the actual portal, not the frame) have an item icon, proper hitbox and will not instantly destroy itself in other dimensions.\nModified classes: net.minecraft.block.BlockEndPortal");
Expand Down
Loading

0 comments on commit b3fc4a0

Please sign in to comment.