use of mods.railcraft.common.blocks.logic.StructureLogic in project Railcraft by Railcraft.
the class TESRTurbineGauge method render.
@Override
public void render(TileSteamTurbine turbine, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
StructureLogic structure = turbine.getLogic(StructureLogic.class).orElse(null);
if (structure == null || structure.getPatternMarker() != 'W')
// not a gauge block
return;
turbine.getLogic(SteamTurbineLogic.class).ifPresent(logic -> {
double xx = x;
double zz = z;
// half width of the needle
double halfWidth = 0.5 / 16;
// length of the needle (along the center)
double len = 0.26;
// offset to prevent z-fighting
double zOffset = 0.001;
// average the value over time to smooth the needle
double value = turbine.guageReadout = logic.readGauge(turbine.guageReadout);
// set the needle angle between 45° (= 0%) and 135° (= 100%)
double angle = Math.toRadians(90 * value + 45);
// vector towards the front of the gauge
int fx = 0, fz = 0;
// vector to the right when looking at the gauge
int rx = 0, rz = 0;
BlockPos patternPos = structure.getPatternPosition();
if (structure.getPatternIndex() == 0) {
if (patternPos.getX() == 1) {
fx = -1;
rz = 1;
} else if (patternPos.getX() == 2) {
xx++;
zz++;
fx = 1;
rz = -1;
}
} else if (structure.getPatternIndex() == 1)
if (patternPos.getZ() == 1) {
xx++;
fz = -1;
rx = -1;
} else if (patternPos.getZ() == 2) {
zz++;
fz = 1;
rx = 1;
}
if (fx == 0 && fz == 0 || rx == 0 && rz == 0)
throw new IllegalStateException("can't detect gauge orientation");
// fix lightmap coords to use the brightness value in front of the block, not inside it (which would be just 0)
int lmCoords = turbine.getWorld().getCombinedLight(turbine.getPos().add(fx, 0, fz), 0);
int lmX = lmCoords % 65536;
int lmY = lmCoords / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lmX / 1.0F, lmY / 1.0F);
OpenGL.glDisable(GL11.GL_TEXTURE_2D);
OpenGL.glDisable(GL11.GL_LIGHTING);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder vertexBuffer = tessellator.getBuffer();
vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
// move the origin to the center of the gauge
vertexBuffer.setTranslation(xx + rx * 0.5 + fx * zOffset, y + 0.5, zz + rz * 0.5 + fz * zOffset);
double cosA = Math.cos(angle);
double sinA = Math.sin(angle);
// displacement along the length of the needle
double glx = cosA * len;
double gly = sinA * len;
// displacement along the width of the needle
double gwx = sinA * halfWidth;
double gwy = cosA * halfWidth;
// half width of the horizontal needle part where it connects to the "case"
double baseOffset = 1. / Math.sin(angle) * halfWidth;
// set the needle color to dark-ish red
int red = 100;
int green = 0;
int blue = 0;
int alphaOne = 255;
vertexBuffer.pos(-rx * baseOffset, 0, -rz * baseOffset).color(red, green, blue, alphaOne).endVertex();
vertexBuffer.pos(rx * baseOffset, 0, rz * baseOffset).color(red, green, blue, alphaOne).endVertex();
vertexBuffer.pos(-rx * glx + rx * gwx, gly + gwy, -rz * glx + rz * gwx).color(red, green, blue, alphaOne).endVertex();
vertexBuffer.pos(-rx * glx - rx * gwx, gly - gwy, -rz * glx - rz * gwx).color(red, green, blue, alphaOne).endVertex();
tessellator.draw();
// resetting
vertexBuffer.setTranslation(0, 0, 0);
OpenGL.glEnable(GL11.GL_LIGHTING);
OpenGL.glEnable(GL11.GL_TEXTURE_2D);
});
}
use of mods.railcraft.common.blocks.logic.StructureLogic in project Railcraft by Railcraft.
the class TESRHollowTank method render.
@Override
public void render(TileTank tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
tile.getLogic(StructureLogic.class).filter(StructureLogic::isStructureValid).ifPresent(structure -> {
structure.getLogic(ValveLogic.class).ifPresent(valve -> {
StandardTank fillTank = valve.getFillTank();
FluidStack fillStack = fillTank.getFluid();
if (fillStack != null && fillStack.amount > 0) {
OpenGL.glPushMatrix();
if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().down()) == 'A') {
// prepFillTexture(fillStack);
int height = getTankHeight(structure);
float yOffset = height / 2f;
float vScale = height;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset - height + 1, (float) z + 0.5F);
OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
draw(fillStack, tile.getPos().down());
} else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().west()) == 'A') {
// prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(structure);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x - 0.5F + RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
draw(fillStack, tile.getPos().west());
} else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().east()) == 'A') {
// prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(structure);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 1.5F - RenderTools.PIXEL * 5, (float) y + yOffset, (float) z + 0.5F);
OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
draw(fillStack, tile.getPos().east());
} else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().north()) == 'A') {
// prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(structure);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z - 0.5F + RenderTools.PIXEL * 5);
OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
draw(fillStack, tile.getPos().north());
} else if (structure.getPattern().getPatternMarkerChecked(structure.getPatternPosition().south()) == 'A') {
// prepFillTexture(fillStack);
float vScale = getVerticalScaleSide(structure);
float yOffset = 0.5f - vScale / 2f + RenderTools.PIXEL * 3;
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset, (float) z + 1.5F - RenderTools.PIXEL * 5);
OpenGL.glScalef(FILL_SCALE, vScale, FILL_SCALE);
draw(fillStack, tile.getPos().south());
}
OpenGL.glPopMatrix();
}
});
if (!structure.isValidMaster() || tile.isInvalid())
return;
int height = getTankHeight(structure);
float yOffset = height / 2f;
float vScale = height - 2;
float hScale = structure.getPattern().getPatternWidthX() - 2;
structure.getFunctionalLogic(FluidLogic.class).map(fluidLogic -> fluidLogic.getTankManager().get(0)).ifPresent(tank -> {
FluidStack fluidStack = tank.getFluid();
if (fluidStack != null && fluidStack.amount > 0) {
preGL(fluidStack, tile.getPos().up());
OpenGL.glTranslatef((float) x + 0.5F, (float) y + yOffset + 0.01f, (float) z + 0.5F);
OpenGL.glScalef(hScale, vScale, hScale);
OpenGL.glScalef(0.999f, 1, 0.999f);
// int[] displayLists = FluidRenderer.getLiquidDisplayLists(fluidStack); this broke
// OpenGL.glPushMatrix();
//
OpenGL.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
float cap = tank.getCapacity();
OpenGL.glTranslatef(-0.5F, -0.501F, -0.5F);
float level = Math.min(fluidStack.amount / cap, 1.0F);
FluidModelRenderer.INSTANCE.renderFluid(fluidStack, Math.min(16, (int) Math.ceil(level * 16F)));
//
// bindTexture(FluidRenderer.getFluidSheet(fluidStack));
// FluidRenderer.setColorForFluid(fluidStack);
// OpenGL.glCallList(displayLists[(int) (level * (float) (FluidRenderer.DISPLAY_STAGES - 1))]);
postGL();
// OpenGL.glPopMatrix();
}
});
});
}
use of mods.railcraft.common.blocks.logic.StructureLogic in project Railcraft by Railcraft.
the class ItemMagnifyingGlass method onItemUseFirst.
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (Game.isClient(world))
return EnumActionResult.PASS;
TileEntity t = WorldPlugin.getBlockTile(world, pos);
EnumActionResult returnValue = EnumActionResult.PASS;
if (t instanceof IOwnable) {
IOwnable ownable = (IOwnable) t;
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.placedby", ownable.getDisplayName(), ownable.getOwner());
returnValue = EnumActionResult.SUCCESS;
}
if (t instanceof TileMultiBlock) {
TileMultiBlock tile = (TileMultiBlock) t;
if (tile.isStructureValid()) {
ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (tile.isValidMaster() ? "true" : "false"));
} else
for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
List<StructurePattern> pats = tile.patternStates.get(returnState);
if (!pats.isEmpty()) {
List<Integer> indexList = pats.stream().map(map -> tile.getPatterns().indexOf(map)).collect(Collectors.toList());
ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
}
}
returnValue = EnumActionResult.SUCCESS;
}
if (t instanceof TileLogic) {
TileLogic tile = (TileLogic) t;
Optional<StructureLogic> optLogic = tile.getLogic(StructureLogic.class);
if (optLogic.isPresent()) {
StructureLogic logic = optLogic.get();
if (logic.isStructureValid()) {
ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.valid");
ChatPlugin.sendLocalizedChatFromServer(player, "railcraft.multiblock.state.master." + (logic.isValidMaster() ? "true" : "false"));
} else
for (State returnState : EnumSet.complementOf(EnumSet.of(State.VALID))) {
List<StructurePattern> pats = logic.patternStates.get(returnState);
if (!pats.isEmpty()) {
List<Integer> indexList = pats.stream().map(map -> logic.getPatterns().indexOf(map)).collect(Collectors.toList());
ChatPlugin.sendLocalizedChatFromServer(player, returnState.message, indexList.toString());
}
}
returnValue = EnumActionResult.SUCCESS;
}
}
if (t instanceof IDualHeadSignal) {
IDualHeadSignal signal = (IDualHeadSignal) t;
SignalAspect top = signal.getSignalAspect(DualLamp.TOP);
SignalAspect bottom = signal.getSignalAspect(DualLamp.BOTTOM);
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect.dual", top.getLocalizationTag(), bottom.getLocalizationTag());
returnValue = EnumActionResult.SUCCESS;
} else if (t instanceof TileSignalBase) {
ChatPlugin.sendLocalizedChatFromServer(player, "gui.railcraft.mag.glass.aspect", ((TileSignalBase) t).getSignalAspect().getLocalizationTag());
returnValue = EnumActionResult.SUCCESS;
}
if (t instanceof IMagnifiable) {
((IMagnifiable) t).onMagnify(player);
}
return returnValue;
}
Aggregations