Skip to content

Commit

Permalink
Fired Crucible renders solid level.
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaMachina committed Jul 1, 2020
1 parent 9b445e3 commit 7b0b8aa
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 15 deletions.
Expand Up @@ -44,9 +44,9 @@ public void render(FiredCrucibleTile tileEntity, float partialTicks, MatrixStack
Fluid fluid = tileEntity.getFluid();
ResourceLocation fluidTexture =
fluid != null ? fluid.getAttributes().getStillTexture() : null;
Color color =
Color fluidColor =
fluid != null ? new Color(fluid.getAttributes().getColor()) : Color.INVALID_COLOR;

Color blockColor = getBlockColor(solidTexture, tileEntity);
if (fluidTexture != null) {
IVertexBuilder builder = buffer.getBuffer(RenderType.getTranslucent());

Expand All @@ -62,20 +62,52 @@ public void render(FiredCrucibleTile tileEntity, float partialTicks, MatrixStack
matrixStack.translate(-.5, -.5, -.5);

add(builder, matrixStack, 0, 0.25f + fillAmount, 1, sprite.getMinU(), sprite.getMaxV(),
color);
fluidColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 1, sprite.getMaxU(), sprite.getMaxV(),
color);
fluidColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 0, sprite.getMaxU(), sprite.getMinV(),
color);
fluidColor);
add(builder, matrixStack, 0, 0.25f + fillAmount, 0, sprite.getMinU(), sprite.getMinV(),
color);
fluidColor);

matrixStack.pop();
}
if (solidTexture != null) {
IVertexBuilder builder = buffer.getBuffer(RenderType.getSolid());

TextureAtlasSprite sprite = Minecraft.getInstance()
.getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(
solidTexture);
new ResourceLocation(solidTexture.getNamespace(),
"block/" + solidTexture.getPath()));

// Subtract 0.005 to prevent texture fighting
float fillAmount = (0.75f * tileEntity.getSolidProportion()) - 0.005f;

matrixStack.push();
matrixStack.translate(.5, .5, .5);
matrixStack.translate(-.5, -.5, -.5);

add(builder, matrixStack, 0, 0.25f + fillAmount, 1, sprite.getMinU(), sprite.getMaxV(),
blockColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 1, sprite.getMaxU(), sprite.getMaxV(),
blockColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 0, sprite.getMaxU(), sprite.getMinV(),
blockColor);
add(builder, matrixStack, 0, 0.25f + fillAmount, 0, sprite.getMinU(), sprite.getMinV(),
blockColor);

matrixStack.pop();
}
}

private Color getBlockColor(ResourceLocation solidTexture,
FiredCrucibleTile tileEntity) {
if (solidTexture != null) {
if (solidTexture.toString().contains("leaves")) {
return new Color(
tileEntity.getWorld().getBiome(tileEntity.getPos()).getFoliageColor());
}
}
return Color.WHITE;
}
}
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nullable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
Expand Down Expand Up @@ -91,14 +92,6 @@ public void tick() {
if (ticksSinceLast >= 10) {
ticksSinceLast = 0;

LogUtil.info(String
.format("Fluid: %s Amount: %d", tank.getFluid().getFluid().toString(),
tank.getFluid().getAmount()));
LogUtil.info(String.format("Current Item: %s", currentItem.toString()));
LogUtil
.info(String.format("Inventory Item: %s", inventory.getStackInSlot(0).toString()));
LogUtil.info(String.format("Solid Amount: %d", solidAmount));

int heat = HeatRegistry.getHeatAmount(world.getBlockState(pos.down()).getBlock());
if (heat <= 0) {
return;
Expand Down Expand Up @@ -184,6 +177,9 @@ public ResourceLocation getSolidTexture() {
if (!inventory.getStackInSlot(0).isEmpty()) {
return inventory.getStackInSlot(0).getItem().getRegistryName();
}
if (!currentItem.isEmpty()) {
return currentItem.getItem().getRegistryName();
}
return null;
}

Expand All @@ -201,6 +197,10 @@ public SUpdateTileEntityPacket getUpdatePacket() {
CompoundNBT blockNbt = inventory.getStackInSlot(0).write(new CompoundNBT());
nbt.put("block", blockNbt);
}
if (!currentItem.isEmpty()) {
CompoundNBT currentItemTag = currentItem.write(new CompoundNBT());
nbt.put("currentItem", currentItemTag);
}
if (!tank.isEmpty()) {
CompoundNBT fluidNbt = tank.writeToNBT(new CompoundNBT());
nbt.put("fluid", fluidNbt);
Expand All @@ -213,6 +213,12 @@ public SUpdateTileEntityPacket getUpdatePacket() {
@Override
public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket packet) {
CompoundNBT nbt = packet.getNbtCompound();
if (nbt.contains("currentItem")) {
currentItem = ItemStack.read((CompoundNBT) nbt.get("currentItem"));
} else {
currentItem = ItemStack.EMPTY;
}

if (nbt.contains("block")) {
inventory.setStackInSlot(0, ItemStack.read((CompoundNBT) nbt.get("block")));
} else {
Expand All @@ -232,10 +238,19 @@ public float getFluidProportion() {
}

public float getSolidProportion() {
LogUtil.info(String.format("Inventory: %s", inventory.getStackInSlot(0).toString()));
LogUtil.info(String.format("Current Item: %s", currentItem.toString()));

int itemCount =
inventory.getStackInSlot(0).isEmpty() ? 0 : inventory.getStackInSlot(0).getCount();
float solidProportion = ((float) itemCount) / 4;

if (solidAmount > 0) {
Meltable meltable = MeltableItems.getMeltable(currentItem.getItem());
solidProportion += ((float) solidAmount) / (4 * meltable.getAmount());
}

LogUtil.info(String.format("Solid Amount: %f", solidProportion));
return solidProportion;
}
}
Expand Up @@ -6,6 +6,7 @@
public class Color {

public static final Color INVALID_COLOR = new Color(-1, -1, -1, -1);
public static final Color WHITE = new Color(1, 1, 1, 1);

public final float r;
public final float g;
Expand Down

0 comments on commit 7b0b8aa

Please sign in to comment.