Fix multipart breaking

This commit is contained in:
aidancbrady committed 2017-03-29 18:44:41 -04:00
1 parent 3fccbada96
commit 2071cb3760
7 files changed
+301 -59

No files matched your search

@@ -28,6 +28,7 @@ import mekanism.client.gui.GuiThermalEvaporationController;
import mekanism.client.gui.element.GuiProgress.ProgressBar;
import mekanism.client.jei.crafting.ShapedMekanismRecipeHandler;
import mekanism.client.jei.crafting.ShapelessMekanismRecipeHandler;
import mekanism.client.jei.gas.GasStackRenderer;
import mekanism.client.jei.machine.AdvancedMachineRecipeCategory;
import mekanism.client.jei.machine.AdvancedMachineRecipeHandler;
import mekanism.client.jei.machine.AdvancedMachineRecipeWrapper;
@@ -111,12 +112,9 @@ import mezz.jei.api.IModRegistry;
import mezz.jei.api.ISubtypeRegistry;
import mezz.jei.api.ISubtypeRegistry.ISubtypeInterpreter;
import mezz.jei.api.JEIPlugin;
import mezz.jei.api.ingredients.IIngredientRenderer;
import mezz.jei.api.ingredients.IModIngredientRegistration;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
@@ -162,26 +160,7 @@ public class MekanismJEI extends BlankModPlugin
public void registerIngredients(IModIngredientRegistration registry)
{
List<GasStack> list = GasRegistry.getRegisteredGasses().stream().filter(g -> g.isVisible()).map(g -> new GasStack(g, Fluid.BUCKET_VOLUME)).collect(Collectors.toList());
registry.register(GasStack.class, list, new GasStackHelper(), new IIngredientRenderer() {
@Override
public void render(Minecraft minecraft, int xPosition, int yPosition, Object ingredient)
{
}
@Override
public List getTooltip(Minecraft minecraft, Object ingredient)
{
List<String> tooltip = new ArrayList<String>();
return tooltip;
}
@Override
public FontRenderer getFontRenderer(Minecraft minecraft, Object ingredient)
{
return minecraft.fontRendererObj;
}
});
registry.register(GasStack.class, list, new GasStackHelper(), new GasStackRenderer());
}
@Override
@@ -0,0 +1,230 @@
package mekanism.client.jei.gas;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.ingredients.IIngredientRenderer;
import mezz.jei.util.Translator;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid;
public class GasStackRenderer implements IIngredientRenderer<GasStack>
{
private static final int TEX_WIDTH = 16;
private static final int TEX_HEIGHT = 16;
private static final int MIN_FLUID_HEIGHT = 1; // ensure tiny amounts of gas are still visible
private final int capacityMb;
private final TooltipMode tooltipMode;
private final int width;
private final int height;
@Nullable
private final IDrawable overlay;
enum TooltipMode
{
SHOW_AMOUNT,
SHOW_AMOUNT_AND_CAPACITY,
ITEM_LIST
}
public GasStackRenderer()
{
this(Fluid.BUCKET_VOLUME, TooltipMode.ITEM_LIST, TEX_WIDTH, TEX_HEIGHT, null);
}
public GasStackRenderer(int capacityMb, boolean showCapacity, int width, int height, @Nullable IDrawable overlay)
{
this(capacityMb, showCapacity ? TooltipMode.SHOW_AMOUNT_AND_CAPACITY : TooltipMode.SHOW_AMOUNT, width, height, overlay);
}
public GasStackRenderer(int capacityMb, TooltipMode tooltipMode, int width, int height, @Nullable IDrawable overlay)
{
this.capacityMb = capacityMb;
this.tooltipMode = tooltipMode;
this.width = width;
this.height = height;
this.overlay = overlay;
}
@Override
public void render(Minecraft minecraft, final int xPosition, final int yPosition, @Nullable GasStack gasStack)
{
GlStateManager.enableBlend();
GlStateManager.enableAlpha();
drawGas(minecraft, xPosition, yPosition, gasStack);
GlStateManager.color(1, 1, 1, 1);
if(overlay != null)
{
GlStateManager.pushMatrix();
GlStateManager.translate(0, 0, 200);
overlay.draw(minecraft, xPosition, yPosition);
GlStateManager.popMatrix();
}
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
private void drawGas(Minecraft minecraft, final int xPosition, final int yPosition, @Nullable GasStack gasStack)
{
if(gasStack == null)
{
return;
}
Gas gas = gasStack.getGas();
if(gas == null)
{
return;
}
TextureAtlasSprite gasStillSprite = getStillGasSprite(minecraft, gas);
int gasColor = 0xFFFFFFFF;
int scaledAmount = (gasStack.amount * height) / capacityMb;
if(gasStack.amount > 0 && scaledAmount < MIN_FLUID_HEIGHT)
{
scaledAmount = MIN_FLUID_HEIGHT;
}
if(scaledAmount > height)
{
scaledAmount = height;
}
drawTiledSprite(minecraft, xPosition, yPosition, width, height, gasColor, scaledAmount, gasStillSprite);
}
private void drawTiledSprite(Minecraft minecraft, final int xPosition, final int yPosition, final int tiledWidth, final int tiledHeight, int color, int scaledAmount, TextureAtlasSprite sprite)
{
minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
setGLColorFromInt(color);
final int xTileCount = tiledWidth / TEX_WIDTH;
final int xRemainder = tiledWidth - (xTileCount * TEX_WIDTH);
final int yTileCount = scaledAmount / TEX_HEIGHT;
final int yRemainder = scaledAmount - (yTileCount * TEX_HEIGHT);
final int yStart = yPosition + tiledHeight;
for(int xTile = 0; xTile <= xTileCount; xTile++)
{
for(int yTile = 0; yTile <= yTileCount; yTile++)
{
int width = (xTile == xTileCount) ? xRemainder : TEX_WIDTH;
int height = (yTile == yTileCount) ? yRemainder : TEX_HEIGHT;
int x = xPosition + (xTile * TEX_WIDTH);
int y = yStart - ((yTile + 1) * TEX_HEIGHT);
if(width > 0 && height > 0)
{
int maskTop = TEX_HEIGHT - height;
int maskRight = TEX_WIDTH - width;
drawTextureWithMasking(x, y, sprite, maskTop, maskRight, 100);
}
}
}
}
private static TextureAtlasSprite getStillGasSprite(Minecraft minecraft, Gas gas)
{
TextureMap textureMapBlocks = minecraft.getTextureMapBlocks();
ResourceLocation gasStill = gas.getIcon();
TextureAtlasSprite gasStillSprite = null;
if(gasStill != null)
{
gasStillSprite = textureMapBlocks.getTextureExtry(gasStill.toString());
}
if(gasStillSprite == null)
{
gasStillSprite = textureMapBlocks.getMissingSprite();
}
return gasStillSprite;
}
private static void setGLColorFromInt(int color)
{
float red = (color >> 16 & 0xFF) / 255.0F;
float green = (color >> 8 & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GlStateManager.color(red, green, blue, 1.0F);
}
private static void drawTextureWithMasking(double xCoord, double yCoord, TextureAtlasSprite textureSprite, int maskTop, int maskRight, double zLevel)
{
double uMin = (double) textureSprite.getMinU();
double uMax = (double) textureSprite.getMaxU();
double vMin = (double) textureSprite.getMinV();
double vMax = (double) textureSprite.getMaxV();
uMax = uMax - (maskRight / 16.0 * (uMax - uMin));
vMax = vMax - (maskTop / 16.0 * (vMax - vMin));
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexBuffer = tessellator.getBuffer();
vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX);
vertexBuffer.pos(xCoord, yCoord + 16, zLevel).tex(uMin, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + 16, zLevel).tex(uMax, vMax).endVertex();
vertexBuffer.pos(xCoord + 16 - maskRight, yCoord + maskTop, zLevel).tex(uMax, vMin).endVertex();
vertexBuffer.pos(xCoord, yCoord + maskTop, zLevel).tex(uMin, vMin).endVertex();
tessellator.draw();
}
@Override
public List<String> getTooltip(Minecraft minecraft, GasStack gasStack)
{
List<String> tooltip = new ArrayList<String>();
Gas gasType = gasStack.getGas();
if(gasType == null)
{
return tooltip;
}
String gasName = gasType.getLocalizedName();
tooltip.add(gasName);
if(tooltipMode == TooltipMode.SHOW_AMOUNT_AND_CAPACITY)
{
String amount = Translator.translateToLocalFormatted("jei.tooltip.liquid.amount.with.capacity", gasStack.amount, capacityMb);
tooltip.add(TextFormatting.GRAY + amount);
}
else if (tooltipMode == TooltipMode.SHOW_AMOUNT)
{
String amount = Translator.translateToLocalFormatted("jei.tooltip.liquid.amount", gasStack.amount);
tooltip.add(TextFormatting.GRAY + amount);
}
return tooltip;
}
@Override
public FontRenderer getFontRenderer(Minecraft minecraft, GasStack gasStack) {
return minecraft.fontRendererObj;
}
}
@@ -132,21 +132,23 @@ public class TransmitterModel extends OBJBakedModelBase
color = -1;
}
int hash = Objects.hash(layer.ordinal(), color, PropertyConnection.INSTANCE.valueToString(extended.getValue(PropertyConnection.INSTANCE)));
if(obj.getVisibilityMap().containsKey(Group.ALL) || obj.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
{
updateStateVisibilityMap(obj);
}
if(!modelCache.containsKey(hash))
{
TransmitterModel model = new TransmitterModel(baseModel, getModel(), obj, vertexFormat, textureMap, transformationMap);
model.tempState = state;
modelCache.put(hash, model.getQuads(state, side, rand));
}
return modelCache.get(hash);
try {
int hash = Objects.hash(layer.ordinal(), color, PropertyConnection.INSTANCE.valueToString(extended.getValue(PropertyConnection.INSTANCE)));
if(obj.getVisibilityMap().containsKey(Group.ALL) || obj.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
{
updateStateVisibilityMap(obj);
}
if(!modelCache.containsKey(hash))
{
TransmitterModel model = new TransmitterModel(baseModel, getModel(), obj, vertexFormat, textureMap, transformationMap);
model.tempState = state;
modelCache.put(hash, model.getQuads(state, side, rand));
}
return modelCache.get(hash);
} catch(Exception e) {}
}
return super.getQuads(state, side, rand);
@@ -89,6 +89,7 @@ import mekanism.common.tile.TileEntityElectricPump;
import mekanism.common.tile.TileEntityElectrolyticSeparator;
import mekanism.common.tile.TileEntityFluidicPlenisher;
import mekanism.common.tile.TileEntityFuelwoodHeater;
import mekanism.common.tile.TileEntityGlowPanel;
import mekanism.common.tile.TileEntityInductionCasing;
import mekanism.common.tile.TileEntityInductionCell;
import mekanism.common.tile.TileEntityInductionPort;
@@ -1223,6 +1224,7 @@ public class Mekanism
GameRegistry.registerTileEntity(TileEntityRotaryCondensentrator.class, "RotaryCondensentrator");
GameRegistry.registerTileEntity(TileEntityElectricPump.class, "ElectricPump");
GameRegistry.registerTileEntity(TileEntityFluidicPlenisher.class, "FluidicPlenisher");
GameRegistry.registerTileEntity(TileEntityGlowPanel.class, "GlowPanel");
//Load tile entities that have special renderers.
proxy.registerSpecialTileEntities();
@@ -9,6 +9,7 @@ import mekanism.common.block.property.PropertyColor;
import mekanism.common.block.states.BlockStateFacing;
import mekanism.common.block.states.BlockStateGlowPanel;
import mekanism.common.integration.multipart.MultipartMekanism;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityGlowPanel;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
@@ -52,6 +53,8 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
{
super(Material.PISTON);
setCreativeTab(Mekanism.tabMekanism);
setHardness(1F);
setResistance(10F);
}
@Override
@@ -145,12 +148,6 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
return super.getBoundingBox(state, world, pos);
}
@Override
public float getBlockHardness(IBlockState state, World world, BlockPos pos)
{
return 3.5F;
}
@Override
public boolean canPlaceBlockOnSide(World world, BlockPos pos, EnumFacing side)
{
@@ -170,9 +167,9 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
}
@Override
public int damageDropped(IBlockState state)
public int quantityDropped(Random random)
{
return ((IExtendedBlockState)state).getValue(PropertyColor.INSTANCE).color.getMetaValue();
return 0;
}
@Override
@@ -182,6 +179,24 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
return new ItemStack(MekanismBlocks.GlowPanel, 1, tileEntity.colour.getMetaValue());
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
if(!player.capabilities.isCreativeMode && !world.isRemote && willHarvest)
{
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, pos.getX() + motionX, pos.getY() + motionY, pos.getZ() + motionZ, getPickBlock(state, null, world, pos, player));
world.spawnEntity(entityItem);
}
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
{
@@ -88,6 +88,8 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
{
super(Material.PISTON);
setCreativeTab(Mekanism.tabMekanism);
setHardness(1F);
setResistance(10F);
}
@Override
@@ -117,12 +119,6 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
return type.ordinal();
}
@Override
public float getBlockHardness(IBlockState state, World world, BlockPos pos)
{
return 3.5F;
}
@Override
public BlockStateContainer createBlockState()
{
@@ -231,7 +227,7 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
TileEntitySidedPipe tileEntity = (TileEntitySidedPipe)world.getTileEntity(pos);
ItemStack itemStack = new ItemStack(MekanismBlocks.EnergyCube);
ItemStack itemStack = new ItemStack(MekanismBlocks.Transmitter, 1, tileEntity.getTransmitterType().ordinal());
if(!itemStack.hasTagCompound())
{
@@ -358,13 +354,25 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
{
return 0;
}
@Override
public Item getItemDropped(IBlockState state, Random random, int fortune)
{
return null;
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
if(!player.capabilities.isCreativeMode && !world.isRemote && willHarvest)
{
float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionY = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
double motionZ = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
EntityItem entityItem = new EntityItem(world, pos.getX() + motionX, pos.getY() + motionY, pos.getZ() + motionZ, getPickBlock(state, null, world, pos, player));
world.spawnEntity(entityItem);
}
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
private static AxisAlignedBB getDefaultForTile(TileEntitySidedPipe tile)
{
if(tile == null || tile.getTransmitterType().getSize() == Size.SMALL)
@@ -684,6 +684,12 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
{
MekanismUtils.notifyLoadedNeighborsOfTileChange(getWorld(), new Coord4D(getPos(), getWorld()));
}
@Override
public boolean canRenderBreaking()
{
return false;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)