mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Got the Ring of Loki working. Still need to patch up block breaking but that's a start :D
This commit is contained in:
1 parent
804b57573f
commit
192cd5b1d5
7 files changed
+256
-8
No files matched your search
+14
-1
@@ -8,17 +8,30 @@
|
||||
*
|
||||
* File Created @ [Mar 29, 2015, 7:17:41 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item.relic;
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
|
||||
/**
|
||||
* An item that implements this counts as a Relic item. This is purely for interaction
|
||||
* and other mod items should not implement this interface.
|
||||
*/
|
||||
public interface IRelic {
|
||||
|
||||
/**
|
||||
* Gets the username of the person this relic is bound to.
|
||||
*/
|
||||
public String getSoulbindUsername(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Sets the achievement that this relic binds to.
|
||||
*/
|
||||
public void setBindAchievement(Achievement achievement);
|
||||
|
||||
/**
|
||||
* Gets the achievement that this relic binds to.
|
||||
*/
|
||||
public Achievement getBindAchievement();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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 @ [Mar 29, 2015, 11:30:41 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.api.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
|
||||
/**
|
||||
* An item that implements this will allow for various wireframes to be drawn
|
||||
* around the player. This will be called while the item is in the inventory,
|
||||
* armor slot or bauble slots.
|
||||
*/
|
||||
public interface IWireframeCoordinateListProvider {
|
||||
|
||||
/**
|
||||
* Returns a list of ChunkCoordinates for the wireframes to draw.
|
||||
* Can be null.
|
||||
*/
|
||||
public List<ChunkCoordinates> getWireframesToDraw(EntityPlayer player, ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
@API(owner = "Botania", apiVersion = "36", provides = "BotaniaAPI")
|
||||
@API(owner = "Botania", apiVersion = "37", provides = "BotaniaAPI")
|
||||
package vazkii.botania.api;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
package vazkii.botania.client.core.handler;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
@@ -25,6 +27,8 @@ import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.item.IWireframeCoordinateListProvider;
|
||||
import vazkii.botania.api.wand.ICoordBoundItem;
|
||||
import vazkii.botania.api.wand.IWireframeAABBProvider;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -42,10 +46,33 @@ public final class BoundTileRenderer {
|
||||
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
int color = Color.HSBtoRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F);
|
||||
if(stack != null && stack.getItem() instanceof ICoordBoundItem) {
|
||||
ChunkCoordinates coords = ((ICoordBoundItem) stack.getItem()).getBinding(stack);
|
||||
if(coords != null)
|
||||
renderBlockOutlineAt(coords, Color.HSBtoRGB(ClientTickHandler.ticksInGame % 200 / 200F, 0.6F, 1F));
|
||||
renderBlockOutlineAt(coords, color);
|
||||
}
|
||||
|
||||
IInventory mainInv = player.inventory;
|
||||
IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player);
|
||||
|
||||
int invSize = mainInv.getSizeInventory();
|
||||
int size = invSize;
|
||||
if(baublesInv != null)
|
||||
size += baublesInv.getSizeInventory();
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
boolean useBaubles = i >= invSize;
|
||||
IInventory inv = useBaubles ? baublesInv : mainInv;
|
||||
ItemStack stackInSlot = inv.getStackInSlot(i - (useBaubles ? invSize : 0));
|
||||
|
||||
if(stackInSlot != null && stackInSlot.getItem() instanceof IWireframeCoordinateListProvider) {
|
||||
IWireframeCoordinateListProvider provider = (IWireframeCoordinateListProvider) stackInSlot.getItem();
|
||||
List<ChunkCoordinates> coordsList = provider.getWireframesToDraw(player, stackInSlot);
|
||||
if(coordsList != null)
|
||||
for(ChunkCoordinates coords : coordsList)
|
||||
renderBlockOutlineAt(coords, color);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
@@ -10,19 +10,193 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.relic;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import baubles.api.BaubleType;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemLokiRing extends ItemRelicBauble {
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import vazkii.botania.api.item.IWireframeCoordinateListProvider;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.equipment.tool.ToolCommons;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemLokiRing extends ItemRelicBauble implements IWireframeCoordinateListProvider {
|
||||
|
||||
private static final String TAG_CURSOR_LIST = "cursorList";
|
||||
private static final String TAG_CURSOR_PREFIX = "cursor";
|
||||
private static final String TAG_CURSOR_COUNT = "cursorCount";
|
||||
private static final String TAG_X_OFFSET = "xOffset";
|
||||
private static final String TAG_Y_OFFSET = "yOffset";
|
||||
private static final String TAG_Z_OFFSET = "zOffset";
|
||||
private static final String TAG_X_ORIGIN = "xOrigin";
|
||||
private static final String TAG_Y_ORIGIN = "yOrigin";
|
||||
private static final String TAG_Z_ORIGIN = "zOrigin";
|
||||
|
||||
public ItemLokiRing() {
|
||||
super(LibItemNames.LOKI_RING);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
EntityPlayer player = event.entityPlayer;
|
||||
ItemStack lokiRing = getLokiRing(player);
|
||||
if(lokiRing == null || player.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
ItemStack heldItemStack = player.getCurrentEquippedItem();
|
||||
ChunkCoordinates originCoords = getOriginPos(lokiRing);
|
||||
MovingObjectPosition lookPos = ToolCommons.raytraceFromEntity(player.worldObj, player, true, 4.5F);
|
||||
|
||||
if(heldItemStack == null && event.action == Action.RIGHT_CLICK_BLOCK && player.isSneaking()) {
|
||||
if(originCoords.posY == -1 && lookPos != null) {
|
||||
setOriginPos(lokiRing, lookPos.blockX, lookPos.blockY, lookPos.blockZ);
|
||||
setCursorList(lokiRing, null);
|
||||
} else if(lookPos != null) {
|
||||
if(originCoords.posX == lookPos.blockX && originCoords.posY == lookPos.blockY && originCoords.posZ == lookPos.blockZ)
|
||||
setOriginPos(lokiRing, 0, -1, 0);
|
||||
else {
|
||||
List<ChunkCoordinates> cursors = getCursorList(lokiRing);
|
||||
addCursor : {
|
||||
for(ChunkCoordinates cursor : cursors)
|
||||
if(cursor.posX == lookPos.blockX && cursor.posY == lookPos.blockY && cursor.posZ == lookPos.blockZ)
|
||||
break addCursor;
|
||||
|
||||
addCursor(lokiRing, lookPos.blockX - originCoords.posX, lookPos.blockY - originCoords.posY, lookPos.blockZ - originCoords.posZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(heldItemStack != null && event.action == Action.RIGHT_CLICK_BLOCK && lookPos != null) {
|
||||
List<ChunkCoordinates> cursors = getCursorList(lokiRing);
|
||||
for(ChunkCoordinates cursor : cursors) {
|
||||
int x = lookPos.blockX + cursor.posX;
|
||||
int y = lookPos.blockY + cursor.posY;
|
||||
int z = lookPos.blockZ + cursor.posZ;
|
||||
Item item = heldItemStack.getItem();
|
||||
item.onItemUse(player.capabilities.isCreativeMode ? heldItemStack.copy() : heldItemStack, player, player.worldObj, x, y, z, lookPos.sideHit, (float) lookPos.hitVec.xCoord - x, (float) lookPos.hitVec.yCoord - y, (float) lookPos.hitVec.zCoord - z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaubleType getBaubleType(ItemStack arg0) {
|
||||
return BaubleType.RING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnequipped(ItemStack stack, EntityLivingBase player) {
|
||||
setCursorList(stack, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<ChunkCoordinates> getWireframesToDraw(EntityPlayer player, ItemStack stack) {
|
||||
MovingObjectPosition lookPos = Minecraft.getMinecraft().objectMouseOver;
|
||||
|
||||
if(lookPos != null && !player.worldObj.isAirBlock(lookPos.blockX, lookPos.blockY, lookPos.blockZ) && lookPos.entityHit == null) {
|
||||
List<ChunkCoordinates> list = getCursorList(stack);
|
||||
ChunkCoordinates origin = getOriginPos(stack);
|
||||
|
||||
if(origin.posY != -1) {
|
||||
for(ChunkCoordinates coords : list) {
|
||||
coords.posX += origin.posX;
|
||||
coords.posY += origin.posY;
|
||||
coords.posZ += origin.posZ;
|
||||
}
|
||||
list.add(origin);
|
||||
} else for(ChunkCoordinates coords : list) {
|
||||
coords.posX += lookPos.blockX;
|
||||
coords.posY += lookPos.blockY;
|
||||
coords.posZ += lookPos.blockZ;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack getLokiRing(EntityPlayer player) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
ItemStack stack1 = baubles.getStackInSlot(1);
|
||||
ItemStack stack2 = baubles.getStackInSlot(2);
|
||||
return (stack1 != null && stack1.getItem() == this) ? stack1 : (stack2 != null && stack2.getItem() == this) ? stack2 : null;
|
||||
}
|
||||
|
||||
private ChunkCoordinates getOriginPos(ItemStack stack) {
|
||||
int x = ItemNBTHelper.getInt(stack, TAG_X_ORIGIN, 0);
|
||||
int y = ItemNBTHelper.getInt(stack, TAG_Y_ORIGIN, -1);
|
||||
int z = ItemNBTHelper.getInt(stack, TAG_Z_ORIGIN, 0);
|
||||
return new ChunkCoordinates(x, y, z);
|
||||
}
|
||||
|
||||
private void setOriginPos(ItemStack stack, int x, int y, int z) {
|
||||
ItemNBTHelper.setInt(stack, TAG_X_ORIGIN, x);
|
||||
ItemNBTHelper.setInt(stack, TAG_Y_ORIGIN, y);
|
||||
ItemNBTHelper.setInt(stack, TAG_Z_ORIGIN, z);
|
||||
}
|
||||
|
||||
private List<ChunkCoordinates> getCursorList(ItemStack stack) {
|
||||
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_CURSOR_LIST, false);
|
||||
List<ChunkCoordinates> cursors = new ArrayList();
|
||||
|
||||
int count = cmp.getInteger(TAG_CURSOR_COUNT);
|
||||
for(int i = 0; i < count; i++) {
|
||||
NBTTagCompound cursorCmp = cmp.getCompoundTag(TAG_CURSOR_PREFIX + i);
|
||||
int x = cursorCmp.getInteger(TAG_X_OFFSET);
|
||||
int y = cursorCmp.getInteger(TAG_Y_OFFSET);
|
||||
int z = cursorCmp.getInteger(TAG_Z_OFFSET);
|
||||
cursors.add(new ChunkCoordinates(x, y, z));
|
||||
}
|
||||
|
||||
return cursors;
|
||||
}
|
||||
|
||||
private void setCursorList(ItemStack stack, List<ChunkCoordinates> cursors) {
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
if(cursors != null) {
|
||||
int i = 0;
|
||||
for(ChunkCoordinates cursor : cursors) {
|
||||
NBTTagCompound cursorCmp = cursorToCmp(cursor.posX, cursor.posY, cursor.posZ);
|
||||
cmp.setTag(TAG_CURSOR_PREFIX + i, cursorCmp);
|
||||
i++;
|
||||
}
|
||||
cmp.setInteger(TAG_CURSOR_COUNT, i);
|
||||
}
|
||||
|
||||
ItemNBTHelper.setCompound(stack, TAG_CURSOR_LIST, cmp);
|
||||
}
|
||||
|
||||
private NBTTagCompound cursorToCmp(int x, int y, int z) {
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
cmp.setInteger(TAG_X_OFFSET, x);
|
||||
cmp.setInteger(TAG_Y_OFFSET, y);
|
||||
cmp.setInteger(TAG_Z_OFFSET, z);
|
||||
return cmp;
|
||||
}
|
||||
|
||||
private void addCursor(ItemStack stack, int x, int y, int z) {
|
||||
NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_CURSOR_LIST, false);
|
||||
int count = cmp.getInteger(TAG_CURSOR_COUNT);
|
||||
cmp.setTag(TAG_CURSOR_PREFIX + count, cursorToCmp(x, y, z));
|
||||
cmp.setInteger(TAG_CURSOR_COUNT, count + 1);
|
||||
ItemNBTHelper.setCompound(stack, TAG_CURSOR_LIST, cmp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IRelic;
|
||||
import vazkii.botania.common.core.helper.ItemNBTHelper;
|
||||
import vazkii.botania.common.item.ItemMod;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IRelic;
|
||||
import vazkii.botania.common.item.equipment.bauble.ItemBauble;
|
||||
|
||||
public abstract class ItemRelicBauble extends ItemBauble implements IRelic {
|
||||
|
||||
Reference in new issue
Block a user