mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 19:49:54 +00:00
Fix fruit pods
This commit is contained in:
1 parent
d5a45a39eb
commit
a192c1ce49
40 files changed
+408
-406
No files matched your search
@@ -6,6 +6,7 @@
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.genetics.IAlleleProperty;
|
||||
|
||||
@@ -17,7 +18,7 @@ public interface IAlleleFruit extends IAlleleProperty<IAlleleFruit> {
|
||||
@Nonnull
|
||||
IFruitProvider getProvider();
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
String getModelName();
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -29,20 +34,25 @@ public interface IFruitProvider {
|
||||
int getRipeningPeriod();
|
||||
|
||||
// / Products, Chance
|
||||
ItemStack[] getProducts();
|
||||
@Nonnull
|
||||
Map<ItemStack, Float> getProducts();
|
||||
|
||||
// / Specialty, Chance
|
||||
ItemStack[] getSpecialty();
|
||||
@Nonnull
|
||||
Map<ItemStack, Float> getSpecialty();
|
||||
|
||||
ItemStack[] getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime);
|
||||
@Nonnull
|
||||
List<ItemStack> getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime);
|
||||
|
||||
/**
|
||||
* @return Short, human-readable identifier used in the treealyzer.
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
|
||||
@Nullable
|
||||
String getModelName();
|
||||
|
||||
|
||||
@Nonnull
|
||||
String getModID();
|
||||
|
||||
/* TEXTURE OVERLAY */
|
||||
|
||||
@@ -7,6 +7,8 @@ package forestry.api.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
@@ -43,11 +45,16 @@ public interface ITree extends IIndividual, ITreeGenData {
|
||||
*/
|
||||
ITree[] getSaplings(World world, GameProfile playerProfile, BlockPos pos, float modifier);
|
||||
|
||||
ItemStack[] getProduceList();
|
||||
// Products, Chance
|
||||
@Nonnull
|
||||
Map<ItemStack, Float> getProducts();
|
||||
|
||||
ItemStack[] getSpecialtyList();
|
||||
// Specialties, Chance
|
||||
@Nonnull
|
||||
Map<ItemStack, Float> getSpecialties();
|
||||
|
||||
ItemStack[] produceStacks(World world, BlockPos pos, int ripeningTime);
|
||||
@Nonnull
|
||||
List<ItemStack> produceStacks(World world, BlockPos pos, int ripeningTime);
|
||||
|
||||
/**
|
||||
* @return Boolean indicating whether a sapling can stay planted at the given position.
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface ITreeRoot extends ISpeciesRoot {
|
||||
@Override
|
||||
IChromosome[] templateAsChromosomes(IAllele[] templateActive, IAllele[] templateInactive);
|
||||
|
||||
boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, short[] indices, BlockPos pos);
|
||||
boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, BlockPos pos);
|
||||
|
||||
/* GAME MODE */
|
||||
ArrayList<ITreekeepingMode> getTreekeepingModes();
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface IFruitBearer {
|
||||
float getRipeness();
|
||||
|
||||
/**
|
||||
* Increases the ripeness of the fruit.
|
||||
* Increases the ripeness of the fruit. Adding 1.0f will fully ripen the fruit.
|
||||
*
|
||||
* @param add
|
||||
* Float to add to the ripeness. Will truncate to valid values.
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.multiblock;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Base logic class for Multiblock-connected tile entities.
|
||||
@@ -71,11 +69,6 @@ public abstract class MultiblockTileEntityBase<T extends IMultiblockLogic> exten
|
||||
super.validate();
|
||||
multiblockLogic.validate(worldObj, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return oldState.getBlock() != newSate.getBlock();
|
||||
}
|
||||
|
||||
/* Network Communication */
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import forestry.apiculture.genetics.alleles.AlleleEffect;
|
||||
import forestry.apiculture.items.EnumHoneyComb;
|
||||
import forestry.apiculture.items.EnumPollenCluster;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.alleles.AlleleHelper;
|
||||
import forestry.core.genetics.alleles.EnumAllele;
|
||||
|
||||
@@ -988,7 +989,7 @@ public enum BeeDefinition implements IBeeDefinition {
|
||||
String lowercaseName = this.toString().toLowerCase(Locale.ENGLISH);
|
||||
String species = "species" + WordUtils.capitalize(lowercaseName);
|
||||
|
||||
String uid = "forestry." + species;
|
||||
String uid = Constants.MOD_ID + '.' + species;
|
||||
String description = "for.description." + species;
|
||||
String name = "for.bees.species." + lowercaseName;
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
|
||||
if (worldObj != null) {
|
||||
if (worldObj.isRemote) {
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
} else {
|
||||
Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
@@ -67,9 +72,10 @@ public class FruitProviderNone implements IFruitProvider {
|
||||
return family;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
return new ItemStack[0];
|
||||
public List<ItemStack> getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,14 +108,16 @@ public class FruitProviderNone implements IFruitProvider {
|
||||
return ripeningPeriod;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getProducts() {
|
||||
return new ItemStack[0];
|
||||
public Map<ItemStack, Float> getProducts() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getSpecialty() {
|
||||
return new ItemStack[0];
|
||||
public Map<ItemStack, Float> getSpecialty() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,12 +149,14 @@ public class FruitProviderNone implements IFruitProvider {
|
||||
TextureManager.registerSpriteUID(overlay.texUID, "blocks/leaves/fruits." + overlay.ident);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getModID() {
|
||||
return Constants.MOD_ID;
|
||||
|
||||
@@ -10,9 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -42,15 +47,17 @@ public class FruitProviderPod extends FruitProviderNone {
|
||||
}
|
||||
}
|
||||
|
||||
private static final ItemStack[] DUMMY = new ItemStack[0];
|
||||
|
||||
private final EnumPodType type;
|
||||
private final ItemStack[] drop;
|
||||
@Nonnull
|
||||
private final Map<ItemStack, Float> drops;
|
||||
|
||||
public FruitProviderPod(String key, IFruitFamily family, EnumPodType type, ItemStack... dropOnMature) {
|
||||
super(key, family);
|
||||
this.type = type;
|
||||
this.drop = dropOnMature;
|
||||
this.drops = new HashMap<>();
|
||||
for (ItemStack drop : dropOnMature) {
|
||||
this.drops.put(drop, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,21 +65,22 @@ public class FruitProviderPod extends FruitProviderNone {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
if (drop == null || drop.length == 0) {
|
||||
return DUMMY;
|
||||
public List<ItemStack> getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
if (drops.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (ripeningTime >= 2) {
|
||||
ItemStack[] dropping = new ItemStack[drop.length];
|
||||
for (int i = 0; i < drop.length; i++) {
|
||||
dropping[i] = drop[i].copy();
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
for (ItemStack aDrop : this.drops.keySet()) {
|
||||
drops.add(aDrop.copy());
|
||||
}
|
||||
return dropping;
|
||||
return drops;
|
||||
}
|
||||
|
||||
return DUMMY;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,27 +91,38 @@ public class FruitProviderPod extends FruitProviderNone {
|
||||
}
|
||||
|
||||
if (type == EnumPodType.COCOA) {
|
||||
return BlockUtil.tryPlantPot(world, pos, Blocks.cocoa);
|
||||
return BlockUtil.tryPlantCocoaPod(world, pos);
|
||||
} else {
|
||||
return TreeManager.treeRoot.setFruitBlock(world, (IAlleleFruit) genome.getActiveAllele(EnumTreeChromosome.FRUITS),
|
||||
genome.getSappiness(), type.uids, pos);
|
||||
IAlleleFruit activeAllele = (IAlleleFruit) genome.getActiveAllele(EnumTreeChromosome.FRUITS);
|
||||
return TreeManager.treeRoot.setFruitBlock(world, activeAllele, genome.getSappiness(), pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getSpriteIndex(ITreeGenome genome, IBlockAccess world, BlockPos pos, int ripeningTime, boolean fancy) {
|
||||
return type.uids[0];
|
||||
if (ripeningTime < 0 || ripeningTime >= type.uids.length) {
|
||||
return getDecorativeSpriteIndex();
|
||||
}
|
||||
return type.uids[ripeningTime];
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getDecorativeSpriteIndex() {
|
||||
return type.uids[0];
|
||||
int index = type.uids.length - 1;
|
||||
return type.uids[index];
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Map<ItemStack, Float> getProducts() {
|
||||
return Collections.unmodifiableMap(drops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSprites() {
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return type.getModelName();
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
@@ -29,6 +31,7 @@ import forestry.api.genetics.IFruitFamily;
|
||||
*/
|
||||
public class FruitProviderRandom extends FruitProviderNone {
|
||||
|
||||
@Nonnull
|
||||
private final Map<ItemStack, Float> products = new HashMap<>();
|
||||
private int colour = 0xffffff;
|
||||
|
||||
@@ -47,9 +50,10 @@ public class FruitProviderRandom extends FruitProviderNone {
|
||||
return colour;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
ArrayList<ItemStack> product = new ArrayList<>();
|
||||
public List<ItemStack> getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
List<ItemStack> product = new ArrayList<>();
|
||||
|
||||
float modeYieldMod = TreeManager.treeRoot.getTreekeepingMode(world).getYieldModifier(genome, 1f);
|
||||
|
||||
@@ -59,18 +63,13 @@ public class FruitProviderRandom extends FruitProviderNone {
|
||||
}
|
||||
}
|
||||
|
||||
return product.toArray(new ItemStack[product.size()]);
|
||||
return product;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getProducts() {
|
||||
Set<ItemStack> products = this.products.keySet();
|
||||
return products.toArray(new ItemStack[products.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getSpecialty() {
|
||||
return new ItemStack[0];
|
||||
public Map<ItemStack, Float> getProducts() {
|
||||
return Collections.unmodifiableMap(products);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
@@ -26,6 +28,7 @@ import forestry.api.genetics.IFruitFamily;
|
||||
|
||||
public class FruitProviderRipening extends FruitProviderNone {
|
||||
|
||||
@Nonnull
|
||||
private final Map<ItemStack, Float> products = new HashMap<>();
|
||||
|
||||
private int colourCallow = 0xffffff;
|
||||
@@ -62,13 +65,14 @@ public class FruitProviderRipening extends FruitProviderNone {
|
||||
return (float) ripeningTime / ripeningPeriod;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
public List<ItemStack> getFruits(ITreeGenome genome, World world, BlockPos pos, int ripeningTime) {
|
||||
ArrayList<ItemStack> product = new ArrayList<>();
|
||||
|
||||
float stage = getRipeningStage(ripeningTime);
|
||||
if (stage < 0.5f) {
|
||||
return new ItemStack[0];
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
float modeYieldMod = TreeManager.treeRoot.getTreekeepingMode(world).getYieldModifier(genome, 1f);
|
||||
@@ -79,13 +83,13 @@ public class FruitProviderRipening extends FruitProviderNone {
|
||||
}
|
||||
}
|
||||
|
||||
return product.toArray(new ItemStack[product.size()]);
|
||||
return product;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getProducts() {
|
||||
Set<ItemStack> products = this.products.keySet();
|
||||
return products.toArray(new ItemStack[products.size()]);
|
||||
public Map<ItemStack, Float> getProducts() {
|
||||
return Collections.unmodifiableMap(products);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.EnumWoodType;
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
@@ -43,7 +44,6 @@ import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.api.storage.StorageManager;
|
||||
import forestry.arboriculture.blocks.BlockArbLog;
|
||||
import forestry.arboriculture.blocks.BlockArbSlab;
|
||||
import forestry.arboriculture.blocks.BlockFruitPod;
|
||||
import forestry.arboriculture.blocks.BlockRegistryArboriculture;
|
||||
import forestry.arboriculture.blocks.BlockTypeArboricultureTesr;
|
||||
import forestry.arboriculture.commands.CommandTree;
|
||||
@@ -53,6 +53,7 @@ import forestry.arboriculture.genetics.TreeFactory;
|
||||
import forestry.arboriculture.genetics.TreeMutationFactory;
|
||||
import forestry.arboriculture.genetics.TreeRoot;
|
||||
import forestry.arboriculture.genetics.TreekeepingMode;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleFruit;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleGrowth;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleLeafEffect;
|
||||
import forestry.arboriculture.items.ItemRegistryArboriculture;
|
||||
@@ -428,23 +429,8 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerSprites(TextureStitchEvent.Pre event) {
|
||||
TextureLeaves.registerAllSprites();
|
||||
BlockFruitPod.registerSprites();
|
||||
}
|
||||
|
||||
/*@SubscribeEvent
|
||||
public void fuelBurnTimeEvent(FuelBurnTimeEvent fuelBurnTimeEvent) {
|
||||
Item item = fuelBurnTimeEvent.fuel.getItem();
|
||||
Block block = Block.getBlockFromItem(item);
|
||||
|
||||
if (block instanceof IWoodTyped) {
|
||||
IWoodTyped woodTypedBlock = (IWoodTyped) block;
|
||||
if (woodTypedBlock.isFireproof()) {
|
||||
fuelBurnTimeEvent.burnTime = 0;
|
||||
fuelBurnTimeEvent.setResult(Event.Result.DENY);
|
||||
} else if (blocks.slabs == block) {
|
||||
fuelBurnTimeEvent.burnTime = 150;
|
||||
fuelBurnTimeEvent.setResult(Event.Result.DENY);
|
||||
}
|
||||
for (IAlleleFruit alleleFruit : AlleleFruit.getFruitAlleles()) {
|
||||
alleleFruit.getProvider().registerSprites();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP
|
||||
|
||||
// Add fruits
|
||||
if (tile.hasFruit()) {
|
||||
Collections.addAll(prod, tile.getTree().produceStacks((World) world, pos, tile.getRipeningTime()));
|
||||
prod.addAll(tile.getTree().produceStacks((World) world, pos, tile.getRipeningTime()));
|
||||
}
|
||||
|
||||
return prod;
|
||||
@@ -345,7 +345,7 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP
|
||||
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
TileLeaves leafTile = TileUtil.getTile(world, pos, TileLeaves.class);
|
||||
if (leafTile != null) {
|
||||
leafTile.addRipeness(1.0f);
|
||||
leafTile.addRipeness(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,79 +10,69 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.blocks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.blocks.property.PropertyFruit;
|
||||
import forestry.arboriculture.render.FluidPodStateMapper;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleFruit;
|
||||
import forestry.arboriculture.render.FruitPodStateMapper;
|
||||
import forestry.arboriculture.tiles.TileFruitPod;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister, ITileEntityProvider {
|
||||
|
||||
public final static PropertyFruit FRUIT = new PropertyFruit("fruit");
|
||||
|
||||
public BlockFruitPod() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
return ((IExtendedBlockState) super.getExtendedState(state, world, pos)).withProperty(UnlistedBlockPos.POS, pos)
|
||||
.withProperty(UnlistedBlockAccess.BLOCKACCESS, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockState createBlockState() {
|
||||
return new ExtendedBlockState(this, new IProperty[]{FACING, AGE, FRUIT},
|
||||
new IUnlistedProperty[]{UnlistedBlockPos.POS, UnlistedBlockAccess.BLOCKACCESS});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileFruitPod pot = getPodTile(world, pos);
|
||||
if(pos != null){
|
||||
IAlleleFruit fruit = pot.getAllele();
|
||||
state = state.withProperty(FRUIT, fruit);
|
||||
public static List<BlockFruitPod> create() {
|
||||
List<BlockFruitPod> blocks = new ArrayList<>();
|
||||
for (IAlleleFruit fruit : AlleleFruit.getFruitAllelesWithModels()) {
|
||||
BlockFruitPod block = new BlockFruitPod(fruit);
|
||||
blocks.add(block);
|
||||
}
|
||||
return super.getActualState(state, world, pos);
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public static TileFruitPod getPodTile(IBlockAccess world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileFruitPod)) {
|
||||
@Nonnull
|
||||
private final IAlleleFruit fruit;
|
||||
|
||||
private BlockFruitPod(@Nonnull IAlleleFruit fruit) {
|
||||
this.fruit = fruit;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public IAlleleFruit getFruit() {
|
||||
return fruit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
|
||||
TileFruitPod tile = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (TileFruitPod) tile;
|
||||
return tile.getPickBlock();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (!canBlockStay(world, pos, state)) {
|
||||
@@ -91,7 +81,7 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
return;
|
||||
}
|
||||
|
||||
TileFruitPod tile = getPodTile(world, pos);
|
||||
TileFruitPod tile = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
@@ -102,9 +92,9 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||
if (!world.isRemote) {
|
||||
TileFruitPod tile = getPodTile(world, pos);
|
||||
TileFruitPod tile = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (tile != null) {
|
||||
for (ItemStack drop : tile.getDrop()) {
|
||||
for (ItemStack drop : tile.getDrops()) {
|
||||
ItemStackUtil.dropItemStackAsEntity(drop, world, pos);
|
||||
}
|
||||
}
|
||||
@@ -115,12 +105,13 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlockStay(World world, BlockPos pos, IBlockState state) {
|
||||
return BlockUtil.getDirectionalMetadata(world, pos) >= 0;
|
||||
EnumFacing facing = state.getValue(FACING);
|
||||
return BlockUtil.isValidPodLocation(world, pos, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,51 +119,33 @@ public class BlockFruitPod extends BlockCocoa implements IStateMapperRegister {
|
||||
world.removeTileEntity(pos);
|
||||
super.breakBlock(world, pos, state);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(IBlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileFruitPod();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, new FluidPodStateMapper());
|
||||
Proxies.render.registerStateMapper(this, new FruitPodStateMapper());
|
||||
}
|
||||
|
||||
/* IGrowable */
|
||||
@Override
|
||||
public boolean canGrow(World world, BlockPos pos, IBlockState state, boolean isClient) {
|
||||
TileFruitPod podTile = getPodTile(world, pos);
|
||||
TileFruitPod podTile = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (podTile != null) {
|
||||
return podTile.canMature();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseBonemeal(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
TileFruitPod podTile = getPodTile(world, pos);
|
||||
TileFruitPod podTile = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (podTile != null) {
|
||||
podTile.mature();
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerSprites() {
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
((IAlleleFruit) allele).getProvider().registerSprites();
|
||||
}
|
||||
podTile.addRipeness(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.arboriculture.EnumWoodType;
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.arboriculture.genetics.TreeDefinition;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleFruit;
|
||||
import forestry.arboriculture.items.ItemBlockDecorativeLeaves;
|
||||
@@ -46,8 +47,8 @@ public class BlockRegistryArboriculture extends BlockRegistry {
|
||||
public final BlockForestryLeaves leaves;
|
||||
public final List<BlockDecorativeLeaves> leavesDecorative;
|
||||
private final Map<String, ItemStack> speciesToLeavesDecorative;
|
||||
public final BlockFruitPod pods;
|
||||
|
||||
public final Map<String, BlockFruitPod> podsMap;
|
||||
|
||||
public final BlockArboriculture arboriculture;
|
||||
|
||||
public BlockRegistryArboriculture() {
|
||||
@@ -146,7 +147,7 @@ public class BlockRegistryArboriculture extends BlockRegistry {
|
||||
leavesDecorative = BlockDecorativeLeaves.create();
|
||||
speciesToLeavesDecorative = new HashMap<>();
|
||||
for (BlockDecorativeLeaves leaves : leavesDecorative) {
|
||||
registerBlock(leaves, ItemBlockDecorativeLeaves.class, "leaves.decorative." + leaves.getBlockNumber());
|
||||
registerBlock(leaves, new ItemBlockDecorativeLeaves(leaves), "leaves.decorative." + leaves.getBlockNumber());
|
||||
registerOreDictWildcard("treeLeaves", leaves);
|
||||
|
||||
for (IBlockState state : leaves.getBlockState().getValidStates()) {
|
||||
@@ -159,8 +160,13 @@ public class BlockRegistryArboriculture extends BlockRegistry {
|
||||
|
||||
// Pods
|
||||
AlleleFruit.createAlleles();
|
||||
pods = registerBlock(new BlockFruitPod(), ItemBlockForestry.class, "pods");
|
||||
|
||||
podsMap = new HashMap<>();
|
||||
for (BlockFruitPod pod : BlockFruitPod.create()) {
|
||||
IAlleleFruit fruit = pod.getFruit();
|
||||
registerBlock(pod, "pods." + fruit.getModelName());
|
||||
podsMap.put(fruit.getUID(), pod);
|
||||
}
|
||||
|
||||
// Machines
|
||||
arboriculture = registerBlock(new BlockArboriculture(), ItemBlockForestry.class, "arboriculture");
|
||||
}
|
||||
@@ -168,4 +174,8 @@ public class BlockRegistryArboriculture extends BlockRegistry {
|
||||
public ItemStack getDecorativeLeaves(String speciesUid) {
|
||||
return speciesToLeavesDecorative.get(speciesUid);
|
||||
}
|
||||
|
||||
public BlockFruitPod getFruitPod(IAlleleFruit fruit) {
|
||||
return podsMap.get(fruit.getUID());
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package forestry.arboriculture.blocks.property;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.core.blocks.propertys.PropertyAllele;
|
||||
|
||||
public class PropertyFruit extends PropertyAllele<IAlleleFruit> {
|
||||
|
||||
public PropertyFruit(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<IAlleleFruit> getValueClass() {
|
||||
return IAlleleFruit.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("name", this.name).add("clazz", IAlleleFruit.class).add("values", this.getAllowedValues()).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * IAlleleTreeSpecies.class.hashCode() + this.name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IAlleleFruit> getAllowedValues() {
|
||||
List<IAlleleFruit> trees = new ArrayList<>();
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
if (((IAlleleFruit) allele).getModelName() != null) {
|
||||
trees.add((IAlleleFruit) allele);
|
||||
}
|
||||
}
|
||||
}
|
||||
return trees;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(IAlleleFruit value) {
|
||||
return value.getModelName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -424,18 +425,21 @@ public class Tree extends Individual implements ITree, IPlantable {
|
||||
return genome.getPrimary().getSuitableFruit().contains(genome.getFruitProvider().getFamily());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getProduceList() {
|
||||
public Map<ItemStack, Float> getProducts() {
|
||||
return genome.getFruitProvider().getProducts();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] getSpecialtyList() {
|
||||
public Map<ItemStack, Float> getSpecialties() {
|
||||
return genome.getFruitProvider().getSpecialty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack[] produceStacks(World world, BlockPos pos, int ripeningTime) {
|
||||
public List<ItemStack> produceStacks(World world, BlockPos pos, int ripeningTime) {
|
||||
return genome.getFruitProvider().getFruits(genome, world, pos, ripeningTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -981,7 +981,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
|
||||
|
||||
// forestry tree constructor
|
||||
TreeDefinition(TreeBranchDefinition branch, String speciesName, String binomial, boolean dominant, EnumLeafType leafType, Color primary, Color secondary, EnumWoodType woodType) {
|
||||
String uid = "forestry.tree" + this;
|
||||
String uid = Constants.MOD_ID + ".tree" + this;
|
||||
String unlocalizedDescription = "for.description.tree" + this;
|
||||
String unlocalizedName = "for.trees.species." + speciesName;
|
||||
String modelName = uid.substring("forestry.".length());
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDirectional;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -26,6 +27,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -57,6 +59,7 @@ import forestry.arboriculture.tiles.TileFruitPod;
|
||||
import forestry.arboriculture.tiles.TileSapling;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.SpeciesRoot;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
@@ -219,29 +222,35 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, short[] indices, BlockPos pos) {
|
||||
public boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, BlockPos pos) {
|
||||
|
||||
int direction = BlockUtil.getDirectionalMetadata(world, pos);
|
||||
if (direction < 0) {
|
||||
EnumFacing facing = BlockUtil.getValidPodFacing(world, pos);
|
||||
if (facing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean placed = world.setBlockState(pos, PluginArboriculture.blocks.pods.getStateFromMeta(direction), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
|
||||
BlockFruitPod fruitPod = PluginArboriculture.blocks.getFruitPod(allele);
|
||||
if (fruitPod == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = fruitPod.getDefaultState().withProperty(BlockDirectional.FACING, facing);
|
||||
boolean placed = world.setBlockState(pos, state);
|
||||
if (!placed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block block = BlockUtil.getBlock(world, pos);
|
||||
if (PluginArboriculture.blocks.pods != block) {
|
||||
if (fruitPod != block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileFruitPod pod = BlockFruitPod.getPodTile(world, pos);
|
||||
TileFruitPod pod = TileUtil.getTile(world, pos, TileFruitPod.class);
|
||||
if (pod == null) {
|
||||
world.setBlockToAir(pos);
|
||||
return false;
|
||||
}
|
||||
pod.setFruit(allele, sappiness, indices);
|
||||
pod.setProperties(allele, sappiness);
|
||||
world.markBlockForUpdate(pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,13 @@
|
||||
package forestry.arboriculture.genetics.alleles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.arboriculture.EnumFruitFamily;
|
||||
@@ -22,6 +25,7 @@ import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.arboriculture.IFruitProvider;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.FruitProviderNone;
|
||||
import forestry.arboriculture.FruitProviderPod;
|
||||
import forestry.arboriculture.FruitProviderRandom;
|
||||
@@ -44,12 +48,14 @@ public class AlleleFruit extends AlleleCategorized implements IAlleleFruit {
|
||||
public static IAlleleFruit fruitLemon;
|
||||
public static IAlleleFruit fruitPlum;
|
||||
public static IAlleleFruit fruitJujube;
|
||||
private static List<IAlleleFruit> fruitAlleles;
|
||||
private static List<IAlleleFruit> fruitAllelesWithModels;
|
||||
|
||||
public static void createAlleles() {
|
||||
List<IAlleleFruit> fruitAlleles = Arrays.asList(
|
||||
fruitNone = new AlleleFruit("none", new FruitProviderNone("none", null)),
|
||||
fruitApple = new AlleleFruit("apple", new FruitProviderRandom("apple", EnumFruitFamily.POMES, new ItemStack(Items.apple), 1.0f).setColour(0xff2e2e).setOverlay("pomes")),
|
||||
fruitCocoa = new AlleleFruit("cocoa", new FruitProviderPod("cocoa", EnumFruitFamily.JUNGLE, FruitProviderPod.EnumPodType.COCOA)),
|
||||
fruitCocoa = new AlleleFruit("cocoa", new FruitProviderPod("cocoa", EnumFruitFamily.JUNGLE, FruitProviderPod.EnumPodType.COCOA, new ItemStack(Items.dye, 1, EnumDyeColor.BROWN.getDyeDamage()))),
|
||||
// .setColours(0xecdca5, 0xc4d24a), true);
|
||||
fruitChestnut = new AlleleFruit("chestnut", new FruitProviderRipening("chestnut", EnumFruitFamily.NUX, ItemFruit.EnumFruit.CHESTNUT.getStack(), 1.0f).setRipeningPeriod(6).setColours(0x7f333d, 0xc4d24a).setOverlay("nuts"), true),
|
||||
fruitWalnut = new AlleleFruit("walnut", new FruitProviderRipening("walnut", EnumFruitFamily.NUX, ItemFruit.EnumFruit.WALNUT.getStack(), 1.0f).setRipeningPeriod(8).setColours(0xfba248, 0xc4d24a).setOverlay("nuts"), true),
|
||||
@@ -65,6 +71,34 @@ public class AlleleFruit extends AlleleCategorized implements IAlleleFruit {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<IAlleleFruit> getFruitAlleles() {
|
||||
if (fruitAlleles == null) {
|
||||
fruitAlleles = new ArrayList<>();
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
IAlleleFruit alleleFruit = (IAlleleFruit) allele;
|
||||
fruitAlleles.add(alleleFruit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return fruitAlleles;
|
||||
}
|
||||
|
||||
public static List<IAlleleFruit> getFruitAllelesWithModels() {
|
||||
if (fruitAllelesWithModels == null) {
|
||||
fruitAllelesWithModels = new ArrayList<>();
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
IAlleleFruit alleleFruit = (IAlleleFruit) allele;
|
||||
if (alleleFruit.getModelName() != null) {
|
||||
fruitAllelesWithModels.add(alleleFruit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return fruitAllelesWithModels;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private final IFruitProvider provider;
|
||||
|
||||
@@ -88,7 +122,7 @@ public class AlleleFruit extends AlleleCategorized implements IAlleleFruit {
|
||||
return getProvider().getDescription();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return getProvider().getModelName();
|
||||
|
||||
@@ -263,7 +263,7 @@ public class GuiTreealyzer extends GuiAlyzer {
|
||||
textLayout.newLine();
|
||||
|
||||
int x = COLUMN_0;
|
||||
for (ItemStack stack : tree.getProduceList()) {
|
||||
for (ItemStack stack : tree.getProducts().keySet()) {
|
||||
itemRender.renderItemIntoGUI(stack, guiLeft + x, guiTop + textLayout.getLineY());
|
||||
x += 18;
|
||||
if (x > 148) {
|
||||
@@ -281,7 +281,7 @@ public class GuiTreealyzer extends GuiAlyzer {
|
||||
textLayout.newLine();
|
||||
|
||||
x = COLUMN_0;
|
||||
for (ItemStack stack : tree.getSpecialtyList()) {
|
||||
for (ItemStack stack : tree.getSpecialties().keySet()) {
|
||||
itemRender.renderItemIntoGUI(stack, guiLeft + x, guiTop + textLayout.getLineY());
|
||||
x += 18;
|
||||
if (x > 148) {
|
||||
|
||||
@@ -16,7 +16,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.arboriculture.network.IRipeningPacketReceiver;
|
||||
import forestry.arboriculture.tiles.TileFruitPod;
|
||||
import forestry.arboriculture.tiles.TileLeaves;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
@@ -32,11 +31,6 @@ public class PacketRipeningUpdate extends PacketCoordinates implements IForestry
|
||||
public PacketRipeningUpdate() {
|
||||
}
|
||||
|
||||
public PacketRipeningUpdate(TileFruitPod fruitPod) {
|
||||
super(fruitPod);
|
||||
value = fruitPod.getMaturity();
|
||||
}
|
||||
|
||||
public PacketRipeningUpdate(TileLeaves leaves) {
|
||||
super(leaves);
|
||||
value = leaves.getFruitColour();
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package forestry.arboriculture.render;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.BlockDirectional;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.blocks.BlockFruitPod;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.render.ForestryStateMapper;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class FluidPodStateMapper extends ForestryStateMapper {
|
||||
|
||||
private final Map<IBlockState, ModelResourceLocation> mapStateModelLocations = Maps.newLinkedHashMap();
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
|
||||
for (EnumFacing facing : EnumFacing.values()) {
|
||||
if (facing != EnumFacing.UP && facing != EnumFacing.DOWN) {
|
||||
for (int age = 0; age < BlockCocoa.AGE.getAllowedValues().size(); age++) {
|
||||
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
|
||||
if (allele instanceof IAlleleFruit) {
|
||||
IAlleleFruit fruit = (IAlleleFruit) allele;
|
||||
if (fruit.getModelName() != null) {
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockFruitPod.FRUIT, fruit).withProperty(BlockDirectional.FACING, facing).withProperty(BlockCocoa.AGE, age);
|
||||
LinkedHashMap<IProperty, Comparable> linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
|
||||
String modID = fruit.getModID();
|
||||
if (modID == null) {
|
||||
modID = Constants.MOD_ID;
|
||||
}
|
||||
String modelName = BlockFruitPod.FRUIT.getName((IAlleleFruit) linkedhashmap.remove(BlockFruitPod.FRUIT));
|
||||
String s = String.format("%s:%s", modID, "pods/" + modelName);
|
||||
mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapStateModelLocations;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package forestry.arboriculture.render;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.arboriculture.blocks.BlockFruitPod;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.render.ForestryStateMapper;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class FruitPodStateMapper extends ForestryStateMapper {
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
|
||||
if (block instanceof BlockFruitPod) {
|
||||
BlockFruitPod blockFruitPod = (BlockFruitPod) block;
|
||||
IAlleleFruit fruit = blockFruitPod.getFruit();
|
||||
String modID = fruit.getModID();
|
||||
if (Constants.MOD_ID.equals(modID)) {
|
||||
String modelName = fruit.getModelName();
|
||||
String resourcePath = Constants.RESOURCE_ID + ":pods/" + modelName;
|
||||
for (IBlockState state : block.getBlockState().getValidStates()) {
|
||||
String propertyString = getPropertyString(state.getProperties());
|
||||
mapStateModelLocations.put(state, new ModelResourceLocation(resourcePath, propertyString));
|
||||
}
|
||||
}
|
||||
}
|
||||
return mapStateModelLocations;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,51 +10,49 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IFruitBearer;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.arboriculture.network.IRipeningPacketReceiver;
|
||||
import forestry.arboriculture.network.packets.PacketRipeningUpdate;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.packets.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamable, IRipeningPacketReceiver {
|
||||
public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamable {
|
||||
|
||||
private static final short MAX_MATURITY = 2;
|
||||
|
||||
private IAlleleFruit allele;
|
||||
|
||||
private short maturity;
|
||||
private int[] indices = new int[0];
|
||||
private float sappiness;
|
||||
|
||||
public void setFruit(IAlleleFruit allele, float sappiness, short[] indices) {
|
||||
public TileFruitPod() {
|
||||
Log.debug("Made a fruit pod");
|
||||
}
|
||||
|
||||
public void setProperties(IAlleleFruit allele, float sappiness) {
|
||||
this.allele = allele;
|
||||
this.sappiness = sappiness;
|
||||
this.indices = new int[indices.length];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
this.indices[i] = indices[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@@ -66,12 +64,11 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
if (stored instanceof IAlleleFruit) {
|
||||
allele = (IAlleleFruit) stored;
|
||||
} else {
|
||||
allele = (IAlleleFruit) AlleleManager.alleleRegistry.getAllele("fruitCocoa");
|
||||
allele = (IAlleleFruit) AlleleManager.alleleRegistry.getAllele(Constants.MOD_ID + ".fruitCocoa");
|
||||
}
|
||||
|
||||
maturity = nbttagcompound.getShort("MT");
|
||||
sappiness = nbttagcompound.getFloat("SP");
|
||||
indices = nbttagcompound.getIntArray("IN");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,39 +81,41 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
|
||||
nbttagcompound.setShort("MT", maturity);
|
||||
nbttagcompound.setFloat("SP", sappiness);
|
||||
nbttagcompound.setIntArray("IN", indices);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
public void onBlockTick() {
|
||||
if (canMature() && worldObj.rand.nextFloat() <= sappiness) {
|
||||
mature();
|
||||
addRipeness(0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
public void mature() {
|
||||
maturity++;
|
||||
sendNetworkUpdateRipening();
|
||||
}
|
||||
|
||||
public boolean canMature() {
|
||||
return maturity < MAX_MATURITY;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public TextureAtlasSprite getSprite() {
|
||||
if (maturity < indices.length) {
|
||||
return TextureManager.getInstance().getSprite((short) indices[maturity]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public short getMaturity() {
|
||||
return maturity;
|
||||
}
|
||||
|
||||
public ItemStack[] getDrop() {
|
||||
@Nullable
|
||||
public ItemStack getPickBlock() {
|
||||
Map<ItemStack, Float> products = allele.getProvider().getProducts();
|
||||
|
||||
ItemStack pickBlock = null;
|
||||
Float maxChance = 0.0f;
|
||||
for (Map.Entry<ItemStack, Float> product : products.entrySet()) {
|
||||
if (maxChance < product.getValue()) {
|
||||
maxChance = product.getValue();
|
||||
pickBlock = product.getKey().copy();
|
||||
}
|
||||
}
|
||||
|
||||
pickBlock.stackSize = 1;
|
||||
return pickBlock;
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops() {
|
||||
return allele.getProvider().getFruits(null, worldObj, getPos(), maturity);
|
||||
}
|
||||
|
||||
@@ -126,19 +125,6 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
private void sendNetworkUpdateRipening() {
|
||||
Proxies.net.sendNetworkPacket(new PacketRipeningUpdate(this), worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromRipeningPacket(int newMaturity) {
|
||||
if (newMaturity == maturity) {
|
||||
return;
|
||||
}
|
||||
maturity = (short) newMaturity;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
|
||||
/* IFRUITBEARER */
|
||||
@Override
|
||||
public boolean hasFruit() {
|
||||
@@ -147,25 +133,17 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
|
||||
@Override
|
||||
public IFruitFamily getFruitFamily() {
|
||||
if (allele == null) {
|
||||
return null;
|
||||
}
|
||||
return allele.getProvider().getFamily();
|
||||
}
|
||||
|
||||
public IAlleleFruit getAllele() {
|
||||
return allele;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> pickFruit(ItemStack tool) {
|
||||
if (allele == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Collection<ItemStack> fruits = Arrays.asList(getDrop());
|
||||
Collection<ItemStack> fruits = getDrops();
|
||||
maturity = 0;
|
||||
sendNetworkUpdateRipening();
|
||||
|
||||
IBlockState state = worldObj.getBlockState(getPos()).withProperty(BlockCocoa.AGE, 0);
|
||||
worldObj.setBlockState(getPos(), state);
|
||||
|
||||
return fruits;
|
||||
}
|
||||
|
||||
@@ -176,28 +154,42 @@ public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamabl
|
||||
|
||||
@Override
|
||||
public void addRipeness(float add) {
|
||||
int previousAge = (int) Math.floor(maturity);
|
||||
|
||||
maturity += MAX_MATURITY * add;
|
||||
sendNetworkUpdateRipening();
|
||||
if (maturity > MAX_MATURITY) {
|
||||
maturity = MAX_MATURITY;
|
||||
}
|
||||
|
||||
int age = (int) Math.floor(maturity);
|
||||
if (age - previousAge > 0) {
|
||||
IBlockState state = worldObj.getBlockState(getPos()).withProperty(BlockCocoa.AGE, age);
|
||||
worldObj.setBlockState(getPos(), state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
|
||||
return oldState.getBlock() != newState.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeShort(maturity);
|
||||
data.writeShort(indices.length);
|
||||
for (int i : indices) {
|
||||
data.writeInt(i);
|
||||
if (allele != null) {
|
||||
data.writeUTF(allele.getUID());
|
||||
} else {
|
||||
data.writeUTF("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
maturity = data.readShort();
|
||||
int indicesLength = data.readShort();
|
||||
indices = new int[indicesLength];
|
||||
for (int i = 0; i < indicesLength; i++) {
|
||||
indices[i] = data.readInt();
|
||||
IAllele stored = AlleleManager.alleleRegistry.getAllele(data.readUTF());
|
||||
if (stored instanceof IAlleleFruit) {
|
||||
allele = (IAlleleFruit) stored;
|
||||
} else {
|
||||
allele = (IAlleleFruit) AlleleManager.alleleRegistry.getAllele(Constants.MOD_ID + ".fruitCocoa");
|
||||
}
|
||||
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,10 @@ package forestry.arboriculture.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -387,7 +387,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
return;
|
||||
}
|
||||
colourFruits = newColourFruits;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
}
|
||||
|
||||
/* IFRUITBEARER */
|
||||
@@ -398,10 +398,10 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ItemStack[] produceStacks = tree.produceStacks(worldObj, getPos(), getRipeningTime());
|
||||
List<ItemStack> produceStacks = tree.produceStacks(worldObj, getPos(), getRipeningTime());
|
||||
ripeningTime = 0;
|
||||
sendNetworkUpdateRipening();
|
||||
return Arrays.asList(produceStacks);
|
||||
return produceStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,7 +73,7 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
public BlockBase(Class<P> machinePropertiesClass) {
|
||||
super(Material.iron);
|
||||
|
||||
this.hasTESR = IBlockTypeTesr.class.isAssignableFrom(machinePropertiesClass);;
|
||||
this.hasTESR = IBlockTypeTesr.class.isAssignableFrom(machinePropertiesClass);
|
||||
this.hasCustom = IBlockTypeCustom.class.isAssignableFrom(machinePropertiesClass);
|
||||
this.lightOpacity = this.isOpaqueCube() ? 255 : 0;
|
||||
this.machinePropertiesClass = machinePropertiesClass;
|
||||
@@ -88,6 +88,10 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
this.setDefaultState(state);
|
||||
}
|
||||
|
||||
public PropertyEnum<P> getTypeProperty() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void addDefinitions(P... blockTypes) {
|
||||
for (P blockType : blockTypes) {
|
||||
|
||||
@@ -37,6 +37,10 @@ public abstract class BlockRegistry {
|
||||
return block;
|
||||
}
|
||||
|
||||
protected <T extends Block> T registerBlock(T block, String name) {
|
||||
return registerBlock(block, (Class<? extends ItemBlock>) null, name);
|
||||
}
|
||||
|
||||
protected <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass, String name, Object... itemCtorArgs) {
|
||||
if (PluginManager.getStage() != PluginManager.Stage.REGISTER) {
|
||||
throw new RuntimeException("Tried to register Block outside of REGISTER");
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -122,7 +123,7 @@ public class ModelManager implements IModelManager {
|
||||
}
|
||||
|
||||
public static void registerCustomModels(ModelBakeEvent event) {
|
||||
IRegistry registry = event.modelRegistry;
|
||||
IRegistry<ModelResourceLocation, IBakedModel> registry = event.modelRegistry;
|
||||
for (final BlockModelIndex index : customBlockModels) {
|
||||
registry.putObject(index.blockModelLocation, index.model);
|
||||
registry.putObject(index.itemModelLocation, index.model);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.models.baker;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
@@ -277,7 +278,7 @@ public class ModelBaker implements IModelBaker {
|
||||
addFace(EnumFacing.EAST, isEdge, to, from, defUVs, sprite);
|
||||
}
|
||||
|
||||
protected void addFace(EnumFacing face, boolean isEdge, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite texture) {
|
||||
protected void addFace(@Nonnull EnumFacing face, boolean isEdge, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite texture) {
|
||||
faces.add(new ModelBakerFace(face, isEdge, colorIndex, to, from, defUVs2, texture));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,22 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.models.baker;
|
||||
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
/**
|
||||
* A face of a {@link ModelBakerModel }
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ModelBakerFace {
|
||||
|
||||
@Nonnull
|
||||
public final EnumFacing face;
|
||||
public final boolean isEdge;
|
||||
|
||||
@@ -35,7 +38,7 @@ public class ModelBakerFace {
|
||||
|
||||
public final int colorIndex;
|
||||
|
||||
public ModelBakerFace(EnumFacing face, boolean isEdge, int colorIndex, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite sprite) {
|
||||
public ModelBakerFace(@Nonnull EnumFacing face, boolean isEdge, int colorIndex, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite sprite) {
|
||||
this.colorIndex = colorIndex;
|
||||
this.face = face;
|
||||
this.isEdge = isEdge;
|
||||
|
||||
@@ -14,6 +14,7 @@ public abstract class ForestryStateMapper implements IStateMapper {
|
||||
|
||||
protected Map<IBlockState, ModelResourceLocation> mapStateModelLocations = Maps.newLinkedHashMap();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getPropertyString(Map<IProperty, Comparable> map) {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
public void handleItemStackForDisplay(ItemStack itemStack) {
|
||||
if (!ItemStack.areItemStacksEqual(itemStack, individualOnDisplayClient)) {
|
||||
individualOnDisplayClient = itemStack;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.config.Config;
|
||||
@@ -52,4 +55,17 @@ public abstract class TileBase extends TileForestry implements IHintSource {
|
||||
}
|
||||
return super.getUnlocalizedTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
|
||||
Block oldBlock = oldState.getBlock();
|
||||
Block newBlock = newState.getBlock();
|
||||
if (oldBlock != newBlock || !(oldBlock instanceof BlockBase) || !(newBlock instanceof BlockBase)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
BlockBase oldBlockBase = (BlockBase) oldBlock;
|
||||
BlockBase newBlockBase = (BlockBase) newBlock;
|
||||
return oldState.getValue(oldBlockBase.getTypeProperty()) != newState.getValue(newBlockBase.getTypeProperty());
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public abstract class TileForestry extends TileEntity implements IStreamable, IE
|
||||
this.orientation = orientation;
|
||||
this.setNeedsNetworkUpdate();
|
||||
worldObj.notifyBlockOfStateChange(getPos(), BlockUtil.getBlock(worldObj, getPos()));
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
}
|
||||
|
||||
protected final void setNeedsNetworkUpdate() {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.core.utils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -30,7 +31,6 @@ import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.tiles.TileEngine;
|
||||
import forestry.core.utils.vect.Vect;
|
||||
import forestry.core.utils.vect.VectUtil;
|
||||
@@ -79,41 +79,39 @@ public abstract class BlockUtil {
|
||||
return receptor.canConnectEnergy(side);
|
||||
}
|
||||
|
||||
public static boolean tryPlantPot(World world, BlockPos pos, Block block) {
|
||||
public static boolean tryPlantCocoaPod(World world, BlockPos pos) {
|
||||
|
||||
int direction = getDirectionalMetadata(world, pos);
|
||||
if (direction < 0) {
|
||||
EnumFacing facing = getValidPodFacing(world, pos);
|
||||
if (facing == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
world.setBlockState(pos, block.getStateFromMeta(direction), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
|
||||
IBlockState state = Blocks.cocoa.getDefaultState().withProperty(BlockCocoa.FACING, facing);
|
||||
world.setBlockState(pos, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int getDirectionalMetadata(World world, BlockPos pos) {
|
||||
for (int i = 2; i < 6; i++) {
|
||||
if (!isValidPot(world, pos, EnumFacing.values()[i])) {
|
||||
continue;
|
||||
|
||||
@Nullable
|
||||
public static EnumFacing getValidPodFacing(World world, BlockPos pos) {
|
||||
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
|
||||
if (isValidPodLocation(world, pos, facing)) {
|
||||
return facing;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isValidPot(World world, BlockPos pos, EnumFacing direction) {
|
||||
public static boolean isValidPodLocation(World world, BlockPos pos, EnumFacing direction) {
|
||||
pos = pos.offset(direction);
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (state.getBlock() == Blocks.log) {
|
||||
Block block = state.getBlock();
|
||||
if (block == Blocks.log) {
|
||||
return state.getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.JUNGLE;
|
||||
} else {
|
||||
return state.getBlock().isWood(world, pos);
|
||||
return block.isWood(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getMaturityPod(IBlockState state) {
|
||||
return state.getValue(BlockCocoa.AGE);
|
||||
}
|
||||
|
||||
public static boolean isWoodSlabBlock(Block block, IBlockAccess world, BlockPos pos) {
|
||||
if (block == null || block.isAir(world, pos)) {
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -42,7 +43,7 @@ public class FarmableCocoa implements IFarmable {
|
||||
return null;
|
||||
}
|
||||
int meta = BlockUtil.getBlockMetadata(world, pos);
|
||||
if (BlockUtil.getMaturityPod(BlockUtil.getBlockState(world, pos)) < 2) {
|
||||
if (BlockUtil.getBlockState(world, pos).getValue(BlockCocoa.AGE) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ public class FarmableCocoa implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return BlockUtil.tryPlantPot(world, pos, COCOA_PLANT);
|
||||
return BlockUtil.tryPlantCocoaPod(world, pos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
public void setFarmBlockTexture(EnumFarmBlockTexture farmBlockTexture) {
|
||||
if (this.farmBlockTexture != farmBlockTexture) {
|
||||
this.farmBlockTexture = farmBlockTexture;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
worldObj.markBlockForUpdate(getPos());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ public enum ButterflyDefinition implements IButterflyDefinition {
|
||||
|
||||
String texture = "butterflies/" + uid;
|
||||
|
||||
IAlleleButterflySpeciesBuilder speciesBuilder = ButterflyManager.butterflyFactory.createSpecies("forestry." + uid, unlocalizedName, "Sengir", unlocalizedDescription, Constants.RESOURCE_ID, texture, dominant, branchDefinition.getBranch(), binomial, serumColor);
|
||||
IAlleleButterflySpeciesBuilder speciesBuilder = ButterflyManager.butterflyFactory.createSpecies(Constants.MOD_ID + '.' + uid, unlocalizedName, "Sengir", unlocalizedDescription, Constants.RESOURCE_ID, texture, dominant, branchDefinition.getBranch(), binomial, serumColor);
|
||||
speciesBuilder.setRarity(rarity);
|
||||
setSpeciesProperties(speciesBuilder);
|
||||
this.species = speciesBuilder.build();
|
||||
|
||||
Reference in new issue
Block a user