i did nothing productive all day

This commit is contained in:
Bob 2022-05-30 19:45:51 +02:00
parent 943e243573
commit 8d8116b3d0
5 changed files with 118 additions and 80 deletions

View File

@ -1,43 +1,70 @@
package com.hbm.blocks.network; package com.hbm.blocks.network;
import com.hbm.entity.item.EntityMovingItem; import com.hbm.entity.item.EntityMovingItem;
import com.hbm.lib.RefStrings;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockConveyor extends Block { public class BlockConveyor extends Block {
@SideOnly(Side.CLIENT)
protected IIcon sideIcon;
public BlockConveyor(Material p_i45394_1_) { public BlockConveyor(Material p_i45394_1_) {
super(p_i45394_1_); super(p_i45394_1_);
} }
@Override @Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { @SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
super.registerBlockIcons(iconRegister);
this.sideIcon = iconRegister.registerIcon(RefStrings.MODID + ":conveyor_side");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
if((metadata == 2 || metadata == 3) && (side == 4 || side == 5))
return this.sideIcon;
if((metadata == 4 || metadata == 5) && (side == 2 || side == 3))
return this.sideIcon;
return super.getIcon(side, metadata);
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
if(!world.isRemote) { if(!world.isRemote) {
if(entity instanceof EntityItem && entity.ticksExisted > 10 && !entity.isDead) { if(entity instanceof EntityItem && entity.ticksExisted > 10 && !entity.isDead) {
EntityMovingItem item = new EntityMovingItem(world); EntityMovingItem item = new EntityMovingItem(world);
item.setItemStack(((EntityItem)entity).getEntityItem()); item.setItemStack(((EntityItem) entity).getEntityItem());
item.setPositionAndRotation(x + 0.5, y + 0.125, z + 0.5, 0, 0); item.setPositionAndRotation(x + 0.5, y + 0.25, z + 0.5, 0, 0);
world.spawnEntityInWorld(item); world.spawnEntityInWorld(item);
entity.setDead(); entity.setDead();
} }
} }
} }
public static int renderID = RenderingRegistry.getNextAvailableRenderId(); public static int renderID = RenderingRegistry.getNextAvailableRenderId();
@Override @Override
public int getRenderType() { public int getRenderType() {
@ -53,35 +80,31 @@ public class BlockConveyor extends Block {
public boolean renderAsNormalBlock() { public boolean renderAsNormalBlock() {
return false; return false;
} }
@Override @Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
} }
@Override @Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y, z + 1); return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 0.25, z + 1);
} }
@Override @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) { public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; int i = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if(i == 0) if(i == 0) {
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2); world.setBlockMetadataWithNotify(x, y, z, 2, 2);
} }
if(i == 1) if(i == 1) {
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2); world.setBlockMetadataWithNotify(x, y, z, 5, 2);
} }
if(i == 2) if(i == 2) {
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2); world.setBlockMetadataWithNotify(x, y, z, 3, 2);
} }
if(i == 3) if(i == 3) {
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2); world.setBlockMetadataWithNotify(x, y, z, 4, 2);
} }
} }

View File

@ -88,38 +88,34 @@ public class EntityMovingItem extends Entity {
worldObj.spawnEntityInWorld(item); worldObj.spawnEntityInWorld(item);
return; return;
} }
}
if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ)) == ModBlocks.conveyor) {
if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ)) == ModBlocks.conveyor) {
if(schedule <= 0) {
ForgeDirection dir = ForgeDirection.getOrientation(worldObj.getBlockMetadata((int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ)));
if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY) + 1, (int)Math.floor(posZ)) == ModBlocks.conveyor && motionY >= 0) {
dir = ForgeDirection.DOWN;
}
if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY) - 1, (int)Math.floor(posZ)) == ModBlocks.conveyor && motionY <= 0) {
dir = ForgeDirection.UP;
}
double speed = 0.1;
schedule = (int) (1 / speed); if(schedule <= 0) {
motionX = -speed * dir.offsetX; ForgeDirection dir = ForgeDirection.getOrientation(worldObj.getBlockMetadata((int)Math.floor(posX), (int)Math.floor(posY), (int)Math.floor(posZ)));
motionY = -speed * dir.offsetY;
motionZ = -speed * dir.offsetZ; if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY) + 1, (int)Math.floor(posZ)) == ModBlocks.conveyor && motionY >= 0) {
dir = ForgeDirection.DOWN;
}
if(worldObj.getBlock((int)Math.floor(posX), (int)Math.floor(posY) - 1, (int)Math.floor(posZ)) == ModBlocks.conveyor && motionY <= 0) {
dir = ForgeDirection.UP;
}
double speed = 0.0625;
schedule = (int) (1 / speed);
motionX = -speed * dir.offsetX;
motionY = -speed * dir.offsetY;
motionZ = -speed * dir.offsetZ;
this.velocityChanged = true;
}
this.velocityChanged = true; schedule--;
} }
this.lastTickPosX = this.prevPosX = this.posX;
this.lastTickPosY = this.prevPosY = this.posY;
this.lastTickPosZ = this.prevPosZ = this.posZ;
this.setPosition(posX + motionX, posY + motionY, posZ + motionZ);
schedule--;
} }
this.moveEntity(motionX, motionY, motionZ);
} }
@Override @Override

View File

@ -20,45 +20,61 @@ public class RenderConveyor implements ISimpleBlockRenderingHandler {
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
GL11.glPushMatrix(); GL11.glPushMatrix();
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
IIcon iicon = block.getIcon(0, 0); IIcon iicon = block.getIcon(0, 0);
tessellator.setColorOpaque_F(1, 1, 1); tessellator.setColorOpaque_F(1, 1, 1);
if (renderer.hasOverrideBlockTexture()) if(renderer.hasOverrideBlockTexture()) {
{ iicon = renderer.overrideBlockTexture;
iicon = renderer.overrideBlockTexture; }
}
GL11.glTranslated(0, -0.125, 0);
GL11.glTranslated(0, -0.125, 0); tessellator.startDrawingQuads();
tessellator.startDrawingQuads(); ObjUtil.renderWithIcon((WavefrontObject) ResourceManager.arrow, iicon, tessellator, 0, false);
ObjUtil.renderWithIcon((WavefrontObject) ResourceManager.arrow, iicon, tessellator, 0, false);
tessellator.draw(); tessellator.draw();
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
@Override @Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
int meta = world.getBlockMetadata(x, y, z); int meta = world.getBlockMetadata(x, y, z);
tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z)); tessellator.setBrightness(block.getMixedBrightnessForBlock(world, x, y, z));
tessellator.setColorOpaque_F(1, 1, 1); tessellator.setColorOpaque_F(1, 1, 1);
if(meta == 2) if(meta == 2) {
renderer.uvRotateTop = 3; renderer.uvRotateTop = 3;
if(meta == 3) renderer.uvRotateBottom = 0;
renderer.uvRotateWest = 3;
}
if(meta == 3) {
renderer.uvRotateTop = 0; renderer.uvRotateTop = 0;
if(meta == 4) renderer.uvRotateBottom = 3;
renderer.uvRotateEast = 3;
}
if(meta == 4) {
renderer.uvRotateTop = 1; renderer.uvRotateTop = 1;
if(meta == 5) renderer.uvRotateBottom = 1;
renderer.uvRotateSouth = 3;
}
if(meta == 5) {
renderer.uvRotateTop = 2; renderer.uvRotateTop = 2;
renderer.uvRotateBottom = 2;
renderer.setRenderBounds((double)0, 0.0D, (double)0, (double)1, 0.125D, (double)1); renderer.uvRotateNorth = 3;
renderer.renderStandardBlock(block, x, y, z); }
renderer.uvRotateTop = 0;
renderer.setRenderBounds((double) 0, 0.0D, (double) 0, (double) 1, 0.25D, (double) 1);
renderer.renderStandardBlock(block, x, y, z);
renderer.uvRotateTop = 0;
renderer.uvRotateBottom = 0;
renderer.uvRotateNorth = 0;
renderer.uvRotateSouth = 0;
renderer.uvRotateEast = 0;
renderer.uvRotateWest = 0;
return true; return true;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

View File

@ -0,0 +1,3 @@
{
"animation": { }
}