Initial work on DemonWillGauge

Includes the PacketHandler as well as the base system for HUDElements. Still need a replacement for the GuiConfig.
This commit is contained in:
WayofTime 2020-11-11 21:15:58 -05:00
parent 648b96601d
commit b6931a3116
17 changed files with 858 additions and 33 deletions

View file

@ -113,6 +113,7 @@ e8bdf0e3f557bb09c665312df380672e676f4382 assets/bloodmagic/models/item/corrosive
f404148f9df3a61da3c18175885ffa56b2a85a6a assets/bloodmagic/models/item/daggerofsacrifice.json
6b89387f771da9535a0234f1a267af1b6853724d assets/bloodmagic/models/item/defaultcrystal.json
9671199681493a396e07d7bcab20137c22d981d5 assets/bloodmagic/models/item/demonslate.json
630d3287fcbdcca0dec3343488a2c868316d83d2 assets/bloodmagic/models/item/demonwillgauge.json
a61193ff59b71a79e8e28720dfce4185122a7ec1 assets/bloodmagic/models/item/destructivecrystal.json
3e952fc5e87bd7883dadd761ef708ddfac29638c assets/bloodmagic/models/item/destructivedemoncrystal.json
7af07ab578bbd20e2f834b26d9cafb5fe23bc7d4 assets/bloodmagic/models/item/dislocationrune.json

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "bloodmagic:item/demonwillgauge"
}
}

View file

@ -32,6 +32,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import wayoftime.bloodmagic.api.impl.BloodMagicAPI;
import wayoftime.bloodmagic.api.impl.BloodMagicCorePlugin;
import wayoftime.bloodmagic.client.ClientEvents;
import wayoftime.bloodmagic.client.hud.Elements;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.common.data.GeneratorBaseRecipes;
import wayoftime.bloodmagic.common.data.GeneratorBlockStates;
@ -200,6 +201,7 @@ public class BloodMagic
// LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
ClientEvents.initClientEvents(event);
Elements.registerElements();
}
private void enqueueIMC(final InterModEnqueueEvent event)

View file

@ -0,0 +1,45 @@
package wayoftime.bloodmagic.client.hud;
import net.minecraft.util.math.vector.Vector2f;
public class ElementInfo
{
public static final ElementInfo DUMMY = new ElementInfo(new Vector2f(0F, 0F), ElementRegistry.getRandomColor());
private final Vector2f defaultPosition;
private final int boxColor;
private Vector2f currentPosition;
public ElementInfo(Vector2f defaultPosition, int boxColor)
{
this.defaultPosition = defaultPosition;
this.boxColor = boxColor;
this.currentPosition = defaultPosition;
}
public Vector2f getDefaultPosition()
{
return defaultPosition;
}
public int getBoxColor()
{
return boxColor;
}
public ElementInfo setPosition(Vector2f position)
{
this.currentPosition = position;
return this;
}
public Vector2f getPosition()
{
return currentPosition;
}
public void resetPosition()
{
this.currentPosition = defaultPosition;
}
}

View file

@ -0,0 +1,185 @@
package wayoftime.bloodmagic.client.hud;
import java.awt.Color;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLPaths;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.client.hud.element.HUDElement;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, value = Dist.CLIENT)
public class ElementRegistry
{
// private static final File CORNFIG = new File(Loader.instance().getConfigDir(), BloodMagic.MODID + "/hud_elements.json");
private static final File CONFIG = FMLPaths.CONFIGDIR.get().resolve(BloodMagic.MODID).resolve("hud_elements.json").toFile();
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private static final Map<ResourceLocation, HUDElement> HUD_ELEMENTS = Maps.newLinkedHashMap();
private static final Map<HUDElement, ResourceLocation> REVERSE = Maps.newHashMap();
private static final Map<ResourceLocation, ElementInfo> ELEMENT_INFO = Maps.newHashMap();
public static void registerHandler(ResourceLocation key, HUDElement element, Vector2f defaultPosition)
{
HUD_ELEMENTS.put(key, element);
REVERSE.put(element, key);
ELEMENT_INFO.put(key, new ElementInfo(defaultPosition, getRandomColor()));
}
public static void resetPos()
{
ELEMENT_INFO.values().forEach(ElementInfo::resetPosition);
}
public static List<HUDElement> getElements()
{
return ImmutableList.copyOf(HUD_ELEMENTS.values());
}
public static ResourceLocation getKey(HUDElement element)
{
return REVERSE.get(element);
}
public static int getColor(ResourceLocation element)
{
return ELEMENT_INFO.getOrDefault(element, ElementInfo.DUMMY).getBoxColor();
}
public static Vector2f getPosition(ResourceLocation element)
{
return ELEMENT_INFO.get(element).getPosition();
}
public static void setPosition(ResourceLocation element, Vector2f point)
{
ELEMENT_INFO.compute(element, (resourceLocation, elementInfo) -> {
if (elementInfo == null)
return new ElementInfo(point, getRandomColor());
elementInfo.setPosition(point);
return elementInfo;
});
}
public static void save(Map<ResourceLocation, Vector2f> newLocations)
{
newLocations.forEach((k, v) -> {
ElementInfo info = ELEMENT_INFO.get(k);
if (info != null)
info.setPosition(v);
});
Map<String, Vector2f> toWrite = Maps.newHashMap();
for (Map.Entry<ResourceLocation, ElementInfo> entry : ELEMENT_INFO.entrySet())
toWrite.put(entry.getKey().toString(), entry.getValue().getPosition());
String json = GSON.toJson(toWrite);
try (FileWriter writer = new FileWriter(CONFIG))
{
writer.write(json);
} catch (Exception e)
{
e.printStackTrace();
}
}
public static void readConfig()
{
if (!CONFIG.exists())
return;
try (FileReader reader = new FileReader(CONFIG))
{
Map<String, Vector2f> toLoad = GSON.fromJson(reader, new TypeToken<Map<String, Vector2f>>()
{
}.getType());
for (Map.Entry<String, Vector2f> entry : toLoad.entrySet())
{
ElementInfo info = ELEMENT_INFO.get(new ResourceLocation(entry.getKey()));
if (info != null)
info.setPosition(entry.getValue());
}
} catch (Exception e)
{
e.printStackTrace();
}
}
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onRenderOverlay(RenderGameOverlayEvent.Pre event)
{
if (event.getType() == RenderGameOverlayEvent.ElementType.HOTBAR)
{
MainWindow window = event.getWindow();
for (HUDElement element : HUD_ELEMENTS.values())
{
if (!element.shouldRender(Minecraft.getInstance()))
continue;
// Vector2f position = ELEMENT_INFO.get(getKey(element)).getPosition();
// int xPos = (int) (resolution.getScaledWidth_double() * position.x);
// if (xPos - element.getWidth() < 0)
// xPos *= 2;
// if (xPos + element.getWidth() > resolution.getScaledWidth())
// xPos -= element.getWidth();
//
// int yPos = (int) (resolution.getScaledHeight_double() * position.y);
// if (yPos - element.getHeight() < 0)
// yPos *= 2;
// if (yPos + element.getHeight() > resolution.getScaledHeight())
// yPos -= element.getHeight();
//
// element.draw(event.getResolution(), event.getPartialTicks(), xPos, yPos);
Vector2f position = ELEMENT_INFO.get(getKey(element)).getPosition();
int xPos = (int) (window.getScaledWidth() * position.x);
if (xPos - element.getWidth() < 0)
xPos *= 2;
if (xPos + element.getWidth() > window.getScaledWidth())
xPos -= element.getWidth();
int yPos = (int) (window.getScaledHeight() * position.y);
if (yPos - element.getHeight() < 0)
yPos *= 2;
if (yPos + element.getHeight() > window.getScaledHeight())
yPos -= element.getHeight();
element.draw(event.getMatrixStack(), event.getPartialTicks(), xPos, yPos);
}
}
}
public static int getRandomColor()
{
Random rand = new Random();
float r = rand.nextFloat() / 2F + 0.5F;
float g = rand.nextFloat() / 2F + 0.5F;
float b = rand.nextFloat() / 2F + 0.5F;
float a = 0.5F;
return new Color(r, g, b, a).getRGB();
}
}

View file

@ -0,0 +1,14 @@
package wayoftime.bloodmagic.client.hud;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector2f;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.client.hud.element.ElementDemonAura;
public class Elements
{
public static void registerElements()
{
ElementRegistry.registerHandler(new ResourceLocation(BloodMagic.MODID, "demon_will_aura"), new ElementDemonAura(), new Vector2f(0.01F, 0.01F));
}
}

View file

@ -0,0 +1,239 @@
package wayoftime.bloodmagic.client.hud;
import java.awt.Point;
import java.util.Map;
import javax.annotation.Nullable;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import wayoftime.bloodmagic.client.hud.element.HUDElement;
public class GuiEditHUD extends Screen
{
private static final int LINE_COLOR = 0x2D2D2D;
private final Screen parent;
private final Map<ResourceLocation, Vector2f> currentOverrides = Maps.newHashMap();
private HUDElement dragged;
public boolean changes;
public GuiEditHUD(Screen parent)
{
super(new StringTextComponent("Testing GuiEditHUD"));
this.parent = parent;
}
@Override
public void init()
{
super.init();
addButton(new Button(width / 2 - 155, height - 30, 70, 20, new TranslationTextComponent("gui.bloodmagic.toggle"), b -> {
Minecraft.getInstance().displayGuiScreen(parent);
})
{
{
active = false;
}
});
addButton(new Button(width / 2 - 75, height - 30, 70, 20, new TranslationTextComponent("gui.bloodmagic.default"), b -> {
currentOverrides.clear();
ElementRegistry.resetPos();
changes = false;
}));
addButton(new Button(width / 2 + 5, height - 30, 70, 20, new TranslationTextComponent("gui.bloodmagic.save"), b -> {
ElementRegistry.save(currentOverrides);
Minecraft.getInstance().displayGuiScreen(parent);
}));
addButton(new Button(width / 2 + 90, height - 30, 70, 20, new TranslationTextComponent("gui.bloodmagic.cancel"), b -> {
currentOverrides.clear();
Minecraft.getInstance().displayGuiScreen(parent);
}));
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks)
{
this.renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks);
// ScaledResolution resolution = new ScaledResolution(Minecraft.getInstance());
MainWindow window = Minecraft.getInstance().getMainWindow();
for (HUDElement element : ElementRegistry.getElements())
{
if (dragged == element)
continue;
ResourceLocation key = ElementRegistry.getKey(element);
Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key));
int xPos = (int) (window.getScaledWidth() * position.x);
int yPos = (int) (window.getScaledHeight() * position.y);
drawWithBox(matrixStack, element, partialTicks, xPos, yPos);
}
if (dragged != null)
{
Point bounded = getBoundedDrag(window, mouseX, mouseY);
drawWithBox(matrixStack, dragged, partialTicks, bounded.x, bounded.y);
}
}
@Override
public boolean isPauseScreen()
{
return true;
}
@Override
// protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick)
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY)
{
if (dragged == null)
{
HUDElement element = getHoveredElement(mouseX, mouseY);
if (element != null)
{
if (button == 0)
dragged = element;
}
}
return super.mouseDragged(mouseX, mouseY, button, dragX, dragY);
// if (dragged != null)
// return false;
//
// HUDElement element = getHoveredElement(mouseX, mouseY);
// if (element == null)
// return false;
//
// if (button == 0)
// dragged = element;
//
// return super.mouseDragged(mouseX, mouseY, button, dragX, dragY);
}
@Override
public boolean mouseReleased(double mouseX, double mouseY, int state)
{
if (dragged != null)
{
MainWindow window = Minecraft.getInstance().getMainWindow();
Point bounded = getBoundedDrag(window, mouseX, mouseY);
float xPos = (float) ((bounded.x) / window.getScaledWidth());
float yPos = (float) ((bounded.y) / window.getScaledHeight());
currentOverrides.put(ElementRegistry.getKey(dragged), new Vector2f(xPos, yPos));
changes = true;
dragged = null;
// return super;
}
return super.mouseReleased(mouseX, mouseY, state);
}
// @Override
// protected void actionPerformed(Button button)
// {
// switch (button.id)
// {
// case 0:
// {
// Minecraft.getInstance().displayGuiScreen(parent);
// break;
// }
// case 1:
// {
// currentOverrides.clear();
// ElementRegistry.resetPos();
// changes = false;
// break;
// }
// case 2:
// {
// ElementRegistry.save(currentOverrides);
// Minecraft.getInstance().displayGuiScreen(parent);
// break;
// }
// case 3:
// {
// currentOverrides.clear();
// Minecraft.getInstance().displayGuiScreen(parent);
// break;
// }
// }
// }
@Nullable
public HUDElement getHoveredElement(double mouseX, double mouseY)
{
MainWindow window = Minecraft.getInstance().getMainWindow();
for (HUDElement element : ElementRegistry.getElements())
{
ResourceLocation key = ElementRegistry.getKey(element);
Vector2f position = currentOverrides.getOrDefault(key, ElementRegistry.getPosition(key));
int xPos = (int) (window.getScaledWidth() * position.x);
int yPos = (int) (window.getScaledHeight() * position.y);
if (mouseX < xPos || mouseX > xPos + element.getWidth())
continue;
if (mouseY < yPos || mouseY > yPos + element.getHeight())
continue;
return element;
}
return null;
}
protected Point getBoundedDrag(MainWindow window, double mouseX, double mouseY)
{
int drawX = (int) (mouseX - dragged.getWidth() / 2);
if (drawX + dragged.getWidth() >= window.getScaledWidth())
drawX = window.getScaledWidth() - dragged.getWidth();
if (drawX < 0)
drawX = 0;
int drawY = (int) (mouseY - dragged.getHeight() / 2);
if (drawY + dragged.getHeight() >= window.getScaledHeight())
drawY = window.getScaledHeight() - dragged.getHeight();
if (drawY < 0)
drawY = 0;
return new Point(drawX, drawY);
}
protected void drawWithBox(MatrixStack matrixStack, HUDElement element, float partialTicks, int drawX, int drawY)
{
int color = ElementRegistry.getColor(ElementRegistry.getKey(element));
matrixStack.push();
// GlStateManager.enableAlpha();
// GlStateManager.enableBlend();
// GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
this.vLine(matrixStack, drawX, drawY, drawY + element.getHeight() - 1, color);
this.vLine(matrixStack, drawX + element.getWidth() - 1, drawY, drawY + element.getHeight() - 1, color);
this.hLine(matrixStack, drawX, drawX + element.getWidth() - 1, drawY, color);
this.hLine(matrixStack, drawX, drawX + element.getWidth() - 1, drawY + element.getHeight() - 1, color);
// GlStateManager.disableBlend();
// GlStateManager.disableAlpha();
matrixStack.pop();
// GlStateManager.color(1.0F, 1.0F, 1.0F);
// GlStateManager.enableTexture2D();
element.draw(matrixStack, partialTicks, drawX, drawY);
// GlStateManager.disableTexture2D();
}
}

View file

@ -0,0 +1,83 @@
package wayoftime.bloodmagic.client.hud.element;
import java.util.List;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ResourceLocation;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.util.Utils;
import wayoftime.bloodmagic.util.handler.event.ClientHandler;
import wayoftime.bloodmagic.will.EnumDemonWillType;
public class ElementDemonAura extends HUDElement
{
private static final ResourceLocation BAR_LOCATION = new ResourceLocation(BloodMagic.MODID, "textures/hud/bars.png");
private final List<EnumDemonWillType> orderedTypes = Lists.newArrayList(EnumDemonWillType.DEFAULT, EnumDemonWillType.CORROSIVE, EnumDemonWillType.STEADFAST, EnumDemonWillType.DESTRUCTIVE, EnumDemonWillType.VENGEFUL);
public ElementDemonAura()
{
super(80, 46);
}
@Override
public void draw(MatrixStack matrixStack, float partialTicks, int drawX, int drawY)
{
Minecraft minecraft = Minecraft.getInstance();
PlayerEntity player = minecraft.player;
minecraft.getTextureManager().bindTexture(BAR_LOCATION);
// GlStateManager.color(1.0F, 1.0F, 1.0F);
this.blit(matrixStack, drawX, drawY, 0, 210, 80, 46);
double maxAmount = Utils.getDemonWillResolution(player);
int i = 0;
for (EnumDemonWillType type : orderedTypes)
{
i++;
// GlStateManager.color(1.0F, 1.0F, 1.0F);
minecraft.getTextureManager().bindTexture(BAR_LOCATION);
int textureXOffset = (i > 3) ? (i - 3) : (3 - i);
int maxBarSize = 30 - 2 * textureXOffset;
double amount = ClientHandler.currentAura == null ? 0 : ClientHandler.currentAura.getWill(type);
double ratio = Math.max(Math.min(amount / maxAmount, 1), 0);
// double amount = 50;
// double ratio = 0.5;
double width = maxBarSize * ratio * 2;
double height = 2;
double x = drawX + 2 * textureXOffset + 10;
double y = drawY + 4 * i + 10;
double textureX = 2 * textureXOffset + 2 * 42;
double textureY = 4 * i + 220;
this.blit(matrixStack, (int) x, (int) y, (int) textureX, (int) textureY, (int) width, (int) height);
if (player.isSneaking())
{
matrixStack.push();
matrixStack.translate(x - 2 * textureXOffset + 70, (y - 2), 0);
matrixStack.scale(0.5f, 0.5f, 1f);
minecraft.fontRenderer.drawStringWithShadow(matrixStack, String.valueOf((int) amount), 0, 2, 0xffffffff);
RenderSystem.clearTexGen();
matrixStack.pop();
}
}
}
@Override
public boolean shouldRender(Minecraft minecraft)
{
return Utils.canPlayerSeeDemonWill(Minecraft.getInstance().player);
}
}

View file

@ -0,0 +1,68 @@
package wayoftime.bloodmagic.client.hud.element;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import wayoftime.bloodmagic.client.hud.ElementRegistry;
@OnlyIn(Dist.CLIENT)
public abstract class HUDElement
{
private int width;
private int height;
protected int blitOffset = 0;
public HUDElement(int width, int height)
{
this.width = width;
this.height = height;
}
public boolean shouldRender(Minecraft minecraft)
{
return true;
}
public abstract void draw(MatrixStack matrixStack, float partialTicks, int drawX, int drawY);
public final int getWidth()
{
return width;
}
public final int getHeight()
{
return height;
}
// protected void drawTexturedModalRect(double x, double y, double textureX, double textureY, double width, double height)
// {
// float f = 0.00390625F;
// float f1 = 0.00390625F;
// Tessellator tessellator = Tessellator.getInstance();
// BufferBuilder buffer = tessellator.getBuffer();
// buffer.begin(7, DefaultVertexFormats.POSITION_TEX);
// buffer.pos(x + 0, y + height, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + height) * f1)).endVertex();
// buffer.pos(x + width, y + height, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + height) * f1)).endVertex();
// buffer.pos(x + width, y + 0, 0).tex((double) ((float) (textureX + width) * f), (double) ((float) (textureY + 0) * f1)).endVertex();
// buffer.pos(x + 0, y + 0, 0).tex((double) ((float) (textureX + 0) * f), (double) ((float) (textureY + 0) * f1)).endVertex();
// tessellator.draw();
// }
public void blit(MatrixStack matrixStack, int x, int y, int uOffset, int vOffset, int uWidth, int vHeight)
{
AbstractGui.blit(matrixStack, x, y, this.blitOffset, (float) uOffset, (float) vOffset, uWidth, vHeight, 256, 256);
}
@Override
public String toString()
{
Vector2f point = ElementRegistry.getPosition(ElementRegistry.getKey(this));
return ElementRegistry.getKey(this) + "@" + point.x + "," + point.y;
}
}

View file

@ -167,6 +167,8 @@ public class BloodMagicItems
public static final RegistryObject<Item> DESTRUCTIVE_CRYSTAL = BASICITEMS.register("destructivecrystal", () -> new ItemDemonCrystal(EnumDemonWillType.DESTRUCTIVE));
public static final RegistryObject<Item> STEADFAST_CRYSTAL = BASICITEMS.register("steadfastcrystal", () -> new ItemDemonCrystal(EnumDemonWillType.STEADFAST));
public static final RegistryObject<Item> DEMON_WILL_GAUGE = BASICITEMS.register("demonwillgauge", ItemDemonWillGauge::new);
// ARC Tools
public static final RegistryObject<Item> SANGUINE_REVERTER = BASICITEMS.register("sanguinereverter", () -> new ItemARCToolBase(32, 2));
public static final RegistryObject<Item> PRIMITIVE_FURNACE_CELL = BASICITEMS.register("furnacecell_primitive", () -> new ItemARCToolBase(128, 1.25));

View file

@ -0,0 +1,12 @@
package wayoftime.bloodmagic.common.item;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IDemonWillViewer
{
boolean canSeeDemonWillAura(World world, ItemStack stack, PlayerEntity player);
int getDemonWillAuraResolution(World world, ItemStack stack, PlayerEntity player);
}

View file

@ -0,0 +1,52 @@
package wayoftime.bloodmagic.common.item;
import java.util.List;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.util.handler.event.GenericHandler;
public class ItemDemonWillGauge extends Item implements IDemonWillViewer
{
public ItemDemonWillGauge()
{
super(new Item.Properties().maxStackSize(1).group(BloodMagic.TAB));
}
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag)
{
tooltip.add(new TranslationTextComponent("tooltip.bloodmagic.willGauge"));
}
@Override
public boolean canSeeDemonWillAura(World world, ItemStack stack, PlayerEntity player)
{
return true;
}
@Override
public int getDemonWillAuraResolution(World world, ItemStack stack, PlayerEntity player)
{
return 100;
}
@Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
{
if (entityIn instanceof PlayerEntity && entityIn.ticksExisted % 50 == 0)
{
GenericHandler.sendPlayerDemonWillAura((PlayerEntity) entityIn);
}
}
}

View file

@ -15,6 +15,7 @@ public class BloodMagicPacketHandler extends BasePacketHandler
{
registerServerToClient(ChatUtil.PacketNoSpamChat.class, ChatUtil.PacketNoSpamChat::encode, ChatUtil.PacketNoSpamChat::decode, ChatUtil.PacketNoSpamChat::handle);
registerServerToClient(ARCTanksPacket.class, ARCTanksPacket::encode, ARCTanksPacket::decode, ARCTanksPacket::handle);
registerServerToClient(DemonAuraClientPacket.class, DemonAuraClientPacket::encode, DemonAuraClientPacket::decode, DemonAuraClientPacket::handle);
// INSTANCE.registerMessage(id, messageType, encoder, decoder, messageConsumer);
// INSTANCE.registerMessage(ChatUtil.PacketNoSpamChat.Handler.class, ChatUtil.PacketNoSpamChat.class, 0, Side.CLIENT);
// INSTANCE.registerMessage(ItemRouterButtonPacketProcessor.class, ItemRouterButtonPacketProcessor.class, 1, Side.SERVER);

View file

@ -0,0 +1,64 @@
package wayoftime.bloodmagic.network;
import java.util.function.Supplier;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkEvent.Context;
import wayoftime.bloodmagic.util.handler.event.ClientHandler;
import wayoftime.bloodmagic.will.DemonWillHolder;
import wayoftime.bloodmagic.will.EnumDemonWillType;
public class DemonAuraClientPacket
{
public DemonWillHolder currentWill = new DemonWillHolder();
public DemonAuraClientPacket()
{
}
public DemonAuraClientPacket(DemonWillHolder holder)
{
this.currentWill = holder;
}
public static void encode(DemonAuraClientPacket pkt, PacketBuffer buf)
{
for (EnumDemonWillType type : EnumDemonWillType.values())
{
if (pkt.currentWill.willMap.containsKey(type))
{
buf.writeDouble(pkt.currentWill.willMap.get(type));
} else
{
buf.writeDouble(0);
}
}
}
public static DemonAuraClientPacket decode(PacketBuffer buf)
{
DemonAuraClientPacket pkt = new DemonAuraClientPacket();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
pkt.currentWill.willMap.put(type, buf.readDouble());
}
return pkt;
}
public static void handle(DemonAuraClientPacket message, Supplier<Context> context)
{
context.get().enqueueWork(() -> updateClientHolder(message.currentWill));
context.get().setPacketHandled(true);
}
@OnlyIn(Dist.CLIENT)
public static void updateClientHolder(DemonWillHolder holder)
{
ClientHandler.currentAura = holder;
}
}

View file

@ -28,6 +28,8 @@ import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import wayoftime.bloodmagic.common.item.IDemonWillViewer;
import wayoftime.bloodmagic.tile.TileInventory;
public class Utils
@ -92,9 +94,7 @@ public class Utils
public static boolean isFlowingLiquid(World world, BlockPos pos, BlockState state)
{
Block block = state.getBlock();
return ((block instanceof IFluidBlock && Math.abs(((IFluidBlock) block).getFilledPercentage(world, pos)) == 1)
|| (block instanceof FlowingFluidBlock
&& !((FlowingFluidBlock) block).getFluidState(state).isSource()));
return ((block instanceof IFluidBlock && Math.abs(((IFluidBlock) block).getFilledPercentage(world, pos)) == 1) || (block instanceof FlowingFluidBlock && !((FlowingFluidBlock) block).getFluidState(state).isSource()));
}
public static boolean spawnStackAtBlock(World world, BlockPos pos, @Nullable Direction pushDirection, ItemStack stack)
@ -174,9 +174,7 @@ public class Utils
BlockState initialState = initialWorld.getBlockState(initialPos);
BlockState finalState = finalWorld.getBlockState(finalPos);
if ((initialState.getBlock().equals(Blocks.AIR) && finalState.getBlock().equals(Blocks.AIR))
|| initialState.getBlock() instanceof NetherPortalBlock
|| finalState.getBlock() instanceof NetherPortalBlock)
if ((initialState.getBlock().equals(Blocks.AIR) && finalState.getBlock().equals(Blocks.AIR)) || initialState.getBlock() instanceof NetherPortalBlock || finalState.getBlock() instanceof NetherPortalBlock)
return false;
if (playSound)
@ -302,8 +300,7 @@ public class Utils
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
for (int in : array)
{
canBeInserted[in] = inventory.isItemValidForSlot(in, stack)
&& ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
canBeInserted[in] = inventory.isItemValidForSlot(in, stack) && ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
}
} else
{
@ -349,8 +346,7 @@ public class Utils
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
for (int in : array)
{
canBeInserted[in] = inventory.isItemValidForSlot(in, stack)
&& ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
canBeInserted[in] = inventory.isItemValidForSlot(in, stack) && ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
}
} else
{
@ -445,4 +441,46 @@ public class Utils
return returned;
}
public static boolean canPlayerSeeDemonWill(PlayerEntity player)
{
IItemHandler inventory = new PlayerMainInvWrapper(player.inventory);
for (int i = 0; i < inventory.getSlots(); i++)
{
ItemStack stack = inventory.getStackInSlot(i);
if (stack.isEmpty())
{
continue;
}
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getEntityWorld(), stack, player))
{
return true;
}
}
return false;
}
public static double getDemonWillResolution(PlayerEntity player)
{
IItemHandler inventory = new PlayerMainInvWrapper(player.inventory);
for (int i = 0; i < inventory.getSlots(); i++)
{
ItemStack stack = inventory.getStackInSlot(i);
if (stack.isEmpty())
{
continue;
}
if (stack.getItem() instanceof IDemonWillViewer && ((IDemonWillViewer) stack.getItem()).canSeeDemonWillAura(player.getEntityWorld(), stack, player))
{
return ((IDemonWillViewer) stack.getItem()).getDemonWillAuraResolution(player.getEntityWorld(), stack, player);
}
}
return 100;
}
}

View file

@ -57,6 +57,7 @@ import wayoftime.bloodmagic.ritual.EnumRitualReaderState;
import wayoftime.bloodmagic.ritual.Ritual;
import wayoftime.bloodmagic.ritual.RitualComponent;
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
import wayoftime.bloodmagic.will.DemonWillHolder;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, value = Dist.CLIENT)
@OnlyIn(Dist.CLIENT)
@ -85,6 +86,8 @@ public class ClientHandler
private static boolean mrsHoloDisplay;
private static boolean mrsRangeDisplay;
public static DemonWillHolder currentAura;
static HashMap<String, ResourceLocation> resourceMap = new HashMap<String, ResourceLocation>();
public static Minecraft mc()
@ -186,8 +189,7 @@ public class ClientHandler
TileEntity tileEntity = world.getTileEntity(((BlockRayTraceResult) minecraft.objectMouseOver).getPos());
if (tileEntity instanceof TileMasterRitualStone && !player.getHeldItemMainhand().isEmpty()
&& player.getHeldItemMainhand().getItem() instanceof ItemRitualDiviner)
if (tileEntity instanceof TileMasterRitualStone && !player.getHeldItemMainhand().isEmpty() && player.getHeldItemMainhand().getItem() instanceof ItemRitualDiviner)
{
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
MatrixStack stack = event.getMatrixStack();
@ -344,8 +346,7 @@ public class ClientHandler
ClientPlayerEntity player = minecraft.player;
World world = player.getEntityWorld();
if (!player.getHeldItemMainhand().isEmpty()
&& player.getHeldItemMainhand().getItem() instanceof ItemRitualReader)
if (!player.getHeldItemMainhand().isEmpty() && player.getHeldItemMainhand().getItem() instanceof ItemRitualReader)
{
ItemStack itemStack = player.getHeldItemMainhand();
EnumRitualReaderState state = ((ItemRitualReader) itemStack.getItem()).getState(itemStack);
@ -375,8 +376,7 @@ public class ClientHandler
stack.translate(minX, minY, minZ);
ResourceLocation rl = boarder;
Model3D model = getBlockModelWithSize(rl, aabb.getXSize() - 2 * sizeOffset, aabb.getYSize() - 2
* sizeOffset, aabb.getZSize() - 2 * sizeOffset);
Model3D model = getBlockModelWithSize(rl, aabb.getXSize() - 2 * sizeOffset, aabb.getYSize() - 2 * sizeOffset, aabb.getZSize() - 2 * sizeOffset);
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0x99FF4444, 0x00F000F0, OverlayTexture.NO_OVERLAY);
stack.pop();
}
@ -483,8 +483,7 @@ public class ClientHandler
int iW = sprite.getWidth();
int iH = sprite.getHeight();
if (iW > 0 && iH > 0)
drawRepeatedSprite(builder, transform, x, y, w, h, iW, iH, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), (col >> 16
& 255) / 255.0f, (col >> 8 & 255) / 255.0f, (col & 255) / 255.0f, 1);
drawRepeatedSprite(builder, transform, x, y, w, h, iW, iH, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), (col >> 16 & 255) / 255.0f, (col >> 8 & 255) / 255.0f, (col & 255) / 255.0f, 1);
}
public static void drawRepeatedSprite(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, int iconWidth, int iconHeight, float uMin, float uMax, float vMin, float vMax, float r, float g, float b, float alpha)
@ -499,20 +498,15 @@ public class ClientHandler
float iconVDif = vMax - vMin;
for (int ww = 0; ww < iterMaxW; ww++)
{
for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + ww * iconWidth, y + hh
* iconHeight, iconWidth, iconHeight, r, g, b, alpha, uMin, uMax, vMin, vMax);
drawTexturedRect(builder, transform, x + ww * iconWidth, y + iterMaxH
* iconHeight, iconWidth, leftoverH, r, g, b, alpha, uMin, uMax, vMin, (vMin + iconVDif
* leftoverHf));
for (int hh = 0; hh < iterMaxH; hh++)
drawTexturedRect(builder, transform, x + ww * iconWidth, y + hh * iconHeight, iconWidth, iconHeight, r, g, b, alpha, uMin, uMax, vMin, vMax);
drawTexturedRect(builder, transform, x + ww * iconWidth, y + iterMaxH * iconHeight, iconWidth, leftoverH, r, g, b, alpha, uMin, uMax, vMin, (vMin + iconVDif * leftoverHf));
}
if (leftoverW > 0)
{
for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + hh
* iconHeight, leftoverW, iconHeight, r, g, b, alpha, uMin, (uMin + iconUDif
* leftoverWf), vMin, vMax);
drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + iterMaxH
* iconHeight, leftoverW, leftoverH, r, g, b, alpha, uMin, (uMin + iconUDif
* leftoverWf), vMin, (vMin + iconVDif * leftoverHf));
for (int hh = 0; hh < iterMaxH; hh++)
drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + hh * iconHeight, leftoverW, iconHeight, r, g, b, alpha, uMin, (uMin + iconUDif * leftoverWf), vMin, vMax);
drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y + iterMaxH * iconHeight, leftoverW, leftoverH, r, g, b, alpha, uMin, (uMin + iconUDif * leftoverWf), vMin, (vMin + iconVDif * leftoverHf));
}
}
@ -527,8 +521,7 @@ public class ClientHandler
public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, int x, int y, int w, int h, float picSize, int u0, int u1, int v0, int v1)
{
drawTexturedRect(builder, transform, x, y, w, h, 1, 1, 1, 1, u0 / picSize, u1 / picSize, v0 / picSize, v1
/ picSize);
drawTexturedRect(builder, transform, x, y, w, h, 1, 1, 1, 1, u0 / picSize, u1 / picSize, v0 / picSize, v1 / picSize);
}
public static void addFluidTooltip(FluidStack fluid, List<ITextComponent> tooltip, int tankCapacity)

View file

@ -1,7 +1,9 @@
package wayoftime.bloodmagic.util.handler.event;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -9,13 +11,16 @@ import net.minecraftforge.fml.common.Mod;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.core.data.Binding;
import wayoftime.bloodmagic.core.data.SoulNetwork;
import wayoftime.bloodmagic.demonaura.WorldDemonWillHandler;
import wayoftime.bloodmagic.event.ItemBindEvent;
import wayoftime.bloodmagic.iface.IBindable;
import wayoftime.bloodmagic.network.DemonAuraClientPacket;
import wayoftime.bloodmagic.orb.BloodOrb;
import wayoftime.bloodmagic.orb.IBloodOrb;
import wayoftime.bloodmagic.util.helper.BindableHelper;
import wayoftime.bloodmagic.util.helper.NetworkHelper;
import wayoftime.bloodmagic.util.helper.PlayerHelper;
import wayoftime.bloodmagic.will.DemonWillHolder;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class GenericHandler
@ -49,8 +54,7 @@ public class GenericHandler
}
// If the binding exists, we'll check if the player's name has changed since
// they last used it and update that if so.
} else if (binding.getOwnerId().equals(player.getGameProfile().getId())
&& !binding.getOwnerName().equals(player.getGameProfile().getName()))
} else if (binding.getOwnerId().equals(player.getGameProfile().getId()) && !binding.getOwnerName().equals(player.getGameProfile().getName()))
{
binding.setOwnerName(player.getGameProfile().getName());
BindableHelper.applyBinding(held, binding);
@ -70,4 +74,20 @@ public class GenericHandler
network.setOrbTier(orb.getTier());
}
}
public static void sendPlayerDemonWillAura(PlayerEntity player)
{
if (player instanceof ServerPlayerEntity)
{
BlockPos pos = player.getPosition();
DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(WorldDemonWillHandler.getDimensionResourceLocation(player.world), pos.getX() >> 4, pos.getZ() >> 4);
if (holder != null)
{
BloodMagic.packetHandler.sendTo(new DemonAuraClientPacket(holder), (ServerPlayerEntity) player);
} else
{
BloodMagic.packetHandler.sendTo(new DemonAuraClientPacket(new DemonWillHolder()), (ServerPlayerEntity) player);
}
}
}
}