mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-29 00:08:52 +00:00
Work on MultiFence
This commit is contained in:
1 parent
c949131976
commit
f1640ff21b
8 files changed
+200
-105
No files matched your search
@@ -122,7 +122,7 @@ public class WoodManager {
|
||||
}
|
||||
|
||||
public static List<IPlankType> getAllPlankTypes() {
|
||||
final List<IPlankType> list = new ArrayList<>();
|
||||
List<IPlankType> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BlockMultiFence, ModelMul
|
||||
|
||||
@Override
|
||||
protected Key getInventoryKey(ItemStack stack) {
|
||||
return new Key(stack.getItemDamage(), ExtraTrees.blocks().blockMultiFence.getDefaultState());
|
||||
return new Key(TileEntityMetadata.getItemDamage(stack), ExtraTrees.blocks().blockMultiFence.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,14 +51,7 @@ public class ModelMultiFence extends ModelBlockDefault<BlockMultiFence, ModelMul
|
||||
IExtendedBlockState stateExtended = (IExtendedBlockState) state;
|
||||
IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS);
|
||||
BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS);
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
int meta;
|
||||
if(tileEntity instanceof TileEntityMetadata){
|
||||
TileEntityMetadata tileMeta = (TileEntityMetadata) tileEntity;
|
||||
meta = tileMeta.getBlockMetadata();
|
||||
}else{
|
||||
meta = 0;
|
||||
}
|
||||
int meta = TileEntityMetadata.getTileMetadata(world, pos);
|
||||
return new Key(meta, stateExtended);
|
||||
}
|
||||
|
||||
@@ -90,6 +84,7 @@ public class ModelMultiFence extends ModelBlockDefault<BlockMultiFence, ModelMul
|
||||
|
||||
IModelBaker baker = new AABBModelBaker();
|
||||
bakeBlock(bBlock, key, baker, true);
|
||||
baker.setModelState(ModelManager.getDefaultFenceState());
|
||||
|
||||
return itemModel = baker.bakeModel(true);
|
||||
}
|
||||
@@ -98,6 +93,102 @@ public class ModelMultiFence extends ModelBlockDefault<BlockMultiFence, ModelMul
|
||||
@Override
|
||||
protected void bakeBlock(BlockMultiFence block, Key key, IModelBaker baker, boolean inventory) {
|
||||
AABBModelBaker modelBaker = (AABBModelBaker) baker;
|
||||
if(inventory){
|
||||
bakeItemModel(block, modelBaker, key);
|
||||
}else{
|
||||
bakeBlockModel(block, modelBaker, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void bakeItemModel(BlockMultiFence block, AABBModelBaker modelBaker, Key key){
|
||||
int meta = key.meta;
|
||||
FenceType type = key.type;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
final float thickness = 0.125f;
|
||||
boolean secondary = false;
|
||||
if (i == 0) {
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(0.5f - thickness, 0.0f, 0.0f, 0.5f + thickness, 1.0f, thickness * 2.0f));
|
||||
}
|
||||
if (i == 1) {
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(0.5f - thickness, 0.0f, 1.0f - thickness * 2.0f, 0.5f + thickness, 1.0f, 1.0f));
|
||||
}
|
||||
final float s = 0.0625f;
|
||||
final boolean bottomBar = !type.solid;
|
||||
float topBarMaxY = 1.0f - s;
|
||||
float topBarMinY = 1.0f - s * 3.0f;
|
||||
float bottomBarMaxY = 0.5f - s;
|
||||
float bottomBarMinY = 0.5f - s * 3.0f;
|
||||
if (type.size == 2) {
|
||||
bottomBarMinY -= 4.0f * s;
|
||||
bottomBarMaxY -= 4.0f * s;
|
||||
topBarMinY -= 4.0f * s;
|
||||
topBarMaxY -= 4.0f * s;
|
||||
}
|
||||
if (type.size == 1) {
|
||||
bottomBarMinY -= 4.0f * s;
|
||||
bottomBarMaxY -= 4.0f * s;
|
||||
}
|
||||
if (type.solid) {
|
||||
topBarMinY = bottomBarMinY;
|
||||
}
|
||||
float minX = 0.5f - s;
|
||||
float maxX = 0.5f + s;
|
||||
float minZ = -s * 2.0f;
|
||||
float maxZ = 1.0f + s * 2.0f;
|
||||
if (i == 2) {
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(minX, topBarMinY, minZ, maxX, topBarMaxY, maxZ));
|
||||
secondary = true;
|
||||
}
|
||||
if (i == 3) {
|
||||
if (!bottomBar) {
|
||||
continue;
|
||||
}
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(minX, bottomBarMinY, minZ, maxX, bottomBarMaxY, maxZ));
|
||||
secondary = true;
|
||||
}
|
||||
if (i == 4) {
|
||||
if (type.embossed) {
|
||||
minX -= s * 0.9f;
|
||||
maxX += s * 0.9f;
|
||||
minZ -= s;
|
||||
maxZ += s;
|
||||
float minY = 0.0f;
|
||||
float maxY = 1.0f;
|
||||
if (type.size != 1 && !type.solid) {
|
||||
minY = bottomBarMinY + 2.0f * s;
|
||||
maxY = topBarMaxY - 2.0f * s;
|
||||
}
|
||||
else if (type.size == 1 && type.solid) {
|
||||
minY = bottomBarMinY + 2.0f * s;
|
||||
maxY = topBarMaxY - 2.0f * s;
|
||||
}
|
||||
else {
|
||||
minY = 0.5f - 2.0f * s;
|
||||
maxY = 0.5f + 2.0f * s;
|
||||
}
|
||||
if (type.solid && type.size == 0) {
|
||||
minY -= s;
|
||||
maxY -= s;
|
||||
}
|
||||
if (type.solid && type.size == 2) {
|
||||
minY += s;
|
||||
maxY += s;
|
||||
}
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
}
|
||||
else {
|
||||
if (type.size != 1 || type.solid) {
|
||||
continue;
|
||||
}
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(minX, 0.5f - s, minZ, maxX, 0.5f + s, maxZ));
|
||||
secondary = true;
|
||||
}
|
||||
}
|
||||
modelBaker.addBlockModel(null, block.getSprite(meta, secondary), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void bakeBlockModel(BlockMultiFence block, AABBModelBaker modelBaker, Key key){
|
||||
float minPostPos = 0.5f - POST_WIDGTH / 2.0f;
|
||||
float maxPostPos = 0.5f + POST_WIDGTH / 2.0f;
|
||||
IBlockState state = key.state;
|
||||
@@ -107,10 +198,10 @@ public class ModelMultiFence extends ModelBlockDefault<BlockMultiFence, ModelMul
|
||||
modelBaker.setModelBounds(new AxisAlignedBB(minPostPos, 0.0, minPostPos, maxPostPos, POST_HEIGHT, maxPostPos));
|
||||
modelBaker.addBlockModel(null, block.getSprite(meta, false), 0);
|
||||
|
||||
boolean connectNegX = state.getValue(net.minecraft.block.BlockFence.WEST);
|
||||
boolean connectPosX = state.getValue(net.minecraft.block.BlockFence.EAST);
|
||||
boolean connectNegZ = state.getValue(net.minecraft.block.BlockFence.NORTH);
|
||||
boolean connectPosZ = state.getValue(net.minecraft.block.BlockFence.SOUTH);
|
||||
boolean connectNegX = state.getValue(BlockFence.WEST);
|
||||
boolean connectPosX = state.getValue(BlockFence.EAST);
|
||||
boolean connectNegZ = state.getValue(BlockFence.NORTH);
|
||||
boolean connectPosZ = state.getValue(BlockFence.SOUTH);
|
||||
boolean connectAnyX = connectNegX || connectPosX;
|
||||
boolean connectAnyZ = connectNegZ || connectPosZ;
|
||||
if (!connectAnyX && !connectAnyZ) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MultiFenceRecipeEmbedded implements IRecipe {
|
||||
final FenceType type2 = WoodManager.getFenceType(c);
|
||||
if (type != null && type2 != null) {
|
||||
if (type.equals(type2)) {
|
||||
final IPlankType pType = WoodManager.get(b);
|
||||
final IPlankType pType = WoodManager.getPlankType(b);
|
||||
FenceDescription fenceDescription = WoodManager.getFenceDescription(a);
|
||||
if (fenceDescription != null && fenceDescription.getPlankType() == pType) {
|
||||
this.cached = WoodManager.getFence(fenceDescription.getPlankType(), fenceDescription.getSecondaryPlankType(), new FenceType(type.size, type.solid, true), 2);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package binnie.extratrees.block.decor;
|
||||
|
||||
import binnie.extratrees.block.IPlankType;
|
||||
import binnie.extratrees.block.WoodManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class MultiFenceRecipePattern{
|
||||
public static MultiFenceRecipePattern[] VALUES;
|
||||
|
||||
static{
|
||||
VALUES = new MultiFenceRecipePattern[] {
|
||||
new MultiFenceRecipePattern(0, "010"+"0 0"+" "),
|
||||
new MultiFenceRecipePattern(0, "000"+"0 0"+" "),
|
||||
new MultiFenceRecipePattern(1, "010"+"0 0"+" 1 "),
|
||||
new MultiFenceRecipePattern(1, "000"+"0 0"+" 0 "),
|
||||
new MultiFenceRecipePattern(2, " 0 "+"1 1"+"101"),
|
||||
new MultiFenceRecipePattern(2, " 0 "+"0 0"+"000")
|
||||
};
|
||||
}
|
||||
|
||||
private final String pattern;
|
||||
private final int size;
|
||||
|
||||
private MultiFenceRecipePattern(int size, String pattern) {
|
||||
this.size = size;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
public boolean matches(String recipePattern){
|
||||
return pattern.contains(recipePattern);
|
||||
}
|
||||
|
||||
public ItemStack createFence(IPlankType plank, IPlankType plankSecondary){
|
||||
return WoodManager.getFence(plank, plankSecondary, new FenceType(size, false, false), 4);
|
||||
}
|
||||
}
|
||||
@@ -9,25 +9,28 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MultiFenceRecipeSize implements IRecipe {
|
||||
private ItemStack cached = ItemStack.EMPTY;
|
||||
|
||||
|
||||
public MultiFenceRecipeSize() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(final InventoryCrafting inv, final World world) {
|
||||
String pattern = "";
|
||||
final List<IPlankType> types = new ArrayList<>();
|
||||
String recipePattern = "";
|
||||
List<IPlankType> 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<ItemStack> getRemainingItems(InventoryCrafting inv) {
|
||||
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PagePlanksOverview extends PageAbstract<ItemStack> {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user