Added ritual range rendering
Currently WIP. Added the ability for the selected Ritual Range to be rendered when holding the RItual Tinkerer. Also fixed the saving issue for the ritual's Ranges.
This commit is contained in:
parent
bac2af8857
commit
0e6c57076d
|
@ -31,8 +31,10 @@ import wayoftime.bloodmagic.ritual.AreaDescriptor;
|
|||
import wayoftime.bloodmagic.ritual.EnumRitualReaderState;
|
||||
import wayoftime.bloodmagic.ritual.IMasterRitualStone;
|
||||
import wayoftime.bloodmagic.ritual.Ritual;
|
||||
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
|
||||
import wayoftime.bloodmagic.util.ChatUtil;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
import wayoftime.bloodmagic.util.handler.event.ClientHandler;
|
||||
import wayoftime.bloodmagic.util.helper.NBTHelper;
|
||||
import wayoftime.bloodmagic.util.helper.TextHelper;
|
||||
import wayoftime.bloodmagic.will.DemonWillHolder;
|
||||
|
@ -148,6 +150,7 @@ public class ItemRitualReader extends Item
|
|||
}
|
||||
|
||||
master.provideInformationOfRangeToPlayer(player, range);
|
||||
|
||||
break;
|
||||
case SET_WILL_TYPES:
|
||||
List<EnumDemonWillType> typeList = new ArrayList<>();
|
||||
|
@ -232,6 +235,22 @@ public class ItemRitualReader extends Item
|
|||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
EnumRitualReaderState state = this.getState(stack);
|
||||
|
||||
if (state == EnumRitualReaderState.SET_AREA)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileMasterRitualStone)
|
||||
{
|
||||
|
||||
System.out.println("Setting range holo... I think");
|
||||
ClientHandler.setRitualRangeHolo((TileMasterRitualStone) tile, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return super.onItemUse(context);
|
||||
|
|
|
@ -112,7 +112,7 @@ public class RitualManager
|
|||
|
||||
public Ritual getRitual(String id)
|
||||
{
|
||||
return rituals.get(id);
|
||||
return rituals.get(id).getNewCopy();
|
||||
}
|
||||
|
||||
public String getId(Ritual ritual)
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -114,6 +115,13 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
|
|||
{
|
||||
currentRitual.readFromNBT(ritualTag);
|
||||
}
|
||||
addBlockRanges(currentRitual.getModableRangeMap());
|
||||
for (Entry<String, AreaDescriptor> entry : modableRangeMap.entrySet())
|
||||
{
|
||||
CompoundNBT descriptorTag = ritualTag.getCompound(entry.getKey());
|
||||
entry.getValue().readFromNBT(descriptorTag);
|
||||
// ritualTag.put(entry.getKey(), descriptorTag);
|
||||
}
|
||||
}
|
||||
active = tag.getBoolean(Constants.NBT.IS_RUNNING);
|
||||
activeTime = tag.getInt(Constants.NBT.RUNTIME);
|
||||
|
@ -140,6 +148,12 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
|
|||
{
|
||||
CompoundNBT ritualTag = new CompoundNBT();
|
||||
currentRitual.writeToNBT(ritualTag);
|
||||
for (Entry<String, AreaDescriptor> entry : modableRangeMap.entrySet())
|
||||
{
|
||||
CompoundNBT descriptorTag = new CompoundNBT();
|
||||
entry.getValue().writeToNBT(descriptorTag);
|
||||
ritualTag.put(entry.getKey(), descriptorTag);
|
||||
}
|
||||
tag.put(Constants.NBT.CURRENT_RITUAL_TAG, ritualTag);
|
||||
}
|
||||
tag.putBoolean(Constants.NBT.IS_RUNNING, isActive());
|
||||
|
@ -393,6 +407,8 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
|
|||
if (modificationType == EnumReaderBoundaries.SUCCESS)
|
||||
descriptor.modifyAreaByBlockPositions(offset1, offset2);
|
||||
|
||||
world.notifyBlockUpdate(pos, this.getBlockState(), this.getBlockState(), 3);
|
||||
|
||||
return modificationType;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,11 @@ import net.minecraft.client.renderer.texture.AtlasTexture;
|
|||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
@ -49,6 +51,9 @@ import wayoftime.bloodmagic.client.render.BloodMagicRenderer.Model3D;
|
|||
import wayoftime.bloodmagic.client.render.RenderResizableCuboid;
|
||||
import wayoftime.bloodmagic.client.utils.BMRenderTypes;
|
||||
import wayoftime.bloodmagic.common.item.ItemRitualDiviner;
|
||||
import wayoftime.bloodmagic.common.item.ItemRitualReader;
|
||||
import wayoftime.bloodmagic.ritual.AreaDescriptor;
|
||||
import wayoftime.bloodmagic.ritual.EnumRitualReaderState;
|
||||
import wayoftime.bloodmagic.ritual.Ritual;
|
||||
import wayoftime.bloodmagic.ritual.RitualComponent;
|
||||
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
|
||||
|
@ -73,9 +78,11 @@ public class ClientHandler
|
|||
// public static TextureAtlasSprite crystalCluster;
|
||||
public static Minecraft minecraft = Minecraft.getInstance();
|
||||
private static TileMasterRitualStone mrsHoloTile;
|
||||
private static TileMasterRitualStone mrsRangeTile;
|
||||
private static Ritual mrsHoloRitual;
|
||||
private static Direction mrsHoloDirection;
|
||||
private static boolean mrsHoloDisplay;
|
||||
private static boolean mrsRangeDisplay;
|
||||
|
||||
static HashMap<String, ResourceLocation> resourceMap = new HashMap<String, ResourceLocation>();
|
||||
|
||||
|
@ -154,6 +161,25 @@ public class ClientHandler
|
|||
}
|
||||
}
|
||||
|
||||
if (mrsRangeTile != null)
|
||||
{
|
||||
if (world.getTileEntity(mrsRangeTile.getPos()) instanceof TileMasterRitualStone)
|
||||
{
|
||||
if (mrsRangeDisplay)
|
||||
{
|
||||
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
MatrixStack stack = event.getMatrixStack();
|
||||
renderRangeHologram(stack, buffers, mrsRangeTile, event.getPartialTicks());
|
||||
RenderSystem.disableDepthTest();
|
||||
buffers.finish();
|
||||
} else
|
||||
ClientHandler.setRitualRangeHoloToNull();
|
||||
} else
|
||||
{
|
||||
ClientHandler.setRitualRangeHoloToNull();
|
||||
}
|
||||
}
|
||||
|
||||
if (minecraft.objectMouseOver == null || minecraft.objectMouseOver.getType() != RayTraceResult.Type.BLOCK)
|
||||
return;
|
||||
|
||||
|
@ -310,6 +336,106 @@ public class ClientHandler
|
|||
stack.pop();
|
||||
}
|
||||
|
||||
// GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public static void renderRangeHologram(MatrixStack stack, IRenderTypeBuffer renderer, TileMasterRitualStone masterRitualStone, float partialTicks)
|
||||
{
|
||||
ActiveRenderInfo activerenderinfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
||||
Vector3d eyePos = activerenderinfo.getProjectedView();
|
||||
IVertexBuilder buffer = renderer.getBuffer(Atlases.getTranslucentCullBlockType());
|
||||
ClientPlayerEntity player = minecraft.player;
|
||||
World world = player.getEntityWorld();
|
||||
|
||||
if (!player.getHeldItemMainhand().isEmpty()
|
||||
&& player.getHeldItemMainhand().getItem() instanceof ItemRitualReader)
|
||||
{
|
||||
ItemStack itemStack = player.getHeldItemMainhand();
|
||||
EnumRitualReaderState state = ((ItemRitualReader) itemStack.getItem()).getState(itemStack);
|
||||
if (state == EnumRitualReaderState.SET_AREA)
|
||||
{
|
||||
Ritual ritual = masterRitualStone.getCurrentRitual();
|
||||
String range = ((ItemRitualReader) itemStack.getItem()).getCurrentBlockRange(itemStack);
|
||||
AreaDescriptor descriptor = masterRitualStone.getBlockRange(range);
|
||||
if (descriptor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stack.push();
|
||||
BlockPos vec3, vX;
|
||||
vec3 = masterRitualStone.getPos();
|
||||
AxisAlignedBB aabb = descriptor.getAABB(vec3);
|
||||
|
||||
double minX = aabb.minX - eyePos.x;
|
||||
double minY = aabb.minY - eyePos.y;
|
||||
double minZ = aabb.minZ - eyePos.z;
|
||||
|
||||
stack.translate(minX, minY, minZ);
|
||||
|
||||
ResourceLocation rl = ritualStoneFire;
|
||||
Model3D model = getBlockModelWithSize(rl, aabb.getXSize(), aabb.getYSize(), aabb.getZSize());
|
||||
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0xDDFFFFFF, 0x00F000F0, OverlayTexture.NO_OVERLAY);
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// if (ritual == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// BlockPos vec3, vX;
|
||||
// vec3 = masterRitualStone.getPos();
|
||||
//
|
||||
// List<RitualComponent> components = Lists.newArrayList();
|
||||
// ritual.gatherComponents(components::add);
|
||||
// for (RitualComponent ritualComponent : components)
|
||||
// {
|
||||
// stack.push();
|
||||
// vX = vec3.add(ritualComponent.getOffset(direction));
|
||||
//
|
||||
// double minX = vX.getX() - eyePos.x;
|
||||
// double minY = vX.getY() - eyePos.y;
|
||||
// double minZ = vX.getZ() - eyePos.z;
|
||||
//
|
||||
// stack.translate(minX, minY, minZ);
|
||||
//
|
||||
// if (!world.getBlockState(vX).isOpaqueCube(world, vX))
|
||||
// {
|
||||
// ResourceLocation rl = null;
|
||||
//
|
||||
// switch (ritualComponent.getRuneType())
|
||||
// {
|
||||
// case BLANK:
|
||||
// rl = ritualStoneBlank;
|
||||
// break;
|
||||
// case WATER:
|
||||
// rl = ritualStoneWater;
|
||||
// break;
|
||||
// case FIRE:
|
||||
// rl = ritualStoneFire;
|
||||
// break;
|
||||
// case EARTH:
|
||||
// rl = ritualStoneEarth;
|
||||
// break;
|
||||
// case AIR:
|
||||
// rl = ritualStoneAir;
|
||||
// break;
|
||||
// case DAWN:
|
||||
// rl = ritualStoneDawn;
|
||||
// break;
|
||||
// case DUSK:
|
||||
// rl = ritualStoneDusk;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
//// RenderFakeBlocks.drawFakeBlock(texture, minX, minY, minZ);
|
||||
// }
|
||||
//
|
||||
// stack.pop();
|
||||
// }
|
||||
|
||||
// GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
|
@ -327,6 +453,20 @@ public class ClientHandler
|
|||
return model;
|
||||
}
|
||||
|
||||
private static Model3D getBlockModelWithSize(ResourceLocation rl, double maxX, double maxY, double maxZ)
|
||||
{
|
||||
Model3D model = new BloodMagicRenderer.Model3D();
|
||||
model.setTexture(Minecraft.getInstance().getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(rl));
|
||||
model.minX = 0;
|
||||
model.minY = 0;
|
||||
model.minZ = 0;
|
||||
model.maxX = maxX;
|
||||
model.maxY = maxY;
|
||||
model.maxZ = maxZ;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void setRitualHolo(TileMasterRitualStone masterRitualStone, Ritual ritual, Direction direction, boolean displayed)
|
||||
{
|
||||
mrsHoloDisplay = displayed;
|
||||
|
@ -343,6 +483,18 @@ public class ClientHandler
|
|||
mrsHoloDirection = Direction.NORTH;
|
||||
}
|
||||
|
||||
public static void setRitualRangeHolo(TileMasterRitualStone masterRitualStone, boolean displayed)
|
||||
{
|
||||
mrsRangeDisplay = displayed;
|
||||
mrsRangeTile = masterRitualStone;
|
||||
}
|
||||
|
||||
public static void setRitualRangeHoloToNull()
|
||||
{
|
||||
mrsRangeDisplay = false;
|
||||
mrsRangeTile = null;
|
||||
}
|
||||
|
||||
public static void handleGuiTank(MatrixStack transform, IFluidTank tank, int x, int y, int w, int h, int oX, int oY, int oW, int oH, int mX, int mY, String originalTexture, List<ITextComponent> tooltip)
|
||||
{
|
||||
handleGuiTank(transform, tank.getFluid(), tank.getCapacity(), x, y, w, h, oX, oY, oW, oH, mX, mY, originalTexture, tooltip);
|
||||
|
@ -363,8 +515,7 @@ public class ClientHandler
|
|||
int xOff = (w - oW) / 2;
|
||||
int yOff = (h - oH) / 2;
|
||||
RenderType renderType = BMRenderTypes.getGui(new ResourceLocation(originalTexture));
|
||||
drawTexturedRect(buffer.getBuffer(renderType), transform, x + xOff, y + yOff, oW, oH, 256f, oX, oX
|
||||
+ oW, oY, oY + oH);
|
||||
drawTexturedRect(buffer.getBuffer(renderType), transform, x + xOff, y + yOff, oW, oH, 256f, oX, oX + oW, oY, oY + oH);
|
||||
buffer.finish(renderType);
|
||||
transform.pop();
|
||||
} else
|
||||
|
@ -404,32 +555,29 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, float r, float g, float b, float alpha, float u0, float u1, float v0, float v1)
|
||||
{
|
||||
Matrix4f mat = transform.getLast().getMatrix();
|
||||
builder.pos(mat, x, y
|
||||
+ h, 0).color(r, g, b, alpha).tex(u0, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(0xf000f0).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x + w, y
|
||||
+ h, 0).color(r, g, b, alpha).tex(u1, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x
|
||||
+ w, y, 0).color(r, g, b, alpha).tex(u1, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x, y + h, 0).color(r, g, b, alpha).tex(u0, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(0xf000f0).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x + w, y + h, 0).color(r, g, b, alpha).tex(u1, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x + w, y, 0).color(r, g, b, alpha).tex(u1, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x, y, 0).color(r, g, b, alpha).tex(u0, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue