mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 03:39:09 +00:00
Add cocoon world genartion with config entry(default false) and add cocoon loot and a greenhouse butterfly hatch
This commit is contained in:
1 parent
bc0d105730
commit
cf23644f45
35 files changed
+748
-61
No files matched your search
@@ -57,7 +57,7 @@ import forestry.plugins.PluginManager;
|
||||
name = Constants.MOD_ID,
|
||||
version = Constants.VERSION,
|
||||
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
|
||||
dependencies = "required-after:Forge@[10.13.4.1566,);"
|
||||
dependencies = "required-after:Forge@[11.15.1.1808,);"
|
||||
+ "after:Buildcraft|Core@[6.1.7,);"
|
||||
+ "after:ExtrabiomesXL;"
|
||||
+ "after:BiomesOPlenty;"
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IGreenhouseState {
|
||||
@@ -22,6 +24,8 @@ public interface IGreenhouseState {
|
||||
float getExactHumidity();
|
||||
|
||||
List<IInternalBlock> getInternalBlocks();
|
||||
|
||||
Collection<IMultiblockComponent> getGreenhouseComponents();
|
||||
|
||||
/**
|
||||
* @return The world in that the greenhouse standing
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@API(apiVersion = "5.0.0", owner = "ForestryAPI|greenhouse", provides = "ForestryAPI|greenhouse")
|
||||
@API(apiVersion = "5.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|greenhouse")
|
||||
package forestry.api.greenhouse;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -10,7 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.lepidopterology;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAlleleButterflyCocoon extends IAllele {
|
||||
|
||||
@@ -18,4 +21,6 @@ public interface IAlleleButterflyCocoon extends IAllele {
|
||||
|
||||
String getCocoonTexture(int age);
|
||||
|
||||
Map<ItemStack, Float> getCocoonLoot();
|
||||
|
||||
}
|
||||
@@ -78,6 +78,12 @@ public interface IButterfly extends IIndividualLiving {
|
||||
*/
|
||||
ItemStack[] getCaterpillarDrop(IButterflyNursery nursery, boolean playerKill, int lootLevel);
|
||||
|
||||
/**
|
||||
* @param cocoon
|
||||
* @return Array of itemstacks to drop on breaking of the cocoon.
|
||||
*/
|
||||
ItemStack[] getCocoonDrop(IButterflyCocoon cocoon);
|
||||
|
||||
/**
|
||||
* Create an exact copy of this butterfly.
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ package forestry.api.lepidopterology;
|
||||
import forestry.api.genetics.IHousing;
|
||||
|
||||
public interface IButterflyCocoon extends IHousing{
|
||||
|
||||
|
||||
IButterfly getCaterpillar();
|
||||
|
||||
void setCaterpillar(IButterfly butterfly);
|
||||
@@ -22,4 +22,6 @@ public interface IButterflyCocoon extends IHousing{
|
||||
|
||||
void setNursery(IButterflyNursery nursery);
|
||||
|
||||
boolean isSolid();
|
||||
|
||||
}
|
||||
@@ -8,6 +8,8 @@ package forestry.api.multiblock;
|
||||
import forestry.api.core.IClimateControlled;
|
||||
import forestry.api.greenhouse.IGreenhouseHousing;
|
||||
import forestry.api.greenhouse.IGreenhouseListener;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> extends IMultiblockComponent {
|
||||
@Override
|
||||
@@ -23,6 +25,10 @@ public interface IGreenhouseComponent<T extends IMultiblockLogicGreenhouse> exte
|
||||
interface Climatiser extends IGreenhouseComponent {
|
||||
<G extends IGreenhouseController & IGreenhouseHousing & IClimateControlled> void changeClimate(int tickCount, G greenhouse);
|
||||
}
|
||||
|
||||
interface ButterflyHatch extends IGreenhouseComponent {
|
||||
ItemStack[] addCocoonLoot(IButterflyCocoon cocoon);
|
||||
}
|
||||
|
||||
interface Active extends IGreenhouseComponent {
|
||||
void updateServer(int tickCount);
|
||||
|
||||
@@ -142,4 +142,4 @@ public class GuiUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -440,6 +440,11 @@ public abstract class ItemStackUtil {
|
||||
List<Stack> stacks = Stack.parseStackStrings(itemStackStrings, missingMetaValue);
|
||||
return getItemStacks(stacks);
|
||||
}
|
||||
|
||||
public static ItemStack parseItemStackString(String itemStackString, int missingMetaValue) {
|
||||
Stack stack = Stack.parseStackString(itemStackString, missingMetaValue);
|
||||
return getItemStack(stack);
|
||||
}
|
||||
|
||||
private static List<ItemStack> getItemStacks(List<Stack> stacks) {
|
||||
List<ItemStack> itemStacks = new ArrayList<>(stacks.size());
|
||||
@@ -453,5 +458,15 @@ public abstract class ItemStackUtil {
|
||||
}
|
||||
return itemStacks;
|
||||
}
|
||||
|
||||
private static ItemStack getItemStack(Stack stack) {
|
||||
Item item = stack.getItem();
|
||||
if (item != null) {
|
||||
int meta = stack.getMeta();
|
||||
ItemStack itemStack = new ItemStack(item, 1, meta);
|
||||
return itemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.greenhouse.IGreenhouseState;
|
||||
import forestry.api.greenhouse.IInternalBlock;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.greenhouse.multiblock.GreenhouseController;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -25,16 +27,18 @@ public final class GreenhouseState implements IGreenhouseState {
|
||||
private final float temperature;
|
||||
private final World world;
|
||||
private final List<IInternalBlock> internalBlocks;
|
||||
private final Collection<IMultiblockComponent> greenhouseComponents;
|
||||
|
||||
public GreenhouseState(World world, float humidity, float temperature, List<IInternalBlock> internalBlocks) {
|
||||
public GreenhouseState(World world, float humidity, float temperature, List<IInternalBlock> internalBlocks, Collection<IMultiblockComponent> greenhouseComponents) {
|
||||
this.world = world;
|
||||
this.humidity = humidity;
|
||||
this.temperature = temperature;
|
||||
this.internalBlocks = internalBlocks;
|
||||
this.greenhouseComponents = greenhouseComponents;
|
||||
}
|
||||
|
||||
public GreenhouseState(GreenhouseController controller) {
|
||||
this(controller.getWorld(), controller.getExactHumidity(), controller.getExactTemperature(), controller.getInternalBlocks());
|
||||
this(controller.getWorld(), controller.getExactHumidity(), controller.getExactTemperature(), controller.getInternalBlocks(), controller.getComponents());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,5 +70,10 @@ public final class GreenhouseState implements IGreenhouseState {
|
||||
public List<IInternalBlock> getInternalBlocks() {
|
||||
return internalBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IMultiblockComponent> getGreenhouseComponents() {
|
||||
return greenhouseComponents;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import forestry.greenhouse.logics.GreenhouseLogicGreenhouseDoor;
|
||||
import forestry.greenhouse.logics.GreenhouseLogicGreenhouseEffect;
|
||||
import forestry.greenhouse.network.PacketRegistryGreenhouse;
|
||||
import forestry.greenhouse.proxy.ProxyGreenhouse;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDoor;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseDryer;
|
||||
@@ -191,6 +192,9 @@ public class PluginGreenhouse extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileGreenhousePlain.class, "forestry.GreenhousePlain");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseDoor.class, "forestry.GreenhouseDoor");
|
||||
GameRegistry.registerTileEntity(TileGreenhouseHatch.class, "forestry.GreenhouseHatch");
|
||||
if(ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)){
|
||||
GameRegistry.registerTileEntity(TileGreenhouseButterflyHatch.class, "forestry.GreenhouseButterflyHatch");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,6 +80,12 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
public static Map<BlockGreenhouseType, BlockGreenhouse> create() {
|
||||
Map<BlockGreenhouseType, BlockGreenhouse> blockMap = new EnumMap<>(BlockGreenhouseType.class);
|
||||
for (final BlockGreenhouseType type : BlockGreenhouseType.VALUES) {
|
||||
if(type == BlockGreenhouseType.BUTTERFLY_HATCH){
|
||||
if(!ForestryAPI.enabledPlugins.contains(ForestryPluginUids.LEPIDOPTEROLOGY)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
BlockGreenhouse block;
|
||||
if(type == BlockGreenhouseType.DOOR){
|
||||
block = new BlockGreenhouseDoor();
|
||||
@@ -204,6 +210,8 @@ public abstract class BlockGreenhouse extends BlockStructure {
|
||||
case HATCH_INPUT:
|
||||
case HATCH_OUTPUT:
|
||||
return new TileGreenhouseHatch();
|
||||
case BUTTERFLY_HATCH:
|
||||
return new TileGreenhouseHatch();
|
||||
default:
|
||||
return new TileGreenhousePlain();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ public enum BlockGreenhouseType {
|
||||
DRYER(true, true),
|
||||
CONTROL(true),
|
||||
SPRINKLER(false, true),
|
||||
DOOR;
|
||||
DOOR,
|
||||
BUTTERFLY_HATCH(true);
|
||||
|
||||
public static final BlockGreenhouseType[] VALUES = values();
|
||||
|
||||
@@ -57,7 +58,7 @@ public enum BlockGreenhouseType {
|
||||
private static EnumMap<BlockGreenhouseSprites, TextureAtlasSprite> sprites;
|
||||
|
||||
private static enum BlockGreenhouseSprites{
|
||||
PLAIN, GLASS, GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output");
|
||||
PLAIN, GLASS, GEARS("gears"), VALVE("valve"), FAN_OFF("fan.off"), FAN_ON("fan.on"), HEATER_OFF("heater.off"), HEATER_ON("heater.on"), DRYER("dryer"), CONTROL("control"), HATCH_DEFAULT("hatch"), HATCH_INPUT("hatch_input"), HATCH_OUTPUT("hatch_output"), BUTTERFLY_HATCH("butterfly_hatch");
|
||||
|
||||
public static final BlockGreenhouseSprites[] VALUES = values();
|
||||
|
||||
@@ -135,6 +136,11 @@ public enum BlockGreenhouseType {
|
||||
return sprites.get(BlockGreenhouseSprites.HATCH_INPUT);
|
||||
}
|
||||
return null;
|
||||
case BUTTERFLY_HATCH:
|
||||
if(facing == EnumFacing.DOWN || facing == EnumFacing.UP){
|
||||
return null;
|
||||
}
|
||||
return sprites.get(BlockGreenhouseSprites.BUTTERFLY_HATCH);
|
||||
default:
|
||||
return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* 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.greenhouse.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import forestry.core.gui.ContainerTile;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
|
||||
public class ContainerGreenhouseButterflyHatch extends ContainerTile<TileGreenhouseButterflyHatch> {
|
||||
|
||||
public ContainerGreenhouseButterflyHatch(InventoryPlayer playerInventory, TileGreenhouseButterflyHatch tile) {
|
||||
super(tile, playerInventory, 8, 84);
|
||||
|
||||
addSlotToContainer(new SlotOutput(tile, 0, 60, 40));
|
||||
addSlotToContainer(new SlotOutput(tile, 1, 80, 27));
|
||||
addSlotToContainer(new SlotOutput(tile, 2, 101, 40));
|
||||
addSlotToContainer(new SlotOutput(tile, 3, 80, 53));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
|
||||
sendPacketToCrafters(packet);
|
||||
}
|
||||
|
||||
public IFluidTank getTank(int slot) {
|
||||
return tile.getMultiblockLogic().getController().getTankManager().getTank(slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* 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.greenhouse.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.ledgers.ClimateLedger;
|
||||
import forestry.greenhouse.gui.widgets.WidgetCamouflageSlot;
|
||||
import forestry.greenhouse.multiblock.IGreenhouseControllerInternal;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
|
||||
public class GuiGreenhouseButterflyHatch extends GuiForestryTitled<ContainerGreenhouseButterflyHatch, TileGreenhouseButterflyHatch> {
|
||||
|
||||
public GuiGreenhouseButterflyHatch(EntityPlayer player, TileGreenhouseButterflyHatch tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/greenhouse_butterfly_hatch.png", new ContainerGreenhouseButterflyHatch(player.inventory, tile), tile);
|
||||
|
||||
//Add the tile camouflage slots
|
||||
widgetManager.add(new WidgetCamouflageSlot(widgetManager, 8, 17, inventory, tile.getCamouflageType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
IGreenhouseControllerInternal greenhouseController = inventory.getMultiblockLogic().getController();
|
||||
|
||||
ledgerManager.add(new ClimateLedger(ledgerManager, greenhouseController));
|
||||
super.addLedgers();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -8,11 +8,12 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.greenhouse.multiblock;
|
||||
package forestry.greenhouse.inventory;
|
||||
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
import forestry.greenhouse.multiblock.GreenhouseController;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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.greenhouse.inventory;
|
||||
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
|
||||
public class InventoryGreenhouseButterflyHatch extends InventoryAdapterTile<TileGreenhouseButterflyHatch> {
|
||||
|
||||
public static final int SLOTS = 4;
|
||||
|
||||
public InventoryGreenhouseButterflyHatch(TileGreenhouseButterflyHatch tile) {
|
||||
super(tile, SLOTS, "Items");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
|
||||
BlockModelShapes modelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
|
||||
|
||||
baker.addBakedModel(modelShapes.getModelForState(Block.getBlockFromItem(camouflageStack.getItem()).getStateFromMeta(camouflageStack.getItemDamage())));
|
||||
baker.setParticleSprite(modelShapes.getModelForState(Block.getBlockFromItem(camouflageStack.getItem()).getStateFromMeta(camouflageStack.getItemDamage())).getParticleTexture());
|
||||
}
|
||||
|
||||
//Bake the default blocks
|
||||
|
||||
@@ -34,6 +34,7 @@ import forestry.api.core.ICamouflagedBlock;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.api.multiblock.IGreenhouseController;
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IGreenhouseComponent.ButterflyHatch;
|
||||
import forestry.core.access.EnumAccess;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.fluids.TankManager;
|
||||
@@ -54,6 +55,7 @@ import forestry.energy.EnergyManager;
|
||||
import forestry.greenhouse.GreenhouseState;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouse;
|
||||
import forestry.greenhouse.network.packets.PacketCamouflageUpdate;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseSprinkler;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -698,5 +700,18 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
public List<IInternalBlock> getInternalBlocks() {
|
||||
return internalBlocks;
|
||||
}
|
||||
|
||||
public static ButterflyHatch getGreenhouseButterflyHatch(World world, BlockPos pos){
|
||||
if(GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos) == null){
|
||||
return null;
|
||||
}
|
||||
IGreenhouseState state = GreenhouseManager.greenhouseHelper.getGreenhouseState(world, pos);
|
||||
for(IMultiblockComponent greenhouse : state.getGreenhouseComponents()){
|
||||
if(greenhouse instanceof ButterflyHatch){
|
||||
return (ButterflyHatch) greenhouse;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* 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.greenhouse.tiles;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.greenhouse.gui.ContainerGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.gui.GuiGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.inventory.InventoryGreenhouseButterflyHatch;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class TileGreenhouseButterflyHatch extends TileGreenhouse implements IGreenhouseComponent.ButterflyHatch {
|
||||
|
||||
private InventoryGreenhouseButterflyHatch inventory;
|
||||
|
||||
public TileGreenhouseButterflyHatch() {
|
||||
super();
|
||||
this.inventory = new InventoryGreenhouseButterflyHatch(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] addCocoonLoot(IButterflyCocoon cocoon) {
|
||||
List<ItemStack> loots = new ArrayList();
|
||||
for(ItemStack loot : cocoon.getCaterpillar().getCocoonDrop(cocoon)){
|
||||
if(!InventoryUtil.tryAddStack(this, loot, 0, InventoryGreenhouseButterflyHatch.SLOTS, true)){
|
||||
loots.add(loot);
|
||||
}
|
||||
}
|
||||
if(loots.size() > 0){
|
||||
return loots.toArray(new ItemStack[loots.size()]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGui(EntityPlayer player, int data) {
|
||||
return new GuiGreenhouseButterflyHatch(player, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerGreenhouseButterflyHatch(player.inventory, this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,14 +16,19 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
@@ -40,6 +45,7 @@ import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IAlleleButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.PluginCore;
|
||||
@@ -48,6 +54,7 @@ import forestry.core.config.LocalizedConfiguration;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.EntityUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.lepidopterology.blocks.BlockRegistryLepidopterology;
|
||||
import forestry.lepidopterology.blocks.BlockTypeLepidopterologyTesr;
|
||||
@@ -66,6 +73,7 @@ import forestry.lepidopterology.items.ItemRegistryLepidopterology;
|
||||
import forestry.lepidopterology.proxy.ProxyLepidopterology;
|
||||
import forestry.lepidopterology.recipes.MatingRecipe;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import forestry.lepidopterology.worldgen.CocoonDecorator;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -80,6 +88,11 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
public static int entityConstraint = 1000;
|
||||
private static boolean allowPollination = true;
|
||||
public static final Map<String, Float> spawnRaritys = Maps.newHashMap();
|
||||
private static boolean spawnButterflysFromLeaves = true;
|
||||
private static boolean generateCocoons = false;
|
||||
private static float generateCocoonsAmount = 1.0f;
|
||||
private static float serumChance = 0.55f;
|
||||
private static float secondSerumChance = 0;
|
||||
|
||||
public static ItemRegistryLepidopterology items;
|
||||
public static BlockRegistryLepidopterology blocks;
|
||||
@@ -91,8 +104,6 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
ButterflyManager.butterflyFactory = new ButterflyFactory();
|
||||
ButterflyManager.butterflyMutationFactory = new ButterflyMutationFactory();
|
||||
|
||||
AlleleButterflyCocoon.createAlleles();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,6 +118,7 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
ButterflyBranchDefinition.createAlleles();
|
||||
AlleleButterflyEffect.createAlleles();
|
||||
AlleleButterflyCocoon.createAlleles();
|
||||
|
||||
GameRegistry.registerTileEntity(TileCocoon.class, "forestry.Cocoon");
|
||||
proxy.preInitializeRendering();
|
||||
@@ -133,7 +145,9 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
|
||||
blocks.lepidopterology.init();
|
||||
|
||||
TreeManager.treeRoot.registerLeafTickHandler(new ButterflySpawner());
|
||||
if(spawnButterflysFromLeaves){
|
||||
TreeManager.treeRoot.registerLeafTickHandler(new ButterflySpawner());
|
||||
}
|
||||
|
||||
RecipeSorter.register("forestry:lepidopterologymating", MatingRecipe.class, RecipeSorter.Category.SHAPELESS, "before:minecraft:shapeless");
|
||||
}
|
||||
@@ -143,6 +157,24 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
File configFile = new File(Forestry.instance.getConfigFolder(), CONFIG_CATEGORY + ".cfg");
|
||||
loadConfig(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateChunk(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
|
||||
if(generateCocoons){
|
||||
if (generateCocoonsAmount > 0.0) {
|
||||
CocoonDecorator.decorateCocoons(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateChunkRetroGen(World world, Random rand, int chunkX, int chunkZ) {
|
||||
if(generateCocoons){
|
||||
if (generateCocoonsAmount > 0.0) {
|
||||
CocoonDecorator.decorateCocoons(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadConfig(File configFile) {
|
||||
LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.1.0");
|
||||
@@ -150,7 +182,21 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
spawnConstraint = config.getIntLocalized("butterfly.entities", "spawn.limit", spawnConstraint, 0, 500);
|
||||
entityConstraint = config.getIntLocalized("butterfly.entities", "maximum", entityConstraint, 0, 5000);
|
||||
allowPollination = config.getBooleanLocalized("butterfly.entities", "pollination", allowPollination);
|
||||
spawnButterflysFromLeaves = config.getBooleanLocalized("butterfly.entities", "spawn.leaves", spawnButterflysFromLeaves);
|
||||
|
||||
generateCocoons = config.getBooleanLocalized("butterfly.cocoons", "generate", generateCocoons);
|
||||
generateCocoonsAmount = config.getFloatLocalized("butterfly.cocoons", "generate.amount", generateCocoonsAmount, 0.0f, 10.0f);
|
||||
|
||||
serumChance = config.getFloatLocalized("butterfly.cocoons", "serum", serumChance, 0.0f, 100.0f);
|
||||
secondSerumChance = config.getFloatLocalized("butterfly.cocoons", "second.serum", secondSerumChance, 0.0f, 100.0f);
|
||||
|
||||
parseRarity(config);
|
||||
parseCooconLoots(config);
|
||||
|
||||
config.save();
|
||||
}
|
||||
|
||||
private static void parseRarity(LocalizedConfiguration config){
|
||||
List<String> butterflyRarity = Lists.newArrayList();
|
||||
for(IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()){
|
||||
if(allele instanceof IAlleleButterflySpecies){
|
||||
@@ -161,7 +207,7 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
Collections.sort(butterflyRarity);
|
||||
String[] defaultRaritys = butterflyRarity.toArray(new String[butterflyRarity.size()]);
|
||||
|
||||
Property rarityConf = config.get("alleles", "rarity", defaultRaritys);
|
||||
Property rarityConf = config.get("butterfly.alleles", "rarity", defaultRaritys);
|
||||
rarityConf.comment = StringUtil.localize("config.butterfly.alleles.rarity");
|
||||
|
||||
String[] configRaritys = rarityConf.getStringList();
|
||||
@@ -175,8 +221,50 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseCooconLoots(LocalizedConfiguration config){
|
||||
for(IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()){
|
||||
if(allele instanceof IAlleleButterflyCocoon){
|
||||
parseCooconLoot(config, (IAlleleButterflyCocoon) allele);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseCooconLoot(LocalizedConfiguration config, IAlleleButterflyCocoon cocoon){
|
||||
Map<ItemStack, Float> cooconLoot = new HashMap();
|
||||
List<String> lootList = new ArrayList();
|
||||
for(Entry<ItemStack, Float> entry : cocoon.getCocoonLoot().entrySet()){
|
||||
String itemStackString = ItemStackUtil.getItemNameFromRegistryAsSting(entry.getKey().getItem());
|
||||
|
||||
int meta = entry.getKey().getItemDamage();
|
||||
if (meta != OreDictionary.WILDCARD_VALUE) {
|
||||
itemStackString = itemStackString + ':' + meta;
|
||||
}
|
||||
lootList.add(itemStackString + ";" + entry.getValue());
|
||||
}
|
||||
Collections.sort(lootList);
|
||||
String[] defaultLoot = lootList.toArray(new String[lootList.size()]);
|
||||
|
||||
config.save();
|
||||
Property lootConf = config.get("butterfly.cocoons.alleles.loot", cocoon.getUID(), defaultLoot);
|
||||
lootConf.comment = StringUtil.localize("config.butterfly.alleles.loot");
|
||||
|
||||
String[] configLoot = lootConf.getStringList();
|
||||
for(String loot : configLoot){
|
||||
if(loot.contains(";") && loot.length() > 3){
|
||||
String[] loots = loot.split(";");
|
||||
try{
|
||||
ItemStack itemStack = ItemStackUtil.parseItemStackString(loots[0], OreDictionary.WILDCARD_VALUE);
|
||||
if(itemStack != null){
|
||||
cooconLoot.put(itemStack, Float.parseFloat(loots[1]));
|
||||
}
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
cocoon.getCocoonLoot().clear();
|
||||
cocoon.getCocoonLoot().putAll(cooconLoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,6 +288,26 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
return allowPollination;
|
||||
}
|
||||
|
||||
public static boolean isSpawnButterflysFromLeaves() {
|
||||
return spawnButterflysFromLeaves;
|
||||
}
|
||||
|
||||
public static boolean isGenerateCocoons() {
|
||||
return generateCocoons;
|
||||
}
|
||||
|
||||
public static float getGenerateCocoonsAmount() {
|
||||
return generateCocoonsAmount;
|
||||
}
|
||||
|
||||
public static float getSerumChance() {
|
||||
return serumChance;
|
||||
}
|
||||
|
||||
public static float getSecondSerumChance() {
|
||||
return secondSerumChance;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerSprites(TextureStitchEvent.Pre event) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -27,7 +28,6 @@ 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;
|
||||
@@ -37,7 +37,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
public class BlockCocoon extends Block implements ITileEntityProvider, IStateMapperRegister {
|
||||
|
||||
public BlockCocoon() {
|
||||
super(Material.leaves);
|
||||
super(Material.cloth);
|
||||
setTickRandomly(true);
|
||||
setStepSound(soundTypeGrass);
|
||||
setCreativeTab(Tabs.tabLepidopterology);
|
||||
@@ -72,39 +72,14 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileCocoon();
|
||||
return new TileCocoon(false);
|
||||
}
|
||||
|
||||
@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) {
|
||||
}
|
||||
@@ -127,4 +102,10 @@ public class BlockCocoon extends Block implements ITileEntityProvider, IStateMap
|
||||
worldIn.setBlockToAir(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,9 +16,11 @@ import forestry.core.items.ItemBlockForestry;
|
||||
public class BlockRegistryLepidopterology extends BlockRegistry {
|
||||
public final BlockLepidopterology lepidopterology;
|
||||
public final BlockCocoon cocoon;
|
||||
public final BlockSolidCocoon solidCocoon;
|
||||
|
||||
public BlockRegistryLepidopterology() {
|
||||
lepidopterology = registerBlock(new BlockLepidopterology(), ItemBlockForestry.class, "lepidopterology");
|
||||
cocoon = registerBlock(new BlockCocoon(), ItemBlockForestry.class, "cocoon");
|
||||
solidCocoon = registerBlock(new BlockSolidCocoon(), ItemBlockForestry.class, "cocoon.solid");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*******************************************************************************
|
||||
* 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.Collections;
|
||||
import java.util.List;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.EmptyStateMapper;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
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.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
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 BlockSolidCocoon extends Block implements ITileEntityProvider, IStateMapperRegister {
|
||||
|
||||
public BlockSolidCocoon() {
|
||||
super(Material.cloth);
|
||||
setHarvestLevel("scoop", 0);
|
||||
setHardness(0.5F);
|
||||
setTickRandomly(true);
|
||||
setStepSound(soundTypeGrass);
|
||||
setCreativeTab(Tabs.tabLepidopterology);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullCube(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaqueCube(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||
if (canHarvestBlock(world, pos, player)) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileCocoon) {
|
||||
TileCocoon cocoon = (TileCocoon) tile;
|
||||
ItemStack[] drops = cocoon.getCocoonDrops();
|
||||
if (drops != null) {
|
||||
for (ItemStack stack : drops) {
|
||||
if (stack != null) {
|
||||
ItemStackUtil.dropItemStackAsEntity(stack, world, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return world.setBlockToAir(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta) {
|
||||
return new TileCocoon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerStateMapper() {
|
||||
Proxies.render.registerStateMapper(this, EmptyStateMapper.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
|
||||
IBlockState stateUp = worldIn.getBlockState(pos.up());
|
||||
if(stateUp.getBlock().isAir(worldIn, pos.up())){
|
||||
worldIn.setBlockToAir(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,9 +26,6 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should lay egg?
|
||||
*/
|
||||
@Override
|
||||
protected boolean canInteract() {
|
||||
if(entity.getButterfly().getMate() == null && entity.canMate()){
|
||||
@@ -53,9 +50,6 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
public void updateTask() {
|
||||
if (continueExecuting()) {
|
||||
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;
|
||||
@@ -66,7 +60,7 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(entity.worldObj, nursery));
|
||||
// Log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
//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);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,10 @@ import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyMutation;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
@@ -49,6 +51,7 @@ import forestry.core.genetics.Chromosome;
|
||||
import forestry.core.genetics.GenericRatings;
|
||||
import forestry.core.genetics.IndividualLiving;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.lepidopterology.PluginLepidopterology;
|
||||
|
||||
public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
|
||||
@@ -303,5 +306,35 @@ public class Butterfly extends IndividualLiving implements IButterfly {
|
||||
|
||||
return drop.toArray(new ItemStack[drop.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getCocoonDrop(IButterflyCocoon cocoon) {
|
||||
ArrayList<ItemStack> drop = new ArrayList<>();
|
||||
float metabolism = (float) getGenome().getMetabolism() / 10;
|
||||
|
||||
for (Map.Entry<ItemStack, Float> entry : getGenome().getCocoon().getCocoonLoot().entrySet()) {
|
||||
if (rand.nextFloat() < entry.getValue() * metabolism) {
|
||||
drop.add(entry.getKey().copy());
|
||||
}
|
||||
}
|
||||
|
||||
if(PluginLepidopterology.getSerumChance() > 0){
|
||||
if(rand.nextFloat() < PluginLepidopterology.getSerumChance() * metabolism){
|
||||
ItemStack stack = ButterflyManager.butterflyRoot.getMemberStack(this, EnumFlutterType.SERUM);
|
||||
if(PluginLepidopterology.getSecondSerumChance() > 0){
|
||||
if(rand.nextFloat() < PluginLepidopterology.getSecondSerumChance() * metabolism){
|
||||
stack.stackSize = 2;
|
||||
}
|
||||
}
|
||||
drop.add(ButterflyManager.butterflyRoot.getMemberStack(this, EnumFlutterType.SERUM));
|
||||
}
|
||||
}
|
||||
|
||||
if(cocoon.isSolid()){
|
||||
drop.add(ButterflyManager.butterflyRoot.getMemberStack(this, EnumFlutterType.BUTTERFLY));
|
||||
}
|
||||
|
||||
return drop.toArray(new ItemStack[drop.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IClassification;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.EnumCocoonType;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
@@ -316,7 +315,7 @@ public enum ButterflyDefinition implements IButterflyDefinition {
|
||||
|
||||
String texture = "butterflies/" + uid;
|
||||
|
||||
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("forestry." + uid, unlocalizedName, "Sengir", unlocalizedDescription, Constants.RESOURCE_ID, texture, dominant, branchDefinition.getBranch(), binomial, serumColor);
|
||||
speciesBuilder.setRarity(rarity);
|
||||
setSpeciesProperties(speciesBuilder);
|
||||
this.species = speciesBuilder.build();
|
||||
|
||||
@@ -19,7 +19,6 @@ import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IClassification;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.EnumCocoonType;
|
||||
import forestry.api.lepidopterology.EnumFlutterType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IAlleleButterflySpeciesBuilder;
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
package forestry.lepidopterology.genetics.alleles;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -19,8 +21,10 @@ import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.api.lepidopterology.EnumCocoonType;
|
||||
import forestry.api.lepidopterology.IAlleleButterflyCocoon;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.alleles.AlleleCategorized;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AlleleButterflyCocoon extends AlleleCategorized implements IAlleleButterflyCocoon {
|
||||
|
||||
@@ -33,6 +37,9 @@ public class AlleleButterflyCocoon extends AlleleCategorized implements IAlleleB
|
||||
cocoonDefault = new AlleleButterflyCocoon("default", EnumCocoonType.DEFAULT, false),
|
||||
cocoonSilk = new AlleleButterflyCocoon("silk", EnumCocoonType.SILK, false)
|
||||
);
|
||||
|
||||
cocoonSilk.getCocoonLoot().put(PluginCore.items.craftingMaterial.getSilkWisp(), 0.75F);
|
||||
cocoonSilk.getCocoonLoot().put(PluginCore.items.craftingMaterial.getSilkWisp(), 0.25F);
|
||||
|
||||
for (IAlleleButterflyCocoon cocoonAllele : cocoonAlleles) {
|
||||
AlleleManager.alleleRegistry.registerAllele(cocoonAllele, EnumButterflyChromosome.COCOON);
|
||||
@@ -41,9 +48,10 @@ public class AlleleButterflyCocoon extends AlleleCategorized implements IAlleleB
|
||||
|
||||
@Nonnull
|
||||
private EnumCocoonType type;
|
||||
private Map<ItemStack, Float> loot = new HashMap();
|
||||
|
||||
public AlleleButterflyCocoon(String name, @Nonnull EnumCocoonType type, boolean isDominant) {
|
||||
super(Constants.MOD_ID, "fruit", name, isDominant);
|
||||
super(Constants.MOD_ID, "cocoon", name, isDominant);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -57,4 +65,9 @@ public class AlleleButterflyCocoon extends AlleleCategorized implements IAlleleB
|
||||
return "textures/blocks/lepidopterology/cocoons/" + type + "_" + age + ".png";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ItemStack, Float> getCocoonLoot() {
|
||||
return loot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import forestry.api.lepidopterology.IAlleleButterflySpecies;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.lepidopterology.blocks.BlockCocoon;
|
||||
import forestry.lepidopterology.blocks.BlockSolidCocoon;
|
||||
import forestry.lepidopterology.genetics.MothDefinition;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -33,7 +34,7 @@ public class RendererCocoon extends TileEntitySpecialRenderer<TileCocoon> {
|
||||
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)){
|
||||
if(state == null || !(state.getBlock() instanceof BlockCocoon) && !(state.getBlock() instanceof BlockSolidCocoon)){
|
||||
return;
|
||||
}
|
||||
IButterfly butterfly = te.getCaterpillar();
|
||||
|
||||
@@ -20,18 +20,22 @@ import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.api.multiblock.IGreenhouseComponent;
|
||||
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.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.greenhouse.multiblock.GreenhouseController;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -40,12 +44,23 @@ import net.minecraft.world.World;
|
||||
|
||||
public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IButterflyCocoon {
|
||||
|
||||
public TileCocoon() {
|
||||
}
|
||||
|
||||
public TileCocoon(boolean isSolid) {
|
||||
this.isSolid = isSolid;
|
||||
if(isSolid){
|
||||
this.age = 2;
|
||||
}
|
||||
}
|
||||
|
||||
private int age;
|
||||
private int maturationTime;
|
||||
private IButterfly caterpillar;
|
||||
private GameProfile owner;
|
||||
private BlockPos nursery;
|
||||
|
||||
private boolean isSolid;
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
@@ -66,6 +81,7 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
|
||||
}
|
||||
age = nbttagcompound.getInteger("Age");
|
||||
maturationTime = nbttagcompound.getInteger("CATMAT");
|
||||
isSolid = nbttagcompound.getBoolean("isSolid");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,6 +108,7 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
|
||||
}
|
||||
nbttagcompound.setInteger("Age", age);
|
||||
nbttagcompound.setInteger("CATMAT", maturationTime);
|
||||
nbttagcompound.setBoolean("isSolid", isSolid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,10 +181,18 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
|
||||
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());
|
||||
IGreenhouseComponent.ButterflyHatch hatch = GreenhouseController.getGreenhouseButterflyHatch(worldObj, pos);
|
||||
ItemStack[] cocoonDrops;
|
||||
if(hatch != null){
|
||||
cocoonDrops = hatch.addCocoonLoot(this);
|
||||
}else{
|
||||
cocoonDrops = caterpillar.getCocoonDrop(this);
|
||||
}
|
||||
for(ItemStack drop : cocoonDrops){
|
||||
ItemStackUtil.dropItemStackAsEntity(drop, worldObj, pos);
|
||||
}
|
||||
worldObj.setBlockToAir(getPos());
|
||||
attemptButterflySpawn(worldObj, caterpillar, getPos());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -216,5 +241,14 @@ public class TileCocoon extends TileEntity implements IStreamable, IOwnable, IBu
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public ItemStack[] getCocoonDrops() {
|
||||
return caterpillar.getCocoonDrop(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return isSolid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*******************************************************************************
|
||||
* 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.worldgen;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.common.BiomeDictionary.Type;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
import net.minecraftforge.event.terraingen.PopulateChunkEvent.Populate.EventType;
|
||||
import net.minecraftforge.event.terraingen.TerrainGen;
|
||||
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.lepidopterology.PluginLepidopterology;
|
||||
import forestry.lepidopterology.tiles.TileCocoon;
|
||||
|
||||
public abstract class CocoonDecorator {
|
||||
|
||||
private static final EventType EVENT_TYPE = EnumHelper.addEnum(EventType.class, "FORESTRY_COCOONS", new Class[0], new Object[0]);
|
||||
|
||||
public static void decorateCocoons(IChunkProvider chunkProvider, World world, Random rand, int chunkX, int chunkZ, boolean hasVillageGenerated) {
|
||||
if (!TerrainGen.populate(chunkProvider, world, rand, chunkX, chunkZ, hasVillageGenerated, EVENT_TYPE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
decorateCocoons(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public static void decorateCocoons(World world, Random rand, int chunkX, int chunkZ) {
|
||||
List<IButterfly> butterflys = ButterflyManager.butterflyRoot.getIndividualTemplates();
|
||||
|
||||
Collections.shuffle(butterflys, rand);
|
||||
for (IButterfly butterfly : butterflys) {
|
||||
if (genCocoon(world, rand, chunkX, chunkZ, butterfly)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean genCocoon(World world, Random rand, int chunkX, int chunkZ, IButterfly butterfly) {
|
||||
if (butterfly.getGenome().getPrimary().getRarity() * PluginLepidopterology.getGenerateCocoonsAmount() < rand.nextFloat() * 100.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int worldX = chunkX * 16;
|
||||
int worldZ = chunkZ * 16;
|
||||
|
||||
BiomeGenBase biome = world.getBiomeGenForCoords(new BlockPos(worldX, 0, worldZ));
|
||||
|
||||
Type[] types = BiomeDictionary.getTypesForBiome(biome);
|
||||
EnumSet<Type> speciesTypes = butterfly.getGenome().getPrimary().getSpawnBiomes();
|
||||
|
||||
boolean biomeTypesGood = false;
|
||||
for(Type type : types){
|
||||
if(speciesTypes == null || speciesTypes.size() <= 0 || speciesTypes.equals(type)){
|
||||
biomeTypesGood = true;
|
||||
}
|
||||
}
|
||||
if(!biomeTypesGood) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int tries = 0; tries < 4; tries++) {
|
||||
int x = worldX + rand.nextInt(16);
|
||||
int z = worldZ + rand.nextInt(16);
|
||||
|
||||
if (tryGenCocoon(world, x, z, butterfly)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean tryGenCocoon(World world, int x, int z, IButterfly butterfly) {
|
||||
|
||||
int y = getYForCocoon(world, x, z);
|
||||
|
||||
if (y < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isValidLocation(world, new BlockPos(x, y, z))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return setCocoon(world, new BlockPos(x, y, z), butterfly);
|
||||
}
|
||||
|
||||
private static boolean setCocoon(World world, BlockPos pos, IButterfly butterfly) {
|
||||
Block cocoonBlock = PluginLepidopterology.blocks.solidCocoon;
|
||||
boolean placed = world.setBlockState(pos, cocoonBlock.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
if (!placed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if (!Block.isEqualTo(cocoonBlock, state.getBlock())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileCocoon){
|
||||
TileCocoon cocoon = (TileCocoon) tile;
|
||||
cocoon.setCaterpillar(butterfly);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
cocoonBlock.onBlockAdded(world, pos, state);
|
||||
world.markBlockForUpdate(pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int getYForCocoon(World world, int x, int z){
|
||||
int y = world.getHeight(new BlockPos(x, 0, z)).getY() - 1;
|
||||
if (!world.getBlockState(new BlockPos(x, y, z)).getBlock().isLeaves(world, new BlockPos(x, y, z))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
y--;
|
||||
} while (world.getBlockState(new BlockPos(x, y, z)).getBlock().isLeaves(world, new BlockPos(x, y, z)));
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
public static boolean isValidLocation(World world, BlockPos pos) {
|
||||
Block blockAbove = world.getBlockState(pos.up()).getBlock();
|
||||
if (!blockAbove.isLeaves(world, pos.up())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return BlockUtil.canReplace(world, pos.down());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user