More astrolabe stuff

This commit is contained in:
Vasco Lavos committed 2016-10-27 19:09:16 +01:00
1 parent 147c32d657
commit 5c3a2c700b
6 files changed
+145 -14

No files matched your search

@@ -0,0 +1,113 @@
/**
* 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 @ [27/10/2016, 17:55:20 (GMT)]
*/
package vazkii.botania.client.core.handler;
import java.util.List;
import org.lwjgl.opengl.ARBShaderObjects;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockRendererDispatcher;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.shader.Shader;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.common.item.ItemAstrolabe;
public final class AstrolabePreviewHandler {
@SubscribeEvent
public static void onWorldRenderLast(RenderWorldLastEvent event) {
World world = Minecraft.getMinecraft().theWorld;
List<EntityPlayer> playerEntities = world.playerEntities;
for (EntityPlayer player : playerEntities) {
ItemStack currentStack = player.getHeldItemMainhand();
if(currentStack == null || !(currentStack.getItem() instanceof ItemAstrolabe))
currentStack = player.getHeldItemOffhand();
if(currentStack != null && currentStack.getItem() instanceof ItemAstrolabe) {
Block block = ItemAstrolabe.getBlock(currentStack);
if(block != Blocks.AIR)
renderPlayerLook(player, currentStack);
}
}
}
private static void renderPlayerLook(EntityPlayer player, ItemStack stack) {
BlockPos[] coords = ItemAstrolabe.getBlocksToPlace(stack, player);
if (ItemAstrolabe.hasBlocks(stack, player, coords)) {
Block block = ItemAstrolabe.getBlock(stack);
int meta = ItemAstrolabe.getBlockMeta(stack);
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
ShaderHelper.useShader(ShaderHelper.alpha, shader -> {
int alpha = ARBShaderObjects.glGetUniformLocationARB(shader, "alpha");
ARBShaderObjects.glUniform1fARB(alpha, 0.4F);
});
for(BlockPos coord : coords)
renderBlockAt(block, meta, coord);
ShaderHelper.releaseShader();
GL11.glPopMatrix();
}
}
private static void renderBlockAt(Block block, int meta, BlockPos pos) {
IBlockState state = block.getStateFromMeta(meta);
if(state == null)
return;
double renderPosX, renderPosY, renderPosZ;
try {
renderPosX = (double) ClientMethodHandles.renderPosX_getter.invokeExact(Minecraft.getMinecraft().getRenderManager());
renderPosY = (double) ClientMethodHandles.renderPosY_getter.invokeExact(Minecraft.getMinecraft().getRenderManager());
renderPosZ = (double) ClientMethodHandles.renderPosZ_getter.invokeExact(Minecraft.getMinecraft().getRenderManager());
} catch (Throwable t) {
return;
}
GlStateManager.pushMatrix();
GlStateManager.translate(-renderPosX, -renderPosY, -renderPosZ);
GlStateManager.disableDepth();
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
GlStateManager.translate(pos.getX(), pos.getY(), pos.getZ() + 1);
GlStateManager.color(1, 1, 1, 1);
brd.renderBlockBrightness(state, 1.0F);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.enableDepth();
GlStateManager.popMatrix();
GlStateManager.popMatrix();
}
}
@@ -53,6 +53,7 @@ import vazkii.botania.api.lexicon.multiblock.component.AnyComponent;
import vazkii.botania.api.wiki.IWikiProvider;
import vazkii.botania.api.wiki.WikiHooks;
import vazkii.botania.client.challenge.ModChallenges;
import vazkii.botania.client.core.handler.AstrolabePreviewHandler;
import vazkii.botania.client.core.handler.BaubleRenderHandler;
import vazkii.botania.client.core.handler.BlockHighlightRenderHandler;
import vazkii.botania.client.core.handler.BossBarHandler;
@@ -215,6 +216,7 @@ public class ClientProxy implements IProxy {
MinecraftForge.EVENT_BUS.register(new RenderLexicon());
MinecraftForge.EVENT_BUS.register(BossBarHandler.class);
MinecraftForge.EVENT_BUS.register(BergamuteEventHandler.class);
MinecraftForge.EVENT_BUS.register(AstrolabePreviewHandler.class);
if(ConfigHandler.useAdaptativeConfig)
MinecraftForge.EVENT_BUS.register(AdaptorNotifier.class);
@@ -119,6 +119,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
addBlock(ModBlocks.teruTeruBozu);
addItem(ModItems.slimeBottle);
addItem(ModItems.sextant);
addItem(ModItems.astrolabe);
addItem(ModItems.blackHoleTalisman);
if(Botania.gardenOfGlassLoaded) {
@@ -26,6 +26,7 @@ import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
@@ -58,7 +59,12 @@ public class ItemAstrolabe extends ItemMod {
if(playerIn.isSneaking()) {
if(setBlock(stack, block, meta))
return EnumActionResult.SUCCESS;
} else placeAllBlocks(stack, playerIn);
} else {
boolean did = placeAllBlocks(stack, playerIn);
if(!worldIn.isRemote)
playerIn.swingArm(hand);
return did ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
return EnumActionResult.PASS;
}
@@ -78,16 +84,15 @@ public class ItemAstrolabe extends ItemMod {
return new ActionResult(EnumActionResult.PASS, itemStackIn);
}
public void placeAllBlocks(ItemStack stack, EntityPlayer player) {
public boolean placeAllBlocks(ItemStack stack, EntityPlayer player) {
BlockPos[] blocksToPlace = getBlocksToPlace(stack, player);
if(!hasBlocks(stack, player, blocksToPlace))
return;
return false;
ItemStack stackToPlace = new ItemStack(getBlock(stack), 1, getBlockMeta(stack));
for(BlockPos coords : blocksToPlace)
placeBlockAndConsume(player, stack, stackToPlace, coords);
// player.worldObj.playSoundAtEntity(player, "thaumcraft:wand", 1F, 1F); TODO
return true;
}
private void placeBlockAndConsume(EntityPlayer player, ItemStack requestor, ItemStack blockToPlace, BlockPos coords) {
@@ -96,9 +101,11 @@ public class ItemAstrolabe extends ItemMod {
Block block = Block.getBlockFromItem(blockToPlace.getItem());
int meta = blockToPlace.getItemDamage();
player.worldObj.setBlockState(coords, block.getStateFromMeta(meta), 1 | 2);
IBlockState state = block.getStateFromMeta(meta);
player.worldObj.setBlockState(coords, state, 1 | 2);
player.worldObj.playEvent(2001, coords, Block.getStateId(state));
if (player.capabilities.isCreativeMode)
if(player.capabilities.isCreativeMode)
return;
List<ItemStack> stacksToCheck = new ArrayList();
@@ -170,16 +177,23 @@ public class ItemAstrolabe extends ItemMod {
if(block != null && block.isReplaceable(player.worldObj, bpos))
bpos = bpos.down();;
EnumFacing dir = pos.sideHit;
int rotation = MathHelper.floor_double(player.rotationYaw * 4F / 360F + 0.5D) & 3;
int range = (getSize(stack) ^ 1) / 2;
boolean topOrBottom = dir == EnumFacing.UP || dir == EnumFacing.DOWN;
int xOff = !(dir == EnumFacing.WEST || dir == EnumFacing.EAST) ? topOrBottom ? player.rotationPitch > 75 || (rotation & 1) == 0 ? range : 0 : range : 0;
int yOff = topOrBottom ? player.rotationPitch > 75 ? 0 : range : range;
int zOff = !(dir == EnumFacing.SOUTH || dir == EnumFacing.NORTH) ? topOrBottom ? player.rotationPitch > 75 || (rotation & 1) == 1 ? range : 0 : range : 0;
EnumFacing dir = pos.sideHit;
EnumFacing rotationDir = EnumFacing.fromAngle(player.rotationYaw);
boolean pitchedVertically = player.rotationPitch > 70 || player.rotationPitch < -70;
boolean axisX = rotationDir.getAxis() == Axis.X;
boolean axisZ = rotationDir.getAxis() == Axis.Z;
int xOff, yOff, zOff;
xOff = axisZ || pitchedVertically ? range : 0;
yOff = pitchedVertically ? 0 : range;
zOff = axisX || pitchedVertically ? range : 0;
for(int x = -xOff; x < xOff + 1; x++)
for(int y = 0; y < yOff * 2 + 1; y++) {
for(int z = -zOff; z < zOff + 1; z++) {
@@ -1608,6 +1608,7 @@ item.botania:invisibilityCloak.name=Invisibility Cloak
item.botania:cloudPendant.name=Cirrus Amulet
item.botania:superCloudPendant.name=Nimbus Amulet
item.botania:thirdEye.name=Third Eye
item.botania:astrolabe.name=Worldshaper's Astrolabe
# BREW NAMES
botania.brew.fallback=Fallback
File renamed without changes.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB