Compare commits

..
51 Commits
Author SHA1 Message Date
mezz 1969ed8b09 Close #1358 Change "Portable Alyzer" to "Portable Analyzer" 2016-07-21 23:44:03 -07:00
mezz c3fc490fac Fix #1355 Crash from Boggy bees 2016-07-21 22:53:58 -07:00
mezz 59687329fb Replace IBackpackFilter with Predicate<ItemStack> 2016-07-20 15:24:05 -07:00
mezz 94f751d78a Improve backpack API and add backpack config blacklists 2016-07-20 02:25:32 -07:00
mezz f6feca096f Remove unused icons from TextureManager 2016-07-19 17:41:50 -07:00
mezz 649f38efb8 Fix Escritoire renderer leaking the world object by keeping a reference 2016-07-19 16:03:30 -07:00
mezz e4e221b9fd Fix butterfly items rendering too low 2016-07-19 16:03:08 -07:00
Nedelosk d7f063eec8 Update EntityButterfly.java 2016-07-17 12:40:47 +02:00
mezz aa988a3be7 Make honeyed slice more appetizing looking 2016-07-15 17:10:40 -07:00
mezz 18f2a027bc Remove unused bucket icons 2016-07-13 22:24:33 -07:00
mezz 7ca34e52d6 Update icons that use cans or capsules 2016-07-13 22:23:26 -07:00
mezz 7f83b5b909 Change portable alyzer icon to 16x 2016-07-13 22:09:44 -07:00
mezz 641f763d05 Add tooltips and JEI descriptions for CircuitBoard, SolderingIron, Tubes 2016-07-13 21:35:27 -07:00
mezz 0df85063a1 Remove "requires discovery" and limits from electron tubes 2016-07-13 21:34:37 -07:00
mezz 550b0dc3f5 Add zombie villager textures 2016-07-13 21:34:37 -07:00
Nedelosk 96a7b688c0 Fix the jar 2016-07-13 19:34:56 +02:00
Nedelosk 8f6c2baba6 Update README.md 2016-07-13 19:20:30 +02:00
mezz 523a8da908 Fix #1348 support for IC2 in 1.10.2 2016-07-10 18:43:58 -07:00
mezz cd10500a17 Fix crash when there is snow in the way of the farm 2016-07-10 18:34:31 -07:00
mezz 6d9211ada1 Remove block access restrictions 2016-07-06 02:00:02 -07:00
mezz 003ca9273d Fix beekeeper vaillager's collar color 2016-07-05 22:13:58 -07:00
mezz 28f65f13a5 Fix worktable bug that could delete container items 2016-07-05 21:57:23 -07:00
mezz 21ee0947d7 Fix isOp permissions check 2016-07-05 21:01:54 -07:00
mezz 1e11992de2 Fix #1333 Stop wild hive bees from attacking passive animals 2016-07-03 23:05:46 -07:00
mezz d690a38fa2 Fix #1340 Rare NPE from BeekeepingLogic.queenWorkTick 2016-07-03 22:16:12 -07:00
mezz 46eb29cf28 Fix #1342 Crash when giving multifarm control a redstone signal 2016-07-03 20:59:26 -07:00
mezz fb01d3ffaa Update IC2 2016-07-03 12:38:47 -07:00
mezz e676a73a7c Fix doors not showing correctly in TheOneProbe 2016-07-01 22:41:29 -07:00
mezz 6e348dbc5d Add support for Tesla power 2016-06-30 16:54:57 -07:00
mezz 39114ec429 Tidy up capabilities 2016-06-30 16:26:36 -07:00
mezz 3b82fe3bd0 Update to Minecraft 1.10.2 2016-06-30 16:22:15 -07:00
mezz 2667334252 Increase chances of getting a research note on the escritoire 2016-06-28 13:56:28 -07:00
mezz be39e2c3c3 Only list mutations for the primary species in the handheld Alyzer 2016-06-28 13:51:15 -07:00
mezz 40eece7d77 Fix bee carts dropping invalid item when broken 2016-06-28 13:01:39 -07:00
mezz 4fcc785e85 Make Escritoire give unlearned mutation notes first 2016-06-28 02:24:00 -07:00
mezz 11e4097bd8 Use List in the API where appropriate 2016-06-28 02:10:03 -07:00
mezz f8c37da06d Improve escritoire responsiveness on slow networks or laggy servers 2016-06-28 01:54:32 -07:00
mezz 09756f21fd Fix grafter break sounds and animation on Forestry leaves
(no fix for vanilla leaves, the harvest event is fired server-side only)
2016-06-25 01:37:44 -07:00
mezz a06c4bd1dc Make grafter work on vanilla leaves 2016-06-25 01:36:33 -07:00
mezz bb477f0dfb Add tooltip for grafter use count on a new grafter 2016-06-25 00:34:51 -07:00
mezz 0b86b3df8f Buff the grafter slightly from 5 uses to 10 uses 2016-06-25 00:34:31 -07:00
mezz edd5357008 Make princess bee crown silver to stand out better 2016-06-25 00:23:24 -07:00
mezz dfb4e04f4a Update Forge 2016-06-25 00:04:26 -07:00
mezz 45c0375387 Fix bee particles becoming active at night when hive is opened 2016-06-25 00:04:11 -07:00
mezz 5e4cfa5112 Add oredict for charcoal 2016-06-25 00:03:16 -07:00
mezz 086b53e4a3 Add beetroot seeds to the squeezer for seed oil 2016-06-24 19:29:02 -07:00
mezz fbb5612b8c Slightly improve the look of larch bark 2016-06-24 19:21:54 -07:00
mezz c3c471ab33 Fix localization for backpack modes 2016-06-24 18:32:48 -07:00
mezz 67ddc252aa Stop Balsa leaves from generating infinitely downwards 2016-06-24 16:50:01 -07:00
mezz 59945a8961 Change name of "managed" farm to "automatic" 2016-06-24 16:40:57 -07:00
mezz bbabb967b1 Fix localization of latticed heath butterfly and ash pile 2016-06-24 16:34:52 -07:00
184 changed files with 1980 additions and 2257 deletions

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ Forestry is a modification for the game Minecraft and known primarily for its fa
[Wiki](http://forestry.sengir.net/)
[Latest Builds for 1.9](http://jenkins.ic2.player.to/job/Forestry_5/)
[Latest Builds for 1.10 / 1.10.2](http://jenkins.ic2.player.to/job/Forestry_5/)
[IRC #forestry on esper.net](http://webchat.esper.net/?nick=ForestryGithub...&channels=forestry&prompt=1)
+4
View File
@@ -55,6 +55,9 @@ sourceSets {
}
repositories {
maven {
url 'http://maven.epoxide.xyz'
}
maven {
url "http://dvs1.progwml6.com/files/maven"
}
@@ -65,6 +68,7 @@ repositories {
}
dependencies {
deobfCompile "net.darkhax.tesla:Tesla:${tesla_version}"
deobfCompile "mezz.jei:jei_${mcversion}:${jei_version}:api"
runtime "mezz.jei:jei_${mcversion}:${jei_version}"
deobfCompile "net.industrial-craft:industrialcraft-2:${ic2_version}:api"
+7 -6
View File
@@ -1,10 +1,11 @@
mcversion=1.10
forgeversion=12.18.0.1984-1.10.0
mcversion=1.10.2
forgeversion=12.18.0.2005-1.10.0
mcp_mappings=snapshot_20160525
jei_version=3.7.0.+
ic2_version=2.5.5-ex19
tesla_version=1.9.4-1.1.0.24
jei_version=3.7.3.221
ic2_version=2.6.5-ex110
version_major=5
version_minor=1
version_patch=3
version_minor=2
version_patch=2
+2 -2
View File
@@ -1,6 +1,6 @@
#Tue Jun 21 15:23:47 PDT 2016
#Mon Sep 14 12:28:28 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
+1 -1
Submodule lang updated: a5a5f41bd7...0d52088d32.
+4 -2
View File
@@ -12,6 +12,7 @@ package forestry;
import java.io.File;
import forestry.plugins.compat.PluginIC2;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod;
@@ -50,8 +51,9 @@ import forestry.plugins.PluginManager;
version = Constants.VERSION,
guiFactory = "forestry.core.config.ForestryGuiConfigFactory",
acceptedMinecraftVersions = "[1.10]",
dependencies = "required-after:Forge@[12.18.0.1984,);"
+ "after:JEI@[3.7.0,);")
dependencies = "required-after:Forge@[12.18.0.1989,);"
+ "after:JEI@[3.7.0,);"
+ "after:" + PluginIC2.modId + ";")
public class Forestry {
@Mod.Instance(Constants.MOD_ID)
@@ -5,6 +5,8 @@
******************************************************************************/
package forestry.api.apiculture;
import javax.annotation.Nonnull;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
@@ -32,6 +34,7 @@ public interface IBeeHousing extends IHousing, IErrorLogicSource {
*/
Iterable<IBeeListener> getBeeListeners();
@Nonnull
IBeeHousingInventory getBeeInventory();
IBeekeepingLogic getBeekeepingLogic();
@@ -7,17 +7,15 @@ package forestry.api.apiculture;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.ISpeciesRoot;
public interface IBeeRoot extends ISpeciesRoot {
/**
@@ -100,7 +98,7 @@ public interface IBeeRoot extends ISpeciesRoot {
/* MUTATIONS */
@Override
Collection<IBeeMutation> getMutations(boolean shuffle);
List<IBeeMutation> getMutations(boolean shuffle);
/* GAME MODE */
void resetBeekeepingMode();
@@ -8,18 +8,17 @@ package forestry.api.arboriculture;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.ISpeciesRoot;
public interface ITreeRoot extends ISpeciesRoot {
@Override
@@ -82,7 +81,7 @@ public interface ITreeRoot extends ISpeciesRoot {
boolean setFruitBlock(World world, IAlleleFruit allele, float sappiness, BlockPos pos);
/* GAME MODE */
ArrayList<ITreekeepingMode> getTreekeepingModes();
List<ITreekeepingMode> getTreekeepingModes();
ITreekeepingMode getTreekeepingMode(World world);
@@ -98,6 +97,5 @@ public interface ITreeRoot extends ISpeciesRoot {
/* MUTATIONS */
@Override
Collection<ITreeMutation> getMutations(boolean shuffle);
List<ITreeMutation> getMutations(boolean shuffle);
}
@@ -10,10 +10,6 @@ import java.util.List;
public interface ICircuit {
String getUID();
boolean requiresDiscovery();
int getLimit();
String getUnlocalizedName();
boolean isCircuitable(Object tile);
@@ -138,13 +138,13 @@ public interface ISpeciesRoot {
/**
* @return All registered mutations.
*/
Collection<? extends IMutation> getMutations(boolean shuffle);
List<? extends IMutation> getMutations(boolean shuffle);
/**
* @param other Allele to match mutations against.
* @return All registered mutations the given allele is part of.
*/
Collection<? extends IMutation> getCombinations(IAllele other);
List<? extends IMutation> getCombinations(IAllele other);
/**
* @since Forestry 3.7
@@ -7,18 +7,16 @@ package forestry.api.lepidopterology;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.ISpeciesRoot;
public interface IButterflyRoot extends ISpeciesRoot {
@Override
@@ -67,7 +65,7 @@ public interface IButterflyRoot extends ISpeciesRoot {
/* MUTATIONS */
@Override
Collection<IButterflyMutation> getMutations(boolean shuffle);
List<IButterflyMutation> getMutations(boolean shuffle);
@Nullable
@Override
@@ -5,43 +5,42 @@
******************************************************************************/
package forestry.api.storage;
import java.util.List;
import javax.annotation.Nonnull;
import java.util.function.Predicate;
import net.minecraft.item.ItemStack;
public interface IBackpackDefinition extends Predicate<ItemStack> {
/**
* To make your own backpack, create a backpack definition and register it with
* {@link IBackpackInterface#registerBackpackDefinition(String, IBackpackDefinition)}.
*/
public interface IBackpackDefinition {
/**
* @return Human-readable name of the backpack.
*/
@Nonnull
String getName(ItemStack backpack);
/**
* @return Primary colour for the backpack icon.
* @return Primary color for the backpack icon.
*/
int getPrimaryColour();
/**
* @return Secondary colour for backpack icon.
* @return Secondary color for backpack icon, normally white.
*/
int getSecondaryColour();
/**
* Adds an item as valid for this backpack.
* Filters items that can be put into a backpack.
*
* @param validItem
* For Backpack Implementers: you can create a new filter with
* {@link IBackpackInterface#createBackpackFilter()} or
* {@link IBackpackInterface#createNaturalistBackpackFilter(String)}
* or implement your own.
*
* @return the backpack's item filter.
*/
void addValidItem(ItemStack validItem);
void addValidItems(List<ItemStack> validItems);
void addValidOreDictName(String oreDictName);
/**
* Returns true if the ItemStack is a valid item for this backpack type.
*/
@Override
boolean test(ItemStack itemstack);
@Nonnull
Predicate<ItemStack> getFilter();
}
@@ -0,0 +1,45 @@
package forestry.api.storage;
import java.util.function.Predicate;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
/**
* A configurable backpack filter. Useful for implementers of {@link IBackpackDefinition}.
* Get a new instance from {@link IBackpackInterface#createBackpackFilter()}.
*/
public interface IBackpackFilterConfigurable extends Predicate<ItemStack> {
/**
* Adds an item as valid for this backpack to pick up.
*/
void acceptItem(ItemStack validItem);
/**
* Adds an item as invalid for this backpack, used to make exceptions to oreDictionary matches.
*
* @see #acceptOreDictName(String)
*/
void rejectItem(ItemStack invalidItem);
/**
* Adds an ore dictionary name as valid for this backpack.
* The backpack will pick up any item that has this oreDictName.
*
* @see OreDictionary
*/
void acceptOreDictName(String oreDictName);
/**
* Removes an ore dictionary name as valid for this backpack.
* The backpack will not pick up any item that has this oreDictName.
*
* @see OreDictionary
*/
void rejectOreDictName(String oreDictName);
/**
* Clear all the rules from this filter.
*/
void clear();
}
@@ -7,32 +7,83 @@ package forestry.api.storage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.function.Predicate;
import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;
import net.minecraftforge.oredict.OreDictionary;
/**
* The Backpack Interface allows you to add items to Forestry backpacks or create your own backpacks.
* <p>
* To create your own backpack, create an {@link IBackpackDefinition}.
* Backpack definitions have a filter, which you can create here with
* {@link #createBackpackFilter()}
* or {@link #createNaturalistBackpackFilter(String)}
* or create your own.
* <p>
* After you've registered your backpack definition, create the item with
* {@link #createBackpack(String, EnumBackpackType)}
* or {@link #createNaturalistBackpack(String, ISpeciesRoot)}
* and then register the returned item with {@link GameRegistry#register(IForgeRegistryEntry)} like any other item.
*/
public interface IBackpackInterface {
/**
* Get a backpack with a given uid so you can add items to it or get information about it.
* returns null if there is no backpack for the given uid.
* Add an accepted item to a Forestry backpack.
*
* @param backpackUid The unique ID of the Forestry backpack. See {@link BackpackManager} for valid UIDs.
* @param itemStack The itemStack that the backpack should accept.
* {@link OreDictionary#WILDCARD_VALUE} can be used for meta value.
*/
void addItemToForestryBackpack(@Nonnull String backpackUid, @Nonnull ItemStack itemStack);
/**
* Register a backpack definition with a given uid.
*/
void registerBackpackDefinition(@Nonnull String backpackUid, @Nonnull IBackpackDefinition definition);
/**
* Get a backpack definition with a given uid.
*/
@Nullable
IBackpackDefinition getBackpack(@Nonnull String uid);
IBackpackDefinition getBackpackDefinition(@Nonnull String backpackUid);
/**
* Register a backpack with a given uid
*/
void registerBackpack(@Nonnull String uid, @Nonnull IBackpackDefinition definition);
/**
* Adds a backpack with the given definition and type, returning the item.
* Creates a backpack with the given UID and type, returning the item.
* The backpack's definition must first be registered with {@link #registerBackpackDefinition(String, IBackpackDefinition)}.
*
* @param definition
* Definition of backpack behaviour.
* @param type
* Type of backpack.
* @param backpackUid The unique ID of the backpack.
* @param type Type of backpack.
* @return Created backpack item.
*/
@Nonnull
Item createBackpack(@Nonnull IBackpackDefinition definition, @Nonnull EnumBackpackType type);
Item createBackpack(@Nonnull String backpackUid, @Nonnull EnumBackpackType type);
/**
* Create a backpack that can hold items from a specific {@link ISpeciesRoot}.
* The backpack's definition must first be registered with {@link #registerBackpackDefinition(String, IBackpackDefinition)}.
*
* @param backpackUid The unique ID of the backpack.
* @param speciesRoot The species root.
* @return Created backpack item.
*/
Item createNaturalistBackpack(@Nonnull String backpackUid, @Nonnull ISpeciesRoot speciesRoot);
/**
* Makes a new configurable backpack filter. Useful for implementing {@link IBackpackDefinition}.
*/
IBackpackFilterConfigurable createBackpackFilter();
/**
* Makes a new naturalist backpack filter. Only accepts items from a specific {@link ISpeciesRoot}.
* Useful for implementing {@link IBackpackDefinition} for naturalist's backpacks.
*
* @param speciesRootUid The species root's unique ID. See {@link ISpeciesRoot#getUID()}.
* @return a new backpack filter for the specified species root
* @see #createNaturalistBackpack(String, ISpeciesRoot)
*/
Predicate<ItemStack> createNaturalistBackpackFilter(String speciesRootUid);
}
@@ -3,7 +3,7 @@
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
@API(apiVersion = "3.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|storage")
@API(apiVersion = "5.0.0", owner = "ForestryAPI|core", provides = "ForestryAPI|storage")
package forestry.api.storage;
import net.minecraftforge.fml.common.API;
@@ -11,6 +11,7 @@
package forestry.apiculture;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -233,18 +234,20 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
if (beeType == EnumBeeType.PRINCESS) {
tickBreed();
} else if (beeType == EnumBeeType.QUEEN) {
queenWorkTick(queen);
queenWorkTick(queen, queenStack);
}
}
@Override
public void clearCachedValues() {
hasFlowersCache.clear();
queenCanWorkCache.clear();
canWork();
if (!housing.getWorldObj().isRemote) {
hasFlowersCache.clear();
queenCanWorkCache.clear();
canWork();
}
}
private void queenWorkTick(IBee queen) {
private void queenWorkTick(@Nullable IBee queen, @Nonnull ItemStack queenStack) {
if (queen == null) {
beeProgress = 0;
beeProgressMax = 0;
@@ -270,7 +273,8 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
// Write the changed queen back into the item stack.
NBTTagCompound nbttagcompound = new NBTTagCompound();
queen.writeToNBT(nbttagcompound);
housing.getBeeInventory().getQueen().setTagCompound(nbttagcompound);
queenStack.setTagCompound(nbttagcompound);
housing.getBeeInventory().setQueen(queenStack);
}
beeProgress = queen.getHealth();
@@ -16,7 +16,6 @@ import net.minecraft.util.EnumFacing;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IBeeHousingInventory;
import forestry.core.access.IAccessHandler;
import forestry.core.inventory.InventoryAdapterRestricted;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.SlotUtil;
@@ -27,8 +26,8 @@ public class InventoryBeeHousing extends InventoryAdapterRestricted implements I
public static final int SLOT_PRODUCT_1 = 2;
public static final int SLOT_PRODUCT_COUNT = 7;
public InventoryBeeHousing(int size, IAccessHandler accessHandler) {
super(size, "Items", accessHandler);
public InventoryBeeHousing(int size) {
super(size, "Items");
}
@Override
@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.apiculture;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -19,34 +17,7 @@ import java.util.Objects;
import java.util.Random;
import java.util.Set;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import com.google.common.collect.ImmutableMap;
import forestry.Forestry;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
@@ -119,6 +90,32 @@ import forestry.food.items.ItemRegistryFood;
import forestry.plugins.BlankForestryPlugin;
import forestry.plugins.ForestryPlugin;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.VillagerRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ForestryPlugin(pluginID = ForestryPluginUids.APICULTURE, name = "Apiculture", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.apiculture.description")
public class PluginApiculture extends BlankForestryPlugin {
@@ -266,7 +263,7 @@ public class PluginApiculture extends BlankForestryPlugin {
VillagerRegistry villagerRegistry = VillagerRegistry.instance();
villagerRegistry.registerVillageCreationHandler(villageHandler);
villagerApiarist = new VillagerRegistry.VillagerProfession(Constants.ID_VILLAGER_APIARIST, Constants.TEXTURE_SKIN_BEEKPEEPER);
villagerApiarist = new VillagerRegistry.VillagerProfession(Constants.ID_VILLAGER_APIARIST, Constants.TEXTURE_SKIN_BEEKPEEPER, Constants.TEXTURE_SKIN_ZOMBIE_BEEKPEEPER);
villagerRegistry.register(villagerApiarist);
ItemStack wildcardPrincess = new ItemStack(items.beePrincessGE, 1);
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture.entities;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -36,9 +37,12 @@ import forestry.core.config.Config;
import forestry.core.inventory.IInventoryAdapter;
public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implements IApiary {
@Nonnull
private static final IBeeModifier beeModifier = new ApiaryBeeModifier();
@Nonnull
private final IBeeListener beeListener = new ApiaryBeeListener(this);
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
@Nonnull
private final InventoryApiary inventory = new InventoryApiary();
@SuppressWarnings("unused")
public EntityMinecartApiary(World world) {
@@ -64,6 +68,7 @@ public class EntityMinecartApiary extends EntityMinecartBeeHousingBase implement
return inventory;
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return inventory;
@@ -10,17 +10,12 @@
******************************************************************************/
package forestry.apiculture.entities;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Random;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import com.google.common.base.Optional;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingLogic;
@@ -36,10 +31,24 @@ import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IForestryPacketServer;
import forestry.core.network.IStreamableGui;
import forestry.core.owner.GameProfileDataSerializer;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.OwnerHandler;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.IClimatised;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IOwnedTile, IGuiBeeHousingInventory, IClimatised, IStreamableGui {
private static final DataParameter<Optional<GameProfile>> OWNER = EntityDataManager.createKey(EntityMinecart.class, GameProfileDataSerializer.INSTANCE);
public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContainerForestry implements IBeeHousing, IGuiBeeHousingInventory, IClimatised, IStreamableGui {
private static final Random random = new Random();
private static final int beeFXInterval = 4;
private static final int pollenFXInterval = 50;
@@ -49,6 +58,23 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
private final IBeekeepingLogic beeLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
private final IErrorLogic errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
private final OwnerHandler ownerHandler = new OwnerHandler() {
@Override
public void setOwner(@Nonnull GameProfile owner) {
super.setOwner(owner);
dataManager.set(OWNER, Optional.of(owner));
}
@Override
public GameProfile getOwner() {
Optional<GameProfile> gameProfileOptional = dataManager.get(OWNER);
if (gameProfileOptional.isPresent()) {
return gameProfileOptional.get();
} else {
return null;
}
}
};
// CLIENT
private int breedingProgressPercent = 0;
@@ -63,6 +89,18 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
super(world, posX, posY, posZ);
}
@Override
protected void entityInit() {
super.entityInit();
this.dataManager.register(OWNER, Optional.absent());
}
/* IOwnedTile */
@Override
public IOwnerHandler getOwnerHandler() {
return ownerHandler;
}
/* IBeeHousing */
@Override
public IBeekeepingLogic getBeekeepingLogic() {
@@ -111,7 +149,7 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
@Override
public GameProfile getOwner() {
return getAccessHandler().getOwner();
return getOwnerHandler().getOwner();
}
@Override
@@ -174,11 +212,13 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {
super.readEntityFromNBT(nbtTagCompound);
beeLogic.readFromNBT(nbtTagCompound);
ownerHandler.readFromNBT(nbtTagCompound);
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {
super.writeEntityToNBT(nbtTagCompound);
beeLogic.writeToNBT(nbtTagCompound);
ownerHandler.writeToNBT(nbtTagCompound);
}
}
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture.entities;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
@@ -33,7 +34,7 @@ import forestry.core.inventory.IInventoryAdapter;
public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase {
private static final IBeeModifier beeModifier = new BeehouseBeeModifier();
private static final IBeeListener beeListener = new DefaultBeeListener();
private final InventoryBeeHousing beeInventory = new InventoryBeeHousing(9, getAccessHandler());
private final InventoryBeeHousing beeInventory = new InventoryBeeHousing(9);
@SuppressWarnings("unused")
public EntityMinecartBeehouse(World world) {
@@ -72,6 +73,7 @@ public class EntityMinecartBeehouse extends EntityMinecartBeeHousingBase {
return Collections.singleton(beeListener);
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return beeInventory;
@@ -12,8 +12,8 @@ package forestry.apiculture.genetics;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
@@ -249,10 +249,10 @@ public class BeeRoot extends SpeciesRoot implements IBeeRoot {
/**
* List of possible mutations on species alleles.
*/
private static final ArrayList<IBeeMutation> beeMutations = new ArrayList<>();
private static final List<IBeeMutation> beeMutations = new ArrayList<>();
@Override
public Collection<IBeeMutation> getMutations(boolean shuffle) {
public List<IBeeMutation> getMutations(boolean shuffle) {
if (shuffle) {
Collections.shuffle(beeMutations);
}
@@ -1,9 +1,15 @@
package forestry.apiculture.genetics.alleles;
import java.util.List;
import java.util.Random;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.core.genetics.EffectData;
import forestry.core.utils.VectUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityMooshroom;
import net.minecraft.init.Blocks;
@@ -11,12 +17,6 @@ import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.core.genetics.EffectData;
public class AlleleEffectFungification extends AlleleEffectThrottled {
@@ -24,7 +24,7 @@ public class AlleleEffectFungification extends AlleleEffectThrottled {
private static final int ENTITY_THROTTLE = 6;
public AlleleEffectFungification() {
super("mycophilic", true, 10, false, false);
super("mycophilic", true, 20, false, false);
}
@Override
@@ -57,50 +57,51 @@ public class AlleleEffectFungification extends AlleleEffectThrottled {
World world = housing.getWorldObj();
BlockPos housingCoordinates = housing.getCoordinates();
Vec3i area = getModifiedArea(genome, housing);
int blockX = getRandomOffset(world.rand, housingCoordinates.getX(), area.getX());
int blockY = getRandomOffset(world.rand, housingCoordinates.getY(), area.getY());
int blockZ = getRandomOffset(world.rand, housingCoordinates.getZ(), area.getZ());
for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) {
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
Block block = world.getBlockState(pos).getBlock();
if (isSuitableForMycelium(world, block, pos)) {
world.setBlockState(pos, Blocks.MYCELIUM.getDefaultState());
break;
} else if (isSuitableForGrowth(block)) {
doMushroomGrowth(block, world, pos);
break;
}
blockX = getRandomOffset(world.rand, housingCoordinates.getX(), area.getX());
blockY = getRandomOffset(world.rand, housingCoordinates.getY(), area.getY());
blockZ = getRandomOffset(world.rand, housingCoordinates.getZ(), area.getZ());
}
Vec3i halfArea = new Vec3i(area.getX() / 2, area.getY() / 2, area.getZ() / 2);
for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) {
BlockPos pos = VectUtil.getRandomPositionInArea(world.rand, area).subtract(halfArea).add(housingCoordinates);
IBlockState blockState = world.getBlockState(pos);
if (convertToMycelium(world, blockState, pos)) {
return;
} else if (growGiantMushroom(world, blockState, pos)) {
return;
}
}
}
private static void doEntityEffect(IBeeGenome genome, IBeeHousing housing) {
List<EntityCow> cows = getEntitiesInRange(genome, housing, EntityCow.class);
for (EntityCow cow : cows) {
convertCowToMooshroom(cow);
if (convertCowToMooshroom(cow)) {
return;
}
}
}
private static int getRandomOffset(Random random, int centrePos, int offset) {
return centrePos + random.nextInt(offset) - offset / 2;
}
private static boolean isSuitableForMycelium(World world, Block block, BlockPos pos) {
return block == Blocks.GRASS || block == Blocks.DIRT && world.canBlockSeeSky(pos);
private static boolean convertToMycelium(World world, IBlockState blockState, BlockPos pos) {
Block block = blockState.getBlock();
if (block == Blocks.GRASS || block == Blocks.DIRT && world.canBlockSeeSky(pos)) {
world.setBlockState(pos, Blocks.MYCELIUM.getDefaultState());
return true;
}
return false;
}
private static boolean isSuitableForGrowth(Block block) {
return block == Blocks.RED_MUSHROOM || block == Blocks.BROWN_MUSHROOM;
private static boolean growGiantMushroom(World world, IBlockState blockState, BlockPos pos) {
Block block = blockState.getBlock();
if (block instanceof BlockMushroom) {
BlockMushroom mushroom = (BlockMushroom) block;
mushroom.generateBigMushroom(world, pos, blockState, world.rand);
return true;
}
return false;
}
private static void convertCowToMooshroom(EntityCow cow) {
private static boolean convertCowToMooshroom(EntityCow cow) {
if (cow instanceof EntityMooshroom) {
return;
return false;
}
World worldObj = cow.worldObj;
cow.setDead();
@@ -110,14 +111,6 @@ public class AlleleEffectFungification extends AlleleEffectThrottled {
mooshroom.renderYawOffset = cow.renderYawOffset;
worldObj.spawnEntityInWorld(mooshroom);
worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, cow.posX, cow.posY + cow.height / 2.0F, cow.posZ, 0.0D, 0.0D, 0.0D);
}
private static void doMushroomGrowth(Block block, World world, BlockPos pos) {
WorldGenBigMushroom giantMushroomGenerator;
giantMushroomGenerator = new WorldGenBigMushroom(block);
world.setBlockToAir(pos);
giantMushroomGenerator.generate(world, world.rand, pos);
return true;
}
}
@@ -22,15 +22,14 @@ import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.api.apiculture.IHiveFrame;
import forestry.apiculture.InventoryBeeHousing;
import forestry.core.access.IAccessHandler;
import forestry.core.utils.SlotUtil;
public class InventoryApiary extends InventoryBeeHousing implements IApiaryInventory {
public static final int SLOT_FRAMES_1 = 9;
public static final int SLOT_FRAMES_COUNT = 3;
public InventoryApiary(IAccessHandler accessHandler) {
super(12, accessHandler);
public InventoryApiary() {
super(12);
}
@Override
@@ -57,7 +57,7 @@ public class ItemHiveFrame extends ItemForestry implements IHiveFrame {
super.addInformation(stack, playerIn, tooltip, advanced);
beeModifier.addInformation(stack, playerIn, tooltip, advanced);
if (!stack.isItemDamaged()) {
tooltip.add(Translator.translateToLocalFormatted("item.for.frame.durability", stack.getMaxDamage()));
tooltip.add(Translator.translateToLocalFormatted("item.for.durability", stack.getMaxDamage()));
}
}
@@ -66,7 +66,8 @@ public class ItemMinecartBeehouse extends ItemMinecart implements IItemModelRegi
} else {
entityMinecart = new EntityMinecartApiary(worldIn, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F);
}
entityMinecart.setOwner(playerIn.getGameProfile());
entityMinecart.getOwnerHandler().setOwner(playerIn.getGameProfile());
if (stack.hasDisplayName()) {
entityMinecart.setCustomNameTag(stack.getDisplayName());
@@ -18,7 +18,6 @@ import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@@ -39,7 +38,6 @@ import forestry.api.multiblock.IAlvearyComponent;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.apiculture.AlvearyBeeModifier;
import forestry.apiculture.InventoryBeeHousing;
import forestry.core.access.EnumAccess;
import forestry.core.inventory.FakeInventoryAdapter;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.multiblock.IMultiblockControllerInternal;
@@ -53,6 +51,7 @@ import forestry.core.utils.Translator;
public class AlvearyController extends RectangularMultiblockControllerBase implements IAlvearyControllerInternal, IClimateControlled {
@Nonnull
private final InventoryBeeHousing inventory;
private final IBeekeepingLogic beekeepingLogic;
@@ -71,12 +70,13 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
public AlvearyController(World world) {
super(world, AlvearyMultiblockSizeLimits.instance);
this.inventory = new InventoryBeeHousing(9, getAccessHandler());
this.inventory = new InventoryBeeHousing(9);
this.beekeepingLogic = BeeManager.beeRoot.createBeekeepingLogic(this);
this.beeModifiers.add(new AlvearyBeeModifier());
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return inventory;
@@ -340,20 +340,6 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
return new Vec3d(coord.getX() + 0.5, coord.getY() + 1.5, coord.getZ() + 0.5);
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
// pipes connected to this need to update
for (IMultiblockComponent part : connectedParts) {
if (part instanceof TileEntity) {
TileEntity tile = (TileEntity) part;
worldObj.notifyBlockOfStateChange(tile.getPos(), tile.getBlockType());
}
}
markDirty();
}
}
@Override
public float getExactTemperature() {
BlockPos coords = getReferenceCoord();
@@ -383,7 +369,7 @@ public class AlvearyController extends RectangularMultiblockControllerBase imple
@Override
public GameProfile getOwner() {
return getAccessHandler().getOwner();
return getOwnerHandler().getOwner();
}
@Override
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture.multiblock;
import javax.annotation.Nonnull;
import java.util.Collections;
import net.minecraft.util.math.BlockPos;
@@ -45,6 +46,7 @@ public class FakeAlvearyController extends FakeMultiblockController implements I
return Collections.emptyList();
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return FakeBeeHousingInventory.instance;
@@ -11,13 +11,13 @@
package forestry.apiculture.multiblock;
import forestry.api.multiblock.IAlvearyController;
import forestry.core.access.IRestrictedAccess;
import forestry.core.owner.IOwnedTile;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.multiblock.IMultiblockControllerInternal;
import forestry.core.network.IStreamableGui;
import forestry.core.tiles.IClimatised;
public interface IAlvearyControllerInternal extends IAlvearyController, IMultiblockControllerInternal, IClimatised, IRestrictedAccess, IStreamableGui {
public interface IAlvearyControllerInternal extends IAlvearyController, IMultiblockControllerInternal, IClimatised, IOwnedTile, IStreamableGui {
IInventoryAdapter getInternalInventory();
int getHealthScaled(int i);
@@ -10,9 +10,12 @@
******************************************************************************/
package forestry.apiculture.multiblock;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.List;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
@@ -33,9 +36,6 @@ import forestry.api.multiblock.IMultiblockController;
import forestry.apiculture.blocks.BlockAlvearyType;
import forestry.apiculture.gui.ContainerAlveary;
import forestry.apiculture.gui.GuiAlveary;
import forestry.core.access.EnumAccess;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.config.Config;
import forestry.core.gui.IHintSource;
import forestry.core.inventory.IInventoryAdapter;
@@ -46,7 +46,7 @@ import forestry.core.network.IStreamableGui;
import forestry.core.tiles.IClimatised;
import forestry.core.tiles.ITitled;
public abstract class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent, IRestrictedAccess, IStreamableGui, ITitled, IClimatised, IHintSource {
public abstract class TileAlveary extends MultiblockTileEntityForestry<MultiblockLogicAlveary> implements IBeeHousing, IAlvearyComponent, IOwnedTile, IStreamableGui, ITitled, IClimatised, IHintSource {
private final String unlocalizedTitle;
protected TileAlveary() {
@@ -99,6 +99,7 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry<Multibloc
return getMultiblockLogic().getController().getBeeListeners();
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return getMultiblockLogic().getController().getBeeInventory();
@@ -141,13 +142,8 @@ public abstract class TileAlveary extends MultiblockTileEntityForestry<Multibloc
}
@Override
public IAccessHandler getAccessHandler() {
return getMultiblockLogic().getController().getAccessHandler();
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess);
public IOwnerHandler getOwnerHandler() {
return getMultiblockLogic().getController().getOwnerHandler();
}
@Override
@@ -11,6 +11,7 @@
package forestry.apiculture.multiblock;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@@ -23,6 +24,7 @@ import forestry.core.tiles.IActivatable;
import forestry.energy.EnergyManager;
import cofh.api.energy.IEnergyReceiver;
import net.minecraftforge.common.capabilities.Capability;
public abstract class TileAlvearyClimatiser extends TileAlveary implements IEnergyReceiver, IActivatable, IAlvearyComponent.Climatiser {
@@ -143,4 +145,18 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
return energyManager.canConnectEnergy(from);
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
}
@Nonnull
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
T energyCapability = energyManager.getCapability(capability);
if (energyCapability != null) {
return energyCapability;
}
return super.getCapability(capability, facing);
}
}
@@ -1,10 +1,13 @@
package forestry.apiculture.tiles;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IBeeHousingInventory;
public class FakeBeeHousingInventory implements IBeeHousingInventory {
@Nonnull
public static final FakeBeeHousingInventory instance = new FakeBeeHousingInventory();
private FakeBeeHousingInventory() {
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture.tiles;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -30,15 +31,19 @@ import forestry.apiculture.inventory.IApiaryInventory;
import forestry.apiculture.inventory.InventoryApiary;
public class TileApiary extends TileBeeHousingBase implements IApiary {
@Nonnull
private final IBeeModifier beeModifier = new ApiaryBeeModifier();
@Nonnull
private final IBeeListener beeListener = new ApiaryBeeListener(this);
private final InventoryApiary inventory = new InventoryApiary(getAccessHandler());
@Nonnull
private final InventoryApiary inventory = new InventoryApiary();
public TileApiary() {
super("apiary");
setInternalInventory(inventory);
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return inventory;
@@ -10,6 +10,7 @@
******************************************************************************/
package forestry.apiculture.tiles;
import javax.annotation.Nonnull;
import java.util.Collections;
import net.minecraft.entity.player.EntityPlayer;
@@ -24,20 +25,24 @@ import forestry.apiculture.gui.ContainerBeeHousing;
import forestry.apiculture.gui.GuiBeeHousing;
public class TileBeeHouse extends TileBeeHousingBase {
@Nonnull
private static final IBeeModifier beeModifier = new BeehouseBeeModifier();
@Nonnull
private final IBeeListener beeListener;
@Nonnull
private final InventoryBeeHousing beeInventory;
public TileBeeHouse() {
super("bee.house");
this.beeListener = new DefaultBeeListener();
beeInventory = new InventoryBeeHousing(12, getAccessHandler());
beeInventory = new InventoryBeeHousing(12);
beeInventory.disableAutomation();
setInternalInventory(beeInventory);
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return beeInventory;
@@ -13,13 +13,7 @@ package forestry.apiculture.tiles;
import javax.annotation.Nonnull;
import java.io.IOException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingLogic;
@@ -30,11 +24,19 @@ import forestry.apiculture.gui.IGuiBeeHousingInventory;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamableGui;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.OwnerHandler;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.IClimatised;
import forestry.core.tiles.TileBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IClimatised, IGuiBeeHousingInventory, IStreamableGui {
public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing, IOwnedTile, IClimatised, IGuiBeeHousingInventory, IStreamableGui {
private final OwnerHandler ownerHandler = new OwnerHandler();
private final IBeekeepingLogic beeLogic;
private Biome cachedBiome;
@@ -57,6 +59,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound = super.writeToNBT(nbttagcompound);
beeLogic.writeToNBT(nbttagcompound);
ownerHandler.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@@ -64,6 +67,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
beeLogic.readFromNBT(nbttagcompound);
ownerHandler.readFromNBT(nbttagcompound);
}
@Nonnull
@@ -71,6 +75,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
public NBTTagCompound getUpdateTag() {
NBTTagCompound updateTag = super.getUpdateTag();
beeLogic.writeToNBT(updateTag);
ownerHandler.writeToNBT(updateTag);
return updateTag;
}
@@ -78,6 +83,12 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
super.handleUpdateTag(tag);
beeLogic.readFromNBT(tag);
ownerHandler.readFromNBT(tag);
}
@Override
public IOwnerHandler getOwnerHandler() {
return ownerHandler;
}
/* ICLIMATISED */
@@ -171,7 +182,7 @@ public abstract class TileBeeHousingBase extends TileBase implements IBeeHousing
@Override
public GameProfile getOwner() {
return getAccessHandler().getOwner();
return getOwnerHandler().getOwner();
}
@Override
@@ -15,26 +15,8 @@ import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import com.google.common.base.Predicate;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
@@ -62,9 +44,41 @@ import forestry.core.tiles.IActivatable;
import forestry.core.utils.DamageSourceForestry;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
public class TileHive extends TileEntity implements ITickable, IHiveTile, IActivatable, IBeeHousing {
private static final DamageSource damageSourceBeeHive = new DamageSourceForestry("bee.hive");
private static final Predicate<EntityLivingBase> BEE_TARGET_PREDICATE = new Predicate<EntityLivingBase>() {
@Override
public boolean apply(@Nullable EntityLivingBase input) {
if (input != null && input.isEntityAlive() && !input.isInvisible()) {
if (input instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) input;
return !player.isSpectator() && !player.isCreative();
} else if (input instanceof IMob) {
return true;
}
}
return false;
}
};
@Nonnull
private final InventoryAdapter contained = new InventoryAdapter(2, "Contained");
@@ -113,7 +127,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
if (calmTime == 0) {
if (canWork) {
AxisAlignedBB boundingBox = AlleleEffect.getBounding(getContainedBee().getGenome(), this);
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox);
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox, BEE_TARGET_PREDICATE);
if (!entities.isEmpty()) {
Collections.shuffle(entities);
EntityLivingBase entity = entities.get(0);
@@ -293,6 +307,7 @@ public class TileHive extends TileEntity implements ITickable, IHiveTile, IActiv
return Collections.emptyList();
}
@Nonnull
@Override
public IBeeHousingInventory getBeeInventory() {
return inventory;
@@ -34,6 +34,7 @@ import forestry.api.genetics.ISaplingTranslator;
import forestry.api.recipes.RecipeManagers;
import forestry.api.storage.ICrateRegistry;
import forestry.api.storage.StorageManager;
import forestry.arboriculture.blocks.BlockForestryLeaves;
import forestry.arboriculture.blocks.BlockPile;
import forestry.arboriculture.blocks.BlockRegistryArboriculture;
import forestry.arboriculture.blocks.log.BlockArbLog;
@@ -49,6 +50,7 @@ import forestry.arboriculture.genetics.alleles.AlleleFruit;
import forestry.arboriculture.genetics.alleles.AlleleGrowth;
import forestry.arboriculture.genetics.alleles.AlleleLeafEffect;
import forestry.arboriculture.items.ItemCharcoal;
import forestry.arboriculture.items.ItemGrafter;
import forestry.arboriculture.items.ItemRegistryArboriculture;
import forestry.arboriculture.models.TextureLeaves;
import forestry.arboriculture.network.PacketRegistryArboriculture;
@@ -79,12 +81,16 @@ import net.minecraft.block.BlockNewLeaf;
import net.minecraft.block.BlockOldLeaf;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.IFuelHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
@@ -192,7 +198,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
blocks.treeChest.init();
if (Config.enableVillagers) {
villagerArborist = new VillagerRegistry.VillagerProfession(Constants.ID_VILLAGER_ARBORIST, Constants.TEXTURE_SKIN_LUMBERJACK);
villagerArborist = new VillagerRegistry.VillagerProfession(Constants.ID_VILLAGER_ARBORIST, Constants.TEXTURE_SKIN_LUMBERJACK, Constants.TEXTURE_SKIN_ZOMBIE_LUMBERJACK);
VillagerRegistry.instance().register(villagerArborist);
VillagerRegistry.VillagerCareer arboristCareer = new VillagerRegistry.VillagerCareer(villagerArborist, "arborist");
@@ -546,4 +552,31 @@ public class PluginArboriculture extends BlankForestryPlugin {
alleleFruit.getProvider().registerSprites();
}
}
@SubscribeEvent
public void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
IBlockState state = event.getState();
Block block = state.getBlock();
if (block instanceof BlockLeaves && !(block instanceof BlockForestryLeaves)) {
EntityPlayer player = event.getHarvester();
if (player != null) {
ItemStack harvestingTool = player.getHeldItemMainhand();
if (harvestingTool != null && harvestingTool.getItem() instanceof ItemGrafter) {
if (event.getDrops().isEmpty()) {
World world = event.getWorld();
Item itemDropped = block.getItemDropped(state, world.rand, 3);
if (itemDropped != null) {
event.getDrops().add(new ItemStack(itemDropped, 1, block.damageDropped(state)));
}
}
harvestingTool.damageItem(1, player);
if (harvestingTool.stackSize <= 0) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, harvestingTool, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}
}
}
}
}
}
@@ -101,7 +101,6 @@ public class BlockArbDoor extends BlockDoor implements IWoodTyped, IItemModelReg
}
@Override
@SideOnly(Side.CLIENT)
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
return new ItemStack(getItem());
}
@@ -16,6 +16,29 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.IToolGrafter;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.IToolScoop;
import forestry.api.core.Tabs;
import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.EnumFlutterType;
import forestry.api.lepidopterology.IButterfly;
import forestry.arboriculture.LeafDecayHelper;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.blocks.IColoredBlock;
import forestry.core.blocks.propertys.UnlistedBlockAccess;
import forestry.core.blocks.propertys.UnlistedBlockPos;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.BlockUtil;
import forestry.core.utils.ItemStackUtil;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.IGrowable;
@@ -40,9 +63,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
@@ -50,29 +70,6 @@ import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.IToolGrafter;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.IToolScoop;
import forestry.api.core.Tabs;
import forestry.api.lepidopterology.ButterflyManager;
import forestry.api.lepidopterology.EnumFlutterType;
import forestry.api.lepidopterology.IButterfly;
import forestry.arboriculture.LeafDecayHelper;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.genetics.TreeDefinition;
import forestry.arboriculture.tiles.TileLeaves;
import forestry.core.blocks.IColoredBlock;
import forestry.core.blocks.propertys.UnlistedBlockAccess;
import forestry.core.blocks.propertys.UnlistedBlockPos;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.BlockUtil;
import forestry.core.utils.ItemStackUtil;
public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvider, IGrowable, IItemModelRegister, IColoredBlock {
public BlockForestryLeaves() {
@@ -137,17 +134,16 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getActiveItemStack());
float saplingModifier = 1.0f;
if (!world.isRemote) {
ItemStack held = player.inventory.getCurrentItem();
if (held != null && held.getItem() instanceof IToolGrafter) {
saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, pos);
held.damageItem(1, player);
if (held.stackSize <= 0) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, held, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}
ItemStack held = player.inventory.getCurrentItem();
if (held != null && held.getItem() instanceof IToolGrafter) {
saplingModifier = ((IToolGrafter) held.getItem()).getSaplingModifier(held, world, player, pos);
held.damageItem(1, player);
if (held.stackSize <= 0) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, held, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, null);
}
}
GameProfile playerProfile = player.getGameProfile();
List<ItemStack> leafDrops = getLeafDrop(world, playerProfile, pos, saplingModifier, fortune);
drops.set(leafDrops);
@@ -13,17 +13,16 @@ package forestry.arboriculture.commands;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.World;
import forestry.api.arboriculture.ITreekeepingMode;
import forestry.api.arboriculture.TreeManager;
import forestry.core.commands.ICommandModeHelper;
import net.minecraft.world.World;
public class TreeModeHelper implements ICommandModeHelper {
@Override
public String[] getModeNames() {
ArrayList<ITreekeepingMode> treekeepingModes = TreeManager.treeRoot.getTreekeepingModes();
List<ITreekeepingMode> treekeepingModes = TreeManager.treeRoot.getTreekeepingModes();
int modeStringCount = treekeepingModes.size();
List<String> modeStrings = new ArrayList<>(modeStringCount);
for (ITreekeepingMode mode : treekeepingModes) {
@@ -1010,7 +1010,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe
return false;
}
tileLeaves.setOwner(owner);
tileLeaves.getOwnerHandler().setOwner(owner);
tileLeaves.setTree(new Tree(genome));
world.markBlockRangeForRenderUpdate(pos, pos);
@@ -219,15 +219,14 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
return false;
}
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileSapling)) {
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
if (sapling == null) {
world.setBlockToAir(pos);
return false;
}
TileSapling sapling = (TileSapling) tile;
sapling.setTree(tree.copy());
sapling.setOwner(owner);
sapling.getOwnerHandler().setOwner(owner);
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, blockState);
Proxies.net.sendNetworkPacket(packet, world);
@@ -10,6 +10,9 @@
******************************************************************************/
package forestry.arboriculture.items;
import java.util.List;
import forestry.core.utils.Translator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.material.Material;
@@ -34,6 +37,14 @@ public class ItemGrafter extends ItemForestryTool implements IToolGrafter {
setEfficiencyOnProperMaterial(4.0f);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
super.addInformation(stack, playerIn, tooltip, advanced);
if (!stack.isItemDamaged()) {
tooltip.add(Translator.translateToLocalFormatted("item.for.uses", stack.getMaxDamage() + 1));
}
}
@Override
public boolean canHarvestBlock(IBlockState state, ItemStack stack) {
Block block = state.getBlock();
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.arboriculture.items;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.arboriculture.EnumGermlingType;
@@ -28,8 +30,12 @@ public class ItemRegistryArboriculture extends ItemRegistry {
OreDictionary.registerOre(OreDictUtil.TREE_SAPLING, sapling.getWildcard());
pollenFertile = registerItem(new ItemGermlingGE(EnumGermlingType.POLLEN), "pollenFertile");
charcoal = registerItem(new ItemCharcoal(), "charcoal");
grafter = registerItem(new ItemGrafter(4), "grafter");
registerOreDict(OreDictUtil.CHARCOAL, new ItemStack(charcoal, 1, OreDictionary.WILDCARD_VALUE));
registerOreDict(OreDictUtil.CHARCOAL, new ItemStack(Items.COAL, 1, 1));
grafter = registerItem(new ItemGrafter(9), "grafter");
grafterProven = registerItem(new ItemGrafter(149), "grafterProven");
}
}
@@ -13,7 +13,6 @@ import forestry.api.multiblock.IMultiblockComponent;
import forestry.apiculture.network.packets.PacketActiveUpdate;
import forestry.arboriculture.PluginArboriculture;
import forestry.arboriculture.blocks.BlockPile;
import forestry.core.access.EnumAccess;
import forestry.core.multiblock.IMultiblockControllerInternal;
import forestry.core.multiblock.MultiblockRegistry;
import forestry.core.multiblock.MultiblockValidationException;
@@ -307,10 +306,6 @@ public class CharcoalPileController extends RectangularMultiblockControllerBase
active = data.readBoolean();
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
}
@Override
public EnumTemperature getTemperature() {
return null;
@@ -461,7 +461,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
int caterpillarMatureTime = Math.round((float) caterpillarGenome.getLifespan() / (caterpillarGenome.getFertility() * 2));
if (maturationTime >= caterpillarMatureTime) {
ButterflyManager.butterflyRoot.plantCocoon(worldObj, this, getOwner(), 0);
ButterflyManager.butterflyRoot.plantCocoon(worldObj, this, getOwnerHandler().getOwner(), 0);
setCaterpillar(null);
} else if (!wasDestroyed && isDestroyed(tree, damage)) {
sendNetworkUpdate();
@@ -106,7 +106,7 @@ public class TileSapling extends TileTreeContainer {
}
if (generated) {
IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(worldObj, getOwner());
IBreedingTracker breedingTracker = TreeManager.treeRoot.getBreedingTracker(worldObj, getOwnerHandler().getOwner());
breedingTracker.registerBirth(tree);
}
}
@@ -15,9 +15,19 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Random;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.genetics.Tree;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.OwnerHandler;
import forestry.core.utils.NBTUtilForestry;
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.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
@@ -25,30 +35,16 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.genetics.Tree;
import forestry.core.access.IOwnable;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.utils.NBTUtilForestry;
import forestry.core.utils.PlayerUtil;
/**
* This is the base TE class for any block that needs to contain tree genome information.
*
* @author SirSengir
*/
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnable {
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnedTile {
@Nullable
private ITree containedTree;
@Nullable
private GameProfile owner;
private final OwnerHandler ownerHandler = new OwnerHandler();
/* SAVING & LOADING */
@Override
@@ -58,9 +54,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
if (nbttagcompound.hasKey("ContainedTree")) {
containedTree = new Tree(nbttagcompound.getCompoundTag("ContainedTree"));
}
if (nbttagcompound.hasKey("owner")) {
owner = PlayerUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("owner"));
}
ownerHandler.readFromNBT(nbttagcompound);
}
@Nonnull
@@ -73,11 +67,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
containedTree.writeToNBT(subcompound);
nbttagcompound.setTag("ContainedTree", subcompound);
}
if (this.owner != null) {
NBTTagCompound nbt = new NBTTagCompound();
PlayerUtil.writeGameProfile(nbt, owner);
nbttagcompound.setTag("owner", nbt);
}
ownerHandler.writeToNBT(nbttagcompound);
return nbttagcompound;
}
@@ -122,26 +112,9 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl
return this.containedTree;
}
/* IOwnable */
@Nullable
@Override
public GameProfile getOwner() {
return owner;
}
@Override
public void setOwner(@Nonnull 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);
public IOwnerHandler getOwnerHandler() {
return ownerHandler;
}
/* UPDATING */
@@ -78,7 +78,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
if (tile == null) {
return null;
}
return tile.getOwner();
return tile.getOwnerHandler().getOwner();
}
public void preGenerate(World world, Random rand, BlockPos startPos) {
@@ -10,18 +10,14 @@
******************************************************************************/
package forestry.arboriculture.worldgen;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.world.ITreeGenData;
import forestry.core.worldgen.WorldGenHelper;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class WorldGenBalsa extends WorldGenTree {
@@ -31,7 +27,8 @@ public class WorldGenBalsa extends WorldGenTree {
@Override
protected void generateLeaves(World world, Random rand, TreeBlockTypeLeaf leaf, List<BlockPos> branchEnds, BlockPos startPos) {
BlockPos.MutableBlockPos leafCenter = new BlockPos.MutableBlockPos(startPos.add(0, height, 0));
BlockPos topPos = startPos.add(0, height + 1, 0);
BlockPos.MutableBlockPos leafCenter = new BlockPos.MutableBlockPos(topPos);
float leafRadius = (girth - 1.0f) / 2.0f;
WorldGenHelper.addBlock(world, leafCenter, leaf, WorldGenHelper.EnumReplaceMode.AIR);
@@ -44,7 +41,7 @@ public class WorldGenBalsa extends WorldGenTree {
leafCenter.move(EnumFacing.DOWN);
}
while (leafCenter.getY() > 6) {
while (leafCenter.getY() > topPos.getY() - 6) {
WorldGenHelper.generateCylinderFromPos(world, leaf, leafCenter, leafRadius + girth, 1, WorldGenHelper.EnumReplaceMode.SOFT);
leafCenter.move(EnumFacing.DOWN);
}
@@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import forestry.core.owner.GameProfileDataSerializer;
import net.minecraft.command.ICommand;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@@ -119,6 +120,8 @@ public class PluginCore extends BlankForestryPlugin {
public void preInit() {
super.preInit();
GameProfileDataSerializer.register();
MinecraftForge.EVENT_BUS.register(this);
rootCommand.addChildCommand(new CommandPlugins());
@@ -1,190 +0,0 @@
/*******************************************************************************
* 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.core.access;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.core.config.Config;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.packets.PacketAccessSwitch;
import forestry.core.network.packets.PacketAccessSwitchEntity;
import forestry.core.proxy.Proxies;
import forestry.core.tiles.ILocatable;
import forestry.core.utils.PlayerUtil;
public final class AccessHandler implements IAccessHandler {
private final IRestrictedAccess accessListener;
private final List<IAccessOwnerListener> accessOwnerListeners = new ArrayList<>();
private final Object target;
private GameProfile owner = null;
private EnumAccess access = EnumAccess.SHARED;
public <T extends IRestrictedAccess & ILocatable> AccessHandler(T tile) {
this.accessListener = tile;
this.target = tile;
}
public <T extends Entity & IRestrictedAccess> AccessHandler(T entity) {
this.accessListener = entity;
this.target = entity;
}
@Override
public void addOwnerListener(IAccessOwnerListener accessListener) {
accessOwnerListeners.add(accessListener);
}
@Override
public void removeOwnerListener(IAccessOwnerListener accessListener) {
accessOwnerListeners.remove(accessListener);
}
@Override
public final boolean allowsRemoval(EntityPlayer player) {
return !Config.enablePermissions || getAccess() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
}
@Override
public final boolean allowsAlteration(EntityPlayer player) {
return allowsRemoval(player);
}
@Override
public final boolean allowsViewing(EntityPlayer player) {
return allowsAlteration(player) || getAccess() == EnumAccess.VIEWABLE;
}
@Override
public boolean allowsInteracting(EntityPlayer player) {
return allowsAlteration(player);
}
@Override
public final boolean allowsPipeConnections() {
return access == EnumAccess.SHARED;
}
@Override
public EnumAccess getAccess() {
return access;
}
@Override
public boolean isOwned() {
return owner != null;
}
@Override
public GameProfile getOwner() {
return owner;
}
@Override
public void setOwner(@Nonnull GameProfile owner) {
this.owner = owner;
for (IAccessOwnerListener listener : accessOwnerListeners) {
listener.onOwnerSet(owner);
}
}
@Override
public boolean isOwner(EntityPlayer player) {
return PlayerUtil.isSameGameProfile(owner, player.getGameProfile());
}
@Override
public boolean switchAccess(EntityPlayer player) {
if (!isOwner(player)) {
return false;
}
int ordinal = (access.ordinal() + 1) % EnumAccess.values().length;
EnumAccess newAccess = EnumAccess.values()[ordinal];
setAccess(player.worldObj, newAccess);
return true;
}
private void setAccess(World world, EnumAccess access) {
EnumAccess oldAccess = this.access;
if (oldAccess == access) {
return;
}
this.access = access;
if (world.isRemote) {
if (target instanceof ILocatable) {
Proxies.net.sendToServer(new PacketAccessSwitch((ILocatable) target));
} else if (target instanceof Entity) {
Proxies.net.sendToServer(new PacketAccessSwitchEntity((Entity) target));
}
} else {
accessListener.onSwitchAccess(oldAccess, access);
}
}
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
if (owner == null) {
data.writeByte(-1);
} else {
data.writeByte(access.ordinal());
data.writeLong(owner.getId().getMostSignificantBits());
data.writeLong(owner.getId().getLeastSignificantBits());
data.writeUTF(owner.getName());
}
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
byte accessOrdinal = data.readByte();
if (accessOrdinal >= 0) {
access = EnumAccess.values()[accessOrdinal];
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
setOwner(owner);
}
}
@Override
public void readFromNBT(NBTTagCompound data) {
access = EnumAccess.values()[data.getInteger("Access")];
if (data.hasKey("owner")) {
owner = PlayerUtil.readGameProfileFromNBT(data.getCompoundTag("owner"));
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
data.setInteger("Access", access.ordinal());
if (this.owner != null) {
NBTTagCompound nbt = new NBTTagCompound();
PlayerUtil.writeGameProfile(nbt, owner);
data.setTag("owner", nbt);
}
return data;
}
}
@@ -1,34 +0,0 @@
/*******************************************************************************
* 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.core.access;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public enum EnumAccess {
SHARED("for.gui.rule.shared"), VIEWABLE("for.gui.rule.restricted"), PRIVATE("for.gui.rule.private");
private final String unlocalizedName;
@SideOnly(Side.CLIENT)
private TextureAtlasSprite icon;
EnumAccess(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
}
public String getUnlocalizedName() {
return this.unlocalizedName;
}
}
@@ -1,122 +0,0 @@
/*******************************************************************************
* 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.core.access;
import javax.annotation.Nonnull;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import com.mojang.authlib.GameProfile;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
public class FakeAccessHandler implements IAccessHandler {
private static FakeAccessHandler instance;
public static FakeAccessHandler getInstance() {
if (instance == null) {
instance = new FakeAccessHandler();
}
return instance;
}
private FakeAccessHandler() {
}
@Override
public boolean switchAccess(EntityPlayer player) {
return false;
}
@Override
public EnumAccess getAccess() {
return EnumAccess.SHARED;
}
@Override
public boolean allowsRemoval(EntityPlayer player) {
return true;
}
@Override
public boolean allowsAlteration(EntityPlayer player) {
return true;
}
@Override
public boolean allowsViewing(EntityPlayer player) {
return true;
}
@Override
public boolean allowsInteracting(EntityPlayer player) {
return true;
}
@Override
public boolean allowsPipeConnections() {
return true;
}
@Override
public void addOwnerListener(IAccessOwnerListener accessListener) {
}
@Override
public void removeOwnerListener(IAccessOwnerListener accessListener) {
}
@Override
public boolean isOwned() {
return false;
}
@Override
public GameProfile getOwner() {
return null;
}
@Override
public void setOwner(@Nonnull GameProfile owner) {
}
@Override
public boolean isOwner(EntityPlayer player) {
return true;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
return nbttagcompound;
}
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
}
}
@@ -1,39 +0,0 @@
/*******************************************************************************
* 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.core.access;
import net.minecraft.entity.player.EntityPlayer;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import forestry.core.network.IStreamable;
public interface IAccessHandler extends IOwnable, IStreamable, INbtWritable, INbtReadable {
boolean switchAccess(EntityPlayer player);
EnumAccess getAccess();
boolean allowsRemoval(EntityPlayer player);
boolean allowsAlteration(EntityPlayer player);
boolean allowsViewing(EntityPlayer player);
boolean allowsInteracting(EntityPlayer player);
boolean allowsPipeConnections();
void addOwnerListener(IAccessOwnerListener accessListener);
void removeOwnerListener(IAccessOwnerListener accessListener);
}
@@ -1,17 +0,0 @@
/*******************************************************************************
* 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.core.access;
public interface IRestrictedAccess {
IAccessHandler getAccessHandler();
void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess);
}
@@ -36,7 +36,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidUtil;
@@ -50,7 +49,6 @@ import forestry.api.core.IModelManager;
import forestry.api.core.ISpriteRegister;
import forestry.api.core.IStateMapperRegister;
import forestry.api.core.ITextureManager;
import forestry.core.access.IAccessHandler;
import forestry.core.circuits.ISocketable;
import forestry.core.proxy.Proxies;
import forestry.core.render.MachineParticleCallback;
@@ -60,7 +58,6 @@ import forestry.core.tiles.TileBase;
import forestry.core.tiles.TileForestry;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.PlayerUtil;
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister {
/** use this instead of {@link BlockHorizontal#FACING} so the blocks rotate in a circle instead of NSWE order. */
@@ -148,35 +145,25 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
TileBase tile = TileUtil.getTile(worldIn, pos, TileBase.class);
if (tile == null) {
return false;
}
if (tile != null) {
if (TileUtil.isUsableByPlayer(playerIn, tile)) {
if (!TileUtil.isUsableByPlayer(playerIn, tile)) {
return false;
}
IAccessHandler access = tile.getAccessHandler();
if (!playerIn.isSneaking()) {
if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler tileFluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, playerIn)) {
return true;
if (!playerIn.isSneaking()) {
if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler tileFluidHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
if (FluidUtil.interactWithFluidHandler(heldItem, tileFluidHandler, playerIn)) {
return true;
}
}
}
if (!worldIn.isRemote) {
tile.openGui(playerIn, heldItem);
}
return true;
}
}
if (worldIn.isRemote) {
return true;
}
if (access.allowsViewing(playerIn)) {
tile.openGui(playerIn, heldItem);
} else {
playerIn.addChatMessage(new TextComponentTranslation("for.chat.accesslocked", PlayerUtil.getOwnerName(access)));
}
return true;
return false;
}
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.core.blocks;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.IOwnerHandler;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
@@ -25,8 +27,6 @@ import com.mojang.authlib.GameProfile;
import forestry.api.core.IItemModelRegister;
import forestry.core.CreativeTabForestry;
import forestry.core.access.IOwnable;
import forestry.core.access.IRestrictedAccess;
import forestry.core.tiles.TileForestry;
import forestry.core.utils.Log;
@@ -38,20 +38,6 @@ public abstract class BlockForestry extends Block implements IItemModelRegister,
setCreativeTab(CreativeTabForestry.tabForestry);
}
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
if (!restrictedAccessTile.getAccessHandler().allowsRemoval(player)) {
return false;
}
}
return super.removedByPlayer(state, world, pos, player, willHarvest);
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
if (world.isRemote) {
@@ -61,19 +47,12 @@ public abstract class BlockForestry extends Block implements IItemModelRegister,
if (placer instanceof EntityPlayer) {
TileEntity tile = world.getTileEntity(pos);
IOwnable ownable;
if (tile instanceof IRestrictedAccess) {
ownable = ((IRestrictedAccess) tile).getAccessHandler();
} else if (tile instanceof IOwnable) {
ownable = (IOwnable) tile;
} else {
return;
if (tile instanceof IOwnedTile) {
IOwnerHandler ownerHandler = ((IOwnedTile) tile).getOwnerHandler();
EntityPlayer player = (EntityPlayer) placer;
GameProfile gameProfile = player.getGameProfile();
ownerHandler.setOwner(gameProfile);
}
EntityPlayer player = (EntityPlayer) placer;
GameProfile gameProfile = player.getGameProfile();
ownable.setOwner(gameProfile);
}
}
@@ -19,35 +19,18 @@ import forestry.core.utils.Translator;
public abstract class Circuit implements ICircuit {
private final String uid;
private final boolean requiresDiscovery;
private int limit = 1;
protected Circuit(String uid, boolean requiresDiscovery) {
protected Circuit(String uid) {
this.uid = uid;
this.requiresDiscovery = requiresDiscovery;
ChipsetManager.circuitRegistry.registerCircuit(this);
}
protected void setLimit(int limit) {
this.limit = limit;
}
@Override
public String getUID() {
return "forestry." + this.uid;
}
@Override
public int getLimit() {
return this.limit;
}
@Override
public boolean requiresDiscovery() {
return this.requiresDiscovery;
}
@Override
public String getUnlocalizedName() {
return "for.circuit." + this.uid;
@@ -11,6 +11,7 @@
package forestry.core.circuits;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -29,7 +30,7 @@ public class CircuitBoard<T> implements ICircuitBoard {
@Nonnull
private final EnumCircuitBoardType type;
@Nonnull
@Nullable
private final ICircuitLayout layout;
@Nonnull
private final ICircuit[] circuits;
@@ -80,19 +81,23 @@ public class CircuitBoard<T> implements ICircuitBoard {
public void addTooltip(List<String> list) {
if (layout != null) {
list.add(TextFormatting.GOLD + layout.getUsage() + ":");
}
List<String> extendedTooltip = new ArrayList<>();
for (ICircuit circuit : circuits) {
if (circuit != null) {
circuit.addTooltip(extendedTooltip);
List<String> extendedTooltip = new ArrayList<>();
for (ICircuit circuit : circuits) {
if (circuit != null) {
circuit.addTooltip(extendedTooltip);
}
}
}
if (Proxies.common.isShiftDown() || extendedTooltip.size() <= 4) {
list.addAll(extendedTooltip);
if (Proxies.common.isShiftDown() || extendedTooltip.size() <= 4) {
list.addAll(extendedTooltip);
} else {
list.add(TextFormatting.ITALIC + "<" + Translator.translateToLocal("for.gui.tooltip.tmi") + ">");
}
} else {
list.add(TextFormatting.ITALIC + "<" + Translator.translateToLocal("for.gui.tooltip.tmi") + ">");
int socketCount = type.getSockets();
String localizationKey = "item.for.circuitboard.tooltip." + (socketCount == 1 ? "singular" : "plural");
String tooltip = Translator.translateToLocalFormatted(localizationKey, type.getSockets());
list.add(tooltip);
}
}
@@ -11,20 +11,22 @@
package forestry.core.circuits;
public enum EnumCircuitBoardType {
BASIC((short) 1, 0x191919, 0x6dcff6), ENHANCED((short) 2, 0x191919, 0xcb7c32), REFINED((short) 3, 0x191919, 0xc9c9c9), INTRICATE((short) 4, 0x191919,
0xe2cb6b);
BASIC(1, 0x191919, 0x6dcff6),
ENHANCED(2, 0x191919, 0xcb7c32),
REFINED(3, 0x191919, 0xc9c9c9),
INTRICATE(4, 0x191919, 0xe2cb6b);
private final short sockets;
private final int sockets;
private final int primaryColor;
private final int secondaryColor;
EnumCircuitBoardType(short sockets, int primaryColor, int secondaryColor) {
EnumCircuitBoardType(int sockets, int primaryColor, int secondaryColor) {
this.sockets = sockets;
this.primaryColor = primaryColor;
this.secondaryColor = secondaryColor;
}
public short getSockets() {
public int getSockets() {
return sockets;
}
@@ -50,7 +50,7 @@ public class GuiSolderingIron extends GuiForestry<ContainerSolderingIron, ItemIn
if (recipe == null) {
description = "(" + Translator.translateToLocal("for.gui.noeffect") + ")";
} else {
description = Translator.translateToLocal(recipe.getCircuit().getUnlocalizedName()) + " (" + recipe.getCircuit().getLimit() + ")";
description = Translator.translateToLocal(recipe.getCircuit().getUnlocalizedName());
}
int row = i * 20;
@@ -41,7 +41,9 @@ public class Constants implements IForestryConstants {
public static final String TEXTURE_APIARIST_ARMOR_SECONDARY = TEXTURE_PATH_ITEMS + "/apiarist_armor_2.png";
public static final String TEXTURE_NATURALIST_ARMOR_PRIMARY = TEXTURE_PATH_ITEMS + "/naturalist_armor_1.png";
public static final String TEXTURE_SKIN_BEEKPEEPER = Constants.MOD_ID + ":" + TEXTURE_PATH_ENTITIES + "/beekeeper.png";
public static final String TEXTURE_SKIN_ZOMBIE_BEEKPEEPER = Constants.MOD_ID + ":" + TEXTURE_PATH_ENTITIES + "/zombie_beekeeper.png";
public static final String TEXTURE_SKIN_LUMBERJACK = Constants.MOD_ID + ":" + TEXTURE_PATH_ENTITIES + "/lumberjack.png";
public static final String TEXTURE_SKIN_ZOMBIE_LUMBERJACK = Constants.MOD_ID + ":" + TEXTURE_PATH_ENTITIES + "/zombie_lumberjack.png";
// Villagers
public static final String ID_VILLAGER_APIARIST = Constants.MOD_ID + ":apiarist";
@@ -10,33 +10,23 @@
******************************************************************************/
package forestry.core.entities;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
import forestry.core.access.AccessHandler;
import forestry.core.access.EnumAccess;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.gui.GuiHandler;
import forestry.core.gui.IGuiHandlerEntity;
import forestry.core.gui.IHintSource;
import forestry.core.tiles.ITitled;
import forestry.core.utils.Translator;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
public abstract class EntityMinecartForestry extends EntityMinecart implements ITitled, IRestrictedAccess, IHintSource, IGuiHandlerEntity {
private final AccessHandler accessHandler = new AccessHandler(this);
public abstract class EntityMinecartForestry extends EntityMinecart implements ITitled, IHintSource, IGuiHandlerEntity {
@SuppressWarnings("unused")
public EntityMinecartForestry(World world) {
@@ -61,27 +51,11 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
return true;
}
public void setOwner(GameProfile owner) {
accessHandler.setOwner(owner);
}
@Override
public Type getType() {
return null;
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) {
super.readEntityFromNBT(nbtTagCompound);
accessHandler.readFromNBT(nbtTagCompound);
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) {
super.writeEntityToNBT(nbtTagCompound);
accessHandler.writeToNBT(nbtTagCompound);
}
/* EntityMinecart */
@Override
public boolean canBeRidden() {
@@ -104,8 +78,10 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
@Override
public void killMinecart(DamageSource damageSource) {
super.killMinecart(damageSource);
Block block = getDisplayTile().getBlock();
entityDropItem(new ItemStack(block, 1, block.getMetaFromState(getDisplayTile())), 0.0F);
if (this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
Block block = getDisplayTile().getBlock();
entityDropItem(new ItemStack(block), 0.0F);
}
}
// fix cart contents rendering as black in the End dimension
@@ -125,17 +101,6 @@ public abstract class EntityMinecartForestry extends EntityMinecart implements I
ItemStack cartItem = getCartItem();
return cartItem.getUnlocalizedName() + ".name";
}
/* IRestrictedAccess */
@Override
public IAccessHandler getAccessHandler() {
return accessHandler;
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
}
@Override
public int getIdOfEntity() {
@@ -20,14 +20,13 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.item.ItemStack;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IMutation;
import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.ItemStack;
public abstract class SpeciesRoot implements ISpeciesRoot {
@@ -82,8 +81,8 @@ public abstract class SpeciesRoot implements ISpeciesRoot {
/* MUTATIONS */
@Override
public Collection<? extends IMutation> getCombinations(IAllele other) {
ArrayList<IMutation> combinations = new ArrayList<>();
public List<IMutation> getCombinations(IAllele other) {
List<IMutation> combinations = new ArrayList<>();
for (IMutation mutation : getMutations(false)) {
if (mutation.isPartner(other)) {
combinations.add(mutation);
@@ -11,7 +11,8 @@
package forestry.core.genetics.alleles;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.mojang.authlib.GameProfile;
@@ -20,6 +21,7 @@ import forestry.api.core.EnumTemperature;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IAlleleSpeciesBuilder;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IClassification;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
@@ -111,20 +113,30 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuil
@Override
public ItemStack[] getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
ItemStack research = null;
if (world.rand.nextFloat() < (float) 10 / bountyLevel) {
Collection<? extends IMutation> combinations = getRoot().getCombinations(this);
if (!combinations.isEmpty()) {
IMutation[] candidates = combinations.toArray(new IMutation[combinations.size()]);
research = AlleleManager.alleleRegistry.getMutationNoteStack(researcher, candidates[world.rand.nextInt(candidates.length)]);
if (world.rand.nextFloat() < bountyLevel / 16.0f) {
List<? extends IMutation> allMutations = getRoot().getCombinations(this);
if (!allMutations.isEmpty()) {
List<IMutation> unresearchedMutations = new ArrayList<>();
IBreedingTracker tracker = individual.getGenome().getSpeciesRoot().getBreedingTracker(world, researcher);
for (IMutation mutation : allMutations) {
if (!tracker.isResearched(mutation)) {
unresearchedMutations.add(mutation);
}
}
IMutation chosenMutation;
if (!unresearchedMutations.isEmpty()) {
chosenMutation = unresearchedMutations.get(world.rand.nextInt(unresearchedMutations.size()));
} else {
chosenMutation = allMutations.get(world.rand.nextInt(allMutations.size()));
}
ItemStack researchNote = AlleleManager.alleleRegistry.getMutationNoteStack(researcher, chosenMutation);
return new ItemStack[]{researchNote};
}
}
if (research != null) {
return new ItemStack[]{research};
} else {
return ItemStackUtil.EMPTY_STACK_ARRAY;
}
return ItemStackUtil.EMPTY_STACK_ARRAY;
}
@Override
@@ -11,34 +11,20 @@
package forestry.core.gui;
import com.google.common.collect.ImmutableSet;
import forestry.api.core.IErrorLogicSource;
import forestry.api.core.IErrorState;
import forestry.core.network.packets.PacketErrorUpdateEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import forestry.api.core.IErrorLogicSource;
import forestry.api.core.IErrorState;
import forestry.core.access.EnumAccess;
import forestry.core.access.FakeAccessHandler;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.IForestryPacketClient;
import forestry.core.network.packets.PacketAccessUpdateEntity;
import forestry.core.network.packets.PacketErrorUpdateEntity;
public class ContainerEntity<T extends Entity & IInventory> extends ContainerForestry {
protected final T entity;
private final IAccessHandler accessHandler;
private ImmutableSet<IErrorState> previousErrorStates;
protected ContainerEntity(T entity) {
this.entity = entity;
if (entity instanceof IRestrictedAccess) {
accessHandler = ((IRestrictedAccess) entity).getAccessHandler();
} else {
accessHandler = FakeAccessHandler.getInstance();
}
}
protected ContainerEntity(T entity, InventoryPlayer playerInventory, int xInv, int yInv) {
@@ -48,17 +34,14 @@ public class ContainerEntity<T extends Entity & IInventory> extends ContainerFor
@Override
protected final boolean canAccess(EntityPlayer player) {
return player != null && accessHandler.allowsAlteration(player);
return player != null;
}
@Override
public final boolean canInteractWith(EntityPlayer entityplayer) {
return entity.isUseableByPlayer(entityplayer) && accessHandler.allowsViewing(entityplayer);
return entity.isUseableByPlayer(entityplayer);
}
private ImmutableSet<IErrorState> previousErrorStates;
private EnumAccess previousAccess;
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
@@ -74,17 +57,5 @@ public class ContainerEntity<T extends Entity & IInventory> extends ContainerFor
previousErrorStates = errorStates;
}
if (entity instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccess = (IRestrictedAccess) entity;
IAccessHandler accessHandler = restrictedAccess.getAccessHandler();
EnumAccess access = accessHandler.getAccess();
if (access != previousAccess) {
IForestryPacketClient packet = new PacketAccessUpdateEntity(restrictedAccess, entity);
sendPacketToListeners(packet);
previousAccess = access;
}
}
}
}
@@ -23,16 +23,11 @@ import forestry.core.tiles.EscritoireGame;
import forestry.core.tiles.TileEscritoire;
public class ContainerEscritoire extends ContainerTile<TileEscritoire> implements IGuiSelectable {
private final EntityPlayer player;
private long lastUpdate;
public ContainerEscritoire(EntityPlayer player, TileEscritoire tile) {
super(tile, player.inventory, 34, 153);
this.player = player;
// Analyze slot
addSlotToContainer(new SlotFiltered(this.tile, InventoryEscritoire.SLOT_ANALYZE, 97, 67).setPickupWatcher(this.tile).setStackLimit(1));
@@ -54,7 +49,7 @@ public class ContainerEscritoire extends ContainerTile<TileEscritoire> implement
long gameLastUpdate = tile.getGame().getLastUpdate();
if (lastUpdate != gameLastUpdate) {
lastUpdate = gameLastUpdate;
Proxies.net.sendToPlayer(new PacketGuiUpdate(tile), player);
sendPacketToListeners(new PacketGuiUpdate(tile));
}
}
@@ -11,19 +11,8 @@
package forestry.core.gui;
import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity;
import forestry.api.core.IErrorLogicSource;
import forestry.api.core.IErrorState;
import forestry.core.access.EnumAccess;
import forestry.core.access.FakeAccessHandler;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.IForestryPacketClient;
import forestry.core.network.packets.PacketAccessUpdate;
import forestry.core.network.packets.PacketErrorUpdate;
import forestry.core.network.packets.PacketGuiEnergy;
import forestry.core.network.packets.PacketGuiUpdate;
@@ -31,20 +20,19 @@ import forestry.core.tiles.IPowerHandler;
import forestry.core.tiles.TilePowered;
import forestry.core.tiles.TileUtil;
import forestry.energy.EnergyManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.tileentity.TileEntity;
public abstract class ContainerTile<T extends TileEntity> extends ContainerForestry {
protected final T tile;
private final IAccessHandler accessHandler;
private ImmutableSet<IErrorState> previousErrorStates;
private int previousEnergyManagerData = 0;
private int previousWorkCounter = 0;
private int previousTicksPerWorkCycle = 0;
protected ContainerTile(T tile) {
this.tile = tile;
if (tile instanceof IRestrictedAccess) {
accessHandler = ((IRestrictedAccess) tile).getAccessHandler();
} else {
accessHandler = FakeAccessHandler.getInstance();
}
}
protected ContainerTile(T tileForestry, InventoryPlayer playerInventory, int xInv, int yInv) {
@@ -55,20 +43,14 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
@Override
protected final boolean canAccess(EntityPlayer player) {
return player != null && accessHandler.allowsAlteration(player);
return player != null;
}
@Override
public final boolean canInteractWith(EntityPlayer entityplayer) {
return TileUtil.isUsableByPlayer(entityplayer, tile) && accessHandler.allowsViewing(entityplayer);
return TileUtil.isUsableByPlayer(entityplayer, tile);
}
private ImmutableSet<IErrorState> previousErrorStates;
private int previousEnergyManagerData = 0;
private EnumAccess previousAccess;
private int previousWorkCounter = 0;
private int previousTicksPerWorkCycle = 0;
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
@@ -96,18 +78,6 @@ public abstract class ContainerTile<T extends TileEntity> extends ContainerFores
}
}
if (tile instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccess = (IRestrictedAccess) tile;
IAccessHandler accessHandler = restrictedAccess.getAccessHandler();
EnumAccess access = accessHandler.getAccess();
if (access != previousAccess) {
IForestryPacketClient packet = new PacketAccessUpdate(restrictedAccess, tile);
sendPacketToListeners(packet);
previousAccess = access;
}
}
if (tile instanceof TilePowered) {
boolean guiNeedsUpdate = false;
+9 -17
View File
@@ -15,6 +15,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Stack;
import forestry.api.genetics.IGenome;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.client.renderer.GlStateManager;
@@ -292,17 +293,9 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
RenderHelper.enableGUIStandardItemLighting();
HashMap<IMutation, IAllele> combinations = new HashMap<>();
ISpeciesRoot speciesRoot = individual.getGenome().getSpeciesRoot();
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getPrimary())) {
combinations.put(mutation, individual.getGenome().getPrimary());
}
for (IMutation mutation : speciesRoot.getCombinations(individual.getGenome().getSecondary())) {
combinations.put(mutation, individual.getGenome().getSecondary());
}
IGenome genome = individual.getGenome();
ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
IAlleleSpecies species = genome.getPrimary();
int columnWidth = 50;
int x = 0;
@@ -310,17 +303,16 @@ public class GuiAlyzer extends GuiForestry<ContainerAlyzer, IInventory> {
EntityPlayer player = Proxies.common.getPlayer();
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.worldObj, player.getGameProfile());
for (Map.Entry<IMutation, IAllele> mutation : combinations.entrySet()) {
if (breedingTracker.isDiscovered(mutation.getKey())) {
drawMutationInfo(mutation.getKey(), mutation.getValue(), COLUMN_0 + x, breedingTracker);
for (IMutation mutation : speciesRoot.getCombinations(species)) {
if (breedingTracker.isDiscovered(mutation)) {
drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
} else {
// Do not display secret undiscovered mutations.
if (mutation.getKey().isSecret()) {
if (mutation.isSecret()) {
continue;
}
drawUnknownMutation(mutation.getKey(), COLUMN_0 + x, breedingTracker);
drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
}
x += columnWidth;
@@ -15,6 +15,7 @@ import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;
import forestry.core.owner.IOwnedTile;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
@@ -27,7 +28,6 @@ import net.minecraft.util.ResourceLocation;
import forestry.api.core.IErrorLogicSource;
import forestry.api.core.IErrorSource;
import forestry.core.access.IRestrictedAccess;
import forestry.core.config.Config;
import forestry.core.gui.ledgers.ClimateLedger;
import forestry.core.gui.ledgers.HintLedger;
@@ -106,8 +106,8 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
}
}
if (inventory instanceof IRestrictedAccess) {
ledgerManager.add(new OwnerLedger(ledgerManager, (IRestrictedAccess) inventory));
if (inventory instanceof IOwnedTile) {
ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnedTile) inventory));
}
}
@@ -10,49 +10,30 @@
******************************************************************************/
package forestry.core.gui.ledgers;
import java.util.Locale;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.player.EntityPlayer;
import com.mojang.authlib.GameProfile;
import forestry.core.access.EnumAccess;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IAccessOwnerListener;
import forestry.core.access.IRestrictedAccess;
import forestry.core.proxy.Proxies;
import forestry.core.owner.IOwnedTile;
import forestry.core.render.TextureManager;
import forestry.core.utils.PlayerUtil;
import forestry.core.utils.Translator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
/**
* Ledger displaying ownership information
*/
public class OwnerLedger extends Ledger implements IAccessOwnerListener {
public class OwnerLedger extends Ledger {
private final IAccessHandler accessHandler;
private final GameProfile owner;
public OwnerLedger(LedgerManager manager, IRestrictedAccess tile) {
public OwnerLedger(LedgerManager manager, IOwnedTile tile) {
super(manager, "owner");
this.accessHandler = tile.getAccessHandler();
accessHandler.addOwnerListener(this);
onOwnerSet(accessHandler.getOwner());
}
private boolean isAccessButton(int mouseX, int mouseY) {
int shiftX = currentShiftX;
int shiftY = currentShiftY + 44;
return mouseX >= shiftX && mouseX <= currentShiftX + currentWidth && mouseY >= shiftY && mouseY <= shiftY + 12;
this.owner = tile.getOwnerHandler().getOwner();
this.maxHeight = 40;
}
@Override
public boolean isVisible() {
return accessHandler.isOwned();
return owner != null;
}
@Override
@@ -61,61 +42,18 @@ public class OwnerLedger extends Ledger implements IAccessOwnerListener {
drawBackground(x, y);
// Draw icon
EnumAccess accessType = accessHandler.getAccess();
TextureAtlasSprite accessIcon = TextureManager.getInstance().getDefault("misc/access." + accessType.toString().toLowerCase(Locale.ENGLISH));
TextureAtlasSprite accessIcon = TextureManager.getInstance().getDefault("misc/access.shared");
drawSprite(accessIcon, x + 3, y + 4);
// Draw description
if (!isFullyOpened()) {
return;
}
drawHeader(Translator.translateToLocal("for.gui.owner"), x + 22, y + 8);
drawText(PlayerUtil.getOwnerName(accessHandler), x + 22, y + 20);
Minecraft minecraft = Proxies.common.getClientInstance();
boolean playerIsOwner = accessHandler.isOwner(minecraft.thePlayer);
if (playerIsOwner) {
drawSubheader(Translator.translateToLocal("for.gui.access") + ':', x + 22, y + 32);
// Access rules
drawSprite(accessIcon, x + 20, y + 40);
drawText(Translator.translateToLocal(accessType.getUnlocalizedName()), x + 38, y + 44);
if (isFullyOpened()) {
drawHeader(Translator.translateToLocal("for.gui.owner"), x + 22, y + 8);
drawText(PlayerUtil.getOwnerName(owner), x + 22, y + 20);
}
}
@Override
public String getTooltip() {
return Translator.translateToLocal("for.gui.owner") + ": " + PlayerUtil.getOwnerName(accessHandler);
}
@Override
public boolean handleMouseClicked(int x, int y, int mouseButton) {
if (isAccessButton(x, y)) {
Minecraft minecraft = Proxies.common.getClientInstance();
EntityPlayer player = minecraft.thePlayer;
return accessHandler.switchAccess(player);
}
return false;
}
@Override
public void onOwnerSet(GameProfile gameProfile) {
Minecraft minecraft = Proxies.common.getClientInstance();
boolean playerIsOwner = PlayerUtil.isSameGameProfile(minecraft.thePlayer.getGameProfile(), gameProfile);
if (playerIsOwner) {
maxHeight = 60;
} else {
maxHeight = 36;
}
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
accessHandler.removeOwnerListener(this);
return Translator.translateToLocal("for.gui.owner") + ": " + PlayerUtil.getOwnerName(owner);
}
}
@@ -91,6 +91,7 @@ public class GameTokenWidget extends Widget {
@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
game.choose(index);
Proxies.net.sendToServer(new PacketGuiSelectRequest(index, 0));
}
}
@@ -10,51 +10,30 @@
******************************************************************************/
package forestry.core.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import forestry.core.access.IAccessHandler;
import forestry.core.config.Constants;
public class InventoryAdapterRestricted extends InventoryAdapter {
private final IAccessHandler accessHandler;
public InventoryAdapterRestricted(int size, String name, IAccessHandler accessHandler) {
public InventoryAdapterRestricted(int size, String name) {
super(size, name);
this.accessHandler = accessHandler;
}
public InventoryAdapterRestricted(int size, String name, int stackLimit, IAccessHandler accessHandler) {
public InventoryAdapterRestricted(int size, String name, int stackLimit) {
super(size, name, stackLimit);
this.accessHandler = accessHandler;
}
@Override
public final boolean isUseableByPlayer(EntityPlayer player) {
return accessHandler.allowsViewing(player);
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack) {
if (itemStack == null || !accessHandler.allowsPipeConnections()) {
if (itemStack == null) {
return false;
}
return canSlotAccept(slotIndex, itemStack);
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
if (!accessHandler.allowsPipeConnections()) {
return Constants.SLOTS_NONE;
}
return super.getSlotsForFace(side);
}
@Override
public final boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
if (itemStack == null || !accessHandler.allowsPipeConnections()) {
if (itemStack == null) {
return false;
}
return isItemValidForSlot(slotIndex, itemStack);
@@ -62,6 +41,6 @@ public class InventoryAdapterRestricted extends InventoryAdapter {
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
return itemStack != null && accessHandler.allowsPipeConnections();
return itemStack != null;
}
}
@@ -14,9 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import forestry.core.access.IRestrictedAccess;
public class InventoryAdapterTile<T extends TileEntity & IRestrictedAccess> extends InventoryAdapterRestricted {
public class InventoryAdapterTile<T extends TileEntity> extends InventoryAdapterRestricted {
protected final T tile;
@@ -25,7 +23,7 @@ public class InventoryAdapterTile<T extends TileEntity & IRestrictedAccess> exte
}
public InventoryAdapterTile(T tile, int size, String name, int stackLimit) {
super(size, name, stackLimit, tile.getAccessHandler());
super(size, name, stackLimit);
this.tile = tile;
}
@@ -37,8 +37,8 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
private final RevolvingList<ICircuitLayout> layouts = new RevolvingList<>(ChipsetManager.circuitRegistry.getRegisteredLayouts().values());
private static final short blankSlot = 0;
private static final short finishedSlot = 1;
private static final short inputCircuitBoardSlot = 0;
private static final short finishedCircuitBoardSlot = 1;
private static final short ingredientSlot1 = 2;
private static final short ingredientSlotCount = 4;
@@ -84,11 +84,6 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
continue;
}
// / Make sure we don't exceed this circuits limit per chipset
if (getCount(recipe.getCircuit(), circuits) >= recipe.getCircuit().getLimit()) {
continue;
}
if (doConsume) {
decrStackSize(ingredientSlot1 + i, recipe.getResource().stackSize);
}
@@ -104,39 +99,36 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
return;
}
ItemStack blank = getStackInSlot(blankSlot);
// Requires blank slot
if (blank == null) {
ItemStack inputCircuitBoard = getStackInSlot(inputCircuitBoardSlot);
if (inputCircuitBoard == null || inputCircuitBoard.stackSize > 1) {
return;
}
if (blank.stackSize > 1) {
return;
}
if (getStackInSlot(finishedSlot) != null) {
if (getStackInSlot(finishedCircuitBoardSlot) != null) {
return;
}
// Need a chipset item
if (!ChipsetManager.circuitRegistry.isChipset(blank)) {
if (!ChipsetManager.circuitRegistry.isChipset(inputCircuitBoard)) {
return;
}
// Illegal type
if (blank.getItemDamage() < 0 || blank.getItemDamage() >= EnumCircuitBoardType.values().length) {
if (inputCircuitBoard.getItemDamage() < 0 || inputCircuitBoard.getItemDamage() >= EnumCircuitBoardType.values().length) {
return;
}
EnumCircuitBoardType type = EnumCircuitBoardType.values()[blank.getItemDamage()];
EnumCircuitBoardType type = EnumCircuitBoardType.values()[inputCircuitBoard.getItemDamage()];
if (getCircuitCount() != type.getSockets()) {
return;
}
ICircuit[] circuits = getCircuits(true);
ItemStack circuitBoard = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits);
ItemStack outputCircuitBoard = ItemCircuitBoard.createCircuitboard(type, layouts.getCurrent(), circuits);
setInventorySlotContents(finishedSlot, circuitBoard);
setInventorySlotContents(blankSlot, null);
setInventorySlotContents(finishedCircuitBoardSlot, outputCircuitBoard);
setInventorySlotContents(inputCircuitBoardSlot, null);
}
private int getCircuitCount() {
@@ -150,16 +142,6 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
return count;
}
public static int getCount(ICircuit circuit, ICircuit[] circuits) {
int count = 0;
for (ICircuit other : circuits) {
if (other != null && other.getUID().equals(circuit.getUID())) {
count++;
}
}
return count;
}
@Override
public ImmutableSet<IErrorState> getErrorStates() {
ImmutableSet.Builder<IErrorState> errorStates = ImmutableSet.builder();
@@ -168,7 +150,7 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
errorStates.add(EnumErrorCode.NO_CIRCUIT_LAYOUT);
}
ItemStack blankCircuitBoard = getStackInSlot(blankSlot);
ItemStack blankCircuitBoard = getStackInSlot(inputCircuitBoardSlot);
if (blankCircuitBoard == null) {
errorStates.add(EnumErrorCode.NO_CIRCUIT_BOARD);
@@ -202,7 +184,7 @@ public class ItemInventorySolderingIron extends ItemInventory implements IErrorS
}
Item item = itemStack.getItem();
if (slotIndex == blankSlot) {
if (slotIndex == inputCircuitBoardSlot) {
return item instanceof ItemCircuitBoard;
} else if (slotIndex >= ingredientSlot1 && slotIndex < ingredientSlot1 + ingredientSlotCount) {
CircuitRecipe recipe = SolderManager.getMatchingRecipe(layouts.getCurrent(), itemStack);
@@ -10,6 +10,9 @@
******************************************************************************/
package forestry.core.items;
import java.util.List;
import forestry.core.utils.Translator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -19,7 +22,13 @@ import forestry.core.circuits.ISolderingIron;
import forestry.core.inventory.ItemInventorySolderingIron;
public class ItemSolderingIron extends ItemWithGui implements ISolderingIron {
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
super.addInformation(stack, playerIn, tooltip, advanced);
tooltip.add(Translator.translateToLocal("item.for.solderingIron.tooltip"));
}
@Override
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
return new GuiSolderingIron(player, new ItemInventorySolderingIron(player, heldItem));
@@ -16,20 +16,18 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.IErrorLogic;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.access.EnumAccess;
import forestry.core.access.FakeAccessHandler;
import forestry.core.access.IAccessHandler;
import forestry.core.errors.FakeErrorLogic;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.owner.FakeOwnerHandler;
import forestry.core.owner.IOwnerHandler;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public abstract class FakeMultiblockController implements IMultiblockControllerInternal {
@Override
@@ -156,13 +154,8 @@ public abstract class FakeMultiblockController implements IMultiblockControllerI
}
@Override
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
}
@Override
public IAccessHandler getAccessHandler() {
return FakeAccessHandler.getInstance();
public IOwnerHandler getOwnerHandler() {
return FakeOwnerHandler.getInstance();
}
@Override
@@ -13,6 +13,7 @@ package forestry.core.multiblock;
import javax.annotation.Nonnull;
import java.util.Set;
import forestry.core.owner.IOwnedTile;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -22,12 +23,11 @@ import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.api.multiblock.IMultiblockController;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.IStreamableGui;
import forestry.core.tiles.IClimatised;
// internal implementation of IMultiblockController
public interface IMultiblockControllerInternal extends IMultiblockController, INbtWritable, INbtReadable, IRestrictedAccess, IErrorLogicSource, IClimatised, IStreamableGui {
public interface IMultiblockControllerInternal extends IMultiblockController, INbtWritable, INbtReadable, IOwnedTile, IErrorLogicSource, IClimatised, IStreamableGui {
/**
* Attach a new part to this machine.
* @param part The part to add.
@@ -10,11 +10,21 @@
******************************************************************************/
package forestry.core.multiblock;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import javax.annotation.Nonnull;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.mojang.authlib.GameProfile;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorLogicSource;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.inventory.FakeInventoryAdapter;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.owner.IOwnerHandler;
import forestry.core.owner.IOwnedTile;
import forestry.core.owner.OwnerHandler;
import forestry.core.tiles.ILocatable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -23,33 +33,20 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorLogic;
import forestry.api.core.IErrorLogicSource;
import forestry.api.multiblock.IMultiblockComponent;
import forestry.core.access.AccessHandler;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.inventory.FakeInventoryAdapter;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.tiles.ILocatable;
public abstract class MultiblockControllerForestry extends MultiblockControllerBase implements ISidedInventory, IRestrictedAccess, IErrorLogicSource, ILocatable {
private final AccessHandler accessHandler;
public abstract class MultiblockControllerForestry extends MultiblockControllerBase implements ISidedInventory, IOwnedTile, IErrorLogicSource, ILocatable {
private final OwnerHandler ownerHandler;
private final IErrorLogic errorLogic;
protected MultiblockControllerForestry(World world) {
super(world);
this.accessHandler = new AccessHandler(this);
this.ownerHandler = new OwnerHandler();
this.errorLogic = ForestryAPI.errorStateRegistry.createErrorLogic();
}
@Override
public IAccessHandler getAccessHandler() {
return accessHandler;
public IOwnerHandler getOwnerHandler() {
return ownerHandler;
}
@Override
@@ -90,19 +87,21 @@ public abstract class MultiblockControllerForestry extends MultiblockControllerB
}
}
getAccessHandler().setOwner(owner);
if (owner != null) {
getOwnerHandler().setOwner(owner);
}
}
/* INbtWritable */
@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
accessHandler.writeToNBT(data);
ownerHandler.writeToNBT(data);
return data;
}
@Override
public void readFromNBT(NBTTagCompound data) {
accessHandler.readFromNBT(data);
ownerHandler.readFromNBT(data);
}
/* INVENTORY */
@@ -26,8 +26,6 @@ public enum PacketIdClient implements IPacketId {
GUI_LAYOUT_SELECT,
GUI_ENERGY,
SOCKET_UPDATE,
ACCESS_UPDATE,
ACCESS_UPDATE_ENTITY,
// Core Tile Entities
TILE_FORESTRY_UPDATE,
@@ -21,8 +21,6 @@ public enum PacketIdServer implements IPacketId {
// Core Gui
GUI_SELECTION_REQUEST,
PIPETTE_CLICK,
ACCESS_SWITCH,
ACCESS_SWITCH_ENTITY,
CHIPSET_CLICK,
SOLDERING_IRON_CLICK,
@@ -10,10 +10,6 @@
******************************************************************************/
package forestry.core.network;
import forestry.core.network.packets.PacketAccessSwitch;
import forestry.core.network.packets.PacketAccessSwitchEntity;
import forestry.core.network.packets.PacketAccessUpdate;
import forestry.core.network.packets.PacketAccessUpdateEntity;
import forestry.core.network.packets.PacketChipsetClick;
import forestry.core.network.packets.PacketErrorUpdate;
import forestry.core.network.packets.PacketErrorUpdateEntity;
@@ -41,8 +37,6 @@ public class PacketRegistryCore extends PacketRegistry {
registerClientPacket(new PacketGuiLayoutSelect());
registerClientPacket(new PacketGuiEnergy());
registerClientPacket(new PacketSocketUpdate());
registerClientPacket(new PacketAccessUpdate());
registerClientPacket(new PacketAccessUpdateEntity());
registerClientPacket(new PacketTileStream());
registerClientPacket(new PacketItemStackDisplay());
registerClientPacket(new PacketFXSignal());
@@ -51,8 +45,6 @@ public class PacketRegistryCore extends PacketRegistry {
registerServerPacket(new PacketGuiSelectRequest());
registerServerPacket(new PacketPipetteClick());
registerServerPacket(new PacketAccessSwitch());
registerServerPacket(new PacketAccessSwitchEntity());
registerServerPacket(new PacketChipsetClick());
registerServerPacket(new PacketSolderingIronClick());
}
@@ -1,47 +0,0 @@
/*******************************************************************************
* 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.core.network.packets;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.IForestryPacketServer;
import forestry.core.network.PacketIdServer;
import forestry.core.tiles.ILocatable;
public class PacketAccessSwitch extends PacketCoordinates implements IForestryPacketServer {
public PacketAccessSwitch() {
}
public PacketAccessSwitch(ILocatable tile) {
super(tile.getCoordinates());
}
@Override
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
TileEntity tile = getTarget(player.worldObj);
if (tile instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
restrictedAccessTile.getAccessHandler().switchAccess(player);
}
}
@Override
public PacketIdServer getPacketId() {
return PacketIdServer.ACCESS_SWITCH;
}
}
@@ -1,45 +0,0 @@
/*******************************************************************************
* 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.core.network.packets;
import java.io.IOException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.IForestryPacketServer;
import forestry.core.network.PacketIdServer;
public class PacketAccessSwitchEntity extends PacketEntityUpdate implements IForestryPacketServer {
public PacketAccessSwitchEntity() {
}
public PacketAccessSwitchEntity(Entity entity) {
super(entity);
}
@Override
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
Entity target = getTarget(player.worldObj);
if (target instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) target;
restrictedAccessTile.getAccessHandler().switchAccess(player);
}
}
@Override
public PacketIdServer getPacketId() {
return PacketIdServer.ACCESS_SWITCH_ENTITY;
}
}
@@ -1,56 +0,0 @@
/*******************************************************************************
* 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.core.network.packets;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IForestryPacketClient;
import forestry.core.network.PacketIdClient;
public class PacketAccessUpdate extends PacketCoordinates implements IForestryPacketClient {
private IAccessHandler accessHandler;
public PacketAccessUpdate() {
}
public PacketAccessUpdate(IRestrictedAccess restrictedAccess, TileEntity tile) {
super(tile);
accessHandler = restrictedAccess.getAccessHandler();
}
@Override
protected void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
accessHandler.writeData(data);
}
@Override
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
TileEntity tile = getTarget(player.worldObj);
if (tile instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
restrictedAccessTile.getAccessHandler().readData(data);
}
}
@Override
public PacketIdClient getPacketId() {
return PacketIdClient.ACCESS_UPDATE;
}
}
@@ -1,56 +0,0 @@
/*******************************************************************************
* 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.core.network.packets;
import java.io.IOException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import forestry.core.access.IAccessHandler;
import forestry.core.access.IRestrictedAccess;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IForestryPacketClient;
import forestry.core.network.PacketIdClient;
public class PacketAccessUpdateEntity extends PacketEntityUpdate implements IForestryPacketClient {
private IAccessHandler accessHandler;
public PacketAccessUpdateEntity() {
}
public PacketAccessUpdateEntity(IRestrictedAccess restrictedAccess, Entity entity) {
super(entity);
accessHandler = restrictedAccess.getAccessHandler();
}
@Override
protected void writeData(DataOutputStreamForestry data) throws IOException {
super.writeData(data);
accessHandler.writeData(data);
}
@Override
public void onPacketData(DataInputStreamForestry data, EntityPlayer player) throws IOException {
Entity tile = getTarget(player.worldObj);
if (tile instanceof IRestrictedAccess) {
IRestrictedAccess restrictedAccessTile = (IRestrictedAccess) tile;
restrictedAccessTile.getAccessHandler().readData(data);
}
}
@Override
public PacketIdClient getPacketId() {
return PacketIdClient.ACCESS_UPDATE_ENTITY;
}
}
@@ -1,17 +1,40 @@
/*******************************************************************************
* 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.core.access;
import com.mojang.authlib.GameProfile;
public interface IAccessOwnerListener {
void onOwnerSet(GameProfile gameProfile);
}
/*******************************************************************************
* 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.core.owner;
import javax.annotation.Nonnull;
import com.mojang.authlib.GameProfile;
public class FakeOwnerHandler implements IOwnerHandler {
private static FakeOwnerHandler instance;
public static FakeOwnerHandler getInstance() {
if (instance == null) {
instance = new FakeOwnerHandler();
}
return instance;
}
private FakeOwnerHandler() {
}
@Override
public GameProfile getOwner() {
return null;
}
@Override
public void setOwner(@Nonnull GameProfile owner) {
}
}
@@ -0,0 +1,52 @@
package forestry.core.owner;
import java.io.IOException;
import java.util.UUID;
import com.google.common.base.Optional;
import com.mojang.authlib.GameProfile;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializer;
import net.minecraft.network.datasync.DataSerializers;
public class GameProfileDataSerializer implements DataSerializer<Optional<GameProfile>> {
public static final GameProfileDataSerializer INSTANCE = new GameProfileDataSerializer();
public static void register() {
DataSerializers.registerSerializer(INSTANCE);
}
private GameProfileDataSerializer() {
}
@Override
public void write(PacketBuffer buf, Optional<GameProfile> value) {
if (!value.isPresent()) {
buf.writeBoolean(false);
} else {
buf.writeBoolean(true);
GameProfile gameProfile = value.get();
buf.writeUuid(gameProfile.getId());
buf.writeString(gameProfile.getName());
}
}
@Override
public Optional<GameProfile> read(PacketBuffer buf) {
if (buf.readBoolean()) {
UUID uuid = buf.readUuid();
String name = buf.readStringFromBuffer(1024);
GameProfile gameProfile = new GameProfile(uuid, name);
return Optional.of(gameProfile);
} else {
return Optional.absent();
}
}
@Override
public DataParameter<Optional<GameProfile>> createKey(int id) {
return new DataParameter<>(id, this);
}
}
@@ -8,8 +8,8 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.mail.tiles;
package forestry.core.owner;
public interface IMailContainer {
boolean hasMail();
public interface IOwnedTile {
IOwnerHandler getOwnerHandler();
}
@@ -8,24 +8,16 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.access;
package forestry.core.owner;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayer;
import com.mojang.authlib.GameProfile;
public interface IOwnable {
boolean isOwned();
public interface IOwnerHandler {
@Nullable
GameProfile getOwner();
void setOwner(@Nonnull GameProfile owner);
boolean isOwner(EntityPlayer player);
}
@@ -0,0 +1,78 @@
/*******************************************************************************
* 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.core.owner;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import forestry.api.core.INbtReadable;
import forestry.api.core.INbtWritable;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.utils.PlayerUtil;
import net.minecraft.nbt.NBTTagCompound;
public class OwnerHandler implements IOwnerHandler, IStreamable, INbtWritable, INbtReadable {
private GameProfile owner = null;
@Override
public GameProfile getOwner() {
return owner;
}
@Override
public void setOwner(@Nonnull GameProfile owner) {
this.owner = owner;
}
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
if (owner == null) {
data.writeBoolean(false);
} else {
data.writeBoolean(true);
data.writeLong(owner.getId().getMostSignificantBits());
data.writeLong(owner.getId().getLeastSignificantBits());
data.writeUTF(owner.getName());
}
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
if (data.readBoolean()) {
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
setOwner(owner);
}
}
@Override
public void readFromNBT(NBTTagCompound data) {
if (data.hasKey("owner")) {
GameProfile owner = PlayerUtil.readGameProfileFromNBT(data.getCompoundTag("owner"));
if (owner != null) {
setOwner(owner);
}
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound data) {
if (this.owner != null) {
NBTTagCompound nbt = new NBTTagCompound();
PlayerUtil.writeGameProfile(nbt, owner);
data.setTag("owner", nbt);
}
return data;
}
}
@@ -64,11 +64,6 @@ public class ProxyClient extends ProxyCommon {
return getClientInstance().theWorld;
}
@Override
public boolean isOp(EntityPlayer player) {
return false;
}
@Override
public double getBlockReachDistance(EntityPlayer entityplayer) {
if (entityplayer instanceof EntityPlayerSP) {
@@ -62,12 +62,6 @@ public class ProxyCommon {
return new File(".");
}
public boolean isOp(EntityPlayer player) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
UserListOpsEntry userlistopsentry = server.getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
return userlistopsentry.getPermissionLevel() >= server.getOpPermissionLevel();
}
public double getBlockReachDistance(EntityPlayer entityplayer) {
return 4f;
}
@@ -104,6 +104,8 @@ public class RenderEscritoire extends TileEntitySpecialRenderer<TileEscritoire>
rendermanager.doRenderEntity(dummyEntityItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F, false);
}
GlStateManager.popMatrix();
dummyEntityItem.worldObj = null; // prevent leaking the world object
}
}
}
@@ -50,8 +50,8 @@ public class TextureManager implements ITextureManager {
public static void initDefaultSprites() {
String[] defaultIconNames = new String[]{"habitats/desert", "habitats/end", "habitats/forest", "habitats/hills", "habitats/jungle", "habitats/mushroom",
"habitats/nether", "habitats/ocean", "habitats/plains", "habitats/snow", "habitats/swamp", "habitats/taiga", "misc/access.private",
"misc/access.viewable", "misc/access.shared", "misc/energy", "misc/hint",
"habitats/nether", "habitats/ocean", "habitats/plains", "habitats/snow", "habitats/swamp", "habitats/taiga",
"misc/access.shared", "misc/energy", "misc/hint",
"analyzer/anything", "analyzer/bee", "analyzer/cave", "analyzer/closed", "analyzer/drone", "analyzer/flyer",
"analyzer/item", "analyzer/nocturnal", "analyzer/princess", "analyzer/pure_breed", "analyzer/pure_cave",
"analyzer/pure_flyer", "analyzer/pure_nocturnal", "analyzer/queen",
@@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import forestry.api.genetics.IAllele;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -72,10 +73,10 @@ public class EscritoireGameBoard implements INbtWritable, IStreamable {
tokenCount = getTokenCount(genome);
for (int i = 0; i < tokenCount / 2; i++) {
IIndividual token = root.templateAsIndividual(root.getRandomTemplate(rand));
ItemStack pair = root.getMemberStack(token, root.getIconType());
gameTokens.add(new EscritoireGameToken(pair));
gameTokens.add(new EscritoireGameToken(pair));
IAllele[] randomTemplate = root.getRandomTemplate(rand);
String speciesUid = randomTemplate[root.getSpeciesChromosomeType().ordinal()].getUID();
gameTokens.add(new EscritoireGameToken(speciesUid));
gameTokens.add(new EscritoireGameToken(speciesUid));
}
Collections.shuffle(gameTokens);
return true;
@@ -14,17 +14,19 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import forestry.api.core.INbtWritable;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
import forestry.core.utils.ColourUtil;
import forestry.core.utils.Translator;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class EscritoireGameToken implements INbtWritable, IStreamable {
@@ -41,6 +43,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
private static final String[] OVERLAY_FAILED = new String[]{"errors/errored"};
private static final String[] OVERLAY_SELECTED = new String[]{"errors/unknown"};
@Nullable
private IIndividual tokenIndividual;
@Nullable
private ItemStack tokenStack;
@Nonnull
@@ -51,8 +55,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
// required for IStreamable serialization
}
public EscritoireGameToken(@Nullable ItemStack tokenStack) {
this.tokenStack = tokenStack;
public EscritoireGameToken(@Nullable String speciesUid) {
setTokenSpecies(speciesUid);
}
public EscritoireGameToken(@Nonnull NBTTagCompound nbttagcompound) {
@@ -61,8 +65,29 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
state = State.values()[stateOrdinal];
}
// legacy
if (nbttagcompound.hasKey("tokenStack")) {
tokenStack = ItemStack.loadItemStackFromNBT(nbttagcompound.getCompoundTag("tokenStack"));
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(tokenStack);
tokenIndividual = speciesRoot.getMember(tokenStack);
}
if (nbttagcompound.hasKey("tokenSpecies")) {
String speciesUid = nbttagcompound.getString("tokenSpecies");
setTokenSpecies(speciesUid);
}
}
private void setTokenSpecies(String speciesUid) {
IAllele allele = AlleleManager.alleleRegistry.getAllele(speciesUid);
if (allele instanceof IAlleleSpecies) {
IAlleleSpecies species = (IAlleleSpecies) allele;
ISpeciesRoot root = species.getRoot();
IAllele[] template = root.getTemplate(speciesUid);
if (template != null) {
this.tokenIndividual = root.templateAsIndividual(template);
this.tokenStack = root.getMemberStack(this.tokenIndividual, root.getIconType());
}
}
}
@@ -108,12 +133,11 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
}
public int getTokenColour() {
if (tokenStack == null || !isVisible()) {
if (tokenIndividual == null || !isVisible()) {
return 0xffffff;
}
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(tokenStack);
int iconColor = individual.getGenome().getPrimary().getSpriteColour(0);
int iconColor = tokenIndividual.getGenome().getPrimary().getSpriteColour(0);
if (state == State.MATCHED) {
return ColourUtil.multiplyRGBComponents(iconColor, 0.7f);
@@ -146,10 +170,8 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("state", state.ordinal());
if (tokenStack != null) {
NBTTagCompound stackcompound = new NBTTagCompound();
tokenStack.writeToNBT(stackcompound);
nbttagcompound.setTag("tokenStack", stackcompound);
if (tokenIndividual != null) {
nbttagcompound.setString("tokenSpecies", tokenIndividual.getGenome().getPrimary().getUID());
}
return nbttagcompound;
}
@@ -158,12 +180,20 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
@Override
public void writeData(DataOutputStreamForestry data) throws IOException {
data.writeEnum(state, State.VALUES);
data.writeItemStack(tokenStack);
if (tokenIndividual != null) {
data.writeBoolean(true);
data.writeUTF(tokenIndividual.getGenome().getPrimary().getUID());
} else {
data.writeBoolean(false);
}
}
@Override
public void readData(DataInputStreamForestry data) throws IOException {
state = data.readEnum(State.VALUES);
tokenStack = data.readItemStack();
if (data.readBoolean()) {
String speciesUid = data.readUTF();
setTokenSpecies(speciesUid);
}
}
}
@@ -11,6 +11,7 @@
package forestry.core.tiles;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
@@ -251,22 +252,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if (super.hasCapability(capability, facing)) {
return true;
}
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY;
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
@Nonnull
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (super.hasCapability(capability, facing)) {
return super.getCapability(capability, facing);
}
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tankManager);
}
return null;
return super.getCapability(capability, facing);
}
@Override
Loaded 100 of 184 files, more files were not shown because too many files have changed in this diff. Show more