Added transporter beacon rendering

This commit is contained in:
Unknown 2019-04-23 01:55:40 +02:00 committed by unknown
parent 57a2c222f1
commit 6365b3ab98
12 changed files with 262 additions and 205 deletions

View file

@ -17,6 +17,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
@ -80,9 +81,20 @@ public class BlockTransporterBeacon extends BlockAbstractContainer {
@Override
public void modelInitialisation() {
super.modelInitialisation();
// Bind our TESR to our tile entity
// @TODO ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTransporterBeacon.class, new TileEntityForceFieldProjectorRenderer());
}
@Override
public boolean isNormalCube(final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos) {
return false;
}
@SuppressWarnings("deprecation")
@Override
public boolean isBlockNormalCube(final IBlockState blockState) {
// not supposed to be called, upstream should use isNormalCube(IBlockState, IBlockAccess, BlockPos) instead
// practically, Forge still use it in WorldEntitySpawner.isValidEmptySpawnBlock(), Block.getAmbientOcclusionLightValue(), BlockRedstoneWire.getAttachPosition()
// calling BlockStateContainer$StateImplementation.isBlockNormalCube()
return false;
}
@SuppressWarnings("deprecation")
@ -91,6 +103,25 @@ public class BlockTransporterBeacon extends BlockAbstractContainer {
return false;
}
@SuppressWarnings("deprecation")
@Override
public boolean isFullCube(final IBlockState blockState) {
return false;
}
@SuppressWarnings("deprecation")
@Override
public boolean isFullBlock(final IBlockState blockState) {
return false;
}
@Nonnull
@SideOnly(Side.CLIENT)
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@SuppressWarnings("deprecation")
@Nonnull
@Override

View file

@ -9,17 +9,22 @@ import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.EnergyWrapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
@ -27,6 +32,9 @@ import net.minecraft.world.World;
import java.util.UUID;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockTransporterBeacon extends ItemBlockAbstractBase implements IItemTransporterBeacon {
public ItemBlockTransporterBeacon(final Block block) {
@ -34,6 +42,25 @@ public class ItemBlockTransporterBeacon extends ItemBlockAbstractBase implements
setMaxStackSize(1);
setMaxDamage(100 * 8);
addPropertyOverride(new ResourceLocation(WarpDrive.MODID, "active"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
@Override
public float apply(@Nonnull final ItemStack itemStack, @Nullable final World world, @Nullable final EntityLivingBase entity) {
final boolean isActive = isActive(itemStack);
return isActive ? 1.0F : 0.0F;
}
});
}
@Nonnull
@SideOnly(Side.CLIENT)
@Override
public ModelResourceLocation getModelResourceLocation(@Nonnull final ItemStack itemStack) {
// suffix registry name to grab the item model so we can use overrides
final ResourceLocation resourceLocation = getRegistryName();
assert resourceLocation != null;
return new ModelResourceLocation(resourceLocation.toString() + "-item", "inventory");
}
private static String getTransporterName(final ItemStack itemStack) {

View file

@ -62,10 +62,6 @@ public class ClientProxy extends CommonProxy {
// entity rendering
// RenderingRegistry.registerEntityRenderingHandler(EntityParticleBunch.class, new RenderEntityParticleBunch());
// @TODO MC1.10 force field rendering
/*
RenderBlockTransporterBeacon.renderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(RenderBlockTransporterBeacon.instance);
/**/
}
@Override

View file

@ -1,184 +0,0 @@
package cr0s.warpdrive.render;
public class RenderBlockTransporterBeacon {
}
/* @TODO MC1.10 ISBRH
public class RenderBlockTransporterBeacon implements ISimpleBlockRenderingHandler {
public static int renderId = 0;
public static RenderBlockTransporterBeacon instance = new RenderBlockTransporterBeacon();
private static final double CORE_RADIUS = 2.0D / 32.0D;
private static final double CORE_Y_MIN_PACKED_INACTIVE = 0.0D / 32.0D;
private static final double CORE_Y_MIN_PACKED_ACTIVE = 0.0D / 32.0D;
private static final double CORE_Y_MIN_DEPLOYED_INACTIVE = 1.0D / 32.0D;
private static final double CORE_Y_MIN_DEPLOYED_ACTIVE = 1.0D / 32.0D;
private static final double CORE_Y_MAX_PACKED_INACTIVE = 11.0D / 32.0D;
private static final double CORE_Y_MAX_PACKED_ACTIVE = 15.0D / 32.0D;
private static final double CORE_Y_MAX_DEPLOYED_INACTIVE = 12.0D / 32.0D;
private static final double CORE_Y_MAX_DEPLOYED_ACTIVE = 20.0D / 32.0D;
private static final double BRANCH_HEIGHT = 24.0D / 32.0D;
private static final double BRANCH_RADIUS = 16.0D / 32.0D;
@Override
public void renderInventoryBlock(final Block block, final int metadata, final int modelId, final RenderBlocks renderer) {
if (!(block instanceof BlockTransporterBeacon)) {
return;
}
final isActive = (metadata & 0x2) != 0;
final isDeployed = (metadata & 0x1) != 0;
final IIcon icon = RenderBlocks.getInstance().getBlockIconFromSideAndMetadata(block, 0, enumTransporterBeaconState.getMetadata());
GL11.glPushMatrix();
final Tessellator tessellator = Tessellator.instance;
// (block bounds aren't used in our render => no need to grab them here)
// disable lightning in item rendering, no need to set brightness
GL11.glDisable(GL11.GL_LIGHTING);
// (blending already by caller)
// (color already set by caller?)
// (transformation already done by caller)
tessellator.startDrawingQuads();
renderTransporterBeacon(tessellator, 0.0D, 0.0D, 0.0D, isActive, isDeployed, icon);
tessellator.draw();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
@Override
public boolean renderWorldBlock(final IBlockAccess blockAccess, final int x, final int y, final int z, final Block block, final int modelId, final RenderBlocks renderer) {
if (!(block instanceof BlockTransporterBeacon)) {
return false;
}
final TileEntity tileEntity = blockAccess.getTileEntity(x, y, z);
if (!(tileEntity instanceof TileEntityTransporterBeacon)) {
return false;
}
final int metadata = blockAccess.getBlockMetadata(x, y, z);
final EnumTransporterBeaconState enumTransporterBeaconState = EnumTransporterBeaconState.get(metadata);
if (enumTransporterBeaconState == null) {
return false;
}
final IIcon icon = RenderBlocks.getInstance().getBlockIconFromSideAndMetadata(block, 0, metadata);
renderTransporterBeacon(tessellator, x, y, z, enumTransporterBeaconState, icon);
return true;
}
private void renderTransporterBeacon(final Tessellator tessellator,
final double x, final double y, final double z,
final boolean isActive, final boolean isDeployed,
final IIcon icon) {
final Tessellator tessellator = Tessellator.instance;
// texture coordinates
final double uMin_side = icon.getInterpolatedU( 0.0D);
final double vMin_side = icon.getInterpolatedV( 4.0D);
final double uMax_side = icon.getInterpolatedU(16.0D);
final double vMax_side = icon.getInterpolatedV(16.0D);
final double uMin_top = icon.getInterpolatedU( 1.0D);
final double vMin_top = icon.getInterpolatedV( 1.0D);
final double uMax_top = icon.getInterpolatedU( 3.0D);
final double vMax_top = icon.getInterpolatedV( 3.0D);
final double uMin_bottom = icon.getInterpolatedU( 5.0D);
final double vMin_bottom = icon.getInterpolatedV( 1.0D);
final double uMax_bottom = icon.getInterpolatedU( 7.0D);
final double vMax_bottom = icon.getInterpolatedV( 3.0D);
// vertex coordinates
final double xCenter = x + 0.5D;
final double zCenter = z + 0.5D;
final double xMin_core = xCenter - CORE_RADIUS;
final double xMax_core = xCenter + CORE_RADIUS;
final double zMin_core = zCenter - CORE_RADIUS;
final double zMax_core = zCenter + CORE_RADIUS;
final double xMin_branch = xCenter - BRANCH_RADIUS;
final double xMax_branch = xCenter + BRANCH_RADIUS;
final double zMin_branch = zCenter - BRANCH_RADIUS;
final double zMax_branch = zCenter + BRANCH_RADIUS;
final double yMin_branch = y + 0.0D;
final double yMin_core;
final double yMax_core;
switch (enumTransporterBeaconState) {
default:
case PACKED_INACTIVE:
yMin_core = y + CORE_Y_MIN_PACKED_INACTIVE;
yMax_core = y + CORE_Y_MAX_PACKED_INACTIVE;
break;
case PACKED_ACTIVE:
yMin_core = y + CORE_Y_MIN_PACKED_ACTIVE;
yMax_core = y + CORE_Y_MAX_PACKED_ACTIVE;
break;
case DEPLOYED_INACTIVE:
yMin_core = y + CORE_Y_MIN_DEPLOYED_INACTIVE;
yMax_core = y + CORE_Y_MAX_DEPLOYED_INACTIVE;
break;
case DEPLOYED_ACTIVE:
yMin_core = y + CORE_Y_MIN_DEPLOYED_ACTIVE;
yMax_core = y + CORE_Y_MAX_DEPLOYED_ACTIVE;
break;
}
final double yMax_branch = y + BRANCH_HEIGHT;
// add top face
tessellator.addVertexWithUV(xMin_core , yMax_core , zMin_core , uMin_top, vMin_top);
tessellator.addVertexWithUV(xMin_core , yMax_core , zMax_core , uMin_top, vMax_top);
tessellator.addVertexWithUV(xMax_core , yMax_core , zMax_core , uMax_top, vMax_top);
tessellator.addVertexWithUV(xMax_core , yMax_core , zMin_core , uMax_top, vMin_top);
// add bottom face
tessellator.addVertexWithUV(xMax_core , yMin_core , zMin_core , uMax_bottom, vMin_bottom);
tessellator.addVertexWithUV(xMax_core , yMin_core , zMax_core , uMax_bottom, vMax_bottom);
tessellator.addVertexWithUV(xMin_core , yMin_core , zMax_core , uMin_bottom, vMax_bottom);
tessellator.addVertexWithUV(xMin_core , yMin_core , zMin_core , uMin_bottom, vMin_bottom);
// add side/branch faces
tessellator.addVertexWithUV(xMin_core , yMax_branch, zMin_branch, uMin_side, vMin_side);
tessellator.addVertexWithUV(xMin_core , yMin_branch, zMin_branch, uMin_side, vMax_side);
tessellator.addVertexWithUV(xMin_core , yMin_branch, zMax_branch, uMax_side, vMax_side);
tessellator.addVertexWithUV(xMin_core , yMax_branch, zMax_branch, uMax_side, vMin_side);
tessellator.addVertexWithUV(xMax_core , yMax_branch, zMax_branch, uMin_side, vMin_side);
tessellator.addVertexWithUV(xMax_core , yMin_branch, zMax_branch, uMin_side, vMax_side);
tessellator.addVertexWithUV(xMax_core , yMin_branch, zMin_branch, uMax_side, vMax_side);
tessellator.addVertexWithUV(xMax_core , yMax_branch, zMin_branch, uMax_side, vMin_side);
tessellator.addVertexWithUV(xMin_branch, yMax_branch, zMax_core , uMin_side, vMin_side);
tessellator.addVertexWithUV(xMin_branch, yMin_branch, zMax_core , uMin_side, vMax_side);
tessellator.addVertexWithUV(xMax_branch, yMin_branch, zMax_core , uMax_side, vMax_side);
tessellator.addVertexWithUV(xMax_branch, yMax_branch, zMax_core , uMax_side, vMin_side);
tessellator.addVertexWithUV(xMax_branch, yMax_branch, zMin_core , uMin_side, vMin_side);
tessellator.addVertexWithUV(xMax_branch, yMin_branch, zMin_core , uMin_side, vMax_side);
tessellator.addVertexWithUV(xMin_branch, yMin_branch, zMin_core , uMax_side, vMax_side);
tessellator.addVertexWithUV(xMin_branch, yMax_branch, zMin_core , uMax_side, vMin_side);
}
@Override
public boolean shouldRender3DInInventory(final int modelId) {
return true;
}
@Override
public int getRenderId() {
return renderId;
}
}
/**/

View file

@ -5,21 +5,28 @@
},
"variants": {
"normal": [{}],
"inventory": { "model": "minecraft:normal_torch", "textures": {
"inventory": {
"model": "minecraft:normal_torch",
"textures": {
"torch" : "warpdrive:blocks/movement/transporter_beacon-deployed_active"
} },
}
},
"active=false,deployed=false": { "model": "minecraft:normal_torch", "textures": {
"torch" : "warpdrive:blocks/movement/transporter_beacon-packed_inactive"
} },
"active=true,deployed=false" : { "model": "minecraft:normal_torch", "textures": {
"torch" : "warpdrive:blocks/movement/transporter_beacon-packed_active"
} },
"active=false,deployed=true" : { "model": "minecraft:normal_torch", "textures": {
"torch" : "warpdrive:blocks/movement/transporter_beacon-deployed_inactive"
} },
"active=true,deployed=true" : { "model": "minecraft:normal_torch", "textures": {
"torch" : "warpdrive:blocks/movement/transporter_beacon-deployed_active"
} }
"active=false,deployed=false": {
"model": "warpdrive:movement/transporter_beacon-packed_inactive",
"textures": { "beacon" : "warpdrive:blocks/movement/transporter_beacon-packed_inactive" }
},
"active=true,deployed=false" : {
"model": "warpdrive:movement/transporter_beacon-packed_active",
"textures": { "beacon" : "warpdrive:blocks/movement/transporter_beacon-packed_active" }
},
"active=false,deployed=true" : {
"model": "warpdrive:movement/transporter_beacon-deployed_inactive",
"textures": { "beacon" : "warpdrive:blocks/movement/transporter_beacon-deployed_inactive" }
},
"active=true,deployed=true" : {
"model": "warpdrive:movement/transporter_beacon-deployed_active",
"textures": { "beacon" : "warpdrive:blocks/movement/transporter_beacon-deployed_active" }
}
}
}

View file

@ -0,0 +1,38 @@
{
"ambientocclusion": false,
"textures": {
"particle": "#beacon"
},
"elements": [
{
"__comments": "core",
"from": [ 7.0, 0.5, 7.0 ],
"to": [ 9.0, 10.0, 9.0 ],
"shade": false,
"faces": {
"down": { "uv": [ 5, 1, 7, 3 ], "texture": "#beacon" },
"up": { "uv": [ 1, 1, 3, 3 ], "texture": "#beacon" }
}
},
{
"__comments": "z planes",
"from": [ 7.0, 0.0, 0.0 ],
"to": [ 9.0, 12.0, 16.0 ],
"shade": false,
"faces": {
"west": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"east": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
},
{
"__comments": "x planes",
"from": [ 0, 0, 7 ],
"to": [ 16, 12, 9 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"south": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
}
]
}

View file

@ -0,0 +1,38 @@
{
"ambientocclusion": false,
"textures": {
"particle": "#beacon"
},
"elements": [
{
"__comments": "core",
"from": [ 7.0, 0.5, 7.0 ],
"to": [ 9.0, 6.0, 9.0 ],
"shade": false,
"faces": {
"down": { "uv": [ 5, 1, 7, 3 ], "texture": "#beacon" },
"up": { "uv": [ 1, 1, 3, 3 ], "texture": "#beacon" }
}
},
{
"__comments": "z planes",
"from": [ 7.0, 0.0, 0.0 ],
"to": [ 9.0, 12.0, 16.0 ],
"shade": false,
"faces": {
"west": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"east": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
},
{
"__comments": "x planes",
"from": [ 0, 0, 7 ],
"to": [ 16, 12, 9 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"south": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
}
]
}

View file

@ -0,0 +1,38 @@
{
"ambientocclusion": false,
"textures": {
"particle": "#beacon"
},
"elements": [
{
"__comments": "core",
"from": [ 7.0, 0.0, 7.0 ],
"to": [ 9.0, 7.5, 9.0 ],
"shade": false,
"faces": {
"down": { "uv": [ 5, 1, 7, 3 ], "texture": "#beacon" },
"up": { "uv": [ 1, 1, 3, 3 ], "texture": "#beacon" }
}
},
{
"__comments": "z planes",
"from": [ 7.0, 0.0, 0.0 ],
"to": [ 9.0, 12.0, 16.0 ],
"shade": false,
"faces": {
"west": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"east": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
},
{
"__comments": "x planes",
"from": [ 0, 0, 7 ],
"to": [ 16, 12, 9 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"south": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
}
]
}

View file

@ -0,0 +1,38 @@
{
"ambientocclusion": false,
"textures": {
"particle": "#beacon"
},
"elements": [
{
"__comments": "core",
"from": [ 7.0, 0.0, 7.0 ],
"to": [ 9.0, 5.5, 9.0 ],
"shade": false,
"faces": {
"down": { "uv": [ 5, 1, 7, 3 ], "texture": "#beacon" },
"up": { "uv": [ 1, 1, 3, 3 ], "texture": "#beacon" }
}
},
{
"__comments": "z planes",
"from": [ 7.0, 0.0, 0.0 ],
"to": [ 9.0, 12.0, 16.0 ],
"shade": false,
"faces": {
"west": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"east": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
},
{
"__comments": "x planes",
"from": [ 0, 0, 7 ],
"to": [ 16, 12, 9 ],
"shade": false,
"faces": {
"north": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" },
"south": { "uv": [ 0, 4, 16, 16 ], "texture": "#beacon" }
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "warpdrive:block/movement/transporter_beacon-deployed_active",
"textures": {
"beacon": "warpdrive:blocks/movement/transporter_beacon-deployed_active"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "warpdrive:block/movement/transporter_beacon-packed_inactive",
"textures": {
"beacon": "warpdrive:blocks/movement/transporter_beacon-packed_inactive"
}
}

View file

@ -0,0 +1,16 @@
{
"parent": "item/generated",
"textures": {
"layer0": "warpdrive:blocks/movement/transporter_beacon-packed_inactive"
},
"overrides": [
{
"predicate": { "warpdrive:active": 0.00 },
"model": "warpdrive:item/movement/transporter_beacon-packed_inactive"
},
{
"predicate": { "warpdrive:active": 0.99 },
"model": "warpdrive:item/movement/transporter_beacon-deployed_active"
}
]
}