Finish up the multiblock preview system.

This commit is contained in:
Lizbeth Rika committed 2015-06-28 15:41:18 +01:00
1 parent 2247a1eace
commit e9f99e972d
13 files changed
+128 -21

No files matched your search

@@ -193,5 +193,10 @@ public class DummyMethodHandler implements IInternalMethodHandler {
public long getWorldElapsedTicks() {
return 0;
}
@Override
public boolean isBotaniaFlower(World world, int x, int y, int z) {
return false;
}
}
@@ -108,4 +108,6 @@ public interface IInternalMethodHandler {
public long getWorldElapsedTicks();
public boolean isBotaniaFlower(World world, int x, int y, int z);
}
@@ -11,7 +11,9 @@
package vazkii.botania.api.lexicon.multiblock.component;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.common.Botania;
import cpw.mods.fml.relauncher.Side;
@@ -32,6 +34,11 @@ public class ColorSwitchingComponent extends MultiblockComponent {
return (int) (BotaniaAPI.internalHandler.getWorldElapsedTicks() / 20) % 16;
}
@Override
public boolean matches(World world, int x, int y, int z) {
return world.getBlock(x, y, z) == getBlock();
}
@Override
public MultiblockComponent copy() {
return new ColorSwitchingComponent(relPos, block);
@@ -0,0 +1,37 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Jun 28, 2015, 3:23:15 PM (GMT)]
*/
package vazkii.botania.api.lexicon.multiblock.component;
import vazkii.botania.api.BotaniaAPI;
import net.minecraft.block.Block;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
/**
* A multiblock component that matches any botania flower.
*/
public class FlowerComponent extends ColorSwitchingComponent {
public FlowerComponent(ChunkCoordinates relPos, Block block) {
super(relPos, block);
}
@Override
public boolean matches(World world, int x, int y, int z) {
return BotaniaAPI.internalHandler.isBotaniaFlower(world, x, y, z);
}
@Override
public MultiblockComponent copy() {
return new FlowerComponent(relPos, block);
}
}
@@ -12,6 +12,7 @@ package vazkii.botania.api.lexicon.multiblock.component;
import net.minecraft.block.Block;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -43,6 +44,10 @@ public class MultiblockComponent {
return meta;
}
public boolean matches(World world, int x, int y, int z) {
return world.getBlock(x, y, z) == getBlock() && (meta == -1 || world.getBlockMetadata(x, y, z) == meta);
}
public void rotate(double angle) {
double x = relPos.posX;
double z = relPos.posZ;
@@ -106,6 +106,13 @@ public final class HUDHandler {
profiler.endSection();
}
if(MultiblockRenderHandler.currentMultiblock != null && MultiblockRenderHandler.anchor == null) {
profiler.startSection("multiblockRightClick");
String s = StatCollector.translateToLocal("botaniamisc.rightClickToAnchor");
mc.fontRenderer.drawStringWithShadow(s, event.resolution.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(s) / 2, event.resolution.getScaledHeight() / 2 - 30, 0xFFFFFF);
profiler.endSection();
}
if(equippedStack != null && equippedStack.getItem() == ModItems.craftingHalo) {
profiler.startSection("craftingHalo");
ItemCraftingHalo.renderHUD(event.resolution, mc.thePlayer, equippedStack);
@@ -17,10 +17,16 @@ import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import org.lwjgl.opengl.GL11;
@@ -39,41 +45,66 @@ public final class MultiblockRenderHandler {
public static MultiblockSet currentMultiblock;
public static ChunkCoordinates anchor;
public static int angle;
public static int blocksPlaced;
public static void setMultiblock(MultiblockSet set) {
currentMultiblock = set;
anchor = null;
angle = 0;
blocksPlaced = 0;
}
@SubscribeEvent
public void onWorldRenderLast(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft();
if(mc.thePlayer != null && mc.objectMouseOver != null) {
if(mc.thePlayer != null && mc.objectMouseOver != null && (!mc.thePlayer.isSneaking() || anchor != null)) {
ItemStack currentStack = mc.thePlayer.getCurrentEquippedItem();
renderPlayerLook(mc.thePlayer, mc.objectMouseOver);
}
}
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
if(currentMultiblock != null && anchor == null && event.action == Action.RIGHT_CLICK_BLOCK) {
anchor = new ChunkCoordinates(event.x, event.y, event.z);
angle = MathHelper.floor_double((event.entityPlayer.rotationYaw * 4.0 / 360.0) + 0.5) & 3;
event.setCanceled(true);
}
}
private void renderPlayerLook(EntityPlayer player, MovingObjectPosition src) {
if(currentMultiblock != null) {
int anchorX = anchor != null ? anchor.posX : src.blockX;
int anchorY = anchor != null ? anchor.posY : src.blockY;
int anchorZ = anchor != null ? anchor.posZ : src.blockZ;
rendering = true;
Multiblock mb = currentMultiblock.getForEntity(player);
Multiblock mb = anchor != null ? currentMultiblock.getForIndex(angle) : currentMultiblock.getForEntity(player);
boolean didAny = false;
for(MultiblockComponent comp : mb.getComponents())
renderComponent(player.worldObj, mb, comp, src);
if(renderComponent(player.worldObj, mb, comp, anchorX, anchorY, anchorZ))
didAny = true;
rendering = false;
if(!didAny) {
setMultiblock(null);
player.addChatComponentMessage(new ChatComponentTranslation("botaniamisc.structureComplete").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
}
}
}
private void renderComponent(World world, Multiblock mb, MultiblockComponent comp, MovingObjectPosition src) {
private boolean renderComponent(World world, Multiblock mb, MultiblockComponent comp, int anchorX, int anchorY, int anchorZ) {
ChunkCoordinates pos = comp.getRelativePosition();
int x = pos.posX + anchorX;
int y = pos.posY + anchorY;
int z = pos.posZ + anchorZ;
if(anchor != null && comp.matches(world, x, y, z))
return false;
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, 0.6F);
GL11.glTranslated(pos.posX + src.blockX + 0.5 - RenderManager.renderPosX, pos.posY + src.blockY + 0.55 - RenderManager.renderPosY, pos.posZ + src.blockZ + 0.5 - RenderManager.renderPosZ);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glColor4f(1F, 1F, 1F, 0.4F);
GL11.glTranslated(x + 0.5 - RenderManager.renderPosX, y + 0.5 - RenderManager.renderPosY, z + 0.5 - RenderManager.renderPosZ);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
blockRender.useInventoryTint = false;
@@ -81,7 +112,9 @@ public final class MultiblockRenderHandler {
if(IMultiblockRenderHook.renderHooks.containsKey(block))
IMultiblockRenderHook.renderHooks.get(block).renderBlockForMultiblock(world, mb, block, comp.getMeta(), blockRender);
else blockRender.renderBlockAsItem(comp.getBlock(), comp.getMeta(), 1F);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glPopMatrix();
return true;
}
}
@@ -123,7 +123,7 @@ public class RenderSpecialFlower implements ISimpleBlockRenderingHandler, IMulti
public void renderBlockForMultiblock(IBlockAccess world, Multiblock mb, Block block, int meta, RenderBlocks renderBlocks) {
Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
drawCrossedSquares(world, block, block.getIcon(0, meta), 0, 0, 0, -0.5, 0.5, -0.5, 1F, renderBlocks);
drawCrossedSquares(world, block, block.getIcon(0, meta), 0, 0, 0, -0.5, -0.5, -0.5, 1F, renderBlocks);
tess.draw();
}
@@ -13,7 +13,6 @@ package vazkii.botania.common.block.tile;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.enchantment.Enchantment;
@@ -30,10 +29,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.api.lexicon.multiblock.Multiblock;
import vazkii.botania.api.lexicon.multiblock.MultiblockSet;
import vazkii.botania.api.lexicon.multiblock.component.ColorSwitchingComponent;
import vazkii.botania.api.lexicon.multiblock.component.FlowerComponent;
import vazkii.botania.api.mana.IManaPool;
import vazkii.botania.api.mana.spark.ISparkAttachable;
import vazkii.botania.api.mana.spark.ISparkEntity;
@@ -88,10 +89,10 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
mb.addComponent(o[0], o[1] + 1, o[2], Blocks.obsidian, 0);
for(int[] p : PYLON_LOCATIONS[0]) {
mb.addComponent(p[0], p[1] + 1, p[2], ModBlocks.pylon, 0);
mb.addComponent(new ColorSwitchingComponent(new ChunkCoordinates(p[0], p[1] - 1, p[2]), ModBlocks.flower));
mb.addComponent(new FlowerComponent(new ChunkCoordinates(p[0], p[1], p[2]), ModBlocks.flower));
}
for(int[] f : FLOWER_LOCATIONS)
mb.addComponent(new ColorSwitchingComponent(new ChunkCoordinates(f[0], f[1], f[2]), ModBlocks.flower));
mb.addComponent(new FlowerComponent(new ChunkCoordinates(f[0], f[1] + 1, f[2]), ModBlocks.flower));
mb.addComponent(0, 1, 0, Blocks.lapis_block, 0);
@@ -369,16 +370,12 @@ public class TileEnchanter extends TileMod implements ISparkAttachable {
return false;
for(int[] pylon : PYLON_LOCATIONS[meta])
if(world.getBlock(pylon[0] + x, pylon[1] + y, pylon[2] + z) != ModBlocks.pylon ||
world.getBlock(pylon[0] + x, pylon[1] + y - 1, pylon[2] + z) != ModBlocks.flower && world.getBlock(pylon[0] + x, pylon[1] + y - 1, pylon[2] + z) != ModBlocks.shinyFlower)
if(world.getBlock(pylon[0] + x, pylon[1] + y, pylon[2] + z) != ModBlocks.pylon || !BotaniaAPI.internalHandler.isBotaniaFlower(world, pylon[0] + x, pylon[1] + y - 1, pylon[2] + z))
return false;
for(int[] flower : FLOWER_LOCATIONS) {
Block block = world.getBlock(flower[0] + x, flower[1] + y, flower[2] + z);
if(block != ModBlocks.flower && block != ModBlocks.shinyFlower)
for(int[] flower : FLOWER_LOCATIONS)
if(!BotaniaAPI.internalHandler.isBotaniaFlower(world, flower[0] + x, flower[1] + y, flower[2] + z))
return false;
}
return true;
}
@@ -12,6 +12,7 @@ package vazkii.botania.common.core.handler;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@@ -216,4 +217,10 @@ public class InternalMethodHandler extends DummyMethodHandler {
public long getWorldElapsedTicks() {
return Botania.proxy.getWorldElapsedTicks();
}
@Override
public boolean isBotaniaFlower(World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == ModBlocks.flower || block == ModBlocks.shinyFlower || block == ModBlocks.specialFlower;
}
}
@@ -528,7 +528,7 @@ public final class LexiconData {
if(ConfigHandler.enchanterEnabled) {
manaEnchanting = new BLexiconEntry(LibLexicon.DEVICE_MANA_ENCHANTING, categoryDevices);
manaEnchanting.setLexiconPages(new PageText("0"), new PageText("1"), new PageMultiblock("2", ModMultiblocks.enchanter), new PageText("3"), new PageText("4"), new PageText("5"), new PageText("6"), new PageText("7")).setIcon(new ItemStack(ModBlocks.enchanter));
manaEnchanting.setLexiconPages(new PageText("0"), new PageText("1"), new PageMultiblock("2", ModMultiblocks.enchanter), new PageText("5"), new PageText("6"), new PageText("7")).setIcon(new ItemStack(ModBlocks.enchanter));
}
turntable = new BLexiconEntry(LibLexicon.DEVICE_TURNTABLE, categoryDevices);
@@ -27,6 +27,7 @@ import org.lwjgl.opengl.GL11;
import vazkii.botania.api.internal.IGuiLexiconEntry;
import vazkii.botania.api.lexicon.LexiconPage;
import vazkii.botania.api.lexicon.multiblock.IMultiblockRenderHook;
import vazkii.botania.api.lexicon.multiblock.Multiblock;
import vazkii.botania.api.lexicon.multiblock.MultiblockSet;
import vazkii.botania.api.lexicon.multiblock.component.MultiblockComponent;
@@ -98,7 +99,11 @@ public class PageMultiblock extends LexiconPage {
GL11.glPushMatrix();
GL11.glTranslatef(x, y, z);
RenderBlocks.getInstance().renderBlockAsItem(block, meta, 0.8F);
RenderBlocks blockRender = RenderBlocks.getInstance();
if(IMultiblockRenderHook.renderHooks.containsKey(block))
IMultiblockRenderHook.renderHooks.get(block).renderBlockForMultiblock(Minecraft.getMinecraft().theWorld, mb, block, meta, blockRender);
else blockRender.renderBlockAsItem(block, meta, 0.8F);
GL11.glPopMatrix();
}
}