Corporea Crystal Cube comparator support and in-world count visualization

This commit is contained in:
Vasco Lavos committed 2015-09-27 23:43:12 +01:00
1 parent d20ef8f82d
commit e61c4f3f4e
3 files changed
+74 -6

No files matched your search

@@ -19,6 +19,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
@@ -49,13 +50,14 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer {
double time = ClientTickHandler.ticksInGame + f;
double worldTicks = tileentity.getWorldObj() == null ? 0 : time;
Minecraft mc = Minecraft.getMinecraft();
GL11.glPushMatrix();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, 1F);
GL11.glTranslated(d0, d1, d2);
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
mc.renderEngine.bindTexture(texture);
GL11.glTranslatef(0.5F, 1.5F, 0.5F);
GL11.glScalef(1F, -1F, -1F);
model.renderBase();
@@ -68,12 +70,46 @@ public class RenderTileCorporeaCrystalCube extends TileEntitySpecialRenderer {
GL11.glRotatef(180F, 0F, 0F, 1F);
((Render) RenderManager.instance.entityRenderMap.get(EntityItem.class)).doRender(entity, 0, 0, 0, 1F, f);
GL11.glPopMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
mc.renderEngine.bindTexture(texture);
}
GL11.glColor4f(1F, 1F, 1F, 0.7F);
GL11.glColor4f(1F, 1F, 1F, 0.4F);
model.renderCube();
GL11.glColor3f(1F, 1F, 1F);
if(stack != null) {
int count = cube.getItemCount();
String countStr = "" + count;
int color = 0xFFFFFF;
if(count > 9999) {
countStr = (count / 1000) + "K";
color = 0xFFFF00;
if(count > 9999999) {
countStr = (count / 10000000) + "M";
color = 0x00FF00;
}
}
color |= 0xA0 << 24;
int colorShade = (color & 16579836) >> 2 | color & -16777216;
float s = 1F / 64F;
GL11.glScalef(s, s, s);
GL11.glDisable(GL11.GL_LIGHTING);
int l = mc.fontRenderer.getStringWidth(countStr);
GL11.glTranslatef(0F, 55F, 0F);
float tr = -16.5F;
for(int i = 0; i < 4; i++) {
GL11.glRotatef(90F, 0F, 1F, 0F);
GL11.glTranslatef(0F, 0F, tr);
mc.fontRenderer.drawString(countStr, -l / 2, 0, color);
GL11.glTranslatef(0F, 0F, 0.1F);
mc.fontRenderer.drawString(countStr, -l / 2 + 1, 1, colorShade);
GL11.glTranslatef(0F, 0F, -tr + 0.1F);
}
GL11.glEnable(GL11.GL_LIGHTING);
}
GL11.glScalef(1F, -1F, -1F);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
@@ -89,5 +89,15 @@ public class BlockCorporeaCrystalCube extends BlockCorporeaBase implements ILexi
public LexiconEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
return LexiconData.corporeaCrystalCube;
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int s) {
return ((TileCorporeaCrystalCube) world.getTileEntity(x, y, z)).compValue;
}
}
@@ -24,10 +24,13 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase {
private static final String TAG_REQUEST_TARGET = "requestTarget";
private static final String TAG_ITEM_COUNT = "itemCount";
private static final double LOG_2 = Math.log(2);
ItemStack requestTarget;
int itemCount = 0;
int ticks = 0;
public int compValue = 0;
@Override
public void updateEntity() {
@@ -72,23 +75,36 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase {
itemCount -= reqStack.stackSize;
did = true;
}
if(did)
if(did) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
onUpdateCount();
}
}
}
private void updateCount() {
if(worldObj.isRemote)
return;
int oldCount = itemCount;
itemCount = 0;
ICorporeaSpark spark = getSpark();
if(spark != null && spark.getMaster() != null && requestTarget != null) {
List<ItemStack> stacks = CorporeaHelper.requestItem(requestTarget, -1, spark, true, false);
for(ItemStack stack : stacks)
itemCount += stack.stackSize;
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
if(itemCount != oldCount) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
onUpdateCount();
}
}
private void onUpdateCount() {
compValue = getComparatorValue();
worldObj.func_147453_f(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
}
@Override
@@ -113,6 +129,12 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase {
public int getSizeInventory() {
return 1;
}
public int getComparatorValue() {
if(itemCount == 0)
return 0;
return Math.min(15, (int) Math.floor(Math.log(itemCount) / LOG_2) + 1);
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {