2016-05-30 18:20:31 -07:00
|
|
|
package WayofTime.bloodmagic.util.handler.event;
|
2016-01-03 15:39:59 -05:00
|
|
|
|
2016-06-17 17:37:47 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2016-06-17 18:46:33 -04:00
|
|
|
import WayofTime.bloodmagic.ConfigHandler;
|
2016-02-18 19:44:39 -08:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
|
|
import net.minecraft.client.renderer.texture.TextureMap;
|
2016-06-07 18:50:41 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
2016-01-14 08:27:09 -05:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-02-18 19:44:39 -08:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-06-17 17:37:47 -04:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-17 13:00:44 -07:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2016-02-18 19:44:39 -08:00
|
|
|
import net.minecraft.world.World;
|
2016-06-07 18:50:41 -04:00
|
|
|
import net.minecraftforge.client.event.MouseEvent;
|
2016-06-15 20:23:15 -07:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2016-02-18 19:44:39 -08:00
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
|
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
2016-01-14 08:27:09 -05:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2016-06-07 18:50:41 -04:00
|
|
|
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
2016-05-30 18:20:31 -07:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-06-17 17:37:47 -04:00
|
|
|
|
|
|
|
import org.lwjgl.input.Keyboard;
|
2016-02-18 19:44:39 -08:00
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
2016-06-17 17:37:47 -04:00
|
|
|
import WayofTime.bloodmagic.annot.Handler;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
|
|
|
import WayofTime.bloodmagic.client.hud.HUDElement;
|
|
|
|
import WayofTime.bloodmagic.client.render.RenderFakeBlocks;
|
|
|
|
import WayofTime.bloodmagic.item.ItemRitualDiviner;
|
|
|
|
import WayofTime.bloodmagic.item.ItemRitualReader;
|
|
|
|
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
|
|
|
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
|
|
|
|
import WayofTime.bloodmagic.network.SigilHoldingPacketProcessor;
|
|
|
|
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
|
|
|
import WayofTime.bloodmagic.util.GhostItemHelper;
|
|
|
|
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2016-04-17 14:03:26 -07:00
|
|
|
|
2016-05-30 18:20:31 -07:00
|
|
|
@Handler
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public class ClientHandler
|
2016-01-03 15:39:59 -05:00
|
|
|
{
|
2016-04-17 14:03:26 -07:00
|
|
|
public TextureAtlasSprite ritualStoneBlank;
|
|
|
|
public TextureAtlasSprite ritualStoneWater;
|
|
|
|
public TextureAtlasSprite ritualStoneFire;
|
|
|
|
public TextureAtlasSprite ritualStoneEarth;
|
|
|
|
public TextureAtlasSprite ritualStoneAir;
|
|
|
|
public TextureAtlasSprite ritualStoneDawn;
|
|
|
|
public TextureAtlasSprite ritualStoneDusk;
|
|
|
|
|
2016-06-07 18:50:41 -04:00
|
|
|
public static Minecraft minecraft = Minecraft.getMinecraft();
|
|
|
|
public static final List<BMKeyBinding> keyBindings = new ArrayList<BMKeyBinding>();
|
2016-06-16 18:12:20 -07:00
|
|
|
public static final List<HUDElement> hudElements = new ArrayList<HUDElement>();
|
2016-02-18 19:44:39 -08:00
|
|
|
|
2016-06-17 17:37:47 -04:00
|
|
|
public static final BMKeyBinding keyOpenSigilHolding = new BMKeyBinding("openSigilHolding", Keyboard.KEY_H, BMKeyBinding.Key.OPEN_SIGIL_HOLDING);
|
|
|
|
|
2016-01-14 08:27:09 -05:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onTooltipEvent(ItemTooltipEvent event)
|
|
|
|
{
|
2016-03-26 14:32:06 -04:00
|
|
|
ItemStack stack = event.getItemStack();
|
2016-01-14 08:27:09 -05:00
|
|
|
if (stack == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GhostItemHelper.hasGhostAmount(stack))
|
|
|
|
{
|
|
|
|
int amount = GhostItemHelper.getItemGhostAmount(stack);
|
|
|
|
if (amount == 0)
|
|
|
|
{
|
2016-03-26 12:32:51 -07:00
|
|
|
event.getToolTip().add(TextHelper.localize("tooltip.BloodMagic.ghost.everything"));
|
2016-01-14 08:27:09 -05:00
|
|
|
} else
|
|
|
|
{
|
2016-03-26 12:32:51 -07:00
|
|
|
event.getToolTip().add(TextHelper.localize("tooltip.BloodMagic.ghost.amount", amount));
|
2016-01-14 08:27:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-18 19:44:39 -08:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onTextureStitch(TextureStitchEvent.Pre event)
|
|
|
|
{
|
|
|
|
final String BLOCKS = "blocks";
|
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
ritualStoneBlank = forName(event.getMap(), "RitualStone", BLOCKS);
|
|
|
|
ritualStoneWater = forName(event.getMap(), "WaterRitualStone", BLOCKS);
|
|
|
|
ritualStoneFire = forName(event.getMap(), "FireRitualStone", BLOCKS);
|
|
|
|
ritualStoneEarth = forName(event.getMap(), "EarthRitualStone", BLOCKS);
|
|
|
|
ritualStoneAir = forName(event.getMap(), "AirRitualStone", BLOCKS);
|
|
|
|
ritualStoneDawn = forName(event.getMap(), "LightRitualStone", BLOCKS);
|
|
|
|
ritualStoneDusk = forName(event.getMap(), "DuskRitualStone", BLOCKS);
|
2016-02-18 19:44:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void render(RenderWorldLastEvent event)
|
|
|
|
{
|
|
|
|
EntityPlayerSP player = minecraft.thePlayer;
|
|
|
|
World world = player.worldObj;
|
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
if (minecraft.objectMouseOver == null || minecraft.objectMouseOver.typeOfHit != RayTraceResult.Type.BLOCK)
|
2016-02-18 19:44:39 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
TileEntity tileEntity = world.getTileEntity(minecraft.objectMouseOver.getBlockPos());
|
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
if (tileEntity instanceof IMasterRitualStone && player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemRitualDiviner)
|
|
|
|
renderRitualStones(player, event.getPartialTicks());
|
2016-02-18 19:44:39 -08:00
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
if (tileEntity instanceof TileMasterRitualStone && player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemRitualReader)
|
|
|
|
renderRitualInformation(player, event.getPartialTicks());
|
|
|
|
}
|
2016-02-18 19:44:39 -08:00
|
|
|
|
2016-06-07 18:50:41 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onMouseEvent(MouseEvent event)
|
|
|
|
{
|
|
|
|
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
|
|
|
|
if (event.getDwheel() != 0 && player != null && player.isSneaking())
|
|
|
|
{
|
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
|
|
|
|
|
|
|
if (stack != null)
|
|
|
|
{
|
|
|
|
Item item = stack.getItem();
|
|
|
|
|
|
|
|
if (item instanceof ItemSigilHolding)
|
|
|
|
{
|
|
|
|
cycleSigil(stack, player, event.getDwheel());
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 20:23:15 -07:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onKey(InputEvent event)
|
|
|
|
{
|
|
|
|
if (!minecraft.inGameHasFocus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (BMKeyBinding key : keyBindings)
|
|
|
|
{
|
|
|
|
if (key.isPressed())
|
|
|
|
key.handleKeyPress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2016-06-17 17:37:47 -04:00
|
|
|
public void onHudRender(RenderGameOverlayEvent.Pre event)
|
|
|
|
{
|
2016-06-16 18:12:20 -07:00
|
|
|
for (HUDElement element : hudElements)
|
|
|
|
if (element.getElementType() == event.getType() && element.shouldRender(minecraft))
|
|
|
|
element.render(minecraft, event.getResolution(), event.getPartialTicks());
|
2016-06-15 20:23:15 -07:00
|
|
|
}
|
|
|
|
|
2016-06-07 18:50:41 -04:00
|
|
|
private void cycleSigil(ItemStack stack, EntityPlayer player, int dWheel)
|
|
|
|
{
|
2016-06-17 18:46:33 -04:00
|
|
|
int mode = dWheel;
|
|
|
|
if (ConfigHandler.sigilHoldingSkipsEmptySlots)
|
|
|
|
{
|
|
|
|
mode = ItemSigilHolding.getCurrentItemOrdinal(stack);
|
|
|
|
mode = dWheel < 0 ? ItemSigilHolding.next(mode) : ItemSigilHolding.prev(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemSigilHolding.cycleToNextSigil(stack, mode);
|
2016-06-07 18:50:41 -04:00
|
|
|
BloodMagicPacketHandler.INSTANCE.sendToServer(new SigilHoldingPacketProcessor(player.inventory.currentItem, mode));
|
|
|
|
}
|
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
private static TextureAtlasSprite forName(TextureMap textureMap, String name, String dir)
|
|
|
|
{
|
|
|
|
return textureMap.registerSprite(new ResourceLocation(Constants.Mod.DOMAIN + dir + "/" + name));
|
|
|
|
}
|
2016-02-18 19:44:39 -08:00
|
|
|
|
2016-05-02 20:56:32 -04:00
|
|
|
private void renderRitualInformation(EntityPlayerSP player, float partialTicks)
|
|
|
|
{
|
2016-04-17 14:03:26 -07:00
|
|
|
World world = player.worldObj;
|
|
|
|
TileMasterRitualStone mrs = (TileMasterRitualStone) world.getTileEntity(minecraft.objectMouseOver.getBlockPos());
|
|
|
|
Ritual ritual = mrs.getCurrentRitual();
|
|
|
|
|
2016-05-02 20:56:32 -04:00
|
|
|
if (ritual != null)
|
|
|
|
{
|
2016-04-17 14:03:26 -07:00
|
|
|
List<String> ranges = ritual.getListOfRanges();
|
2016-05-02 20:56:32 -04:00
|
|
|
for (String range : ranges)
|
|
|
|
{
|
2016-04-17 14:03:26 -07:00
|
|
|
AreaDescriptor areaDescriptor = ritual.getBlockRange(range);
|
2016-02-18 19:44:39 -08:00
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
for (BlockPos pos : areaDescriptor.getContainedPositions(minecraft.objectMouseOver.getBlockPos()))
|
|
|
|
RenderFakeBlocks.drawFakeBlock(ritualStoneBlank, pos.getX(), pos.getY(), pos.getZ(), world);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-02 20:56:32 -04:00
|
|
|
private void renderRitualStones(EntityPlayerSP player, float partialTicks)
|
|
|
|
{
|
2016-04-17 14:03:26 -07:00
|
|
|
World world = player.worldObj;
|
|
|
|
ItemRitualDiviner ritualDiviner = (ItemRitualDiviner) player.inventory.getCurrentItem().getItem();
|
|
|
|
EnumFacing direction = ritualDiviner.getDirection(player.inventory.getCurrentItem());
|
|
|
|
Ritual ritual = RitualRegistry.getRitualForId(ritualDiviner.getCurrentRitual(player.inventory.getCurrentItem()));
|
|
|
|
|
|
|
|
if (ritual == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
BlockPos vec3 = new BlockPos(minecraft.objectMouseOver.getBlockPos().getX(), minecraft.objectMouseOver.getBlockPos().getY(), minecraft.objectMouseOver.getBlockPos().getZ());
|
|
|
|
double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
|
|
|
double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
|
|
|
double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
|
|
|
|
|
|
|
for (RitualComponent ritualComponent : ritual.getComponents())
|
|
|
|
{
|
|
|
|
BlockPos vX = vec3.add(new BlockPos(ritualComponent.getX(direction), ritualComponent.getY(), ritualComponent.getZ(direction)));
|
|
|
|
double minX = vX.getX() - posX;
|
|
|
|
double minY = vX.getY() - posY;
|
|
|
|
double minZ = vX.getZ() - posZ;
|
|
|
|
|
|
|
|
if (!world.getBlockState(vX).isOpaqueCube())
|
|
|
|
{
|
|
|
|
TextureAtlasSprite texture = null;
|
|
|
|
|
|
|
|
switch (ritualComponent.getRuneType())
|
2016-02-18 19:44:39 -08:00
|
|
|
{
|
2016-05-02 20:56:32 -04:00
|
|
|
case BLANK:
|
|
|
|
texture = ritualStoneBlank;
|
|
|
|
break;
|
|
|
|
case WATER:
|
|
|
|
texture = ritualStoneWater;
|
|
|
|
break;
|
|
|
|
case FIRE:
|
|
|
|
texture = ritualStoneFire;
|
|
|
|
break;
|
|
|
|
case EARTH:
|
|
|
|
texture = ritualStoneEarth;
|
|
|
|
break;
|
|
|
|
case AIR:
|
|
|
|
texture = ritualStoneAir;
|
|
|
|
break;
|
|
|
|
case DAWN:
|
|
|
|
texture = ritualStoneDawn;
|
|
|
|
break;
|
|
|
|
case DUSK:
|
|
|
|
texture = ritualStoneDusk;
|
|
|
|
break;
|
2016-02-18 19:44:39 -08:00
|
|
|
}
|
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
RenderFakeBlocks.drawFakeBlock(texture, minX, minY, minZ, world);
|
2016-02-18 19:44:39 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 14:03:26 -07:00
|
|
|
GlStateManager.popMatrix();
|
2016-02-18 19:44:39 -08:00
|
|
|
}
|
2016-06-07 18:50:41 -04:00
|
|
|
|
2016-06-15 20:23:15 -07:00
|
|
|
protected void renderHotbarItem(int x, int y, float partialTicks, EntityPlayer player, @Nullable ItemStack stack)
|
2016-06-07 18:50:41 -04:00
|
|
|
{
|
2016-06-15 20:23:15 -07:00
|
|
|
if (stack != null)
|
2016-06-07 18:50:41 -04:00
|
|
|
{
|
2016-06-15 20:23:15 -07:00
|
|
|
float animation = (float) stack.animationsToGo - partialTicks;
|
|
|
|
|
|
|
|
if (animation > 0.0F)
|
|
|
|
{
|
|
|
|
GlStateManager.pushMatrix();
|
|
|
|
float f1 = 1.0F + animation / 5.0F;
|
|
|
|
GlStateManager.translate((float) (x + 8), (float) (y + 12), 0.0F);
|
|
|
|
GlStateManager.scale(1.0F / f1, (f1 + 1.0F) / 2.0F, 1.0F);
|
|
|
|
GlStateManager.translate((float) (-(x + 8)), (float) (-(y + 12)), 0.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
minecraft.getRenderItem().renderItemAndEffectIntoGUI(player, stack, x, y);
|
|
|
|
|
|
|
|
if (animation > 0.0F)
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
|
|
|
|
minecraft.getRenderItem().renderItemOverlays(minecraft.fontRendererObj, stack, x, y);
|
2016-06-07 18:50:41 -04:00
|
|
|
}
|
|
|
|
}
|
2016-01-03 15:39:59 -05:00
|
|
|
}
|