Attempt to try to fix the 1.16.3's branch having multiple 'wayoftime' folders.

This commit is contained in:
WayofTime 2020-10-29 15:48:44 -04:00
parent c159828248
commit 6b4145a67c
224 changed files with 0 additions and 24047 deletions

View file

@ -1,295 +0,0 @@
package wayoftime.bloodmagic.util;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
public class MultiSlotItemHandler implements IItemHandler
{
private ItemStack[] items;
private final int invLimit;
public MultiSlotItemHandler(int size, int invLimit)
{
items = new ItemStack[size];
for (int i = 0; i < size; i++)
{
items[i] = ItemStack.EMPTY;
}
this.invLimit = invLimit;
}
public MultiSlotItemHandler(ItemStack[] items, int invLimit)
{
this.items = items;
this.invLimit = invLimit;
}
@Override
public int getSlots()
{
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return items[slot];
}
public boolean isItemValid(int slot, ItemStack stack)
{
return true;
}
public void setInventorySlotContents(int slot, ItemStack stack)
{
items[slot] = stack;
}
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{
if (stack.isEmpty())
return ItemStack.EMPTY;
ItemStack stackInSlot = getStackInSlot(slot);
int m;
if (!stackInSlot.isEmpty())
{
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
return stack;
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
return stack;
if (!isItemValid(slot, stack))
return stack;
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount();
if (stack.getCount() <= m)
{
if (!simulate)
{
ItemStack copy = stack.copy();
copy.grow(stackInSlot.getCount());
setInventorySlotContents(slot, copy);
}
return ItemStack.EMPTY;
} else
{
// copy the stack to not modify the original one
stack = stack.copy();
if (!simulate)
{
ItemStack copy = stack.split(m);
copy.grow(stackInSlot.getCount());
setInventorySlotContents(slot, copy);
return stack;
} else
{
stack.shrink(m);
return stack;
}
}
} else
{
if (!isItemValid(slot, stack))
return stack;
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot));
if (m < stack.getCount())
{
// copy the stack to not modify the original one
stack = stack.copy();
if (!simulate)
{
setInventorySlotContents(slot, stack.split(m));
return stack;
} else
{
stack.shrink(m);
return stack;
}
} else
{
if (!simulate)
{
setInventorySlotContents(slot, stack);
}
return ItemStack.EMPTY;
}
}
}
public boolean canTransferAllItemsToSlots(List<ItemStack> stackList, boolean simulate)
{
ItemStack[] copyList = new ItemStack[items.length];
for (int i = 0; i < copyList.length; i++)
{
copyList[i] = items[i].copy();
}
boolean hasStashedAll = true;
for (ItemStack stack : stackList)
{
if (stack.isEmpty())
{
continue;
}
slots: for (int slot = 0; slot < copyList.length; slot++)
{
ItemStack stackInSlot = copyList[slot];
int m;
if (!stackInSlot.isEmpty())
{
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
continue;
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
continue;
if (!isItemValid(slot, stack))
continue;
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount();
if (stack.getCount() <= m)
{
ItemStack copy = stack.copy();
if (!simulate)
{
copy.grow(stackInSlot.getCount());
copyList[slot] = copy;
}
stack = ItemStack.EMPTY;
break slots;
} else
{
// copy the stack to not modify the original one
stack = stack.copy();
if (!simulate)
{
ItemStack copy = stack.split(m);
copy.grow(stackInSlot.getCount());
copyList[slot] = copy;
} else
{
stack.shrink(m);
}
}
} else
{
if (!isItemValid(slot, stack))
continue;
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot));
if (m < stack.getCount())
{
// copy the stack to not modify the original one
stack = stack.copy();
if (!simulate)
{
copyList[slot] = stack.split(m);
} else
{
stack.shrink(m);
}
} else
{
if (!simulate)
{
copyList[slot] = stack;
}
stack = ItemStack.EMPTY;
}
}
}
if (!stack.isEmpty())
{
hasStashedAll = false;
break;
}
}
if (!simulate)
{
items = copyList;
}
return hasStashedAll;
}
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
return ItemStack.EMPTY;
ItemStack stackInSlot = getStackInSlot(slot);
if (stackInSlot.isEmpty())
return ItemStack.EMPTY;
if (simulate)
{
if (stackInSlot.getCount() < amount)
{
return stackInSlot.copy();
} else
{
ItemStack copy = stackInSlot.copy();
copy.setCount(amount);
return copy;
}
} else
{
int m = Math.min(stackInSlot.getCount(), amount);
ItemStack decrStackSize = decrStackSize(slot, m);
return decrStackSize;
}
}
public ItemStack decrStackSize(int slot, int amount)
{
if (!getStackInSlot(slot).isEmpty())
{
if (getStackInSlot(slot).getCount() <= amount)
{
ItemStack itemStack = getStackInSlot(slot);
setInventorySlotContents(slot, ItemStack.EMPTY);
return itemStack;
}
ItemStack itemStack = getStackInSlot(slot).split(amount);
return itemStack;
}
return ItemStack.EMPTY;
}
@Override
public int getSlotLimit(int slot)
{
return invLimit;
}
}

View file

@ -1,479 +0,0 @@
package wayoftime.bloodmagic.util.handler.event;
import java.util.HashMap;
import java.util.List;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.Atlases;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.Tessellator;
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.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.fml.common.Mod;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.client.render.BloodMagicRenderer;
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.ritual.Ritual;
import wayoftime.bloodmagic.ritual.RitualComponent;
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, value = Dist.CLIENT)
@OnlyIn(Dist.CLIENT)
public class ClientHandler
{
public static final boolean SUPPRESS_ASSET_ERRORS = true;
public static ResourceLocation ritualStoneBlank = BloodMagic.rl("block/ritualstone");;
public static ResourceLocation ritualStoneWater = BloodMagic.rl("block/waterritualstone");;
public static ResourceLocation ritualStoneFire = BloodMagic.rl("block/fireritualstone");;
public static ResourceLocation ritualStoneEarth = BloodMagic.rl("block/earthritualstone");;
public static ResourceLocation ritualStoneAir = BloodMagic.rl("block/airritualstone");;
public static ResourceLocation ritualStoneDawn = BloodMagic.rl("block/dawnritualstone");;
public static ResourceLocation ritualStoneDusk = BloodMagic.rl("block/duskritualstone");;
public static TextureAtlasSprite blankBloodRune;
public static TextureAtlasSprite stoneBrick;
public static TextureAtlasSprite glowstone;
// public static TextureAtlasSprite bloodStoneBrick;
public static TextureAtlasSprite beacon;
// public static TextureAtlasSprite crystalCluster;
public static Minecraft minecraft = Minecraft.getInstance();
private static TileMasterRitualStone mrsHoloTile;
private static Ritual mrsHoloRitual;
private static Direction mrsHoloDirection;
private static boolean mrsHoloDisplay;
static HashMap<String, ResourceLocation> resourceMap = new HashMap<String, ResourceLocation>();
public static Minecraft mc()
{
return Minecraft.getInstance();
}
public static void bindTexture(String path)
{
mc().getTextureManager().bindTexture(getResource(path));
}
public static void bindAtlas()
{
mc().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
}
public static ResourceLocation getResource(String path)
{
ResourceLocation rl = resourceMap.containsKey(path) ? resourceMap.get(path) : new ResourceLocation(path);
if (!resourceMap.containsKey(path))
resourceMap.put(path, rl);
return rl;
}
public static TextureAtlasSprite getSprite(ResourceLocation rl)
{
return mc().getModelManager().getAtlasTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE).getSprite(rl);
}
@SubscribeEvent
public static void onTextureStitch(TextureStitchEvent.Pre event)
{
final String BLOCKS = "block/";
// ritualStoneBlank = Minecraft.getInstance().getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(BloodMagic.rl(block//" + "blankrune"));
//// 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);
blankBloodRune = forName(event.getMap(), "blankrune", BLOCKS);
stoneBrick = event.getMap().getSprite(new ResourceLocation("minecraft:block/stonebrick"));
glowstone = event.getMap().getSprite(new ResourceLocation("minecraft:block/glowstone"));
// bloodStoneBrick = forName(event.getMap(), "BloodStoneBrick", BLOCKS);
beacon = event.getMap().getSprite(new ResourceLocation("minecraft:block/beacon"));
// crystalCluster = forName(event.getMap(), "ShardCluster", BLOCKS);
}
@SubscribeEvent
public static void render(RenderWorldLastEvent event)
{
ClientPlayerEntity player = minecraft.player;
World world = player.getEntityWorld();
if (mrsHoloTile != null)
{
if (world.getTileEntity(mrsHoloTile.getPos()) instanceof TileMasterRitualStone)
{
if (mrsHoloDisplay)
{
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
MatrixStack stack = event.getMatrixStack();
renderRitualStones(stack, buffers, mrsHoloTile, event.getPartialTicks());
RenderSystem.disableDepthTest();
buffers.finish();
} else
ClientHandler.setRitualHoloToNull();
} else
{
ClientHandler.setRitualHoloToNull();
}
}
if (minecraft.objectMouseOver == null || minecraft.objectMouseOver.getType() != RayTraceResult.Type.BLOCK)
return;
TileEntity tileEntity = world.getTileEntity(((BlockRayTraceResult) minecraft.objectMouseOver).getPos());
if (tileEntity instanceof TileMasterRitualStone && !player.getHeldItemMainhand().isEmpty()
&& player.getHeldItemMainhand().getItem() instanceof ItemRitualDiviner)
{
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
MatrixStack stack = event.getMatrixStack();
renderRitualStones(stack, buffers, player, event.getPartialTicks());
RenderSystem.disableDepthTest();
buffers.finish();
}
}
private static TextureAtlasSprite forName(AtlasTexture textureMap, String name, String dir)
{
return textureMap.getSprite(new ResourceLocation(BloodMagic.MODID + dir + "/" + name));
}
private static void renderRitualStones(MatrixStack stack, IRenderTypeBuffer renderer, ClientPlayerEntity player, float partialTicks)
{
ActiveRenderInfo activerenderinfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
Vector3d eyePos = activerenderinfo.getProjectedView();
IVertexBuilder buffer = renderer.getBuffer(Atlases.getTranslucentCullBlockType());
World world = player.getEntityWorld();
ItemRitualDiviner ritualDiviner = (ItemRitualDiviner) player.inventory.getCurrentItem().getItem();
Direction direction = ritualDiviner.getDirection(player.inventory.getCurrentItem());
Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(ritualDiviner.getCurrentRitual(player.inventory.getCurrentItem()));
if (ritual == null)
return;
BlockPos vec3, vX;
vec3 = ((BlockRayTraceResult) minecraft.objectMouseOver).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;
}
Model3D model = getBlockModel(rl);
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0xDDFFFFFF, 0x00F000F0, OverlayTexture.NO_OVERLAY);
}
stack.pop();
}
}
public static void renderRitualStones(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();
Direction direction = mrsHoloDirection;
Ritual ritual = mrsHoloRitual;
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;
}
Model3D model = getBlockModel(rl);
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0xDDFFFFFF, 0x00F000F0, OverlayTexture.NO_OVERLAY);
// RenderFakeBlocks.drawFakeBlock(texture, minX, minY, minZ);
}
stack.pop();
}
// GlStateManager.popMatrix();
}
private static Model3D getBlockModel(ResourceLocation rl)
{
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 = 1;
model.maxY = 1;
model.maxZ = 1;
return model;
}
public static void setRitualHolo(TileMasterRitualStone masterRitualStone, Ritual ritual, Direction direction, boolean displayed)
{
mrsHoloDisplay = displayed;
mrsHoloTile = masterRitualStone;
mrsHoloRitual = ritual;
mrsHoloDirection = direction;
}
public static void setRitualHoloToNull()
{
mrsHoloDisplay = false;
mrsHoloTile = null;
mrsHoloRitual = null;
mrsHoloDirection = Direction.NORTH;
}
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);
}
public static void handleGuiTank(MatrixStack transform, FluidStack fluid, int capacity, 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)
{
if (tooltip == null)
{
transform.push();
IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer());
if (fluid != null && fluid.getFluid() != null)
{
int fluidHeight = (int) (h * (fluid.getAmount() / (float) capacity));
drawRepeatedFluidSpriteGui(buffer, transform, fluid, x, y + h - fluidHeight, w, fluidHeight);
RenderSystem.color3f(1, 1, 1);
}
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);
buffer.finish(renderType);
transform.pop();
} else
{
if (mX >= x && mX < x + w && mY >= y && mY < y + h)
addFluidTooltip(fluid, tooltip, capacity);
}
}
public static void drawRepeatedFluidSpriteGui(IRenderTypeBuffer buffer, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h)
{
RenderType renderType = BMRenderTypes.getGui(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
IVertexBuilder builder = buffer.getBuffer(renderType);
drawRepeatedFluidSprite(builder, transform, fluid, x, y, w, h);
}
public static void drawRepeatedFluidSprite(IVertexBuilder builder, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h)
{
TextureAtlasSprite sprite = getSprite(fluid.getFluid().getAttributes().getStillTexture(fluid));
int col = fluid.getFluid().getAttributes().getColor(fluid);
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);
}
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)
{
int iterMaxW = (int) (w / iconWidth);
int iterMaxH = (int) (h / iconHeight);
float leftoverW = w % iconWidth;
float leftoverH = h % iconHeight;
float leftoverWf = leftoverW / (float) iconWidth;
float leftoverHf = leftoverH / (float) iconHeight;
float iconUDif = uMax - uMin;
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));
}
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));
}
}
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, 0).color(r, g, b, alpha).tex(u0, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
}
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);
}
public static void addFluidTooltip(FluidStack fluid, List<ITextComponent> tooltip, int tankCapacity)
{
if (!fluid.isEmpty())
tooltip.add(applyFormat(fluid.getDisplayName(), fluid.getFluid().getAttributes().getRarity(fluid).color));
else
tooltip.add(new TranslationTextComponent("gui.bloodmagic.empty"));
// if (fluid.getFluid() instanceof IEFluid)
// ((IEFluid) fluid.getFluid()).addTooltipInfo(fluid, null, tooltip);
if (mc().gameSettings.advancedItemTooltips && !fluid.isEmpty())
{
if (!Screen.hasShiftDown())
tooltip.add(new TranslationTextComponent("tooltip.bloodmagic.holdShiftForInfo"));
else
{
// TODO translation keys
tooltip.add(applyFormat(new StringTextComponent("Fluid Registry: " + fluid.getFluid().getRegistryName()), TextFormatting.DARK_GRAY));
tooltip.add(applyFormat(new StringTextComponent("Density: " + fluid.getFluid().getAttributes().getDensity(fluid)), TextFormatting.DARK_GRAY));
tooltip.add(applyFormat(new StringTextComponent("Temperature: " + fluid.getFluid().getAttributes().getTemperature(fluid)), TextFormatting.DARK_GRAY));
tooltip.add(applyFormat(new StringTextComponent("Viscosity: " + fluid.getFluid().getAttributes().getViscosity(fluid)), TextFormatting.DARK_GRAY));
tooltip.add(applyFormat(new StringTextComponent("NBT Data: " + fluid.getTag()), TextFormatting.DARK_GRAY));
}
}
if (tankCapacity > 0)
tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "/" + tankCapacity + "mB"), TextFormatting.GRAY));
else
tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "mB"), TextFormatting.GRAY));
}
public static IFormattableTextComponent applyFormat(ITextComponent component, TextFormatting... color)
{
Style style = component.getStyle();
for (TextFormatting format : color) style = style.applyFormatting(format);
return component.deepCopy().setStyle(style);
}
}

View file

@ -1,253 +0,0 @@
package wayoftime.bloodmagic.util.helper;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.util.LazyOptional;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.common.block.BlockRitualStone;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.ritual.EnumRuneType;
import wayoftime.bloodmagic.ritual.IRitualStone;
import wayoftime.bloodmagic.ritual.IRitualStone.Tile;
import wayoftime.bloodmagic.ritual.Ritual;
import wayoftime.bloodmagic.ritual.RitualComponent;
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
public class RitualHelper
{
@CapabilityInject(IRitualStone.Tile.class)
static Capability<IRitualStone.Tile> RUNE_CAPABILITY = null;
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel)
{
return ritual.getCrystalLevel() <= crystalLevel
&& BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(ritual), false);
}
/**
* Checks the RitualRegistry to see if the configuration of the ritual stones in
* the world is valid for the given Direction.
*
* @param world - The world
* @param pos - Location of the MasterRitualStone
* @return The ID of the valid ritual
*/
public static String getValidRitual(World world, BlockPos pos)
{
for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals())
{
for (int i = 0; i < 4; i++)
{
Direction direction = Direction.byHorizontalIndex(i);
if (checkValidRitual(world, pos, ritual, direction))
return BloodMagic.RITUAL_MANAGER.getId(ritual);
}
}
return "";
}
public static Direction getDirectionOfRitual(World world, BlockPos pos, Ritual ritual)
{
for (int i = 0; i < 4; i++)
{
Direction direction = Direction.byHorizontalIndex(i);
if (checkValidRitual(world, pos, ritual, direction))
return direction;
}
return null;
}
public static boolean checkValidRitual(World world, BlockPos pos, Ritual ritual, Direction direction)
{
if (ritual == null)
{
return false;
}
List<RitualComponent> components = Lists.newArrayList();
ritual.gatherComponents(components::add);
for (RitualComponent component : components)
{
BlockPos newPos = pos.add(component.getOffset(direction));
if (!isRuneType(world, newPos, component.getRuneType()))
return false;
}
return true;
}
public static boolean isRuneType(World world, BlockPos pos, EnumRuneType type)
{
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return ((IRitualStone) block).isRuneType(world, pos, type);
else if (tile instanceof IRitualStone.Tile)
return ((IRitualStone.Tile) tile).isRuneType(type);
else if (tile != null && tile.getCapability(RUNE_CAPABILITY, null).isPresent())
return tile.getCapability(RUNE_CAPABILITY, null).resolve().get().isRuneType(type);
return false;
}
public static boolean isRune(World world, BlockPos pos)
{
if (world == null)
return false;
Block block = world.getBlockState(pos).getBlock();
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
return true;
else if (tile instanceof IRitualStone.Tile)
return true;
else
return tile != null && tile.getCapability(RUNE_CAPABILITY, null).isPresent();
}
public static void setRuneType(World world, BlockPos pos, EnumRuneType type)
{
if (world == null)
return;
BlockState state = world.getBlockState(pos);
TileEntity tile = world.getTileEntity(pos);
if (state.getBlock() instanceof IRitualStone)
((IRitualStone) state.getBlock()).setRuneType(world, pos, type);
else if (tile instanceof IRitualStone.Tile)
((IRitualStone.Tile) tile).setRuneType(type);
else
{
LazyOptional<Tile> cap = tile.getCapability(RUNE_CAPABILITY, null);
if (cap.isPresent())
{
cap.resolve().get().setRuneType(type);
world.notifyBlockUpdate(pos, state, state, 3);
}
}
}
public static boolean createRitual(World world, BlockPos pos, Direction direction, Ritual ritual, boolean safe)
{
List<RitualComponent> components = Lists.newArrayList();
ritual.gatherComponents(components::add);
if (abortConstruction(world, pos, direction, safe, components))
return false;
BlockState mrs = BloodMagicBlocks.MASTER_RITUAL_STONE.get().getDefaultState();
world.setBlockState(pos, mrs);
setRitualStones(direction, world, pos, components);
return true;
}
public static boolean abortConstruction(World world, BlockPos pos, Direction direction, boolean safe, List<RitualComponent> components)
{
// TODO: can be optimized to check only for the first and last component if
// every ritual has those at the highest and lowest y-level respectivly.
for (RitualComponent component : components)
{
BlockPos offset = component.getOffset(direction);
BlockPos newPos = pos.add(offset);
if (world.isOutsideBuildHeight(newPos) || (safe && !world.isAirBlock(newPos)))
return true;
}
return false;
}
public static boolean repairRitualFromRuins(TileMasterRitualStone tile, boolean safe)
{
Ritual ritual = tile.getCurrentRitual();
Direction direction;
Pair<Ritual, Direction> pair;
if (ritual == null)
{
pair = getRitualFromRuins(tile);
ritual = pair.getKey();
direction = pair.getValue();
} else
direction = tile.getDirection();
World world = tile.getWorld();
BlockPos pos = tile.getPos();
List<RitualComponent> components = Lists.newArrayList();
ritual.gatherComponents(components::add);
if (abortConstruction(world, pos, direction, safe, components))
return false;
setRitualStones(direction, world, pos, components);
return true;
}
public static void setRitualStones(Direction direction, World world, BlockPos pos, List<RitualComponent> gatheredComponents)
{
for (RitualComponent component : gatheredComponents)
{
BlockPos offset = component.getOffset(direction);
BlockPos newPos = pos.add(offset);
((BlockRitualStone) BloodMagicBlocks.BLANK_RITUAL_STONE.get()).setRuneType(world, newPos, component.getRuneType());
}
}
public static Pair<Ritual, Direction> getRitualFromRuins(TileMasterRitualStone tile)
{
BlockPos pos = tile.getPos();
World world = tile.getWorld();
Ritual possibleRitual = tile.getCurrentRitual();
Direction possibleDirection = tile.getDirection();
int highestCount = 0;
if (possibleRitual == null || possibleDirection == null)
for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals())
{
for (int i = 0; i < 4; i++)
{
Direction direction = Direction.byHorizontalIndex(i);
List<RitualComponent> components = Lists.newArrayList();
ritual.gatherComponents(components::add);
int currentCount = 0;
for (RitualComponent component : components)
{
BlockPos newPos = pos.add(component.getOffset(direction));
if (isRuneType(world, newPos, component.getRuneType()))
currentCount += 1;
}
if (currentCount > highestCount)
{
highestCount = currentCount;
possibleRitual = ritual;
possibleDirection = direction;
}
}
}
return Pair.of(possibleRitual, possibleDirection);
}
}