mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Utils porting
This commit is contained in:
parent
24fb9a26e0
commit
3e61998ca8
10 changed files with 238 additions and 258 deletions
|
@ -9,6 +9,7 @@ import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler;
|
||||||
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
||||||
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
|
import de.ellpeck.actuallyadditions.api.lens.LensConversion;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.*;
|
import de.ellpeck.actuallyadditions.api.recipe.*;
|
||||||
|
import de.ellpeck.actuallyadditions.common.recipes.CrusherRecipe;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
|
|
@ -1,41 +1,36 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.common.network.PacketHandler;
|
import de.ellpeck.actuallyadditions.common.network.PacketHandler;
|
||||||
import de.ellpeck.actuallyadditions.common.network.PacketServerToClient;
|
import de.ellpeck.actuallyadditions.common.network.PacketServerToClient;
|
||||||
import de.ellpeck.actuallyadditions.common.particle.ParticleBeam;
|
import de.ellpeck.actuallyadditions.common.particle.ParticleBeam;
|
||||||
import de.ellpeck.actuallyadditions.common.tile.TileEntityBase;
|
import de.ellpeck.actuallyadditions.common.tile.TileEntityBase;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.particle.Particle;
|
import net.minecraft.client.particle.Particle;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.ItemRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager.DestFactor;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
|
|
||||||
import net.minecraft.client.renderer.RenderHelper;
|
import net.minecraft.client.renderer.RenderHelper;
|
||||||
import net.minecraft.client.renderer.RenderItem;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.renderer.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType;
|
import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.renderer.texture.TextureManager;
|
||||||
import net.minecraft.client.renderer.texture.TextureMap;
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.inventory.container.PlayerContainer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import org.lwjgl.opengl.GL11;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
public final class AssetUtil {
|
public final class AssetUtil {
|
||||||
|
|
||||||
|
@ -52,99 +47,99 @@ public final class AssetUtil {
|
||||||
return getGuiLocation("booklet/" + file);
|
return getGuiLocation("booklet/" + file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, String text) {
|
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, String text) {
|
||||||
font.drawString(text, xSize / 2 - font.getStringWidth(text) / 2, yPositionOfMachineText, StringUtil.DECIMAL_COLOR_WHITE);
|
font.drawString(text, xSize / 2 - font.getStringWidth(text) / 2, yPositionOfMachineText, StringUtil.DECIMAL_COLOR_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, TileEntityBase tile) {
|
public static void displayNameString(FontRenderer font, int xSize, int yPositionOfMachineText, TileEntityBase tile) {
|
||||||
displayNameString(font, xSize, yPositionOfMachineText, StringUtil.localize(tile.getNameForTranslation()));
|
displayNameString(font, xSize, yPositionOfMachineText, StringUtil.localize(tile.getNameForTranslation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderBlockInWorld(Block block, int meta) {
|
public static void renderBlockInWorld(Block block, int meta) {
|
||||||
renderItemInWorld(new ItemStack(block, 1, meta));
|
renderItemInWorld(new ItemStack(block, 1, meta));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderItemInWorld(ItemStack stack) {
|
public static void renderItemInWorld(ItemStack stack) {
|
||||||
if (StackUtil.isValid(stack)) {
|
if (StackUtil.isValid(stack)) {
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
GlStateManager.disableLighting();
|
RenderSystem.disableLighting();
|
||||||
GlStateManager.pushAttrib();
|
RenderSystem.pushAttrib();
|
||||||
RenderHelper.enableStandardItemLighting();
|
RenderHelper.enableStandardItemLighting();
|
||||||
Minecraft.getMinecraft().getRenderItem().renderItem(stack, TransformType.FIXED);
|
Minecraft.getInstance().getItemRenderer().renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
|
||||||
RenderHelper.disableStandardItemLighting();
|
RenderHelper.disableStandardItemLighting();
|
||||||
GlStateManager.popAttrib();
|
RenderSystem.popAttrib();
|
||||||
GlStateManager.enableLighting();
|
RenderSystem.enableLighting();
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderStateInWorld(IBlockState state, IBlockAccess world, BlockPos pos, float brightness) {
|
public static void renderStateInWorld(IBlockState state, IBlockAccess world, BlockPos pos, float brightness) {
|
||||||
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
Minecraft.getInstance().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
||||||
IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state);
|
IBakedModel model = Minecraft.getInstance().getBlockRendererDispatcher().getModelForState(state);
|
||||||
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
RenderSystem.rotate(90.0F, 0.0F, 1.0F, 0.0F);
|
||||||
int i = Minecraft.getMinecraft().getBlockColors().colorMultiplier(state, world, pos, 0);
|
int i = Minecraft.getInstance().getBlockColors().colorMultiplier(state, world, pos, 0);
|
||||||
|
|
||||||
float r = (i >> 16 & 255) / 255F;
|
float r = (i >> 16 & 255) / 255F;
|
||||||
float g = (i >> 8 & 255) / 255F;
|
float g = (i >> 8 & 255) / 255F;
|
||||||
float b = (i & 255) / 255F;
|
float b = (i & 255) / 255F;
|
||||||
|
|
||||||
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(state, model, brightness, r, g, b);
|
Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(state, model, brightness, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderItemWithoutScrewingWithColors(ItemStack stack) {
|
public static void renderItemWithoutScrewingWithColors(ItemStack stack) {
|
||||||
if (StackUtil.isValid(stack)) {
|
if (StackUtil.isValid(stack)) {
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
RenderItem renderer = mc.getRenderItem();
|
ItemRenderer renderer = mc.getItemRenderer();
|
||||||
TextureManager manager = mc.getTextureManager();
|
TextureManager manager = mc.getTextureManager();
|
||||||
|
|
||||||
IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null);
|
IBakedModel model = renderer.getItemModelWithOverrides(stack, null, null);
|
||||||
|
|
||||||
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
manager.bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
||||||
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
|
manager.getTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
|
||||||
GlStateManager.enableRescaleNormal();
|
RenderSystem.enableRescaleNormal();
|
||||||
GlStateManager.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
model = ForgeHooksClient.handleCameraTransforms(model, TransformType.FIXED, false);
|
model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.FIXED, false, false);
|
||||||
renderer.renderItem(stack, model);
|
renderer.renderItem(stack, model);
|
||||||
GlStateManager.cullFace(GlStateManager.CullFace.BACK);
|
RenderSystem.cullFace(RenderSystem.CullFace.BACK);
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
GlStateManager.disableRescaleNormal();
|
RenderSystem.disableRescaleNormal();
|
||||||
GlStateManager.disableBlend();
|
RenderSystem.disableBlend();
|
||||||
manager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
manager.bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
||||||
manager.getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
|
manager.getTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderStackToGui(ItemStack stack, int x, int y, float scale) {
|
public static void renderStackToGui(ItemStack stack, int x, int y, float scale) {
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
GlStateManager.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
RenderHelper.enableGUIStandardItemLighting();
|
RenderHelper.enableGUIStandardItemLighting();
|
||||||
GlStateManager.enableDepth();
|
RenderSystem.enableDepth();
|
||||||
GlStateManager.enableRescaleNormal();
|
RenderSystem.enableRescaleNormal();
|
||||||
GlStateManager.translate(x, y, 0);
|
RenderSystem.translate(x, y, 0);
|
||||||
GlStateManager.scale(scale, scale, scale);
|
RenderSystem.scale(scale, scale, scale);
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
boolean flagBefore = mc.fontRenderer.getUnicodeFlag();
|
boolean flagBefore = mc.fontRenderer.getUnicodeFlag();
|
||||||
mc.fontRenderer.setUnicodeFlag(false);
|
mc.fontRenderer.setUnicodeFlag(false);
|
||||||
Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0);
|
Minecraft.getInstance().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0);
|
||||||
Minecraft.getMinecraft().getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, stack, 0, 0, null);
|
Minecraft.getInstance().getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, stack, 0, 0, null);
|
||||||
mc.fontRenderer.setUnicodeFlag(flagBefore);
|
mc.fontRenderer.setUnicodeFlag(flagBefore);
|
||||||
|
|
||||||
RenderHelper.disableStandardItemLighting();
|
RenderHelper.disableStandardItemLighting();
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Copied from Gui.class and changed
|
//Copied from Gui.class and changed
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void drawHorizontalGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, float zLevel) {
|
public static void drawHorizontalGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, float zLevel) {
|
||||||
float f = (startColor >> 24 & 255) / 255.0F;
|
float f = (startColor >> 24 & 255) / 255.0F;
|
||||||
float f1 = (startColor >> 16 & 255) / 255.0F;
|
float f1 = (startColor >> 16 & 255) / 255.0F;
|
||||||
|
@ -154,11 +149,11 @@ public final class AssetUtil {
|
||||||
float f5 = (endColor >> 16 & 255) / 255.0F;
|
float f5 = (endColor >> 16 & 255) / 255.0F;
|
||||||
float f6 = (endColor >> 8 & 255) / 255.0F;
|
float f6 = (endColor >> 8 & 255) / 255.0F;
|
||||||
float f7 = (endColor & 255) / 255.0F;
|
float f7 = (endColor & 255) / 255.0F;
|
||||||
GlStateManager.disableTexture2D();
|
RenderSystem.disableTexture2D();
|
||||||
GlStateManager.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
GlStateManager.disableAlpha();
|
RenderSystem.disableAlpha();
|
||||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
RenderSystem.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||||
GlStateManager.shadeModel(7425);
|
RenderSystem.shadeModel(7425);
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBuffer();
|
||||||
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||||
|
@ -167,73 +162,73 @@ public final class AssetUtil {
|
||||||
renderer.pos(right, bottom, zLevel).color(f5, f6, f7, f4).endVertex();
|
renderer.pos(right, bottom, zLevel).color(f5, f6, f7, f4).endVertex();
|
||||||
renderer.pos(right, top, zLevel).color(f5, f6, f7, f4).endVertex();
|
renderer.pos(right, top, zLevel).color(f5, f6, f7, f4).endVertex();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
GlStateManager.shadeModel(7424);
|
RenderSystem.shadeModel(7424);
|
||||||
GlStateManager.disableBlend();
|
RenderSystem.disableBlend();
|
||||||
GlStateManager.enableAlpha();
|
RenderSystem.enableAlpha();
|
||||||
GlStateManager.enableTexture2D();
|
RenderSystem.enableTexture2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderNameTag(String tag, double x, double y, double z) {
|
public static void renderNameTag(String tag, double x, double y, double z) {
|
||||||
FontRenderer fontrenderer = Minecraft.getMinecraft().fontRenderer;
|
FontRenderer fontrenderer = Minecraft.getInstance().fontRenderer;
|
||||||
float f = 1.6F;
|
float f = 1.6F;
|
||||||
float f1 = 0.016666668F * f;
|
float f1 = 0.016666668F * f;
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
GlStateManager.translate(x, y, z);
|
RenderSystem.translate(x, y, z);
|
||||||
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
|
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
|
||||||
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
|
RenderSystem.rotate(-Minecraft.getInstance().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
|
||||||
GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
|
RenderSystem.rotate(Minecraft.getInstance().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
|
||||||
GlStateManager.scale(-f1, -f1, f1);
|
RenderSystem.scale(-f1, -f1, f1);
|
||||||
GlStateManager.disableLighting();
|
RenderSystem.disableLighting();
|
||||||
GlStateManager.depthMask(false);
|
RenderSystem.depthMask(false);
|
||||||
GlStateManager.disableDepth();
|
RenderSystem.disableDepth();
|
||||||
GlStateManager.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
RenderSystem.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBuffer();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = fontrenderer.getStringWidth(tag) / 2;
|
int j = fontrenderer.getStringWidth(tag) / 2;
|
||||||
GlStateManager.disableTexture2D();
|
RenderSystem.disableTexture2D();
|
||||||
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
renderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||||
renderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
renderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||||
renderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
renderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||||
renderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
renderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||||
renderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
renderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
GlStateManager.enableTexture2D();
|
RenderSystem.enableTexture2D();
|
||||||
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, 553648127);
|
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, 553648127);
|
||||||
GlStateManager.enableDepth();
|
RenderSystem.enableDepth();
|
||||||
GlStateManager.depthMask(true);
|
RenderSystem.depthMask(true);
|
||||||
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, -1);
|
fontrenderer.drawString(tag, -fontrenderer.getStringWidth(tag) / 2, i, -1);
|
||||||
GlStateManager.enableLighting();
|
RenderSystem.enableLighting();
|
||||||
GlStateManager.disableBlend();
|
RenderSystem.disableBlend();
|
||||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
RenderSystem.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spawnLaserWithTimeServer(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
public static void spawnLaserWithTimeServer(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
NBTTagCompound data = new NBTTagCompound();
|
CompoundNBT data = new CompoundNBT();
|
||||||
data.setDouble("StartX", startX);
|
data.putDouble("StartX", startX);
|
||||||
data.setDouble("StartY", startY);
|
data.putDouble("StartY", startY);
|
||||||
data.setDouble("StartZ", startZ);
|
data.putDouble("StartZ", startZ);
|
||||||
data.setDouble("EndX", endX);
|
data.putDouble("EndX", endX);
|
||||||
data.setDouble("EndY", endY);
|
data.putDouble("EndY", endY);
|
||||||
data.setDouble("EndZ", endZ);
|
data.putDouble("EndZ", endZ);
|
||||||
data.setFloat("Color1", color[0]);
|
data.putFloat("Color1", color[0]);
|
||||||
data.setFloat("Color2", color[1]);
|
data.putFloat("Color2", color[1]);
|
||||||
data.setFloat("Color3", color[2]);
|
data.putFloat("Color3", color[2]);
|
||||||
data.setDouble("RotationTime", rotationTime);
|
data.putDouble("RotationTime", rotationTime);
|
||||||
data.setFloat("Size", size);
|
data.putFloat("Size", size);
|
||||||
data.setInteger("MaxAge", maxAge);
|
data.putInt("MaxAge", maxAge);
|
||||||
data.setFloat("Alpha", alpha);
|
data.putFloat("Alpha", alpha);
|
||||||
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
|
PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.LASER_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha) {
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Minecraft mc = Minecraft.getInstance();
|
||||||
|
|
||||||
if (mc.player.getDistance(startX, startY, startZ) <= 64 || mc.player.getDistance(endX, endY, endZ) <= 64) {
|
if (mc.player.getDistance(startX, startY, startZ) <= 64 || mc.player.getDistance(endX, endY, endZ) <= 64) {
|
||||||
Particle fx = new ParticleBeam(mc.world, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha);
|
Particle fx = new ParticleBeam(mc.world, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha);
|
||||||
|
@ -243,11 +238,11 @@ public final class AssetUtil {
|
||||||
|
|
||||||
//Thanks to feldim2425 for this.
|
//Thanks to feldim2425 for this.
|
||||||
//I can't do rendering code. Ever.
|
//I can't do rendering code. Ever.
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderLaser(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, double rotationTime, float alpha, double beamWidth, float[] color) {
|
public static void renderLaser(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ, double rotationTime, float alpha, double beamWidth, float[] color) {
|
||||||
Tessellator tessy = Tessellator.getInstance();
|
Tessellator tessy = Tessellator.getInstance();
|
||||||
BufferBuilder render = tessy.getBuffer();
|
BufferBuilder render = tessy.getBuffer();
|
||||||
World world = Minecraft.getMinecraft().world;
|
World world = Minecraft.getInstance().world;
|
||||||
|
|
||||||
float r = color[0];
|
float r = color[0];
|
||||||
float g = color[1];
|
float g = color[1];
|
||||||
|
@ -263,22 +258,22 @@ public final class AssetUtil {
|
||||||
|
|
||||||
double length = combinedVec.length();
|
double length = combinedVec.length();
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
|
|
||||||
GlStateManager.disableLighting();
|
RenderSystem.disableLighting();
|
||||||
GlStateManager.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE);
|
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE);
|
||||||
int func = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
|
int func = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
|
||||||
float ref = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
|
float ref = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
|
||||||
GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
|
RenderSystem.alphaFunc(GL11.GL_ALWAYS, 0);
|
||||||
GlStateManager.translate(firstX - TileEntityRendererDispatcher.staticPlayerX, firstY - TileEntityRendererDispatcher.staticPlayerY, firstZ - TileEntityRendererDispatcher.staticPlayerZ);
|
RenderSystem.translate(firstX - TileEntityRendererDispatcher.staticPlayerX, firstY - TileEntityRendererDispatcher.staticPlayerY, firstZ - TileEntityRendererDispatcher.staticPlayerZ);
|
||||||
GlStateManager.rotate((float) (180 * yaw / Math.PI), 0, 1, 0);
|
RenderSystem.rotate((float) (180 * yaw / Math.PI), 0, 1, 0);
|
||||||
GlStateManager.rotate((float) (180 * pitch / Math.PI), 0, 0, 1);
|
RenderSystem.rotate((float) (180 * pitch / Math.PI), 0, 0, 1);
|
||||||
GlStateManager.rotate((float) rot, 1, 0, 0);
|
RenderSystem.rotate((float) rot, 1, 0, 0);
|
||||||
|
|
||||||
/*if(r != r2 || g != g2 || b != b2){
|
/*if(r != r2 || g != g2 || b != b2){
|
||||||
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(ClientUtil.LIGHT_BEAM_GRADIENT);
|
Minecraft.getInstance().renderEngine.bindTexture(ClientUtil.LIGHT_BEAM_GRADIENT);
|
||||||
|
|
||||||
render.pos(length, -beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
render.pos(length, -beamWidth, beamWidth).tex(0, 0).color(r, g, b, alpha).endVertex();
|
||||||
render.pos(length, beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
render.pos(length, beamWidth, beamWidth).tex(0, 1).color(r, g, b, alpha).endVertex();
|
||||||
|
@ -322,7 +317,7 @@ public final class AssetUtil {
|
||||||
tessy.draw();
|
tessy.draw();
|
||||||
}
|
}
|
||||||
else{*/
|
else{*/
|
||||||
GlStateManager.disableTexture2D();
|
RenderSystem.disableTexture2D();
|
||||||
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
|
render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
|
||||||
for (double i = 0; i < 4; i++) {
|
for (double i = 0; i < 4; i++) {
|
||||||
double width = beamWidth * (i / 4.0);
|
double width = beamWidth * (i / 4.0);
|
||||||
|
@ -348,14 +343,14 @@ public final class AssetUtil {
|
||||||
}
|
}
|
||||||
tessy.draw();
|
tessy.draw();
|
||||||
|
|
||||||
GlStateManager.enableTexture2D();
|
RenderSystem.enableTexture2D();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
GlStateManager.alphaFunc(func, ref);
|
RenderSystem.alphaFunc(func, ref);
|
||||||
GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||||
GlStateManager.disableBlend();
|
RenderSystem.disableBlend();
|
||||||
GlStateManager.enableLighting();
|
RenderSystem.enableLighting();
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float[] getWheelColor(float pos) {
|
public static float[] getWheelColor(float pos) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.world.storage.loot.LootContext;
|
import net.minecraft.world.storage.loot.LootContext;
|
||||||
import net.minecraft.world.storage.loot.LootTable;
|
import net.minecraft.world.storage.loot.LootTable;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
|
import net.minecraftforge.fml.loading.FMLLoader;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||||
|
|
||||||
//This is stuff copied from somewhere in vanilla and changed so that it works properly
|
//This is stuff copied from somewhere in vanilla and changed so that it works properly
|
||||||
|
@ -52,7 +53,7 @@ public final class AwfulUtil {
|
||||||
while (someInt > 0 && list.size() > 0) {
|
while (someInt > 0 && list.size() > 0) {
|
||||||
ItemStack itemstack2 = list.remove(MathHelper.getInt(rand, 0, list.size() - 1));
|
ItemStack itemstack2 = list.remove(MathHelper.getInt(rand, 0, list.size() - 1));
|
||||||
int i = MathHelper.getInt(rand, 1, itemstack2.getCount() / 2);
|
int i = MathHelper.getInt(rand, 1, itemstack2.getCount() / 2);
|
||||||
ItemStack itemstack1 = itemstack2.splitStack(i);
|
ItemStack itemstack1 = itemstack2.split(i);
|
||||||
|
|
||||||
if (itemstack2.getCount() > 1 && rand.nextBoolean()) {
|
if (itemstack2.getCount() > 1 && rand.nextBoolean()) {
|
||||||
list.add(itemstack2);
|
list.add(itemstack2);
|
||||||
|
@ -90,7 +91,7 @@ public final class AwfulUtil {
|
||||||
for (Object k : stuff) {
|
for (Object k : stuff) {
|
||||||
error += "\n" + i++ + ": " + (k == null ? "null" : k.getClass().getSimpleName() + " <- CLASS | INSTANCE -> " + k.toString() + ", ");
|
error += "\n" + i++ + ": " + (k == null ? "null" : k.getClass().getSimpleName() + " <- CLASS | INSTANCE -> " + k.toString() + ", ");
|
||||||
}
|
}
|
||||||
error += "\n" + "The current side is: " + FMLCommonHandler.instance().getEffectiveSide();
|
error += "\n" + "The current side is: " + FMLLoader.getDist();
|
||||||
error += "\n" + "Report this to https://github.com/Ellpeck/ActuallyAdditions/issues";
|
error += "\n" + "Report this to https://github.com/Ellpeck/ActuallyAdditions/issues";
|
||||||
throw new IllegalStateException(error);
|
throw new IllegalStateException(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
|
import net.minecraft.enchantment.Enchantment;
|
||||||
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
||||||
import de.ellpeck.actuallyadditions.common.RegistryHandler;
|
|
||||||
import de.ellpeck.actuallyadditions.common.creative.CreativeTab;
|
|
||||||
import de.ellpeck.actuallyadditions.common.util.compat.IMCHandler;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.enchantment.Enchantment;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.util.EnumHand;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
|
||||||
|
|
||||||
public final class ItemUtil {
|
public final class ItemUtil {
|
||||||
|
|
||||||
|
@ -24,40 +19,40 @@ public final class ItemUtil {
|
||||||
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(name));
|
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // canitzp: should be removed
|
// @Deprecated // canitzp: should be removed
|
||||||
public static void registerBlock(Block block, BlockItemBase itemBlock, String name, boolean addTab) {
|
// public static void registerBlock(Block block, BlockAtomicReconstructor.BlockItem itemBlock, String name, boolean addTab) {
|
||||||
block.setTranslationKey(ActuallyAdditions.MODID + "." + name);
|
// block.setTranslationKey(ActuallyAdditions.MODID + "." + name);
|
||||||
|
//
|
||||||
|
// block.setRegistryName(ActuallyAdditions.MODID, name);
|
||||||
|
// RegistryHandler.BLOCKS_TO_REGISTER.add(block);
|
||||||
|
//
|
||||||
|
// itemBlock.setRegistryName(block.getRegistryName());
|
||||||
|
// RegistryHandler.ITEMS_TO_REGISTER.add(itemBlock);
|
||||||
|
//
|
||||||
|
// block.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
|
||||||
|
//
|
||||||
|
// IMCHandler.doBlockIMC(block);
|
||||||
|
//
|
||||||
|
// if (block instanceof IColorProvidingBlock) {
|
||||||
|
// ActuallyAdditions.PROXY.addColoredBlock(block);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
block.setRegistryName(ActuallyAdditions.MODID, name);
|
// @Deprecated // canitzp: should be removed
|
||||||
RegistryHandler.BLOCKS_TO_REGISTER.add(block);
|
// public static void registerItem(Item item, String name, boolean addTab) {
|
||||||
|
// item.setTranslationKey(ActuallyAdditions.MODID + "." + name);
|
||||||
itemBlock.setRegistryName(block.getRegistryName());
|
//
|
||||||
RegistryHandler.ITEMS_TO_REGISTER.add(itemBlock);
|
// item.setRegistryName(ActuallyAdditions.MODID, name);
|
||||||
|
// RegistryHandler.ITEMS_TO_REGISTER.add(item);
|
||||||
block.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
|
//
|
||||||
|
// item.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
|
||||||
IMCHandler.doBlockIMC(block);
|
//
|
||||||
|
// IMCHandler.doItemIMC(item);
|
||||||
if (block instanceof IColorProvidingBlock) {
|
//
|
||||||
ActuallyAdditions.PROXY.addColoredBlock(block);
|
// if (item instanceof IColorProvidingItem) {
|
||||||
}
|
// ActuallyAdditions.PROXY.addColoredItem(item);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
@Deprecated // canitzp: should be removed
|
|
||||||
public static void registerItem(Item item, String name, boolean addTab) {
|
|
||||||
item.setTranslationKey(ActuallyAdditions.MODID + "." + name);
|
|
||||||
|
|
||||||
item.setRegistryName(ActuallyAdditions.MODID, name);
|
|
||||||
RegistryHandler.ITEMS_TO_REGISTER.add(item);
|
|
||||||
|
|
||||||
item.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
|
|
||||||
|
|
||||||
IMCHandler.doItemIMC(item);
|
|
||||||
|
|
||||||
if (item instanceof IColorProvidingItem) {
|
|
||||||
ActuallyAdditions.PROXY.addColoredItem(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean contains(ItemStack[] array, ItemStack stack, boolean checkWildcard) {
|
public static boolean contains(ItemStack[] array, ItemStack stack, boolean checkWildcard) {
|
||||||
return getPlaceAt(array, stack, checkWildcard) != -1;
|
return getPlaceAt(array, stack, checkWildcard) != -1;
|
||||||
|
@ -77,7 +72,8 @@ public final class ItemUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2, boolean checkWildcard) {
|
public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2, boolean checkWildcard) {
|
||||||
return StackUtil.isValid(stack1) && StackUtil.isValid(stack2) && (stack1.isItemEqual(stack2) || checkWildcard && stack1.getItem() == stack2.getItem() && (stack1.getItemDamage() == Util.WILDCARD || stack2.getItemDamage() == Util.WILDCARD));
|
// todo: fix wildcard
|
||||||
|
return StackUtil.isValid(stack1) && StackUtil.isValid(stack2) && (stack1.isItemEqual(stack2) || checkWildcard && stack1.getItem() == stack2.getItem() && (stack1.getDamage() == Util.WILDCARD || stack2.getDamage() == Util.WILDCARD));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,29 +90,14 @@ public final class ItemUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasEnchantment(ItemStack stack, Enchantment e) {
|
public static boolean hasEnchantment(ItemStack stack, Enchantment e) {
|
||||||
NBTTagList ench = stack.getEnchantmentTagList();
|
return EnchantmentHelper.getEnchantments(stack).containsKey(e);
|
||||||
if (ench != null) {
|
|
||||||
for (int i = 0; i < ench.tagCount(); i++) {
|
|
||||||
short id = ench.getCompoundTagAt(i).getShort("id");
|
|
||||||
if (id == Enchantment.getEnchantmentID(e)) { return true; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeEnchantment(ItemStack stack, Enchantment e) {
|
public static void removeEnchantment(ItemStack stack, Enchantment e) {
|
||||||
NBTTagList ench = stack.getEnchantmentTagList();
|
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
|
||||||
if (ench != null) {
|
enchantments.remove(e);
|
||||||
for (int i = 0; i < ench.tagCount(); i++) {
|
|
||||||
short id = ench.getCompoundTagAt(i).getShort("id");
|
EnchantmentHelper.setEnchantments(enchantments, stack);
|
||||||
if (id == Enchantment.getEnchantmentID(e)) {
|
|
||||||
ench.removeTag(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ench.isEmpty() && stack.hasTagCompound()) {
|
|
||||||
stack.getTagCompound().removeTag("ench");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canBeStacked(ItemStack stack1, ItemStack stack2) {
|
public static boolean canBeStacked(ItemStack stack1, ItemStack stack2) {
|
||||||
|
@ -124,19 +105,15 @@ public final class ItemUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEnabled(ItemStack stack) {
|
public static boolean isEnabled(ItemStack stack) {
|
||||||
return stack.hasTagCompound() && stack.getTagCompound().getBoolean("IsEnabled");
|
return stack.getOrCreateTag().getBoolean("IsEnabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void changeEnabled(EntityPlayer player, EnumHand hand) {
|
public static void changeEnabled(PlayerEntity player, Hand hand) {
|
||||||
changeEnabled(player.getHeldItem(hand));
|
changeEnabled(player.getHeldItem(hand));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void changeEnabled(ItemStack stack) {
|
public static void changeEnabled(ItemStack stack) {
|
||||||
if (!stack.hasTagCompound()) {
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isEnabled = isEnabled(stack);
|
boolean isEnabled = isEnabled(stack);
|
||||||
stack.getTagCompound().setBoolean("IsEnabled", !isEnabled);
|
stack.getOrCreateTag().putBoolean("IsEnabled", !isEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
|
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
|
||||||
|
import de.ellpeck.actuallyadditions.common.recipes.CrusherRecipe;
|
||||||
import de.ellpeck.actuallyadditions.common.util.crafting.RecipeHandler;
|
import de.ellpeck.actuallyadditions.common.util.crafting.RecipeHandler;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class RecipeUtil {
|
public final class RecipeUtil {
|
||||||
|
|
||||||
public static LensConversionRecipe lastReconstructorRecipe() {
|
public static LensConversionRecipe lastReconstructorRecipe() {
|
||||||
|
|
|
@ -1,20 +1,17 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
|
import com.google.common.base.MoreObjects;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import net.minecraftforge.fml.loading.FMLEnvironment;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
|
|
||||||
|
|
||||||
public class RefHelp {
|
public class RefHelp {
|
||||||
|
|
||||||
public static class UnableToFindMethodException extends RuntimeException {
|
public static class UnableToFindMethodException extends RuntimeException {
|
||||||
|
@ -86,7 +83,7 @@ public class RefHelp {
|
||||||
Preconditions.checkNotNull(clazz);
|
Preconditions.checkNotNull(clazz);
|
||||||
Preconditions.checkArgument(StringUtils.isNotEmpty(fieldName), "Field name cannot be empty");
|
Preconditions.checkArgument(StringUtils.isNotEmpty(fieldName), "Field name cannot be empty");
|
||||||
|
|
||||||
String nameToFind = FMLLaunchHandler.isDeobfuscatedEnvironment() ? fieldName : MoreObjects.firstNonNull(fieldObfName, fieldName);
|
String nameToFind = !FMLEnvironment.production ? fieldName : MoreObjects.firstNonNull(fieldObfName, fieldName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Field f = clazz.getDeclaredField(nameToFind);
|
Field f = clazz.getDeclaredField(nameToFind);
|
||||||
|
@ -184,7 +181,7 @@ public class RefHelp {
|
||||||
Preconditions.checkNotNull(clazz);
|
Preconditions.checkNotNull(clazz);
|
||||||
Preconditions.checkArgument(StringUtils.isNotEmpty(methodName), "Method name cannot be empty");
|
Preconditions.checkArgument(StringUtils.isNotEmpty(methodName), "Method name cannot be empty");
|
||||||
|
|
||||||
String nameToFind = FMLLaunchHandler.isDeobfuscatedEnvironment() ? methodName : MoreObjects.firstNonNull(methodObfName, methodName);
|
String nameToFind = !FMLEnvironment.production ? methodName : MoreObjects.firstNonNull(methodObfName, methodName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Method m = clazz.getDeclaredMethod(nameToFind, parameterTypes);
|
Method m = clazz.getDeclaredMethod(nameToFind, parameterTypes);
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
|
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
|
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.common.util.compat.SlotlessableItemHandlerWrapper;
|
import de.ellpeck.actuallyadditions.common.util.compat.SlotlessableItemHandlerWrapper;
|
||||||
|
@ -13,6 +8,9 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class StackUtil {
|
public final class StackUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,10 +181,11 @@ public final class StackUtil {
|
||||||
|
|
||||||
if (ActuallyAdditions.commonCapsLoaded) {
|
if (ActuallyAdditions.commonCapsLoaded) {
|
||||||
Object handler = wrapper.getSlotlessHandler();
|
Object handler = wrapper.getSlotlessHandler();
|
||||||
if (handler instanceof ISlotlessItemHandler) {
|
// todo: reimplement?
|
||||||
remain = ((ISlotlessItemHandler) handler).insertItem(remain, simulate);
|
// if (handler instanceof ISlotlessItemHandler) {
|
||||||
if (!ItemStack.areItemStacksEqual(remain, stack)) return remain;
|
// remain = ((ISlotlessItemHandler) handler).insertItem(remain, simulate);
|
||||||
}
|
// if (!ItemStack.areItemStacksEqual(remain, stack)) return remain;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
IItemHandler handler = wrapper.getNormalHandler();
|
IItemHandler handler = wrapper.getNormalHandler();
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import net.minecraft.util.text.LanguageMap;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.util.text.translation.LanguageMap;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
|
|
||||||
public final class StringUtil {
|
public final class StringUtil {
|
||||||
|
|
||||||
public static final int DECIMAL_COLOR_WHITE = 16777215;
|
public static final int DECIMAL_COLOR_WHITE = 16777215;
|
||||||
|
@ -22,7 +22,7 @@ public final class StringUtil {
|
||||||
/**
|
/**
|
||||||
* Localizes a given String
|
* Localizes a given String
|
||||||
*/
|
*/
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static String localize(String text) {
|
public static String localize(String text) {
|
||||||
return I18n.format(text);
|
return I18n.format(text);
|
||||||
}
|
}
|
||||||
|
@ -30,39 +30,50 @@ public final class StringUtil {
|
||||||
/**
|
/**
|
||||||
* Localizes a given formatted String with the given Replacements
|
* Localizes a given formatted String with the given Replacements
|
||||||
*/
|
*/
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static String localizeFormatted(String text, Object... replace) {
|
public static String localizeFormatted(String text, Object... replace) {
|
||||||
return I18n.format(text, replace);
|
return I18n.format(text, replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") //TODO: delete this shit and move ItemPotionRing's getItemStackDisplayName into getUnlocalizedName
|
// @SuppressWarnings("deprecation") //TODO: delete this shit and move ItemPotionRing's getItemStackDisplayName into getUnlocalizedName
|
||||||
public static String localizeIllegallyOnTheServerDontUseMePls(String langKey) {
|
// public static String localizeIllegallyOnTheServerDontUseMePls(String langKey) {
|
||||||
return net.minecraft.util.text.translation.I18n.translateToLocal(langKey);
|
// return net.minecraft.util.text.translation.I18n.translateToLocal(langKey);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void drawSplitString(FontRenderer renderer, String strg, int x, int y, int width, int color, boolean shadow) {
|
public static void drawSplitString(FontRenderer renderer, String strg, int x, int y, int width, int color, boolean shadow) {
|
||||||
List<String> list = renderer.listFormattedStringToWidth(strg, width);
|
List<String> list = renderer.listFormattedStringToWidth(strg, width);
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
String s1 = list.get(i);
|
String s1 = list.get(i);
|
||||||
renderer.drawString(s1, x, y + i * renderer.FONT_HEIGHT, color, shadow);
|
if (shadow) {
|
||||||
|
renderer.drawStringWithShadow(s1, x, y + i * renderer.FONT_HEIGHT, color);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
renderer.drawString(s1, x, y + i * renderer.FONT_HEIGHT, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderScaledAsciiString(FontRenderer font, String text, float x, float y, int color, boolean shadow, float scale) {
|
public static void renderScaledAsciiString(FontRenderer font, String text, float x, float y, int color, boolean shadow, float scale) {
|
||||||
GlStateManager.pushMatrix();
|
RenderSystem.pushMatrix();
|
||||||
GlStateManager.scale(scale, scale, scale);
|
RenderSystem.scalef(scale, scale, scale);
|
||||||
boolean oldUnicode = font.getUnicodeFlag();
|
// todo: validate
|
||||||
font.setUnicodeFlag(false);
|
// boolean oldUnicode = font.getUnicodeFlag();
|
||||||
|
// font.setUnicodeFlag(false);
|
||||||
|
|
||||||
font.drawString(text, x / scale, y / scale, color, shadow);
|
if (shadow) {
|
||||||
|
font.drawStringWithShadow(text, x / scale, y / scale, color);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
font.drawString(text, x / scale, y / scale, color);
|
||||||
|
}
|
||||||
|
|
||||||
font.setUnicodeFlag(oldUnicode);
|
// font.setUnicodeFlag(oldUnicode);
|
||||||
GlStateManager.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public static void renderSplitScaledAsciiString(FontRenderer font, String text, int x, int y, int color, boolean shadow, float scale, int length) {
|
public static void renderSplitScaledAsciiString(FontRenderer font, String text, int x, int y, int color, boolean shadow, float scale, int length) {
|
||||||
List<String> lines = font.listFormattedStringToWidth(text, (int) (length / scale));
|
List<String> lines = font.listFormattedStringToWidth(text, (int) (length / scale));
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDevVersion() {
|
public static boolean isDevVersion() {
|
||||||
return ActuallyAdditions.VERSION.equals("@VERSION@");
|
return false; // ActuallyAdditions.VERSION.equals("@VERSION@"); //todo: reimplement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated // canitzp: should not be used and removed asap
|
@Deprecated // canitzp: should not be used and removed asap
|
||||||
|
@ -33,7 +33,7 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] splitVersion() {
|
private static String[] splitVersion() {
|
||||||
return ActuallyAdditions.VERSION.split("-");
|
return "1-1".split("-"); // ActuallyAdditions.VERSION.split("-"); todo: implement
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMcVersion() {
|
public static String getMcVersion() {
|
||||||
|
|
|
@ -1,24 +1,22 @@
|
||||||
package de.ellpeck.actuallyadditions.common.util;
|
package de.ellpeck.actuallyadditions.common.util;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.server.management.PlayerChunkMapEntry;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
|
|
||||||
public final class VanillaPacketDispatcher {
|
public final class VanillaPacketDispatcher {
|
||||||
|
|
||||||
//Don't call from the client.
|
//Don't call from the client.
|
||||||
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
|
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
|
||||||
WorldServer world = (WorldServer) tile.getWorld();
|
ServerWorld world = (ServerWorld) tile.getWorld();
|
||||||
PlayerChunkMapEntry entry = world.getPlayerChunkMap().getEntry(tile.getPos().getX() >> 4, tile.getPos().getZ() >> 4);
|
PlayerChunkMapEntry entry = world.getPlayerChunkMap().getEntry(tile.getPos().getX() >> 4, tile.getPos().getZ() >> 4);
|
||||||
|
|
||||||
if (entry == null) return;
|
if (entry == null) return;
|
||||||
|
|
||||||
for (EntityPlayerMP player : entry.getWatchingPlayers())
|
for (ServerPlayerEntity player : entry.getWatchingPlayers())
|
||||||
player.connection.sendPacket(tile.getUpdatePacket());
|
player.connection.sendPacket(tile.getUpdatePacket());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
|
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
|
||||||
|
|
Loading…
Reference in a new issue