From f1640ff21baf96f843d8cc7d4619c71050fc8b04 Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Mon, 10 Apr 2017 19:19:19 +0200 Subject: [PATCH] Work on MultiFence --- .../binnie/core/models/AABBModelBaker.java | 16 ++- .../java/binnie/core/models/ModelManager.java | 70 ++++------- .../binnie/extratrees/block/WoodManager.java | 8 +- .../block/decor/ModelMultiFence.java | 119 +++++++++++++++--- .../block/decor/MultiFenceRecipeEmbedded.java | 2 +- .../block/decor/MultiFenceRecipePattern.java | 36 ++++++ .../block/decor/MultiFenceRecipeSize.java | 52 +++----- .../machines/craftgui/PagePlanksOverview.java | 2 +- 8 files changed, 200 insertions(+), 105 deletions(-) create mode 100644 src/main/java/binnie/extratrees/block/decor/MultiFenceRecipePattern.java diff --git a/src/main/java/binnie/core/models/AABBModelBaker.java b/src/main/java/binnie/core/models/AABBModelBaker.java index b5be0b93..f0bfb63a 100644 --- a/src/main/java/binnie/core/models/AABBModelBaker.java +++ b/src/main/java/binnie/core/models/AABBModelBaker.java @@ -105,7 +105,7 @@ public class AABBModelBaker implements IModelBaker { } } - protected float[] getFaceUvs(final EnumFacing face, final Vector3f to, final Vector3f from) { + protected float[] getFaceUvs(EnumFacing face, Vector3f to, Vector3f from) { float minU; float minV; float maxU; @@ -153,14 +153,22 @@ public class AABBModelBaker implements IModelBaker { maxV = to.z; break; } - default:{ - minU= 6; + default: { + minU = 0; minV = 0; - maxU= 10; + maxU = 16; maxV = 16; break; } } + if (minU < 0 || maxU > 16) { + minU = 0; + maxU = 16; + } + if (minV < 0 || maxV > 16) { + minV = 0; + maxV = 16; + } minU = 16 - minU; minV = 16 - minV; maxU = 16 - maxU; diff --git a/src/main/java/binnie/core/models/ModelManager.java b/src/main/java/binnie/core/models/ModelManager.java index d87a958d..fa70f56b 100644 --- a/src/main/java/binnie/core/models/ModelManager.java +++ b/src/main/java/binnie/core/models/ModelManager.java @@ -1,6 +1,8 @@ package binnie.core.models; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import forestry.api.core.ForestryAPI; import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; @@ -10,6 +12,7 @@ import forestry.core.blocks.IColoredBlock; import forestry.core.items.IColoredItem; import forestry.core.models.BlockModelEntry; import forestry.core.models.ModelEntry; +import forestry.core.utils.ModelUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -28,16 +31,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.IRegistry; import net.minecraft.world.IBlockAccess; import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.model.IPerspectiveAwareModel; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.SimpleModelState; import net.minecraftforge.common.model.IModelState; import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; - -import javax.vecmath.Vector3f; import java.util.ArrayList; import java.util.List; +import java.util.Map; @SideOnly(Side.CLIENT) public class ModelManager implements IModelManager { @@ -53,56 +56,10 @@ public class ModelManager implements IModelManager { private final List itemColorList = new ArrayList<>(); private final static List spriteRegister = new ArrayList<>(); - private TRSRTransformation flipX = new TRSRTransformation(null, null, new Vector3f(-1, 1, 1), null); - public final IModelState DEFAULT_BLOCK; - public final IModelState DEFAULT_ITEM; - public final IModelState DEFAULT_TOOL; + public static IModelState defaultFenceState; public ModelManager(String modID) { this.modID = modID; - - TRSRTransformation blockThirdperson = get(0, 2.5f, 0, 75, 45, 0, 0.375f); - ImmutableMap.Builder blockBuilder = ImmutableMap.builder(); - blockBuilder.put(TransformType.GUI, get(0, 0, 0, 30, 225, 0, 0.625f)); - blockBuilder.put(TransformType.GROUND, get(0, 3, 0, 0, 0, 0, 0.25f)); - blockBuilder.put(TransformType.FIXED, get(0, 0, 0, 0, 0, 0, 0.5f)); - blockBuilder.put(TransformType.THIRD_PERSON_RIGHT_HAND, blockThirdperson); - blockBuilder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(blockThirdperson)); - blockBuilder.put(TransformType.FIRST_PERSON_RIGHT_HAND, get(0, 0, 0, 0, 45, 0, 0.4f)); - blockBuilder.put(TransformType.FIRST_PERSON_LEFT_HAND, get(0, 0, 0, 0, 225, 0, 0.4f)); - DEFAULT_BLOCK = new SimpleModelState(blockBuilder.build()); - - TRSRTransformation itemThirdperson = get(0, 3, 1, 0, 0, 0, 0.55f); - TRSRTransformation firstperson = get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f); - ImmutableMap.Builder itemBuilder = ImmutableMap.builder(); - itemBuilder.put(TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f)); - itemBuilder.put(TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1)); - itemBuilder.put(TransformType.THIRD_PERSON_RIGHT_HAND, itemThirdperson); - itemBuilder.put(TransformType.THIRD_PERSON_LEFT_HAND, leftify(itemThirdperson)); - itemBuilder.put(TransformType.FIRST_PERSON_RIGHT_HAND, firstperson); - itemBuilder.put(TransformType.FIRST_PERSON_LEFT_HAND, leftify(firstperson)); - DEFAULT_ITEM = new SimpleModelState(itemBuilder.build()); - - DEFAULT_TOOL = new SimpleModelState(ImmutableMap.of( - TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f), - TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f), - TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f), - TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))); - } - - private TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s) { - return TRSRTransformation.blockCenterToCorner(new TRSRTransformation( - new Vector3f(tx / 16, ty / 16, tz / 16), - TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)), - new Vector3f(s, s, s), - null)); - } - - private TRSRTransformation leftify(TRSRTransformation transform) { - if (flipX == null) { - flipX = new TRSRTransformation(null, null, new Vector3f(-1, 1, 1), null); - } - return TRSRTransformation.blockCenterToCorner(flipX.compose(TRSRTransformation.blockCornerToCenter(transform)).compose(flipX)); } @Override @@ -141,6 +98,10 @@ public class ModelManager implements IModelManager { return new ModelResourceLocation(new ResourceLocation(modID, identifier), "inventory"); } + public static IModelState getDefaultFenceState() { + return defaultFenceState; + } + @SideOnly(Side.CLIENT) public void registerBlockClient(Block block) { if (block instanceof IItemModelRegister) { @@ -266,6 +227,17 @@ public class ModelManager implements IModelManager { for (final ModelEntry entry : customModels) { registry.putObject(entry.modelLocation, entry.model); } + IModelState defaultBlockState = ModelUtil.loadModelState(new ResourceLocation("minecraft:models/block/block")); + IModelState defaultFenceState = ModelUtil.loadModelState(new ResourceLocation("minecraft:models/block/fence_inventory")); + ModelManager.defaultFenceState = mergeStates(defaultBlockState, defaultFenceState); + } + + private static IModelState mergeStates(IModelState state, IModelState secondaryState){ + Map tMap = Maps.newHashMap(); + TRSRTransformation guiTransformation = secondaryState.apply(Optional.of(TransformType.GUI)).get(); + tMap.putAll(IPerspectiveAwareModel.MapWrapper.getTransforms(state)); + tMap.put(TransformType.GUI, guiTransformation); + return new SimpleModelState(ImmutableMap.copyOf(tMap)); } public static void registerCustomBlockModel(BlockModelEntry index) { diff --git a/src/main/java/binnie/extratrees/block/WoodManager.java b/src/main/java/binnie/extratrees/block/WoodManager.java index 26c25710..217ac6d2 100644 --- a/src/main/java/binnie/extratrees/block/WoodManager.java +++ b/src/main/java/binnie/extratrees/block/WoodManager.java @@ -122,7 +122,7 @@ public class WoodManager { } public static List getAllPlankTypes() { - final List list = new ArrayList<>(); + List list = new ArrayList<>(); Collections.addAll(list, PlankType.ExtraTreePlanks.values()); Collections.addAll(list, PlankType.ForestryPlanks.values()); //TODO: extrabiomes 1.10.2 @@ -136,9 +136,9 @@ public class WoodManager { } @Nullable - public static IPlankType get(final ItemStack species) { - for (final IPlankType type : getAllPlankTypes()) { - if (type.getStack().isItemEqual(species)) { + public static IPlankType getPlankType(ItemStack itemStack) { + for (IPlankType type : getAllPlankTypes()) { + if (type.getStack(false).isItemEqual(itemStack)) { return type; } } diff --git a/src/main/java/binnie/extratrees/block/decor/ModelMultiFence.java b/src/main/java/binnie/extratrees/block/decor/ModelMultiFence.java index 89db5392..ff03903b 100644 --- a/src/main/java/binnie/extratrees/block/decor/ModelMultiFence.java +++ b/src/main/java/binnie/extratrees/block/decor/ModelMultiFence.java @@ -2,6 +2,7 @@ package binnie.extratrees.block.decor; import binnie.core.block.TileEntityMetadata; import binnie.core.models.AABBModelBaker; +import binnie.core.models.ModelManager; import binnie.extratrees.ExtraTrees; import binnie.extratrees.block.WoodManager; import forestry.api.core.IModelBaker; @@ -9,10 +10,10 @@ import forestry.core.blocks.properties.UnlistedBlockAccess; import forestry.core.blocks.properties.UnlistedBlockPos; import forestry.core.models.ModelBlockDefault; import net.minecraft.block.Block; +import net.minecraft.block.BlockFence; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; @@ -42,7 +43,7 @@ public class ModelMultiFence extends ModelBlockDefault types = new ArrayList<>(); + String recipePattern = ""; + List types = new ArrayList<>(); for (int i = 0; i < inv.getSizeInventory(); ++i) { - final ItemStack stack = inv.getStackInSlot(i); - final IPlankType type = (stack.isEmpty()) ? null : WoodManager.get(stack); - if (!stack.isEmpty() && type == null) { + ItemStack stack = inv.getStackInSlot(i); + boolean isEmpty = stack.isEmpty(); + IPlankType type = isEmpty ? null : WoodManager.getPlankType(stack); + if (!isEmpty && type == null) { return false; } - if (stack.isEmpty()) { - pattern += " "; + if (isEmpty) { + recipePattern += " "; } else { if (!types.contains(type)) { types.add(type); @@ -35,28 +38,20 @@ public class MultiFenceRecipeSize implements IRecipe { return false; } } - pattern += types.indexOf(type); + recipePattern += types.indexOf(type); } } if (types.isEmpty()) { return false; } - ItemStack fence = ItemStack.EMPTY; - if (pattern.contains("0100 0 ")) { - fence = WoodManager.getFence(types.get(0), types.get(1), new FenceType(0, false, false), 4); - } else if (pattern.contains("0000 0 ")) { - fence = WoodManager.getFence(types.get(0), types.get(0), new FenceType(0, false, false), 4); - } else if (pattern.contains("0100 0 1 ")) { - fence = WoodManager.getFence(types.get(0), types.get(1), new FenceType(1, false, false), 4); - } else if (pattern.contains("0000 0 0 ")) { - fence = WoodManager.getFence(types.get(0), types.get(0), new FenceType(1, false, false), 4); - } else if (pattern.contains(" 0 1 1101")) { - fence = WoodManager.getFence(types.get(1), types.get(0), new FenceType(2, false, false), 4); - } else if (pattern.contains(" 0 0 0000")) { - fence = WoodManager.getFence(types.get(0), types.get(0), new FenceType(2, false, false), 4); + for(MultiFenceRecipePattern pattern : MultiFenceRecipePattern.VALUES){ + if(pattern.matches(recipePattern)){ + cached = pattern.createFence(types.get(0), types.get(1)); + return true; + } } - this.cached = fence; - return !fence.isEmpty(); + this.cached = ItemStack.EMPTY; + return false; } @Override @@ -74,13 +69,6 @@ public class MultiFenceRecipeSize implements IRecipe { return (this.cached.isEmpty()) ? new ItemStack(Blocks.OAK_FENCE) : this.cached; } - // TODO: what is this? - public static void generateTypes() { - final int type = 0; - for (int type2 = 0; type2 < 2; ++type2) { - } - } - @Override public NonNullList getRemainingItems(InventoryCrafting inv) { return ForgeHooks.defaultRecipeGetRemainingItems(inv); diff --git a/src/main/java/binnie/extratrees/machines/craftgui/PagePlanksOverview.java b/src/main/java/binnie/extratrees/machines/craftgui/PagePlanksOverview.java index 3615fc89..1590dc2d 100644 --- a/src/main/java/binnie/extratrees/machines/craftgui/PagePlanksOverview.java +++ b/src/main/java/binnie/extratrees/machines/craftgui/PagePlanksOverview.java @@ -30,7 +30,7 @@ public class PagePlanksOverview extends PageAbstract { final WindowAbstractDatabase database = Window.get(this); new ControlText(this, new Area(0, 0, this.size().x(), 24), species.getDisplayName(), TextJustification.MiddleCenter); new ControlText(this, new Area(12, 24, this.size().x() - 24, 24), ExtraTrees.proxy.localise("gui.database.planks.use"), TextJustification.MIDDLE_LEFTt); - final IPlankType type = WoodManager.get(species); + final IPlankType type = WoodManager.getPlankType(species); int x = 12; if (type != null) { final ItemStack fence = WoodManager.getFence(type, new FenceType(0), 1);