Particle fixes (#5411)

* Make transmitters return an actual particle instead of the default WHITE
Make fluid tank particle/break particle be the glass wall
Have hit particle for fluid tank and transmitters use the correct tier instead of being basic. Running and Falling particle still displays as the basic tier

* Get actual state for transmitters (gets the proper tier data so that we don't have to manually replace it)

* Fix dif of just imports

* Fix dif of just imports

* query the blockstate directly for the MachineType

* remove incorrect copy-pasted use of FML logger

* remove unnecessary list wrapping

* tidy copied particle code a little and un-inline constants

* use built in singleton rather than immulatble list
This commit is contained in:
Richard Freimer authored and GitHub committed 2019-04-20 10:45:13 -04:00
1 parent 0dba7cb584
commit 77d774e55f
12 files changed
+216 -37

No files matched your search

@@ -117,8 +117,7 @@ public class MekanismRenderer {
spriteLocation = fluid.getFlowing();
}
TextureAtlasSprite sprite = texMap.getTextureExtry(spriteLocation.toString());
return sprite != null ? sprite : missingIcon;
return getTextureAtlasSprite(spriteLocation);
}
public static TextureAtlasSprite getFluidTexture(FluidStack fluidStack, FluidType type) {
@@ -134,6 +133,10 @@ public class MekanismRenderer {
} else {
spriteLocation = fluid.getFlowing(fluidStack);
}
return getTextureAtlasSprite(spriteLocation);
}
public static TextureAtlasSprite getTextureAtlasSprite(ResourceLocation spriteLocation) {
TextureAtlasSprite sprite = texMap.getTextureExtry(spriteLocation.toString());
return sprite != null ? sprite : missingIcon;
}
@@ -1,12 +1,13 @@
package mekanism.client.render.obj;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
import mekanism.client.render.obj.MekanismOBJModel.OBJModelType;
import mekanism.common.Mekanism;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@@ -15,6 +16,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.IRegistry;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.client.model.IModel;
@@ -23,10 +25,10 @@ import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.client.model.obj.OBJModel.OBJBakedModel;
import net.minecraftforge.client.model.obj.OBJModel.OBJState;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.Level;
public class MekanismOBJLoader implements ICustomModelLoader {
@@ -39,13 +41,12 @@ public class MekanismOBJLoader implements ICustomModelLoader {
public void onModelBake(ModelBakeEvent event) {
GlowPanelModel.forceRebake();
IRegistry<ModelResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
for (String s : OBJ_RENDERS) {
ModelResourceLocation model = new ModelResourceLocation("mekanism:" + s, "inventory");
IBakedModel bakedModel = event.getModelRegistry().getObject(model);
event.getModelRegistry().putObject(model,
createBakedObjItemModel(bakedModel, "mekanism:models/block/" + s + ".obj.mek",
new OBJModel.OBJState(Lists.newArrayList(OBJModel.Group.ALL), true),
DefaultVertexFormats.ITEM));
IBakedModel bakedModel = modelRegistry.getObject(model);
modelRegistry.putObject(model, createBakedObjItemModel(bakedModel, "mekanism:models/block/" + s +
".obj.mek", new OBJState(Lists.newArrayList(OBJModel.Group.ALL), true), DefaultVertexFormats.ITEM));
}
}
@@ -63,14 +64,13 @@ public class MekanismOBJLoader implements ICustomModelLoader {
TextureAtlasSprite missing = textureGetter.apply(new ResourceLocation("missingno"));
for (String s : objModel.getMatLib().getMaterialNames()) {
if (objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation().getPath().startsWith("#")) {
FMLLog.log(Level.ERROR, "OBJLoader: Unresolved texture '%s' for obj model '%s'",
objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation().getPath(),
ResourceLocation texture = objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation();
if (texture.getPath().startsWith("#")) {
Mekanism.logger.error("OBJLoader: Unresolved texture '{}' for obj model '{}'", texture.getPath(),
modelLocation);
builder.put(s, missing);
} else {
builder.put(s,
textureGetter.apply(objModel.getMatLib().getMaterial(s).getTexture().getTextureLocation()));
builder.put(s, textureGetter.apply(texture));
}
}
@@ -166,8 +166,9 @@ public abstract class OBJBakedModelBase extends OBJBakedModel {
for (Face f : faces) {
String groupName = groupNameMap.get(f);
if (getOverrideTexture(f, groupName) != null) {
tempSprite = getOverrideTexture(f, groupName);
TextureAtlasSprite overrideTexture = getOverrideTexture(f, groupName);
if (overrideTexture != null) {
tempSprite = overrideTexture;
} else if (getModel().getMatLib().getMaterial(f.getMaterialName()).isWhite()) {
for (Vertex v : f.getVertices()) {
if (!v.getMaterial().equals(getModel().getMatLib().getMaterial(v.getMaterial().getName()))) {
@@ -182,8 +183,9 @@ public abstract class OBJBakedModelBase extends OBJBakedModel {
float[] color = new float[]{1, 1, 1, 1};
if (getOverrideColor(f, groupName) != null) {
color = getOverrideColor(f, groupName);
float[] overrideColor = getOverrideColor(f, groupName);
if (overrideColor != null) {
color = overrideColor;
}
EnumFacing facing = EnumFacing.getFacingFromVector(f.getNormal().x, f.getNormal().y, f.getNormal().z);
@@ -214,9 +216,7 @@ public abstract class OBJBakedModelBase extends OBJBakedModel {
bakedQuads.add(quad);
}
List<BakedQuad> quadList = Collections.synchronizedList(Lists.newArrayList(bakedQuads));
return quadList;
return bakedQuads;
}
@SuppressWarnings("deprecation")
@@ -68,12 +68,13 @@ public class TransmitterModel extends OBJBakedModelBase {
private TransmitterModel itemCache;
private IBlockState tempState;
private ItemStack tempStack;
private TextureAtlasSprite particle;
private TransmitterOverride override = new TransmitterOverride();
public TransmitterModel(IBakedModel base, OBJModel model, IModelState state, VertexFormat format,
ImmutableMap<String, TextureAtlasSprite> textures, HashMap<TransformType, Matrix4f> transform) {
super(base, model, state, format, textures, transform);
particle = textureMap.getOrDefault("None_Center", textureMap.getOrDefault("CentreMaterial", tempSprite));
modelInstances.add(this);
}
@@ -179,6 +180,12 @@ public class TransmitterModel extends OBJBakedModelBase {
return null;
}
@Nonnull
@Override
public TextureAtlasSprite getParticleTexture() {
return particle;
}
@Override
public TextureAtlasSprite getOverrideTexture(Face f, String groupName) {
if (tempState != null) {
@@ -0,0 +1,87 @@
package mekanism.client.render.particle;
import mekanism.api.EnumColor;
import mekanism.common.base.ITieredTile;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MekanismParticleHelper {
/** Centre offset? */
private static final double OFFSET_1 = 0.20000000298023224D;
/** Side offset? */
private static final double OFFSET_2 = 0.10000000149011612D;
/**
* Adds block hit particles for the specified block, accounting for tier colour
* @see ParticleManager#addBlockHitEffects(net.minecraft.util.math.BlockPos, net.minecraft.util.EnumFacing) for source of copy
*
* @param world relevant world
* @param pos position of block
* @param side which side was hit
* @param manager vanilla particle manager in use
* @return true if handled (always true)
*/
public static boolean addBlockHitEffects(World world, BlockPos pos, EnumFacing side, ParticleManager manager) {
TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos);
EnumColor color = null;
IBlockState iblockstate = world.getBlockState(pos);
//Makes it so transmitters don't need to change their tier
iblockstate = iblockstate.getBlock().getActualState(iblockstate, world, pos);
if (tile instanceof ITieredTile) {
color = ((ITieredTile) tile).getTier().getColor();
}
if (iblockstate.getRenderType() != EnumBlockRenderType.INVISIBLE) {
int blockX = pos.getX();
int blockY = pos.getY();
int blockZ = pos.getZ();
AxisAlignedBB axisalignedbb = iblockstate.getBoundingBox(world, pos);
double particleX = (double) blockX + world.rand.nextDouble() * (axisalignedbb.maxX - axisalignedbb.minX
- OFFSET_1) + OFFSET_2 + axisalignedbb.minX;
double particleY = (double) blockY + world.rand.nextDouble() * (axisalignedbb.maxY - axisalignedbb.minY
- OFFSET_1) + OFFSET_2 + axisalignedbb.minY;
double particleZ = (double) blockZ + world.rand.nextDouble() * (axisalignedbb.maxZ - axisalignedbb.minZ
- OFFSET_1) + OFFSET_2 + axisalignedbb.minZ;
if (side == EnumFacing.DOWN) {
particleY = (double) blockY + axisalignedbb.minY - OFFSET_2;
}
if (side == EnumFacing.UP) {
particleY = (double) blockY + axisalignedbb.maxY + OFFSET_2;
}
if (side == EnumFacing.NORTH) {
particleZ = (double) blockZ + axisalignedbb.minZ - OFFSET_2;
}
if (side == EnumFacing.SOUTH) {
particleZ = (double) blockZ + axisalignedbb.maxZ + OFFSET_2;
}
if (side == EnumFacing.WEST) {
particleX = (double) blockX + axisalignedbb.minX - OFFSET_2;
}
if (side == EnumFacing.EAST) {
particleX = (double) blockX + axisalignedbb.maxX + OFFSET_2;
}
manager.addEffect(new TieredParticleDigging(world, particleX, particleY, particleZ, 0, 0, 0, iblockstate, color)
.setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
}
return true;
}
}
@@ -0,0 +1,33 @@
package mekanism.client.render.particle;
import javax.annotation.Nullable;
import mekanism.api.EnumColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleDigging;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class TieredParticleDigging extends ParticleDigging {
@Nullable
private final EnumColor color;
public TieredParticleDigging(World world, double xCoord, double yCoord, double zCoord, double xSpeed,
double ySpeed, double zSpeed, IBlockState state, EnumColor color) {
super(world, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, state);
this.color = color;
}
@Override
protected void multiplyColor(@Nullable BlockPos pos) {
if (color == null) {
return;
}
this.particleRed *= color.getColor(0);
this.particleGreen *= color.getColor(1);
this.particleBlue *= color.getColor(2);
}
}
@@ -1,10 +1,11 @@
package mekanism.client.render.transmitter;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import mekanism.client.render.MekanismRenderer;
import mekanism.common.ColourRGBA;
import mekanism.common.tile.transmitter.TileEntityTransmitter;
@@ -22,6 +23,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.Attributes;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.client.model.obj.OBJModel.OBJState;
import net.minecraftforge.client.model.pipeline.LightUtil;
import org.lwjgl.opengl.GL11;
@@ -47,15 +49,12 @@ public abstract class RenderTransmitterBase<T extends TileEntityTransmitter> ext
public static HashMap<String, IBakedModel> buildModelMap(OBJModel objModel) {
HashMap<String, IBakedModel> modelParts = new HashMap<>();
if (!objModel.getMatLib().getGroups().keySet().isEmpty()) {
for (String key : objModel.getMatLib().getGroups().keySet()) {
String k = key;
Set<String> keys = objModel.getMatLib().getGroups().keySet();
if (!keys.isEmpty()) {
for (String key : keys) {
if (!modelParts.containsKey(key)) {
modelParts.put(k, objModel
.bake(new OBJModel.OBJState(ImmutableList.of(k), false), Attributes.DEFAULT_BAKED_FORMAT,
textureGetterFlipV));
modelParts.put(key, objModel.bake(new OBJState(Collections.singletonList(key), false),
Attributes.DEFAULT_BAKED_FORMAT, textureGetterFlipV));
}
}
}
@@ -0,0 +1,8 @@
package mekanism.common.base;
import mekanism.common.tier.BaseTier;
public interface ITieredTile {
BaseTier getTier();
}
@@ -7,8 +7,8 @@ import mekanism.api.Coord4D;
import mekanism.api.IMekWrench;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.client.render.particle.MekanismParticleHelper;
import mekanism.common.Mekanism;
import mekanism.common.tier.FluidTankTier;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IBoundingBlock;
import mekanism.common.base.IFactory;
@@ -32,6 +32,7 @@ import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMess
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tier.FluidTankTier;
import mekanism.common.tile.TileEntityFactory;
import mekanism.common.tile.TileEntityFluidTank;
import mekanism.common.tile.TileEntityLaser;
@@ -56,6 +57,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -77,6 +79,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
@@ -806,6 +809,22 @@ public abstract class BlockMachine extends BlockContainer {
return itemStack;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager) {
if (!target.typeOfHit.equals(Type.BLOCK)) {
return super.addHitEffects(state, world, target, manager);
}
MachineType type = state.getValue(getTypeProperty());
//If it is one of the types that block state won't have a color for
if (type == MachineType.FLUID_TANK) {
if (MekanismParticleHelper.addBlockHitEffects(world, target.getBlockPos(), target.sideHit, manager)) {
return true;
}
}
return super.addHitEffects(state, world, target, manager);
}
@Override
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
MachineType type = MachineType.get(getMachineBlock(), state.getBlock().getMetaFromState(state));
@@ -6,9 +6,9 @@ import java.util.Random;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import mekanism.api.IMekWrench;
import mekanism.client.render.particle.MekanismParticleHelper;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.tier.BaseTier;
import mekanism.common.base.ITierItem;
import mekanism.common.block.property.PropertyConnection;
import mekanism.common.block.states.BlockStateTransmitter;
@@ -16,6 +16,7 @@ import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.integration.wrenches.Wrenches;
import mekanism.common.tier.BaseTier;
import mekanism.common.tile.transmitter.TileEntityDiversionTransporter;
import mekanism.common.tile.transmitter.TileEntityLogisticalTransporter;
import mekanism.common.tile.transmitter.TileEntityMechanicalPipe;
@@ -33,6 +34,7 @@ import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -49,6 +51,7 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -286,6 +289,16 @@ public class BlockTransmitter extends Block implements ITileEntityProvider {
return itemStack;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World world, RayTraceResult target, ParticleManager manager) {
if (!target.typeOfHit.equals(Type.BLOCK)) {
return super.addHitEffects(state, world, target, manager);
}
return MekanismParticleHelper.addBlockHitEffects(world, target.getBlockPos(), target.sideHit, manager) ||
super.addHitEffects(state, world, target, manager);
}
public ItemStack dismantleBlock(IBlockState state, World world, BlockPos pos, boolean returnBlock) {
ItemStack itemStack = getPickBlock(state, null, world, pos, null);
@@ -8,8 +8,6 @@ import mekanism.api.IConfigurable;
import mekanism.api.Range4D;
import mekanism.api.TileNetworkList;
import mekanism.common.Mekanism;
import mekanism.common.tier.BaseTier;
import mekanism.common.tier.FluidTankTier;
import mekanism.common.base.FluidHandlerWrapper;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IFluidContainerManager;
@@ -17,10 +15,13 @@ import mekanism.common.base.IFluidHandlerWrapper;
import mekanism.common.base.ISustainedTank;
import mekanism.common.base.ITankManager;
import mekanism.common.base.ITierUpgradeable;
import mekanism.common.base.ITieredTile;
import mekanism.common.capabilities.Capabilities;
import mekanism.common.config.MekanismConfig;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tier.BaseTier;
import mekanism.common.tier.FluidTankTier;
import mekanism.common.tile.component.TileComponentSecurity;
import mekanism.common.tile.prefab.TileEntityContainerBlock;
import mekanism.common.util.CapabilityUtils;
@@ -51,7 +52,8 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.items.CapabilityItemHandler;
public class TileEntityFluidTank extends TileEntityContainerBlock implements IActiveState, IConfigurable,
IFluidHandlerWrapper, ISustainedTank, IFluidContainerManager, ITankManager, ISecurityTile, ITierUpgradeable {
IFluidHandlerWrapper, ISustainedTank, IFluidContainerManager, ITankManager, ISecurityTile, ITierUpgradeable,
ITieredTile {
public boolean isActive;
@@ -574,4 +576,9 @@ public class TileEntityFluidTank extends TileEntityContainerBlock implements IAc
public TileComponentSecurity getSecurity() {
return securityComponent;
}
@Override
public BaseTier getTier() {
return tier.getBaseTier();
}
}