mirror of
https://github.com/GTNewHorizons/BetterBuildersWands.git
synced 2026-11-26 06:52:59 +00:00
Get block outline working + use metadata.
This commit is contained in:
1 parent
faad24ef08
commit
8bfddeda62
4 files changed
+60
No files matched your search
@@ -2,7 +2,25 @@ package portablejim.bbw.core;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import portablejim.bbw.basics.Point3d;
|
||||
import portablejim.bbw.core.items.IWandItem;
|
||||
import portablejim.bbw.core.wands.UnbreakingWand;
|
||||
import portablejim.bbw.shims.BasicPlayerShim;
|
||||
import portablejim.bbw.shims.BasicWorldShim;
|
||||
import portablejim.bbw.shims.CreativePlayerShim;
|
||||
import portablejim.bbw.shims.IPlayerShim;
|
||||
import portablejim.bbw.shims.IWorldShim;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Events for supporting wands.
|
||||
@@ -10,6 +28,35 @@ import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
public class BlockEvents {
|
||||
@SubscribeEvent
|
||||
public void blockHighlightEvent(DrawBlockHighlightEvent event) {
|
||||
if(event.currentItem != null && event.currentItem.getItem() instanceof IWandItem
|
||||
&& event.target != null && event.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
IPlayerShim playerShim = new BasicPlayerShim(event.player);
|
||||
if(event.player.capabilities.isCreativeMode) {
|
||||
playerShim = new CreativePlayerShim();
|
||||
}
|
||||
IWorldShim worldShim = new BasicWorldShim(event.player.getEntityWorld());
|
||||
UnbreakingWand unbreakingWand = new UnbreakingWand(event.currentItem);
|
||||
|
||||
WandWorker worker = new WandWorker(unbreakingWand, playerShim, worldShim);
|
||||
|
||||
Point3d clickedPos = new Point3d(event.target.blockX, event.target.blockY, event.target.blockZ);
|
||||
|
||||
ItemStack targetItemstack = worker.getEquivalentItemStack(clickedPos);
|
||||
int numBlocks = Math.min(unbreakingWand.getMaxBlocks(), playerShim.countItems(targetItemstack));
|
||||
|
||||
LinkedList<Point3d> blocks = worker.getBlockPositionList(clickedPos, ForgeDirection.getOrientation(event.target.sideHit), numBlocks);
|
||||
if(blocks.size() > 0) {
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDepthMask(false);
|
||||
GL11.glLineWidth(2.5F);
|
||||
for(Point3d block : blocks) {
|
||||
AxisAlignedBB boundingBox = AxisAlignedBB.getBoundingBox(block.x, block.y, block.z, block.x + 1, block.y + 1, block.z + 1).contract(0.005, 0.005, 0.005);
|
||||
RenderGlobal.drawOutlinedBoundingBox(boundingBox.getOffsetBoundingBox(-event.player.posX, -event.player.posY, -event.player.posZ), 0xC0C0C0);
|
||||
}
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
}
|
||||
//FMLLog.info("Happened!" + event.target.toString());
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class WandWorker {
|
||||
LinkedList<Point3d> toPlace = new LinkedList<Point3d>();
|
||||
|
||||
Block targetBlock = world.getBlock(blockLookedAt);
|
||||
int targetMetadata = world.getMetadata(blockLookedAt);
|
||||
Point3d startingPoint = blockLookedAt.move(placeDirection);
|
||||
|
||||
candidates.add(startingPoint);
|
||||
@@ -48,8 +49,10 @@ public class WandWorker {
|
||||
|
||||
Point3d supportingPoint = currentCandidate.move(placeDirection.getOpposite());
|
||||
Block candidateSupportingBlock = world.getBlock(supportingPoint);
|
||||
int candidateSupportingMeta = world.getMetadata(supportingPoint);
|
||||
if(world.blockIsAir(currentCandidate)
|
||||
&& targetBlock.equals(candidateSupportingBlock)
|
||||
&& targetMetadata == candidateSupportingMeta
|
||||
&& allCandidates.add(currentCandidate)) {
|
||||
toPlace.add(currentCandidate);
|
||||
switch (placeDirection) {
|
||||
|
||||
@@ -46,4 +46,12 @@ public class BasicWorldShim implements IWorldShim {
|
||||
public void setBlockToAir(Point3d blockPos) {
|
||||
world.setBlock(blockPos.x, blockPos.y, blockPos.z, Blocks.air);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(Point3d point) {
|
||||
if(world != null) {
|
||||
return world.getBlockMetadata(point.x, point.y, point.z);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,6 @@ public interface IWorldShim {
|
||||
boolean copyBlock(Point3d originalBlock, Point3d blockPos);
|
||||
|
||||
void setBlockToAir(Point3d blockPos);
|
||||
|
||||
int getMetadata(Point3d blockPos);
|
||||
}
|
||||
Reference in new issue
Block a user