mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 11:49:14 +00:00
Add cocoons and fix bugs
This commit is contained in:
1 parent
c4f447aa67
commit
5b42b5fbae
37 files changed
+831
-54
No files matched your search
@@ -66,6 +66,11 @@ public interface IAlleleButterflySpecies extends IAlleleSpecies {
|
||||
|
||||
ISpriteProvider getSpriteProvider();
|
||||
|
||||
/**
|
||||
* @return the IButterflyCocoonProvider
|
||||
*/
|
||||
IButterflyCocoonProvider getCocoonProvider();
|
||||
|
||||
/**
|
||||
* @return The modid from the mod of the species.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import forestry.api.genetics.IHousing;
|
||||
|
||||
public interface IButterflyCocoon extends IHousing{
|
||||
|
||||
IButterfly getCaterpillar();
|
||||
|
||||
void setCaterpillar(IButterfly butterfly);
|
||||
|
||||
IButterflyNursery getNursery();
|
||||
|
||||
void setNursery(IButterflyNursery nursery);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
public interface IButterflyCocoonProvider {
|
||||
|
||||
String getCocoonTexture(int age);
|
||||
|
||||
}
|
||||
@@ -25,12 +25,13 @@ public interface IButterflyFactory {
|
||||
* @param authority Authority for the binomial name, e.g. "Sengir" on species of base Forestry.
|
||||
* @param unlocalizedDescription Unlocalized description for this species
|
||||
* @param modID The modID form the mod of the butterfly
|
||||
* @param texturePath String texture path for this butterfly e.g. "forestry:textures/entities/butterfly/..."
|
||||
* @param texturePath String texture path for this butterfly e.g. "forestry:butterfly/..."
|
||||
* @param dominant Whether this species is genetically dominant (false means it is recessive)
|
||||
* @param branch Classification of this species
|
||||
* @param binomial Binomial name of the species sans genus. "humboldti" will have the bee species flavour name be "Apis humboldti". Feel free to use fun names or null.
|
||||
* @param serumColour The color of this butterfly's serum.
|
||||
* @param cocoonProvider A IButterflyCocoonProvider for the butterfly
|
||||
* @return a new butterfly species allele.
|
||||
*/
|
||||
IAlleleButterflySpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean dominant, IClassification branch, String binomial, Color serumColour);
|
||||
IAlleleButterflySpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean dominant, IClassification branch, String binomial, Color serumColour, IButterflyCocoonProvider cocoonProvider);
|
||||
}
|
||||
@@ -53,6 +53,8 @@ public interface IButterflyRoot extends ISpeciesRoot {
|
||||
* @return butterfly entity on success, null otherwise.
|
||||
*/
|
||||
EntityLiving spawnButterflyInWorld(World world, IButterfly butterfly, double x, double y, double z);
|
||||
|
||||
boolean plantCocoon(World world, IButterflyNursery nursery, GameProfile owner);
|
||||
|
||||
/**
|
||||
* @return true if passed item is mated.
|
||||
|
||||
@@ -26,4 +26,8 @@ public interface IEntityButterfly extends IAnimals {
|
||||
ITree getPollen();
|
||||
|
||||
void setPollen(ITree pollen);
|
||||
|
||||
boolean canMateWith(IEntityButterfly butterfly);
|
||||
|
||||
boolean canMate();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
|
||||
|
||||
// Entities are not attacked if they wear a full set of apiarist's armor.
|
||||
int count = BeeManager.armorApiaristHelper.wearsItems(entity, getUID(), true);
|
||||
damage -= (count * 2);
|
||||
damage -= count * 2;
|
||||
if (damage <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public abstract class HiveGen implements IHiveGen {
|
||||
public boolean canReplace(World world, BlockPos pos) {
|
||||
Block block = BlockUtil.getBlock(world, pos);
|
||||
Material material = block.getMaterial();
|
||||
return material.isReplaceable() && !material.isLiquid() ||
|
||||
material == Material.air ||
|
||||
return block.isReplaceable(world, pos) && !material.isLiquid() ||
|
||||
block.isAir(world, pos) ||
|
||||
material == Material.plants;
|
||||
}
|
||||
}
|
||||
@@ -76,8 +76,11 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP
|
||||
|
||||
public BlockForestryLeaves() {
|
||||
super(Material.leaves, false);
|
||||
this.setCreativeTab(Tabs.tabArboriculture);
|
||||
setCreativeTab(Tabs.tabArboriculture);
|
||||
setStepSound(soundTypeGrass);
|
||||
setTickRandomly(true);
|
||||
setHardness(0.2F);
|
||||
setLightOpacity(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,8 +22,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -59,7 +57,6 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.ColourUtil;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
public class TileLeaves extends TileTreeContainer implements IPollinatable, IFruitBearer, IButterflyNursery, IRipeningPacketReceiver {
|
||||
|
||||
@@ -458,28 +455,14 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
IButterflyGenome caterpillarGenome = caterpillar.getGenome();
|
||||
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
|
||||
|
||||
if (maturationTime >= caterpillarMatureTime && caterpillar.canTakeFlight(worldObj, getPos().getX(), getPos().getY(), getPos().getZ())) {
|
||||
if (worldObj.isAirBlock(getPos().add(-1, 0, 0))) {
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos().add(-1, 0, 0));
|
||||
} else if (worldObj.isAirBlock(getPos().add(1, 0, 0))) {
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos().add(1, 0, 0));
|
||||
} else if (worldObj.isAirBlock(getPos().add(0, 0, -1))) {
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos().add(0, 0, -1));
|
||||
} else if (worldObj.isAirBlock(getPos().add(0, 0, 1))) {
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos().add(0, 0, 1));
|
||||
}
|
||||
if (maturationTime >= caterpillarMatureTime) {
|
||||
ButterflyManager.butterflyRoot.plantCocoon(worldObj, this, getOwner());
|
||||
setCaterpillar(null);
|
||||
} else if (!wasDestroyed && isDestroyed(tree, damage)) {
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
if (ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ()) != null) {
|
||||
Log.trace("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
return getPos();
|
||||
|
||||
@@ -18,7 +18,6 @@ import java.util.Arrays;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package forestry.core.render;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class EmptyStateMapper implements IStateMapper {
|
||||
|
||||
public static final EmptyStateMapper instance = new EmptyStateMapper();
|
||||
|
||||
private EmptyStateMapper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map putStateModelLocations(Block block) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
@@ -51,6 +52,7 @@ import forestry.lepidopterology.items.ItemButterflyGE;
|
||||
import forestry.lepidopterology.items.ItemRegistryLepidopterology;
|
||||
import forestry.lepidopterology.proxy.ProxyLepidopterology;
|
||||
import forestry.lepidopterology.recipes.MatingRecipe;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -88,6 +90,9 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
ButterflyBranchDefinition.createAlleles();
|
||||
AlleleButterflyEffect.createAlleles();
|
||||
|
||||
GameRegistry.registerTileEntity(TileCocoon.class, "forestry.Cocoon");
|
||||
proxy.preInitializeRendering();
|
||||
|
||||
blocks.lepidopterology.addDefinitions(BlockTypeLepidopterologyTesr.VALUES);
|
||||
}
|
||||
@@ -108,7 +113,6 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
PluginCore.rootCommand.addChildCommand(new CommandButterfly());
|
||||
|
||||
EntityUtil.registerEntity(EntityButterfly.class, "butterflyGE", 0, 0x000000, 0xffffff, 50, 1, true);
|
||||
proxy.initializeRendering();
|
||||
|
||||
MothDefinition.initMoths();
|
||||
ButterflyDefinition.initButterflies();
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.EmptyStateMapper;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockCocoon extends Block implements ITileEntityProvider, IStateMapperRegister {
|
||||
|
||||
public BlockCocoon() {
|
||||
super(Material.leaves);
|
||||
setTickRandomly(true);
|
||||
setStepSound(soundTypeGrass);
|
||||
setCreativeTab(Tabs.tabLepidopterology);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
TileCocoon tileCocoon = TileUtil.getTile(world, pos, TileCocoon.class);
|
||||
if (tileCocoon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tileCocoon.isInvalid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (world.rand.nextFloat() > 0.1) {
|
||||
return;
|
||||
}
|
||||
tileCocoon.onBlockTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileCocoon();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state){
|
||||
setBlockBoundsBasedOnState(worldIn, pos);
|
||||
return super.getCollisionBoundingBox(worldIn, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos){
|
||||
setBlockBoundsBasedOnState(worldIn, pos);
|
||||
return super.getSelectedBoundingBox(worldIn, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos){
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos);
|
||||
//int a = iblockstate.getValue(AGE);
|
||||
//setBlockBounds((8.0F - f) / 16.0F, (12.0F - (float)k) / 16.0F, (15.0F - (float)j) / 16.0F, (8.0F + f) / 16.0F, 0.75F, 0.9375F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return getMetaFromState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
|
||||
super.getSubBlocks(itemIn, tab, list);
|
||||
list.add(new ItemStack(itemIn, 1, 1));
|
||||
list.add(new ItemStack(itemIn, 1, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, EmptyStateMapper.instance);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,8 +15,10 @@ import forestry.core.items.ItemBlockForestry;
|
||||
|
||||
public class BlockRegistryLepidopterology extends BlockRegistry {
|
||||
public final BlockLepidopterology lepidopterology;
|
||||
public final BlockCocoon cocoon;
|
||||
|
||||
public BlockRegistryLepidopterology() {
|
||||
lepidopterology = registerBlock(new BlockLepidopterology(), ItemBlockForestry.class, "lepidopterology");
|
||||
cocoon = registerBlock(new BlockCocoon(), ItemBlockForestry.class, "cocoon");
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import java.util.List;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
@@ -17,6 +18,10 @@ import forestry.lepidopterology.PluginLepidopterology;
|
||||
|
||||
public class AIButterflyMate extends AIButterflyInteract {
|
||||
|
||||
private EntityButterfly targetMate;
|
||||
private double moveSpeed;
|
||||
|
||||
|
||||
public AIButterflyMate(EntityButterfly entity) {
|
||||
super(entity);
|
||||
}
|
||||
@@ -26,6 +31,9 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
*/
|
||||
@Override
|
||||
protected boolean canInteract() {
|
||||
if(entity.getButterfly().getMate() == null && entity.canMate()){
|
||||
return true;
|
||||
}
|
||||
if (entity.cooldownEgg > 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -44,20 +52,79 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
@Override
|
||||
public void updateTask() {
|
||||
if (continueExecuting()) {
|
||||
IPollinatable tile = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest);
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(nursery));
|
||||
// Log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getRNG().nextFloat() < 1.0f / entity.getButterfly().getGenome().getFertility()) {
|
||||
entity.setHealth(0);
|
||||
if(entity.getButterfly().getMate() == null){
|
||||
entity.getLookHelper().setLookPositionWithEntity(targetMate, 10.0F, entity.getVerticalFaceSpeed());
|
||||
entity.getNavigator().tryMoveToEntityLiving(targetMate, 0.7D);
|
||||
|
||||
if (entity.cooldownMate <= 0 && entity.getDistanceSqToEntity(targetMate) < 9.0D){
|
||||
entity.getButterfly().mate(targetMate.getButterfly());
|
||||
entity.cooldownMate = EntityButterfly.COOLDOWNS;
|
||||
}
|
||||
}else{
|
||||
IPollinatable tile = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest);
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(nursery));
|
||||
// Log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getRNG().nextFloat() < 1.0f / entity.getButterfly().getGenome().getFertility()) {
|
||||
entity.setHealth(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
setHasInteracted();
|
||||
entity.cooldownEgg = EntityButterfly.COOLDOWNS;
|
||||
}
|
||||
setHasInteracted();
|
||||
entity.cooldownEgg = EntityButterfly.COOLDOWNS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute(){
|
||||
if(!super.shouldExecute()){
|
||||
return false;
|
||||
}
|
||||
if(entity.getButterfly().getMate() == null){
|
||||
if (!entity.canMate()){
|
||||
return false;
|
||||
}else{
|
||||
targetMate = getNearbyMate();
|
||||
return targetMate != null;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueExecuting(){
|
||||
if(!super.continueExecuting()){
|
||||
return false;
|
||||
}
|
||||
if(entity.getButterfly().getMate() == null){
|
||||
return targetMate.isEntityAlive() && targetMate.canMate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTask(){
|
||||
super.resetTask();
|
||||
|
||||
targetMate = null;
|
||||
}
|
||||
|
||||
private EntityButterfly getNearbyMate(){
|
||||
float f = 8.0F;
|
||||
List<EntityButterfly> nextButterflys = entity.worldObj.getEntitiesWithinAABB(EntityButterfly.class, this.entity.getEntityBoundingBox().expand(f, f, f));
|
||||
double d0 = Double.MAX_VALUE;
|
||||
EntityButterfly nextButterfly = null;
|
||||
|
||||
for (EntityButterfly butterfly : nextButterflys){
|
||||
if (this.entity.canMateWith(butterfly) && this.entity.getDistanceSqToEntity(butterfly) < d0){
|
||||
nextButterfly = butterfly;
|
||||
d0 = this.entity.getDistanceSqToEntity(butterfly);
|
||||
}
|
||||
}
|
||||
|
||||
return nextButterfly;
|
||||
}
|
||||
}
|
||||
@@ -44,14 +44,14 @@ public class AIButterflyRest extends AIButterflyBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
y--;
|
||||
pos = pos.add(x, -1, z);
|
||||
if (entity.worldObj.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
if (entity.worldObj.getBlockState(pos).getBlock().getMaterial().isLiquid()) {
|
||||
return false;
|
||||
}
|
||||
if (!entity.getButterfly().isAcceptedEnvironment(entity.worldObj, x, y, z)) {
|
||||
if (!entity.getButterfly().isAcceptedEnvironment(entity.worldObj, x, pos.getY(), z)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
|
||||
public int cooldownPollination = 0;
|
||||
public int cooldownEgg = 0;
|
||||
public int cooldownMate = 0;
|
||||
|
||||
// Client Rendering
|
||||
private IAlleleButterflySpecies species;
|
||||
@@ -449,6 +450,9 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
if (cooldownPollination > 0) {
|
||||
cooldownPollination--;
|
||||
}
|
||||
if (cooldownMate > 0) {
|
||||
cooldownMate--;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -515,4 +519,20 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
IButterfly butterfly = root.templateAsIndividual(template);
|
||||
return root.getMemberStack(butterfly, EnumFlutterType.BUTTERFLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMateWith(IEntityButterfly butterfly) {
|
||||
if(butterfly == null || butterfly.getButterfly() == null || butterfly.getButterfly().getMate() != null){
|
||||
return false;
|
||||
}
|
||||
if (getButterfly() == null || getButterfly().getMate() != null) {
|
||||
return false;
|
||||
}
|
||||
return !getButterfly().isGeneticEqual(butterfly.getButterfly());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMate() {
|
||||
return cooldownMate <= 0;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoonProvider;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.alleles.AlleleHelper;
|
||||
@@ -314,8 +315,9 @@ public enum ButterflyDefinition implements IButterflyDefinition {
|
||||
String unlocalizedDescription = "for.description." + uid;
|
||||
|
||||
String texture = "butterflies/" + uid;
|
||||
IButterflyCocoonProvider cocoonProvider = new DefaultCocoonProvider();
|
||||
|
||||
IAlleleButterflySpeciesBuilder speciesBuilder = ButterflyManager.butterflyFactory.createSpecies(Constants.MOD_ID + '.' + 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, cocoonProvider);
|
||||
speciesBuilder.setRarity(rarity);
|
||||
setSpeciesProperties(speciesBuilder);
|
||||
this.species = speciesBuilder.build();
|
||||
|
||||
@@ -14,12 +14,13 @@ import java.awt.Color;
|
||||
|
||||
import forestry.api.genetics.IClassification;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
import forestry.api.lepidopterology.IButterflyCocoonProvider;
|
||||
import forestry.api.lepidopterology.IButterflyFactory;
|
||||
import forestry.lepidopterology.genetics.alleles.AlleleButterflySpecies;
|
||||
|
||||
public class ButterflyFactory implements IButterflyFactory {
|
||||
@Override
|
||||
public IAlleleButterflySpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean isDominant, IClassification branch, String binomial, Color serumColour) {
|
||||
return new AlleleButterflySpecies(uid, unlocalizedName, authority, unlocalizedDescription, modID, texturePath, isDominant, branch, binomial, serumColour);
|
||||
public IAlleleButterflySpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean isDominant, IClassification branch, String binomial, Color serumColour, IButterflyCocoonProvider cocoonProvider) {
|
||||
return new AlleleButterflySpecies(uid, unlocalizedName, authority, unlocalizedDescription, modID, texturePath, isDominant, branch, binomial, serumColour, cocoonProvider);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ package forestry.lepidopterology.genetics;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.api.genetics.IAlleleFloat;
|
||||
import forestry.api.genetics.IAlleleFlowers;
|
||||
|
||||
@@ -16,9 +16,14 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -36,12 +41,16 @@ import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyMutation;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.api.lepidopterology.IButterflyRoot;
|
||||
import forestry.api.lepidopterology.ILepidopteristTracker;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.SpeciesRoot;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.EntityUtil;
|
||||
import forestry.lepidopterology.PluginLepidopterology;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
|
||||
public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
|
||||
|
||||
@@ -162,6 +171,52 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
|
||||
public EntityButterfly spawnButterflyInWorld(World world, IButterfly butterfly, double x, double y, double z) {
|
||||
return EntityUtil.spawnEntity(world, new EntityButterfly(world, butterfly), x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantCocoon(World world, IButterflyNursery nursery, GameProfile owner) {
|
||||
BlockPos pos = getNextPos(world, nursery.getCoordinates());
|
||||
IBlockState state = PluginLepidopterology.blocks.cocoon.getDefaultState();
|
||||
boolean placed = world.setBlockState(pos, state, Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
|
||||
if (!placed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Block block = BlockUtil.getBlock(world, pos);
|
||||
if (PluginLepidopterology.blocks.cocoon != block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileCocoon)) {
|
||||
world.setBlockToAir(pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
TileCocoon cocoon = (TileCocoon) tile;
|
||||
cocoon.setCaterpillar(nursery.getCaterpillar());
|
||||
cocoon.setOwner(owner);
|
||||
cocoon.setNursery(nursery);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private BlockPos getNextPos(World world, BlockPos pos){
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
|
||||
do {
|
||||
y--;
|
||||
} while (!canReplace(world, new BlockPos(x, y, z)));
|
||||
|
||||
return new BlockPos(x, y, z);
|
||||
}
|
||||
|
||||
private boolean canReplace(World world, BlockPos pos) {
|
||||
Block block = BlockUtil.getBlock(world, pos);
|
||||
Material material = block.getMaterial();
|
||||
return block.isReplaceable(world, pos) && !material.isLiquid() || block.isAir(world, pos) || material == Material.plants;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMated(ItemStack stack) {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.genetics;
|
||||
|
||||
import forestry.api.lepidopterology.IButterflyCocoonProvider;
|
||||
|
||||
public class DefaultCocoonProvider implements IButterflyCocoonProvider {
|
||||
|
||||
@Override
|
||||
public String getCocoonTexture(int age) {
|
||||
return "textures/blocks/lepidopterology/cocoons/default_" + age + ".png";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoonProvider;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.alleles.AlleleHelper;
|
||||
@@ -58,8 +59,10 @@ public enum MothDefinition implements IButterflyDefinition {
|
||||
String unlocalizedDescription = "for.description." + uid;
|
||||
|
||||
String texture = "butterflies/" + uid;
|
||||
|
||||
IButterflyCocoonProvider cocoonProvider = new DefaultCocoonProvider();
|
||||
|
||||
IAlleleButterflySpeciesBuilder speciesBuilder = ButterflyManager.butterflyFactory.createSpecies("forestry." + uid, unlocalizedName, "Sengir", unlocalizedDescription, Constants.RESOURCE_ID, texture, dominant, branchDefinition.getBranch(), binomial, serumColor);
|
||||
IAlleleButterflySpeciesBuilder speciesBuilder = ButterflyManager.butterflyFactory.createSpecies("forestry." + uid, unlocalizedName, "Sengir", unlocalizedDescription, Constants.RESOURCE_ID, texture, dominant, branchDefinition.getBranch(), binomial, serumColor, cocoonProvider);
|
||||
speciesBuilder.setRarity(rarity);
|
||||
speciesBuilder.setNocturnal();
|
||||
setSpeciesProperties(speciesBuilder);
|
||||
|
||||
+12
-3
@@ -37,6 +37,7 @@ import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
import forestry.api.lepidopterology.IButterflyCocoonProvider;
|
||||
import forestry.api.lepidopterology.IButterflyRoot;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.alleles.AlleleSpecies;
|
||||
@@ -54,13 +55,16 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
|
||||
|
||||
private final Map<ItemStack, Float> butterflyLoot = new HashMap<>();
|
||||
private final Map<ItemStack, Float> caterpillarLoot = new HashMap<>();
|
||||
|
||||
private final IButterflyCocoonProvider cocoonProvider;
|
||||
|
||||
public AlleleButterflySpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean isDominant, IClassification branch, String binomial, Color serumColour) {
|
||||
public AlleleButterflySpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, String modID, String texturePath, boolean isDominant, IClassification branch, String binomial, Color serumColour, IButterflyCocoonProvider cocoonProvider) {
|
||||
super(uid, unlocalizedName, authority, unlocalizedDescription, isDominant, branch, binomial);
|
||||
this.serumColour = serumColour;
|
||||
|
||||
this.modID = modID;
|
||||
this.texture = texturePath;
|
||||
this.cocoonProvider = cocoonProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,9 +113,9 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
|
||||
|
||||
@Override
|
||||
public String getItemTexture() {
|
||||
return getModID() + ":" + "items/" + texture;
|
||||
return getModID() + ":items/" + texture;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EnumSet<BiomeDictionary.Type> getSpawnBiomes() {
|
||||
return spawnBiomes;
|
||||
@@ -219,4 +223,9 @@ public class AlleleButterflySpecies extends AlleleSpecies implements IAlleleButt
|
||||
public String getModID() {
|
||||
return modID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IButterflyCocoonProvider getCocoonProvider() {
|
||||
return cocoonProvider;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,6 @@ package forestry.lepidopterology.proxy;
|
||||
|
||||
public class ProxyLepidopterology {
|
||||
|
||||
public void initializeRendering() {
|
||||
public void preInitializeRendering() {
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.proxy;
|
||||
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import forestry.core.models.ModelIndex;
|
||||
import forestry.core.models.ModelManager;
|
||||
@@ -17,12 +18,15 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import forestry.lepidopterology.render.ModelButterflyItem;
|
||||
import forestry.lepidopterology.render.RenderButterflyEntity;
|
||||
import forestry.lepidopterology.render.RendererCocoon;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
|
||||
public class ProxyLepidopterologyClient extends ProxyLepidopterology {
|
||||
|
||||
@Override
|
||||
public void initializeRendering() {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, new RenderButterflyEntity());
|
||||
public void preInitializeRendering() {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, new RenderButterflyEntity.Factory());
|
||||
Proxies.render.registerModel(new ModelIndex(ModelManager.getInstance().getModelLocation("butterflyGE"), new ModelButterflyItem()));
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileCocoon.class, new RendererCocoon());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package forestry.lepidopterology.render;
|
||||
|
||||
import net.minecraft.client.model.ModelBase;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
|
||||
public class ModelCocoon extends ModelBase {
|
||||
public ModelRenderer cocoonbody_0_age_0;
|
||||
public ModelRenderer cocoonbody_1_age_0;
|
||||
public ModelRenderer cocoonbody_2_age_0;
|
||||
public ModelRenderer cocoonbody_3_age_0;
|
||||
public ModelRenderer cocoonbody_4_age_0;
|
||||
public ModelRenderer cocoonbody_5_age_0;
|
||||
public ModelRenderer cocoonbody_0_age_1;
|
||||
public ModelRenderer cocoonbody_1_age_1;
|
||||
public ModelRenderer cocoonbody_2_age_1;
|
||||
public ModelRenderer cocoonbody_3_age_1;
|
||||
public ModelRenderer cocoonbody_4_age_1;
|
||||
public ModelRenderer cocoonbody_5_age_1;
|
||||
public ModelRenderer cocoonbody_0_age_2;
|
||||
public ModelRenderer cocoonbody_1_age_2;
|
||||
public ModelRenderer cocoonbody_2_age_2;
|
||||
public ModelRenderer cocoonbody_3_age_2;
|
||||
public ModelRenderer cocoonbody_4_age_2;
|
||||
public ModelRenderer cocoonbody_5_age_2;
|
||||
|
||||
|
||||
public ModelCocoon() {
|
||||
this.textureWidth = 64;
|
||||
this.textureHeight = 32;
|
||||
this.cocoonbody_1_age_0 = new ModelRenderer(this, 48, 0);
|
||||
this.cocoonbody_1_age_0.setRotationPoint(-1.5F, 9.0F, -1.5F);
|
||||
this.cocoonbody_1_age_0.addBox(0.0F, 0.0F, 0.0F, 4, 1, 4, 0.0F);
|
||||
this.cocoonbody_0_age_0 = new ModelRenderer(this, 31, 0);
|
||||
this.cocoonbody_0_age_0.setRotationPoint(-0.5F, 8.0F, -0.5F);
|
||||
this.cocoonbody_0_age_0.addBox(0.0F, 0.0F, 0.0F, 2, 1, 2, 0.0F);
|
||||
this.cocoonbody_2_age_0 = new ModelRenderer(this, 0, 18);
|
||||
this.cocoonbody_2_age_0.setRotationPoint(-2.5F, 10.0F, -2.5F);
|
||||
this.cocoonbody_2_age_0.addBox(0.0F, 0.0F, 0.0F, 6, 8, 6, 0.0F);
|
||||
this.cocoonbody_4_age_0 = new ModelRenderer(this, 0, 7);
|
||||
this.cocoonbody_4_age_0.setRotationPoint(-2.5F, 18.0F, -2.5F);
|
||||
this.cocoonbody_4_age_0.addBox(0.0F, 0.0F, 0.0F, 6, 1, 5, 0.0F);
|
||||
this.cocoonbody_3_age_0 = new ModelRenderer(this, 30, 24);
|
||||
this.cocoonbody_3_age_0.setRotationPoint(-2.5F, 11.0F, -3.5F);
|
||||
this.cocoonbody_3_age_0.addBox(0.0F, 0.0F, 0.0F, 6, 7, 1, 0.0F);
|
||||
this.cocoonbody_5_age_0 = new ModelRenderer(this, 0, 0);
|
||||
this.cocoonbody_5_age_0.setRotationPoint(-1.5F, 19.0F, -1.0F);
|
||||
this.cocoonbody_5_age_0.addBox(0.0F, 0.0F, 0.0F, 4, 1, 2, 0.0F);
|
||||
this.cocoonbody_2_age_1 = new ModelRenderer(this, 0, 18);
|
||||
this.cocoonbody_2_age_1.setRotationPoint(-2.5F, 10.0F, -2.5F);
|
||||
this.cocoonbody_2_age_1.addBox(0.0F, 0.0F, 0.0F, 4, 6, 4, 0.0F);
|
||||
this.cocoonbody_0_age_1 = new ModelRenderer(this, 31, 0);
|
||||
this.cocoonbody_0_age_1.setRotationPoint(-1.0F, 8.0F, -1.0F);
|
||||
this.cocoonbody_0_age_1.addBox(0.0F, 0.0F, 0.0F, 1, 1, 1, 0.0F);
|
||||
this.cocoonbody_3_age_1 = new ModelRenderer(this, 30, 24);
|
||||
this.cocoonbody_3_age_1.setRotationPoint(-2.5F, 11.0F, -3.5F);
|
||||
this.cocoonbody_3_age_1.addBox(0.0F, 0.0F, 0.0F, 4, 5, 1, 0.0F);
|
||||
this.cocoonbody_1_age_1 = new ModelRenderer(this, 48, 0);
|
||||
this.cocoonbody_1_age_1.setRotationPoint(-1.5F, 9.0F, -1.5F);
|
||||
this.cocoonbody_1_age_1.addBox(0.0F, 0.0F, 0.0F, 2, 1, 2, 0.0F);
|
||||
this.cocoonbody_5_age_1 = new ModelRenderer(this, 0, 0);
|
||||
this.cocoonbody_5_age_1.setRotationPoint(-1.0F, 17.0F, -2.5F);
|
||||
this.cocoonbody_5_age_1.addBox(0.0F, 0.0F, 0.0F, 2, 1, 3, 0.0F);
|
||||
this.cocoonbody_4_age_1 = new ModelRenderer(this, 0, 7);
|
||||
this.cocoonbody_4_age_1.setRotationPoint(-1.5F, 16.0F, -3.0F);
|
||||
this.cocoonbody_4_age_1.addBox(0.0F, 0.0F, 0.0F, 3, 1, 4, 0.0F);
|
||||
this.cocoonbody_3_age_2 = new ModelRenderer(this, 30, 24);
|
||||
this.cocoonbody_3_age_2.setRotationPoint(-2.0F, 11.0F, -3.0F);
|
||||
this.cocoonbody_3_age_2.addBox(0.0F, 0.0F, 0.0F, 3, 3, 1, 0.0F);
|
||||
this.cocoonbody_2_age_2 = new ModelRenderer(this, 0, 18);
|
||||
this.cocoonbody_2_age_2.setRotationPoint(-2.0F, 10.0F, -2.0F);
|
||||
this.cocoonbody_2_age_2.addBox(0.0F, 0.0F, 0.0F, 3, 4, 3, 0.0F);
|
||||
this.cocoonbody_4_age_2 = new ModelRenderer(this, 0, 7);
|
||||
this.cocoonbody_4_age_2.setRotationPoint(-1.5F, 14.0F, -2.5F);
|
||||
this.cocoonbody_4_age_2.addBox(0.0F, 0.0F, 0.0F, 2, 1, 3, 0.0F);
|
||||
this.cocoonbody_1_age_2 = new ModelRenderer(this, 48, 0);
|
||||
this.cocoonbody_1_age_2.setRotationPoint(-1.5F, 9.0F, -1.5F);
|
||||
this.cocoonbody_1_age_2.addBox(0.0F, 0.0F, 0.0F, 2, 1, 2, 0.0F);
|
||||
this.cocoonbody_5_age_2 = new ModelRenderer(this, 0, 0);
|
||||
this.cocoonbody_5_age_2.setRotationPoint(-1.0F, 15.0F, -2.0F);
|
||||
this.cocoonbody_5_age_2.addBox(0.0F, 0.0F, 0.0F, 1, 1, 2, 0.0F);
|
||||
this.cocoonbody_0_age_2 = new ModelRenderer(this, 31, 0);
|
||||
this.cocoonbody_0_age_2.setRotationPoint(-1.0F, 8.0F, -1.0F);
|
||||
this.cocoonbody_0_age_2.addBox(0.0F, 0.0F, 0.0F, 1, 1, 1, 0.0F);
|
||||
}
|
||||
|
||||
public void renderCucoon(int age){
|
||||
float pixel = 0.0625F;
|
||||
if(age == 0){
|
||||
this.cocoonbody_1_age_0.render(pixel);
|
||||
this.cocoonbody_0_age_0.render(pixel);
|
||||
this.cocoonbody_2_age_0.render(pixel);
|
||||
this.cocoonbody_4_age_0.render(pixel);
|
||||
this.cocoonbody_3_age_0.render(pixel);
|
||||
this.cocoonbody_5_age_0.render(pixel);
|
||||
}else if(age == 1){
|
||||
this.cocoonbody_2_age_1.render(pixel);
|
||||
this.cocoonbody_0_age_1.render(pixel);
|
||||
this.cocoonbody_3_age_1.render(pixel);
|
||||
this.cocoonbody_1_age_1.render(pixel);
|
||||
this.cocoonbody_5_age_1.render(pixel);
|
||||
this.cocoonbody_4_age_1.render(pixel);
|
||||
}else if(age == 2){
|
||||
this.cocoonbody_3_age_2.render(pixel);
|
||||
this.cocoonbody_2_age_2.render(pixel);
|
||||
this.cocoonbody_4_age_2.render(pixel);
|
||||
this.cocoonbody_1_age_2.render(pixel);
|
||||
this.cocoonbody_5_age_2.render(pixel);
|
||||
this.cocoonbody_0_age_2.render(pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,19 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.render;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderLiving;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fml.client.registry.IRenderFactory;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
|
||||
public class RenderButterflyEntity extends RenderLiving<EntityButterfly> {
|
||||
|
||||
private final ModelButterfly butterflyModel;
|
||||
|
||||
public RenderButterflyEntity() {
|
||||
super(Minecraft.getMinecraft().getRenderManager(), new ModelButterfly(), 0.25f);
|
||||
public RenderButterflyEntity(RenderManager manager) {
|
||||
super(manager, new ModelButterfly(), 0.25f);
|
||||
butterflyModel = (ModelButterfly) mainModel;
|
||||
}
|
||||
|
||||
@@ -49,4 +50,12 @@ public class RenderButterflyEntity extends RenderLiving<EntityButterfly> {
|
||||
return entity.getWingFlap(partialTickTime);
|
||||
}
|
||||
|
||||
public static class Factory implements IRenderFactory<EntityButterfly>{
|
||||
@Override
|
||||
public Render<? super EntityButterfly> createRenderFor(RenderManager manager) {
|
||||
return new RenderButterflyEntity(manager);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.render;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.lepidopterology.blocks.BlockCocoon;
|
||||
import forestry.lepidopterology.genetics.ButterflyDefinition;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class RendererCocoon extends TileEntitySpecialRenderer<TileCocoon> {
|
||||
|
||||
private static ModelCocoon modelCocoon = new ModelCocoon();
|
||||
|
||||
public RendererCocoon() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileCocoon te, double x, double y, double z, float partialTicks, int destroyStage) {
|
||||
IBlockState state = te.getWorld().getBlockState(te.getPos());
|
||||
|
||||
if(state == null || !(state.getBlock() instanceof BlockCocoon)){
|
||||
return;
|
||||
}
|
||||
IButterfly butterfly = te.getCaterpillar();
|
||||
if(butterfly == null){
|
||||
butterfly = ButterflyDefinition.Brimstone.getIndividual();
|
||||
}
|
||||
render(butterfly, te.getAge(), x, y, z);
|
||||
}
|
||||
|
||||
private static void render(IButterfly butterfly, int age, double x, double y, double z){
|
||||
IAlleleButterflySpecies species = butterfly.getGenome().getPrimary();
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
|
||||
GL11.glRotated(180, 0F, 0F, 1F);
|
||||
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
|
||||
Proxies.render.bindTexture(new ResourceLocation(species.getModID(), species.getCocoonProvider().getCocoonTexture(age)));
|
||||
modelCocoon.renderCucoon(age);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.access.IOwnable;
|
||||
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.utils.Log;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.lepidopterology.genetics.Butterfly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IButterflyCocoon {
|
||||
|
||||
private int age;
|
||||
private int maturationTime;
|
||||
private IButterfly caterpillar;
|
||||
private GameProfile owner;
|
||||
private BlockPos nursery;
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
if (nbttagcompound.hasKey("Caterpillar")) {
|
||||
caterpillar = new Butterfly(nbttagcompound.getCompoundTag("Caterpillar"));
|
||||
}
|
||||
if (nbttagcompound.hasKey("owner")) {
|
||||
owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"));
|
||||
}
|
||||
if(nbttagcompound.hasKey("nursery")){
|
||||
NBTTagCompound nbt = nbttagcompound.getCompoundTag("nursery");
|
||||
int x = nbt.getInteger("x");
|
||||
int y = nbt.getInteger("y");
|
||||
int z = nbt.getInteger("z");
|
||||
nursery = new BlockPos(x, y, z);
|
||||
}
|
||||
age = nbttagcompound.getInteger("Age");
|
||||
maturationTime = nbttagcompound.getInteger("CATMAT");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
if (caterpillar != null) {
|
||||
NBTTagCompound subcompound = new NBTTagCompound();
|
||||
caterpillar.writeToNBT(subcompound);
|
||||
nbttagcompound.setTag("Caterpillar", subcompound);
|
||||
}
|
||||
if (this.owner != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
PlayerUtil.writeGameProfile(nbt, owner);
|
||||
nbttagcompound.setTag("owner", nbt);
|
||||
}
|
||||
if(nursery != null){
|
||||
BlockPos pos = nursery;
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setInteger("x", pos.getX());
|
||||
nbt.setInteger("y", pos.getY());
|
||||
nbt.setInteger("z", pos.getZ());
|
||||
nbttagcompound.setTag("nursery", nbt);
|
||||
}
|
||||
nbttagcompound.setInteger("Age", age);
|
||||
nbttagcompound.setInteger("CATMAT", maturationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
String speciesUID = "";
|
||||
IButterfly caterpillar = getCaterpillar();
|
||||
if (caterpillar != null) {
|
||||
speciesUID = caterpillar.getIdent();
|
||||
}
|
||||
data.writeUTF(speciesUID);
|
||||
data.writeInt(age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
String speciesUID = data.readUTF();
|
||||
IButterfly caterpillar = getButterfly(speciesUID);
|
||||
setCaterpillar(caterpillar);
|
||||
age = data.readInt();
|
||||
}
|
||||
|
||||
private static IButterfly getButterfly(String speciesUID) {
|
||||
IAllele[] butterflyTemplate = ButterflyManager.butterflyRoot.getTemplate(speciesUID);
|
||||
if (butterflyTemplate == null) {
|
||||
return null;
|
||||
}
|
||||
return ButterflyManager.butterflyRoot.templateAsIndividual(butterflyTemplate);
|
||||
}
|
||||
|
||||
/* IOwnable */
|
||||
@Override
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(GameProfile owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwner(EntityPlayer player) {
|
||||
return player != null && PlayerUtil.isSameGameProfile(player.getGameProfile(), owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return !Block.isEqualTo(oldState.getBlock(), newSate.getBlock());
|
||||
}
|
||||
|
||||
/* INETWORKEDENTITY */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
public void onBlockTick() {
|
||||
maturationTime++;
|
||||
|
||||
IButterflyGenome caterpillarGenome = caterpillar.getGenome();
|
||||
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
|
||||
|
||||
if (maturationTime >= caterpillarMatureTime) {
|
||||
if(age < 2){
|
||||
age++;
|
||||
maturationTime = 0;
|
||||
}else if(caterpillar.canTakeFlight(worldObj, getPos().getX(), getPos().getY(), getPos().getZ())){
|
||||
worldObj.setBlockToAir(getPos());
|
||||
if (worldObj.isAirBlock(getPos())) {
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
if (ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ()) != null) {
|
||||
Log.trace("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
return getPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IButterfly getCaterpillar() {
|
||||
return caterpillar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IButterflyNursery getNursery() {
|
||||
TileEntity nursery = worldObj.getTileEntity(this.nursery);
|
||||
if(nursery instanceof IButterflyNursery){
|
||||
return (IButterflyNursery) nursery;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNursery(IButterflyNursery nursery) {
|
||||
this.nursery = nursery.getCoordinates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCaterpillar(IButterfly butterfly) {
|
||||
this.caterpillar = butterfly;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
private void sendNetworkUpdate() {
|
||||
Proxies.net.sendNetworkPacket(new PacketTileStream(this), worldObj);
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user