Panels can have any texture now, textures are changed by crafting the unfinished panel with the block it should "imitate". Closes #54
ToDo documentation
This commit is contained in:
parent
ceb28da474
commit
63d9fca789
9 changed files with 177 additions and 18 deletions
|
@ -26,6 +26,7 @@ import malte0811.industrialwires.containers.ContainerRenameKey;
|
|||
import malte0811.industrialwires.mech_mb.MechEnergy;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
@ -90,4 +91,8 @@ public class CommonProxy implements IGuiHandler {
|
|||
public boolean isSingleplayer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isValidTextureSource(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemBlock;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ import net.minecraft.nbt.NBTTagList;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
|
@ -140,8 +140,8 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
|
|||
}
|
||||
}
|
||||
components.setHeight(nbt.getFloat("height"));
|
||||
if (nbt.hasKey("texture")) {
|
||||
components.setTexture(new ResourceLocation(nbt.getString("texture")));
|
||||
if (nbt.hasKey("texture", Constants.NBT.TAG_COMPOUND)) {
|
||||
components.setTextureSource(new ItemStack(nbt.getCompoundTag("texture")));
|
||||
}
|
||||
components.setAngle(nbt.getFloat("angle"));
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
|
|||
nbt.setTag("components", comps);
|
||||
nbt.setFloat("height", components.getHeight());
|
||||
nbt.setFloat("angle", components.getAngle());
|
||||
nbt.setString("texture", components.getTexture().toString());
|
||||
nbt.setTag("texture", components.getTextureSource().serializeNBT());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
|
|
@ -115,7 +115,12 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI,
|
|||
}
|
||||
}
|
||||
if (valid) {
|
||||
NBTTagCompound panelNBT = new NBTTagCompound();
|
||||
NBTTagCompound panelNBT;
|
||||
if (inv.hasTagCompound()) {
|
||||
panelNBT = inv.getTagCompound().copy();
|
||||
} else {
|
||||
panelNBT = new NBTTagCompound();
|
||||
}
|
||||
writeToItemNBT(panelNBT, true);
|
||||
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||
panel.setTagCompound(panelNBT);
|
||||
|
|
|
@ -59,6 +59,8 @@ import net.minecraft.client.audio.MovingSound;
|
|||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -457,6 +459,28 @@ public class ClientProxy extends CommonProxy {
|
|||
return Minecraft.getMinecraft().isSingleplayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidTextureSource(ItemStack stack) {
|
||||
if (!super.isValidTextureSource(stack)) {
|
||||
return false;
|
||||
}
|
||||
IBakedModel texModel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(stack,
|
||||
null, null);
|
||||
TextureAtlasSprite sprite = texModel.getParticleTexture();
|
||||
if (sprite.hasAnimationMetadata()) {
|
||||
return false;
|
||||
}
|
||||
int[][] data = sprite.getFrameTextureData(0);
|
||||
for (int x = 0; x < data.length; x++) {
|
||||
for (int y = 0; y < data[x].length; y++) {
|
||||
if ((data[x][y] >>> 24) != 255) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (ID == 0) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import malte0811.industrialwires.client.RawQuad;
|
|||
import malte0811.industrialwires.controlpanel.PropertyComponents.PanelRenderProperties;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
|
@ -62,11 +63,17 @@ public final class PanelUtils {
|
|||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static List<BakedQuad> generateQuads(PanelRenderProperties components) {
|
||||
TextureMap texMap = Minecraft.getMinecraft().getTextureMapBlocks();
|
||||
if (PANEL_TEXTURE == null) {
|
||||
TextureMap texMap = Minecraft.getMinecraft().getTextureMapBlocks();
|
||||
PANEL_TEXTURE = texMap.getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel");
|
||||
}
|
||||
final TextureAtlasSprite mainTex = texMap.getAtlasSprite(components.getTexture().toString());
|
||||
ItemStack source = components.getTextureSource();
|
||||
IBakedModel texModel = null;
|
||||
if (IndustrialWires.proxy.isValidTextureSource(source)) {
|
||||
texModel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(source,
|
||||
null, null);
|
||||
}
|
||||
final TextureAtlasSprite mainTex = texModel != null ? texModel.getParticleTexture() : PANEL_TEXTURE;
|
||||
List<BakedQuad> ret = new ArrayList<>();
|
||||
Matrix4 m4 = components.getPanelTopTransform();
|
||||
Matrix4 m4RotOnly = m4.copy();
|
||||
|
|
|
@ -17,11 +17,13 @@ package malte0811.industrialwires.controlpanel;
|
|||
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import malte0811.industrialwires.IndustrialWires;
|
||||
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
@ -64,7 +66,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
|
|||
private Matrix4 topTransform;
|
||||
private Matrix4 topTransformInverse;
|
||||
private Matrix4 baseTransform;
|
||||
private ResourceLocation texture = new ResourceLocation(IndustrialWires.MODID, "blocks/control_panel");
|
||||
private ItemStack textureSource = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.DUMMY.ordinal());
|
||||
|
||||
|
||||
public PanelRenderProperties() {
|
||||
|
@ -177,7 +179,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
|
|||
ret.facing = facing;
|
||||
ret.top = top;
|
||||
ret.angle = angle;
|
||||
ret.texture = texture;
|
||||
ret.textureSource = textureSource;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -202,12 +204,13 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
|
|||
}
|
||||
}
|
||||
|
||||
public void setTexture(ResourceLocation texture) {
|
||||
this.texture = texture;
|
||||
public void setTextureSource(ItemStack textureSource) {
|
||||
if (textureSource.getItem() instanceof ItemBlock)
|
||||
this.textureSource = textureSource;
|
||||
}
|
||||
|
||||
public ResourceLocation getTexture() {
|
||||
return texture;
|
||||
public ItemStack getTextureSource() {
|
||||
return textureSource;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
|
@ -255,7 +258,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
|
|||
if (Float.compare(that.angle, angle) != 0) return false;
|
||||
if (facing != that.facing) return false;
|
||||
if (top != that.top) return false;
|
||||
return texture.equals(that.texture);
|
||||
return ItemStack.areItemStacksEqual(textureSource, that.textureSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -265,7 +268,6 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
|
|||
result = 31 * result + (height != +0.0f ? Float.floatToIntBits(height) : 0);
|
||||
result = 31 * result + top.hashCode();
|
||||
result = 31 * result + (angle != +0.0f ? Float.floatToIntBits(angle) : 0);
|
||||
result = 31 * result + texture.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> imple
|
|||
boolean found = false;
|
||||
int foundX = -1;
|
||||
int foundY = -1;
|
||||
boolean foundPanel = false;
|
||||
boolean foundPanel;
|
||||
for (int x = 0; x < inv.getWidth(); x++) {
|
||||
for (int y = 0; y < inv.getHeight(); y++) {
|
||||
ItemStack here = inv.getStackInRowAndColumn(x, y);
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* This file is part of Industrial Wires.
|
||||
* Copyright (C) 2016-2018 malte0811
|
||||
* Industrial Wires is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* Industrial Wires is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package malte0811.industrialwires.crafting;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
|
||||
import malte0811.industrialwires.IndustrialWires;
|
||||
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
|
||||
import malte0811.industrialwires.util.NBTKeys;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class RecipePanelTexture extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
||||
@Override
|
||||
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
|
||||
boolean foundTexture = false;
|
||||
boolean foundPanel = false;
|
||||
for (int x = 0; x < inv.getWidth(); x++) {
|
||||
for (int y = 0; y < inv.getHeight(); y++) {
|
||||
ItemStack here = inv.getStackInRowAndColumn(x, y);
|
||||
if (isUnfinishedPanel(here)) {
|
||||
if (foundPanel) {
|
||||
return false;
|
||||
}
|
||||
foundPanel = true;
|
||||
} else if (IndustrialWires.proxy.isValidTextureSource(here)) {
|
||||
if (foundTexture || (here.getItem() == Item.getItemFromBlock(IndustrialWires.panel)
|
||||
&& here.getMetadata() != BlockTypes_Panel.DUMMY.ordinal())) {
|
||||
return false;
|
||||
}
|
||||
foundTexture = true;
|
||||
} else if (!here.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return foundPanel && foundTexture;
|
||||
}
|
||||
|
||||
private boolean isUnfinishedPanel(ItemStack stack) {
|
||||
return stack.getItem() == Item.getItemFromBlock(IndustrialWires.panel)
|
||||
&& stack.getMetadata() == BlockTypes_Panel.UNFINISHED.ordinal();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
|
||||
ItemStack texture = null;
|
||||
ItemStack panel = null;
|
||||
for (int x = 0; x < inv.getWidth(); x++) {
|
||||
for (int y = 0; y < inv.getHeight(); y++) {
|
||||
ItemStack here = inv.getStackInRowAndColumn(x, y);
|
||||
if (isUnfinishedPanel(here)) {
|
||||
panel = here;
|
||||
} else if (IndustrialWires.proxy.isValidTextureSource(here)) {
|
||||
texture = here;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert texture != null && panel != null;
|
||||
NBTTagCompound texAsNBT = texture.serializeNBT();
|
||||
ItemStack ret = panel.copy();
|
||||
if (ret.getTagCompound() == null) {
|
||||
ItemNBTHelper.setFloat(ret, NBTKeys.ANGLE, 0);
|
||||
ItemNBTHelper.setFloat(ret, NBTKeys.HEIGHT, .5F);
|
||||
}
|
||||
ItemNBTHelper.setTagCompound(ret, "texture", texAsNBT);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFit(int width, int height) {
|
||||
return width * height >= 2;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
|
||||
NonNullList<ItemStack> ret = IRecipe.super.getRemainingItems(inv);
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack here = inv.getStackInSlot(i);
|
||||
if (!isUnfinishedPanel(here) && !here.isEmpty()) {
|
||||
ret.set(i, ApiUtils.copyStackWithAmount(here, 1));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ public class Recipes {
|
|||
registry.register(new RecipeKeyRing(true).setRegistryName(MODID, "add_key_ring"));
|
||||
registry.register(new RecipeKeyRing(false).setRegistryName(MODID, "remove_key_ring"));
|
||||
registry.register(new RecipeKeyLock().setRegistryName(MODID, "key_lock"));
|
||||
registry.register(new RecipePanelTexture().setRegistryName(MODID, "panel_texture"));
|
||||
registry.register(new RecipeComponentCopy().setRegistryName(MODID, "component_copy"));
|
||||
AssemblerHandler.registerRecipeAdapter(RecipeCoilLength.class, new Recipes.AllRecipeAdapter<>());
|
||||
AssemblerHandler.registerRecipeAdapter(RecipeComponentCopy.class, new Recipes.AllRecipeAdapter<>());
|
||||
|
@ -55,7 +56,7 @@ public class Recipes {
|
|||
ret.add(new AssemblerHandler.RecipeQuery(in.get(i), 1));
|
||||
}
|
||||
}
|
||||
return ret.toArray(new AssemblerHandler.RecipeQuery[ret.size()]);
|
||||
return ret.toArray(new AssemblerHandler.RecipeQuery[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue