Better game element rendering in GUIs

- Fixed uv issues with connected textures
- Fixed chromatic scope not showing on blockzappers
- Refactored game element rendering in user interfaces, such as JEI screens
This commit is contained in:
simibubi 2020-05-11 17:48:00 +02:00
parent e69af69b0a
commit 20ab49e46e
29 changed files with 543 additions and 602 deletions

View file

@ -2,11 +2,9 @@ package com.simibubi.create.compat.jei.category;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.BlockState; import net.minecraft.fluid.Fluids;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.item.crafting.AbstractCookingRecipe; import net.minecraft.item.crafting.AbstractCookingRecipe;
@ -23,28 +21,12 @@ public class BlastingViaFanCategory extends ProcessingViaFanCategory<AbstractCoo
@Override @Override
public void renderAttachedBlock() { public void renderAttachedBlock() {
BlockState state = Blocks.LAVA.getDefaultState().with(FlowingFluidBlock.LEVEL, 8);
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(0, 0, 200);
RenderSystem.enableRescaleNormal();
RenderSystem.pushMatrix();
RenderSystem.translated(0, 200, 0);
RenderSystem.rotatef(90, 1, 0, 0);
ScreenElementRenderer.renderBlock(() -> state);
RenderSystem.popMatrix();
RenderSystem.pushMatrix(); GuiGameElement.of(Fluids.LAVA)
RenderSystem.translated(0, 200, 0); .scale(24)
RenderSystem.rotatef(90, 1, 0, 0); .atLocal(0, 0, 2)
RenderSystem.rotatef(270, 0, 0, 1); .render();
ScreenElementRenderer.renderBlock(() -> state);
RenderSystem.popMatrix();
RenderSystem.pushMatrix();
RenderSystem.translated(-103, -100, 0);
ScreenElementRenderer.renderBlock(() -> state);
RenderSystem.popMatrix();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }

View file

@ -66,8 +66,7 @@ public class BlockCuttingCategory extends CreateRecipeCategory<CondensedBlockCut
ScreenResources.JEI_SLOT.draw(77 + xOffset, 47 + yOffset); ScreenResources.JEI_SLOT.draw(77 + xOffset, 47 + yOffset);
} }
ScreenResources.JEI_DOWN_ARROW.draw(31, 6); ScreenResources.JEI_DOWN_ARROW.draw(31, 6);
ScreenResources.JEI_SHADOW.draw(19, 55); saw.draw(33, 37);
saw.draw(33, 35);
} }
public static class CondensedBlockCuttingRecipe extends StonecuttingRecipe { public static class CondensedBlockCuttingRecipe extends StonecuttingRecipe {

View file

@ -10,7 +10,7 @@ import java.util.stream.Collectors;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.compat.jei.ScreenResourceWrapper; import com.simibubi.create.compat.jei.ScreenResourceWrapper;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.curiosities.zapper.blockzapper.BlockzapperUpgradeRecipe; import com.simibubi.create.modules.curiosities.zapper.blockzapper.BlockzapperUpgradeRecipe;
@ -80,18 +80,17 @@ public class BlockzapperUpgradeCategory extends CreateRecipeCategory<Blockzapper
public void draw(BlockzapperUpgradeRecipe recipe, double mouseX, double mouseY) { public void draw(BlockzapperUpgradeRecipe recipe, double mouseX, double mouseY) {
FontRenderer font = Minecraft.getInstance().fontRenderer; FontRenderer font = Minecraft.getInstance().fontRenderer;
String componentName = String componentName =
Lang.translate("blockzapper.component." + Lang.asId(recipe.getUpgradedComponent().name())); Lang.translate("blockzapper.component." + Lang.asId(recipe.getUpgradedComponent().name()));
String text = "+ " + recipe.getTier().color + componentName; String text = "+ " + recipe.getTier().color + componentName;
font.drawStringWithShadow(text, (BLOCKZAPPER_UPGRADE_RECIPE.width - font.getStringWidth(text)) / 2, 57, font.drawStringWithShadow(text, (BLOCKZAPPER_UPGRADE_RECIPE.width - font.getStringWidth(text)) / 2, 57,
0x8B8B8B); 0x8B8B8B);
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(126, 0, 0); RenderSystem.translated(126, 0, 0);
RenderSystem.scaled(3.5, 3.5, 3.5); RenderSystem.scaled(3.5, 3.5, 3.5);
RenderSystem.translated(-10, 0, 0); RenderSystem.translated(-10, 0, 0);
RenderSystem.color3f(1, 1, 1); RenderSystem.color3f(1, 1, 1);
RenderSystem.enableDepthTest(); GuiGameElement.of(recipe.getRecipeOutput()).render();
ScreenElementRenderer.render3DItem(() -> recipe.getRecipeOutput());
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
} }

View file

@ -63,7 +63,7 @@ public class CrushingCategory extends CreateRecipeCategory<AbstractCrushingRecip
for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) for (int outputIndex = 0; outputIndex < results.size(); outputIndex++)
getRenderedSlot(recipe, outputIndex).draw(getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78); getRenderedSlot(recipe, outputIndex).draw(getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78);
crushingWheels.draw(92, 49); crushingWheels.draw(62, 59);
} }
} }

View file

@ -168,11 +168,10 @@ public class MechanicalCraftingCategory extends CreateRecipeCategory<ShapedRecip
ScreenResources.JEI_SLOT.draw(133, 80); ScreenResources.JEI_SLOT.draw(133, 80);
ScreenResources.JEI_DOWN_ARROW.draw(128, 59); ScreenResources.JEI_DOWN_ARROW.draw(128, 59);
ScreenResources.JEI_SHADOW.draw(116, 36); crafter.draw(129, 25);
crafter.draw(219, 8);
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(0, 0, 200); RenderSystem.translated(0, 0, 300);
RenderHelper.disableStandardItemLighting(); RenderHelper.disableStandardItemLighting();
int amount = 0; int amount = 0;

View file

@ -58,11 +58,9 @@ public class MillingCategory extends CreateRecipeCategory<AbstractCrushingRecipe
int size = recipe.getPossibleOutputs().size(); int size = recipe.getPossibleOutputs().size();
ScreenResources.JEI_SLOT.draw(14, 8); ScreenResources.JEI_SLOT.draw(14, 8);
ScreenResources.JEI_SHADOW.draw(30, 40);
ScreenResources.JEI_ARROW.draw(85, 32); ScreenResources.JEI_ARROW.draw(85, 32);
ScreenResources.JEI_DOWN_ARROW.draw(43, 4); ScreenResources.JEI_DOWN_ARROW.draw(43, 4);
millstone.draw(48, 27);
millstone.draw(57, 27);
if (size == 1) { if (size == 1) {
getRenderedSlot(recipe, 0).draw(139, 27); getRenderedSlot(recipe, 0).draw(139, 27);

View file

@ -103,7 +103,7 @@ public class MixingCategory extends CreateRecipeCategory<MixingRecipe> {
ScreenResources.JEI_SLOT.draw(141, 50); ScreenResources.JEI_SLOT.draw(141, 50);
ScreenResources.JEI_DOWN_ARROW.draw(136, 32); ScreenResources.JEI_DOWN_ARROW.draw(136, 32);
ScreenResources.JEI_SHADOW.draw(81, 57); ScreenResources.JEI_SHADOW.draw(81, 57);
mixer.draw(getBackground().getWidth() / 2 + 20, 8); mixer.draw(getBackground().getWidth() / 2 + 3, 25);
} }
} }

View file

@ -65,7 +65,7 @@ public class PackingCategory extends CreateRecipeCategory<IRecipe<?>> {
ScreenResources.JEI_SLOT.draw(141, 50); ScreenResources.JEI_SLOT.draw(141, 50);
ScreenResources.JEI_DOWN_ARROW.draw(136, 32); ScreenResources.JEI_DOWN_ARROW.draw(136, 32);
ScreenResources.JEI_SHADOW.draw(81, 57); ScreenResources.JEI_SHADOW.draw(81, 57);
press.draw(getBackground().getWidth() / 2 + 20, 8); press.draw(getBackground().getWidth() / 2 + 6, 30);
} }
} }

View file

@ -58,7 +58,7 @@ public class PressingCategory extends CreateRecipeCategory<PressingRecipe> {
getRenderedSlot(recipe, 1).draw(131 + 19, 50); getRenderedSlot(recipe, 1).draw(131 + 19, 50);
ScreenResources.JEI_SHADOW.draw(61, 41); ScreenResources.JEI_SHADOW.draw(61, 41);
ScreenResources.JEI_LONG_ARROW.draw(52, 54); ScreenResources.JEI_LONG_ARROW.draw(52, 54);
press.draw(getBackground().getWidth() / 2, 8); press.draw(getBackground().getWidth() / 2 - 17, 22);
} }
} }

View file

@ -7,18 +7,14 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics; import com.simibubi.create.compat.jei.category.animations.AnimatedKinetics;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
public abstract class ProcessingViaFanCategory<T extends IRecipe<?>> extends CreateRecipeCategory<T> { public abstract class ProcessingViaFanCategory<T extends IRecipe<?>> extends CreateRecipeCategory<T> {
@ -53,47 +49,29 @@ public abstract class ProcessingViaFanCategory<T extends IRecipe<?>> extends Cre
@Override @Override
public void draw(T recipe, double mouseX, double mouseY) { public void draw(T recipe, double mouseX, double mouseY) {
renderWidgets(recipe, mouseX, mouseY); renderWidgets(recipe, mouseX, mouseY);
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.color3f(1, 1, 1);
RenderSystem.enableDepthTest(); RenderSystem.translatef(56, 33, 0);
RenderSystem.rotatef(-12.5f, 1, 0, 0);
RenderSystem.rotatef(22.5f, 0, 1, 0);
int scale = 24;
RenderSystem.translated(28, 18, 0); GuiGameElement.of(AllBlockPartials.ENCASED_FAN_INNER)
RenderSystem.rotatef(10.5f, -1f, 0, 0); .rotateBlock(180, 0, AnimatedKinetics.getCurrentAngle() * 16)
RenderSystem.rotatef(15.5f, 0, 1, 0); .scale(scale)
RenderSystem.scaled(.6f, .6f, .6f); .render();
ScreenElementRenderer.renderBlock(this::renderFanCasing);
RenderSystem.pushMatrix();
float angle = AnimatedKinetics.getCurrentAngle() * 12;
float t = 25;
RenderSystem.translatef(t, -t, t);
RenderSystem.rotatef(angle, 0, 0, 1);
RenderSystem.translatef(-t, t, -t);
RenderSystem.translatef(t, 0, 175);
RenderSystem.rotatef(90, 0, 1, 0);
RenderSystem.translatef(-t, 0, -175);
ScreenElementRenderer.renderModel(this::renderFanInner);
RenderSystem.popMatrix();
RenderSystem.translated(-10, 0, 95); GuiGameElement.of(AllBlocks.ENCASED_FAN.getDefault())
RenderSystem.rotatef(7, 0, 1, 0); .rotateBlock(0, 180, 0)
.atLocal(0, 0, 0)
.scale(scale)
.render();
renderAttachedBlock(); renderAttachedBlock();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
protected BlockState renderFanCasing() {
return AllBlocks.ENCASED_FAN.get().getDefaultState().with(BlockStateProperties.FACING, Direction.WEST);
}
protected IBakedModel renderFanInner() {
return AllBlockPartials.ENCASED_FAN_INNER.get();
}
public abstract void renderAttachedBlock(); public abstract void renderAttachedBlock();
} }

View file

@ -62,8 +62,7 @@ public class SawingCategory extends CreateRecipeCategory<CuttingRecipe> {
getRenderedSlot(recipe, i).draw(117 + xOffset, 47 + yOffset); getRenderedSlot(recipe, i).draw(117 + xOffset, 47 + yOffset);
} }
ScreenResources.JEI_DOWN_ARROW.draw(70, 6); ScreenResources.JEI_DOWN_ARROW.draw(70, 6);
ScreenResources.JEI_SHADOW.draw(58, 55); saw.draw(72, 42);
saw.draw(72, 35);
} }
} }

View file

@ -1,7 +1,7 @@
package com.simibubi.create.compat.jei.category; package com.simibubi.create.compat.jei.category;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.item.Items; import net.minecraft.item.Items;
@ -20,6 +20,11 @@ public class SmokingViaFanCategory extends ProcessingViaFanCategory<SmokingRecip
@Override @Override
public void renderAttachedBlock() { public void renderAttachedBlock() {
ScreenElementRenderer.renderBlock(() -> Blocks.FIRE.getDefaultState());
GuiGameElement.of(Blocks.FIRE.getDefaultState())
.scale(24)
.atLocal(0, 0, 2)
.render();
} }
} }

View file

@ -6,7 +6,7 @@ import java.util.List;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.modules.contraptions.components.fan.SplashingRecipe; import com.simibubi.create.modules.contraptions.components.fan.SplashingRecipe;
import com.simibubi.create.modules.contraptions.processing.ProcessingOutput; import com.simibubi.create.modules.contraptions.processing.ProcessingOutput;
@ -14,9 +14,7 @@ import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.ingredients.IIngredients;
import net.minecraft.block.BlockState; import net.minecraft.fluid.Fluids;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.item.Items; import net.minecraft.item.Items;
public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe> { public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe> {
@ -40,7 +38,9 @@ public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe>
public void setRecipe(IRecipeLayout recipeLayout, SplashingRecipe recipe, IIngredients ingredients) { public void setRecipe(IRecipeLayout recipeLayout, SplashingRecipe recipe, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(0, true, 20, 47); itemStacks.init(0, true, 20, 47);
itemStacks.set(0, Arrays.asList(recipe.getIngredients().get(0).getMatchingStacks())); itemStacks.set(0, Arrays.asList(recipe.getIngredients()
.get(0)
.getMatchingStacks()));
List<ProcessingOutput> results = recipe.getRollableResults(); List<ProcessingOutput> results = recipe.getRollableResults();
boolean single = results.size() == 1; boolean single = results.size() == 1;
@ -49,7 +49,8 @@ public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe>
int yOffset = (outputIndex / 2) * -19; int yOffset = (outputIndex / 2) * -19;
itemStacks.init(outputIndex + 1, false, single ? 139 : 133 + xOffset, 47 + yOffset); itemStacks.init(outputIndex + 1, false, single ? 139 : 133 + xOffset, 47 + yOffset);
itemStacks.set(outputIndex + 1, results.get(outputIndex).getStack()); itemStacks.set(outputIndex + 1, results.get(outputIndex)
.getStack());
} }
addStochasticTooltip(itemStacks, results); addStochasticTooltip(itemStacks, results);
@ -57,7 +58,8 @@ public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe>
@Override @Override
protected void renderWidgets(SplashingRecipe recipe, double mouseX, double mouseY) { protected void renderWidgets(SplashingRecipe recipe, double mouseX, double mouseY) {
int size = recipe.getPossibleOutputs().size(); int size = recipe.getPossibleOutputs()
.size();
ScreenResources.JEI_SLOT.draw(20, 47); ScreenResources.JEI_SLOT.draw(20, 47);
ScreenResources.JEI_SHADOW.draw(47, 29); ScreenResources.JEI_SHADOW.draw(47, 29);
@ -78,27 +80,12 @@ public class SplashingCategory extends ProcessingViaFanCategory<SplashingRecipe>
@Override @Override
public void renderAttachedBlock() { public void renderAttachedBlock() {
BlockState state = Blocks.WATER.getDefaultState().with(FlowingFluidBlock.LEVEL, 8);
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translated(0, 0, 200);
RenderSystem.pushMatrix(); GuiGameElement.of(Fluids.WATER)
RenderSystem.translated(0, 200, 0); .scale(24)
RenderSystem.rotatef(90, 1, 0, 0); .atLocal(0, 0, 2)
ScreenElementRenderer.renderBlock(() -> state); .render();
RenderSystem.popMatrix();
RenderSystem.pushMatrix();
RenderSystem.translated(0, 200, 0);
RenderSystem.rotatef(90, 1, 0, 0);
RenderSystem.rotatef(270, 0, 0, 1);
ScreenElementRenderer.renderBlock(() -> state);
RenderSystem.popMatrix();
RenderSystem.pushMatrix();
RenderSystem.translated(-103, -100, 0);
ScreenElementRenderer.renderBlock(() -> state);
RenderSystem.popMatrix();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }

View file

@ -1,57 +1,34 @@
package com.simibubi.create.compat.jei.category.animations; package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.ScreenResources;
import com.simibubi.create.modules.contraptions.components.crafter.MechanicalCrafterBlock; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.util.Direction;
public class AnimatedCrafter extends AnimatedKinetics { public class AnimatedCrafter extends AnimatedKinetics {
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 50;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.enableDepthTest();
RenderSystem.rotatef(-15.5f, 1, 0, 0);
RenderSystem.rotatef(-22.5f, 0, 1, 0);
RenderSystem.translatef(xOffset, yOffset, 0); RenderSystem.translatef(xOffset, yOffset, 0);
RenderSystem.translatef(-45, -5, 0); ScreenResources.JEI_SHADOW.draw(-16, 13);
RenderSystem.scaled(.45f, .45f, .45f);
RenderSystem.translatef(3, 16, 0);
RenderSystem.rotatef(-12.5f, 1, 0, 0);
RenderSystem.rotatef(-22.5f, 0, 1, 0);
int scale = 22;
ScreenElementRenderer.renderModel(() -> cogwheel(true)); GuiGameElement.of(cogwheel())
ScreenElementRenderer.renderBlock(this::body); .rotateBlock(90, 0, getCurrentAngle())
.scale(scale)
.render();
GuiGameElement.of(AllBlocks.MECHANICAL_CRAFTER.getDefault())
.rotateBlock(0, 180, 0)
.scale(scale)
.render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
private IBakedModel cogwheel(boolean forward) {
float t = 25;
RenderSystem.translatef(t, -t, -t);
RenderSystem.rotatef(getCurrentAngle() * 2 * (forward ? 1 : -1), 0, 0, 1);
RenderSystem.rotatef(90, 1, 0, 0);
RenderSystem.translatef(-t, t, t);
return AllBlockPartials.SHAFTLESS_COGWHEEL.get();
}
private BlockState body() {
return AllBlocks.MECHANICAL_CRAFTER
.get()
.getDefaultState()
.with(MechanicalCrafterBlock.HORIZONTAL_FACING, Direction.WEST);
}
} }

View file

@ -2,7 +2,7 @@ package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
@ -10,49 +10,27 @@ import net.minecraft.util.Direction.Axis;
public class AnimatedCrushingWheels extends AnimatedKinetics { public class AnimatedCrushingWheels extends AnimatedKinetics {
@Override
public int getWidth() {
return 150;
}
@Override
public int getHeight() {
return 100;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
RenderSystem.translatef(xOffset, yOffset, 0); RenderSystem.translatef(xOffset, yOffset, 300);
RenderSystem.translatef(-45, 10, 0); RenderSystem.rotatef(-22.5f, 0, 1, 0);
RenderSystem.rotatef(22.5f, 0, 1, 0); int scale = 22;
RenderSystem.scaled(.45f, .45f, .45f);
ScreenElementRenderer.renderBlock(this::leftWheel); BlockState wheel = AllBlocks.CRUSHING_WHEEL.get()
ScreenElementRenderer.renderBlock(this::rightWheel); .getDefaultState()
} .with(BlockStateProperties.AXIS, Axis.X);
private BlockState leftWheel() { GuiGameElement.of(wheel)
float angle = getCurrentAngle(); .rotateBlock(0, 90, -getCurrentAngle())
RenderSystem.translatef(-50, 0, 0); .scale(scale)
.render();
float t = 25;
RenderSystem.translatef(t, -t, t);
RenderSystem.rotatef(angle, 0, 0, 1);
RenderSystem.translatef(-t, t, -t);
return AllBlocks.CRUSHING_WHEEL.get().getDefaultState().with(BlockStateProperties.AXIS, Axis.X);
}
private BlockState rightWheel() { GuiGameElement.of(wheel)
float angle = -getCurrentAngle(); .rotateBlock(0, 90, getCurrentAngle())
RenderSystem.translatef(50, 0, 0); .atLocal(2, 0, 0)
.scale(scale)
float t = 25; .render();
RenderSystem.translatef(t, -t, t);
RenderSystem.rotatef(angle, 0, 0, 1);
RenderSystem.translatef(-t, t, -t);
return AllBlocks.CRUSHING_WHEEL.get().getDefaultState().with(BlockStateProperties.AXIS, Axis.X);
} }
} }

View file

@ -1,5 +1,6 @@
package com.simibubi.create.compat.jei.category.animations; package com.simibubi.create.compat.jei.category.animations;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocksNew; import com.simibubi.create.AllBlocksNew;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -18,5 +19,19 @@ public abstract class AnimatedKinetics implements IDrawable {
protected BlockState shaft(Axis axis) { protected BlockState shaft(Axis axis) {
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS, axis); return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS, axis);
} }
protected AllBlockPartials cogwheel() {
return AllBlockPartials.SHAFTLESS_COGWHEEL;
}
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 50;
}
} }

View file

@ -3,53 +3,30 @@ package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.IBakedModel;
public class AnimatedMillstone extends AnimatedKinetics { public class AnimatedMillstone extends AnimatedKinetics {
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 50;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.enableDepthTest();
RenderSystem.translatef(xOffset, yOffset, 0); RenderSystem.translatef(xOffset, yOffset, 0);
RenderSystem.rotatef(-15.5f, 1, 0, 0); ScreenResources.JEI_SHADOW.draw(-16, 13);
RenderSystem.rotatef(22.5f, 0, 1, 0); RenderSystem.translatef(-2, 18, 0);
RenderSystem.translatef(-45, -5, 0); int scale = 22;
RenderSystem.scaled(.45f, .45f, .45f);
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlockPartials.MILLSTONE_COG)
ScreenElementRenderer.renderModel(this::cogwheel); .rotateBlock(22.5, getCurrentAngle() * 2, 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.pushMatrix();
ScreenElementRenderer.renderBlock(this::body); GuiGameElement.of(AllBlocks.MILLSTONE.getDefault())
RenderSystem.popMatrix(); .rotateBlock(22.5, 22.5, 0)
.scale(scale)
.render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
private IBakedModel cogwheel() {
float t = 25;
RenderSystem.translatef(t, -t, -t);
RenderSystem.rotatef(getCurrentAngle() * 2, 0, 1, 0);
RenderSystem.translatef(-t, t, t);
return AllBlockPartials.MILLSTONE_COG.get();
}
private BlockState body() {
return AllBlocks.MILLSTONE.get().getDefaultState();
}
} }

View file

@ -3,84 +3,46 @@ package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.model.IBakedModel;
public class AnimatedMixer extends AnimatedKinetics { public class AnimatedMixer extends AnimatedKinetics {
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 150;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.enableDepthTest(); RenderSystem.translatef(xOffset, yOffset, 200);
RenderSystem.translatef(xOffset, yOffset, 0);
RenderSystem.rotatef(-15.5f, 1, 0, 0); RenderSystem.rotatef(-15.5f, 1, 0, 0);
RenderSystem.rotatef(22.5f, 0, 1, 0); RenderSystem.rotatef(22.5f, 0, 1, 0);
RenderSystem.translatef(-45, -5, 0); int scale = 23;
RenderSystem.scaled(.45f, .45f, .45f);
RenderSystem.pushMatrix(); GuiGameElement.of(cogwheel())
ScreenElementRenderer.renderModel(this::cogwheel); .rotateBlock(0, getCurrentAngle() * 2, 0)
RenderSystem.popMatrix(); .atLocal(0, 0, 0)
.scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlocks.MECHANICAL_MIXER.getDefault())
ScreenElementRenderer.renderBlock(this::body); .atLocal(0, 0, 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlockPartials.MECHANICAL_MIXER_POLE)
ScreenElementRenderer.renderModel(this::pole); .atLocal(0, 1, 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlockPartials.MECHANICAL_MIXER_HEAD)
ScreenElementRenderer.renderModel(this::head); .rotateBlock(0, getCurrentAngle() * 4, 0)
RenderSystem.popMatrix(); .atLocal(0, 1, 0)
.scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlocks.BASIN.getDefault())
ScreenElementRenderer.renderBlock(this::basin); .atLocal(0, 1.65, 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
private IBakedModel cogwheel() {
float t = 25;
RenderSystem.translatef(t, -t, -t);
RenderSystem.rotatef(getCurrentAngle() * 2, 0, 1, 0);
RenderSystem.translatef(-t, t, t);
return AllBlockPartials.SHAFTLESS_COGWHEEL.get();
}
private BlockState body() {
return AllBlocks.MECHANICAL_MIXER.get().getDefaultState();
}
private IBakedModel pole() {
RenderSystem.translatef(0, 51, 0);
return AllBlockPartials.MECHANICAL_MIXER_POLE.get();
}
private IBakedModel head() {
float t = 25;
RenderSystem.translatef(0, 51, 0);
RenderSystem.translatef(t, -t, -t);
RenderSystem.rotatef(getCurrentAngle() * 4, 0, 1, 0);
RenderSystem.translatef(-t, t, t);
return AllBlockPartials.MECHANICAL_MIXER_HEAD.get();
}
private BlockState basin() {
RenderSystem.translatef(0, 85, 0);
return AllBlocks.BASIN.get().getDefaultState();
}
} }

View file

@ -5,14 +5,9 @@ import static com.simibubi.create.foundation.utility.AnimationTickHolder.ticks;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllBlocksNew; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.gui.ScreenElementRenderer;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
public class AnimatedPress extends AnimatedKinetics { public class AnimatedPress extends AnimatedKinetics {
@ -23,80 +18,49 @@ public class AnimatedPress extends AnimatedKinetics {
this.basin = basin; this.basin = basin;
} }
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 100;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.enableDepthTest(); RenderSystem.translatef(xOffset, yOffset, 100);
RenderSystem.translatef(xOffset, yOffset, 0);
RenderSystem.rotatef(-15.5f, 1, 0, 0); RenderSystem.rotatef(-15.5f, 1, 0, 0);
RenderSystem.rotatef(22.5f, 0, 1, 0); RenderSystem.rotatef(22.5f, 0, 1, 0);
RenderSystem.translatef(-45, -5, 0); int scale = basin ? 20 : 24;
RenderSystem.scaled(.45f, .45f, .45f);
RenderSystem.pushMatrix(); GuiGameElement.of(shaft(Axis.Z))
ScreenElementRenderer.renderBlock(this::shaft); .rotateBlock(0, 0, getCurrentAngle())
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlocks.MECHANICAL_PRESS.getDefault())
ScreenElementRenderer.renderBlock(this::body); .scale(scale)
RenderSystem.popMatrix(); .render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlockPartials.MECHANICAL_PRESS_HEAD)
ScreenElementRenderer.renderModel(this::head); .atLocal(0, -getAnimatedHeadOffset(), 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
if (basin) { if (basin)
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlocks.BASIN.getDefault())
ScreenElementRenderer.renderBlock(this::basin); .atLocal(0, 1.65, 0)
RenderSystem.popMatrix(); .scale(scale)
} .render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
private BlockState shaft() { private float getAnimatedHeadOffset() {
float t = 25; float cycle = (ticks + Minecraft.getInstance()
RenderSystem.translatef(t, -t, -t); .getRenderPartialTicks()) % 30;
RenderSystem.rotatef(getCurrentAngle() * 2, 1, 0, 0);
RenderSystem.translatef(-t, t, t);
return AllBlocksNew.getDefault(AllBlocksNew.SHAFT).with(BlockStateProperties.AXIS, Axis.Z);
}
private BlockState body() {
return AllBlocks.MECHANICAL_PRESS.get().getDefaultState().with(BlockStateProperties.HORIZONTAL_FACING,
Direction.SOUTH);
}
private IBakedModel head() {
float cycle = (ticks + Minecraft.getInstance().getRenderPartialTicks()) % 30;
float verticalOffset = 0;
if (cycle < 10) { if (cycle < 10) {
float progress = cycle / 10; float progress = cycle / 10;
verticalOffset = -(progress * progress * progress); return -(progress * progress * progress);
} else if (cycle < 15) {
verticalOffset = -1;
} else if (cycle < 20) {
verticalOffset = -1 + (1 - ((20 - cycle) / 5));
} else {
verticalOffset = 0;
} }
RenderSystem.translated(0, -verticalOffset * 50, 0); if (cycle < 15)
return AllBlockPartials.MECHANICAL_PRESS_HEAD.get(); return -1;
} if (cycle < 20)
return -1 + (1 - ((20 - cycle) / 5));
private BlockState basin() { return 0;
RenderSystem.translatef(0, 85, 0);
return AllBlocks.BASIN.get().getDefaultState();
} }
} }

View file

@ -2,58 +2,40 @@ package com.simibubi.create.compat.jei.category.animations;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.modules.contraptions.components.saw.SawBlock; import com.simibubi.create.modules.contraptions.components.saw.SawBlock;
import net.minecraft.block.BlockState;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
public class AnimatedSaw extends AnimatedKinetics { public class AnimatedSaw extends AnimatedKinetics {
@Override
public int getWidth() {
return 50;
}
@Override
public int getHeight() {
return 50;
}
@Override @Override
public void draw(int xOffset, int yOffset) { public void draw(int xOffset, int yOffset) {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.enableDepthTest();
RenderSystem.translatef(xOffset, yOffset, 0); RenderSystem.translatef(xOffset, yOffset, 0);
RenderSystem.rotatef(-15.5f, 1, 0, 0); ScreenResources.JEI_SHADOW.draw(-16, 13);
RenderSystem.rotatef(22.5f, 0, 1, 0);
RenderSystem.translatef(-45, -5, 0); RenderSystem.translatef(0, 0, 200);
RenderSystem.scaled(.6f, .6f, .6f); RenderSystem.translatef(-6, 19, 0);
RenderSystem.rotatef(-22.5f, 1, 0, 0);
RenderSystem.rotatef(90 - 22.5f, 0, 1, 0);
int scale = 25;
RenderSystem.pushMatrix(); GuiGameElement.of(shaft(Axis.X))
ScreenElementRenderer.renderBlock(this::shaft); .rotateBlock(-getCurrentAngle(), 0, 0)
RenderSystem.popMatrix(); .scale(scale)
.render();
RenderSystem.pushMatrix(); GuiGameElement.of(AllBlocks.SAW.getDefault()
ScreenElementRenderer.renderBlock(this::block); .with(SawBlock.FACING, Direction.UP)
RenderSystem.popMatrix(); .with(SawBlock.RUNNING, true))
.rotateBlock(0, 0, 0)
.scale(scale)
.render();
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }
private BlockState shaft() {
float t = 25;
RenderSystem.translatef(t, -t, t);
RenderSystem.rotatef(-getCurrentAngle() * 2, 0, 0, 1);
RenderSystem.translatef(-t, t, -t);
return shaft(Axis.X);
}
private BlockState block() {
return AllBlocks.SAW.get().getDefaultState().with(BlockStateProperties.FACING, Direction.UP)
.with(SawBlock.RUNNING, true).with(SawBlock.AXIS_ALONG_FIRST_COORDINATE, true);
}
} }

View file

@ -94,7 +94,7 @@ public class CTModel extends BakedModelWrapper<IBakedModel> {
int[] vertexData = newQuad.getVertexData(); int[] vertexData = newQuad.getVertexData();
for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) { for (int vertex = 0; vertex < vertexData.length; vertex += format.getIntegerSize()) {
int uvOffset = 20 / 4; // TODO 1.15 is this the right offset? int uvOffset = 16 / 4;
int uIndex = vertex + uvOffset; int uIndex = vertex + uvOffset;
int vIndex = vertex + uvOffset + 1; int vIndex = vertex + uvOffset + 1;
float u = Float.intBitsToFloat(vertexData[uIndex]); float u = Float.intBitsToFloat(vertexData[uIndex]);

View file

@ -0,0 +1,251 @@
package com.simibubi.create.foundation.gui;
import javax.annotation.Nullable;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FireBlock;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.data.EmptyModelData;
public class GuiGameElement {
public static GuiRenderBuilder of(ItemStack stack) {
return new GuiItemRenderBuilder(stack);
}
public static GuiRenderBuilder of(IItemProvider itemProvider) {
return new GuiItemRenderBuilder(itemProvider);
}
public static GuiRenderBuilder of(BlockState state) {
return new GuiBlockStateRenderBuilder(state);
}
public static GuiRenderBuilder of(AllBlockPartials partial) {
return new GuiBlockPartialRenderBuilder(partial);
}
public static GuiRenderBuilder of(Fluid fluid) {
return new GuiBlockStateRenderBuilder(fluid.getDefaultState()
.getBlockState()
.with(FlowingFluidBlock.LEVEL, 5));
}
public static abstract class GuiRenderBuilder {
double xBeforeScale, yBeforeScale;
double x, y, z;
double xRot, yRot, zRot;
double scale = 1;
int color = 0xFFFFFF;
Vec3d rotationOffset = Vec3d.ZERO;
public GuiRenderBuilder atLocal(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
public GuiRenderBuilder at(double x, double y) {
this.xBeforeScale = x;
this.yBeforeScale = y;
return this;
}
public GuiRenderBuilder rotate(double xRot, double yRot, double zRot) {
this.xRot = xRot;
this.yRot = yRot;
this.zRot = zRot;
return this;
}
public GuiRenderBuilder rotateBlock(double xRot, double yRot, double zRot) {
return this.rotate(xRot, yRot, zRot)
.withRotationOffset(VecHelper.getCenterOf(BlockPos.ZERO));
}
public GuiRenderBuilder scale(double scale) {
this.scale = scale;
return this;
}
public GuiRenderBuilder color(int color) {
this.color = color;
return this;
}
public GuiRenderBuilder withRotationOffset(Vec3d offset) {
this.rotationOffset = offset;
return this;
}
public abstract void render();
protected void prepare() {
RenderSystem.pushMatrix();
RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal();
RenderSystem.enableAlphaTest();
RenderHelper.enableGuiDepthLighting();
RenderSystem.alphaFunc(516, 0.1F);
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
}
protected void transform() {
int verticalFlip = (this instanceof GuiItemRenderBuilder) ? 1 : -1;
RenderSystem.translated(xBeforeScale, yBeforeScale, 0);
RenderSystem.scaled(scale, scale, scale);
RenderSystem.translated(x, y, z);
RenderSystem.scaled(1, verticalFlip, 1);
RenderSystem.translated(rotationOffset.x, rotationOffset.y, rotationOffset.z);
RenderSystem.rotatef((float) zRot, 0, 0, 1);
RenderSystem.rotatef((float) xRot, 1, 0, 0);
RenderSystem.rotatef((float) yRot, 0, 1, 0);
RenderSystem.translated(-rotationOffset.x, -rotationOffset.y, -rotationOffset.z);
}
protected void cleanUp() {
RenderSystem.popMatrix();
RenderSystem.disableAlphaTest();
RenderSystem.disableRescaleNormal();
}
}
private static class GuiBlockModelRenderBuilder extends GuiRenderBuilder {
protected IBakedModel blockmodel;
protected BlockState blockState;
public GuiBlockModelRenderBuilder(IBakedModel blockmodel, @Nullable BlockState blockState) {
this.blockState = blockState == null ? Blocks.AIR.getDefaultState() : blockState;
this.blockmodel = blockmodel;
}
@Override
public void render() {
prepare();
Minecraft mc = Minecraft.getInstance();
BlockRendererDispatcher blockRenderer = mc.getBlockRendererDispatcher();
IRenderTypeBuffer.Impl buffer = mc.getBufferBuilders()
.getEntityVertexConsumers();
RenderType renderType = RenderTypeLookup.getEntityBlockLayer(blockState);
IVertexBuilder vb = buffer.getBuffer(renderType);
MatrixStack ms = new MatrixStack();
transform();
mc.getTextureManager()
.bindTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE);
renderModel(blockRenderer, buffer, renderType, vb, ms);
cleanUp();
}
protected void renderModel(BlockRendererDispatcher blockRenderer, IRenderTypeBuffer.Impl buffer,
RenderType renderType, IVertexBuilder vb, MatrixStack ms) {
Vec3d rgb = ColorHelper.getRGB(color);
blockRenderer.getBlockModelRenderer()
.renderModel(ms.peek(), vb, blockState, blockmodel, (float) rgb.x, (float) rgb.y, (float) rgb.z,
0xF000F0, OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE);
buffer.draw();
}
}
public static class GuiBlockStateRenderBuilder extends GuiBlockModelRenderBuilder {
public GuiBlockStateRenderBuilder(BlockState blockstate) {
super(Minecraft.getInstance()
.getBlockRendererDispatcher()
.getModelForState(blockstate), blockstate);
}
@Override
protected void renderModel(BlockRendererDispatcher blockRenderer, IRenderTypeBuffer.Impl buffer,
RenderType renderType, IVertexBuilder vb, MatrixStack ms) {
if (blockState.getBlock() instanceof FireBlock) {
RenderHelper.disableGuiDepthLighting();
blockRenderer.renderBlock(blockState, ms, buffer, 0xF000F0, OverlayTexture.DEFAULT_UV,
EmptyModelData.INSTANCE);
RenderHelper.enable();
buffer.draw();
return;
}
super.renderModel(blockRenderer, buffer, renderType, vb, ms);
if (blockState.getFluidState().isEmpty())
return;
// TODO fluids are not visible for some reason. See fan washing recipes in JEI for an example use case
for (RenderType type : RenderType.getBlockLayers()) {
if (!RenderTypeLookup.canRenderInLayer(blockState.getFluidState(), type))
continue;
vb = buffer.getBuffer(type);
blockRenderer.renderFluid(new BlockPos(0, 0, 0), Minecraft.getInstance().world, vb,
blockState.getFluidState());
buffer.draw(type);
break;
}
}
}
public static class GuiBlockPartialRenderBuilder extends GuiBlockModelRenderBuilder {
public GuiBlockPartialRenderBuilder(AllBlockPartials partial) {
super(partial.get(), null);
}
}
public static class GuiItemRenderBuilder extends GuiRenderBuilder {
private ItemStack stack;
public GuiItemRenderBuilder(ItemStack stack) {
this.stack = stack;
}
public GuiItemRenderBuilder(IItemProvider provider) {
this(new ItemStack(provider));
}
@Override
public void render() {
prepare();
transform();
Minecraft.getInstance()
.getItemRenderer()
.renderItemIntoGUI(stack, 0, 0);
cleanUp();
}
}
}

View file

@ -1,130 +0,0 @@
package com.simibubi.create.foundation.gui;
import java.util.function.Supplier;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.foundation.utility.ColorHelper;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FireBlock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.data.EmptyModelData;
public class ScreenElementRenderer {
public static void render3DItem(Supplier<ItemStack> transformsAndStack) {
RenderSystem.pushMatrix();
RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal();
RenderSystem.enableAlphaTest();
RenderHelper.enableGuiDepthLighting(); // TODO 1.15 buffered render
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
ItemStack stack = transformsAndStack.get();
Minecraft.getInstance().getItemRenderer().renderItemIntoGUI(stack, 0, 0);
RenderSystem.popMatrix();
}
public static void renderBlock(Supplier<BlockState> transformsAndState) {
renderBlock(transformsAndState, -1);
}
public static void renderBlock(Supplier<BlockState> transformsAndState, int color) {
render(transformsAndState, null, -1);
}
public static void renderModel(Supplier<IBakedModel> transformsAndModel) {
render(null, transformsAndModel, -1);
}
private static void render(Supplier<BlockState> transformsAndState, Supplier<IBakedModel> transformsAndModel,
int color) {
RenderSystem.pushMatrix();
RenderSystem.enableBlend();
RenderSystem.enableRescaleNormal();
RenderSystem.enableAlphaTest();
RenderHelper.enableGuiDepthLighting();
RenderSystem.alphaFunc(516, 0.1F);
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.translated(0, 0, 200);
Minecraft mc = Minecraft.getInstance();
BlockRendererDispatcher blockRenderer = mc.getBlockRendererDispatcher();
IBakedModel modelToRender = null;
BlockState blockToRender = Blocks.AIR.getDefaultState();
boolean stateMode = transformsAndModel == null;
boolean fire = false;
if (transformsAndModel == null) {
blockToRender = transformsAndState.get();
fire = (blockToRender.getBlock() instanceof FireBlock);
modelToRender = blockRenderer.getModelForState(blockToRender);
} else {
modelToRender = transformsAndModel.get();
}
RenderSystem.scaled(50, -50, 50);
IRenderTypeBuffer.Impl buffer = mc.getBufferBuilders().getEntityVertexConsumers();
RenderType renderType = RenderTypeLookup.getEntityBlockLayer(blockToRender);
IVertexBuilder vb = buffer.getBuffer(renderType);
MatrixStack ms = new MatrixStack();
mc.getTextureManager().bindTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE);
RenderSystem.pushMatrix();
if (fire) {
blockRenderer.renderBlock(blockToRender, ms, buffer, 0xF000F0, OverlayTexture.DEFAULT_UV,
EmptyModelData.INSTANCE);
} else {
if (modelToRender != null) {
RenderSystem.rotatef(90, 0, 1, 0);
if (color == -1) {
blockRenderer.getBlockModelRenderer().renderModel(ms.peek(), vb, blockToRender, modelToRender, 1, 1,
1, 0xF000F0, OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE);
} else {
Vec3d rgb = ColorHelper.getRGB(color);
blockRenderer.getBlockModelRenderer().renderModel(ms.peek(), vb, blockToRender, modelToRender,
(float) rgb.x, (float) rgb.y, (float) rgb.z, 0xF000F0, OverlayTexture.DEFAULT_UV,
EmptyModelData.INSTANCE);
}
}
}
RenderSystem.popMatrix();
buffer.draw(renderType);
if (blockToRender != null && !blockToRender.getFluidState().isEmpty()) {
renderType = RenderTypeLookup.getFluidLayer(blockToRender.getFluidState());
vb = buffer.getBuffer(renderType);
RenderHelper.disableStandardItemLighting();
RenderSystem.translatef(0, -300, 0);
blockRenderer.renderFluid(new BlockPos(0, 300, 0), mc.world, vb, blockToRender.getFluidState());
buffer.draw(renderType);
}
RenderSystem.disableAlphaTest();
RenderSystem.disableRescaleNormal();
RenderSystem.popMatrix();
}
}

View file

@ -3,9 +3,9 @@ package com.simibubi.create.modules.contraptions.goggle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
@ -16,6 +16,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
@ -25,6 +26,7 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber(value = Dist.CLIENT) @EventBusSubscriber(value = Dist.CLIENT)
public class GoggleOverlayRenderer { public class GoggleOverlayRenderer {
@SubscribeEvent @SubscribeEvent
public static void lookingAtBlocksThroughGogglesShowsTooltip(RenderGameOverlayEvent.Post event) { public static void lookingAtBlocksThroughGogglesShowsTooltip(RenderGameOverlayEvent.Post event) {
if (event.getType() != ElementType.HOTBAR) if (event.getType() != ElementType.HOTBAR)
@ -71,29 +73,30 @@ public class GoggleOverlayRenderer {
if (tooltip.isEmpty()) if (tooltip.isEmpty())
return; return;
GlStateManager.pushMatrix(); RenderSystem.pushMatrix();
Screen tooltipScreen = new Screen(null) { Screen tooltipScreen = new TooltipScreen(null);
@Override
public void init(Minecraft mc, int width, int height) {
this.minecraft = mc;
this.itemRenderer = mc.getItemRenderer();
this.font = mc.fontRenderer;
this.width = width;
this.height = height;
}
};
tooltipScreen.init(mc, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight()); tooltipScreen.init(mc, mc.getWindow().getScaledWidth(), mc.getWindow().getScaledHeight());
tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2); tooltipScreen.renderTooltip(tooltip, tooltipScreen.width / 2, tooltipScreen.height / 2);
ItemStack item = AllItems.GOGGLES.asStack(); ItemStack item = AllItems.GOGGLES.asStack();
ScreenElementRenderer.render3DItem(() -> { GuiGameElement.of(item).at(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16).render();
GlStateManager.translated(tooltipScreen.width / 2 + 10, tooltipScreen.height / 2 - 16, 0); RenderSystem.popMatrix();
return item; }
});
GlStateManager.popMatrix();
private static final class TooltipScreen extends Screen {
private TooltipScreen(ITextComponent p_i51108_1_) {
super(p_i51108_1_);
}
@Override
public void init(Minecraft mc, int width, int height) {
this.minecraft = mc;
this.itemRenderer = mc.getItemRenderer();
this.font = mc.fontRenderer;
this.width = width;
this.height = height;
}
} }
} }

View file

@ -7,7 +7,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllPackets; import com.simibubi.create.AllPackets;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.gui.widgets.ScrollInput; import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
@ -18,8 +18,8 @@ import net.minecraft.util.math.BlockPos;
public class SequencedGearshiftScreen extends AbstractSimiScreen { public class SequencedGearshiftScreen extends AbstractSimiScreen {
private static final ItemStack renderedItem = new ItemStack(AllBlocks.SEQUENCED_GEARSHIFT.get()); private final ItemStack renderedItem = new ItemStack(AllBlocks.SEQUENCED_GEARSHIFT.get());
private static final ScreenResources background = ScreenResources.SEQUENCER; private final ScreenResources background = ScreenResources.SEQUENCER;
private final String title = Lang.translate("gui.sequenced_gearshift.title"); private final String title = Lang.translate("gui.sequenced_gearshift.title");
private ListNBT compareTag; private ListNBT compareTag;
@ -61,7 +61,8 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen {
ScrollInput type = ScrollInput type =
new SelectionScrollInput(x, y + rowHeight * row, 50, 14).forOptions(SequencerInstructions.getOptions()) new SelectionScrollInput(x, y + rowHeight * row, 50, 14).forOptions(SequencerInstructions.getOptions())
.calling(state -> instructionUpdated(index, state)).setState(instruction.instruction.ordinal()) .calling(state -> instructionUpdated(index, state))
.setState(instruction.instruction.ordinal())
.titled(Lang.translate("gui.sequenced_gearshift.instruction")); .titled(Lang.translate("gui.sequenced_gearshift.instruction"));
ScrollInput value = ScrollInput value =
new ScrollInput(x + 54, y + rowHeight * row, 30, 14).calling(state -> instruction.value = state); new ScrollInput(x + 54, y + rowHeight * row, 30, 14).calling(state -> instruction.value = state);
@ -88,8 +89,11 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen {
ScrollInput value = rowInputs.get(1); ScrollInput value = rowInputs.get(1);
value.active = value.visible = hasValue; value.active = value.visible = hasValue;
if (hasValue) if (hasValue)
value.withRange(1, def.maxValue + 1).titled(Lang.translate(def.parameterKey)).withShiftStep(def.shiftStep) value.withRange(1, def.maxValue + 1)
.setState(instruction.value).onChanged(); .titled(Lang.translate(def.parameterKey))
.withShiftStep(def.shiftStep)
.setState(instruction.value)
.onChanged();
if (def == SequencerInstructions.WAIT) { if (def == SequencerInstructions.WAIT) {
value.withStepFunction(context -> { value.withStepFunction(context -> {
int v = context.currentValue; int v = context.currentValue;
@ -139,7 +143,13 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen {
font.drawStringWithShadow(title, guiLeft - 3 + (background.width - font.getStringWidth(title)) / 2, guiTop + 10, font.drawStringWithShadow(title, guiLeft - 3 + (background.width - font.getStringWidth(title)) / 2, guiTop + 10,
hFontColor); hFontColor);
ScreenElementRenderer.render3DItem(this::getRenderedBlock);
RenderSystem.pushMatrix();
RenderSystem.translated(guiLeft + background.width + 20, guiTop + 50, 0);
GuiGameElement.of(renderedItem)
.scale(5)
.render();
RenderSystem.popMatrix();
} }
private void label(int x, int y, String text) { private void label(int x, int y, String text) {
@ -158,12 +168,6 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen {
sendPacket(); sendPacket();
} }
public ItemStack getRenderedBlock() {
RenderSystem.translated(guiLeft + background.width + 20, guiTop + 50, 0);
RenderSystem.scaled(5, 5, 5);
return renderedItem;
}
private void instructionUpdated(int index, int state) { private void instructionUpdated(int index, int state) {
SequencerInstructions newValue = SequencerInstructions.values()[state]; SequencerInstructions newValue = SequencerInstructions.values()[state];
instructions.get(index).instruction = newValue; instructions.get(index).instruction = newValue;

View file

@ -27,26 +27,30 @@ import net.minecraft.util.math.MathHelper;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class BlockzapperItemRenderer extends ZapperItemRenderer { public class BlockzapperItemRenderer extends ZapperItemRenderer {
@Override @Override
public void render(ItemStack stack, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) { public void render(ItemStack stack, MatrixStack ms, IRenderTypeBuffer buffer, int light, int overlay) {
ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); ItemRenderer itemRenderer = Minecraft.getInstance()
BlockzapperModel mainModel = (BlockzapperModel) itemRenderer.getItemModelWithOverrides(stack, Minecraft.getInstance().world, null); .getItemRenderer();
float pt = Minecraft.getInstance().getRenderPartialTicks(); BlockzapperModel mainModel =
(BlockzapperModel) itemRenderer.getItemModelWithOverrides(stack, Minecraft.getInstance().world, null);
float pt = Minecraft.getInstance()
.getRenderPartialTicks();
float worldTime = AnimationTickHolder.getRenderTick() / 20; float worldTime = AnimationTickHolder.getRenderTick() / 20;
ms.push(); ms.push();
ms.translate(0.5F, 0.5F, 0.5F); ms.translate(0.5F, 0.5F, 0.5F);
itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, light, overlay, mainModel.getBakedModel()); itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, light, overlay,
mainModel.getBakedModel());
renderComponent(stack, mainModel, Body, itemRenderer, ms, buffer, light, overlay); renderComponent(stack, mainModel, Body, itemRenderer, ms, buffer, light, overlay);
renderComponent(stack, mainModel, Amplifier, itemRenderer, ms, buffer, light, overlay); renderComponent(stack, mainModel, Amplifier, itemRenderer, ms, buffer, light, overlay);
renderComponent(stack, mainModel, Retriever, itemRenderer, ms, buffer, light, overlay); renderComponent(stack, mainModel, Retriever, itemRenderer, ms, buffer, light, overlay);
renderComponent(stack, mainModel, Scope, itemRenderer, ms, buffer, light, overlay); renderComponent(stack, mainModel, Scope, itemRenderer, ms, buffer, light, overlay);
// Block indicator // Block indicator
if (mainModel.getCurrentPerspective() == TransformType.GUI && stack.hasTag() if (mainModel.getCurrentPerspective() == TransformType.GUI && stack.hasTag() && stack.getTag()
&& stack.getTag().contains("BlockUsed")) .contains("BlockUsed"))
renderBlockUsed(stack, itemRenderer, ms, buffer, light, overlay); renderBlockUsed(stack, itemRenderer, ms, buffer, light, overlay);
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
@ -55,8 +59,8 @@ public class BlockzapperItemRenderer extends ZapperItemRenderer {
boolean offHand = player.getHeldItemOffhand() == stack; boolean offHand = player.getHeldItemOffhand() == stack;
float last = mainHand ^ leftHanded ? ZapperRenderHandler.lastRightHandAnimation float last = mainHand ^ leftHanded ? ZapperRenderHandler.lastRightHandAnimation
: ZapperRenderHandler.lastLeftHandAnimation; : ZapperRenderHandler.lastLeftHandAnimation;
float current = mainHand ^ leftHanded ? ZapperRenderHandler.rightHandAnimation float current =
: ZapperRenderHandler.leftHandAnimation; mainHand ^ leftHanded ? ZapperRenderHandler.rightHandAnimation : ZapperRenderHandler.leftHandAnimation;
float animation = MathHelper.clamp(MathHelper.lerp(pt, last, current) * 5, 0, 1); float animation = MathHelper.clamp(MathHelper.lerp(pt, last, current) * 5, 0, 1);
// Core glows // Core glows
@ -64,10 +68,12 @@ public class BlockzapperItemRenderer extends ZapperItemRenderer {
if (mainHand || offHand) { if (mainHand || offHand) {
multiplier = animation; multiplier = animation;
} }
int glowLight = LightTexture.pack((int) (15 * multiplier), 15); int glowLight = LightTexture.pack(0, (int) (15 * multiplier));
itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, glowLight, overlay, mainModel.getPartial("core")); itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, glowLight, overlay,
mainModel.getPartial("core"));
if (BlockzapperItem.getTier(Amplifier, stack) != ComponentTier.None) if (BlockzapperItem.getTier(Amplifier, stack) != ComponentTier.None)
itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, glowLight, overlay, mainModel.getPartial("amplifier_core")); itemRenderer.renderItem(stack, TransformType.NONE, false, ms, buffer, glowLight, overlay,
mainModel.getPartial("amplifier_core"));
// Accelerator spins // Accelerator spins
float angle = worldTime * -25; float angle = worldTime * -25;

View file

@ -14,7 +14,7 @@ public class BlockzapperModel extends CustomRenderedItemModel {
public BlockzapperModel(IBakedModel template) { public BlockzapperModel(IBakedModel template) {
super(template, "blockzapper"); super(template, "blockzapper");
addPartials("core", "body", "amplifier_core", "accelerator", "gold_body", "gold_scope", "gold_amplifier", addPartials("core", "body", "amplifier_core", "accelerator", "gold_body", "gold_scope", "gold_amplifier",
"gold_retriever", "gold_accelerator", "chorus_body", "chorus_amplifier", "chorus_retriever", "gold_retriever", "gold_accelerator", "chorus_body", "chorus_scope", "chorus_amplifier", "chorus_retriever",
"chorus_accelerator"); "chorus_accelerator");
} }

View file

@ -9,13 +9,13 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllPackets; import com.simibubi.create.AllPackets;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AbstractSimiScreen;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.Label;
import com.simibubi.create.foundation.gui.widgets.ScrollInput; import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.logistics.packet.ConfigureStockswitchPacket; import com.simibubi.create.modules.logistics.packet.ConfigureStockswitchPacket;
import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack;
public class StockswitchScreen extends AbstractSimiScreen { public class StockswitchScreen extends AbstractSimiScreen {
@ -31,6 +31,7 @@ public class StockswitchScreen extends AbstractSimiScreen {
private final String stopAt = Lang.translate("gui.stockswitch.stopAt"); private final String stopAt = Lang.translate("gui.stockswitch.stopAt");
private final String lowerLimit = Lang.translate("gui.stockswitch.lowerLimit"); private final String lowerLimit = Lang.translate("gui.stockswitch.lowerLimit");
private final String upperLimit = Lang.translate("gui.stockswitch.upperLimit"); private final String upperLimit = Lang.translate("gui.stockswitch.upperLimit");
private final ItemStack renderedItem = new ItemStack(AllBlocks.STOCKSWITCH.get());
private int lastModification; private int lastModification;
private StockswitchTileEntity te; private StockswitchTileEntity te;
@ -48,8 +49,10 @@ public class StockswitchScreen extends AbstractSimiScreen {
widgets.clear(); widgets.clear();
cursorPos = te.currentLevel == -1 ? 0 : te.currentLevel; cursorPos = te.currentLevel == -1 ? 0 : te.currentLevel;
offBelowLabel = new Label(guiLeft + 116, guiTop + 72, "").colored(0xD3CBBE).withShadow(); offBelowLabel = new Label(guiLeft + 116, guiTop + 72, "").colored(0xD3CBBE)
offBelow = new ScrollInput(guiLeft + 113, guiTop + 69, 33, 14).withRange(0, 96).titled(lowerLimit) .withShadow();
offBelow = new ScrollInput(guiLeft + 113, guiTop + 69, 33, 14).withRange(0, 96)
.titled(lowerLimit)
.calling(state -> { .calling(state -> {
offBelowLabel.text = state + "%"; offBelowLabel.text = state + "%";
lastModification = 0; lastModification = 0;
@ -57,10 +60,13 @@ public class StockswitchScreen extends AbstractSimiScreen {
onAbove.setState(state + 5); onAbove.setState(state + 5);
onAbove.onChanged(); onAbove.onChanged();
} }
}).setState((int) (te.offWhenBelow * 100)); })
.setState((int) (te.offWhenBelow * 100));
onAboveLabel = new Label(guiLeft + 116, guiTop + 55, "").colored(0xD3CBBE).withShadow(); onAboveLabel = new Label(guiLeft + 116, guiTop + 55, "").colored(0xD3CBBE)
onAbove = new ScrollInput(guiLeft + 113, guiTop + 52, 33, 14).withRange(5, 101).titled(upperLimit) .withShadow();
onAbove = new ScrollInput(guiLeft + 113, guiTop + 52, 33, 14).withRange(5, 101)
.titled(upperLimit)
.calling(state -> { .calling(state -> {
onAboveLabel.text = state + "%"; onAboveLabel.text = state + "%";
lastModification = 0; lastModification = 0;
@ -68,7 +74,8 @@ public class StockswitchScreen extends AbstractSimiScreen {
offBelow.setState(state - 5); offBelow.setState(state - 5);
offBelow.onChanged(); offBelow.onChanged();
} }
}).setState((int) (te.onWhenAbove * 100)); })
.setState((int) (te.onWhenAbove * 100));
onAbove.onChanged(); onAbove.onChanged();
offBelow.onChanged(); offBelow.onChanged();
@ -101,14 +108,19 @@ public class StockswitchScreen extends AbstractSimiScreen {
ScreenResources.STOCKSWITCH_BOUND_LEFT.draw(this, (int) (guiLeft + lowerBound) - 1, guiTop + 24); ScreenResources.STOCKSWITCH_BOUND_LEFT.draw(this, (int) (guiLeft + lowerBound) - 1, guiTop + 24);
ScreenResources.STOCKSWITCH_BOUND_RIGHT.draw(this, (int) (guiLeft + upperBound) - 5, guiTop + 24); ScreenResources.STOCKSWITCH_BOUND_RIGHT.draw(this, (int) (guiLeft + upperBound) - 5, guiTop + 24);
ScreenResources cursor = te.powered ? ScreenResources.STOCKSWITCH_CURSOR_ON ScreenResources cursor =
: ScreenResources.STOCKSWITCH_CURSOR_OFF; te.powered ? ScreenResources.STOCKSWITCH_CURSOR_ON : ScreenResources.STOCKSWITCH_CURSOR_OFF;
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
RenderSystem.translatef((cursorPos * (sprite.width - 20) + 10), 0, 0); RenderSystem.translatef((cursorPos * (sprite.width - 20) + 10), 0, 0);
cursor.draw(this, guiLeft - 4, guiTop + 24); cursor.draw(this, guiLeft - 4, guiTop + 24);
RenderSystem.popMatrix(); RenderSystem.popMatrix();
ScreenElementRenderer.renderBlock(this::getRenderedBlock); RenderSystem.pushMatrix();
GuiGameElement.of(renderedItem)
.at(guiLeft + STOCKSWITCH.width + 15, guiTop + 20)
.scale(5)
.render();
RenderSystem.popMatrix();
} }
@Override @Override
@ -136,10 +148,4 @@ public class StockswitchScreen extends AbstractSimiScreen {
new ConfigureStockswitchPacket(te.getPos(), offBelow.getState() / 100f, onAbove.getState() / 100f)); new ConfigureStockswitchPacket(te.getPos(), offBelow.getState() / 100f, onAbove.getState() / 100f));
} }
public BlockState getRenderedBlock() {
RenderSystem.translated(guiLeft + STOCKSWITCH.width + 50, guiTop + 100, 0);
RenderSystem.rotatef(50, -.5f, 1, -.2f);
return AllBlocks.STOCKSWITCH.get().getDefaultState();
}
} }

View file

@ -12,15 +12,15 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllPackets; import com.simibubi.create.AllPackets;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
import com.simibubi.create.foundation.gui.ScreenElementRenderer; import com.simibubi.create.foundation.gui.GuiGameElement;
import com.simibubi.create.foundation.gui.widgets.Label; import com.simibubi.create.foundation.gui.widgets.Label;
import com.simibubi.create.foundation.gui.widgets.ScrollInput; import com.simibubi.create.foundation.gui.widgets.ScrollInput;
import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket; import com.simibubi.create.modules.logistics.packet.ConfigureFlexcratePacket;
import net.minecraft.block.BlockState;
import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.client.renderer.Rectangle2d;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContainer> { public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContainer> {
@ -32,6 +32,7 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
private List<Rectangle2d> extraAreas; private List<Rectangle2d> extraAreas;
private final ItemStack renderedItem = new ItemStack(AllBlocks.FLEXCRATE.get());
private final String title = Lang.translate("gui.flexcrate.title"); private final String title = Lang.translate("gui.flexcrate.title");
private final String storageSpace = Lang.translate("gui.flexcrate.storageSpace"); private final String storageSpace = Lang.translate("gui.flexcrate.storageSpace");
@ -47,10 +48,14 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
super.init(); super.init();
widgets.clear(); widgets.clear();
allowedItemsLabel = new Label(guiLeft + 100 + 70, guiTop + 107, "").colored(0xD3CBBE).withShadow(); allowedItemsLabel = new Label(guiLeft + 100 + 70, guiTop + 107, "").colored(0xD3CBBE)
.withShadow();
allowedItems = new ScrollInput(guiLeft + 100 + 65, guiTop + 104, 41, 14).titled(storageSpace) allowedItems = new ScrollInput(guiLeft + 100 + 65, guiTop + 104, 41, 14).titled(storageSpace)
.withRange(1, (container.doubleCrate ? 2049 : 1025)).writingTo(allowedItemsLabel).withShiftStep(64) .withRange(1, (container.doubleCrate ? 2049 : 1025))
.setState(te.allowedAmount).calling(s -> lastModification = 0); .writingTo(allowedItemsLabel)
.withShiftStep(64)
.setState(te.allowedAmount)
.calling(s -> lastModification = 0);
allowedItems.onChanged(); allowedItems.onChanged();
widgets.add(allowedItemsLabel); widgets.add(allowedItemsLabel);
widgets.add(allowedItems); widgets.add(allowedItems);
@ -80,7 +85,8 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
font.drawString(itemCount, guiLeft + 100 + 53 - font.getStringWidth(itemCount), crateTop + 107, fontColor); font.drawString(itemCount, guiLeft + 100 + 53 - font.getStringWidth(itemCount), crateTop + 107, fontColor);
PLAYER_INVENTORY.draw(this, invLeft, invTop); PLAYER_INVENTORY.draw(this, invLeft, invTop);
font.drawString(playerInventory.getDisplayName().getFormattedText(), invLeft + 7, invTop + 6, 0x666666); font.drawString(playerInventory.getDisplayName()
.getFormattedText(), invLeft + 7, invTop + 6, 0x666666);
for (int slot = 0; slot < (container.doubleCrate ? 32 : 16); slot++) { for (int slot = 0; slot < (container.doubleCrate ? 32 : 16); slot++) {
if (allowedItems.getState() > slot * 64) if (allowedItems.getState() > slot * 64)
@ -91,12 +97,12 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
ScreenResources.FLEXCRATE_LOCKED_SLOT.draw(this, x, y); ScreenResources.FLEXCRATE_LOCKED_SLOT.draw(this, x, y);
} }
ScreenElementRenderer.renderBlock(this::getRenderedBlock); RenderSystem.pushMatrix();
RenderSystem.translated(guiLeft + FLEXCRATE.width + 110, guiTop + 40, 0);
// to see or debug the bounds of the extra area uncomment the following lines GuiGameElement.of(renderedItem)
// Rectangle2d r = extraAreas.get(0); .scale(5)
// fill(r.getX() + r.getWidth(), r.getY() + r.getHeight(), r.getX(), r.getY(), .render();
// 0xd3d3d3d3); RenderSystem.popMatrix();
} }
@Override @Override
@ -123,12 +129,6 @@ public class FlexcrateScreen extends AbstractSimiContainerScreen<FlexcrateContai
container.playerInventory.player.closeScreen(); container.playerInventory.player.closeScreen();
} }
public BlockState getRenderedBlock() {
RenderSystem.translated(guiLeft + FLEXCRATE.width + 145, guiTop + 115, 0);
RenderSystem.rotatef(50, -.5f, 1, -.2f);
return AllBlocks.FLEXCRATE.get().getDefaultState();
}
@Override @Override
public List<Rectangle2d> getExtraAreas() { public List<Rectangle2d> getExtraAreas() {
return extraAreas; return extraAreas;