diff --git a/LICENSE.md b/LICENSE.md index a432c3677..1b599bf18 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -7,7 +7,7 @@ Section 2: Added *, curseforge.net and the Growthcraft Community Edition GitHub # Updated License ->Section 1: This document is Copyright © (2014-2015) "Gwafu" and is the intellectual property of the author. +>Section 1: This document is Copyright © (2014-2016) "Gwafu" and is the intellectual property of the author. > >Section 2: Terms regarding file hosting: >Only minecraftforum.net, curseforge.net and the Growthcraft Community Edition GitHub repository is able to host any of these materials without the author's consent. You can just simply ask the author to allow you to host it in your website or distribute it. @@ -24,7 +24,7 @@ Section 2: Added *, curseforge.net and the Growthcraft Community Edition GitHub # Orginal License ->This document is Copyright © (2014-2015) "Gwafu" and is the intellectual property of the author. +>This document is Copyright © (2014-2016) "Gwafu" and is the intellectual property of the author. > >Terms regarding file hosting: >Only minecraftforum.net is able to host any of these materials without the author's consent. You can just simply ask the author to allow you to host it in your website or distribute it. diff --git a/build.gradle b/build.gradle index d814ec0f3..85c49a3e5 100644 --- a/build.gradle +++ b/build.gradle @@ -141,7 +141,7 @@ debugClient { } tasks.withType(JavaCompile) { - options.compilerArgs += ["-Xlint:all", "-Xlint:deprecation", "-Xlint:-rawtypes", "-Xlint:-unchecked"] + options.compilerArgs += ["-Xlint:all", "-Xlint:deprecation", "-Xlint:rawtypes", "-Xlint:unchecked"] options.deprecation = true options.encoding = "utf8" } diff --git a/gradle.properties b/gradle.properties index 7764c9ea4..c29442407 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ minecraft_version=1.7.10 # Forge minecraft_forge_version=1.7.10-10.13.4.1566-1.7.10 # GrowthCraft -growthcraft_version=2.6.3 +growthcraft_version=2.7.0 # Depdendencies applecore_version=1.3.0 -bc_version=7.1.16 +bc_version=7.1.17 code_chicken_core_version=1.0.7.47 code_chicken_lib_version=1.1.3.140 nei_version=1.0.5.120 diff --git a/src/java/growthcraft/api/core/nbt/NBTStringTagList.java b/src/java/growthcraft/api/core/nbt/NBTTagStringList.java similarity index 86% rename from src/java/growthcraft/api/core/nbt/NBTStringTagList.java rename to src/java/growthcraft/api/core/nbt/NBTTagStringList.java index fde57f709..5f0a7ecfa 100644 --- a/src/java/growthcraft/api/core/nbt/NBTStringTagList.java +++ b/src/java/growthcraft/api/core/nbt/NBTTagStringList.java @@ -23,7 +23,7 @@ */ package growthcraft.api.core.nbt; -import java.util.List; +import java.util.Collection; import javax.annotation.Nonnull; import net.minecraft.nbt.NBTTagList; @@ -32,7 +32,7 @@ /** * Utility class for wrapping a NBTTagList for Strings */ -public class NBTStringTagList +public class NBTTagStringList { private NBTTagList parent; @@ -41,15 +41,15 @@ public class NBTStringTagList * * @param list - the tag list to use as the parent */ - public NBTStringTagList(@Nonnull NBTTagList list) + public NBTTagStringList(@Nonnull NBTTagList list) { this.parent = list; } /** - * Initializes the NBTStringTagList with a default taglist + * Initializes the NBTTagStringList with a default taglist */ - public NBTStringTagList() + public NBTTagStringList() { this(new NBTTagList()); } @@ -57,12 +57,12 @@ public NBTStringTagList() /** * @param list - a string list */ - public NBTStringTagList(@Nonnull List list) + public NBTTagStringList(@Nonnull Collection list) { this(); - for (String str : list) + for (Object obj : list) { - add(str); + add(obj.toString()); } } @@ -81,7 +81,7 @@ public int size() * * @param str - the string to add */ - public NBTStringTagList add(@Nonnull String str) + public NBTTagStringList add(@Nonnull String str) { parent.appendTag(new NBTTagString(str)); return this; diff --git a/src/java/growthcraft/api/core/nbt/NBTType.java b/src/java/growthcraft/api/core/nbt/NBTType.java index 96d8091b9..d7a1977e1 100644 --- a/src/java/growthcraft/api/core/nbt/NBTType.java +++ b/src/java/growthcraft/api/core/nbt/NBTType.java @@ -44,18 +44,10 @@ public enum NBTType public static final Map MAPPING = new HashMap(); static { - END.register(); - BYTE.register(); - SHORT.register(); - INT.register(); - LONG.register(); - FLOAT.register(); - DOUBLE.register(); - BYTE_ARRAY.register(); - STRING.register(); - LIST.register(); - COMPOUND.register(); - INT_ARRAY.register(); + for (NBTType type : values()) + { + MAPPING.put(type.id, type); + } } public final int id; @@ -65,11 +57,6 @@ private NBTType(int i) this.id = i; } - private void register() - { - MAPPING.put(this.id, this); - } - public static NBTType byId(int id) { return MAPPING.get(id); diff --git a/src/java/growthcraft/api/core/registry/GenericItemRegistry.java b/src/java/growthcraft/api/core/registry/GenericItemRegistry.java new file mode 100644 index 000000000..578f17406 --- /dev/null +++ b/src/java/growthcraft/api/core/registry/GenericItemRegistry.java @@ -0,0 +1,52 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.core.registry; + +import java.util.LinkedList; +import java.util.List; + +public class GenericItemRegistry> +{ + protected List entries = new LinkedList(); + + public void add(T entry) + { + entries.add(entry); + } + + public T find(ItemType item) + { + if (item == null) return null; + for (T entry : entries) + { + if (entry.matches(item)) return entry; + } + return null; + } + + public boolean contains(ItemType item) + { + return find(item) != null; + } +} diff --git a/src/java/growthcraft/core/common/inventory/IInventoryFlagging.java b/src/java/growthcraft/api/core/registry/IItemRegistryEntry.java similarity index 90% rename from src/java/growthcraft/core/common/inventory/IInventoryFlagging.java rename to src/java/growthcraft/api/core/registry/IItemRegistryEntry.java index 56f5142af..d15bffbe7 100644 --- a/src/java/growthcraft/core/common/inventory/IInventoryFlagging.java +++ b/src/java/growthcraft/api/core/registry/IItemRegistryEntry.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.inventory; +package growthcraft.api.core.registry; -public interface IInventoryFlagging +public interface IItemRegistryEntry { - public void markForInventoryUpdate(); + public boolean matches(T item); } diff --git a/src/java/growthcraft/api/core/registry/ItemRegistryEntry.java b/src/java/growthcraft/api/core/registry/ItemRegistryEntry.java new file mode 100644 index 000000000..f59bc77f4 --- /dev/null +++ b/src/java/growthcraft/api/core/registry/ItemRegistryEntry.java @@ -0,0 +1,48 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.core.registry; + +import growthcraft.api.core.definition.IMultiItemStacks; +import growthcraft.api.core.util.MultiStacksUtil; + +import net.minecraft.item.ItemStack; + +public class ItemRegistryEntry implements IItemRegistryEntry +{ + public T handle; + private IMultiItemStacks stacks; + + public ItemRegistryEntry(Object stack, T p_handle) + { + this.handle = p_handle; + this.stacks = MultiStacksUtil.toMultiItemStacks(stack); + } + + @Override + public boolean matches(ItemStack stack) + { + if (stack == null) return false; + return stacks.containsItemStack(stack); + } +} diff --git a/src/java/growthcraft/api/core/util/BoundUtils.java b/src/java/growthcraft/api/core/util/BoundUtils.java index 8da9c7893..c38723428 100644 --- a/src/java/growthcraft/api/core/util/BoundUtils.java +++ b/src/java/growthcraft/api/core/util/BoundUtils.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015 IceDragon200 + * Copyright (c) 2015, 2016 IceDragon200 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,8 +33,76 @@ */ public class BoundUtils { + public static final float[] NORMALIZED_CLAMP = new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; + private BoundUtils() {} + /** + * Clamps the target bounds using the provided `clamp` bounds + * @param target target bounds to modify + * @param clamp bounds to clamp with + * @return bounds + */ + public static float[] clampBounds(float[] target, float[] clamp) + { + assert target.length == 6; + if (target[0] < clamp[0]) target[0] = clamp[0]; + if (target[1] < clamp[1]) target[1] = clamp[1]; + if (target[2] < clamp[2]) target[2] = clamp[2]; + if (target[3] > clamp[3]) target[3] = clamp[3]; + if (target[4] > clamp[4]) target[4] = clamp[4]; + if (target[5] > clamp[5]) target[5] = clamp[5]; + return target; + } + + /** + * Clamps the target bounds using the NORMALIZED_CLAMP + * @param target target bounds to modify + * @return bounds + */ + public static float[] clampBounds(float[] target) + { + return clampBounds(target, NORMALIZED_CLAMP); + } + + /** + * Adds the expander + * + * @param target target bounds to modify + * @param expander the bounds to add + * @return bounds + */ + public static float[] addBounds(float[] target, float[] expander) + { + assert target.length == 6; + target[0] += expander[0]; + target[1] += expander[1]; + target[2] += expander[2]; + target[3] += expander[3]; + target[4] += expander[4]; + target[5] += expander[5]; + return target; + } + + /** + * Adds the expander + * + * @param target target bounds to modify + * @param contractor the bounds to add + * @return bounds + */ + public static float[] subBounds(float[] target, float[] contractor) + { + assert target.length == 6; + target[0] -= contractor[0]; + target[1] -= contractor[1]; + target[2] -= contractor[2]; + target[3] -= contractor[3]; + target[4] -= contractor[4]; + target[5] -= contractor[5]; + return target; + } + /** * Creates a new 6 element float array for use as a Bounding Box * diff --git a/src/java/growthcraft/api/core/util/DomainResourceLocationFactory.java b/src/java/growthcraft/api/core/util/DomainResourceLocationFactory.java new file mode 100644 index 000000000..f3a77f4e8 --- /dev/null +++ b/src/java/growthcraft/api/core/util/DomainResourceLocationFactory.java @@ -0,0 +1,68 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.core.util; + +import net.minecraft.util.ResourceLocation; + +/** + * You will get frustrated having to import ResourceLocation and then remembering the domain you want the resource from. + * NO MORE I SAY, I WANT MORE MAGIC IN MY LIFE. + */ +public class DomainResourceLocationFactory +{ + private final String domain; + + /** + * @param p_domain name of the domain that will be prefixed to the resource locations created by the factory + */ + public DomainResourceLocationFactory(String p_domain) + { + this.domain = p_domain; + } + + /** + * @return domain the domain this factory serves up + */ + public String getDomainName() + { + return domain; + } + + /** + * @param str str to append to the domain + * @return domained string + */ + public String join(String str) + { + return String.format("%s:%s", getDomainName(), str); + } + + /** + * @return resource location + */ + public ResourceLocation create(String name) + { + return new ResourceLocation(getDomainName(), name); + } +} diff --git a/src/java/growthcraft/api/fishtrap/BaitRegistry.java b/src/java/growthcraft/api/fishtrap/BaitRegistry.java new file mode 100644 index 000000000..40adb3204 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/BaitRegistry.java @@ -0,0 +1,59 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap; + +import growthcraft.api.core.registry.GenericItemRegistry; +import growthcraft.api.core.registry.ItemRegistryEntry; + +import net.minecraft.item.ItemStack; + +public class BaitRegistry extends GenericItemRegistry> +{ + public static class BaitHandle + { + public float baseRate; + public float multiplier = 1.0f; + + public BaitHandle() {} + + public BaitHandle(float base, float mul) + { + this(); + this.baseRate = base; + this.multiplier = mul; + } + } + + public void add(Object stack, BaitHandle handle) + { + add(new ItemRegistryEntry(stack, handle)); + } + + public BaitHandle findHandle(ItemStack stack) + { + final ItemRegistryEntry entry = find(stack); + if (entry != null) return entry.handle; + return null; + } +} diff --git a/src/java/growthcraft/core/common/tileentity/GrcTileEntityCommonBase.java b/src/java/growthcraft/api/fishtrap/CatchGroupEntry.java similarity index 62% rename from src/java/growthcraft/core/common/tileentity/GrcTileEntityCommonBase.java rename to src/java/growthcraft/api/fishtrap/CatchGroupEntry.java index 633043cd2..0042ce3f6 100644 --- a/src/java/growthcraft/core/common/tileentity/GrcTileEntityCommonBase.java +++ b/src/java/growthcraft/api/fishtrap/CatchGroupEntry.java @@ -21,48 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.api.fishtrap; -public abstract class GrcTileEntityCommonBase extends GrcTileEntityBase -{ - protected boolean needInventoryUpdate; +import javax.annotation.Nonnull; - protected void updateDevice() - { - } +import net.minecraft.util.WeightedRandom; + +public class CatchGroupEntry extends WeightedRandom.Item +{ + protected final String name; - // Call this when you modify a fluid tank outside of its usual methods - protected void markForFluidUpdate() + public CatchGroupEntry(@Nonnull String p_name, int weight) { - // + super(weight); + this.name = p_name; } - // Call this when you have modified the inventory, or you're not sure what - // kind of update you require - public void markForInventoryUpdate() + public String getName() { - needInventoryUpdate = true; + return name; } - protected void checkUpdateFlags() + @Override + public int hashCode() { - if (needInventoryUpdate) - { - needInventoryUpdate = false; - markDirty(); - } + return name.hashCode(); } @Override - public void updateEntity() + public boolean equals(Object other) { - super.updateEntity(); - - checkUpdateFlags(); - - if (!worldObj.isRemote) + if (other instanceof CatchGroupEntry) { - updateDevice(); + return this.name.equals(((CatchGroupEntry)other).name); } + return false; } } diff --git a/src/java/growthcraft/api/fishtrap/FishTrapRegistry.java b/src/java/growthcraft/api/fishtrap/FishTrapRegistry.java index 48a3b3427..8b00b3f92 100644 --- a/src/java/growthcraft/api/fishtrap/FishTrapRegistry.java +++ b/src/java/growthcraft/api/fishtrap/FishTrapRegistry.java @@ -1,82 +1,137 @@ package growthcraft.api.fishtrap; -import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Random; +import java.util.Set; +import javax.annotation.Nonnull; + +import growthcraft.api.core.log.ILogger; +import growthcraft.api.core.log.NullLogger; +import growthcraft.api.core.log.ILoggable; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandom; import net.minecraft.world.World; -public class FishTrapRegistry +public class FishTrapRegistry implements ILoggable { private static final FishTrapRegistry instance = new FishTrapRegistry(); - private final List fishList = new ArrayList(); - private final List treasureList = new ArrayList(); - private final List junkList = new ArrayList(); + private final BaitRegistry baits = new BaitRegistry(); + private final Set catchGroups = new HashSet(); + private final Map> entriesByGroup = new HashMap>(); + private ILogger logger = NullLogger.INSTANCE; public static final FishTrapRegistry instance() { return instance; } - ////////////////////////////////////////////////////////////////////// - // FISH TRAP ///////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////// + @Override + public void setLogger(@Nonnull ILogger l) + { + this.logger = l; + } - /** - * addTrapFish() // addTrapTreasure() // addTrapJunk() - * - * Example: - * FishTrapRegistry.instance().addTrapTreasure(new FishTrapEntry(new ItemStack(Item.bow), 1).setDamage(0.25F).setEnchantable()); - * - * new FishTrapEntry(new ItemStack(Item.bow), 1) - * -- ItemStack represents the...ItemStack. k - * -- 1 represents the weight of the ItemStack when randomly picked. Higher number means better chances being randomly picked. - * - * .setDamage(0.25F) - * -- Float param is the damage factor of the ItemStack. It will serve as the base factor for the ItemStack's damage. - * - * .setEnchantable() - * -- Call if the ItemStack can be enchanted. - * - * @param entry - The entry to be added. - */ - public void addTrapFish(FishTrapEntry entry) + public void addBait(Object stack, BaitRegistry.BaitHandle handle) { - this.fishList.add(entry); + logger.debug("Adding FishTrap Bait `%s`", stack); + baits.add(stack, handle); } - public void addTrapTreasure(FishTrapEntry entry) + public void addBait(Object stack, float base, float mul) { - this.treasureList.add(entry); + addBait(stack, new BaitRegistry.BaitHandle(base, mul)); } - public void addTrapJunk(FishTrapEntry entry) + public BaitRegistry.BaitHandle findBait(ItemStack stack) { - this.junkList.add(entry); + return baits.findHandle(stack); + } + + public void addCatchGroup(String name, int weight) + { + logger.debug("Adding Catch Group group=`%s` weight=%d", name, weight); + catchGroups.add(new CatchGroupEntry(name, weight)); + } + + public Collection getCatchGroups() + { + return catchGroups; + } + + public String getRandomCatchGroup(Random random) + { + final CatchGroupEntry entry = (CatchGroupEntry)WeightedRandom.getRandomItem(random, getCatchGroups()); + if (entry != null) return entry.getName(); + return null; + } + + public void addCatchToGroup(FishTrapEntry entry, String group) + { + if (!entriesByGroup.containsKey(group)) + { + entriesByGroup.put(group, new LinkedList()); + } + entriesByGroup.get(group).add(entry); + } + + private ItemStack getRandomCatchFromList(Random random, List list) + { + if (list.isEmpty()) return null; + return ((FishTrapEntry)WeightedRandom.getRandomItem(random, list)).getFishable(random); + } + + public ItemStack getRandomCatchFromGroup(Random random, String group) + { + final List list = entriesByGroup.get(group); + if (list != null) + { + return getRandomCatchFromList(random, list); + } + return null; } /** - * STUFF + * Use addCatchToGroup instead */ - private ItemStack getFishableEntry(Random random, List list) + @Deprecated + public void addTrapFish(FishTrapEntry entry) { - return ((FishTrapEntry)WeightedRandom.getRandomItem(random, list)).getFishable(random); + addCatchToGroup(entry, "fish"); + } + + @Deprecated + public void addTrapTreasure(FishTrapEntry entry) + { + addCatchToGroup(entry, "treasure"); + } + + @Deprecated + public void addTrapJunk(FishTrapEntry entry) + { + addCatchToGroup(entry, "junk"); } + @Deprecated public ItemStack getFishList(World world) { - return this.getFishableEntry(world.rand, this.fishList); + return getRandomCatchFromGroup(world.rand, "fish"); } + @Deprecated public ItemStack getTreasureList(World world) { - return this.getFishableEntry(world.rand, this.treasureList); + return getRandomCatchFromGroup(world.rand, "treasure"); } + @Deprecated public ItemStack getJunkList(World world) { - return this.getFishableEntry(world.rand, this.junkList); + return getRandomCatchFromGroup(world.rand, "junk"); } } diff --git a/src/java/growthcraft/api/fishtrap/user/UserBaitConfig.java b/src/java/growthcraft/api/fishtrap/user/UserBaitConfig.java new file mode 100644 index 000000000..526ea1269 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserBaitConfig.java @@ -0,0 +1,99 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import java.io.BufferedReader; + +import growthcraft.api.core.definition.IMultiItemStacks; +import growthcraft.api.core.user.AbstractUserJSONConfig; +import growthcraft.api.fishtrap.BaitRegistry; +import growthcraft.api.fishtrap.FishTrapRegistry; + +import net.minecraft.item.ItemStack; + +public class UserBaitConfig extends AbstractUserJSONConfig +{ + private final UserBaitEntries defaultEntries = new UserBaitEntries(); + private UserBaitEntries entries; + + public void addDefault(UserBaitEntry entry) + { + defaultEntries.data.add(entry); + } + + public void addDefault(ItemStack stack, float base, float mul) + { + addDefault(new UserBaitEntry(stack, base, mul)); + } + + @Override + protected String getDefault() + { + return gson.toJson(defaultEntries); + } + + @Override + protected void loadFromBuffer(BufferedReader buff) throws IllegalStateException + { + this.entries = gson.fromJson(buff, UserBaitEntries.class); + } + + private void addBaitEntry(UserBaitEntry entry) + { + if (entry == null) + { + logger.error("Invalid Entry"); + return; + } + + if (entry.item == null || entry.item.isInvalid()) + { + logger.error("Invalid item for entry {%s}", entry); + return; + } + + final BaitRegistry.BaitHandle handle = new BaitRegistry.BaitHandle(entry.base_rate, entry.multiplier); + for (IMultiItemStacks item : entry.item.getMultiItemStacks()) + { + FishTrapRegistry.instance().addBait(item, handle); + } + } + + @Override + public void postInit() + { + if (entries != null) + { + if (entries.data != null) + { + logger.debug("Adding %d user bait entries.", entries.data.size()); + for (UserBaitEntry entry : entries.data) addBaitEntry(entry); + } + else + { + logger.error("Config contains invalid data."); + } + } + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserBaitEntries.java b/src/java/growthcraft/api/fishtrap/user/UserBaitEntries.java new file mode 100644 index 000000000..88d3a0972 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserBaitEntries.java @@ -0,0 +1,47 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import java.util.ArrayList; +import java.util.List; + +import growthcraft.api.core.schema.ICommentable; + +public class UserBaitEntries implements ICommentable +{ + public String comment = ""; + public List data = new ArrayList(); + + @Override + public String getComment() + { + return comment; + } + + @Override + public void setComment(String com) + { + this.comment = com; + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserBaitEntry.java b/src/java/growthcraft/api/fishtrap/user/UserBaitEntry.java new file mode 100644 index 000000000..05ea62d38 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserBaitEntry.java @@ -0,0 +1,65 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import growthcraft.api.core.schema.ICommentable; +import growthcraft.api.core.schema.ItemKeySchema; + +import net.minecraft.item.ItemStack; + +public class UserBaitEntry implements ICommentable +{ + public String comment = ""; + public float base_rate; + public float multiplier; + public ItemKeySchema item; + + /** + * @param g - item group, can be "treasure", "junk", or "fish" + * @param w - entry weight + * @param stack - item stack + * @param dam - damage variance, how much damage is applied to the item when fished up? + * @param enc - is the item enchanted? + */ + public UserBaitEntry(ItemStack stack, float base, float mul) + { + this.item = new ItemKeySchema(stack); + this.base_rate = base; + this.multiplier = mul; + } + + public UserBaitEntry() {} + + @Override + public String getComment() + { + return comment; + } + + @Override + public void setComment(String com) + { + this.comment = com; + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserCatchGroupConfig.java b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupConfig.java new file mode 100644 index 000000000..ff005c846 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupConfig.java @@ -0,0 +1,93 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import java.io.BufferedReader; +import java.util.Map; + +import growthcraft.api.core.user.AbstractUserJSONConfig; +import growthcraft.api.fishtrap.FishTrapRegistry; + +public class UserCatchGroupConfig extends AbstractUserJSONConfig +{ + private final UserCatchGroupEntries defaultEntries = new UserCatchGroupEntries(); + private UserCatchGroupEntries entries; + + public void addDefault(String group, int weight, String comment) + { + final UserCatchGroupEntry entry = new UserCatchGroupEntry(weight); + entry.setComment(comment); + defaultEntries.data.put(group, entry); + } + + @Override + protected String getDefault() + { + return gson.toJson(defaultEntries); + } + + @Override + protected void loadFromBuffer(BufferedReader buff) throws IllegalStateException + { + this.entries = gson.fromJson(buff, UserCatchGroupEntries.class); + } + + private void addCatchGroupEntry(String name, UserCatchGroupEntry entry) + { + if (entry == null) + { + logger.error("Invalid Entry"); + return; + } + + if (entry.weight <= 0) + { + logger.error("Invalid weight for entry {%s}", entry); + return; + } + + logger.debug("Adding Catch Group %s", name); + FishTrapRegistry.instance().addCatchGroup(name, entry.weight); + } + + @Override + public void postInit() + { + if (entries != null) + { + if (entries.data != null) + { + logger.debug("Adding %d user catch groups.", entries.data.size()); + for (Map.Entry pair : entries.data.entrySet()) + { + addCatchGroupEntry(pair.getKey(), pair.getValue()); + } + } + else + { + logger.error("Config contains invalid data."); + } + } + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntries.java b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntries.java new file mode 100644 index 000000000..0b3020f69 --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntries.java @@ -0,0 +1,47 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import java.util.HashMap; +import java.util.Map; + +import growthcraft.api.core.schema.ICommentable; + +public class UserCatchGroupEntries implements ICommentable +{ + public String comment = ""; + public Map data = new HashMap(); + + @Override + public String getComment() + { + return comment; + } + + @Override + public void setComment(String com) + { + this.comment = com; + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntry.java b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntry.java new file mode 100644 index 000000000..b4ec7ff2a --- /dev/null +++ b/src/java/growthcraft/api/fishtrap/user/UserCatchGroupEntry.java @@ -0,0 +1,54 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.api.fishtrap.user; + +import growthcraft.api.core.schema.ICommentable; + +public class UserCatchGroupEntry implements ICommentable +{ + public String comment = ""; + public int weight; + + public UserCatchGroupEntry() + { + this.weight = 1; + } + + public UserCatchGroupEntry(int p_weight) + { + this.weight = p_weight; + } + + @Override + public String getComment() + { + return comment; + } + + @Override + public void setComment(String com) + { + this.comment = com; + } +} diff --git a/src/java/growthcraft/api/fishtrap/user/UserFishTrapConfig.java b/src/java/growthcraft/api/fishtrap/user/UserFishTrapConfig.java index d45422f03..c41d59954 100644 --- a/src/java/growthcraft/api/fishtrap/user/UserFishTrapConfig.java +++ b/src/java/growthcraft/api/fishtrap/user/UserFishTrapConfig.java @@ -67,20 +67,7 @@ private void addFishTrapEntry(UserFishTrapEntry entry) for (FishTrapEntry obj : entry.getFishTrapEntries()) { - switch (entry.group) - { - case "treasure": - FishTrapRegistry.instance().addTrapTreasure(obj); - break; - case "fish": - FishTrapRegistry.instance().addTrapFish(obj); - break; - case "junk": - FishTrapRegistry.instance().addTrapJunk(obj); - break; - default: - logger.error("There is no '%s' group for entry {%s}", entry.group, entry); - } + FishTrapRegistry.instance().addCatchToGroup(obj, entry.group); } } diff --git a/src/java/growthcraft/apples/GrcApplesConfig.java b/src/java/growthcraft/apples/GrcApplesConfig.java index 9612a8e0e..a63bb113b 100644 --- a/src/java/growthcraft/apples/GrcApplesConfig.java +++ b/src/java/growthcraft/apples/GrcApplesConfig.java @@ -28,6 +28,9 @@ public class GrcApplesConfig extends ConfigBase public int silkenNectarColor = 0xff9500; + @ConfigOption(catergory="Village", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Village", name="Generate Village Apple Farms", desc="Should we spawn Apple Farms in Villages?") public boolean generateAppleFarms; diff --git a/src/java/growthcraft/apples/GrowthCraftApples.java b/src/java/growthcraft/apples/GrowthCraftApples.java index 2a63e7087..4cbb7146f 100644 --- a/src/java/growthcraft/apples/GrowthCraftApples.java +++ b/src/java/growthcraft/apples/GrowthCraftApples.java @@ -3,20 +3,15 @@ import growthcraft.api.core.log.GrcLogger; import growthcraft.api.core.log.ILogger; import growthcraft.api.core.module.ModuleContainer; -import growthcraft.apples.common.block.BlockApple; -import growthcraft.apples.common.block.BlockAppleLeaves; -import growthcraft.apples.common.block.BlockAppleSapling; import growthcraft.apples.common.CommonProxy; -import growthcraft.apples.common.item.ItemAppleSeeds; import growthcraft.apples.common.village.ComponentVillageAppleFarm; import growthcraft.apples.common.village.VillageHandlerApples; import growthcraft.apples.handler.AppleFuelHandler; +import growthcraft.apples.init.GrcApplesBlocks; +import growthcraft.apples.init.GrcApplesItems; import growthcraft.apples.init.GrcApplesFluids; import growthcraft.apples.init.GrcApplesRecipes; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.core.common.definition.BlockTypeDefinition; -import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.definition.ItemDefinition; import growthcraft.core.GrowthCraftCore; import growthcraft.core.integration.NEI; import growthcraft.core.util.MapGenHelper; @@ -33,11 +28,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.oredict.OreDictionary; @Mod( modid = GrowthCraftApples.MOD_ID, @@ -54,11 +47,8 @@ public class GrowthCraftApples @Instance(MOD_ID) public static GrowthCraftApples instance; public static CreativeTabs creativeTab; - - public static BlockDefinition appleSapling; - public static BlockDefinition appleLeaves; - public static BlockTypeDefinition appleBlock; - public static ItemDefinition appleSeeds; + public static final GrcApplesBlocks blocks = new GrcApplesBlocks(); + public static final GrcApplesItems items = new GrcApplesItems(); public static final GrcApplesFluids fluids = new GrcApplesFluids(); private final ILogger logger = new GrcLogger(MOD_ID); @@ -77,55 +67,28 @@ public void preload(FMLPreInitializationEvent event) creativeTab = GrowthCraftCore.creativeTab; config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/apples.conf"); - + modules.add(blocks); + modules.add(items); modules.add(fluids); modules.add(recipes); if (config.enableForestryIntegration) modules.add(new growthcraft.apples.integration.ForestryModule()); if (config.enableMFRIntegration) modules.add(new growthcraft.apples.integration.MFRModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.apples.integration.ThaumcraftModule()); + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); - - appleSapling = new BlockDefinition(new BlockAppleSapling()); - appleLeaves = new BlockDefinition(new BlockAppleLeaves()); - appleBlock = new BlockTypeDefinition(new BlockApple()); - - appleSeeds = new ItemDefinition(new ItemAppleSeeds()); - + modules.freeze(); modules.preInit(); register(); } public void register() { - appleSapling.register("grc.appleSapling"); - appleLeaves.register("grc.appleLeaves"); - appleBlock.register("grc.appleBlock"); - appleSeeds.register("grc.appleSeeds"); - MapGenHelper.registerVillageStructure(ComponentVillageAppleFarm.class, "grc.applefarm"); - //==================== - // ADDITIONAL PROPS. - //==================== - Blocks.fire.setFireInfo(appleLeaves.getBlock(), 30, 60); - - //==================== - // ORE DICTIONARY - //==================== - OreDictionary.registerOre("saplingTree", appleSapling.getItem()); - OreDictionary.registerOre("treeSapling", appleSapling.getItem()); - OreDictionary.registerOre("seedApple", appleSeeds.getItem()); - OreDictionary.registerOre("treeLeaves", appleLeaves.asStack(1, OreDictionary.WILDCARD_VALUE)); - // For Pam's HarvestCraft - // Uses the same OreDict. names as HarvestCraft - OreDictionary.registerOre("listAllseed", appleSeeds.getItem()); - // Common - OreDictionary.registerOre("foodApple", Items.apple); - OreDictionary.registerOre("foodFruit", Items.apple); //==================== // CRAFTING //==================== - GameRegistry.addShapelessRecipe(appleSeeds.asStack(), Items.apple); + GameRegistry.addShapelessRecipe(items.appleSeeds.asStack(), Items.apple); MinecraftForge.EVENT_BUS.register(this); @@ -134,19 +97,24 @@ public void register() //==================== GameRegistry.registerFuelHandler(new AppleFuelHandler()); - NEI.hideItem(appleBlock.asStack()); + NEI.hideItem(blocks.appleBlock.asStack()); modules.register(); } - @EventHandler - public void load(FMLInitializationEvent event) + private void initVillageHandlers() { - CommonProxy.instance.initRenders(); final VillageHandlerApples handler = new VillageHandlerApples(); - VillagerRegistry.instance().registerVillageTradeHandler(GrowthCraftCellar.getConfig().villagerBrewerID, handler); + final int brewerID = GrowthCraftCellar.getConfig().villagerBrewerID; + if (brewerID > 0) + VillagerRegistry.instance().registerVillageTradeHandler(brewerID, handler); VillagerRegistry.instance().registerVillageCreationHandler(handler); + } + @EventHandler + public void load(FMLInitializationEvent event) + { + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } diff --git a/src/java/growthcraft/apples/client/ClientProxy.java b/src/java/growthcraft/apples/client/ClientProxy.java index 57fcc6043..15265580a 100644 --- a/src/java/growthcraft/apples/client/ClientProxy.java +++ b/src/java/growthcraft/apples/client/ClientProxy.java @@ -1,9 +1,30 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.apples.client; import growthcraft.apples.common.CommonProxy; public class ClientProxy extends CommonProxy { - @Override - public void initRenders() {} } diff --git a/src/java/growthcraft/apples/common/CommonProxy.java b/src/java/growthcraft/apples/common/CommonProxy.java index c7bc97a36..054b312a7 100644 --- a/src/java/growthcraft/apples/common/CommonProxy.java +++ b/src/java/growthcraft/apples/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.apples.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.apples.client.ClientProxy", serverSide="growthcraft.apples.common.CommonProxy") public static CommonProxy instance; - - public void initRenders() {} } diff --git a/src/java/growthcraft/apples/common/block/BlockApple.java b/src/java/growthcraft/apples/common/block/BlockApple.java index a8eb9bac2..bb5707a7a 100644 --- a/src/java/growthcraft/apples/common/block/BlockApple.java +++ b/src/java/growthcraft/apples/common/block/BlockApple.java @@ -161,7 +161,7 @@ public void onNeighborBlockChange(World world, int x, int y, int z, Block block) @Override public boolean canBlockStay(World world, int x, int y, int z) { - return GrowthCraftApples.appleLeaves.getBlock() == world.getBlock(x, y + 1, z) && + return GrowthCraftApples.blocks.appleLeaves.equals(world.getBlock(x, y + 1, z)) && (world.getBlockMetadata(x, y + 1, z) & 3) == 0; } diff --git a/src/java/growthcraft/apples/common/block/BlockAppleLeaves.java b/src/java/growthcraft/apples/common/block/BlockAppleLeaves.java index ef62df999..39ea012b1 100644 --- a/src/java/growthcraft/apples/common/block/BlockAppleLeaves.java +++ b/src/java/growthcraft/apples/common/block/BlockAppleLeaves.java @@ -74,7 +74,7 @@ private void growApple(World world, Random random, int x, int y, int z) { if (world.isAirBlock(x, y - 1, z)) { - world.setBlock(x, y - 1, z, GrowthCraftApples.appleBlock.getBlock()); + world.setBlock(x, y - 1, z, GrowthCraftApples.blocks.appleBlock.getBlock()); } } @@ -292,7 +292,7 @@ public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, in @Override public Item getItemDropped(int meta, Random random, int par3) { - return GrowthCraftApples.appleSapling.getItem(); + return GrowthCraftApples.blocks.appleSapling.getItem(); } @Override diff --git a/src/java/growthcraft/apples/common/item/ItemAppleSeeds.java b/src/java/growthcraft/apples/common/item/ItemAppleSeeds.java index 46f3e5473..226ff4e16 100644 --- a/src/java/growthcraft/apples/common/item/ItemAppleSeeds.java +++ b/src/java/growthcraft/apples/common/item/ItemAppleSeeds.java @@ -24,7 +24,7 @@ public class ItemAppleSeeds extends GrcItemBase implements IPlantable public ItemAppleSeeds() { super(); - this.cropBlock = GrowthCraftApples.appleSapling.getBlock(); + this.cropBlock = GrowthCraftApples.blocks.appleSapling.getBlock(); this.setUnlocalizedName("grc.appleSeeds"); this.setCreativeTab(GrowthCraftCore.creativeTab); } diff --git a/src/java/growthcraft/apples/common/world/WorldGenAppleTree.java b/src/java/growthcraft/apples/common/world/WorldGenAppleTree.java index eacb81466..1ee5eb411 100644 --- a/src/java/growthcraft/apples/common/world/WorldGenAppleTree.java +++ b/src/java/growthcraft/apples/common/world/WorldGenAppleTree.java @@ -18,7 +18,7 @@ public class WorldGenAppleTree extends WorldGenerator private final int metaWood = 0; private final int metaLeaves = 0; private final Block log = Blocks.log; - private final Block leaves = GrowthCraftApples.appleLeaves.getBlock(); + private final Block leaves = GrowthCraftApples.blocks.appleLeaves.getBlock(); public WorldGenAppleTree(boolean doblocknotify) { diff --git a/src/java/growthcraft/apples/handler/AppleFuelHandler.java b/src/java/growthcraft/apples/handler/AppleFuelHandler.java index 90f873c8a..22eae1603 100644 --- a/src/java/growthcraft/apples/handler/AppleFuelHandler.java +++ b/src/java/growthcraft/apples/handler/AppleFuelHandler.java @@ -18,7 +18,7 @@ public int getBurnTime(ItemStack fuel) if (fuel != null) { final Item item = fuel.getItem(); - if (GrowthCraftApples.appleSapling.equals(item)) + if (GrowthCraftApples.blocks.appleSapling.getItem().equals(item)) { return 100; } diff --git a/src/java/growthcraft/apples/init/GrcApplesBlocks.java b/src/java/growthcraft/apples/init/GrcApplesBlocks.java new file mode 100644 index 000000000..41683d875 --- /dev/null +++ b/src/java/growthcraft/apples/init/GrcApplesBlocks.java @@ -0,0 +1,63 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.apples.init; + +import growthcraft.apples.common.block.BlockApple; +import growthcraft.apples.common.block.BlockAppleLeaves; +import growthcraft.apples.common.block.BlockAppleSapling; +import growthcraft.core.common.definition.BlockDefinition; +import growthcraft.core.common.definition.BlockTypeDefinition; +import growthcraft.core.common.GrcModuleBlocks; + +import net.minecraft.init.Blocks; +import net.minecraftforge.oredict.OreDictionary; + +public class GrcApplesBlocks extends GrcModuleBlocks +{ + public BlockDefinition appleSapling; + public BlockDefinition appleLeaves; + public BlockTypeDefinition appleBlock; + + @Override + public void preInit() + { + this.appleSapling = newDefinition(new BlockAppleSapling()); + this.appleLeaves = newDefinition(new BlockAppleLeaves()); + this.appleBlock = newTypedDefinition(new BlockApple()); + } + + @Override + public void register() + { + appleSapling.register("grc.appleSapling"); + appleLeaves.register("grc.appleLeaves"); + appleBlock.register("grc.appleBlock"); + + OreDictionary.registerOre("saplingTree", appleSapling.getItem()); + OreDictionary.registerOre("treeSapling", appleSapling.getItem()); + OreDictionary.registerOre("treeLeaves", appleLeaves.asStack(1, OreDictionary.WILDCARD_VALUE)); + + Blocks.fire.setFireInfo(appleLeaves.getBlock(), 30, 60); + } +} diff --git a/src/java/growthcraft/apples/init/GrcApplesItems.java b/src/java/growthcraft/apples/init/GrcApplesItems.java new file mode 100644 index 000000000..85c852dcb --- /dev/null +++ b/src/java/growthcraft/apples/init/GrcApplesItems.java @@ -0,0 +1,55 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.apples.init; + +import growthcraft.apples.common.item.ItemAppleSeeds; +import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.common.GrcModuleItems; +import net.minecraft.init.Items; +import net.minecraftforge.oredict.OreDictionary; + +public class GrcApplesItems extends GrcModuleItems +{ + public ItemDefinition appleSeeds; + + @Override + public void preInit() + { + appleSeeds = newDefinition(new ItemAppleSeeds()); + } + + @Override + public void register() + { + appleSeeds.register("grc.appleSeeds"); + + OreDictionary.registerOre("seedApple", appleSeeds.getItem()); + // For Pam's HarvestCraft + // Uses the same OreDict. names as HarvestCraft + OreDictionary.registerOre("listAllseed", appleSeeds.getItem()); + // Common + OreDictionary.registerOre("foodApple", Items.apple); + OreDictionary.registerOre("foodFruit", Items.apple); + } +} diff --git a/src/java/growthcraft/apples/integration/ForestryModule.java b/src/java/growthcraft/apples/integration/ForestryModule.java index be0b7956e..771d0e6f3 100644 --- a/src/java/growthcraft/apples/integration/ForestryModule.java +++ b/src/java/growthcraft/apples/integration/ForestryModule.java @@ -41,7 +41,7 @@ public ForestryModule() @Optional.Method(modid="Forestry") protected void integrate() { - final ItemStack appleSeed = GrowthCraftApples.appleSeeds.asStack(); + final ItemStack appleSeed = GrowthCraftApples.items.appleSeeds.asStack(); final int seedamount = getActiveMode().getIntegerSetting("squeezer.liquid.seed"); if (ForestryFluids.SEEDOIL.exists()) recipes().squeezerManager.addRecipe(10, new ItemStack[]{appleSeed}, ForestryFluids.SEEDOIL.asFluidStack(seedamount)); Backpack.FORESTERS.add(appleSeed); diff --git a/src/java/growthcraft/apples/integration/MFRModule.java b/src/java/growthcraft/apples/integration/MFRModule.java index ca6113d2f..56ce11c16 100644 --- a/src/java/growthcraft/apples/integration/MFRModule.java +++ b/src/java/growthcraft/apples/integration/MFRModule.java @@ -41,7 +41,7 @@ public MFRModule() protected void integrate() { registerPickableFruit(new AppleBlockFactoryFruit()); - registerHarvestableLeaves(GrowthCraftApples.appleLeaves.getBlock()); - registerPlantableSapling(GrowthCraftApples.appleSapling.getBlock()); + registerHarvestableLeaves(GrowthCraftApples.blocks.appleLeaves.getBlock()); + registerPlantableSapling(GrowthCraftApples.blocks.appleSapling.getBlock()); } } diff --git a/src/java/growthcraft/apples/integration/ThaumcraftModule.java b/src/java/growthcraft/apples/integration/ThaumcraftModule.java index b7644c72c..f4e9d9efa 100644 --- a/src/java/growthcraft/apples/integration/ThaumcraftModule.java +++ b/src/java/growthcraft/apples/integration/ThaumcraftModule.java @@ -46,11 +46,11 @@ public ThaumcraftModule() @Optional.Method(modid="Thaumcraft") protected void integrate() { - FMLInterModComms.sendMessage(modID, "harvestStandardCrop", GrowthCraftApples.appleBlock.asStack(1, 2)); + FMLInterModComms.sendMessage(modID, "harvestStandardCrop", GrowthCraftApples.blocks.appleBlock.asStack(1, 2)); - ThaumcraftApi.registerObjectTag(GrowthCraftApples.appleSapling.asStack(), new AspectList().add(Aspect.PLANT, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftApples.appleSeeds.asStack(), new AspectList().add(Aspect.PLANT, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftApples.appleLeaves.asStack(), new AspectList().add(Aspect.PLANT, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftApples.blocks.appleSapling.asStack(), new AspectList().add(Aspect.PLANT, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftApples.items.appleSeeds.asStack(), new AspectList().add(Aspect.PLANT, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftApples.blocks.appleLeaves.asStack(), new AspectList().add(Aspect.PLANT, 1)); final AspectList[] common = new AspectList[] { diff --git a/src/java/growthcraft/apples/integration/mfr/AppleBlockFactoryFruit.java b/src/java/growthcraft/apples/integration/mfr/AppleBlockFactoryFruit.java index bf42bd135..ad0515114 100644 --- a/src/java/growthcraft/apples/integration/mfr/AppleBlockFactoryFruit.java +++ b/src/java/growthcraft/apples/integration/mfr/AppleBlockFactoryFruit.java @@ -34,7 +34,7 @@ public class AppleBlockFactoryFruit extends AbstractFactoryFruit public AppleBlockFactoryFruit() { super(); - setPlant(GrowthCraftApples.appleBlock.getBlock()); + setPlant(GrowthCraftApples.blocks.appleBlock.getBlock()); } @Override diff --git a/src/java/growthcraft/bamboo/GrowthCraftBamboo.java b/src/java/growthcraft/bamboo/GrowthCraftBamboo.java index 1eef3478c..38a8d22c1 100644 --- a/src/java/growthcraft/bamboo/GrowthCraftBamboo.java +++ b/src/java/growthcraft/bamboo/GrowthCraftBamboo.java @@ -52,14 +52,14 @@ public class GrowthCraftBamboo public static GrowthCraftBamboo instance; public static CreativeTabs creativeTab; - public static GrcBambooBlocks blocks = new GrcBambooBlocks(); - public static GrcBambooItems items = new GrcBambooItems(); + public static final GrcBambooBlocks blocks = new GrcBambooBlocks(); + public static final GrcBambooItems items = new GrcBambooItems(); public static BiomeGenBase bambooBiome; - private ILogger logger = new GrcLogger(MOD_ID); - private GrcBambooConfig config = new GrcBambooConfig(); - private ModuleContainer modules = new ModuleContainer(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcBambooConfig config = new GrcBambooConfig(); + private final ModuleContainer modules = new ModuleContainer(); public static GrcBambooConfig getConfig() { @@ -71,14 +71,14 @@ public void preInit(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/bamboo.conf"); - modules.add(blocks); modules.add(items); if (config.enableForestryIntegration) modules.add(new growthcraft.bamboo.integration.ForestryModule()); if (config.enableMFRIntegration) modules.add(new growthcraft.bamboo.integration.MFRModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.bamboo.integration.ThaumcraftModule()); + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); - + modules.freeze(); creativeTab = new CreativeTabsGrowthcraftBamboo("creative_tab_grcbamboo"); modules.preInit(); @@ -102,7 +102,7 @@ private void register() { //GameRegistry.addBiome(bambooBiome); BiomeManager.addSpawnBiome(bambooBiome); - BiomeDictionary.registerBiomeType(bambooBiome, Type.FOREST); + BiomeDictionary.registerBiomeType(bambooBiome, Type.DENSE, Type.LUSH, Type.FOREST); } GameRegistry.registerWorldGenerator(new WorldGeneratorBamboo(), 0); @@ -179,10 +179,8 @@ public void registerOres() @EventHandler public void init(FMLInitializationEvent event) { - CommonProxy.instance.initRenders(); final VillageHandlerBamboo handler = new VillageHandlerBamboo(); VillagerRegistry.instance().registerVillageCreationHandler(handler); - modules.init(); } diff --git a/src/java/growthcraft/bamboo/client/ClientProxy.java b/src/java/growthcraft/bamboo/client/ClientProxy.java index 093634d73..e1a60158e 100644 --- a/src/java/growthcraft/bamboo/client/ClientProxy.java +++ b/src/java/growthcraft/bamboo/client/ClientProxy.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.bamboo.client; import growthcraft.bamboo.client.renderer.RenderBamboo; @@ -13,8 +36,9 @@ public class ClientProxy extends CommonProxy { @Override - public void initRenders() + public void init() { + super.init(); RenderingRegistry.registerBlockHandler(new RenderBamboo()); RenderingRegistry.registerBlockHandler(new RenderBambooFence()); RenderingRegistry.registerBlockHandler(new RenderBambooWall()); diff --git a/src/java/growthcraft/bamboo/common/CommonProxy.java b/src/java/growthcraft/bamboo/common/CommonProxy.java index 19a1fe6ea..09528c6af 100644 --- a/src/java/growthcraft/bamboo/common/CommonProxy.java +++ b/src/java/growthcraft/bamboo/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.bamboo.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.bamboo.client.ClientProxy", serverSide="growthcraft.bamboo.common.CommonProxy") public static CommonProxy instance; - - public void initRenders() {} } diff --git a/src/java/growthcraft/bamboo/common/block/BlockBambooSlab.java b/src/java/growthcraft/bamboo/common/block/BlockBambooSlab.java index 30c2902a0..256e1d95f 100644 --- a/src/java/growthcraft/bamboo/common/block/BlockBambooSlab.java +++ b/src/java/growthcraft/bamboo/common/block/BlockBambooSlab.java @@ -37,7 +37,7 @@ public BlockBambooSlab(boolean par2) @SuppressWarnings({"rawtypes", "unchecked"}) public void getSubBlocks(Item item, CreativeTabs tab, List list) { - if (item != Item.getItemFromBlock(GrowthCraftBamboo.blocks.bambooDoubleSlab.getBlock())) + if (GrowthCraftBamboo.blocks.bambooDoubleSlab.getItem() != item) { list.add(new ItemStack(item, 1, 0)); } @@ -59,7 +59,7 @@ private static boolean isBlockSingleSlab(Block block) @SideOnly(Side.CLIENT) public Item getItem(World par1World, int par2, int par3, int par4) { - return Item.getItemFromBlock(GrowthCraftBamboo.blocks.bambooSingleSlab.getBlock()); + return GrowthCraftBamboo.blocks.bambooSingleSlab.getItem(); } /************ @@ -68,12 +68,12 @@ public Item getItem(World par1World, int par2, int par3, int par4) @Override public Item getItemDropped(int par1, Random par2Random, int par3) { - return Item.getItemFromBlock(GrowthCraftBamboo.blocks.bambooSingleSlab.getBlock()); + return GrowthCraftBamboo.blocks.bambooSingleSlab.getItem(); } protected ItemStack createStackedBlock(int par1) { - return new ItemStack(GrowthCraftBamboo.blocks.bambooSingleSlab.getBlock(), 2, 0); + return new ItemStack(GrowthCraftBamboo.blocks.bambooSingleSlab.getItem(), 2, 0); } /************ diff --git a/src/java/growthcraft/bamboo/init/GrcBambooBlocks.java b/src/java/growthcraft/bamboo/init/GrcBambooBlocks.java index 26a9da676..80fb68c64 100644 --- a/src/java/growthcraft/bamboo/init/GrcBambooBlocks.java +++ b/src/java/growthcraft/bamboo/init/GrcBambooBlocks.java @@ -38,14 +38,14 @@ import growthcraft.core.common.block.BlockFenceRope; import growthcraft.core.common.definition.BlockDefinition; import growthcraft.core.common.definition.BlockTypeDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleBlocks; import growthcraft.core.integration.NEI; import growthcraft.core.registry.FenceRopeRegistry; import net.minecraft.block.BlockSlab; import net.minecraft.init.Blocks; -public class GrcBambooBlocks extends GrcModuleBase +public class GrcBambooBlocks extends GrcModuleBlocks { public BlockTypeDefinition bambooBlock; public BlockTypeDefinition bambooShoot; @@ -55,8 +55,8 @@ public class GrcBambooBlocks extends GrcModuleBase public BlockDefinition bambooFenceRope; public BlockDefinition bambooWall; public BlockDefinition bambooStairs; - public BlockTypeDefinition bambooSingleSlab; - public BlockTypeDefinition bambooDoubleSlab; + public BlockTypeDefinition bambooSingleSlab; + public BlockTypeDefinition bambooDoubleSlab; public BlockDefinition bambooDoor; public BlockDefinition bambooFenceGate; public BlockDefinition bambooScaffold; @@ -64,19 +64,19 @@ public class GrcBambooBlocks extends GrcModuleBase @Override public void preInit() { - bambooBlock = new BlockTypeDefinition(new BlockBamboo()); - bambooShoot = new BlockTypeDefinition(new BlockBambooShoot()); - bambooStalk = new BlockTypeDefinition(new BlockBambooStalk()); - bambooLeaves = new BlockDefinition(new BlockBambooLeaves()); - bambooFence = new BlockDefinition(new BlockBambooFence()); - bambooWall = new BlockDefinition(new BlockBambooWall()); - bambooStairs = new BlockDefinition(new BlockBambooStairs()); - bambooSingleSlab = new BlockTypeDefinition(new BlockBambooSlab(false)); - bambooDoubleSlab = new BlockTypeDefinition(new BlockBambooSlab(true)); - bambooDoor = new BlockDefinition(new BlockBambooDoor()); - bambooFenceGate = new BlockDefinition(new BlockBambooFenceGate()); - bambooScaffold = new BlockDefinition(new BlockBambooScaffold()); - bambooFenceRope = new BlockDefinition(new BlockFenceRope(bambooFence.getBlock(), "grc.bambooFenceRope")); + bambooBlock = newTypedDefinition(new BlockBamboo()); + bambooShoot = newTypedDefinition(new BlockBambooShoot()); + bambooStalk = newTypedDefinition(new BlockBambooStalk()); + bambooLeaves = newDefinition(new BlockBambooLeaves()); + bambooFence = newDefinition(new BlockBambooFence()); + bambooWall = newDefinition(new BlockBambooWall()); + bambooStairs = newDefinition(new BlockBambooStairs()); + bambooSingleSlab = newTypedDefinition(new BlockBambooSlab(false)); + bambooDoubleSlab = newTypedDefinition(new BlockBambooSlab(true)); + bambooDoor = newDefinition(new BlockBambooDoor()); + bambooFenceGate = newDefinition(new BlockBambooFenceGate()); + bambooScaffold = newDefinition(new BlockBambooScaffold()); + bambooFenceRope = newDefinition(new BlockFenceRope(bambooFence.getBlock(), "grc.bambooFenceRope")); FenceRopeRegistry.instance().addEntry(bambooFence.getBlock(), bambooFenceRope.getBlock()); } diff --git a/src/java/growthcraft/bamboo/init/GrcBambooItems.java b/src/java/growthcraft/bamboo/init/GrcBambooItems.java index 72ac6b33c..062e354da 100644 --- a/src/java/growthcraft/bamboo/init/GrcBambooItems.java +++ b/src/java/growthcraft/bamboo/init/GrcBambooItems.java @@ -29,9 +29,9 @@ import growthcraft.bamboo.common.item.ItemBambooRaft; import growthcraft.bamboo.common.item.ItemBambooShoot; import growthcraft.core.common.definition.ItemDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleItems; -public class GrcBambooItems extends GrcModuleBase +public class GrcBambooItems extends GrcModuleItems { public ItemDefinition bamboo; public ItemDefinition bambooDoorItem; @@ -42,11 +42,11 @@ public class GrcBambooItems extends GrcModuleBase @Override public void preInit() { - this.bamboo = new ItemDefinition(new ItemBamboo()); - this.bambooDoorItem = new ItemDefinition(new ItemBambooDoor()); - this.bambooRaft = new ItemDefinition(new ItemBambooRaft()); - this.bambooCoal = new ItemDefinition(new ItemBambooCoal()); - this.bambooShootFood = new ItemDefinition(new ItemBambooShoot()); + this.bamboo = newDefinition(new ItemBamboo()); + this.bambooDoorItem = newDefinition(new ItemBambooDoor()); + this.bambooRaft = newDefinition(new ItemBambooRaft()); + this.bambooCoal = newDefinition(new ItemBambooCoal()); + this.bambooShootFood = newDefinition(new ItemBambooShoot()); } @Override diff --git a/src/java/growthcraft/bees/GrcBeesConfig.java b/src/java/growthcraft/bees/GrcBeesConfig.java index dc3c3d5cf..ea0083002 100644 --- a/src/java/growthcraft/bees/GrcBeesConfig.java +++ b/src/java/growthcraft/bees/GrcBeesConfig.java @@ -41,6 +41,9 @@ public class GrcBeesConfig extends ConfigBase public int honeyMeadColor = 0xA3610C; + @ConfigOption(catergory="Village", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Village", name="Apiarist ID") public int villagerApiaristID = 7766; diff --git a/src/java/growthcraft/bees/GrowthCraftBees.java b/src/java/growthcraft/bees/GrowthCraftBees.java index 919408879..f33f3c56f 100644 --- a/src/java/growthcraft/bees/GrowthCraftBees.java +++ b/src/java/growthcraft/bees/GrowthCraftBees.java @@ -1,7 +1,5 @@ package growthcraft.bees; -import java.util.List; - import growthcraft.api.bees.BeesFluidTag; import growthcraft.api.bees.BeesRegistry; import growthcraft.api.bees.user.UserBeesConfig; @@ -13,25 +11,23 @@ import growthcraft.api.core.log.ILogger; import growthcraft.api.core.module.ModuleContainer; import growthcraft.bees.client.eventhandler.GrcBeesHandleTextureStitch; -import growthcraft.bees.client.gui.GuiHandlerBees; -import growthcraft.bees.common.block.BlockBeeBox; -import growthcraft.bees.common.block.BlockBeeHive; import growthcraft.bees.common.CommonProxy; -import growthcraft.bees.common.item.ItemBlockBeeBox; import growthcraft.bees.common.tileentity.TileEntityBeeBox; import growthcraft.bees.common.village.ComponentVillageApiarist; import growthcraft.bees.common.village.VillageHandlerBees; import growthcraft.bees.common.village.VillageHandlerBeesApiarist; import growthcraft.bees.common.world.WorldGeneratorBees; import growthcraft.bees.creativetab.CreativeTabsGrowthcraftBees; +import growthcraft.bees.init.GrcBeesBlocks; import growthcraft.bees.init.GrcBeesFluids; import growthcraft.bees.init.GrcBeesItems; import growthcraft.bees.init.GrcBeesRecipes; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.definition.BlockTypeDefinition; +import growthcraft.core.GrcGuiProvider; import growthcraft.core.integration.bop.BopPlatform; import growthcraft.core.util.MapGenHelper; + import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -63,28 +59,18 @@ public class GrowthCraftBees @Instance(MOD_ID) public static GrowthCraftBees instance; - public static CreativeTabs tab; - - public static BlockTypeDefinition beeBox; - public static BlockTypeDefinition beeBoxBamboo; - public static BlockTypeDefinition beeBoxNatura; - public static BlockTypeDefinition beeBoxBiomesOPlenty; - public static BlockTypeDefinition beeBoxBotania; - public static BlockTypeDefinition beeBoxNether; - public static BlockTypeDefinition beeBoxThaumcraft; - public static List> beeBoxesForestry; - public static List> beeBoxesForestryFireproof; - public static BlockDefinition beeHive; - public static GrcBeesItems items = new GrcBeesItems(); - public static GrcBeesFluids fluids = new GrcBeesFluids(); - - private ILogger logger = new GrcLogger(MOD_ID); - private GrcBeesConfig config = new GrcBeesConfig(); - private ModuleContainer modules = new ModuleContainer(); - private UserBeesConfig userBeesConfig = new UserBeesConfig(); - private UserFlowersConfig userFlowersConfig = new UserFlowersConfig(); - private GrcBeesRecipes recipes = new GrcBeesRecipes(); + public static final GrcBeesBlocks blocks = new GrcBeesBlocks(); + public static final GrcBeesItems items = new GrcBeesItems(); + public static final GrcBeesFluids fluids = new GrcBeesFluids(); + public static final GrcGuiProvider guiProvider = new GrcGuiProvider(new GrcLogger(MOD_ID + ":GuiProvider")); + + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcBeesConfig config = new GrcBeesConfig(); + private final ModuleContainer modules = new ModuleContainer(); + private final UserBeesConfig userBeesConfig = new UserBeesConfig(); + private final UserFlowersConfig userFlowersConfig = new UserFlowersConfig(); + private final GrcBeesRecipes recipes = new GrcBeesRecipes(); //private UserHoneyConfig userHoneyConfig = new UserHoneyConfig(); public static UserBeesConfig getUserBeesConfig() @@ -106,11 +92,11 @@ public static GrcBeesConfig getConfig() } @EventHandler - public void preload(FMLPreInitializationEvent event) + public void preInit(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/bees.conf"); - + modules.add(blocks); modules.add(items); modules.add(fluids); modules.add(recipes); @@ -132,36 +118,23 @@ public void preload(FMLPreInitializationEvent event) if (config.enableBotaniaIntegration) modules.add(new growthcraft.bees.integration.BotaniaModule()); if (config.enableForestryIntegration) modules.add(new growthcraft.bees.integration.ForestryModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.bees.integration.ThaumcraftModule()); - + modules.add(CommonProxy.instance); if (config.debugEnabled) { BeesRegistry.instance().setLogger(logger); modules.setLogger(logger); } - + modules.freeze(); tab = new CreativeTabsGrowthcraftBees("creative_tab_grcbees"); MinecraftForge.EVENT_BUS.register(new GrcBeesHandleTextureStitch()); - initBlocksAndItems(); - } - - private void initBlocksAndItems() - { - beeBox = new BlockTypeDefinition(new BlockBeeBox()); - beeBox.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); - beeHive = new BlockDefinition(new BlockBeeHive()); - modules.preInit(); register(); } private void register() { - // Bee Boxes - GameRegistry.registerBlock(beeBox.getBlock(), ItemBlockBeeBox.class, "grc.beeBox"); - // Bee Hive(s) - GameRegistry.registerBlock(beeHive.getBlock(), "grc.beeHive"); // TileEntities GameRegistry.registerTileEntity(TileEntityBeeBox.class, "grc.tileentity.beeBox"); GameRegistry.registerWorldGenerator(new WorldGeneratorBees(), 0); @@ -187,13 +160,10 @@ private void register() private void registerRecipes() { - //==================== - // CRAFTING - //==================== final BlockDefinition planks = new BlockDefinition(Blocks.planks); for (int i = 0; i < 6; ++i) { - GameRegistry.addRecipe(beeBox.asStack(1, i), new Object[] { " A ", "A A", "AAA", 'A', planks.asStack(1, i) }); + GameRegistry.addRecipe(blocks.beeBox.asStack(1, i), new Object[] { " A ", "A A", "AAA", 'A', planks.asStack(1, i) }); } final ItemStack honeyStack = items.honeyCombFilled.asStack(); @@ -203,7 +173,7 @@ private void registerRecipes() private void postRegisterRecipes() { - GameRegistry.addRecipe(new ShapedOreRecipe(beeBox.asStack(), " A ", "A A", "AAA", 'A', "plankWood")); + GameRegistry.addRecipe(new ShapedOreRecipe(blocks.beeBox.asStack(), " A ", "A A", "AAA", 'A', "plankWood")); GameRegistry.addRecipe(new ShapelessMultiRecipe( items.honeyJar.asStack(), @@ -211,27 +181,33 @@ private void postRegisterRecipes() Items.flower_pot)); } - @EventHandler - public void load(FMLInitializationEvent event) + private void initVillageHandlers() { - CommonProxy.instance.initRenders(); - CommonProxy.instance.initSounds(); - - NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerBees()); - final VillageHandlerBeesApiarist handler = new VillageHandlerBeesApiarist(); - VillagerRegistry.instance().registerVillagerId(config.villagerApiaristID); + final int brewerID = GrowthCraftCellar.getConfig().villagerBrewerID; + final int apiaristID = config.villagerApiaristID; + if (apiaristID > 0) + { + VillagerRegistry.instance().registerVillagerId(apiaristID); + VillagerRegistry.instance().registerVillageTradeHandler(apiaristID, handler); + } VillagerRegistry.instance().registerVillageCreationHandler(handler); - VillagerRegistry.instance().registerVillageTradeHandler(GrowthCraftCellar.getConfig().villagerBrewerID, new VillageHandlerBees()); - VillagerRegistry.instance().registerVillageTradeHandler(config.villagerApiaristID, handler); - - CommonProxy.instance.registerVillagerSkin(); + if (brewerID > 0) + { + VillagerRegistry.instance().registerVillageTradeHandler(brewerID, new VillageHandlerBees()); + } + } + @EventHandler + public void init(FMLInitializationEvent event) + { + NetworkRegistry.INSTANCE.registerGuiHandler(this, guiProvider); + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } @EventHandler - public void postload(FMLPostInitializationEvent event) + public void postInit(FMLPostInitializationEvent event) { userBeesConfig.loadUserConfig(); userFlowersConfig.loadUserConfig(); diff --git a/src/java/growthcraft/bees/client/ClientProxy.java b/src/java/growthcraft/bees/client/ClientProxy.java index 2c97eefec..25e32ad3a 100644 --- a/src/java/growthcraft/bees/client/ClientProxy.java +++ b/src/java/growthcraft/bees/client/ClientProxy.java @@ -1,5 +1,29 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.bees.client; +import growthcraft.bees.client.gui.GuiBeeBox; import growthcraft.bees.client.renderer.RenderBeeBox; import growthcraft.bees.client.renderer.RenderBeeHive; import growthcraft.bees.common.CommonProxy; @@ -11,16 +35,27 @@ public class ClientProxy extends CommonProxy { - @Override - public void initRenders() + protected void initRenders() { RenderingRegistry.registerBlockHandler(new RenderBeeBox()); RenderingRegistry.registerBlockHandler(new RenderBeeHive()); } + protected void registerVillagerSkin() + { + final int villagerID = GrowthCraftBees.getConfig().villagerApiaristID; + if (villagerID > 0) + { + VillagerRegistry.instance().registerVillagerSkin(villagerID, new ResourceLocation("grcbees" , "textures/entity/apiarist.png")); + } + } + @Override - public void registerVillagerSkin() + public void init() { - VillagerRegistry.instance().registerVillagerSkin(GrowthCraftBees.getConfig().villagerApiaristID, new ResourceLocation("grcbees" , "textures/entity/apiarist.png")); + super.init(); + initRenders(); + registerVillagerSkin(); + GrowthCraftBees.guiProvider.register("grcbees:bee_box", GuiBeeBox.class); } } diff --git a/src/java/growthcraft/bees/client/eventhandler/GrcBeesHandleTextureStitch.java b/src/java/growthcraft/bees/client/eventhandler/GrcBeesHandleTextureStitch.java index c00921666..4691f1889 100644 --- a/src/java/growthcraft/bees/client/eventhandler/GrcBeesHandleTextureStitch.java +++ b/src/java/growthcraft/bees/client/eventhandler/GrcBeesHandleTextureStitch.java @@ -46,11 +46,11 @@ public class GrcBeesHandleTextureStitch @SideOnly(Side.CLIENT) private void loadShimmerWoodInterpolatedIcons(TextureStitchEvent.Pre event) { - if (GrowthCraftBees.beeBoxBotania != null) + if (GrowthCraftBees.blocks.beeBoxBotania != null) { final int offset = EnumBotaniaWoodType.SHIMMER_WOOD.meta; final String[] sides = { "bottom", "top", "side", "side_honey" }; - final IIcon[] icons = GrowthCraftBees.beeBoxBotania.getBlock().getIcons(); + final IIcon[] icons = GrowthCraftBees.blocks.beeBoxBotania.getBlock().getIcons(); int i = 0; for (String side : sides) { diff --git a/src/java/growthcraft/bees/client/gui/GuiHandlerBees.java b/src/java/growthcraft/bees/client/gui/GuiHandlerBees.java deleted file mode 100644 index 92ad8c1f4..000000000 --- a/src/java/growthcraft/bees/client/gui/GuiHandlerBees.java +++ /dev/null @@ -1,38 +0,0 @@ -package growthcraft.bees.client.gui; - -import growthcraft.bees.common.inventory.ContainerBeeBox; -import growthcraft.bees.common.tileentity.TileEntityBeeBox; - -import cpw.mods.fml.common.network.IGuiHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class GuiHandlerBees implements IGuiHandler -{ - @Override - public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityBeeBox) - { - return new ContainerBeeBox(player.inventory, (TileEntityBeeBox)te); - } - - return null; - } - - @Override - public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityBeeBox) - { - return new GuiBeeBox(player.inventory, (TileEntityBeeBox)te); - } - - return null; - } -} diff --git a/src/java/growthcraft/bees/common/CommonProxy.java b/src/java/growthcraft/bees/common/CommonProxy.java index 2ff520621..a39ad9aab 100644 --- a/src/java/growthcraft/bees/common/CommonProxy.java +++ b/src/java/growthcraft/bees/common/CommonProxy.java @@ -1,13 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.bees.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.bees.client.ClientProxy", serverSide="growthcraft.bees.common.CommonProxy") public static CommonProxy instance; - - public void initRenders(){} - public void initSounds(){} - public void registerVillagerSkin(){} } diff --git a/src/java/growthcraft/bees/common/block/BlockBeeBox.java b/src/java/growthcraft/bees/common/block/BlockBeeBox.java index 522032a1a..aacad7745 100644 --- a/src/java/growthcraft/bees/common/block/BlockBeeBox.java +++ b/src/java/growthcraft/bees/common/block/BlockBeeBox.java @@ -191,12 +191,6 @@ public int damageDropped(int damage) return damage; } - @Override - public Item getItemDropped(int par1, Random random, int par3) - { - return GrowthCraftBees.beeBox.getItem(); - } - @Override public int quantityDropped(Random random) { diff --git a/src/java/growthcraft/bees/common/block/EnumBeeBoxThaumcraft.java b/src/java/growthcraft/bees/common/block/EnumBeeBoxThaumcraft.java index 332845eb6..2a0a8d996 100644 --- a/src/java/growthcraft/bees/common/block/EnumBeeBoxThaumcraft.java +++ b/src/java/growthcraft/bees/common/block/EnumBeeBoxThaumcraft.java @@ -47,9 +47,9 @@ private EnumBeeBoxThaumcraft() public ItemStack asStack(int size) { - if (GrowthCraftBees.beeBoxThaumcraft != null) + if (GrowthCraftBees.blocks.beeBoxThaumcraft != null) { - return GrowthCraftBees.beeBoxThaumcraft.asStack(size, meta); + return GrowthCraftBees.blocks.beeBoxThaumcraft.asStack(size, meta); } return null; } diff --git a/src/java/growthcraft/bees/common/inventory/SlotHoneyComb.java b/src/java/growthcraft/bees/common/inventory/SlotHoneyComb.java index 474fbb962..59aba4a8e 100644 --- a/src/java/growthcraft/bees/common/inventory/SlotHoneyComb.java +++ b/src/java/growthcraft/bees/common/inventory/SlotHoneyComb.java @@ -1,30 +1,32 @@ package growthcraft.bees.common.inventory; import growthcraft.api.bees.BeesRegistry; -import growthcraft.core.common.inventory.slot.GrcSlot; +import growthcraft.core.common.inventory.slot.SlotInput; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -public class SlotHoneyComb extends GrcSlot +public class SlotHoneyComb extends SlotInput { - final ContainerBeeBox con; + final ContainerBeeBox container; public SlotHoneyComb(ContainerBeeBox cont, IInventory inv, int x, int y, int z) { super(inv, x, y, z); - this.con = cont; + this.container = cont; } @Override public boolean isItemValid(ItemStack stack) { + // Only if the item is some kind of honey comb return BeesRegistry.instance().isItemHoneyComb(stack); } @Override public int getSlotStackLimit() { + // 1 comb per slot return 1; } } diff --git a/src/java/growthcraft/bees/common/tileentity/TileEntityBeeBox.java b/src/java/growthcraft/bees/common/tileentity/TileEntityBeeBox.java index 2dec24325..269ce0035 100644 --- a/src/java/growthcraft/bees/common/tileentity/TileEntityBeeBox.java +++ b/src/java/growthcraft/bees/common/tileentity/TileEntityBeeBox.java @@ -1,24 +1,28 @@ package growthcraft.bees.common.tileentity; import growthcraft.api.bees.BeesRegistry; -import growthcraft.api.core.util.AuxFX; import growthcraft.api.core.item.EnumDye; +import growthcraft.api.core.util.AuxFX; import growthcraft.bees.common.inventory.ContainerBeeBox; import growthcraft.bees.common.tileentity.device.DeviceBeeBox; import growthcraft.bees.GrowthCraftBees; import growthcraft.core.common.inventory.GrcInternalInventory; -import growthcraft.core.common.tileentity.GrcTileEntityInventoryBase; -import growthcraft.core.common.tileentity.IItemHandler; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.IInteractionObject; +import growthcraft.core.common.tileentity.feature.IItemHandler; +import growthcraft.core.common.tileentity.GrcTileInventoryBase; import growthcraft.core.util.ItemUtils; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; +import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class TileEntityBeeBox extends GrcTileEntityInventoryBase implements IItemHandler +public class TileEntityBeeBox extends GrcTileInventoryBase implements IItemHandler, IInteractionObject { public static enum HoneyCombExpect { @@ -32,12 +36,26 @@ public static enum HoneyCombExpect private static final int[] honeyCombSlotIds = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}; private DeviceBeeBox beeBox = new DeviceBeeBox(this); + @Override + public String getGuiID() + { + return "grcbees:bee_box"; + } + + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) + { + return new ContainerBeeBox(playerInventory, this); + } + @Override public void onInventoryChanged(IInventory inv, int index) { super.onInventoryChanged(inv, index); if (index > 0) - markForBlockUpdate(); + { + markDirtyAndUpdate(); + } } @Override @@ -47,7 +65,7 @@ public String getDefaultInventoryName() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 28); } @@ -130,7 +148,7 @@ public int countHoney() public int countEmptyCombs() { - return countCombsOfType(HoneyCombExpect.ANY); + return countCombsOfType(HoneyCombExpect.EMPTY); } //counts both empty and filled honeycombs @@ -175,7 +193,7 @@ public ItemStack getBeeStack() private void setBeeStack(ItemStack itemstack) { setInventorySlotContents(ContainerBeeBox.SlotId.BEE, itemstack); - markForInventoryUpdate(); + markDirtyAndUpdate(); } public void spawnBee() @@ -183,11 +201,16 @@ public void spawnBee() final ItemStack beestack = getBeeStack(); if (beestack == null) { + // Put a bee in the slot if we have none currently setBeeStack(GrowthCraftBees.items.bee.asStack()); } else { - setBeeStack(ItemUtils.increaseStack(beestack)); + // Ensure that the item in the slot IS a bee, and prevent duplication + if (BeesRegistry.instance().isItemBee(beestack)) + { + setBeeStack(ItemUtils.increaseStack(beestack)); + } } } @@ -200,7 +223,7 @@ public void spawnHoneyCombs(int n) if (stack == null) { setInventorySlotContents(i, GrowthCraftBees.items.honeyCombEmpty.asStack()); - markForInventoryUpdate(); + markDirtyAndUpdate(); n--; } } @@ -228,8 +251,7 @@ public boolean decreaseHoney(int count) } if (shouldMark) { - markForInventoryUpdate(); - markForBlockUpdate(); + markDirtyAndUpdate(); return true; } return false; @@ -255,8 +277,7 @@ public boolean fillHoneyCombs(int count) } if (shouldMark) { - markForInventoryUpdate(); - markForBlockUpdate(); + markDirtyAndUpdate(); return true; } return false; @@ -267,13 +288,9 @@ public void fillHoneyComb() fillHoneyCombs(1); } - /************ - * NBT - ************/ - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_BeeBox(NBTTagCompound nbt) { - super.readFromNBT(nbt); beeBox.readFromNBT(nbt, "bee_box"); if (nbt.hasKey("time")) { @@ -281,10 +298,9 @@ public void readFromNBT(NBTTagCompound nbt) } } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_BeeBox(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("BeeBox.version", beeBoxVersion); beeBox.writeToNBT(nbt, "bee_box"); } @@ -324,8 +340,9 @@ public boolean canExtractItem(int index, ItemStack stack, int side) } @Override - public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) + public boolean tryPlaceItem(IItemHandler.Action action, EntityPlayer player, ItemStack stack) { + if (IItemHandler.Action.RIGHT != action) return false; if (stack != null) { final Item item = stack.getItem(); @@ -355,7 +372,7 @@ else if (stack.getItemDamage() == EnumDye.MAGENTA.meta) setTime(time); worldObj.playAuxSFX(AuxFX.BONEMEAL, xCoord, yCoord, zCoord, 0); ItemUtils.consumeStackOnPlayer(stack, player); - markForBlockUpdate(); + markDirtyAndUpdate(); } return true; } @@ -392,7 +409,7 @@ else if (item == Items.bucket) } @Override - public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) + public boolean tryTakeItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { return false; } diff --git a/src/java/growthcraft/bees/common/tileentity/device/DeviceBeeBox.java b/src/java/growthcraft/bees/common/tileentity/device/DeviceBeeBox.java index dde1a4b98..6b52cc608 100644 --- a/src/java/growthcraft/bees/common/tileentity/device/DeviceBeeBox.java +++ b/src/java/growthcraft/bees/common/tileentity/device/DeviceBeeBox.java @@ -41,6 +41,7 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class DeviceBeeBox extends DeviceBase @@ -204,6 +205,18 @@ public void update() if (bonusTime > 0) bonusTime--; } + // Honey Comb bias, if the value is less than 0, it means there are more empty combs than + // filled, and that the device should focus on filling these combs before creating new ones + // Otherwise if the value is greater than or equal to zero, the device should focus on creating + // more empty honey combs + protected int honeyCombBias() + { + final TileEntityBeeBox te = getParentTile(); + final int empty = te.countEmptyCombs(); + final int filled = te.countHoney(); + return filled - empty; + } + @SuppressWarnings({"rawtypes", "unchecked"}) public void updateTick() { @@ -216,51 +229,50 @@ public void updateTick() float f = getGrowthRate(); - if (te.countCombs() < 27) + if (!te.hasMaxBees()) { - if (te.hasMaxBees()) + if (random.nextInt((int)(beeSpawnRate / f) + 1) == 0) { - if (random.nextInt((int)(honeyCombSpawnRate / f) + 1) == 0) - { - te.spawnHoneyComb(); - } + te.spawnBee(); } - else + } + + final int maxCombs = te.getHoneyCombMax(); + final int curCombs = te.countCombs(); + if (te.countHoney() < maxCombs) + { + final int bias = honeyCombBias(); + // If the bias is less than 0, then we should focus on filling with honey + boolean shouldFill = bias < 0; + if (bias != 0 && curCombs < maxCombs) { - if (random.nextInt(5) == 0) + // abs the bias, and then clamp it to a range of 6 + final int biasSpawn = Math.min(MathHelper.abs_int(bias), 6); + // if the biasSpawn isn't invalid + if (biasSpawn > 0) { - if (random.nextInt((int)(beeSpawnRate / f) + 1) == 0) + // the higher the bias, the less likely the operation will flip + if (random.nextInt(biasSpawn) == 0) { - te.spawnBee(); - } - } - else - { - if (random.nextInt((int)(honeyCombSpawnRate / f) + 1) == 0) - { - te.spawnHoneyComb(); + // flip the operation + shouldFill = !shouldFill; } } } - } - else - { - if (random.nextInt((int)(honeySpawnRate / f) + 1) == 0) + if (shouldFill) { - if (te.hasMaxBees()) + // try to fill a honey comb + if (random.nextInt((int)(honeySpawnRate / f) + 1) == 0) { te.fillHoneyComb(); } - else + } + else + { + // try to spawn a honey comb + if (random.nextInt((int)(honeyCombSpawnRate / f) + 1) == 0) { - if (random.nextInt(5) == 0) - { - te.spawnBee(); - } - else - { - te.fillHoneyComb(); - } + te.spawnHoneyComb(); } } } diff --git a/src/java/growthcraft/bees/common/village/ComponentVillageApiarist.java b/src/java/growthcraft/bees/common/village/ComponentVillageApiarist.java index 89a757a45..ec3375f1a 100644 --- a/src/java/growthcraft/bees/common/village/ComponentVillageApiarist.java +++ b/src/java/growthcraft/bees/common/village/ComponentVillageApiarist.java @@ -191,7 +191,7 @@ public class ComponentVillageApiarist extends StructureVillagePieces.Village imp new WeightedRandomChestContent(GrowthCraftBees.items.honeyCombEmpty.asStack(), 1, 3, 5), new WeightedRandomChestContent(GrowthCraftBees.items.honeyCombFilled.asStack(), 1, 3, 5), new WeightedRandomChestContent(GrowthCraftBees.items.honeyJar.asStack(), 1, 1, 10), - new WeightedRandomChestContent(GrowthCraftBees.beeBox.asStack(), 1, 2, 5) + new WeightedRandomChestContent(GrowthCraftBees.blocks.beeBox.asStack(), 1, 2, 5) }; // DO NOT REMOVE @@ -283,8 +283,8 @@ public boolean addComponentParts(World world, Random random, StructureBoundingBo map.put('Y', new BlockEntry(Blocks.planks, 2)); map.put('B', new BlockEntry(Blocks.planks, 1)); - map.put('H', new BlockEntry(GrowthCraftBees.beeHive.getBlock(), this.getMetadataWithOffset(GrowthCraftBees.beeHive.getBlock(), 3))); - map.put('+', new BlockEntry(GrowthCraftBees.beeBox.getBlock(), this.getMetadataWithOffset(GrowthCraftBees.beeBox.getBlock(), random.nextInt(6)))); + map.put('H', new BlockEntry(GrowthCraftBees.blocks.beeHive.getBlock(), this.getMetadataWithOffset(GrowthCraftBees.blocks.beeHive.getBlock(), 3))); + map.put('+', new BlockEntry(GrowthCraftBees.blocks.beeBox.getBlock(), this.getMetadataWithOffset(GrowthCraftBees.blocks.beeBox.getBlock(), random.nextInt(6)))); SchemaToVillage.drawSchema(this, world, random, box, apiaristExteriorSchema, map, 0, 0, 0); diff --git a/src/java/growthcraft/bees/common/world/WorldGenBeeHive.java b/src/java/growthcraft/bees/common/world/WorldGenBeeHive.java index 068869335..db413ea22 100644 --- a/src/java/growthcraft/bees/common/world/WorldGenBeeHive.java +++ b/src/java/growthcraft/bees/common/world/WorldGenBeeHive.java @@ -22,7 +22,7 @@ public boolean generate(World world, Random random, int x, int y, int z) final int j = y + random.nextInt(4) - random.nextInt(4); final int k = z + random.nextInt(8) - random.nextInt(8); - final BlockBeeHive beeHive = (BlockBeeHive)GrowthCraftBees.beeHive.getBlock(); + final BlockBeeHive beeHive = (BlockBeeHive)GrowthCraftBees.blocks.beeHive.getBlock(); if (world.isAirBlock(i, j, k) && beeHive.canBlockStay(world, i, j, k)) { // System.out.println(x + " " + y + " " + z); diff --git a/src/java/growthcraft/bees/init/GrcBeesBlocks.java b/src/java/growthcraft/bees/init/GrcBeesBlocks.java new file mode 100644 index 000000000..8537ea4e5 --- /dev/null +++ b/src/java/growthcraft/bees/init/GrcBeesBlocks.java @@ -0,0 +1,62 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.bees.init; + +import java.util.List; + +import growthcraft.bees.common.block.BlockBeeBox; +import growthcraft.bees.common.block.BlockBeeHive; +import growthcraft.bees.common.item.ItemBlockBeeBox; +import growthcraft.core.common.definition.BlockDefinition; +import growthcraft.core.common.definition.BlockTypeDefinition; +import growthcraft.core.common.GrcModuleBlocks; + +public class GrcBeesBlocks extends GrcModuleBlocks +{ + public BlockTypeDefinition beeBox; + public BlockTypeDefinition beeBoxBamboo; + public BlockTypeDefinition beeBoxNatura; + public BlockTypeDefinition beeBoxBiomesOPlenty; + public BlockTypeDefinition beeBoxBotania; + public BlockTypeDefinition beeBoxNether; + public BlockTypeDefinition beeBoxThaumcraft; + public List> beeBoxesForestry; + public List> beeBoxesForestryFireproof; + public BlockDefinition beeHive; + + @Override + public void preInit() + { + this.beeBox = newTypedDefinition(new BlockBeeBox()); + beeBox.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); + this.beeHive = newDefinition(new BlockBeeHive()); + } + + @Override + public void register() + { + beeBox.register("grc.beeBox", ItemBlockBeeBox.class); + beeHive.register("grc.beeHive"); + } +} diff --git a/src/java/growthcraft/bees/init/GrcBeesItems.java b/src/java/growthcraft/bees/init/GrcBeesItems.java index eb7787ef1..78ad67779 100644 --- a/src/java/growthcraft/bees/init/GrcBeesItems.java +++ b/src/java/growthcraft/bees/init/GrcBeesItems.java @@ -30,11 +30,11 @@ import growthcraft.bees.common.item.ItemHoneyCombFilled; import growthcraft.bees.common.item.ItemHoneyJar; import growthcraft.core.common.definition.ItemDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleItems; import net.minecraftforge.oredict.OreDictionary; -public class GrcBeesItems extends GrcModuleBase +public class GrcBeesItems extends GrcModuleItems { public ItemDefinition honeyCombEmpty; public ItemDefinition honeyCombFilled; @@ -45,11 +45,11 @@ public class GrcBeesItems extends GrcModuleBase @Override public void preInit() { - this.honeyCombEmpty = new ItemDefinition(new ItemHoneyCombEmpty()); - this.honeyCombFilled = new ItemDefinition(new ItemHoneyCombFilled()); - this.honeyJar = new ItemDefinition(new ItemHoneyJar()); - this.bee = new ItemDefinition(new ItemBee()); - this.beesWax = new ItemDefinition(new ItemBeesWax()); + this.honeyCombEmpty = newDefinition(new ItemHoneyCombEmpty()); + this.honeyCombFilled = newDefinition(new ItemHoneyCombFilled()); + this.honeyJar = newDefinition(new ItemHoneyJar()); + this.bee = newDefinition(new ItemBee()); + this.beesWax = newDefinition(new ItemBeesWax()); } @Override diff --git a/src/java/growthcraft/bees/init/GrcBeesRecipes.java b/src/java/growthcraft/bees/init/GrcBeesRecipes.java index d3a7b9ae6..a41784095 100644 --- a/src/java/growthcraft/bees/init/GrcBeesRecipes.java +++ b/src/java/growthcraft/bees/init/GrcBeesRecipes.java @@ -32,19 +32,21 @@ import growthcraft.api.core.item.OreItemStacks; import growthcraft.api.core.item.recipes.ShapelessMultiRecipe; import growthcraft.api.core.util.TickUtils; -import growthcraft.bees.GrowthCraftBees; import growthcraft.bees.common.item.EnumBeesWax; +import growthcraft.bees.GrowthCraftBees; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.cellar.util.BoozeUtils; -import growthcraft.core.GrowthCraftCore; import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.GrowthCraftCore; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.ShapelessOreRecipe; -import cpw.mods.fml.common.registry.GameRegistry; public class GrcBeesRecipes extends GrcModuleBase { @@ -140,11 +142,108 @@ public void register() public void postInit() { final ItemStack meadBucket = GrowthCraftBees.fluids.honeyMeadBuckets[0].asStack(); + final ItemStack meadBottle = GrowthCraftBees.fluids.honeyMeadBottle.asStack(); + final int bottleCapacity = GrowthCraftCore.getConfig().bottleCapacity; + + // Tagged Fluid compat + /// Buckets + GameRegistry.addRecipe(new ShapelessMultiRecipe( + meadBucket, + Items.bucket, + new TaggedFluidStacks(1000, "honey"), + new FluidStack(FluidRegistry.WATER, 1000))); GameRegistry.addRecipe(new ShapelessMultiRecipe( - meadBucket, - Items.bucket, - new TaggedFluidStacks(1000, "honey"), - new FluidStack(FluidRegistry.WATER, 1000))); + GrowthCraftBees.fluids.honeyMeadBottle.asStack(3), + Items.glass_bottle, + Items.glass_bottle, + Items.glass_bottle, + new TaggedFluidStacks(1000, "honey"), + new FluidStack(FluidRegistry.WATER, 1000))); + + /// Bottles + GameRegistry.addRecipe(new ShapelessMultiRecipe( + meadBottle, + Items.glass_bottle, + new TaggedFluidStacks(bottleCapacity, "honey"), + new FluidStack(FluidRegistry.WATER, bottleCapacity))); + + // Ore Dictionary compat + /// Buckets + GameRegistry.addRecipe(new ShapelessMultiRecipe( + meadBucket, + Items.bucket, + new OreItemStacks("bucketHoney"), + new FluidStack(FluidRegistry.WATER, 1000))); + + GameRegistry.addRecipe(new ShapelessMultiRecipe( + meadBottle, + Items.glass_bottle, + new OreItemStacks("bottleHoney"), + new FluidStack(FluidRegistry.WATER, bottleCapacity))); + + // Transfer recipes + /// To Honey Jar from `bucketHoney` + GameRegistry.addRecipe(new ShapelessMultiRecipe( + GrowthCraftBees.items.honeyJar.asStack(), + Blocks.flower_pot, + new TaggedFluidStacks(1000, "honey") + )); + + GameRegistry.addRecipe(new ShapelessOreRecipe( + GrowthCraftBees.items.honeyJar.asStack(), + Blocks.flower_pot, + "bucketHoney" + )); + + /// To Honey Bucket from `bucketHoney` + GameRegistry.addRecipe(new ShapelessMultiRecipe( + GrowthCraftBees.fluids.honey.asBucketItemStack(), + Items.bucket, + new TaggedFluidStacks(1000, "honey") + )); + + GameRegistry.addRecipe(new ShapelessOreRecipe( + GrowthCraftBees.fluids.honey.asBucketItemStack(), + "bucketHoney", + Items.bucket + )); + + /// To Honey Bottle from `bucketHoney` + GameRegistry.addRecipe(new ShapelessMultiRecipe( + GrowthCraftBees.fluids.honey.asBottleItemStack(3), + Items.glass_bottle, + Items.glass_bottle, + Items.glass_bottle, + new TaggedFluidStacks(1000, "honey") + )); + + GameRegistry.addRecipe(new ShapelessOreRecipe( + GrowthCraftBees.fluids.honey.asBottleItemStack(3), + Items.glass_bottle, + Items.glass_bottle, + Items.glass_bottle, + "bucketHoney" + )); + + /// To Honey Bottle from 3 `bottleHoney` + GameRegistry.addRecipe(new ShapelessOreRecipe( + GrowthCraftBees.fluids.honey.asBottleItemStack(3), + Items.glass_bottle, + Items.glass_bottle, + Items.glass_bottle, + "bottleHoney", + "bottleHoney", + "bottleHoney" + )); + + /// To Honey Bucket from 3 `bottleHoney` + GameRegistry.addRecipe(new ShapelessOreRecipe( + GrowthCraftBees.fluids.honey.asBucketItemStack(), + Items.bucket, + "bottleHoney", + "bottleHoney", + "bottleHoney" + )); } } diff --git a/src/java/growthcraft/bees/integration/BoPModule.java b/src/java/growthcraft/bees/integration/BoPModule.java index 06f2f3335..fe22ea9c7 100644 --- a/src/java/growthcraft/bees/integration/BoPModule.java +++ b/src/java/growthcraft/bees/integration/BoPModule.java @@ -23,11 +23,9 @@ */ package growthcraft.bees.integration; -import growthcraft.bees.common.block.BlockBeeBox; import growthcraft.bees.common.block.BlockBeeBoxBiomesOPlenty; import growthcraft.bees.common.item.ItemBlockBeeBox; import growthcraft.bees.GrowthCraftBees; -import growthcraft.core.common.definition.BlockTypeDefinition; import growthcraft.core.integration.bop.BopPlatform; import growthcraft.core.integration.bop.EnumBopWoodType; import growthcraft.core.integration.ModIntegrationBase; @@ -45,13 +43,13 @@ public BoPModule() @Override public void doPreInit() { - GrowthCraftBees.beeBoxBiomesOPlenty = new BlockTypeDefinition(new BlockBeeBoxBiomesOPlenty()); + GrowthCraftBees.blocks.beeBoxBiomesOPlenty = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxBiomesOPlenty()); } @Override public void doRegister() { - GrowthCraftBees.beeBoxBiomesOPlenty.register("grc.BeeBox.BiomesOPlenty", ItemBlockBeeBox.class); + GrowthCraftBees.blocks.beeBoxBiomesOPlenty.register("grc.BeeBox.BiomesOPlenty", ItemBlockBeeBox.class); } @Override @@ -62,7 +60,7 @@ protected void doLateRegister() final ItemStack planks = type.asPlanksItemStack(); if (planks != null) { - GameRegistry.addShapedRecipe(GrowthCraftBees.beeBoxBiomesOPlenty.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); + GameRegistry.addShapedRecipe(GrowthCraftBees.blocks.beeBoxBiomesOPlenty.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); } } } diff --git a/src/java/growthcraft/bees/integration/BotaniaModule.java b/src/java/growthcraft/bees/integration/BotaniaModule.java index 6cc1f9b79..ca8ddc2ea 100644 --- a/src/java/growthcraft/bees/integration/BotaniaModule.java +++ b/src/java/growthcraft/bees/integration/BotaniaModule.java @@ -23,11 +23,9 @@ */ package growthcraft.bees.integration; -import growthcraft.bees.common.block.BlockBeeBox; import growthcraft.bees.common.block.BlockBeeBoxBotania; import growthcraft.bees.common.item.ItemBlockBeeBox; import growthcraft.bees.GrowthCraftBees; -import growthcraft.core.common.definition.BlockTypeDefinition; import growthcraft.core.integration.botania.BotaniaPlatform; import growthcraft.core.integration.botania.EnumBotaniaWoodType; import growthcraft.core.integration.ModIntegrationBase; @@ -45,13 +43,13 @@ public BotaniaModule() @Override public void doPreInit() { - GrowthCraftBees.beeBoxBotania = new BlockTypeDefinition(new BlockBeeBoxBotania()); + GrowthCraftBees.blocks.beeBoxBotania = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxBotania()); } @Override public void doRegister() { - GrowthCraftBees.beeBoxBotania.register("grc.BeeBox.Botania", ItemBlockBeeBox.class); + GrowthCraftBees.blocks.beeBoxBotania.register("grc.BeeBox.Botania", ItemBlockBeeBox.class); } @Override @@ -62,7 +60,7 @@ protected void doLateRegister() final ItemStack planks = type.asPlanksItemStack(); if (planks != null) { - GameRegistry.addShapedRecipe(GrowthCraftBees.beeBoxBotania.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); + GameRegistry.addShapedRecipe(GrowthCraftBees.blocks.beeBoxBotania.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); } } } diff --git a/src/java/growthcraft/bees/integration/ForestryModule.java b/src/java/growthcraft/bees/integration/ForestryModule.java index 99643f38e..8dfd1ce80 100644 --- a/src/java/growthcraft/bees/integration/ForestryModule.java +++ b/src/java/growthcraft/bees/integration/ForestryModule.java @@ -64,19 +64,19 @@ private void maybeAddBee(Item item) protected void doPreInit() { final int beeboxCount = EnumBeeBoxForestry.VALUES.length; - GrowthCraftBees.beeBoxesForestry = new ArrayList>(); - GrowthCraftBees.beeBoxesForestryFireproof = new ArrayList>(); + GrowthCraftBees.blocks.beeBoxesForestry = new ArrayList>(); + GrowthCraftBees.blocks.beeBoxesForestryFireproof = new ArrayList>(); int i = 0; int offset = 0; for (EnumBeeBoxForestry[] row : EnumBeeBoxForestry.ROWS) { - final BlockTypeDefinition beeBox = new BlockTypeDefinition(new BlockBeeBoxForestry(row, offset, i, false)); - final BlockTypeDefinition beeBoxFP = new BlockTypeDefinition(new BlockBeeBoxForestry(row, offset, i, true)); + final BlockTypeDefinition beeBox = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxForestry(row, offset, i, false)); + final BlockTypeDefinition beeBoxFP = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxForestry(row, offset, i, true)); beeBox.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); beeBoxFP.getBlock().setHarvestLevel("axe", 0); - GrowthCraftBees.beeBoxesForestry.add(beeBox); - GrowthCraftBees.beeBoxesForestryFireproof.add(beeBoxFP); + GrowthCraftBees.blocks.beeBoxesForestry.add(beeBox); + GrowthCraftBees.blocks.beeBoxesForestryFireproof.add(beeBoxFP); beeBox.register(String.format("grc.BeeBox.Forestry.%d.%s", i, "Normal"), ItemBlockBeeBox.class); beeBoxFP.register(String.format("grc.BeeBox.Forestry.%d.%s", i, "Fireproof"), ItemBlockBeeBox.class); i++; @@ -100,7 +100,7 @@ protected void doLateRegister() if (en == null) continue; { - final BlockTypeDefinition beeBox = GrowthCraftBees.beeBoxesForestry.get(en.row); + final BlockTypeDefinition beeBox = GrowthCraftBees.blocks.beeBoxesForestry.get(en.row); if (beeBox != null) { final ItemStack planks = en.getForestryPlanksStack(); @@ -111,7 +111,7 @@ protected void doLateRegister() } } { - final BlockTypeDefinition beeBoxFP = GrowthCraftBees.beeBoxesForestryFireproof.get(en.row); + final BlockTypeDefinition beeBoxFP = GrowthCraftBees.blocks.beeBoxesForestryFireproof.get(en.row); if (beeBoxFP != null) { final ItemStack planks = en.getForestryFireproofPlanksStack(); diff --git a/src/java/growthcraft/bees/integration/GrcBambooModule.java b/src/java/growthcraft/bees/integration/GrcBambooModule.java index 175e00b12..971217dc1 100644 --- a/src/java/growthcraft/bees/integration/GrcBambooModule.java +++ b/src/java/growthcraft/bees/integration/GrcBambooModule.java @@ -25,10 +25,8 @@ import growthcraft.bees.GrowthCraftBees; import growthcraft.core.integration.ModIntegrationBase; -import growthcraft.bees.common.block.BlockBeeBox; import growthcraft.bees.common.block.BlockBeeBoxBamboo; import growthcraft.bees.common.item.ItemBlockBeeBox; -import growthcraft.core.common.definition.BlockTypeDefinition; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraftforge.oredict.ShapedOreRecipe; @@ -43,20 +41,26 @@ public GrcBambooModule() @Override protected void doPreInit() { - GrowthCraftBees.beeBoxBamboo = new BlockTypeDefinition(new BlockBeeBoxBamboo()); - GrowthCraftBees.beeBoxBamboo.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); + GrowthCraftBees.blocks.beeBoxBamboo = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxBamboo()); + GrowthCraftBees.blocks.beeBoxBamboo.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); } @Override protected void doRegister() { - GameRegistry.registerBlock(GrowthCraftBees.beeBoxBamboo.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Bamboo"); + if (GrowthCraftBees.blocks.beeBoxBamboo != null) + { + GameRegistry.registerBlock(GrowthCraftBees.blocks.beeBoxBamboo.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Bamboo"); + } } @Override protected void doLateRegister() { // Bamboo - GameRegistry.addRecipe(new ShapedOreRecipe(GrowthCraftBees.beeBoxBamboo.asStack(), " A ", "A A", "AAA", 'A', "plankBamboo")); + if (GrowthCraftBees.blocks.beeBoxBamboo != null) + { + GameRegistry.addRecipe(new ShapedOreRecipe(GrowthCraftBees.blocks.beeBoxBamboo.asStack(), " A ", "A A", "AAA", 'A', "plankBamboo")); + } } } diff --git a/src/java/growthcraft/bees/integration/GrcNetherModule.java b/src/java/growthcraft/bees/integration/GrcNetherModule.java index c14e14ad4..90fd7ea3c 100644 --- a/src/java/growthcraft/bees/integration/GrcNetherModule.java +++ b/src/java/growthcraft/bees/integration/GrcNetherModule.java @@ -23,11 +23,9 @@ */ package growthcraft.bees.integration; -import growthcraft.bees.common.block.BlockBeeBox; import growthcraft.bees.common.block.BlockBeeBoxNether; import growthcraft.bees.common.item.ItemBlockBeeBox; import growthcraft.bees.GrowthCraftBees; -import growthcraft.core.common.definition.BlockTypeDefinition; import growthcraft.core.integration.ModIntegrationBase; import cpw.mods.fml.common.registry.GameRegistry; @@ -43,26 +41,26 @@ public GrcNetherModule() @Override protected void doPreInit() { - GrowthCraftBees.beeBoxNether = new BlockTypeDefinition(new BlockBeeBoxNether()); - GrowthCraftBees.beeBoxNether.getBlock().setHarvestLevel("axe", 0); + GrowthCraftBees.blocks.beeBoxNether = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxNether()); + GrowthCraftBees.blocks.beeBoxNether.getBlock().setHarvestLevel("axe", 0); } @Override protected void doRegister() { - if (GrowthCraftBees.beeBoxNether != null) + if (GrowthCraftBees.blocks.beeBoxNether != null) { - GameRegistry.registerBlock(GrowthCraftBees.beeBoxNether.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Nether"); + GameRegistry.registerBlock(GrowthCraftBees.blocks.beeBoxNether.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Nether"); } } @Override protected void doLateRegister() { - if (GrowthCraftBees.beeBoxNether != null) + if (GrowthCraftBees.blocks.beeBoxNether != null) { // plankMaliceWood is registered by the Growthcraft|Nether module, and is a non-flammable plank - GameRegistry.addRecipe(new ShapedOreRecipe(GrowthCraftBees.beeBoxNether.asStack(), " A ", "A A", "AAA", 'A', "plankMaliceWood")); + GameRegistry.addRecipe(new ShapedOreRecipe(GrowthCraftBees.blocks.beeBoxNether.asStack(), " A ", "A A", "AAA", 'A', "plankMaliceWood")); } } } diff --git a/src/java/growthcraft/bees/integration/NaturaModule.java b/src/java/growthcraft/bees/integration/NaturaModule.java index 81128596b..3d4096e71 100644 --- a/src/java/growthcraft/bees/integration/NaturaModule.java +++ b/src/java/growthcraft/bees/integration/NaturaModule.java @@ -23,11 +23,9 @@ */ package growthcraft.bees.integration; -import growthcraft.bees.common.block.BlockBeeBox; import growthcraft.bees.common.block.BlockBeeBoxNatura; import growthcraft.bees.common.item.ItemBlockBeeBox; import growthcraft.bees.GrowthCraftBees; -import growthcraft.core.common.definition.BlockTypeDefinition; import growthcraft.core.integration.natura.NaturaPlatform; import growthcraft.core.integration.natura.EnumNaturaWoodType; import growthcraft.core.integration.ModIntegrationBase; @@ -45,13 +43,13 @@ public NaturaModule() @Override public void doPreInit() { - GrowthCraftBees.beeBoxNatura = new BlockTypeDefinition(new BlockBeeBoxNatura()); + GrowthCraftBees.blocks.beeBoxNatura = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxNatura()); } @Override public void doRegister() { - GrowthCraftBees.beeBoxNatura.register("grc.BeeBox.Natura", ItemBlockBeeBox.class); + GrowthCraftBees.blocks.beeBoxNatura.register("grc.BeeBox.Natura", ItemBlockBeeBox.class); } @Override @@ -62,7 +60,7 @@ protected void doLateRegister() final ItemStack planks = type.asPlanksItemStack(); if (planks != null) { - GameRegistry.addShapedRecipe(GrowthCraftBees.beeBoxNatura.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); + GameRegistry.addShapedRecipe(GrowthCraftBees.blocks.beeBoxNatura.asStack(1, type.meta), " A ", "A A", "AAA", 'A', planks); } } } diff --git a/src/java/growthcraft/bees/integration/ThaumcraftModule.java b/src/java/growthcraft/bees/integration/ThaumcraftModule.java index 678aae276..f935a4a70 100644 --- a/src/java/growthcraft/bees/integration/ThaumcraftModule.java +++ b/src/java/growthcraft/bees/integration/ThaumcraftModule.java @@ -53,23 +53,23 @@ public ThaumcraftModule() @Override protected void doPreInit() { - GrowthCraftBees.beeBoxThaumcraft = new BlockTypeDefinition(new BlockBeeBoxThaumcraft()); - GrowthCraftBees.beeBoxThaumcraft.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); + GrowthCraftBees.blocks.beeBoxThaumcraft = GrowthCraftBees.blocks.newTypedDefinition(new BlockBeeBoxThaumcraft()); + GrowthCraftBees.blocks.beeBoxThaumcraft.getBlock().setFlammability(20).setFireSpreadSpeed(5).setHarvestLevel("axe", 0); } @Override protected void doRegister() { - if (GrowthCraftBees.beeBoxThaumcraft != null) + if (GrowthCraftBees.blocks.beeBoxThaumcraft != null) { - GameRegistry.registerBlock(GrowthCraftBees.beeBoxThaumcraft.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Thaumcraft"); + GameRegistry.registerBlock(GrowthCraftBees.blocks.beeBoxThaumcraft.getBlock(), ItemBlockBeeBox.class, "grc.BeeBox.Thaumcraft"); } } @Override protected void doLateRegister() { - if (GrowthCraftBees.beeBoxThaumcraft != null) + if (GrowthCraftBees.blocks.beeBoxThaumcraft != null) { final Block blockWoodenDevice = GameRegistry.findBlock(modID, "blockWoodenDevice"); if (blockWoodenDevice != null) @@ -92,8 +92,8 @@ protected void integrate() ThaumcraftApi.registerObjectTag(GrowthCraftBees.items.honeyCombFilled.asStack(), new AspectList().add(Aspect.ORDER, 1).add(Aspect.SLIME, 1).add(Aspect.GREED, 1).add(Aspect.HUNGER, 1)); ThaumcraftApi.registerObjectTag(GrowthCraftBees.items.honeyJar.asStack(), new AspectList().add(Aspect.SLIME, 1).add(Aspect.EARTH, 1).add(Aspect.FIRE, 1).add(Aspect.VOID, 1).add(Aspect.GREED, 3).add(Aspect.HUNGER, 1)); ThaumcraftApi.registerObjectTag(GrowthCraftBees.items.bee.asStack(), new AspectList().add(Aspect.BEAST, 1).add(Aspect.AIR, 1).add(Aspect.FLIGHT, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeHive.asStack(), new AspectList().add(Aspect.SLIME, 1).add(Aspect.BEAST, 1).add(Aspect.ORDER, 1).add(Aspect.VOID, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBox.asStack(), new int[]{0,1,2,3,4,5}, new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeHive.asStack(), new AspectList().add(Aspect.SLIME, 1).add(Aspect.BEAST, 1).add(Aspect.ORDER, 1).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBox.asStack(), new int[]{0,1,2,3,4,5}, new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); { final AspectList[] common = new AspectList[] @@ -143,33 +143,33 @@ protected void integrate() } } - if (GrowthCraftBees.beeBoxNether != null) + if (GrowthCraftBees.blocks.beeBoxNether != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxNether.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.ENTROPY, 1).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxNether.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.ENTROPY, 1).add(Aspect.VOID, 1)); } - if (GrowthCraftBees.beeBoxBamboo != null) + if (GrowthCraftBees.blocks.beeBoxBamboo != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxBamboo.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxBamboo.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); } - if (GrowthCraftBees.beeBoxThaumcraft != null) + if (GrowthCraftBees.blocks.beeBoxThaumcraft != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxThaumcraft.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1).add(Aspect.MAGIC, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxThaumcraft.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1).add(Aspect.MAGIC, 1)); } - if (GrowthCraftBees.beeBoxNatura != null) + if (GrowthCraftBees.blocks.beeBoxNatura != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxNatura.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxNatura.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); } - if (GrowthCraftBees.beeBoxBiomesOPlenty != null) + if (GrowthCraftBees.blocks.beeBoxBiomesOPlenty != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxBiomesOPlenty.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxBiomesOPlenty.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1)); } - if (GrowthCraftBees.beeBoxBotania != null) + if (GrowthCraftBees.blocks.beeBoxBotania != null) { - ThaumcraftApi.registerObjectTag(GrowthCraftBees.beeBoxBotania.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1).add(Aspect.MAGIC, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftBees.blocks.beeBoxBotania.asStack(1, ItemKey.WILDCARD_VALUE), new AspectList().add(Aspect.TREE, 4).add(Aspect.VOID, 1).add(Aspect.MAGIC, 1)); } - if (GrowthCraftBees.beeBoxesForestry != null) + if (GrowthCraftBees.blocks.beeBoxesForestry != null) { - for (BlockTypeDefinition bdef : GrowthCraftBees.beeBoxesForestry) + for (BlockTypeDefinition bdef : GrowthCraftBees.blocks.beeBoxesForestry) { if (bdef != null) { @@ -177,9 +177,9 @@ protected void integrate() } } } - if (GrowthCraftBees.beeBoxesForestryFireproof != null) + if (GrowthCraftBees.blocks.beeBoxesForestryFireproof != null) { - for (BlockTypeDefinition bdef : GrowthCraftBees.beeBoxesForestryFireproof) + for (BlockTypeDefinition bdef : GrowthCraftBees.blocks.beeBoxesForestryFireproof) { if (bdef != null) { diff --git a/src/java/growthcraft/cellar/GrcCellarConfig.java b/src/java/growthcraft/cellar/GrcCellarConfig.java index 3b3a45201..39009bb7f 100644 --- a/src/java/growthcraft/cellar/GrcCellarConfig.java +++ b/src/java/growthcraft/cellar/GrcCellarConfig.java @@ -7,6 +7,9 @@ public class GrcCellarConfig extends ConfigBase @ConfigOption(catergory="Potions", name="Potion Tipsy ID") public int potionTipsyID = 50; + @ConfigOption(catergory="Villager", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Villager", name="Brewer ID") public int villagerBrewerID = 6677; diff --git a/src/java/growthcraft/cellar/GrowthCraftCellar.java b/src/java/growthcraft/cellar/GrowthCraftCellar.java index bc537e58b..ad19e42fe 100644 --- a/src/java/growthcraft/cellar/GrowthCraftCellar.java +++ b/src/java/growthcraft/cellar/GrowthCraftCellar.java @@ -16,9 +16,7 @@ import growthcraft.cellar.common.booze.ModifierFunctionHyperExtended; import growthcraft.cellar.common.booze.ModifierFunctionPotent; import growthcraft.cellar.common.CommonProxy; -import growthcraft.cellar.common.item.ItemChievDummy; -import growthcraft.cellar.common.item.ItemWaterBag; -import growthcraft.cellar.common.item.ItemYeast; +import growthcraft.cellar.common.item.EnumYeast; import growthcraft.cellar.common.potion.PotionCellar; import growthcraft.cellar.common.tileentity.TileEntityBrewKettle; import growthcraft.cellar.common.tileentity.TileEntityCultureJar; @@ -31,15 +29,14 @@ import growthcraft.cellar.eventhandler.EventHandlerCauldronUseItem; import growthcraft.cellar.eventhandler.EventHandlerItemCraftedEventCellar; import growthcraft.cellar.eventhandler.EventHandlerLivingUpdateEventCellar; -import growthcraft.cellar.handler.GuiHandlerCellar; import growthcraft.cellar.init.GrcCellarBlocks; +import growthcraft.cellar.init.GrcCellarItems; import growthcraft.cellar.network.PacketPipeline; import growthcraft.cellar.stats.CellarAchievement; import growthcraft.cellar.stats.GrcCellarAchievements; import growthcraft.cellar.util.CellarBoozeBuilderFactory; import growthcraft.cellar.util.GrcCellarUserApis; -import growthcraft.cellar.common.item.EnumYeast; -import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.GrcGuiProvider; import growthcraft.core.integration.NEI; import growthcraft.core.util.MapGenHelper; @@ -77,30 +74,22 @@ public class GrowthCraftCellar @Instance(MOD_ID) public static GrowthCraftCellar instance; - public static GrcCellarBlocks blocks = new GrcCellarBlocks(); - public static CreativeTabs tab; - - public static ItemDefinition yeast; - public static ItemDefinition waterBag; - + public static final GrcCellarBlocks blocks = new GrcCellarBlocks(); + public static final GrcCellarItems items = new GrcCellarItems(); public static Potion potionTipsy; - // Achievments - public static ItemDefinition chievItemDummy; public static GrcCellarAchievements achievements; - // Network public static final PacketPipeline packetPipeline = new PacketPipeline(); public static CellarBoozeBuilderFactory boozeBuilderFactory; - // Events public static final EventBus CELLAR_BUS = new EventBus(); - - private ILogger logger = new GrcLogger(MOD_ID); - private GrcCellarConfig config = new GrcCellarConfig(); - private GrcCellarUserApis userApis = new GrcCellarUserApis(); - private ModuleContainer modules = new ModuleContainer(); + public static final GrcGuiProvider guiProvider = new GrcGuiProvider(new GrcLogger(MOD_ID + ":GuiProvider")); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcCellarConfig config = new GrcCellarConfig(); + private final GrcCellarUserApis userApis = new GrcCellarUserApis(); + private final ModuleContainer modules = new ModuleContainer(); public static UserHeatSourcesConfig getUserHeatSources() { @@ -118,26 +107,25 @@ public static ILogger getLogger() } @EventHandler - public void preload(FMLPreInitializationEvent event) + public void preInit(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/cellar.conf"); - - if (config.debugEnabled) - { - logger.debug("Pre-Initializing %s", MOD_ID); - CellarRegistry.instance().setLogger(logger); - } - modules.add(blocks); + modules.add(items); if (config.enableWailaIntegration) modules.add(new growthcraft.cellar.integration.Waila()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.cellar.integration.ThaumcraftModule()); //if (config.enableNEIIntegration) modules.add(new growthcraft.cellar.integration.NEIModule()); // ALWAYS set the user modules as last, this ensures that other modules are given a chance to setup defaults and such. modules.add(userApis); - - if (config.debugEnabled) modules.setLogger(logger); + modules.add(CommonProxy.instance); + if (config.debugEnabled) + { + logger.debug("Pre-Initializing %s", MOD_ID); + CellarRegistry.instance().setLogger(logger); + modules.setLogger(logger); + } modules.freeze(); userApis.getUserBrewingRecipes() @@ -161,10 +149,6 @@ public void preload(FMLPreInitializationEvent event) //==================== tab = new CreativeTabsCellar("creative_tab_grccellar"); - yeast = new ItemDefinition(new ItemYeast()); - waterBag = new ItemDefinition(new ItemWaterBag()); - chievItemDummy = new ItemDefinition(new ItemChievDummy()); - modules.preInit(); register(); } @@ -188,15 +172,8 @@ private void registerBoozeModifierFunctions() private void register() { - addDefaultHeatSources(); - //==================== - // REGISTRIES - //==================== modules.register(); - - GameRegistry.registerItem(yeast.getItem(), "grc.yeast"); - GameRegistry.registerItem(waterBag.getItem(), "grc.waterBag"); - GameRegistry.registerItem(chievItemDummy.getItem(), "grc.chievItemDummy"); + addDefaultHeatSources(); GameRegistry.registerTileEntity(TileEntityFruitPress.class, "grc.tileentity.fruitPress"); GameRegistry.registerTileEntity(TileEntityFruitPresser.class, "grc.tileentity.fruitPresser"); @@ -214,23 +191,23 @@ private void register() GameRegistry.addRecipe(new ShapedOreRecipe(blocks.fermentBarrel.asStack(), "AAA", "BBB", "AAA", 'B', "plankWood", 'A', "ingotIron")); GameRegistry.addRecipe(new ShapedOreRecipe(blocks.cultureJar.asStack(), "GAG", "G G", "GGG", 'A', "plankWood", 'G', "paneGlass")); - GameRegistry.addRecipe(new ShapedOreRecipe(waterBag.asStack(1, 16), "AAA", "ABA", "AAA", 'A', Items.leather, 'B', "materialRope")); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 0), "dyeWhite", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 1), "dyeOrange", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 2), "dyeMagenta", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 3), "dyeLightBlue", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 4), "dyeYellow", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 5), "dyeLime", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 6), "dyePink", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 7), "dyeGray", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 8), "dyeLightGray", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 9), "dyeCyan", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 10), "dyePurple", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 11), "dyeBlue", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 12), "dyeBrown", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 13), "dyeGreen", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 14), "dyeRed", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); - GameRegistry.addRecipe(new ShapelessOreRecipe(waterBag.asStack(1, 15), "dyeBlack", waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapedOreRecipe(items.waterBag.asStack(1, 16), "AAA", "ABA", "AAA", 'A', Items.leather, 'B', "materialRope")); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 0), "dyeWhite", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 1), "dyeOrange", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 2), "dyeMagenta", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 3), "dyeLightBlue", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 4), "dyeYellow", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 5), "dyeLime", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 6), "dyePink", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 7), "dyeGray", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 8), "dyeLightGray", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 9), "dyeCyan", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 10), "dyePurple", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 11), "dyeBlue", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 12), "dyeBrown", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 13), "dyeGreen", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 14), "dyeRed", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); + GameRegistry.addRecipe(new ShapelessOreRecipe(items.waterBag.asStack(1, 15), "dyeBlack", items.waterBag.asStack(1, OreDictionary.WILDCARD_VALUE))); //==================== // POTION @@ -245,7 +222,7 @@ private void register() //==================== achievements = new GrcCellarAchievements(); - NEI.hideItem(chievItemDummy.asStack()); + NEI.hideItem(items.chievItemDummy.asStack()); } private void extendPotionsArray() @@ -281,7 +258,7 @@ private void extendPotionsArray() private void registerOres() { - OreDictionary.registerOre("materialYeast", yeast.getItem()); + OreDictionary.registerOre("materialYeast", items.yeast.getItem()); OreDictionary.registerOre("yeastBrewers", EnumYeast.BREWERS.asStack()); OreDictionary.registerOre("yeastLager", EnumYeast.LAGER.asStack()); OreDictionary.registerOre("yeastBayanus", EnumYeast.BAYANUS.asStack()); @@ -298,20 +275,23 @@ private void registerYeast() CellarRegistry.instance().yeast().addYeast(EnumYeast.ORIGIN.asStack()); } + private void initVillageHandlers() + { + if (config.villagerBrewerID > 0) + { + VillagerRegistry.instance().registerVillagerId(config.villagerBrewerID); + } + VillagerRegistry.instance().registerVillageCreationHandler(new VillageHandlerCellar()); + } + @EventHandler public void load(FMLInitializationEvent event) { registerOres(); registerYeast(); - packetPipeline.initialise(); - NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerCellar()); - - VillagerRegistry.instance().registerVillagerId(config.villagerBrewerID); - VillagerRegistry.instance().registerVillageCreationHandler(new VillageHandlerCellar()); - - CommonProxy.instance.init(); - + NetworkRegistry.INSTANCE.registerGuiHandler(this, guiProvider); + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } diff --git a/src/java/growthcraft/cellar/client/ClientProxy.java b/src/java/growthcraft/cellar/client/ClientProxy.java index 33244507f..491d21ca4 100644 --- a/src/java/growthcraft/cellar/client/ClientProxy.java +++ b/src/java/growthcraft/cellar/client/ClientProxy.java @@ -1,11 +1,38 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.cellar.client; +import growthcraft.cellar.client.gui.GuiBrewKettle; +import growthcraft.cellar.client.gui.GuiCultureJar; +import growthcraft.cellar.client.gui.GuiFermentBarrel; +import growthcraft.cellar.client.gui.GuiFruitPress; +import growthcraft.cellar.client.render.item.ItemRenderCultureJar; import growthcraft.cellar.client.render.RenderBrewKettle; -import growthcraft.cellar.client.render.RenderFermentBarrel; import growthcraft.cellar.client.render.RenderCultureJar; +import growthcraft.cellar.client.render.RenderFermentBarrel; import growthcraft.cellar.client.render.RenderFruitPress; import growthcraft.cellar.client.render.RenderFruitPresser; -import growthcraft.cellar.client.render.item.ItemRenderCultureJar; import growthcraft.cellar.client.renderer.TileEntityCultureJarRenderer; import growthcraft.cellar.client.renderer.TileEntityFruitPresserRenderer; import growthcraft.cellar.client.resource.GrcCellarResources; @@ -22,7 +49,7 @@ public class ClientProxy extends CommonProxy { - public void initRenders() + protected void initRenders() { MinecraftForgeClient.registerItemRenderer(GrowthCraftCellar.blocks.cultureJar.getItem(), new ItemRenderCultureJar()); RenderingRegistry.registerBlockHandler(new RenderBrewKettle()); @@ -30,22 +57,29 @@ public void initRenders() RenderingRegistry.registerBlockHandler(new RenderFermentBarrel()); RenderingRegistry.registerBlockHandler(new RenderFruitPress()); RenderingRegistry.registerBlockHandler(new RenderFruitPresser()); - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityFruitPresser.class, new TileEntityFruitPresserRenderer()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCultureJar.class, new TileEntityCultureJarRenderer()); } - public void registerVillagerSkin() + protected void registerVillagerSkin() { - VillagerRegistry.instance().registerVillagerSkin(GrowthCraftCellar.getConfig().villagerBrewerID, - new ResourceLocation("grccellar" , "textures/entity/brewer.png")); + final int villagerID = GrowthCraftCellar.getConfig().villagerBrewerID; + if (villagerID > 0) + { + VillagerRegistry.instance().registerVillagerSkin(villagerID, new ResourceLocation("grccellar" , "textures/entity/brewer.png")); + } } + @Override public void init() { + super.init(); new GrcCellarResources(); - initRenders(); registerVillagerSkin(); + GrowthCraftCellar.guiProvider.register("grccellar:fruit_press", GuiFruitPress.class); + GrowthCraftCellar.guiProvider.register("grccellar:ferment_barrel", GuiFermentBarrel.class); + GrowthCraftCellar.guiProvider.register("grccellar:culture_jar", GuiCultureJar.class); + GrowthCraftCellar.guiProvider.register("grccellar:brew_kettle", GuiBrewKettle.class); } } diff --git a/src/java/growthcraft/cellar/common/CommonProxy.java b/src/java/growthcraft/cellar/common/CommonProxy.java index 120e6b090..a37e0be18 100644 --- a/src/java/growthcraft/cellar/common/CommonProxy.java +++ b/src/java/growthcraft/cellar/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.cellar.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.cellar.client.ClientProxy", serverSide="growthcraft.cellar.common.CommonProxy") public static CommonProxy instance; - - public void init() {} } diff --git a/src/java/growthcraft/cellar/common/block/BlockBrewKettle.java b/src/java/growthcraft/cellar/common/block/BlockBrewKettle.java index e5facec2f..54a7eb7b1 100644 --- a/src/java/growthcraft/cellar/common/block/BlockBrewKettle.java +++ b/src/java/growthcraft/cellar/common/block/BlockBrewKettle.java @@ -7,7 +7,6 @@ import growthcraft.cellar.client.render.RenderBrewKettle; import growthcraft.cellar.common.tileentity.TileEntityBrewKettle; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.cellar.util.CellarGuiType; import growthcraft.core.Utils; import cpw.mods.fml.relauncher.Side; @@ -47,7 +46,6 @@ public BlockBrewKettle() setHardness(2.0F); setBlockName("grc.brewKettle"); setCreativeTab(GrowthCraftCellar.tab); - setGuiType(CellarGuiType.BREW_KETTLE); } @Override diff --git a/src/java/growthcraft/cellar/common/block/BlockCellarContainer.java b/src/java/growthcraft/cellar/common/block/BlockCellarContainer.java index 972634ffd..2f09a614a 100644 --- a/src/java/growthcraft/cellar/common/block/BlockCellarContainer.java +++ b/src/java/growthcraft/cellar/common/block/BlockCellarContainer.java @@ -23,14 +23,13 @@ */ package growthcraft.cellar.common.block; -import javax.annotation.Nonnull; - import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.cellar.util.CellarGuiType; import growthcraft.core.common.block.GrcBlockContainer; +import growthcraft.core.common.tileentity.feature.IInteractionObject; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; /** @@ -38,25 +37,17 @@ */ public abstract class BlockCellarContainer extends GrcBlockContainer { - protected CellarGuiType guiType = CellarGuiType.NONE; - public BlockCellarContainer(Material material) { super(material); } - - protected BlockCellarContainer setGuiType(@Nonnull CellarGuiType type) - { - this.guiType = type; - return this; - } - protected boolean openGui(EntityPlayer player, World world, int x, int y, int z) { - if (guiType != CellarGuiType.NONE) + final TileEntity te = getTileEntity(world, x, y, z); + if (te instanceof IInteractionObject) { - player.openGui(GrowthCraftCellar.instance, guiType.ordinal(), world, x, y, z); + player.openGui(GrowthCraftCellar.instance, 0, world, x, y, z); return true; } return false; diff --git a/src/java/growthcraft/cellar/common/block/BlockCultureJar.java b/src/java/growthcraft/cellar/common/block/BlockCultureJar.java index ddee7a89c..3e435badb 100644 --- a/src/java/growthcraft/cellar/common/block/BlockCultureJar.java +++ b/src/java/growthcraft/cellar/common/block/BlockCultureJar.java @@ -3,7 +3,6 @@ import growthcraft.cellar.client.render.RenderCultureJar; import growthcraft.cellar.common.tileentity.TileEntityCultureJar; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.cellar.util.CellarGuiType; import growthcraft.api.core.util.BBox; import cpw.mods.fml.relauncher.Side; @@ -22,7 +21,6 @@ public BlockCultureJar() setBlockTextureName("grccellar:ferment_jar_glass"); setCreativeTab(GrowthCraftCellar.tab); setTileEntityType(TileEntityCultureJar.class); - setGuiType(CellarGuiType.FERMENT_JAR); final BBox bbox = BBox.newCube(6, 0, 6, 4, 6, 4).scale(1 / 16.0f); setBlockBounds(bbox.x0(), bbox.y0(), bbox.z0(), bbox.x1(), bbox.y1(), bbox.z1()); diff --git a/src/java/growthcraft/cellar/common/block/BlockFermentBarrel.java b/src/java/growthcraft/cellar/common/block/BlockFermentBarrel.java index f89f62005..9f1660d39 100644 --- a/src/java/growthcraft/cellar/common/block/BlockFermentBarrel.java +++ b/src/java/growthcraft/cellar/common/block/BlockFermentBarrel.java @@ -4,7 +4,6 @@ import growthcraft.cellar.common.tileentity.TileEntityFermentBarrel; import growthcraft.cellar.event.EventBarrelDrained; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.cellar.util.CellarGuiType; import growthcraft.api.core.util.BlockFlags; import growthcraft.core.Utils; @@ -38,7 +37,6 @@ public BlockFermentBarrel() setBlockName("grc.fermentBarrel"); setBlockTextureName("grccellar:ferment_barrel"); setCreativeTab(GrowthCraftCellar.tab); - setGuiType(CellarGuiType.FERMENT_BARREL); } @Override diff --git a/src/java/growthcraft/cellar/common/block/BlockFruitPress.java b/src/java/growthcraft/cellar/common/block/BlockFruitPress.java index d85eba480..08d73a99c 100644 --- a/src/java/growthcraft/cellar/common/block/BlockFruitPress.java +++ b/src/java/growthcraft/cellar/common/block/BlockFruitPress.java @@ -5,7 +5,6 @@ import growthcraft.cellar.client.render.RenderFruitPress; import growthcraft.cellar.common.tileentity.TileEntityFruitPress; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.cellar.util.CellarGuiType; import growthcraft.api.core.util.BlockFlags; import cpw.mods.fml.relauncher.Side; @@ -35,7 +34,6 @@ public BlockFruitPress() setStepSound(soundTypeWood); setBlockName("grc.fruitPress"); setCreativeTab(GrowthCraftCellar.tab); - setGuiType(CellarGuiType.FRUIT_PRESS); } private Block getPresserBlock() @@ -43,11 +41,13 @@ private Block getPresserBlock() return GrowthCraftCellar.blocks.fruitPresser.getBlock(); } + @Override public boolean isRotatable(IBlockAccess world, int x, int y, int z, ForgeDirection side) { return true; } + @Override public void doRotateBlock(World world, int x, int y, int z, ForgeDirection side) { world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) ^ 1, BlockFlags.SYNC); diff --git a/src/java/growthcraft/cellar/common/block/BlockFruitPresser.java b/src/java/growthcraft/cellar/common/block/BlockFruitPresser.java index 2ca6377a8..94a25be80 100644 --- a/src/java/growthcraft/cellar/common/block/BlockFruitPresser.java +++ b/src/java/growthcraft/cellar/common/block/BlockFruitPresser.java @@ -2,30 +2,28 @@ import java.util.Random; +import growthcraft.api.core.util.BlockFlags; import growthcraft.cellar.client.render.RenderFruitPresser; import growthcraft.cellar.common.tileentity.TileEntityFruitPresser; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.block.IRotatableBlock; import growthcraft.core.common.block.IWrenchable; -import growthcraft.api.core.util.BlockFlags; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class BlockFruitPresser extends BlockContainer implements IWrenchable, IRotatableBlock +public class BlockFruitPresser extends BlockCellarContainer implements IWrenchable, IRotatableBlock { @SideOnly(Side.CLIENT) private IIcon[] icons; @@ -34,6 +32,7 @@ public BlockFruitPresser() { super(Material.piston); this.isBlockContainer = true; + setTileEntityType(TileEntityFruitPresser.class); setHardness(0.5F); setStepSound(soundTypePiston); setBlockName("grc.fruitPresser"); @@ -61,6 +60,7 @@ public String getPressStateName(int meta) ************/ /* IRotatableBLock */ + @Override public boolean isRotatable(IBlockAccess world, int x, int y, int z, ForgeDirection side) { final Block below = world.getBlock(x, y - 1, z); @@ -71,6 +71,7 @@ public boolean isRotatable(IBlockAccess world, int x, int y, int z, ForgeDirecti return false; } + @Override public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection side) { if (isRotatable(world, x, y, z, side)) @@ -199,12 +200,6 @@ public Item getItem(World world, int x, int y, int z) return GrowthCraftCellar.blocks.fruitPress.getItem(); } - @Override - public TileEntity createNewTileEntity(World world, int par2) - { - return new TileEntityFruitPresser(); - } - /************ * DROPS ************/ diff --git a/src/java/growthcraft/cellar/common/item/EnumYeast.java b/src/java/growthcraft/cellar/common/item/EnumYeast.java index dd3bb87a9..9cff5b373 100644 --- a/src/java/growthcraft/cellar/common/item/EnumYeast.java +++ b/src/java/growthcraft/cellar/common/item/EnumYeast.java @@ -47,7 +47,7 @@ public enum EnumYeast implements IItemStackFactory */ public ItemStack asStack(int size) { - return GrowthCraftCellar.yeast.asStack(size, ordinal()); + return GrowthCraftCellar.items.yeast.asStack(size, ordinal()); } /** diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityBrewKettle.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityBrewKettle.java index 68ceca54e..9da9f160f 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityBrewKettle.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityBrewKettle.java @@ -5,13 +5,16 @@ import io.netty.buffer.ByteBuf; import growthcraft.cellar.common.fluids.CellarTank; +import growthcraft.cellar.common.inventory.ContainerBrewKettle; import growthcraft.cellar.common.tileentity.device.BrewKettle; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.inventory.GrcInternalInventory; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.ITileHeatedDevice; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.ITileHeatedDevice; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.item.ItemStack; @@ -60,16 +63,17 @@ protected FluidTank[] createTanks() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 2); } - protected void markForFluidUpdate() + @Override + protected void markFluidDirty() { // Brew Kettles need to update their rendering state when a fluid // changes, most of the other cellar blocks are unaffected by this - markForBlockUpdate(); + markForUpdate(); } @Override @@ -78,6 +82,18 @@ public String getDefaultInventoryName() return "container.grc.brewKettle"; } + @Override + public String getGuiID() + { + return "grccellar:brew_kettle"; + } + + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) + { + return new ContainerBrewKettle(playerInventory, this); + } + @Override public float getDeviceProgress() { @@ -90,13 +106,14 @@ public int getDeviceProgressScaled(int scale) return brewKettle.getProgressScaled(scale); } - /************ - * UPDATE - ************/ @Override - protected void updateDevice() + public void updateEntity() { - brewKettle.update(); + super.updateEntity(); + if (!worldObj.isRemote) + { + brewKettle.update(); + } } @Override @@ -136,14 +153,9 @@ public boolean canExtractItem(int index, ItemStack stack, int side) return side != 0 || index == 1; } - /************ - * NBT - ************/ - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_BrewKettle(NBTTagCompound nbt) { - super.readFromNBT(nbt); - if (nbt.hasKey("time")) { // Pre 2.5 @@ -156,22 +168,20 @@ public void readFromNBT(NBTTagCompound nbt) } } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_BrewKettle(NBTTagCompound nbt) { - super.writeToNBT(nbt); - brewKettle.writeToNBT(nbt, "brew_kettle"); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_BrewKettle(ByteBuf stream) throws IOException { brewKettle.readFromStream(stream); return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_BrewKettle(ByteBuf stream) throws IOException { brewKettle.writeToStream(stream); @@ -254,7 +264,6 @@ public void switchTanks() this.clearTank(1); this.getFluidTank(0).fill(f1, true); this.getFluidTank(1).fill(f0, true); - - markForBlockUpdate(); + markForUpdate(); } } diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityCellarDevice.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityCellarDevice.java index 529797d9e..74ff965a1 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityCellarDevice.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityCellarDevice.java @@ -24,15 +24,16 @@ package growthcraft.cellar.common.tileentity; import growthcraft.api.core.fluids.FluidUtils; -import growthcraft.core.common.tileentity.GrcTileEntityDeviceBase; -import growthcraft.core.common.tileentity.IGuiNetworkSync; +import growthcraft.core.common.tileentity.feature.IGuiNetworkSync; +import growthcraft.core.common.tileentity.feature.IInteractionObject; +import growthcraft.core.common.tileentity.GrcTileDeviceBase; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -public abstract class TileEntityCellarDevice extends GrcTileEntityDeviceBase implements IGuiNetworkSync +public abstract class TileEntityCellarDevice extends GrcTileDeviceBase implements IGuiNetworkSync, IInteractionObject { @Override public void receiveGUINetworkData(int id, int v) diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityCultureJar.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityCultureJar.java index 2b8d22411..3b44bccdd 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityCultureJar.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityCultureJar.java @@ -26,18 +26,21 @@ import java.io.IOException; import growthcraft.cellar.common.fluids.CellarTank; +import growthcraft.cellar.common.inventory.ContainerCultureJar; import growthcraft.cellar.common.tileentity.component.TileHeatingComponent; import growthcraft.cellar.common.tileentity.device.CultureGenerator; import growthcraft.cellar.common.tileentity.device.YeastGenerator; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.inventory.GrcInternalInventory; import growthcraft.core.common.tileentity.device.DeviceProgressive; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.ITileHeatedDevice; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.ITileHeatedDevice; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.item.ItemStack; @@ -131,7 +134,7 @@ protected FluidTank[] createTanks() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 1); } @@ -142,11 +145,24 @@ public String getDefaultInventoryName() return "container.grc.CultureJar"; } - protected void markForFluidUpdate() + @Override + public String getGuiID() + { + return "grccellar:culture_jar"; + } + + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) + { + return new ContainerCultureJar(playerInventory, this); + } + + @Override + protected void markFluidDirty() { // Ferment Jars need to update their rendering state when a fluid // changes, most of the other cellar blocks are unaffected by this - markForBlockUpdate(); + markForUpdate(); } @Override @@ -190,26 +206,29 @@ protected FluidStack doDrain(ForgeDirection from, FluidStack resource, boolean s } @Override - protected void updateDevice() + public void updateEntity() { - heatComponent.update(); - final int lastState = jarDeviceState; - final DeviceProgressive prog = getActiveDevice(); - if (prog == cultureGen) - { - this.jarDeviceState = 1; - yeastGen.resetTime(); - } - else + super.updateEntity(); + if (!worldObj.isRemote) { - this.jarDeviceState = 0; - cultureGen.resetTime(); - } - getActiveDevice().update(); - if (jarDeviceState != lastState) - { - GrowthCraftCellar.getLogger().debug("Jar changed device state %d, {%s}", jarDeviceState, getActiveDevice()); - markForBlockUpdate(); + heatComponent.update(); + final int lastState = jarDeviceState; + final DeviceProgressive prog = getActiveDevice(); + if (prog == cultureGen) + { + this.jarDeviceState = 1; + yeastGen.resetTime(); + } + else + { + this.jarDeviceState = 0; + cultureGen.resetTime(); + } + getActiveDevice().update(); + if (jarDeviceState != lastState) + { + markDirtyAndUpdate(); + } } } @@ -251,25 +270,23 @@ public void sendGUINetworkData(Container container, ICrafting iCrafting) iCrafting.sendProgressBarUpdate(container, CultureJarDataId.HEAT_AMOUNT.ordinal(), (int)(heatComponent.getHeatMultiplier() * 0x7FFF)); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_CultureJar(NBTTagCompound nbt) { - super.readFromNBT(nbt); yeastGen.readFromNBT(nbt, "yeastgen"); cultureGen.readFromNBT(nbt, "culture_gen"); heatComponent.readFromNBT(nbt, "heat_component"); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_CultureJar(NBTTagCompound nbt) { - super.writeToNBT(nbt); yeastGen.writeToNBT(nbt, "yeastgen"); cultureGen.writeToNBT(nbt, "culture_gen"); heatComponent.writeToNBT(nbt, "heat_component"); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_YeastGen(ByteBuf stream) throws IOException { this.jarDeviceState = stream.readInt(); @@ -279,7 +296,7 @@ public boolean readFromStream_YeastGen(ByteBuf stream) throws IOException return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_YeastGen(ByteBuf stream) throws IOException { stream.writeInt(jarDeviceState); diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityFermentBarrel.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityFermentBarrel.java index 3354b688c..a8d96db58 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityFermentBarrel.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityFermentBarrel.java @@ -10,14 +10,17 @@ import growthcraft.api.core.nbt.INBTItemSerializable; import growthcraft.api.core.nbt.NBTHelper; import growthcraft.cellar.common.fluids.CellarTank; +import growthcraft.cellar.common.inventory.ContainerFermentBarrel; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.inventory.GrcInternalInventory; import growthcraft.core.common.inventory.InventoryProcessor; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -67,7 +70,7 @@ protected FluidTank[] createTanks() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 2); } @@ -78,6 +81,18 @@ public String getDefaultInventoryName() return "container.grc.fermentBarrel"; } + @Override + public String getGuiID() + { + return "grccellar:ferment_barrel"; + } + + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) + { + return new ContainerFermentBarrel(playerInventory, this); + } + protected void markForRecipeRecheck() { this.recheckRecipe = true; @@ -111,7 +126,7 @@ private IFermentationRecipe refreshRecipe() resetTime(); } this.activeRecipe = recipe; - markForInventoryUpdate(); + markDirty(); } else { @@ -119,7 +134,7 @@ private IFermentationRecipe refreshRecipe() { this.activeRecipe = null; resetTime(); - markForInventoryUpdate(); + markDirty(); } } return activeRecipe; @@ -207,31 +222,35 @@ public int getDeviceProgressScaled(int scale) } @Override - protected void updateDevice() + public void updateEntity() { - if (recheckRecipe) - { - this.recheckRecipe = false; - refreshRecipe(); - } - - if (canFerment()) + super.updateEntity(); + if (!worldObj.isRemote) { - this.time++; + if (recheckRecipe) + { + this.recheckRecipe = false; + refreshRecipe(); + } - if (time >= getTimeMax()) + if (canFerment()) { - resetTime(); - fermentItem(); - markForInventoryUpdate(); + this.time++; + + if (time >= getTimeMax()) + { + resetTime(); + fermentItem(); + markDirty(); + } } - } - else - { - if (time != 0) + else { - resetTime(); - markForInventoryUpdate(); + if (time != 0) + { + resetTime(); + markDirty(); + } } } } @@ -289,10 +308,9 @@ public void readFromNBTForItem(NBTTagCompound nbt) } } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_FermentBarrel(NBTTagCompound nbt) { - super.readFromNBT(nbt); readFermentTimeFromNBT(nbt); } @@ -309,10 +327,9 @@ public void writeToNBTForItem(NBTTagCompound nbt) nbt.setBoolean("lid_on", lidOn); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_FermentBarrel(NBTTagCompound nbt) { - super.writeToNBT(nbt); writeFermentTimeToNBT(nbt); } @@ -342,7 +359,7 @@ public void sendGUINetworkData(Container container, ICrafting iCrafting) iCrafting.sendProgressBarUpdate(container, FermentBarrelDataID.TIME_MAX.ordinal(), getTimeMax()); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_FermentBarrel(ByteBuf stream) throws IOException { this.time = stream.readInt(); @@ -350,7 +367,7 @@ public boolean readFromStream_FermentBarrel(ByteBuf stream) throws IOException return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_FermentBarrel(ByteBuf stream) throws IOException { stream.writeInt(time); @@ -395,9 +412,9 @@ protected FluidStack doDrain(ForgeDirection from, FluidStack resource, boolean s } @Override - protected void markForFluidUpdate() + protected void markFluidDirty() { - super.markForFluidUpdate(); + super.markFluidDirty(); markForRecipeRecheck(); } diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPress.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPress.java index 5c6eb2da3..3536de8b9 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPress.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPress.java @@ -1,11 +1,15 @@ package growthcraft.cellar.common.tileentity; import growthcraft.cellar.common.fluids.CellarTank; +import growthcraft.cellar.common.inventory.ContainerFruitPress; import growthcraft.cellar.common.tileentity.device.FruitPress; import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.common.inventory.GrcInternalInventory; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.item.ItemStack; @@ -37,7 +41,7 @@ protected FluidTank[] createTanks() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 2); } @@ -48,6 +52,18 @@ public String getDefaultInventoryName() return "container.grc.fruitPress"; } + @Override + public String getGuiID() + { + return "grccellar:fruit_press"; + } + + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) + { + return new ContainerFruitPress(playerInventory, this); + } + @Override public float getDeviceProgress() { @@ -61,9 +77,13 @@ public int getDeviceProgressScaled(int scale) } @Override - protected void updateDevice() + public void updateEntity() { - fruitPress.update(); + super.updateEntity(); + if (!worldObj.isRemote) + { + fruitPress.update(); + } } @Override @@ -120,10 +140,9 @@ protected void readTanksFromNBT(NBTTagCompound nbt) } } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_FruitPress(NBTTagCompound nbt) { - super.readFromNBT(nbt); if (nbt.getInteger("FruitPress_version") > 0) { fruitPress.readFromNBT(nbt, "fruit_press"); @@ -134,10 +153,9 @@ public void readFromNBT(NBTTagCompound nbt) } } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_FruitPress(NBTTagCompound nbt) { - super.writeToNBT(nbt); fruitPress.writeToNBT(nbt, "fruit_press"); nbt.setInteger("FruitPress_version", 2); } diff --git a/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPresser.java b/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPresser.java index d29370298..dab650a43 100644 --- a/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPresser.java +++ b/src/java/growthcraft/cellar/common/tileentity/TileEntityFruitPresser.java @@ -1,14 +1,16 @@ package growthcraft.cellar.common.tileentity; +import java.io.IOException; + +import io.netty.buffer.ByteBuf; + import growthcraft.cellar.GrowthCraftCellar; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.GrcTileBase; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntity; -public class TileEntityFruitPresser extends TileEntity +public class TileEntityFruitPresser extends GrcTileBase { public float trans; public float transPrev; @@ -17,19 +19,17 @@ public class TileEntityFruitPresser extends TileEntity private float transMin; private float transMax = 0.4375F; - /************ - * UPDATE - ************/ + @Override public void updateEntity() { super.updateEntity(); - if (GrowthCraftCellar.blocks.fruitPresser.getBlock() != worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord)) + if (GrowthCraftCellar.blocks.fruitPresser.getBlock() != getBlockType()) { invalidate(); } - final int meta = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + final int meta = getBlockMetadata(); this.transPrev = this.trans; if ((meta == 0 || meta == 1) && this.trans > this.transMin) @@ -47,40 +47,33 @@ public float getTranslation() return this.trans; } - /************ - * NBT - ************/ - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_FruitPresser(NBTTagCompound nbt) { - super.readFromNBT(nbt); this.trans = nbt.getFloat("trans"); this.transPrev = nbt.getFloat("transprev"); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_FruitPresser(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setFloat("trans", trans); nbt.setFloat("transprev", transPrev); } - /************ - * PACKETS - ************/ - @Override - public Packet getDescriptionPacket() + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) + public boolean readFromStream_FruitPresser(ByteBuf stream) throws IOException { - final NBTTagCompound nbtTag = new NBTTagCompound(); - writeToNBT(nbtTag); - return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); + this.trans = stream.readFloat(); + this.transPrev = stream.readFloat(); + return true; } - @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) + public boolean writeToStream_FruitPresser(ByteBuf stream) throws IOException { - readFromNBT(packet.func_148857_g()); - this.worldObj.func_147479_m(this.xCoord, this.yCoord, this.zCoord); + stream.writeFloat(trans); + stream.writeFloat(transPrev); + return true; } } diff --git a/src/java/growthcraft/cellar/common/tileentity/device/BrewKettle.java b/src/java/growthcraft/cellar/common/tileentity/device/BrewKettle.java index ccbbc686b..beee58337 100644 --- a/src/java/growthcraft/cellar/common/tileentity/device/BrewKettle.java +++ b/src/java/growthcraft/cellar/common/tileentity/device/BrewKettle.java @@ -174,7 +174,7 @@ private void brewItem(BrewingRecipe recipe) inputFluidSlot.consume(recipe.getInputFluidStack(), true); outputFluidSlot.fill(recipe.asFluidStack(), true); brewingSlot.consume(recipe.getInputItemStack()); - markForBlockUpdate(); + markForUpdate(); GrowthCraftCellar.CELLAR_BUS.post(new EventBrewed(parent, recipe)); } @@ -197,7 +197,7 @@ public void update() } else { - if (resetTime()) markForInventoryUpdate(); + if (resetTime()) markForUpdate(); } } diff --git a/src/java/growthcraft/cellar/common/tileentity/device/CultureGenerator.java b/src/java/growthcraft/cellar/common/tileentity/device/CultureGenerator.java index 4c560f146..3e329b4f3 100644 --- a/src/java/growthcraft/cellar/common/tileentity/device/CultureGenerator.java +++ b/src/java/growthcraft/cellar/common/tileentity/device/CultureGenerator.java @@ -100,12 +100,12 @@ public void update() { resetTime(); produceCulture(activeRecipe); - markForInventoryUpdate(); + markDirty(); } } else { - if (resetTime()) markForInventoryUpdate(); + if (resetTime()) markDirty(); } } } diff --git a/src/java/growthcraft/cellar/common/tileentity/device/FruitPress.java b/src/java/growthcraft/cellar/common/tileentity/device/FruitPress.java index 400815e7e..d6d707780 100644 --- a/src/java/growthcraft/cellar/common/tileentity/device/FruitPress.java +++ b/src/java/growthcraft/cellar/common/tileentity/device/FruitPress.java @@ -124,12 +124,12 @@ public void update() { resetTime(); pressItem(); - markForInventoryUpdate(); + markDirty(); } } else { - if (resetTime()) markForInventoryUpdate(); + if (resetTime()) markDirty(); } } diff --git a/src/java/growthcraft/cellar/common/tileentity/device/YeastGenerator.java b/src/java/growthcraft/cellar/common/tileentity/device/YeastGenerator.java index 5806b6e25..be3ac8574 100644 --- a/src/java/growthcraft/cellar/common/tileentity/device/YeastGenerator.java +++ b/src/java/growthcraft/cellar/common/tileentity/device/YeastGenerator.java @@ -122,7 +122,7 @@ public boolean canProduceYeast() public void consumeFluid() { fluidSlot.consume(consumption, true); - markForBlockUpdate(); + markDirty(); } /** @@ -200,12 +200,12 @@ public void update() { resetTime(); produceYeast(); - markForInventoryUpdate(); + markDirty(); } } else { - if (resetTime()) markForInventoryUpdate(); + if (resetTime()) markDirty(); } } } diff --git a/src/java/growthcraft/cellar/eventhandler/EventHandlerCauldronUseItem.java b/src/java/growthcraft/cellar/eventhandler/EventHandlerCauldronUseItem.java index e64c063ea..9f9eba1a3 100644 --- a/src/java/growthcraft/cellar/eventhandler/EventHandlerCauldronUseItem.java +++ b/src/java/growthcraft/cellar/eventhandler/EventHandlerCauldronUseItem.java @@ -53,7 +53,7 @@ public void handle(PlayerInteractEvent event) if (itemstack == null) return; - if (GrowthCraftCellar.waterBag.equals(itemstack.getItem())) + if (GrowthCraftCellar.items.waterBag.equals(itemstack.getItem())) { final int meta = event.world.getBlockMetadata(event.x, event.y, event.z); if (meta > 0) diff --git a/src/java/growthcraft/cellar/handler/GuiHandlerCellar.java b/src/java/growthcraft/cellar/handler/GuiHandlerCellar.java deleted file mode 100644 index 5b392da6b..000000000 --- a/src/java/growthcraft/cellar/handler/GuiHandlerCellar.java +++ /dev/null @@ -1,78 +0,0 @@ -package growthcraft.cellar.handler; - -import growthcraft.cellar.client.gui.GuiBrewKettle; -import growthcraft.cellar.client.gui.GuiFermentBarrel; -import growthcraft.cellar.client.gui.GuiCultureJar; -import growthcraft.cellar.client.gui.GuiFruitPress; -import growthcraft.cellar.common.inventory.ContainerBrewKettle; -import growthcraft.cellar.common.inventory.ContainerFermentBarrel; -import growthcraft.cellar.common.inventory.ContainerCultureJar; -import growthcraft.cellar.common.inventory.ContainerFruitPress; -import growthcraft.cellar.common.tileentity.TileEntityBrewKettle; -import growthcraft.cellar.common.tileentity.TileEntityFermentBarrel; -import growthcraft.cellar.common.tileentity.TileEntityCultureJar; -import growthcraft.cellar.common.tileentity.TileEntityFruitPress; - -import cpw.mods.fml.common.network.IGuiHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class GuiHandlerCellar implements IGuiHandler -{ - @Override - public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityFruitPress) - { - return new ContainerFruitPress(player.inventory, (TileEntityFruitPress)te); - } - - if (te instanceof TileEntityBrewKettle) - { - return new ContainerBrewKettle(player.inventory, (TileEntityBrewKettle)te); - } - - if (te instanceof TileEntityFermentBarrel) - { - return new ContainerFermentBarrel(player.inventory, (TileEntityFermentBarrel)te); - } - - if (te instanceof TileEntityCultureJar) - { - return new ContainerCultureJar(player.inventory, (TileEntityCultureJar)te); - } - - return null; - } - - @Override - public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityFruitPress) - { - return new GuiFruitPress(player.inventory, (TileEntityFruitPress)te); - } - - if (te instanceof TileEntityBrewKettle) - { - return new GuiBrewKettle(player.inventory, (TileEntityBrewKettle)te); - } - - if (te instanceof TileEntityFermentBarrel) - { - return new GuiFermentBarrel(player.inventory, (TileEntityFermentBarrel)te); - } - - if (te instanceof TileEntityCultureJar) - { - return new GuiCultureJar(player.inventory, (TileEntityCultureJar)te); - } - - return null; - } -} diff --git a/src/java/growthcraft/cellar/init/GrcCellarBlocks.java b/src/java/growthcraft/cellar/init/GrcCellarBlocks.java index c3c79149d..1ab2fde6e 100644 --- a/src/java/growthcraft/cellar/init/GrcCellarBlocks.java +++ b/src/java/growthcraft/cellar/init/GrcCellarBlocks.java @@ -30,10 +30,10 @@ import growthcraft.cellar.common.block.BlockFruitPresser; import growthcraft.cellar.common.itemblock.ItemBlockFermentBarrel; import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleBlocks; import growthcraft.core.integration.NEI; -public class GrcCellarBlocks extends GrcModuleBase +public class GrcCellarBlocks extends GrcModuleBlocks { public BlockDefinition brewKettle; public BlockDefinition cultureJar; @@ -44,11 +44,11 @@ public class GrcCellarBlocks extends GrcModuleBase @Override public void preInit() { - this.brewKettle = new BlockDefinition(new BlockBrewKettle()); - this.cultureJar = new BlockDefinition(new BlockCultureJar()); - this.fermentBarrel = new BlockDefinition(new BlockFermentBarrel()); - this.fruitPress = new BlockDefinition(new BlockFruitPress()); - this.fruitPresser = new BlockDefinition(new BlockFruitPresser()); + this.brewKettle = newDefinition(new BlockBrewKettle()); + this.cultureJar = newDefinition(new BlockCultureJar()); + this.fermentBarrel = newDefinition(new BlockFermentBarrel()); + this.fruitPress = newDefinition(new BlockFruitPress()); + this.fruitPresser = newDefinition(new BlockFruitPresser()); } @Override diff --git a/src/java/growthcraft/cellar/init/GrcCellarItems.java b/src/java/growthcraft/cellar/init/GrcCellarItems.java new file mode 100644 index 000000000..d218af036 --- /dev/null +++ b/src/java/growthcraft/cellar/init/GrcCellarItems.java @@ -0,0 +1,53 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.cellar.init; + +import growthcraft.cellar.common.item.ItemChievDummy; +import growthcraft.cellar.common.item.ItemWaterBag; +import growthcraft.cellar.common.item.ItemYeast; +import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.common.GrcModuleItems; + +public class GrcCellarItems extends GrcModuleItems +{ + public ItemDefinition yeast; + public ItemDefinition waterBag; + public ItemDefinition chievItemDummy; + + @Override + public void preInit() + { + this.yeast = newDefinition(new ItemYeast()); + this.waterBag = newDefinition(new ItemWaterBag()); + this.chievItemDummy = newDefinition(new ItemChievDummy()); + } + + @Override + public void register() + { + yeast.register("grc.yeast"); + waterBag.register("grc.waterBag"); + chievItemDummy.register("grc.chievItemDummy"); + } +} diff --git a/src/java/growthcraft/cellar/integration/ThaumcraftModule.java b/src/java/growthcraft/cellar/integration/ThaumcraftModule.java index 8038c68ef..e1407f4f0 100644 --- a/src/java/growthcraft/cellar/integration/ThaumcraftModule.java +++ b/src/java/growthcraft/cellar/integration/ThaumcraftModule.java @@ -57,7 +57,7 @@ protected void integrate() ThaumcraftApi.registerObjectTag(GrowthCraftCellar.blocks.fermentBarrel.asStack(), new AspectList().add(Aspect.METAL, 6).add(Aspect.CRAFT, 2).add(Aspect.WATER, 2)); ThaumcraftApi.registerObjectTag(GrowthCraftCellar.blocks.fruitPress.asStack(), new AspectList().add(Aspect.METAL, 3).add(Aspect.CRAFT, 2).add(Aspect.MECHANISM, 2)); - ThaumcraftApi.registerObjectTag(GrowthCraftCellar.waterBag.asStack(), new AspectList().add(Aspect.BEAST, 1).add(Aspect.VOID, 2).add(Aspect.WATER, 2)); + ThaumcraftApi.registerObjectTag(GrowthCraftCellar.items.waterBag.asStack(), new AspectList().add(Aspect.BEAST, 1).add(Aspect.VOID, 2).add(Aspect.WATER, 2)); ThaumcraftApi.registerObjectTag(EnumYeast.BREWERS.asStack(), new AspectList().add(Aspect.EARTH, 1)); ThaumcraftApi.registerObjectTag(EnumYeast.LAGER.asStack(), new AspectList().add(Aspect.COLD, 1)); diff --git a/src/java/growthcraft/cellar/stats/GrcCellarAchievements.java b/src/java/growthcraft/cellar/stats/GrcCellarAchievements.java index 52d5a6f84..9224e9fa5 100644 --- a/src/java/growthcraft/cellar/stats/GrcCellarAchievements.java +++ b/src/java/growthcraft/cellar/stats/GrcCellarAchievements.java @@ -35,14 +35,14 @@ public GrcCellarAchievements() achievements.put(CellarAchievement.GET_DRUNK, (new Achievement("grc.achievement.getDrunk", "getDrunk", 0, -4, - GrowthCraftCellar.chievItemDummy.asStack(), + GrowthCraftCellar.items.chievItemDummy.asStack(), achievements.get(CellarAchievement.FERMENT_BOOZE)) ).setSpecial().registerStat() ); achievements.put(CellarAchievement.ON_THE_GO, (new Achievement("grc.achievement.onTheGo", "onTheGo", 2, -4, - GrowthCraftCellar.waterBag.asStack(1, 16), + GrowthCraftCellar.items.waterBag.asStack(1, 16), NO_ACHIEVEMENT) ).registerStat() ); diff --git a/src/java/growthcraft/cellar/util/CellarGuiType.java b/src/java/growthcraft/cellar/util/CellarGuiType.java deleted file mode 100644 index 7fabbc8cd..000000000 --- a/src/java/growthcraft/cellar/util/CellarGuiType.java +++ /dev/null @@ -1,11 +0,0 @@ -package growthcraft.cellar.util; - -public enum CellarGuiType -{ - NONE, - FERMENT_JAR, - FERMENT_BARREL, - BREW_KETTLE, - FRUIT_PRESS, - STILL; -} diff --git a/src/java/growthcraft/core/ConfigTypeHandler.java b/src/java/growthcraft/core/ConfigTypeHandler.java index e49732fe0..d67c48e5c 100644 --- a/src/java/growthcraft/core/ConfigTypeHandler.java +++ b/src/java/growthcraft/core/ConfigTypeHandler.java @@ -40,6 +40,7 @@ public abstract class ConfigTypeHandler public static class TagHandler extends ConfigTypeHandler { @Override + @SuppressWarnings({"rawtypes"}) public boolean canHandle(Field field) { final Class typeClass = field.getType(); @@ -70,6 +71,7 @@ public Object handle(Field field, Configuration config) public static class TagTableHandler extends ConfigTypeHandler { @Override + @SuppressWarnings({"rawtypes"}) public boolean canHandle(Field field) { final Class typeClass = field.getType(); diff --git a/src/java/growthcraft/core/GrcGuiProvider.java b/src/java/growthcraft/core/GrcGuiProvider.java new file mode 100644 index 000000000..f581f67bf --- /dev/null +++ b/src/java/growthcraft/core/GrcGuiProvider.java @@ -0,0 +1,171 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core; + +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.Map; +import javax.annotation.Nonnull; + +import growthcraft.api.core.log.ILogger; +import growthcraft.core.common.tileentity.feature.IInteractionObject; + +import cpw.mods.fml.common.network.IGuiHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +/** + * Cross Ported from YATM + */ +public class GrcGuiProvider implements IGuiHandler +{ + public static class InvalidGuiElement extends IllegalStateException + { + public static final long serialVersionUID = 1L; + + public InvalidGuiElement(String str) + { + super(str); + } + } + + // Leave this Map empty on server, only the client should fill it + @SuppressWarnings({"rawtypes"}) + public final Map guiMap = new HashMap(); + protected ILogger logger; + + public GrcGuiProvider(ILogger p_logger) + { + this.logger = p_logger; + } + + /** + * Register your GUI class mappings here and have your tile entities import + * @param name name to register the gui as, prefix your mod domain, just because + * @param guiClass - the Class to use, ensure it has a constructor for (InventoryPlayer, TileEntity), (IInventory, TileEntity) will work as well + */ + @SuppressWarnings({"rawtypes"}) + public void register(String name, Class guiClass) + { + if (guiMap.containsKey(name)) + { + logger.warn("Overwriting Existing Gui mapping: %s with `%s`", name, guiClass); + } + guiMap.put(name, guiClass); + } + + private String typeName(Object inventory) + { + if (inventory == null) + { + return "NULL"; + } + return inventory.getClass().getName(); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object te) + { + final Class teClass = te.getClass(); + final Class invClass = inventory.getClass(); + for (Constructor con : c) + { + final Class[] types = con.getParameterTypes(); + if (types.length == 2) + { + if (types[0].isAssignableFrom(invClass) && types[1].isAssignableFrom(teClass)) + { + return con; + } + } + } + return null; + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private Object createContainerInstance(@Nonnull Class containerClass, @Nonnull InventoryPlayer inventory, Object te) + { + try + { + final Constructor[] c = containerClass.getConstructors(); + if (c.length == 0) + { + throw new InvalidGuiElement("Invalid Gui Element Class " + containerClass.getName()); + } + + final Constructor target = findConstructor(c, inventory, te); + + if (target == null) + { + throw new IllegalStateException("Cannot find " + containerClass.getName() + "( " + this.typeName(inventory) + ", " + this.typeName(te) + " )"); + } + + return target.newInstance(inventory, te); + } + catch (Throwable t) + { + throw new IllegalStateException(t); + } + } + + @Override + public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) + { + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IInteractionObject) + { + final IInteractionObject iobj = (IInteractionObject)te; + return iobj.createContainer(player.inventory, player); + } + else + { + logger.error("Container requested for TE but TE was not a IInteractionObject tile_entity=%s id=%d", te, id); + } + return null; + } + + @Override + @SuppressWarnings({"rawtypes"}) + public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) + { + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IInteractionObject) + { + final IInteractionObject iobj = (IInteractionObject)te; + final String guiId = iobj.getGuiID(); + final Class klass = guiMap.get(guiId); + if (klass != null) + { + return createContainerInstance(klass, player.inventory, te); + } + else + { + logger.error("Missing GUI Class for %s", guiId); + } + } + return null; + } +} diff --git a/src/java/growthcraft/core/GrowthCraftCore.java b/src/java/growthcraft/core/GrowthCraftCore.java index 74ad9f84e..9fb0a5723 100644 --- a/src/java/growthcraft/core/GrowthCraftCore.java +++ b/src/java/growthcraft/core/GrowthCraftCore.java @@ -80,11 +80,11 @@ public class GrowthCraftCore // Constants public static ItemStack EMPTY_BOTTLE; - private ILogger logger = new GrcLogger(MOD_ID); - private GrcCoreConfig config = new GrcCoreConfig(); - private ModuleContainer modules = new ModuleContainer(); - private UserFluidDictionaryConfig userFluidDictionary = new UserFluidDictionaryConfig(); - private UserVinesConfig userVinesConfig = new UserVinesConfig(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcCoreConfig config = new GrcCoreConfig(); + private final ModuleContainer modules = new ModuleContainer(); + private final UserFluidDictionaryConfig userFluidDictionary = new UserFluidDictionaryConfig(); + private final UserVinesConfig userVinesConfig = new UserVinesConfig(); public static GrcCoreConfig getConfig() { @@ -101,29 +101,26 @@ public void preInit(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/core.conf"); - if (config.debugEnabled) logger.info("Pre-Initializing %s", MOD_ID); - + if (config.debugEnabled) + { + logger.info("Pre-Initializing %s", MOD_ID); + CoreRegistry.instance().setLogger(logger); + } modules.add(blocks); modules.add(items); modules.add(fluids); modules.add(recipes); - userVinesConfig.setConfigFile(event.getModConfigurationDirectory(), "growthcraft/core/vines.json"); userFluidDictionary.setConfigFile(event.getModConfigurationDirectory(), "growthcraft/core/fluid_dictionary.json"); modules.add(userVinesConfig); modules.add(userFluidDictionary); - if (config.enableThaumcraftIntegration) modules.add(new growthcraft.core.integration.ThaumcraftModule()); if (config.enableWailaIntegration) modules.add(new growthcraft.core.integration.Waila()); if (config.enableAppleCoreIntegration) modules.add(new growthcraft.core.integration.AppleCore()); //if (config.enableNEIIntegration) modules.add(new growthcraft.core.integration.nei.NEIModule()); - - if (config.debugEnabled) - { - CoreRegistry.instance().setLogger(logger); - modules.setLogger(logger); - } - + modules.add(CommonProxy.instance); + if (config.debugEnabled) modules.setLogger(logger); + modules.freeze(); creativeTab = new CreativeTabsGrowthcraft("creative_tab_grccore"); EMPTY_BOTTLE = new ItemStack(Items.glass_bottle); @@ -157,9 +154,7 @@ private void register() public void init(FMLInitializationEvent event) { userFluidDictionary.loadUserConfig(); - CommonProxy.instance.initRenders(); AchievementPageGrowthcraft.init(); - userVinesConfig.addDefault(Blocks.vine); if (BopPlatform.isLoaded()) { diff --git a/src/java/growthcraft/core/client/ClientProxy.java b/src/java/growthcraft/core/client/ClientProxy.java index d7ac500f6..9584aa4b5 100644 --- a/src/java/growthcraft/core/client/ClientProxy.java +++ b/src/java/growthcraft/core/client/ClientProxy.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.core.client; import growthcraft.core.client.renderer.RenderBlockFruit; @@ -13,8 +36,9 @@ public class ClientProxy extends CommonProxy public static int paddyRenderPass; @Override - public void initRenders() + public void init() { + super.init(); RenderingRegistry.registerBlockHandler(new RenderPaddy()); RenderingRegistry.registerBlockHandler(new RenderFenceRope()); RenderingRegistry.registerBlockHandler(new RenderRope()); diff --git a/src/java/growthcraft/core/client/gui/GrcGuiContainer.java b/src/java/growthcraft/core/client/gui/GrcGuiContainer.java index 706321efb..59ca766fa 100644 --- a/src/java/growthcraft/core/client/gui/GrcGuiContainer.java +++ b/src/java/growthcraft/core/client/gui/GrcGuiContainer.java @@ -52,7 +52,9 @@ public abstract class GrcGuiContainer { protected T tileEntity; protected ResourceLocation guiResource; + @SuppressWarnings({"rawtypes"}) protected TooltipManager tooltipManager; + @SuppressWarnings({"rawtypes"}) protected WidgetManager widgets; public GrcGuiContainer(ResourceLocation res, C container, T te) @@ -111,6 +113,7 @@ public void initGui() } @Override + @SuppressWarnings({"rawtypes"}) public void drawHoveringText(List l, int x, int y, FontRenderer renderer) { super.drawHoveringText(l, x, y, renderer); diff --git a/src/java/growthcraft/core/client/gui/widget/Widget.java b/src/java/growthcraft/core/client/gui/widget/Widget.java index 913610abf..20d67b01f 100644 --- a/src/java/growthcraft/core/client/gui/widget/Widget.java +++ b/src/java/growthcraft/core/client/gui/widget/Widget.java @@ -29,14 +29,17 @@ public class Widget { public boolean visible = true; public Rectangle rect; + @SuppressWarnings({"rawtypes"}) protected WidgetManager manager; + @SuppressWarnings({"rawtypes"}) public Widget(WidgetManager man, Rectangle r) { this.manager = man; this.rect = r; } + @SuppressWarnings({"rawtypes"}) public Widget(WidgetManager man, int x, int y, int w, int h) { this(man, new Rectangle(x, y, w, h)); diff --git a/src/java/growthcraft/core/client/gui/widget/WidgetDeviceProgressIcon.java b/src/java/growthcraft/core/client/gui/widget/WidgetDeviceProgressIcon.java index 39073a50a..27681c1c3 100644 --- a/src/java/growthcraft/core/client/gui/widget/WidgetDeviceProgressIcon.java +++ b/src/java/growthcraft/core/client/gui/widget/WidgetDeviceProgressIcon.java @@ -23,7 +23,7 @@ */ package growthcraft.core.client.gui.widget; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; import net.minecraft.tileentity.TileEntity; @@ -39,6 +39,7 @@ public static enum ProgressDirection public ProgressDirection progressDirection = ProgressDirection.LEFT_TO_RIGHT; + @SuppressWarnings({"rawtypes"}) public WidgetDeviceProgressIcon(WidgetManager man, int x, int y, int w, int h) { super(man, x, y, w, h); diff --git a/src/java/growthcraft/core/client/gui/widget/WidgetFluidTank.java b/src/java/growthcraft/core/client/gui/widget/WidgetFluidTank.java index de5e67b77..ba561f6dc 100644 --- a/src/java/growthcraft/core/client/gui/widget/WidgetFluidTank.java +++ b/src/java/growthcraft/core/client/gui/widget/WidgetFluidTank.java @@ -34,6 +34,7 @@ public class WidgetFluidTank extends Widget public int numberColor = 0xFFFFFF; public Rectangle ruleRect = new Rectangle(); + @SuppressWarnings({"rawtypes"}) public WidgetFluidTank(WidgetManager man, int index, int x, int y, int w, int h) { super(man, x, y, w, h); diff --git a/src/java/growthcraft/core/client/gui/widget/WidgetHeatIcon.java b/src/java/growthcraft/core/client/gui/widget/WidgetHeatIcon.java index 76d6c0771..562efe340 100644 --- a/src/java/growthcraft/core/client/gui/widget/WidgetHeatIcon.java +++ b/src/java/growthcraft/core/client/gui/widget/WidgetHeatIcon.java @@ -23,12 +23,13 @@ */ package growthcraft.core.client.gui.widget; -import growthcraft.core.common.tileentity.ITileHeatedDevice; +import growthcraft.core.common.tileentity.feature.ITileHeatedDevice; import net.minecraft.tileentity.TileEntity; public class WidgetHeatIcon extends WidgetIconBase { + @SuppressWarnings({"rawtypes"}) public WidgetHeatIcon(WidgetManager man, int x, int y, int w, int h) { super(man, x, y, w, h); diff --git a/src/java/growthcraft/core/client/gui/widget/WidgetIconBase.java b/src/java/growthcraft/core/client/gui/widget/WidgetIconBase.java index 65b70f52a..416a5bc1c 100644 --- a/src/java/growthcraft/core/client/gui/widget/WidgetIconBase.java +++ b/src/java/growthcraft/core/client/gui/widget/WidgetIconBase.java @@ -29,6 +29,7 @@ public class WidgetIconBase extends Widget { public final Rectangle textureRect = new Rectangle(); + @SuppressWarnings({"rawtypes"}) public WidgetIconBase(WidgetManager man, int x, int y, int w, int h) { super(man, x, y, w, h); diff --git a/src/java/growthcraft/core/client/gui/widget/WidgetManager.java b/src/java/growthcraft/core/client/gui/widget/WidgetManager.java index 050596c92..59dc39b75 100644 --- a/src/java/growthcraft/core/client/gui/widget/WidgetManager.java +++ b/src/java/growthcraft/core/client/gui/widget/WidgetManager.java @@ -40,6 +40,7 @@ public WidgetManager(GrcGuiContainer g) this.gui = g; } + @SuppressWarnings({"rawtypes"}) public WidgetManager add(Widget widget) { widgets.add(widget); diff --git a/src/java/growthcraft/core/common/CommonProxy.java b/src/java/growthcraft/core/common/CommonProxy.java index a4038e93f..afdc9f46d 100644 --- a/src/java/growthcraft/core/common/CommonProxy.java +++ b/src/java/growthcraft/core/common/CommonProxy.java @@ -1,11 +1,32 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.core.common; import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.core.client.ClientProxy", serverSide="growthcraft.core.common.CommonProxy") public static CommonProxy instance; - - public void initRenders() {} } diff --git a/src/java/growthcraft/core/common/GrcModuleBase.java b/src/java/growthcraft/core/common/GrcModuleBase.java index 7eb8462a4..ee21b49e1 100644 --- a/src/java/growthcraft/core/common/GrcModuleBase.java +++ b/src/java/growthcraft/core/common/GrcModuleBase.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.core.common; import javax.annotation.Nonnull; diff --git a/src/java/growthcraft/core/common/GrcModuleBlocks.java b/src/java/growthcraft/core/common/GrcModuleBlocks.java new file mode 100644 index 000000000..e304ea417 --- /dev/null +++ b/src/java/growthcraft/core/common/GrcModuleBlocks.java @@ -0,0 +1,64 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core.common; + +import java.util.LinkedList; +import java.util.List; + +import growthcraft.core.common.definition.BlockDefinition; +import growthcraft.core.common.definition.BlockTypeDefinition; + +import net.minecraft.block.Block; + +public class GrcModuleBlocks extends GrcModuleBase +{ + // All items that had defintions created via the interface + public final List> all = new LinkedList>(); + + /** + * Creates a basic BlockDefintion from the given block + * + * @param block the block to wrap + * @return definition + */ + public BlockDefinition newDefinition(Block block) + { + final BlockDefinition def = new BlockDefinition(block); + all.add(def); + return def; + } + + /** + * Creates a BlockTypeDefintion from the given block + * + * @param block the block to wrap and type by + * @return typed definition + */ + public BlockTypeDefinition newTypedDefinition(T block) + { + final BlockTypeDefinition def = new BlockTypeDefinition(block); + all.add(def); + return def; + } +} diff --git a/src/java/growthcraft/core/common/GrcModuleItems.java b/src/java/growthcraft/core/common/GrcModuleItems.java new file mode 100644 index 000000000..28079ad3c --- /dev/null +++ b/src/java/growthcraft/core/common/GrcModuleItems.java @@ -0,0 +1,64 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core.common; + +import java.util.LinkedList; +import java.util.List; + +import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.common.definition.ItemTypeDefinition; + +import net.minecraft.item.Item; + +public class GrcModuleItems extends GrcModuleBase +{ + // All items that had defintions created via the interface + public final List> all = new LinkedList>(); + + /** + * Creates a basic ItemDefintion from the given item + * + * @param item the item to wrap + * @return definition + */ + public ItemDefinition newDefinition(Item item) + { + final ItemDefinition def = new ItemDefinition(item); + all.add(def); + return def; + } + + /** + * Creates a ItemTypeDefintion from the given item + * + * @param item the item to wrap and type by + * @return typed definition + */ + public ItemTypeDefinition newTypedDefinition(T item) + { + final ItemTypeDefinition def = new ItemTypeDefinition(item); + all.add(def); + return def; + } +} diff --git a/src/java/growthcraft/core/common/tileentity/IBlockUpdateFlagging.java b/src/java/growthcraft/core/common/GrcModuleProxyBase.java similarity index 88% rename from src/java/growthcraft/core/common/tileentity/IBlockUpdateFlagging.java rename to src/java/growthcraft/core/common/GrcModuleProxyBase.java index 72eeace0e..b69685e40 100644 --- a/src/java/growthcraft/core/common/tileentity/IBlockUpdateFlagging.java +++ b/src/java/growthcraft/core/common/GrcModuleProxyBase.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015 IceDragon200 + * Copyright (c) 2016 IceDragon200 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,9 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common; -public interface IBlockUpdateFlagging +public class GrcModuleProxyBase extends GrcModuleBase { - public void markForBlockUpdate(); } diff --git a/src/java/growthcraft/core/common/block/GrcBlockContainer.java b/src/java/growthcraft/core/common/block/GrcBlockContainer.java index ba01790a1..0ec4293df 100644 --- a/src/java/growthcraft/core/common/block/GrcBlockContainer.java +++ b/src/java/growthcraft/core/common/block/GrcBlockContainer.java @@ -30,9 +30,10 @@ import growthcraft.api.core.nbt.INBTItemSerializable; import growthcraft.api.core.util.BlockFlags; +import growthcraft.core.common.inventory.InventoryProcessor; import growthcraft.core.common.item.IItemTileBlock; -import growthcraft.core.common.tileentity.ICustomDisplayName; -import growthcraft.core.common.tileentity.IItemHandler; +import growthcraft.core.common.tileentity.feature.ICustomDisplayName; +import growthcraft.core.common.tileentity.feature.IItemHandler; import growthcraft.core.GrowthCraftCore; import growthcraft.core.util.ItemUtils; import growthcraft.core.Utils; @@ -71,12 +72,6 @@ public GrcBlockContainer(@Nonnull Material material) this.isBlockContainer = true; } - @Override - public void onBlockAdded(World world, int x, int y, int z) - { - super.onBlockAdded(world, x, y, z); - } - @Override public boolean onBlockEventReceived(World world, int x, int y, int z, int code, int value) { @@ -170,24 +165,45 @@ public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection side return false; } - public boolean wrenchBlock(World world, int x, int y, int z, EntityPlayer player, ItemStack wrench) + protected void fellBlockFromWrench(World world, int x, int y, int z) { - if (player != null) + final int metadata = world.getBlockMetadata(x, y, z); + final List drops = new ArrayList(); + if (shouldDropTileStack(world, x, y, z, metadata, 0)) { - if (ItemUtils.canWrench(wrench, player, x, y, z)) + GrowthCraftCore.getLogger().info("Dropping Tile As ItemStack"); + getTileItemStackDrops(drops, world, x, y, z, metadata, 0); + for (ItemStack stack : drops) { - if (player.isSneaking()) - { - if (!world.isRemote) - { - fellBlockAsItem(world, x, y, z); - ItemUtils.wrenchUsed(wrench, player, x, y, z); - } - return true; - } + ItemUtils.spawnItemStack(world, x, y, z, stack, world.rand); } + final TileEntity te = getTileEntity(world, x, y, z); + if (te instanceof IInventory) + { + GrowthCraftCore.getLogger().info("Clearing Inventory"); + InventoryProcessor.instance().clearSlots((IInventory)te); + } + GrowthCraftCore.getLogger().info("Setting Block To Air"); + world.setBlockToAir(x, y, z); } - return false; + else + { + fellBlockAsItem(world, x, y, z); + } + } + + @Override + public boolean wrenchBlock(World world, int x, int y, int z, EntityPlayer player, ItemStack wrench) + { + if (player == null) return false; + if (!ItemUtils.canWrench(wrench, player, x, y, z)) return false; + if (!player.isSneaking()) return false; + if (!world.isRemote) + { + fellBlockFromWrench(world, x, y, z); + ItemUtils.wrenchUsed(wrench, player, x, y, z); + } + return true; } public boolean tryWrenchItem(EntityPlayer player, World world, int x, int y, int z) @@ -298,7 +314,11 @@ protected void scatterInventory(World world, int x, int y, int z, Block block) for (int index = 0; index < inventory.getSizeInventory(); ++index) { final ItemStack stack = inventory.getStackInSlot(index); - ItemUtils.spawnItemStack(world, x, y, z, stack, rand); + if (stack != null) + { + ItemUtils.spawnItemStack(world, x, y, z, stack, rand); + } + inventory.setInventorySlotContents(index, (ItemStack)null); } world.func_147453_f(x, y, z, block); } @@ -452,7 +472,7 @@ private boolean handleIFluidHandler(World world, int x, int y, int z, EntityPlay return false; } - private boolean handleOnUseItem(World world, int x, int y, int z, EntityPlayer player, int meta) + protected boolean handleOnUseItem(IItemHandler.Action action, World world, int x, int y, int z, EntityPlayer player) { final TileEntity te = world.getTileEntity(x, y, z); if (te instanceof IItemHandler) @@ -467,11 +487,11 @@ private boolean handleOnUseItem(World world, int x, int y, int z, EntityPlayer p final ItemStack is = player.inventory.getCurrentItem(); boolean needUpdate = false; - if (ih.tryPlaceItem(player, is)) + if (ih.tryPlaceItem(action, player, is)) { needUpdate = true; } - else if (ih.tryTakeItem(player, is)) + else if (ih.tryTakeItem(action, player, is)) { needUpdate = true; } @@ -487,12 +507,29 @@ else if (ih.tryTakeItem(player, is)) return false; } + @Override + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) + { + if (!world.isRemote) + { + final TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IItemHandler) + { + if (handleOnUseItem(IItemHandler.Action.LEFT, world, x, y, z, player)) + { + return; + } + } + } + super.onBlockClicked(world, x, y, z, player); + } + @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float par7, float par8, float par9) { if (tryWrenchItem(player, world, x, y, z)) return true; if (handleIFluidHandler(world, x, y, z, player, meta)) return true; - if (handleOnUseItem(world, x, y, z, player, meta)) return true; + if (handleOnUseItem(IItemHandler.Action.RIGHT, world, x, y, z, player)) return true; return false; } diff --git a/src/java/growthcraft/core/common/definition/GrcBlockFluidDefinition.java b/src/java/growthcraft/core/common/definition/GrcBlockFluidDefinition.java index 5204bc654..01d4186d9 100644 --- a/src/java/growthcraft/core/common/definition/GrcBlockFluidDefinition.java +++ b/src/java/growthcraft/core/common/definition/GrcBlockFluidDefinition.java @@ -54,6 +54,7 @@ public static GrcBlockFluidDefinition create(Fluid fluid) return create(fluid, Material.water); } + @SuppressWarnings({"rawtypes"}) public static GrcBlockFluidDefinition create(FluidTypeDefinition def) { return create(def.getFluid()); diff --git a/src/java/growthcraft/core/common/inventory/GrcContainer.java b/src/java/growthcraft/core/common/inventory/GrcContainer.java index cf4f1c486..494f1a89f 100644 --- a/src/java/growthcraft/core/common/inventory/GrcContainer.java +++ b/src/java/growthcraft/core/common/inventory/GrcContainer.java @@ -27,7 +27,7 @@ import growthcraft.core.common.inventory.slot.SlotPlayer; import growthcraft.core.common.inventory.slot.SlotPlayerBackpack; import growthcraft.core.common.inventory.slot.SlotPlayerHotbar; -import growthcraft.core.common.tileentity.IGuiNetworkSync; +import growthcraft.core.common.tileentity.feature.IGuiNetworkSync; import growthcraft.core.util.Platform; import cpw.mods.fml.relauncher.Side; @@ -68,7 +68,7 @@ public boolean mergeWithSlot(Slot slot, ItemStack stack) return false; } - public boolean mergeWithSlotsOfKind(ItemStack stack, Class slot) + public boolean mergeWithSlotsOfKind(ItemStack stack, Class slotClass) { if (stack == null) return false; if (stack.stackSize <= 0) return false; @@ -78,7 +78,7 @@ public boolean mergeWithSlotsOfKind(ItemStack stack, Class slot) for (Object sub : inventorySlots) { - if (slot.isInstance(sub)) + if (slotClass.isInstance(sub)) { final Slot subSlot = (Slot)sub; if (start < 0) @@ -90,6 +90,21 @@ public boolean mergeWithSlotsOfKind(ItemStack stack, Class slot) } if (start <= -1 || end <= -1) return false; + boolean merged = false; + for (int i = start; i < end; ++i) + { + // Stop iterating if the stack has been successfully merged + if (stack.stackSize <= 0) break; + // Get the object at the given index + final Object obj = inventorySlots.get(i); + // Determine if the slot is the expected (in case the slots are interleaved) + if (slotClass.isInstance(obj)) + { + final Slot subSlot = (Slot)obj; + // try to merge it + merged |= mergeWithSlot(subSlot, stack); + } + } return mergeItemStack(stack, start, end + 1, false); } diff --git a/src/java/growthcraft/core/common/inventory/GrcInternalInventory.java b/src/java/growthcraft/core/common/inventory/GrcInternalInventory.java index a2813d5de..a7c1f5331 100644 --- a/src/java/growthcraft/core/common/inventory/GrcInternalInventory.java +++ b/src/java/growthcraft/core/common/inventory/GrcInternalInventory.java @@ -81,7 +81,7 @@ public void markDirty() onSlotChanged(WILDCARD_SLOT); } - public void clearInventory() + public void clear() { for (int i = 0; i < getMaxSize(); ++i) { @@ -90,6 +90,16 @@ public void clearInventory() onSlotChanged(WILDCARD_SLOT); } + /** + * @deprecated + * Use #clear instead + */ + @Deprecated + public void clearInventory() + { + clear(); + } + protected void readFromNBT(NBTTagList data) { this.items = ItemUtils.clearInventorySlots(items, getSizeInventory()); diff --git a/src/java/growthcraft/core/common/inventory/InventoryProcessor.java b/src/java/growthcraft/core/common/inventory/InventoryProcessor.java index 40cbc10a4..3cf62d53a 100644 --- a/src/java/growthcraft/core/common/inventory/InventoryProcessor.java +++ b/src/java/growthcraft/core/common/inventory/InventoryProcessor.java @@ -168,10 +168,17 @@ public boolean mergeWithSlot(@Nonnull IInventory inv, @Nullable ItemStack item, return true; } + /** + * Attempts to merge the given ItemStack into the inventory + * + * @param inv inventory to merge to + * @param stack the stack to merge into the inventory + * @param slots the selected slots to merge with + * @param true, the stack was merged somehow, false otherwise + */ public boolean mergeWithSlots(@Nonnull IInventory inv, @Nullable ItemStack stack, int[] slots) { if (stack == null) return false; - boolean anythingMerged = false; for (int slot : slots) { @@ -181,6 +188,25 @@ public boolean mergeWithSlots(@Nonnull IInventory inv, @Nullable ItemStack stack return anythingMerged; } + /** + * Attempts to merge the given ItemStack into the inventory + * + * @param inv inventory to merge to + * @param stack the stack to merge into the inventory + * @param true, the stack was merged somehow, false otherwise + */ + public boolean mergeWithSlots(@Nonnull IInventory inv, @Nullable ItemStack stack) + { + if (stack == null) return false; + boolean anythingMerged = false; + for (int i = 0; i < inv.getSizeInventory(); ++i) + { + if (stack.stackSize <= 0) break; + anythingMerged |= mergeWithSlot(inv, stack, i); + } + return anythingMerged; + } + /** * Attempts to merge the given ItemStack into the inventory * @@ -188,7 +214,7 @@ public boolean mergeWithSlots(@Nonnull IInventory inv, @Nullable ItemStack stack * @param stack - * @param remaining stack OR null if the item was completely expeneded */ - public ItemStack mergeWithSlots(@Nonnull IInventory inv, @Nullable ItemStack stack) + public ItemStack mergeWithSlotsStack(@Nonnull IInventory inv, @Nullable ItemStack stack) { if (stack == null) return null; @@ -250,8 +276,15 @@ public ItemStack yankSlot(@Nonnull IInventory inv, int slot) return null; } + protected boolean checkItemEquality(ItemStack actual, ItemStack expected) + { + if (actual == null) return false; + if (!expected.isItemEqual(actual)) return false; + return true; + } + /** - * Checks the given inventory and slot for an expected ItemStack + * Checks the given inventory and slot for an expected ItemStack, this will ignore stack sizes * * @param inv - inventory to check * @param expected - itemstack expected @@ -270,8 +303,32 @@ public boolean checkSlot(@Nonnull IInventory inv, @Nullable ItemStack expected, } else { - if (actual == null) return false; - if (!expected.isItemEqual(actual)) return false; + if (!checkItemEquality(actual, expected)) return false; + } + return true; + } + + /** + * Checks the given inventory and slot for an expected ItemStack + * + * @param inv - inventory to check + * @param expected - itemstack expected + * If the stack is null, then the slot is expected to be null as well + * Otherwise it is required + * @param src - slot to check + */ + public boolean checkSlotAndSize(@Nonnull IInventory inv, @Nullable ItemStack expected, int src) + { + final ItemStack actual = inv.getStackInSlot(src); + + if (expected == null) + { + // if the item is not needed, and is not available + if (actual != null) return false; + } + else + { + if (!checkItemEquality(actual, expected)) return false; if (actual.stackSize < expected.stackSize) return false; } return true; @@ -286,7 +343,7 @@ public boolean checkSlot(@Nonnull IInventory inv, @Nullable ItemStack expected, * Otherwise it is required * @param src - slot to check */ - public boolean checkSlot(@Nonnull IInventory inv, @Nullable IMultiItemStacks expected, int src) + public boolean checkSlotAndSize(@Nonnull IInventory inv, @Nullable IMultiItemStacks expected, int src) { final ItemStack actual = inv.getStackInSlot(src); @@ -312,13 +369,13 @@ public boolean checkSlot(@Nonnull IInventory inv, @Nullable IMultiItemStacks exp * @param from - a slice of slots to look in * @return true, all the items in the filter are present in the inv, false otherwise */ - public boolean checkSlots(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, int[] from) + public boolean checkSlotsAndSizes(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, int[] from) { assert filter.length == from.length; for (int i = 0; i < filter.length; ++i) { - if (!checkSlot(inv, filter[i], from[i])) return false; + if (!checkSlotAndSize(inv, filter[i], from[i])) return false; } return true; } @@ -331,13 +388,13 @@ public boolean checkSlots(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, * @param from - a slice of slots to look in * @return true, all the items in the filter are present in the inv, false otherwise */ - public boolean checkSlots(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] filter, int[] from) + public boolean checkSlotsAndSizes(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] filter, int[] from) { assert filter.length == from.length; for (int i = 0; i < filter.length; ++i) { - if (!checkSlot(inv, filter[i], from[i])) return false; + if (!checkSlotAndSize(inv, filter[i], from[i])) return false; } return true; } @@ -351,7 +408,7 @@ public boolean checkSlots(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] f * @return true, all the items in the filter are present in the inv, false otherwise */ @SuppressWarnings({"rawtypes"}) - public boolean checkSlots(@Nonnull IInventory inv, @Nonnull List filter, int[] from) + public boolean checkSlotsAndSizes(@Nonnull IInventory inv, @Nonnull List filter, int[] from) { assert filter.size() == from.length; @@ -360,11 +417,11 @@ public boolean checkSlots(@Nonnull IInventory inv, @Nonnull List filter, int[] f final Object filterObject = filter.get(i); if (filterObject instanceof IMultiItemStacks) { - if (!checkSlot(inv, (IMultiItemStacks)filterObject, from[i])) return false; + if (!checkSlotAndSize(inv, (IMultiItemStacks)filterObject, from[i])) return false; } else if (filterObject instanceof ItemStack || filterObject == null) { - if (!checkSlot(inv, (ItemStack)filterObject, from[i])) return false; + if (!checkSlotAndSize(inv, (ItemStack)filterObject, from[i])) return false; } else { @@ -383,7 +440,7 @@ public boolean moveToSlots(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, assert filter.length == to.length; // first ensure that each stack in the input has the item and enough of them - if (!checkSlots(inv, filter, from)) return false; + if (!checkSlotsAndSizes(inv, filter, from)) return false; for (int i = 0; i < filter.length; ++i) { @@ -405,7 +462,7 @@ public boolean moveToSlots(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] assert filter.length == to.length; // first ensure that each stack in the input has the item and enough of them - if (!checkSlots(inv, filter, from)) return false; + if (!checkSlotsAndSizes(inv, filter, from)) return false; for (int i = 0; i < filter.length; ++i) { @@ -430,7 +487,7 @@ public boolean moveToSlots(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] public boolean moveToSlot(@Nonnull IInventory inv, @Nonnull ItemStack filter, int from, int to) { // first ensure that each stack in the input has the item and enough of them - if (!checkSlot(inv, filter, from)) return false; + if (!checkSlotAndSize(inv, filter, from)) return false; final ItemStack stack = inv.decrStackSize(from, filter.stackSize); inv.setInventorySlotContents(to, stack); @@ -503,11 +560,11 @@ public int[] findItemSlots(@Nonnull IInventory inv, @Nonnull List expected, @Non boolean foundItem = false; if (expectedStack instanceof IMultiItemStacks) { - foundItem = checkSlot(inv, (IMultiItemStacks)expectedStack, slotIndex); + foundItem = checkSlotAndSize(inv, (IMultiItemStacks)expectedStack, slotIndex); } else if (expectedStack instanceof ItemStack) { - foundItem = checkSlot(inv, (ItemStack)expectedStack, slotIndex); + foundItem = checkSlotAndSize(inv, (ItemStack)expectedStack, slotIndex); } if (foundItem) @@ -606,7 +663,7 @@ public int findNextPresentFromEnd(@Nonnull IInventory inv) * @return true, all the items in the filter are present in the inv, false otherwise */ @SuppressWarnings({"rawtypes"}) - public boolean checkSlotsUnordered(@Nonnull IInventory inv, @Nonnull List filter, int[] from) + public boolean checkSlotsAndSizesUnordered(@Nonnull IInventory inv, @Nonnull List filter, int[] from) { assert filter.size() == from.length; final int[] slots = findItemSlots(inv, filter, from); @@ -625,9 +682,9 @@ public boolean checkSlotsUnordered(@Nonnull IInventory inv, @Nonnull List filter * @param from - a slice of slots to look in * @return true, all the items in the filter are present in the inv, false otherwise */ - public boolean checkSlotsUnordered(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, int[] from) + public boolean checkSlotsAndSizesUnordered(@Nonnull IInventory inv, @Nonnull ItemStack[] filter, int[] from) { - return checkSlotsUnordered(inv, Arrays.asList(filter), from); + return checkSlotsAndSizesUnordered(inv, Arrays.asList(filter), from); } /** @@ -638,9 +695,9 @@ public boolean checkSlotsUnordered(@Nonnull IInventory inv, @Nonnull ItemStack[] * @param from - a slice of slots to look in * @return true, all the items in the filter are present in the inv, false otherwise */ - public boolean checkSlotsUnordered(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] filter, int[] from) + public boolean checkSlotsAndSizesUnordered(@Nonnull IInventory inv, @Nonnull IMultiItemStacks[] filter, int[] from) { - return checkSlotsUnordered(inv, Arrays.asList(filter), from); + return checkSlotsAndSizesUnordered(inv, Arrays.asList(filter), from); } /** @@ -699,7 +756,7 @@ else if (expectedStack instanceof ItemStack) public boolean consumeItems(@Nonnull IInventory inv, @Nonnull List expected) { final int[] slots = findItemSlots(inv, expected); - if (!checkSlots(inv, expected, slots)) return false; + if (!checkSlotsAndSizes(inv, expected, slots)) return false; return consumeItemsInSlots(inv, expected, slots); } @@ -714,7 +771,10 @@ public boolean canInsertItem(@Nonnull IInventory inv, @Nullable ItemStack stack, final ItemStack expected = inv.getStackInSlot(slot); if (expected != null) { - return checkSlot(inv, stack, slot); + if (!checkSlot(inv, stack, slot)) return false; + if (expected.stackSize >= inv.getInventoryStackLimit()) return false; + final int estSize = expected.stackSize + stack.stackSize; + return estSize <= inv.getInventoryStackLimit(); } return true; } @@ -729,7 +789,7 @@ public boolean canExtractItem(@Nonnull IInventory inv, @Nullable ItemStack stack { final ItemStack expected = inv.getStackInSlot(slot); if (expected == null) return false; - return checkSlot(inv, stack, slot); + return checkSlotAndSize(inv, stack, slot); } public static InventoryProcessor instance() diff --git a/src/java/growthcraft/core/common/tileentity/GrcTileEntityBase.java b/src/java/growthcraft/core/common/tileentity/GrcTileBase.java similarity index 56% rename from src/java/growthcraft/core/common/tileentity/GrcTileEntityBase.java rename to src/java/growthcraft/core/common/tileentity/GrcTileBase.java index ad7cd35c7..558ca913f 100644 --- a/src/java/growthcraft/core/common/tileentity/GrcTileEntityBase.java +++ b/src/java/growthcraft/core/common/tileentity/GrcTileBase.java @@ -23,20 +23,17 @@ */ package growthcraft.core.common.tileentity; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.annotation.Nonnull; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import growthcraft.api.core.stream.IStreamable; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.event.EventFunction; +import growthcraft.api.core.nbt.INBTSerializable; +import growthcraft.core.common.tileentity.event.TileEventFunction; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.event.TileEventHandlerMap; import net.minecraft.tileentity.TileEntity; import net.minecraft.network.NetworkManager; @@ -51,99 +48,33 @@ * copied the code for use in YATM, but I've ported it over to Growthcraft as * well. */ -public abstract class GrcTileEntityBase extends TileEntity implements IBlockUpdateFlagging, IStreamable +public abstract class GrcTileBase extends TileEntity implements IStreamable, INBTSerializable { - protected static class HandlerMap extends EnumMap> - { - public static final long serialVersionUID = 1L; - - public HandlerMap() - { - super(EventHandler.EventType.class); - } - } - - protected static Map, HandlerMap> HANDLERS = new HashMap, HandlerMap>(); - - protected boolean needBlockUpdate = true; - - @Override - public void markForBlockUpdate() - { - needBlockUpdate = true; - } - - public boolean shouldMarkForBlockUpdate() - { - return true; - } - - private void doMarkForUpdate() - { - if (shouldMarkForBlockUpdate()) - { - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } - } - - protected void preMarkForUpdate() - { - - } - - @Override - public void updateEntity() - { - if (needBlockUpdate) - { - this.needBlockUpdate = false; - preMarkForUpdate(); - doMarkForUpdate(); - } - - super.updateEntity(); - } + protected static TileEventHandlerMap HANDLERS = new TileEventHandlerMap(); - protected void addHandler(@Nonnull HandlerMap handlerMap, @Nonnull EventHandler.EventType type, @Nonnull Method method) + public void markForUpdate() { - if (!handlerMap.containsKey(type)) - { - handlerMap.put(type, new ArrayList()); - } - handlerMap.get(type).add(new EventFunction(method)); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } - @SuppressWarnings({"unchecked", "rawtypes"}) - @Nonnull - protected HandlerMap getHandlersMap() + public void markDirtyAndUpdate() { - final Class klass = getClass(); - HandlerMap cached = HANDLERS.get(klass); - if (cached == null) - { - cached = new HandlerMap(); - HANDLERS.put(klass, cached); - for (Method method : klass.getMethods()) - { - final EventHandler anno = method.getAnnotation(EventHandler.class); - if (anno != null) addHandler(cached, anno.type(), method); - } - } - return cached; + markDirty(); + markForUpdate(); } - protected List getHandlersFor(@Nonnull EventHandler.EventType type) + protected List getHandlersFor(@Nonnull TileEventHandler.EventType event) { - return getHandlersMap().get(type); + return HANDLERS.getEventFunctionsForClass(getClass(), event); } @Override - public boolean writeToStream(ByteBuf stream) + public final boolean writeToStream(ByteBuf stream) { - final List handlers = getHandlersFor(EventHandler.EventType.NETWORK_WRITE); + final List handlers = getHandlersFor(TileEventHandler.EventType.NETWORK_WRITE); if (handlers != null) { - for (EventFunction func : handlers) + for (TileEventFunction func : handlers) { func.writeToStream(this, stream); } @@ -178,13 +109,13 @@ public Packet getDescriptionPacket() } @Override - public boolean readFromStream(ByteBuf stream) + public final boolean readFromStream(ByteBuf stream) { boolean shouldUpdate = false; - final List handlers = getHandlersFor(EventHandler.EventType.NETWORK_READ); + final List handlers = getHandlersFor(TileEventHandler.EventType.NETWORK_READ); if (handlers != null) { - for (EventFunction func : handlers) + for (TileEventFunction func : handlers) { if (func.readFromStream(this, stream)) { @@ -201,14 +132,16 @@ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) if (packet.func_148853_f() == 127) { final NBTTagCompound tag = packet.func_148857_g(); + boolean dirty = false; if (tag != null) { final ByteBuf stream = Unpooled.copiedBuffer(tag.getByteArray("P")); if (readFromStream(stream)) { - doMarkForUpdate(); + dirty = true; } } + if (dirty) markForUpdate(); } } @@ -219,4 +152,32 @@ public void readFromNBTForItem(NBTTagCompound tag) public void writeToNBTForItem(NBTTagCompound tag) { } + + @Override + public final void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + final List handlers = getHandlersFor(TileEventHandler.EventType.NBT_READ); + if (handlers != null) + { + for (TileEventFunction func : handlers) + { + func.readFromNBT(this, nbt); + } + } + } + + @Override + public final void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + final List handlers = getHandlersFor(TileEventHandler.EventType.NBT_WRITE); + if (handlers != null) + { + for (TileEventFunction func : handlers) + { + func.writeToNBT(this, nbt); + } + } + } } diff --git a/src/java/growthcraft/core/common/tileentity/GrcTileEntityDeviceBase.java b/src/java/growthcraft/core/common/tileentity/GrcTileDeviceBase.java similarity index 85% rename from src/java/growthcraft/core/common/tileentity/GrcTileEntityDeviceBase.java rename to src/java/growthcraft/core/common/tileentity/GrcTileDeviceBase.java index 5f1fb3f60..8b1b9e4e9 100644 --- a/src/java/growthcraft/core/common/tileentity/GrcTileEntityDeviceBase.java +++ b/src/java/growthcraft/core/common/tileentity/GrcTileDeviceBase.java @@ -28,7 +28,7 @@ import growthcraft.api.core.fluids.FluidTest; import growthcraft.core.common.tileentity.device.FluidTanks; import growthcraft.core.common.tileentity.device.IFluidTanks; -import growthcraft.core.common.tileentity.event.EventHandler; +import growthcraft.core.common.tileentity.event.TileEventHandler; import io.netty.buffer.ByteBuf; @@ -43,16 +43,20 @@ /** * Extend this base class if you want a base class with an `Inventory` and `Fluid Tanks` */ -public abstract class GrcTileEntityDeviceBase extends GrcTileEntityInventoryBase implements IFluidHandler, IFluidTanks +public abstract class GrcTileDeviceBase extends GrcTileInventoryBase implements IFluidHandler, IFluidTanks { private FluidTanks tanks; - public GrcTileEntityDeviceBase() + public GrcTileDeviceBase() { super(); this.tanks = new FluidTanks(createTanks()); } + protected void markFluidDirty() + { + } + protected FluidTank[] createTanks() { return new FluidTank[] {}; @@ -84,7 +88,7 @@ protected FluidStack doDrain(ForgeDirection dir, FluidStack stack, boolean shoul public FluidStack drain(ForgeDirection dir, int amount, boolean shouldDrain) { final FluidStack result = doDrain(dir, amount, shouldDrain); - if (shouldDrain && FluidTest.isValid(result)) markForFluidUpdate(); + if (shouldDrain && FluidTest.isValid(result)) markFluidDirty(); return result; } @@ -93,7 +97,7 @@ public FluidStack drain(ForgeDirection dir, FluidStack stack, boolean shouldDrai { if (!FluidTest.isValid(stack)) return null; final FluidStack result = doDrain(dir, stack, shouldDrain); - if (shouldDrain && FluidTest.isValid(result)) markForFluidUpdate(); + if (shouldDrain && FluidTest.isValid(result)) markFluidDirty(); return result; } @@ -106,7 +110,7 @@ protected int doFill(ForgeDirection dir, FluidStack stack, boolean shouldFill) public int fill(ForgeDirection dir, FluidStack stack, boolean shouldFill) { final int result = doFill(dir, stack, shouldFill); - if (shouldFill && result != 0) markForFluidUpdate(); + if (shouldFill && result != 0) markFluidDirty(); return result; } @@ -185,7 +189,7 @@ public FluidStack getFluidStack(int slot) public FluidStack drainFluidTank(int slot, int amount, boolean shouldDrain) { final FluidStack result = tanks.drainFluidTank(slot, amount, shouldDrain); - if (shouldDrain && FluidTest.isValid(result)) markForFluidUpdate(); + if (shouldDrain && FluidTest.isValid(result)) markFluidDirty(); return result; } @@ -193,7 +197,7 @@ public FluidStack drainFluidTank(int slot, int amount, boolean shouldDrain) public int fillFluidTank(int slot, FluidStack fluid, boolean shouldFill) { final int result = tanks.fillFluidTank(slot, fluid, shouldFill); - if (shouldFill && result != 0) markForFluidUpdate(); + if (shouldFill && result != 0) markFluidDirty(); return result; } @@ -201,7 +205,7 @@ public int fillFluidTank(int slot, FluidStack fluid, boolean shouldFill) public void setFluidStack(int slot, FluidStack stack) { tanks.setFluidStack(slot, stack); - markForFluidUpdate(); + markFluidDirty(); } @Override @@ -214,7 +218,7 @@ public Fluid getFluid(int slot) public void clearTank(int slot) { tanks.clearTank(slot); - markForFluidUpdate(); + markFluidDirty(); } protected void readTanksFromNBT(NBTTagCompound nbt) @@ -230,10 +234,9 @@ public void readFromNBTForItem(NBTTagCompound nbt) readTanksFromNBT(nbt); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_DeviceBase(NBTTagCompound nbt) { - super.readFromNBT(nbt); readTanksFromNBT(nbt); } @@ -250,14 +253,13 @@ public void writeToNBTForItem(NBTTagCompound nbt) writeTanksToNBT(nbt); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_DeviceBase(NBTTagCompound nbt) { - super.writeToNBT(nbt); writeTanksToNBT(nbt); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_FluidTanks(ByteBuf stream) throws IOException { if (tanks != null) @@ -265,7 +267,7 @@ public boolean readFromStream_FluidTanks(ByteBuf stream) throws IOException return true; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_FluidTanks(ByteBuf stream) throws IOException { if (tanks != null) diff --git a/src/java/growthcraft/core/common/tileentity/GrcTileEntityInventoryBase.java b/src/java/growthcraft/core/common/tileentity/GrcTileInventoryBase.java similarity index 89% rename from src/java/growthcraft/core/common/tileentity/GrcTileEntityInventoryBase.java rename to src/java/growthcraft/core/common/tileentity/GrcTileInventoryBase.java index 680277b18..917e7f34c 100644 --- a/src/java/growthcraft/core/common/tileentity/GrcTileEntityInventoryBase.java +++ b/src/java/growthcraft/core/common/tileentity/GrcTileInventoryBase.java @@ -24,9 +24,10 @@ package growthcraft.core.common.tileentity; import growthcraft.core.common.inventory.GrcInternalInventory; -import growthcraft.core.common.inventory.IInventoryFlagging; import growthcraft.core.common.inventory.IInventoryWatcher; import growthcraft.core.common.inventory.InventoryProcessor; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.ICustomDisplayName; import growthcraft.core.util.ItemUtils; import net.minecraft.entity.player.EntityPlayer; @@ -38,24 +39,29 @@ /** * Extend this base class if you want a Tile with an `Inventory` */ -public abstract class GrcTileEntityInventoryBase extends GrcTileEntityCommonBase implements ISidedInventory, ICustomDisplayName, IInventoryWatcher, IInventoryFlagging +public abstract class GrcTileInventoryBase extends GrcTileBase implements ISidedInventory, ICustomDisplayName, IInventoryWatcher { protected static final int[] NO_SLOTS = new int[]{}; protected String inventoryName; protected GrcInternalInventory inventory; - public GrcTileEntityInventoryBase() + public GrcTileInventoryBase() { super(); this.inventory = createInventory(); } - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 0); } + public GrcInternalInventory getInternalInventory() + { + return inventory; + } + public String getDefaultInventoryName() { return "grc.inventory.name"; @@ -64,7 +70,7 @@ public String getDefaultInventoryName() @Override public void onInventoryChanged(IInventory inv, int index) { - markForInventoryUpdate(); + markDirty(); } @Override @@ -187,7 +193,7 @@ public int[] getAccessibleSlotsFromSide(int side) return NO_SLOTS; } - private void readInventoryFromNBT(NBTTagCompound nbt) + protected void readInventoryFromNBT(NBTTagCompound nbt) { if (nbt.hasKey("items")) { @@ -220,10 +226,9 @@ public void readFromNBTForItem(NBTTagCompound nbt) //readInventoryNameFromNBT(nbt); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_Inventory(NBTTagCompound nbt) { - super.readFromNBT(nbt); readInventoryFromNBT(nbt); readInventoryNameFromNBT(nbt); } @@ -246,10 +251,9 @@ public void writeToNBTForItem(NBTTagCompound nbt) writeInventoryToNBT(nbt); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_Inventory(NBTTagCompound nbt) { - super.writeToNBT(nbt); writeInventoryToNBT(nbt); } } diff --git a/src/java/growthcraft/core/common/tileentity/device/DeviceBase.java b/src/java/growthcraft/core/common/tileentity/device/DeviceBase.java index 0ae30a3fa..8be52881d 100644 --- a/src/java/growthcraft/core/common/tileentity/device/DeviceBase.java +++ b/src/java/growthcraft/core/common/tileentity/device/DeviceBase.java @@ -29,8 +29,6 @@ import growthcraft.api.core.nbt.INBTSerializableContext; import growthcraft.api.core.stream.IStreamable; -import growthcraft.core.common.inventory.IInventoryFlagging; -import growthcraft.core.common.tileentity.IBlockUpdateFlagging; import net.minecraft.inventory.IInventory; import net.minecraft.world.World; @@ -59,7 +57,7 @@ public World getWorld() public int getMetadata() { - return getWorld().getBlockMetadata(parent.xCoord, parent.yCoord, parent.zCoord); + return parent.getBlockMetadata(); } public IInventory getInventory() @@ -71,20 +69,14 @@ public IInventory getInventory() return null; } - protected void markForBlockUpdate() + protected void markForUpdate() { - if (parent instanceof IBlockUpdateFlagging) - { - ((IBlockUpdateFlagging)parent).markForBlockUpdate(); - } + getWorld().markBlockForUpdate(parent.xCoord, parent.yCoord, parent.zCoord); } - protected void markForInventoryUpdate() + protected void markDirty() { - if (parent instanceof IInventoryFlagging) - { - ((IInventoryFlagging)parent).markForInventoryUpdate(); - } + parent.markDirty(); } /** diff --git a/src/java/growthcraft/core/common/tileentity/device/DeviceInventorySlot.java b/src/java/growthcraft/core/common/tileentity/device/DeviceInventorySlot.java index 4f7623cf9..919e9cb6f 100644 --- a/src/java/growthcraft/core/common/tileentity/device/DeviceInventorySlot.java +++ b/src/java/growthcraft/core/common/tileentity/device/DeviceInventorySlot.java @@ -41,11 +41,21 @@ public DeviceInventorySlot(IInventory inv, int idx) this.index = idx; } + /** + * Returns the current item in the slot, if any + * + * @return stack + */ public ItemStack get() { return inventory.getStackInSlot(index); } + /** + * The size of the ItemStack in the slot, if none is present the size is 0 + * + * @return size + */ public int getSize() { final ItemStack stack = get(); @@ -53,21 +63,48 @@ public int getSize() return stack.stackSize; } + /** + * Returns the total capacity of the slot. + * If an item occupies the slot then the stack's maxStackSize is returned + * + * @return capacity + */ public int getCapacity() { + final ItemStack stack = get(); + if (stack != null) + { + return stack.getMaxStackSize(); + } return inventory.getInventoryStackLimit(); } + /** + * Returns the current available capacity, that is the maxCapactity - current size + * + * @return available capacity + */ public int getAvailableCapacity() { return getCapacity() - getSize(); } + /** + * Set the stack for this slot + * + * @param newStack the stack to set + */ public void set(ItemStack newStack) { inventory.setInventorySlotContents(index, newStack); } + /** + * Is there any VALID item in this slot, where valid is an item with + * a stackSize greater than 0 + * + * @return true there is content, false otherwise + */ public boolean hasContent() { return getSize() > 0; @@ -83,6 +120,16 @@ public boolean isEmpty() return !hasContent(); } + /** + * Is this slot full? + * + * @return true, the slot is full, false otherwise + */ + public boolean isFull() + { + return getAvailableCapacity() <= 0; + } + /** * Does the provided stack match the one in the slot? * diff --git a/src/java/growthcraft/core/common/tileentity/event/EventFunction.java b/src/java/growthcraft/core/common/tileentity/event/TileEventFunction.java similarity index 77% rename from src/java/growthcraft/core/common/tileentity/event/EventFunction.java rename to src/java/growthcraft/core/common/tileentity/event/TileEventFunction.java index 1c9e2c812..5d37d5250 100644 --- a/src/java/growthcraft/core/common/tileentity/event/EventFunction.java +++ b/src/java/growthcraft/core/common/tileentity/event/TileEventFunction.java @@ -31,23 +31,22 @@ import growthcraft.api.core.stream.IStreamable; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.nbt.NBTTagCompound; -public class EventFunction +public class TileEventFunction { private Method method; - public EventFunction(@Nonnull Method m) + public TileEventFunction(@Nonnull Method m) { this.method = m; } - public boolean writeToStream(IStreamable tile, ByteBuf data) + private Object invoke2(Object a, Object b) { try { - return (Boolean)this.method.invoke(tile, data); + return this.method.invoke(a, b); } catch (IllegalAccessException e) { @@ -63,24 +62,23 @@ public boolean writeToStream(IStreamable tile, ByteBuf data) } } - @SideOnly (Side.CLIENT) + public void readFromNBT(Object tile, NBTTagCompound nbt) + { + invoke2(tile, nbt); + } + + public void writeToNBT(Object tile, NBTTagCompound nbt) + { + invoke2(tile, nbt); + } + + public boolean writeToStream(IStreamable tile, ByteBuf data) + { + return (Boolean)invoke2(tile, data); + } + public boolean readFromStream(IStreamable tile, ByteBuf data) { - try - { - return (Boolean)this.method.invoke(tile, data); - } - catch (IllegalAccessException e) - { - throw new IllegalStateException(e); - } - catch (IllegalArgumentException e) - { - throw new IllegalStateException(e); - } - catch (InvocationTargetException e) - { - throw new IllegalStateException(e); - } + return (Boolean)invoke2(tile, data); } } diff --git a/src/java/growthcraft/core/common/tileentity/event/TileEventFunctionMap.java b/src/java/growthcraft/core/common/tileentity/event/TileEventFunctionMap.java new file mode 100644 index 000000000..7e38af406 --- /dev/null +++ b/src/java/growthcraft/core/common/tileentity/event/TileEventFunctionMap.java @@ -0,0 +1,37 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core.common.tileentity.event; + +import java.util.EnumMap; +import java.util.List; + +public class TileEventFunctionMap extends EnumMap> +{ + public static final long serialVersionUID = 1L; + + public TileEventFunctionMap() + { + super(TileEventHandler.EventType.class); + } +} diff --git a/src/java/growthcraft/core/common/tileentity/event/EventHandler.java b/src/java/growthcraft/core/common/tileentity/event/TileEventHandler.java similarity index 94% rename from src/java/growthcraft/core/common/tileentity/event/EventHandler.java rename to src/java/growthcraft/core/common/tileentity/event/TileEventHandler.java index fb0923c98..18651901e 100644 --- a/src/java/growthcraft/core/common/tileentity/event/EventHandler.java +++ b/src/java/growthcraft/core/common/tileentity/event/TileEventHandler.java @@ -30,7 +30,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface EventHandler +public @interface TileEventHandler { public static enum EventType { @@ -38,8 +38,10 @@ public static enum EventType GUI_NETWORK_WRITE, GUI_NETWORK_READ, NETWORK_WRITE, - NETWORK_READ; + NETWORK_READ, + NBT_WRITE, + NBT_READ; } - EventType type(); + EventType event(); } diff --git a/src/java/growthcraft/core/common/tileentity/event/TileEventHandlerMap.java b/src/java/growthcraft/core/common/tileentity/event/TileEventHandlerMap.java new file mode 100644 index 000000000..6d8846dee --- /dev/null +++ b/src/java/growthcraft/core/common/tileentity/event/TileEventHandlerMap.java @@ -0,0 +1,67 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core.common.tileentity.event; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import javax.annotation.Nonnull; + +import net.minecraft.tileentity.TileEntity; + +public class TileEventHandlerMap extends HashMap, TileEventFunctionMap> +{ + public static final long serialVersionUID = 1L; + + protected void addHandlerEventFunction(@Nonnull TileEventFunctionMap handlerMap, @Nonnull TileEventHandler.EventType type, @Nonnull Method method) + { + if (!handlerMap.containsKey(type)) + { + handlerMap.put(type, new ArrayList()); + } + handlerMap.get(type).add(new TileEventFunction(method)); + } + + public TileEventFunctionMap getEventFunctionMap(Class klass) + { + TileEventFunctionMap cached = get(klass); + if (cached == null) + { + cached = new TileEventFunctionMap(); + put(klass, cached); + for (Method method : klass.getMethods()) + { + final TileEventHandler anno = method.getAnnotation(TileEventHandler.class); + if (anno != null) addHandlerEventFunction(cached, anno.event(), method); + } + } + return cached; + } + + public List getEventFunctionsForClass(Class klass, TileEventHandler.EventType type) + { + return getEventFunctionMap(klass).get(type); + } +} diff --git a/src/java/growthcraft/core/common/tileentity/ICustomDisplayName.java b/src/java/growthcraft/core/common/tileentity/feature/ICustomDisplayName.java similarity index 95% rename from src/java/growthcraft/core/common/tileentity/ICustomDisplayName.java rename to src/java/growthcraft/core/common/tileentity/feature/ICustomDisplayName.java index 6bac52864..cc233bbfa 100644 --- a/src/java/growthcraft/core/common/tileentity/ICustomDisplayName.java +++ b/src/java/growthcraft/core/common/tileentity/feature/ICustomDisplayName.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; public interface ICustomDisplayName { diff --git a/src/java/growthcraft/core/common/tileentity/IGuiNetworkSync.java b/src/java/growthcraft/core/common/tileentity/feature/IGuiNetworkSync.java similarity index 96% rename from src/java/growthcraft/core/common/tileentity/IGuiNetworkSync.java rename to src/java/growthcraft/core/common/tileentity/feature/IGuiNetworkSync.java index 0ad0b1ad6..4932198df 100644 --- a/src/java/growthcraft/core/common/tileentity/IGuiNetworkSync.java +++ b/src/java/growthcraft/core/common/tileentity/feature/IGuiNetworkSync.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Container; diff --git a/src/java/growthcraft/core/common/tileentity/feature/IInteractionObject.java b/src/java/growthcraft/core/common/tileentity/feature/IInteractionObject.java new file mode 100644 index 000000000..0d45c49a0 --- /dev/null +++ b/src/java/growthcraft/core/common/tileentity/feature/IInteractionObject.java @@ -0,0 +1,37 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.core.common.tileentity.feature; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; + +/** + * Backport from Minecraft 1.8.9 + */ +public interface IInteractionObject +{ + Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn); + String getGuiID(); +} diff --git a/src/java/growthcraft/core/common/tileentity/IItemHandler.java b/src/java/growthcraft/core/common/tileentity/feature/IItemHandler.java similarity index 78% rename from src/java/growthcraft/core/common/tileentity/IItemHandler.java rename to src/java/growthcraft/core/common/tileentity/feature/IItemHandler.java index 6c8e65d82..d3fe1f3e5 100644 --- a/src/java/growthcraft/core/common/tileentity/IItemHandler.java +++ b/src/java/growthcraft/core/common/tileentity/feature/IItemHandler.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -31,23 +31,33 @@ public interface IItemHandler { + public static enum Action + { + // Player used the right click (onBlockActivated) + RIGHT, + // Player used the left click (onBlockClicked) + LEFT; + } + /** * Tries to place the item from the player into the target * + * @param action - whether it was a left click or right click * @param player - the player placing the item * @param stack - the item stack being placed * @return true, if something happened, eg. item was inserted, false otherwise */ - boolean tryPlaceItem(@Nonnull EntityPlayer player, @Nullable ItemStack stack); + boolean tryPlaceItem(@Nonnull Action action, @Nonnull EntityPlayer player, @Nullable ItemStack stack); /** * Tries to remove an item from the target * The stack provided is the player's current item stack, this can be safely * ignored, OR changes the behaviour of the target. * + * @param action - whether it was a left click or right click * @param player - player taking the item * @param stack - stack on player's hand currently * @return true, an item was taken, false otherwise */ - boolean tryTakeItem(@Nonnull EntityPlayer player, @Nullable ItemStack stack); + boolean tryTakeItem(@Nonnull Action action, @Nonnull EntityPlayer player, @Nullable ItemStack stack); } diff --git a/src/java/growthcraft/core/common/tileentity/ITileHeatedDevice.java b/src/java/growthcraft/core/common/tileentity/feature/ITileHeatedDevice.java similarity index 96% rename from src/java/growthcraft/core/common/tileentity/ITileHeatedDevice.java rename to src/java/growthcraft/core/common/tileentity/feature/ITileHeatedDevice.java index 270c598c3..cdc56aea4 100644 --- a/src/java/growthcraft/core/common/tileentity/ITileHeatedDevice.java +++ b/src/java/growthcraft/core/common/tileentity/feature/ITileHeatedDevice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; public interface ITileHeatedDevice { diff --git a/src/java/growthcraft/core/common/tileentity/ITileNamedFluidTanks.java b/src/java/growthcraft/core/common/tileentity/feature/ITileNamedFluidTanks.java similarity index 96% rename from src/java/growthcraft/core/common/tileentity/ITileNamedFluidTanks.java rename to src/java/growthcraft/core/common/tileentity/feature/ITileNamedFluidTanks.java index 52d4cbd5f..632b03db4 100644 --- a/src/java/growthcraft/core/common/tileentity/ITileNamedFluidTanks.java +++ b/src/java/growthcraft/core/common/tileentity/feature/ITileNamedFluidTanks.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/java/growthcraft/core/common/tileentity/ITileProgressiveDevice.java b/src/java/growthcraft/core/common/tileentity/feature/ITileProgressiveDevice.java similarity index 96% rename from src/java/growthcraft/core/common/tileentity/ITileProgressiveDevice.java rename to src/java/growthcraft/core/common/tileentity/feature/ITileProgressiveDevice.java index 7c246727f..a1c270f8f 100644 --- a/src/java/growthcraft/core/common/tileentity/ITileProgressiveDevice.java +++ b/src/java/growthcraft/core/common/tileentity/feature/ITileProgressiveDevice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -package growthcraft.core.common.tileentity; +package growthcraft.core.common.tileentity.feature; public interface ITileProgressiveDevice { diff --git a/src/java/growthcraft/core/init/GrcCoreBlocks.java b/src/java/growthcraft/core/init/GrcCoreBlocks.java index 42c10a108..8ea3de67a 100644 --- a/src/java/growthcraft/core/init/GrcCoreBlocks.java +++ b/src/java/growthcraft/core/init/GrcCoreBlocks.java @@ -30,7 +30,7 @@ import growthcraft.core.common.block.BlockRope; import growthcraft.core.common.block.BlockSaltBlock; import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleBlocks; import growthcraft.core.common.item.ItemBlockFenceRope; import growthcraft.core.common.item.ItemBlockNaturaFenceRope; import growthcraft.core.integration.minecraft.EnumMinecraftWoodType; @@ -44,7 +44,7 @@ import net.minecraft.init.Blocks; import net.minecraftforge.oredict.OreDictionary; -public class GrcCoreBlocks extends GrcModuleBase +public class GrcCoreBlocks extends GrcModuleBlocks { public BlockDefinition ropeBlock; public BlockDefinition saltBlock; @@ -57,10 +57,10 @@ public class GrcCoreBlocks extends GrcModuleBase @Override public void preInit() { - this.saltBlock = new BlockDefinition(new BlockSaltBlock()); - this.ropeBlock = new BlockDefinition(new BlockRope()); - this.fenceRope = new BlockDefinition(new BlockFenceRope(Blocks.fence, "grc.fenceRope")); - this.netherBrickFenceRope = new BlockDefinition(new BlockFenceRope(Blocks.nether_brick_fence, "grc.netherBrickFenceRope")); + this.saltBlock = newDefinition(new BlockSaltBlock()); + this.ropeBlock = newDefinition(new BlockRope()); + this.fenceRope = newDefinition(new BlockFenceRope(Blocks.fence, "grc.fenceRope")); + this.netherBrickFenceRope = newDefinition(new BlockFenceRope(Blocks.nether_brick_fence, "grc.netherBrickFenceRope")); FenceRopeRegistry.instance().addEntry(Blocks.fence, fenceRope.getBlock()); FenceRopeRegistry.instance().addEntry(Blocks.nether_brick_fence, netherBrickFenceRope.getBlock()); @@ -89,7 +89,7 @@ private void initEtfuturum() if (block != null) { final String basename = "grc.etfuturum_fence_rope_" + woodTypeName; - final BlockDefinition fp = new BlockDefinition(new BlockFenceRope(block, basename)); + final BlockDefinition fp = newDefinition(new BlockFenceRope(block, basename)); fp.register(basename, ItemBlockFenceRope.class); Blocks.fire.setFireInfo(fp.getBlock(), 5, 20); FenceRopeRegistry.instance().addEntry(block, fp.getBlock()); @@ -157,7 +157,7 @@ private void initNatura() final Block block = GameRegistry.findBlock(modId, "Natura.fence"); if (block != null) { - this.naturaFenceRope = new BlockDefinition(new BlockFenceRope(block, "grc.naturaFenceRope")); + this.naturaFenceRope = newDefinition(new BlockFenceRope(block, "grc.naturaFenceRope")); naturaFenceRope.register("grc.naturaFenceRope", ItemBlockNaturaFenceRope.class); Blocks.fire.setFireInfo(naturaFenceRope.getBlock(), 5, 20); FenceRopeRegistry.instance().addEntry(block, naturaFenceRope.getBlock()); diff --git a/src/java/growthcraft/core/init/GrcCoreItems.java b/src/java/growthcraft/core/init/GrcCoreItems.java index 7b0b89d06..5633d9d36 100644 --- a/src/java/growthcraft/core/init/GrcCoreItems.java +++ b/src/java/growthcraft/core/init/GrcCoreItems.java @@ -24,7 +24,7 @@ package growthcraft.core.init; import growthcraft.core.common.definition.ItemDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleItems; import growthcraft.core.common.item.ItemBottleSalt; import growthcraft.core.common.item.ItemBucketSalt; import growthcraft.core.common.item.ItemCrowbar; @@ -33,7 +33,7 @@ import net.minecraftforge.oredict.OreDictionary; -public class GrcCoreItems extends GrcModuleBase +public class GrcCoreItems extends GrcModuleItems { public ItemDefinition rope; public ItemDefinition salt; @@ -44,11 +44,11 @@ public class GrcCoreItems extends GrcModuleBase @Override public void preInit() { - this.rope = new ItemDefinition(new ItemRope()); - this.salt = new ItemDefinition(new ItemSalt()); - this.saltBottle = new ItemDefinition(new ItemBottleSalt()); - this.saltBucket = new ItemDefinition(new ItemBucketSalt()); - this.crowbar = new ItemDefinition(new ItemCrowbar()); + this.rope = newDefinition(new ItemRope()); + this.salt = newDefinition(new ItemSalt()); + this.saltBottle = newDefinition(new ItemBottleSalt()); + this.saltBucket = newDefinition(new ItemBucketSalt()); + this.crowbar = newDefinition(new ItemCrowbar()); } @Override diff --git a/src/java/growthcraft/core/integration/ModIntegrationBase.java b/src/java/growthcraft/core/integration/ModIntegrationBase.java index 4bdf4d50c..80060506a 100644 --- a/src/java/growthcraft/core/integration/ModIntegrationBase.java +++ b/src/java/growthcraft/core/integration/ModIntegrationBase.java @@ -26,7 +26,9 @@ import growthcraft.core.common.GrcModuleBase; import growthcraft.core.util.Platform; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; /** * Base class for integrating other mods with Growthcraft, this idea was @@ -49,6 +51,12 @@ public boolean modIsLoaded() return modLoaded; } + public String getModTag() + { + final ModContainer cont = FMLCommonHandler.instance().findContainerFor(modID); + return String.format("%s [%s]", modID, cont != null ? cont.getVersion() : "NOT LOADED"); + } + protected void doPreInit() { @@ -60,7 +68,7 @@ public final void preInit() this.modLoaded = Loader.isModLoaded(modID); if (modIsLoaded()) { - logger.debug("preInit " + modID); + logger.debug("preInit " + getModTag()); doPreInit(); } } @@ -75,7 +83,7 @@ public final void init() { if (modIsLoaded()) { - logger.debug("init " + modID); + logger.debug("init " + getModTag()); doInit(); } } @@ -93,7 +101,7 @@ public final void register() { if (modIsLoaded()) { - logger.debug("register " + modID); + logger.debug("register " + getModTag()); doRegister(); } } @@ -115,7 +123,7 @@ public final void postInit() { if (modIsLoaded()) { - logger.debug("postInit " + modID); + logger.debug("postInit " + getModTag()); doPostInit(); doLateRegister(); } @@ -144,7 +152,7 @@ public void tryToIntegrate() { if (modIsLoaded()) { - logger.debug("Attemping to integrate with %s.", modID); + logger.debug("Attemping to integrate with %s.", getModTag()); try { if (Platform.isClient()) @@ -156,16 +164,16 @@ public void tryToIntegrate() integrateServer(); } integrate(); - logger.debug("Successfully integrated with %s.", modID); + logger.debug("Successfully integrated with %s.", getModTag()); } catch (Exception e) { - logger.warn("%s integration failed.", modID); + logger.warn("%s integration failed.", getModTag()); } } else { - logger.debug("%s not found; No integration made.", modID); + logger.debug("%s not found; No integration made.", getModTag()); } } } diff --git a/src/java/growthcraft/core/integration/mfr/AbstractFactoryFruit.java b/src/java/growthcraft/core/integration/mfr/AbstractFactoryFruit.java index fbc81b8df..8211d7b7a 100644 --- a/src/java/growthcraft/core/integration/mfr/AbstractFactoryFruit.java +++ b/src/java/growthcraft/core/integration/mfr/AbstractFactoryFruit.java @@ -42,7 +42,7 @@ public abstract class AbstractFactoryFruit implements IFac { protected TBlock plantBlock; - public AbstractFactoryFruit setPlant(TBlock pBlock) + public AbstractFactoryFruit setPlant(TBlock pBlock) { this.plantBlock = pBlock; return this; diff --git a/src/java/growthcraft/core/integration/mfr/AbstractFactoryHarvestable.java b/src/java/growthcraft/core/integration/mfr/AbstractFactoryHarvestable.java index fbaa07f89..285501ccf 100644 --- a/src/java/growthcraft/core/integration/mfr/AbstractFactoryHarvestable.java +++ b/src/java/growthcraft/core/integration/mfr/AbstractFactoryHarvestable.java @@ -44,14 +44,14 @@ public abstract class AbstractFactoryHarvestable implement protected TBlock plantBlock; protected HarvestType type = HarvestType.Normal; - public AbstractFactoryHarvestable setPlant(TBlock pBlock) + public AbstractFactoryHarvestable setPlant(TBlock pBlock) { this.plantBlock = pBlock; return this; } @Optional.Method(modid=MFRModuleBase.MOD_ID) - public AbstractFactoryHarvestable setHarvestType(HarvestType pType) + public AbstractFactoryHarvestable setHarvestType(HarvestType pType) { this.type = pType; return this; diff --git a/src/java/growthcraft/core/integration/waila/CoreDataProvider.java b/src/java/growthcraft/core/integration/waila/CoreDataProvider.java index 0d99d4550..e76621b25 100644 --- a/src/java/growthcraft/core/integration/waila/CoreDataProvider.java +++ b/src/java/growthcraft/core/integration/waila/CoreDataProvider.java @@ -27,9 +27,9 @@ import growthcraft.api.core.i18n.GrcI18n; import growthcraft.api.core.nbt.NBTHelper; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; -import growthcraft.core.common.tileentity.ITileHeatedDevice; -import growthcraft.core.common.tileentity.ITileNamedFluidTanks; +import growthcraft.core.common.tileentity.feature.ITileHeatedDevice; +import growthcraft.core.common.tileentity.feature.ITileNamedFluidTanks; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; import growthcraft.core.util.TagFormatterFluidHandler; import cpw.mods.fml.common.Optional; diff --git a/src/java/growthcraft/core/util/GameRegistryDumper.java b/src/java/growthcraft/core/util/GameRegistryDumper.java index 5dd4c3eaf..35bebc257 100644 --- a/src/java/growthcraft/core/util/GameRegistryDumper.java +++ b/src/java/growthcraft/core/util/GameRegistryDumper.java @@ -30,12 +30,15 @@ import java.util.List; import java.util.Set; +import growthcraft.api.core.util.StringUtils; import growthcraft.core.GrowthCraftCore; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.fluids.FluidRegistry; /** @@ -192,10 +195,33 @@ public static void dumpFluids() } } + public static void dumpBiomes() + { + final BiomeGenBase[] biomes = BiomeGenBase.getBiomeGenArray(); + try (FileWriter writer = new FileWriter("dumps/Biomes_dump.txt")) + { + writer.write("Biome ID, Name, [TYPES...]\n"); + for (BiomeGenBase biome : biomes) + { + if (biome == null) continue; + writer.write(String.format("%d,%s,%s\n", + biome.biomeID, + biome.biomeName, + StringUtils.inspect(BiomeDictionary.getTypesForBiome(biome)) + )); + } + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + public static void run() { dumpBlocks(); dumpItems(); dumpFluids(); + dumpBiomes(); } } diff --git a/src/java/growthcraft/fishtrap/GrowthCraftFishTrap.java b/src/java/growthcraft/fishtrap/GrowthCraftFishTrap.java index cc2578d74..f1959ada2 100644 --- a/src/java/growthcraft/fishtrap/GrowthCraftFishTrap.java +++ b/src/java/growthcraft/fishtrap/GrowthCraftFishTrap.java @@ -4,9 +4,11 @@ import growthcraft.api.core.log.ILogger; import growthcraft.api.core.module.ModuleContainer; import growthcraft.api.fishtrap.FishTrapEntry; +import growthcraft.api.fishtrap.user.UserBaitConfig; +import growthcraft.api.fishtrap.user.UserCatchGroupConfig; import growthcraft.api.fishtrap.user.UserFishTrapConfig; import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.fishtrap.client.gui.GuiHandlerFishTrap; +import growthcraft.core.GrcGuiProvider; import growthcraft.fishtrap.common.block.BlockFishTrap; import growthcraft.fishtrap.common.CommonProxy; import growthcraft.fishtrap.common.tileentity.TileEntityFishTrap; @@ -39,37 +41,42 @@ public class GrowthCraftFishTrap @Instance(MOD_ID) public static GrowthCraftFishTrap instance; - public static BlockDefinition fishTrap; + public static final GrcGuiProvider guiProvider = new GrcGuiProvider(new GrcLogger(MOD_ID + ":GuiProvider")); - private ILogger logger = new GrcLogger(MOD_ID); - private GrcFishtrapConfig config = new GrcFishtrapConfig(); - private ModuleContainer modules = new ModuleContainer(); - private UserFishTrapConfig userFishTrapConfig = new UserFishTrapConfig(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcFishtrapConfig config = new GrcFishtrapConfig(); + private final ModuleContainer modules = new ModuleContainer(); + private final UserBaitConfig userBaitConfig = new UserBaitConfig(); + private final UserCatchGroupConfig userCatchGroupConfig = new UserCatchGroupConfig(); + private final UserFishTrapConfig userFishTrapConfig = new UserFishTrapConfig(); public static GrcFishtrapConfig getConfig() { return instance.config; } + public static ILogger getLogger() + { + return instance.logger; + } + @EventHandler - public void preload(FMLPreInitializationEvent event) + public void preInit(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/fishtrap.conf"); - + userBaitConfig.setConfigFile(event.getModConfigurationDirectory(), "growthcraft/fishtrap/baits.json"); + userCatchGroupConfig.setConfigFile(event.getModConfigurationDirectory(), "growthcraft/fishtrap/catch_groups.json"); userFishTrapConfig.setConfigFile(event.getModConfigurationDirectory(), "growthcraft/fishtrap/entries.json"); + modules.add(userBaitConfig); + modules.add(userCatchGroupConfig); modules.add(userFishTrapConfig); - if (config.enableThaumcraftIntegration) modules.add(new growthcraft.fishtrap.integration.ThaumcraftModule()); - + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); - - //==================== - // INIT - //==================== + modules.freeze(); fishTrap = new BlockDefinition(new BlockFishTrap()); - modules.preInit(); register(); } @@ -83,8 +90,18 @@ private void register() GameRegistry.registerTileEntity(TileEntityFishTrap.class, "grc.tileentity.fishTrap"); + // Gives a +0.2 bonus on base and a 1.1f bonus multiplier + userBaitConfig.addDefault(new ItemStack(Items.rotten_flesh), 0.2f, 1.1f); + + // Catch Groups + userCatchGroupConfig.addDefault("junk", 3, "Useless Stuff"); + userCatchGroupConfig.addDefault("treasure", 5, "Fancy Stuff"); + userCatchGroupConfig.addDefault("fish", 1, "Fishes"); + userCatchGroupConfig.addDefault("mineral", 7, "Ingots and other metallic stuff"); + userCatchGroupConfig.addDefault("legendary", 10, "Stuff you probably would never find on average"); + // Will use same chances as Fishing Rods - //JUNK + // Junk userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.leather_boots), 10).setDamage(0.9F)); userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.leather), 10)); userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.bone), 10)); @@ -94,20 +111,26 @@ private void register() userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.bowl), 10)); userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.stick), 5)); userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.dye, 10), 1)); - userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Blocks.tripwire_hook), 10)); userFishTrapConfig.addDefault("junk", new FishTrapEntry(new ItemStack(Items.rotten_flesh), 10)); - //TREASURE + // Treasure userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Blocks.waterlily), 1)); userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Items.name_tag), 1)); userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Items.saddle), 1)); userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Items.bow), 1).setDamage(0.25F).setEnchantable()); userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Items.fishing_rod), 1).setDamage(0.25F).setEnchantable()); userFishTrapConfig.addDefault("treasure", new FishTrapEntry(new ItemStack(Items.book), 1).setEnchantable()); - //FISH + // Fishes userFishTrapConfig.addDefault("fish", new FishTrapEntry(new ItemStack(Items.fish, 1, ItemFishFood.FishType.COD.func_150976_a()), 60)); userFishTrapConfig.addDefault("fish", new FishTrapEntry(new ItemStack(Items.fish, 1, ItemFishFood.FishType.SALMON.func_150976_a()), 25)); userFishTrapConfig.addDefault("fish", new FishTrapEntry(new ItemStack(Items.fish, 1, ItemFishFood.FishType.CLOWNFISH.func_150976_a()), 2)); userFishTrapConfig.addDefault("fish", new FishTrapEntry(new ItemStack(Items.fish, 1, ItemFishFood.FishType.PUFFERFISH.func_150976_a()), 13)); + // Minerals + userFishTrapConfig.addDefault("mineral", new FishTrapEntry(new ItemStack(Blocks.tripwire_hook), 1)); + userFishTrapConfig.addDefault("mineral", new FishTrapEntry(new ItemStack(Items.iron_ingot), 10)); + userFishTrapConfig.addDefault("mineral", new FishTrapEntry(new ItemStack(Items.gold_nugget), 5)); + // Legendary + userFishTrapConfig.addDefault("legendary", new FishTrapEntry(new ItemStack(Items.gold_ingot), 1)); + userFishTrapConfig.addDefault("legendary", new FishTrapEntry(new ItemStack(Items.diamond), 10)); //==================== // CRAFTING @@ -118,18 +141,17 @@ private void register() } @EventHandler - public void load(FMLInitializationEvent event) + public void init(FMLInitializationEvent event) { + userBaitConfig.loadUserConfig(); + userCatchGroupConfig.loadUserConfig(); userFishTrapConfig.loadUserConfig(); - CommonProxy.instance.initRenders(); - - NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerFishTrap()); - + NetworkRegistry.INSTANCE.registerGuiHandler(this, guiProvider); modules.init(); } @EventHandler - public void postload(FMLPostInitializationEvent event) + public void postInit(FMLPostInitializationEvent event) { modules.postInit(); } diff --git a/src/java/growthcraft/fishtrap/client/ClientProxy.java b/src/java/growthcraft/fishtrap/client/ClientProxy.java index 0de139717..b83d0b65b 100644 --- a/src/java/growthcraft/fishtrap/client/ClientProxy.java +++ b/src/java/growthcraft/fishtrap/client/ClientProxy.java @@ -1,12 +1,38 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.fishtrap.client; +import growthcraft.fishtrap.client.gui.GuiFishTrap; import growthcraft.fishtrap.common.CommonProxy; +import growthcraft.fishtrap.GrowthCraftFishTrap; public class ClientProxy extends CommonProxy { @Override - public void initRenders() + public void init() { - //RenderingRegistry.registerBlockHandler(new RenderFishTrap()); + super.init(); + GrowthCraftFishTrap.guiProvider.register("grcfishtrap:fish_trap", GuiFishTrap.class); } } diff --git a/src/java/growthcraft/fishtrap/client/gui/GuiFishTrap.java b/src/java/growthcraft/fishtrap/client/gui/GuiFishTrap.java index 1c3fa878f..fe067cabd 100644 --- a/src/java/growthcraft/fishtrap/client/gui/GuiFishTrap.java +++ b/src/java/growthcraft/fishtrap/client/gui/GuiFishTrap.java @@ -1,44 +1,23 @@ package growthcraft.fishtrap.client.gui; -import growthcraft.api.core.i18n.GrcI18n; +import growthcraft.core.client.gui.GrcGuiContainer; import growthcraft.fishtrap.common.inventory.ContainerFishTrap; import growthcraft.fishtrap.common.tileentity.TileEntityFishTrap; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) -public class GuiFishTrap extends GuiContainer +public class GuiFishTrap extends GrcGuiContainer { private static final ResourceLocation res = new ResourceLocation("grcfishtrap" , "textures/guis/fishtrap_gui.png"); private TileEntityFishTrap te; public GuiFishTrap(InventoryPlayer inv, TileEntityFishTrap fishTrap) { - super(new ContainerFishTrap(inv, fishTrap)); - this.te = fishTrap; + super(res, new ContainerFishTrap(inv, fishTrap), fishTrap); this.ySize = 133; } - - @Override - protected void drawGuiContainerForegroundLayer(int par1, int par2) - { - final String s = this.te.hasCustomInventoryName() ? this.te.getInventoryName() : GrcI18n.translate(this.te.getInventoryName()); - this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); - this.fontRendererObj.drawString(GrcI18n.translate("container.inventory"), 8, this.ySize - 96 + 2, 4210752); - } - - @Override - protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) - { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(res); - final int w = (this.width - this.xSize) / 2; - final int h = (this.height - this.ySize) / 2; - this.drawTexturedModalRect(w, h, 0, 0, this.xSize, this.ySize); - } } diff --git a/src/java/growthcraft/fishtrap/client/gui/GuiHandlerFishTrap.java b/src/java/growthcraft/fishtrap/client/gui/GuiHandlerFishTrap.java deleted file mode 100644 index ff22410db..000000000 --- a/src/java/growthcraft/fishtrap/client/gui/GuiHandlerFishTrap.java +++ /dev/null @@ -1,38 +0,0 @@ -package growthcraft.fishtrap.client.gui; - -import growthcraft.fishtrap.common.inventory.ContainerFishTrap; -import growthcraft.fishtrap.common.tileentity.TileEntityFishTrap; - -import cpw.mods.fml.common.network.IGuiHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; - -public class GuiHandlerFishTrap implements IGuiHandler -{ - @Override - public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityFishTrap) - { - return new ContainerFishTrap(player.inventory, (TileEntityFishTrap)te); - } - - return null; - } - - @Override - public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) - { - final TileEntity te = world.getTileEntity(x, y, z); - - if (te instanceof TileEntityFishTrap) - { - return new GuiFishTrap(player.inventory, (TileEntityFishTrap)te); - } - - return null; - } -} diff --git a/src/java/growthcraft/fishtrap/common/CommonProxy.java b/src/java/growthcraft/fishtrap/common/CommonProxy.java index 86f8c25c9..a8edba094 100644 --- a/src/java/growthcraft/fishtrap/common/CommonProxy.java +++ b/src/java/growthcraft/fishtrap/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.fishtrap.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.fishtrap.client.ClientProxy", serverSide="growthcraft.fishtrap.common.CommonProxy") public static CommonProxy instance; - - public void initRenders(){} } diff --git a/src/java/growthcraft/fishtrap/common/block/BlockFishTrap.java b/src/java/growthcraft/fishtrap/common/block/BlockFishTrap.java index 7344b1035..477154442 100644 --- a/src/java/growthcraft/fishtrap/common/block/BlockFishTrap.java +++ b/src/java/growthcraft/fishtrap/common/block/BlockFishTrap.java @@ -1,10 +1,35 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) < 2014, Gwafu + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.fishtrap.common.block; import java.util.Random; import growthcraft.api.fishtrap.FishTrapRegistry; -import growthcraft.core.GrowthCraftCore; import growthcraft.core.common.block.GrcBlockContainer; +import growthcraft.core.common.tileentity.feature.IInteractionObject; +import growthcraft.core.GrowthCraftCore; import growthcraft.core.util.BlockCheck; import growthcraft.core.Utils; import growthcraft.fishtrap.common.tileentity.TileEntityFishTrap; @@ -18,9 +43,9 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.biome.BiomeGenBase; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.BiomeDictionary.Type; import net.minecraftforge.common.BiomeDictionary; @@ -44,8 +69,53 @@ public BlockFishTrap() setCreativeTab(GrowthCraftCore.creativeTab); } + protected boolean openGui(EntityPlayer player, World world, int x, int y, int z) + { + final TileEntity te = getTileEntity(world, x, y, z); + if (te instanceof IInteractionObject) + { + player.openGui(GrowthCraftFishTrap.instance, 0, world, x, y, z); + return true; + } + return false; + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float par7, float par8, float par9) + { + if (super.onBlockActivated(world, x, y, z, player, meta, par7, par8, par9)) return true; + return !player.isSneaking() && openGui(player, world, x, y, z); + } + + private boolean isWater(Block block) + { + return BlockCheck.isWater(block); + } + + private float applyBiomeCatchModifier(World world, int x, int y, int z, float f) + { + boolean isInWaterBiome; + if (GrowthCraftFishTrap.getConfig().useBiomeDict) + { + final BiomeGenBase biome = world.getBiomeGenForCoords(x, z); + isInWaterBiome = BiomeDictionary.isBiomeOfType(biome, Type.WATER); + } + else + { + isInWaterBiome = Utils.isIDInList(world.getBiomeGenForCoords(x, z).biomeID, GrowthCraftFishTrap.getConfig().biomesList); + } + + if (isInWaterBiome) + { + f *= 1.75; + } + return f; + } + private float getCatchRate(World world, int x, int y, int z) { + final TileEntityFishTrap te = getTileEntity(world, x, y, z); + if (te == null) return 0.0f; final int checkSize = 3; final int i = x - ((checkSize - 1) / 2); final int j = y - ((checkSize - 1) / 2); @@ -75,63 +145,39 @@ private float getCatchRate(World world, int x, int y, int z) } } } - - return f; + f = applyBiomeCatchModifier(world, x, y, z, f); + return te.applyBaitModifier(f); } - private void doCatch(World world, int x, int y, int z, Random random, TileEntityFishTrap te, boolean debugFlag) + protected ItemStack pickCatch(World world, int x, int y, int z) { - float f = this.getCatchRate(world, x, y, z); - boolean flag; - if (GrowthCraftFishTrap.getConfig().useBiomeDict) - { - final BiomeGenBase biome = world.getBiomeGenForCoords(x, z); - flag = BiomeDictionary.isBiomeOfType(biome, Type.WATER); - } - else - { - flag = Utils.isIDInList(world.getBiomeGenForCoords(x, z).biomeID, GrowthCraftFishTrap.getConfig().biomesList); - } - - if (flag) - { - f *= 1 + (75 / 100); - } + final String catchGroup = FishTrapRegistry.instance().getRandomCatchGroup(world.rand); + GrowthCraftFishTrap.getLogger().debug("Picking Catch from group=%s x=%d y=%d z=%d dimension=%d", catchGroup, x, y, z, world.provider.dimensionId); + return FishTrapRegistry.instance().getRandomCatchFromGroup(world.rand, catchGroup); + } - if (random.nextInt((int)(this.chance / f) + 1) == 0 || debugFlag) + protected void doCatch(World world, int x, int y, int z, TileEntityFishTrap te) + { + final ItemStack item = pickCatch(world, x, y, z); + if (item != null) { - final ItemStack item = pickCatch(world); - if (item != null) + GrowthCraftFishTrap.getLogger().debug("Attempting to add item to inventory x=%d y=%d z=%d dimension=%d item=%s", x, y, z, world.provider.dimensionId, item); + if (te.addStack(item)) { - te.addStack(item); + GrowthCraftFishTrap.getLogger().debug("Added item to inventory x=%d y=%d z=%d dimension=%d item=%s", x, y, z, world.provider.dimensionId, item); + te.consumeBait(); } } } - private ItemStack pickCatch(World world) + protected void attemptCatch(World world, int x, int y, int z, Random random, TileEntityFishTrap te, boolean debugFlag) { - float f1 = world.rand.nextFloat(); - final float f2 = 0.1F; - final float f3 = 0.05F; - - if (f1 < f2) - { - return FishTrapRegistry.instance().getJunkList(world); - } - f1 -= f2; - - if (f1 < f3) + final float f = this.getCatchRate(world, x, y, z); + GrowthCraftFishTrap.getLogger().debug("Attempting Catch x=%d y=%d z=%d dimension=%d rate=%f", x, y, z, world.provider.dimensionId, f); + if (random.nextInt((int)(this.chance / f) + 1) == 0 || debugFlag) { - return FishTrapRegistry.instance().getTreasureList(world); + doCatch(world, x, y, z, te); } - f1 -= f3; - - return FishTrapRegistry.instance().getFishList(world); - } - - private boolean isWater(Block block) - { - return BlockCheck.isWater(block); } private boolean canCatch(World world, int x, int y, int z) @@ -146,34 +192,21 @@ private boolean canCatch(World world, int x, int y, int z) public void updateTick(World world, int x, int y, int z, Random random) { super.updateTick(world, x, y, z, random); - final TileEntityFishTrap te = getTileEntity(world, x, y, z); - if (te != null) { + GrowthCraftFishTrap.getLogger().debug("Checking if fishtrap can catch x=%d y=%d z=%d dimension=%d", x, y, z, world.provider.dimensionId); if (canCatch(world, x, y, z)) { - doCatch(world, x, y, z, random, te, false); + attemptCatch(world, x, y, z, random, te, false); } } - } - - /************ - * TRIGGERS - ************/ - @Override - public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float par7, float par8, float par9) - { - if (!world.isRemote) + else { - player.openGui(GrowthCraftFishTrap.instance, 0, world, x, y, z); + GrowthCraftFishTrap.getLogger().warn("Missing TileEntityFishTrap at x=%d y=%d z=%d dimension=%d", x, y, z, world.provider.dimensionId); } - return true; } - /************ - * TEXTURES - ************/ @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister reg) @@ -202,14 +235,6 @@ public boolean renderAsNormalBlock() return false; } - @Override - @SideOnly(Side.CLIENT) - public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) - { - if (this == world.getBlock(x, y, z)) return false; - return super.shouldSideBeRendered(world, x, y, z, side); - } - @Override @SideOnly(Side.CLIENT) public int getRenderBlockPass() @@ -217,9 +242,6 @@ public int getRenderBlockPass() return 0; } - /************ - * COMPARATOR - ************/ @Override public boolean hasComparatorInputOverride() { diff --git a/src/java/growthcraft/fishtrap/common/inventory/ContainerFishTrap.java b/src/java/growthcraft/fishtrap/common/inventory/ContainerFishTrap.java index dbd5160de..ab4ff0ce5 100644 --- a/src/java/growthcraft/fishtrap/common/inventory/ContainerFishTrap.java +++ b/src/java/growthcraft/fishtrap/common/inventory/ContainerFishTrap.java @@ -1,82 +1,23 @@ package growthcraft.fishtrap.common.inventory; +import growthcraft.core.common.inventory.GrcContainer; +import growthcraft.core.common.inventory.slot.GrcSlot; +import growthcraft.core.common.inventory.slot.SlotInput; import growthcraft.fishtrap.common.tileentity.TileEntityFishTrap; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -public class ContainerFishTrap extends Container +public class ContainerFishTrap extends GrcContainer { - private TileEntityFishTrap te; - public ContainerFishTrap(InventoryPlayer player, TileEntityFishTrap fishtrap) { - this.te = fishtrap; - this.te.openInventory(); - final byte b0 = 51; - int i; - - for (i = 0; i < te.getSizeInventory(); ++i) - { - this.addSlotToContainer(new Slot(this.te, i, 44 + i * 18, 20)); - } - - for (i = 0; i < 3; ++i) - { - for (int j = 0; j < 9; ++j) - { - this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, i * 18 + b0)); - } - } - - for (i = 0; i < 9; ++i) - { - this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 58 + b0)); - } - } - - @Override - public boolean canInteractWith(EntityPlayer player) - { - return this.te.isUseableByPlayer(player); - } - - @Override - public ItemStack transferStackInSlot(EntityPlayer player, int index) - { - ItemStack itemstack = null; - final Slot slot = (Slot)this.inventorySlots.get(index); - - if (slot != null && slot.getHasStack()) + super(fishtrap); + this.addSlotToContainer(new SlotInput(fishtrap, fishtrap.getBaitInventoryOffset(), 17, 20)); + for (int i = 0; i < fishtrap.getTrapInventorySize(); ++i) { - final ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - - if (index < this.te.getSizeInventory()) - { - if (!this.mergeItemStack(itemstack1, this.te.getSizeInventory(), this.inventorySlots.size(), true)) - { - return null; - } - } - else if (!this.mergeItemStack(itemstack1, 0, this.te.getSizeInventory(), false)) - { - return null; - } - - if (itemstack1.stackSize == 0) - { - slot.putStack((ItemStack)null); - } - else - { - slot.onSlotChanged(); - } + final int x = 44 + i * 18; + this.addSlotToContainer(new GrcSlot(fishtrap, i, x, 20)); } - - return itemstack; + bindPlayerInventory(player, 8, 51); } } diff --git a/src/java/growthcraft/fishtrap/common/tileentity/TileEntityFishTrap.java b/src/java/growthcraft/fishtrap/common/tileentity/TileEntityFishTrap.java index 0d8689656..53f943207 100644 --- a/src/java/growthcraft/fishtrap/common/tileentity/TileEntityFishTrap.java +++ b/src/java/growthcraft/fishtrap/common/tileentity/TileEntityFishTrap.java @@ -1,221 +1,171 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) < 2014, Gwafu + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.fishtrap.common.tileentity; +import growthcraft.api.core.nbt.NBTType; +import growthcraft.api.fishtrap.BaitRegistry.BaitHandle; +import growthcraft.api.fishtrap.FishTrapRegistry; +import growthcraft.core.common.inventory.GrcInternalInventory; +import growthcraft.core.common.inventory.InventoryProcessor; +import growthcraft.core.common.inventory.InventorySlice; +import growthcraft.core.common.tileentity.feature.IInteractionObject; +import growthcraft.core.common.tileentity.GrcTileInventoryBase; +import growthcraft.fishtrap.common.inventory.ContainerFishTrap; + import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; -public class TileEntityFishTrap extends TileEntity implements IInventory +public class TileEntityFishTrap extends GrcTileInventoryBase implements IInteractionObject { - // Constants - private ItemStack[] invSlots = new ItemStack[5]; + private static final int[] trapSlots = new int[] {0,1,2,3,4,5}; + private static final int[] baitSlots = new int[] {6}; + public InventorySlice trapInventory; + public InventorySlice baitInventory; - // Other Vars. - private String name; + public TileEntityFishTrap() + { + super(); + this.trapInventory = new InventorySlice(this, trapSlots); + this.baitInventory = new InventorySlice(this, baitSlots); + } - /************ - * UPDATE - ************/ @Override - public boolean canUpdate() + public String getGuiID() { - return false; + return "grcfishtrap:fish_trap"; } - public boolean canAddStack(ItemStack stack, int index) + @Override + public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { - if (this.invSlots[index] == null) return true; - if (!this.invSlots[index].isItemEqual(stack)) return false; - final int result = this.invSlots[index].stackSize + stack.stackSize; - return result <= getInventoryStackLimit() && result <= stack.getMaxStackSize(); + return new ContainerFishTrap(playerInventory, this); } - public void addStack(ItemStack stack) + @Override + public GrcInternalInventory createInventory() { - for (int loop = 0; loop < this.invSlots.length; loop++) - { - if (canAddStack(stack, loop)) - { - if (this.invSlots[loop] == null) - { - this.invSlots[loop] = stack.copy(); - } - else if (this.invSlots[loop].isItemEqual(stack)) - { - this.invSlots[loop].stackSize += stack.stackSize; - } - break; - } - } + return new GrcInternalInventory(this, 7); } - /************ - * INVENTORY - ************/ - @Override - public ItemStack getStackInSlot(int index) + /** + * Called after a successful catch, this will remove an item from the stack + * of provided bait + */ + public void consumeBait() { - return this.invSlots[index]; + baitInventory.decrStackSize(0, 1); } - @Override - public ItemStack decrStackSize(int index, int par2) + /** + * Called by the block to modify the catch rate + * + * @param f the current catch rate + * @return result the modified catch rate + */ + public float applyBaitModifier(float f) { - if (this.invSlots[index] != null) + float result = f; + final ItemStack bait = baitInventory.getStackInSlot(0); + if (bait != null) { - ItemStack itemstack; - - if (this.invSlots[index].stackSize <= par2) - { - itemstack = this.invSlots[index]; - this.invSlots[index] = null; - return itemstack; - } - else + final BaitHandle handle = FishTrapRegistry.instance().findBait(bait); + if (handle != null) { - itemstack = this.invSlots[index].splitStack(par2); - - if (this.invSlots[index].stackSize == 0) - { - this.invSlots[index] = null; - } - - return itemstack; + result += handle.baseRate; + result *= handle.multiplier; } } - else - { - return null; - } + return result; } - @Override - public ItemStack getStackInSlotOnClosing(int index) + public int getBaitInventoryOffset() { - if (this.invSlots[index] != null) - { - final ItemStack itemstack = this.invSlots[index]; - this.invSlots[index] = null; - return itemstack; - } - else - { - return null; - } + return baitSlots[0]; } - @Override - public void setInventorySlotContents(int index, ItemStack itemstack) + public int getTrapInventorySize() { - this.invSlots[index] = itemstack; - - if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) - { - itemstack.stackSize = this.getInventoryStackLimit(); - } + return trapSlots.length; } - @Override - public int getInventoryStackLimit() + public int getBaitInventorySize() { - return 64; + return baitSlots.length; } + /** + * The fishtrap does not update on it's own, instead it relies on the + * block for processing. + */ @Override - public int getSizeInventory() + public boolean canUpdate() { - return this.invSlots.length; + return false; } - @Override - public boolean isUseableByPlayer(EntityPlayer player) + /** + * @param stack the stack to add to the invetory + * @return true, the stack was added, false otherwise + */ + public boolean addStack(ItemStack stack) { - return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; + return InventoryProcessor.instance().mergeWithSlots(trapInventory, stack); } @Override - public void openInventory(){} - - @Override - public void closeInventory(){} - - @Override - public boolean isItemValidForSlot(int index, ItemStack itemstack) + public String getDefaultInventoryName() { - return true; + return "container.grc.fishTrap"; } - /************ - * NBT - ************/ @Override - public void readFromNBT(NBTTagCompound nbt) + protected void readInventoryFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - final NBTTagList tags = nbt.getTagList("items", 10); - this.invSlots = new ItemStack[this.getSizeInventory()]; - - for (int i = 0; i < tags.tagCount(); ++i) + // Backwards compatability + if (nbt.hasKey("items")) { - final NBTTagCompound nbttagcompound1 = tags.getCompoundTagAt(i); - final byte b0 = nbttagcompound1.getByte("Slot"); - if (b0 >= 0 && b0 < this.invSlots.length) + inventory.clear(); + final NBTTagList tags = nbt.getTagList("items", NBTType.COMPOUND.id); + for (int i = 0; i < tags.tagCount(); ++i) { - this.invSlots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); - } - } - - if (nbt.hasKey("name")) - { - this.name = nbt.getString("name"); - } - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - - final NBTTagList nbttaglist = new NBTTagList(); - - for (int i = 0; i < this.invSlots.length; ++i) - { - if (this.invSlots[i] != null) - { - final NBTTagCompound nbttagcompound1 = new NBTTagCompound(); - nbttagcompound1.setByte("Slot", (byte)i); - this.invSlots[i].writeToNBT(nbttagcompound1); - nbttaglist.appendTag(nbttagcompound1); + final NBTTagCompound item = tags.getCompoundTagAt(i); + final byte b0 = item.getByte("Slot"); + if (b0 >= 0 && b0 < trapInventory.getSizeInventory()) + { + final ItemStack stack = ItemStack.loadItemStackFromNBT(item); + InventoryProcessor.instance().mergeWithSlot(trapInventory, stack, (int)b0); + } } } - - nbt.setTag("items", nbttaglist); - - if (this.hasCustomInventoryName()) + else { - nbt.setString("name", this.name); + super.readInventoryFromNBT(nbt); } } - - /************ - * NAMES - ************/ - @Override - public String getInventoryName() - { - return this.hasCustomInventoryName() ? this.name : "container.grc.fishTrap"; - } - - @Override - public boolean hasCustomInventoryName() - { - return this.name != null && this.name.length() > 0; - } - - public void setGuiDisplayName(String string) - { - this.name = string; - } } diff --git a/src/java/growthcraft/grapes/GrcGrapesConfig.java b/src/java/growthcraft/grapes/GrcGrapesConfig.java index b64b6f728..5d1a8fd14 100644 --- a/src/java/growthcraft/grapes/GrcGrapesConfig.java +++ b/src/java/growthcraft/grapes/GrcGrapesConfig.java @@ -52,6 +52,9 @@ public class GrcGrapesConfig extends ConfigBase public int portWineBrewingYield = 40; + @ConfigOption(catergory="Villager", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Village", name="Generate Village Grape Vineyards", desc="Controls hop vineyards spawning in villages") public boolean generateGrapeVineyardStructure = true; diff --git a/src/java/growthcraft/grapes/GrowthCraftGrapes.java b/src/java/growthcraft/grapes/GrowthCraftGrapes.java index b63c307d3..eab89c423 100644 --- a/src/java/growthcraft/grapes/GrowthCraftGrapes.java +++ b/src/java/growthcraft/grapes/GrowthCraftGrapes.java @@ -52,13 +52,13 @@ public class GrowthCraftGrapes public static GrowthCraftGrapes instance; public static CreativeTabs creativeTab; - public static GrcGrapesBlocks blocks = new GrcGrapesBlocks(); - public static GrcGrapesItems items = new GrcGrapesItems(); - public static GrcGrapesFluids fluids = new GrcGrapesFluids(); + public static final GrcGrapesBlocks blocks = new GrcGrapesBlocks(); + public static final GrcGrapesItems items = new GrcGrapesItems(); + public static final GrcGrapesFluids fluids = new GrcGrapesFluids(); - private ILogger logger = new GrcLogger(MOD_ID); - private GrcGrapesConfig config = new GrcGrapesConfig(); - private ModuleContainer modules = new ModuleContainer(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcGrapesConfig config = new GrcGrapesConfig(); + private final ModuleContainer modules = new ModuleContainer(); public static GrcGrapesConfig getConfig() { @@ -72,13 +72,13 @@ public void preInit(FMLPreInitializationEvent event) config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/grapes.conf"); - modules.add(blocks); modules.add(items); modules.add(fluids); if (config.enableForestryIntegration) modules.add(new growthcraft.grapes.integration.ForestryModule()); if (config.enableMFRIntegration) modules.add(new growthcraft.grapes.integration.MFRModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.grapes.integration.ThaumcraftModule()); + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); modules.freeze(); creativeTab = new CreativeTabsGrowthcraftGrapes("creative_tab_grcgrapes"); @@ -125,18 +125,21 @@ private void register() NEI.hideItem(blocks.grapeLeaves.asStack()); } + private void initVillageHandlers() + { + final VillageHandlerGrapes handler = new VillageHandlerGrapes(); + final int brewerID = GrowthCraftCellar.getConfig().villagerBrewerID; + if (brewerID > 0) + VillagerRegistry.instance().registerVillageTradeHandler(brewerID, handler); + VillagerRegistry.instance().registerVillageCreationHandler(handler); + } + @EventHandler public void init(FMLInitializationEvent event) { - CommonProxy.instance.initRenders(); - ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CORRIDOR).addItem(new WeightedRandomChestContent(items.grapes.asStack(), 1, 2, 10)); ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CROSSING).addItem(new WeightedRandomChestContent(items.grapes.asStack(), 1, 2, 10)); - - final VillageHandlerGrapes handler = new VillageHandlerGrapes(); - VillagerRegistry.instance().registerVillageTradeHandler(GrowthCraftCellar.getConfig().villagerBrewerID, handler); - VillagerRegistry.instance().registerVillageCreationHandler(handler); - + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } diff --git a/src/java/growthcraft/grapes/client/ClientProxy.java b/src/java/growthcraft/grapes/client/ClientProxy.java index 9dde7d0e5..3dc00f595 100644 --- a/src/java/growthcraft/grapes/client/ClientProxy.java +++ b/src/java/growthcraft/grapes/client/ClientProxy.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.grapes.client; import growthcraft.grapes.client.renderer.RenderGrape; @@ -10,8 +33,9 @@ public class ClientProxy extends CommonProxy { @Override - public void initRenders() + public void init() { + super.init(); RenderingRegistry.registerBlockHandler(new RenderGrape()); RenderingRegistry.registerBlockHandler(new RenderGrapeLeaves()); RenderingRegistry.registerBlockHandler(new RenderGrapeVine1()); diff --git a/src/java/growthcraft/grapes/common/CommonProxy.java b/src/java/growthcraft/grapes/common/CommonProxy.java index 7bbc99104..b3c6234f8 100644 --- a/src/java/growthcraft/grapes/common/CommonProxy.java +++ b/src/java/growthcraft/grapes/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.grapes.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.grapes.client.ClientProxy", serverSide="growthcraft.grapes.common.CommonProxy") public static CommonProxy instance; - - public void initRenders(){} } diff --git a/src/java/growthcraft/grapes/init/GrcGrapesBlocks.java b/src/java/growthcraft/grapes/init/GrcGrapesBlocks.java index 00761b75a..d0d4c7122 100644 --- a/src/java/growthcraft/grapes/init/GrcGrapesBlocks.java +++ b/src/java/growthcraft/grapes/init/GrcGrapesBlocks.java @@ -25,13 +25,13 @@ import growthcraft.core.common.definition.BlockDefinition; import growthcraft.core.common.definition.BlockTypeDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleBlocks; import growthcraft.grapes.common.block.BlockGrapeBlock; import growthcraft.grapes.common.block.BlockGrapeLeaves; import growthcraft.grapes.common.block.BlockGrapeVine0; import growthcraft.grapes.common.block.BlockGrapeVine1; -public class GrcGrapesBlocks extends GrcModuleBase +public class GrcGrapesBlocks extends GrcModuleBlocks { public BlockTypeDefinition grapeVine0; public BlockTypeDefinition grapeVine1; @@ -41,10 +41,10 @@ public class GrcGrapesBlocks extends GrcModuleBase @Override public void preInit() { - this.grapeVine0 = new BlockTypeDefinition(new BlockGrapeVine0()); - this.grapeVine1 = new BlockTypeDefinition(new BlockGrapeVine1()); - this.grapeLeaves = new BlockTypeDefinition(new BlockGrapeLeaves()); - this.grapeBlock = new BlockDefinition(new BlockGrapeBlock()); + this.grapeVine0 = newTypedDefinition(new BlockGrapeVine0()); + this.grapeVine1 = newTypedDefinition(new BlockGrapeVine1()); + this.grapeLeaves = newTypedDefinition(new BlockGrapeLeaves()); + this.grapeBlock = newDefinition(new BlockGrapeBlock()); } @Override diff --git a/src/java/growthcraft/grapes/init/GrcGrapesItems.java b/src/java/growthcraft/grapes/init/GrcGrapesItems.java index 656a4dc71..3ec004f00 100644 --- a/src/java/growthcraft/grapes/init/GrcGrapesItems.java +++ b/src/java/growthcraft/grapes/init/GrcGrapesItems.java @@ -24,11 +24,11 @@ package growthcraft.grapes.init; import growthcraft.core.common.definition.ItemDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleItems; import growthcraft.grapes.common.item.ItemGrapes; import growthcraft.grapes.common.item.ItemGrapeSeeds; -public class GrcGrapesItems extends GrcModuleBase +public class GrcGrapesItems extends GrcModuleItems { public ItemDefinition grapes; public ItemDefinition grapeSeeds; @@ -36,8 +36,8 @@ public class GrcGrapesItems extends GrcModuleBase @Override public void preInit() { - this.grapes = new ItemDefinition(new ItemGrapes()); - this.grapeSeeds = new ItemDefinition(new ItemGrapeSeeds()); + this.grapes = newDefinition(new ItemGrapes()); + this.grapeSeeds = newDefinition(new ItemGrapeSeeds()); } @Override diff --git a/src/java/growthcraft/hops/GrcHopsConfig.java b/src/java/growthcraft/hops/GrcHopsConfig.java index 7b48addc1..bb9b7fa87 100644 --- a/src/java/growthcraft/hops/GrcHopsConfig.java +++ b/src/java/growthcraft/hops/GrcHopsConfig.java @@ -22,6 +22,9 @@ public class GrcHopsConfig extends ConfigBase public int lagerColor = 0x9F7851; + @ConfigOption(catergory="Villager", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Village", name="Generate Village Hop Vineyards", desc="Should we spawn Hop Vineyards in villages?") public boolean generateHopVineyardStructure = true; diff --git a/src/java/growthcraft/hops/GrowthCraftHops.java b/src/java/growthcraft/hops/GrowthCraftHops.java index 7b5784a54..9b293201c 100644 --- a/src/java/growthcraft/hops/GrowthCraftHops.java +++ b/src/java/growthcraft/hops/GrowthCraftHops.java @@ -4,20 +4,17 @@ import growthcraft.api.core.CoreRegistry; import growthcraft.api.core.log.GrcLogger; import growthcraft.api.core.log.ILogger; -import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.core.common.definition.BlockTypeDefinition; -import growthcraft.core.common.definition.ItemDefinition; import growthcraft.api.core.module.ModuleContainer; +import growthcraft.cellar.GrowthCraftCellar; import growthcraft.core.GrowthCraftCore; import growthcraft.core.integration.NEI; import growthcraft.core.util.MapGenHelper; -import growthcraft.hops.common.block.BlockHops; import growthcraft.hops.common.CommonProxy; -import growthcraft.hops.common.item.ItemHops; -import growthcraft.hops.common.item.ItemHopSeeds; import growthcraft.hops.common.village.ComponentVillageHopVineyard; import growthcraft.hops.common.village.VillageHandlerHops; +import growthcraft.hops.init.GrcHopsBlocks; import growthcraft.hops.init.GrcHopsFluids; +import growthcraft.hops.init.GrcHopsItems; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -50,16 +47,13 @@ public class GrowthCraftHops @Instance(MOD_ID) public static GrowthCraftHops instance; + public static final GrcHopsBlocks blocks = new GrcHopsBlocks(); + public static final GrcHopsItems items = new GrcHopsItems(); + public static final GrcHopsFluids fluids = new GrcHopsFluids(); - public static BlockTypeDefinition hopVine; - - public static ItemDefinition hops; - public static ItemDefinition hopSeeds; - public static GrcHopsFluids fluids = new GrcHopsFluids(); - - private ILogger logger = new GrcLogger(MOD_ID); - private GrcHopsConfig config = new GrcHopsConfig(); - private ModuleContainer modules = new ModuleContainer(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcHopsConfig config = new GrcHopsConfig(); + private final ModuleContainer modules = new ModuleContainer(); public static GrcHopsConfig getConfig() { @@ -71,74 +65,63 @@ public void preload(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/hops.conf"); - + modules.add(blocks); + modules.add(items); modules.add(fluids); if (config.enableForestryIntegration) modules.add(new growthcraft.hops.integration.ForestryModule()); if (config.enableMFRIntegration) modules.add(new growthcraft.hops.integration.MFRModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.hops.integration.ThaumcraftModule()); + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); - - //==================== - // INIT - //==================== - hopVine = new BlockTypeDefinition(new BlockHops()); - - hops = new ItemDefinition(new ItemHops()); - hopSeeds = new ItemDefinition(new ItemHopSeeds()); - + modules.freeze(); modules.preInit(); register(); } private void register() { - //==================== - // REGISTRIES - //==================== - GameRegistry.registerBlock(hopVine.getBlock(), "grc.hopVine"); - - GameRegistry.registerItem(hops.getItem(), "grc.hops"); - GameRegistry.registerItem(hopSeeds.getItem(), "grc.hopSeeds"); - - CoreRegistry.instance().vineDrops().addDropEntry(hops.asStack(2), config.hopsVineDropRarity); + modules.register(); + CoreRegistry.instance().vineDrops().addDropEntry(items.hops.asStack(2), config.hopsVineDropRarity); - ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CORRIDOR).addItem(new WeightedRandomChestContent(hops.asStack(), 1, 2, 10)); - ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CROSSING).addItem(new WeightedRandomChestContent(hops.asStack(), 1, 2, 10)); + ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CORRIDOR).addItem(new WeightedRandomChestContent(items.hops.asStack(), 1, 2, 10)); + ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CROSSING).addItem(new WeightedRandomChestContent(items.hops.asStack(), 1, 2, 10)); MapGenHelper.registerVillageStructure(ComponentVillageHopVineyard.class, "grc.hopvineyard"); //==================== // ORE DICTIONARY //==================== - OreDictionary.registerOre("cropHops", hops.getItem()); - OreDictionary.registerOre("materialHops", hops.getItem()); - OreDictionary.registerOre("conesHops", hops.getItem()); - OreDictionary.registerOre("seedHops", hopSeeds.getItem()); + OreDictionary.registerOre("cropHops", items.hops.getItem()); + OreDictionary.registerOre("materialHops", items.hops.getItem()); + OreDictionary.registerOre("conesHops", items.hops.getItem()); + OreDictionary.registerOre("seedHops", items.hopSeeds.getItem()); // For Pam's HarvestCraft // Uses the same OreDict. names as HarvestCraft - OreDictionary.registerOre("listAllseed", hopSeeds.getItem()); + OreDictionary.registerOre("listAllseed", items.hopSeeds.getItem()); //==================== // CRAFTING //==================== - GameRegistry.addShapelessRecipe(hopSeeds.asStack(), hops.getItem()); + GameRegistry.addShapelessRecipe(items.hopSeeds.asStack(), items.hops.getItem()); - NEI.hideItem(hopVine.asStack()); + NEI.hideItem(blocks.hopVine.asStack()); MinecraftForge.EVENT_BUS.register(this); - - modules.register(); } - @EventHandler - public void load(FMLInitializationEvent event) + private void initVillageHandlers() { - CommonProxy.instance.initRenders(); - final VillageHandlerHops handler = new VillageHandlerHops(); - VillagerRegistry.instance().registerVillageTradeHandler(GrowthCraftCellar.getConfig().villagerBrewerID, handler); + final int brewerID = GrowthCraftCellar.getConfig().villagerBrewerID; + if (brewerID > 0) + VillagerRegistry.instance().registerVillageTradeHandler(brewerID, handler); VillagerRegistry.instance().registerVillageCreationHandler(handler); + } + @EventHandler + public void load(FMLInitializationEvent event) + { + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } diff --git a/src/java/growthcraft/hops/client/ClientProxy.java b/src/java/growthcraft/hops/client/ClientProxy.java index d220ad8ab..8aa8b6a5f 100644 --- a/src/java/growthcraft/hops/client/ClientProxy.java +++ b/src/java/growthcraft/hops/client/ClientProxy.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.hops.client; import growthcraft.hops.client.renderer.RenderHops; @@ -8,8 +31,9 @@ public class ClientProxy extends CommonProxy { @Override - public void initRenders() + public void init() { + super.init(); RenderingRegistry.registerBlockHandler(new RenderHops()); } } diff --git a/src/java/growthcraft/hops/common/CommonProxy.java b/src/java/growthcraft/hops/common/CommonProxy.java index 40fc113a7..b8f9dca4a 100644 --- a/src/java/growthcraft/hops/common/CommonProxy.java +++ b/src/java/growthcraft/hops/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.hops.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.hops.client.ClientProxy", serverSide="growthcraft.hops.common.CommonProxy") public static CommonProxy instance; - - public void initRenders(){} } diff --git a/src/java/growthcraft/hops/common/block/BlockHops.java b/src/java/growthcraft/hops/common/block/BlockHops.java index f7b60ae30..a48b3ef35 100644 --- a/src/java/growthcraft/hops/common/block/BlockHops.java +++ b/src/java/growthcraft/hops/common/block/BlockHops.java @@ -261,7 +261,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p if (!world.isRemote) { removeFruit(world, x, y, z); - dropBlockAsItem(world, x, y, z, GrowthCraftHops.hops.asStack(1 + world.rand.nextInt(8))); + dropBlockAsItem(world, x, y, z, GrowthCraftHops.items.hops.asStack(1 + world.rand.nextInt(8))); } return true; } @@ -315,7 +315,7 @@ private boolean isVineRoot(World world, int x, int y, int z) public Item getItem(World world, int x, int y, int z) { final int meta = world.getBlockMetadata(x, y, z); - return meta < HopsStage.FRUIT ? GrowthCraftHops.hopSeeds.getItem() : GrowthCraftHops.hops.getItem(); + return meta < HopsStage.FRUIT ? GrowthCraftHops.items.hopSeeds.getItem() : GrowthCraftHops.items.hops.getItem(); } @Override @@ -356,7 +356,7 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad ret.add(GrowthCraftCore.items.rope.asStack()); if (world.getBlockMetadata(x, y, z) >= HopsStage.BIG) { - ret.add(GrowthCraftHops.hops.asStack(1 + world.rand.nextInt(8))); + ret.add(GrowthCraftHops.items.hops.asStack(1 + world.rand.nextInt(8))); } return ret; } diff --git a/src/java/growthcraft/hops/common/item/ItemHopSeeds.java b/src/java/growthcraft/hops/common/item/ItemHopSeeds.java index c3af0b34a..d6616ee6c 100644 --- a/src/java/growthcraft/hops/common/item/ItemHopSeeds.java +++ b/src/java/growthcraft/hops/common/item/ItemHopSeeds.java @@ -38,9 +38,9 @@ public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int } else if (player.canPlayerEdit(x, y, z, dir, stack) && player.canPlayerEdit(x, y + 1, z, dir, stack)) { - if (BlockCheck.canSustainPlant(world, x, y, z, ForgeDirection.UP, GrowthCraftHops.hopVine.getBlock()) && BlockCheck.isRope(world, x, y + 1, z)) + if (BlockCheck.canSustainPlant(world, x, y, z, ForgeDirection.UP, GrowthCraftHops.blocks.hopVine.getBlock()) && BlockCheck.isRope(world, x, y + 1, z)) { - world.setBlock(x, y + 1, z, GrowthCraftHops.hopVine.getBlock()); + world.setBlock(x, y + 1, z, GrowthCraftHops.blocks.hopVine.getBlock()); --stack.stackSize; return true; } @@ -74,7 +74,7 @@ public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z) @Override public Block getPlant(IBlockAccess world, int x, int y, int z) { - return GrowthCraftHops.hopVine.getBlock(); + return GrowthCraftHops.blocks.hopVine.getBlock(); } @Override diff --git a/src/java/growthcraft/hops/common/village/ComponentVillageHopVineyard.java b/src/java/growthcraft/hops/common/village/ComponentVillageHopVineyard.java index ecb61c801..61559ce43 100644 --- a/src/java/growthcraft/hops/common/village/ComponentVillageHopVineyard.java +++ b/src/java/growthcraft/hops/common/village/ComponentVillageHopVineyard.java @@ -74,9 +74,9 @@ public boolean addComponentParts(World world, Random random, StructureBoundingBo { this.placeBlockAtCurrentPosition(world, Blocks.fence, 0, loop, loop2, 1, box); this.placeBlockAtCurrentPosition(world, Blocks.fence, 0, loop, loop2, 7, box); - this.placeBlockAtCurrentPosition(world, GrowthCraftHops.hopVine.getBlock(), 3, loop, loop2, 2, box); - this.placeBlockAtCurrentPosition(world, GrowthCraftHops.hopVine.getBlock(), 3, loop, loop2, 4, box); - this.placeBlockAtCurrentPosition(world, GrowthCraftHops.hopVine.getBlock(), 3, loop, loop2, 6, box); + this.placeBlockAtCurrentPosition(world, GrowthCraftHops.blocks.hopVine.getBlock(), 3, loop, loop2, 2, box); + this.placeBlockAtCurrentPosition(world, GrowthCraftHops.blocks.hopVine.getBlock(), 3, loop, loop2, 4, box); + this.placeBlockAtCurrentPosition(world, GrowthCraftHops.blocks.hopVine.getBlock(), 3, loop, loop2, 6, box); } } diff --git a/src/java/growthcraft/hops/init/GrcHopsBlocks.java b/src/java/growthcraft/hops/init/GrcHopsBlocks.java new file mode 100644 index 000000000..fc5975717 --- /dev/null +++ b/src/java/growthcraft/hops/init/GrcHopsBlocks.java @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.hops.init; + +import growthcraft.core.common.definition.BlockTypeDefinition; +import growthcraft.core.common.GrcModuleBlocks; +import growthcraft.hops.common.block.BlockHops; + +public class GrcHopsBlocks extends GrcModuleBlocks +{ + public BlockTypeDefinition hopVine; + + @Override + public void preInit() + { + this.hopVine = newTypedDefinition(new BlockHops()); + } + + @Override + public void register() + { + hopVine.register("grc.hopVine"); + } +} diff --git a/src/java/growthcraft/hops/init/GrcHopsItems.java b/src/java/growthcraft/hops/init/GrcHopsItems.java new file mode 100644 index 000000000..8c67ba367 --- /dev/null +++ b/src/java/growthcraft/hops/init/GrcHopsItems.java @@ -0,0 +1,49 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.hops.init; + +import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.common.GrcModuleItems; +import growthcraft.hops.common.item.ItemHops; +import growthcraft.hops.common.item.ItemHopSeeds; + +public class GrcHopsItems extends GrcModuleItems +{ + public ItemDefinition hops; + public ItemDefinition hopSeeds; + + @Override + public void preInit() + { + this.hops = newDefinition(new ItemHops()); + this.hopSeeds = newDefinition(new ItemHopSeeds()); + } + + @Override + public void register() + { + hops.register("grc.hops"); + hopSeeds.register("grc.hopSeeds"); + } +} diff --git a/src/java/growthcraft/hops/integration/ForestryModule.java b/src/java/growthcraft/hops/integration/ForestryModule.java index d8589a63c..f20272a37 100644 --- a/src/java/growthcraft/hops/integration/ForestryModule.java +++ b/src/java/growthcraft/hops/integration/ForestryModule.java @@ -47,9 +47,9 @@ protected void integrate() final int saplingYield = getActiveMode().getIntegerSetting("fermenter.yield.sapling"); final int seedamount = getActiveMode().getIntegerSetting("squeezer.liquid.seed"); - final ItemStack hopSeed = GrowthCraftHops.hopSeeds.asStack(); - final ItemStack hops = GrowthCraftHops.hops.asStack(); - final Block hopVine = GrowthCraftHops.hopVine.getBlock(); + final ItemStack hopSeed = GrowthCraftHops.items.hopSeeds.asStack(); + final ItemStack hops = GrowthCraftHops.items.hops.asStack(); + final Block hopVine = GrowthCraftHops.blocks.hopVine.getBlock(); Backpack.FORESTERS.add(hopSeed); Backpack.FORESTERS.add(hops); diff --git a/src/java/growthcraft/hops/integration/ThaumcraftModule.java b/src/java/growthcraft/hops/integration/ThaumcraftModule.java index 3c3a09807..3bb3df3ad 100644 --- a/src/java/growthcraft/hops/integration/ThaumcraftModule.java +++ b/src/java/growthcraft/hops/integration/ThaumcraftModule.java @@ -46,10 +46,10 @@ public ThaumcraftModule() @Optional.Method(modid="Thaumcraft") protected void integrate() { - FMLInterModComms.sendMessage("Thaumcraft", "harvestClickableCrop", GrowthCraftHops.hopVine.asStack(1, 3)); + FMLInterModComms.sendMessage("Thaumcraft", "harvestClickableCrop", GrowthCraftHops.blocks.hopVine.asStack(1, 3)); - ThaumcraftApi.registerObjectTag(GrowthCraftHops.hopSeeds.asStack(), new AspectList().add(Aspect.PLANT, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftHops.hops.asStack(), new AspectList().add(Aspect.CROP, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftHops.items.hopSeeds.asStack(), new AspectList().add(Aspect.PLANT, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftHops.items.hops.asStack(), new AspectList().add(Aspect.CROP, 1)); // hopAle AspectList[] common = new AspectList[] diff --git a/src/java/growthcraft/hops/integration/mfr/HopFactoryFruit.java b/src/java/growthcraft/hops/integration/mfr/HopFactoryFruit.java index 08ce9f3d6..ac646eafa 100644 --- a/src/java/growthcraft/hops/integration/mfr/HopFactoryFruit.java +++ b/src/java/growthcraft/hops/integration/mfr/HopFactoryFruit.java @@ -44,7 +44,7 @@ public class HopFactoryFruit extends AbstractFactoryFruit public HopFactoryFruit() { super(); - setPlant(GrowthCraftHops.hopVine.getBlock()); + setPlant(GrowthCraftHops.blocks.hopVine.getBlock()); this.replacementBlock = new ReplacementBlock(plantBlock); replacementBlock.setMeta(BlockHops.HopsStage.BIG); } diff --git a/src/java/growthcraft/milk/GrowthCraftMilk.java b/src/java/growthcraft/milk/GrowthCraftMilk.java index a0d7be892..8523bf2de 100644 --- a/src/java/growthcraft/milk/GrowthCraftMilk.java +++ b/src/java/growthcraft/milk/GrowthCraftMilk.java @@ -82,9 +82,9 @@ public class GrowthCraftMilk // Events public static final EventBus MILK_BUS = new EventBus(); - private ILogger logger = new GrcLogger(MOD_ID); - private GrcMilkConfig config = new GrcMilkConfig(); - private ModuleContainer modules = new ModuleContainer(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcMilkConfig config = new GrcMilkConfig(); + private final ModuleContainer modules = new ModuleContainer(); public static GrcMilkConfig getConfig() { @@ -106,7 +106,6 @@ public void preload(FMLPreInitializationEvent event) modules.setLogger(logger); MilkRegistry.instance().setLogger(logger); } - modules.add(blocks); modules.add(items); modules.add(fluids); @@ -115,6 +114,7 @@ public void preload(FMLPreInitializationEvent event) if (config.enableThaumcraftIntegration) modules.add(new growthcraft.milk.integration.ThaumcraftModule()); if (config.enableWailaIntegration) modules.add(new growthcraft.milk.integration.Waila()); modules.add(userApis); + modules.add(CommonProxy.instance); modules.freeze(); GrcMilkEffects.init(); @@ -148,10 +148,8 @@ private void register() @EventHandler public void load(FMLInitializationEvent event) { - CommonProxy.instance.initRenders(); modules.init(); userApis.loadConfigs(); - CommonProxy.instance.registerWorldGen(); } @EventHandler diff --git a/src/java/growthcraft/milk/client/ClientProxy.java b/src/java/growthcraft/milk/client/ClientProxy.java index 7892f2263..e984c69b8 100644 --- a/src/java/growthcraft/milk/client/ClientProxy.java +++ b/src/java/growthcraft/milk/client/ClientProxy.java @@ -50,8 +50,10 @@ public class ClientProxy extends CommonProxy { - public void initRenders() + @Override + public void init() { + super.init(); new GrcMilkResources(); MinecraftForgeClient.registerItemRenderer(GrowthCraftMilk.blocks.cheeseBlock.getItem(), new ItemRendererCheeseBlock()); diff --git a/src/java/growthcraft/milk/common/CommonProxy.java b/src/java/growthcraft/milk/common/CommonProxy.java index 9160dbbff..0ecd53554 100644 --- a/src/java/growthcraft/milk/common/CommonProxy.java +++ b/src/java/growthcraft/milk/common/CommonProxy.java @@ -23,22 +23,28 @@ */ package growthcraft.milk.common; -import growthcraft.milk.GrowthCraftMilk; +import growthcraft.core.common.GrcModuleProxyBase; import growthcraft.milk.common.world.WorldGeneratorThistle; +import growthcraft.milk.GrowthCraftMilk; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.registry.GameRegistry; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.milk.client.ClientProxy", serverSide="growthcraft.milk.common.CommonProxy") public static CommonProxy instance; - public void initRenders() {} - - public void registerWorldGen() + protected void registerWorldGen() { if (GrowthCraftMilk.getConfig().canThistleGenerate()) GameRegistry.registerWorldGenerator(new WorldGeneratorThistle(), 0); } + + @Override + public void init() + { + super.init(); + registerWorldGen(); + } } diff --git a/src/java/growthcraft/milk/common/block/BlockCheesePress.java b/src/java/growthcraft/milk/common/block/BlockCheesePress.java index dfe4c5d7b..f18236a7e 100644 --- a/src/java/growthcraft/milk/common/block/BlockCheesePress.java +++ b/src/java/growthcraft/milk/common/block/BlockCheesePress.java @@ -56,6 +56,7 @@ public BlockCheesePress() setBlockTextureName("grcmilk:cheese_press"); } + @Override public boolean isRotatable(IBlockAccess world, int x, int y, int z, ForgeDirection side) { return true; diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityButterChurn.java b/src/java/growthcraft/milk/common/tileentity/TileEntityButterChurn.java index 21797fa65..0cb2997fb 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityButterChurn.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityButterChurn.java @@ -32,9 +32,9 @@ import growthcraft.core.common.inventory.GrcInternalInventory; import growthcraft.core.common.tileentity.device.DeviceFluidSlot; import growthcraft.core.common.tileentity.device.DeviceInventorySlot; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.GrcTileEntityDeviceBase; -import growthcraft.core.common.tileentity.IItemHandler; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.IItemHandler; +import growthcraft.core.common.tileentity.GrcTileDeviceBase; import growthcraft.core.util.ItemUtils; import io.netty.buffer.ByteBuf; @@ -50,7 +50,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -public class TileEntityButterChurn extends GrcTileEntityDeviceBase implements IItemHandler +public class TileEntityButterChurn extends GrcTileDeviceBase implements IItemHandler { public static enum WorkState { @@ -91,7 +91,7 @@ protected FluidTank[] createTanks() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 1); } @@ -120,9 +120,6 @@ public boolean canExtractItem(int index, ItemStack stack, int side) return accessibleSlots.sideContains(side, index); } - @Override - protected void updateDevice() {} - @Override public void updateEntity() { @@ -182,14 +179,14 @@ public WorkState doWork() { this.shaftState = 0; } - markForBlockUpdate(); + markForUpdate(); } else { if (shaftState != 0) { this.shaftState = 0; - markForBlockUpdate(); + markForUpdate(); } this.churns = 0; } @@ -269,7 +266,7 @@ protected int doFill(ForgeDirection dir, FluidStack stack, boolean doFill) * @return false */ @Override - public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) + public boolean tryPlaceItem(IItemHandler.Action action, EntityPlayer player, ItemStack stack) { return false; } @@ -282,8 +279,9 @@ public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) * @return true, the item was removed, false otherwise */ @Override - public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) + public boolean tryTakeItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { + if (IItemHandler.Action.RIGHT != action) return false; final ItemStack stack = outputInventorySlot.yank(); if (stack != null) { @@ -293,23 +291,21 @@ public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) return false; } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_ButterChurn(NBTTagCompound nbt) { - super.readFromNBT(nbt); this.shaftState = nbt.getInteger("shaft_state"); this.churns = nbt.getInteger("churns"); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_ButterChurn(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("shaft_state", shaftState); nbt.setInteger("churns", churns); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_ButterChurn(ByteBuf stream) throws IOException { this.shaftState = stream.readInt(); @@ -317,7 +313,7 @@ public boolean readFromStream_ButterChurn(ByteBuf stream) throws IOException return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_ButterChurn(ByteBuf stream) throws IOException { stream.writeInt(shaftState); diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseBlock.java b/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseBlock.java index 02f05198c..465cb5871 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseBlock.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseBlock.java @@ -27,9 +27,9 @@ import java.io.IOException; import growthcraft.api.core.nbt.INBTItemSerializable; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.GrcTileEntityBase; -import growthcraft.core.common.tileentity.IItemHandler; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.IItemHandler; +import growthcraft.core.common.tileentity.GrcTileBase; import growthcraft.core.util.ItemUtils; import growthcraft.milk.common.item.ItemBlockCheeseBlock; import growthcraft.milk.common.struct.Cheese; @@ -41,7 +41,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class TileEntityCheeseBlock extends GrcTileEntityBase implements IItemHandler, INBTItemSerializable +public class TileEntityCheeseBlock extends GrcTileBase implements IItemHandler, INBTItemSerializable { private Cheese cheese = new Cheese(); @@ -87,10 +87,9 @@ public void readFromNBTForItem(NBTTagCompound nbt) readCheeseFromNBT(nbt); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_CheeseBlock(NBTTagCompound nbt) { - super.readFromNBT(nbt); readCheeseFromNBT(nbt); } @@ -106,10 +105,9 @@ public void writeToNBTForItem(NBTTagCompound nbt) writeCheeseToNBT(nbt); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_CheeseBlock(NBTTagCompound nbt) { - super.writeToNBT(nbt); writeCheeseToNBT(nbt); } @@ -121,14 +119,14 @@ public ItemStack asItemStack() return stack; } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_CheeseBlock(ByteBuf stream) throws IOException { cheese.readFromStream(stream); return true; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_CheeseBlock(ByteBuf stream) throws IOException { cheese.writeToStream(stream); @@ -139,7 +137,6 @@ public boolean writeToStream_CheeseBlock(ByteBuf stream) throws IOException public void updateEntity() { super.updateEntity(); - if (!worldObj.isRemote) { cheese.update(); @@ -148,7 +145,7 @@ public void updateEntity() cheese.needClientUpdate = false; if (cheese.hasSlices()) { - markForBlockUpdate(); + markForUpdate(); } else { @@ -159,14 +156,16 @@ public void updateEntity() } @Override - public boolean tryPlaceItem(EntityPlayer player, ItemStack onHand) + public boolean tryPlaceItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { + if (IItemHandler.Action.RIGHT != action) return false; return cheese.tryWaxing(onHand); } @Override - public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) + public boolean tryTakeItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { + if (IItemHandler.Action.RIGHT != action) return false; if (cheese.isAged()) { final ItemStack stack = cheese.yankSlices(1, true); diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityCheesePress.java b/src/java/growthcraft/milk/common/tileentity/TileEntityCheesePress.java index 8fe7ffa30..637df7bc9 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityCheesePress.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityCheesePress.java @@ -30,10 +30,10 @@ import growthcraft.api.milk.MilkRegistry; import growthcraft.core.common.inventory.GrcInternalInventory; import growthcraft.core.common.tileentity.device.DeviceInventorySlot; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.GrcTileEntityInventoryBase; -import growthcraft.core.common.tileentity.IItemHandler; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.IItemHandler; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.GrcTileInventoryBase; import growthcraft.core.util.ItemUtils; import growthcraft.milk.common.item.ItemBlockHangingCurds; import growthcraft.milk.GrowthCraftMilk; @@ -48,7 +48,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.inventory.IInventory; -public class TileEntityCheesePress extends GrcTileEntityInventoryBase implements IItemHandler, ITileProgressiveDevice +public class TileEntityCheesePress extends GrcTileInventoryBase implements IItemHandler, ITileProgressiveDevice { private static int[][] accessibleSlots = { { 0 }, @@ -137,7 +137,7 @@ public void onInventoryChanged(IInventory inv, int index) } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 1, 1); } @@ -236,7 +236,7 @@ private void updateEntityServer() if (time != 0) { this.time = 0; - markForBlockUpdate(); + markDirty(); } } } @@ -266,7 +266,7 @@ public boolean toggle(boolean state) { final int oldScrewState = screwState; this.screwState = state ? 1 : 0; - markForBlockUpdate(); + if (oldScrewState != screwState) markForUpdate(); return oldScrewState != screwState; } @@ -281,8 +281,9 @@ public boolean toggle() } @Override - public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) + public boolean tryPlaceItem(IItemHandler.Action action, EntityPlayer player, ItemStack stack) { + if (IItemHandler.Action.RIGHT != action) return false; if (ItemTest.isValid(stack)) { // Items cannot be added if the user slot already has an item AND @@ -305,41 +306,37 @@ public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) } @Override - public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) + public boolean tryTakeItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { - if (!ItemTest.isValid(onHand)) + if (IItemHandler.Action.LEFT != action) return false; + // Items cannot be removed if the cheese press is active + if (isUnpressed()) { - // Items cannot be removed if the cheese press is active - if (isUnpressed()) + final ItemStack result = invSlot.yank(); + if (result != null) { - final ItemStack result = invSlot.yank(); - if (result != null) - { - ItemUtils.spawnItemStackAtTile(result, this, worldObj.rand); - return true; - } + ItemUtils.spawnItemStackAtTile(result, this, worldObj.rand); + return true; } } return false; } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_CheesePress(NBTTagCompound nbt) { - super.readFromNBT(nbt); this.screwState = nbt.getInteger("screw_state"); this.time = nbt.getInteger("time"); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_CheesePress(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("screw_state", screwState); nbt.setInteger("time", time); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_CheesePress(ByteBuf stream) throws IOException { this.screwState = stream.readInt(); @@ -347,7 +344,7 @@ public boolean readFromStream_CheesePress(ByteBuf stream) throws IOException return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_CheesePress(ByteBuf stream) throws IOException { stream.writeInt(screwState); diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseVat.java b/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseVat.java index 0b75ebe0e..5883b6533 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseVat.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityCheeseVat.java @@ -36,7 +36,7 @@ import growthcraft.api.core.fluids.FluidTest; import growthcraft.api.core.fluids.FluidUtils; import growthcraft.api.core.item.ItemTest; -import growthcraft.api.core.nbt.NBTStringTagList; +import growthcraft.api.core.nbt.NBTTagStringList; import growthcraft.api.core.stream.StreamUtils; import growthcraft.api.milk.cheesevat.ICheeseVatRecipe; import growthcraft.api.milk.MilkFluidTags; @@ -46,12 +46,12 @@ import growthcraft.core.common.inventory.GrcInternalInventory; import growthcraft.core.common.inventory.InventoryProcessor; import growthcraft.core.common.tileentity.device.DeviceFluidSlot; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.GrcTileEntityDeviceBase; -import growthcraft.core.common.tileentity.IItemHandler; -import growthcraft.core.common.tileentity.ITileHeatedDevice; -import growthcraft.core.common.tileentity.ITileNamedFluidTanks; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.feature.IItemHandler; +import growthcraft.core.common.tileentity.feature.ITileHeatedDevice; +import growthcraft.core.common.tileentity.feature.ITileNamedFluidTanks; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.GrcTileDeviceBase; import growthcraft.core.util.ItemUtils; import growthcraft.milk.common.item.EnumCheeseType; import growthcraft.milk.common.tileentity.cheesevat.CheeseVatState; @@ -71,7 +71,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -public class TileEntityCheeseVat extends GrcTileEntityDeviceBase implements IItemHandler, ITileHeatedDevice, ITileNamedFluidTanks, ITileProgressiveDevice +public class TileEntityCheeseVat extends GrcTileDeviceBase implements IItemHandler, ITileHeatedDevice, ITileNamedFluidTanks, ITileProgressiveDevice { public static enum FluidTankType { @@ -128,7 +128,7 @@ public boolean isWorking() private void setVatState(CheeseVatState state) { this.vatState = state; - markForBlockUpdate(); + markDirty(); } private void goIdle() @@ -220,7 +220,7 @@ public int getVatFluidCapacity() } @Override - protected GrcInternalInventory createInventory() + public GrcInternalInventory createInventory() { return new GrcInternalInventory(this, 3, 1); } @@ -336,7 +336,7 @@ private boolean commitMilkCurdRecipe(boolean checkOnly) // locate all the items in the inventory final int[] invSlots = InventoryProcessor.instance().findItemSlots(this, inputItems); if (InventoryProcessor.instance().slotsAreValid(this, invSlots) && - InventoryProcessor.instance().checkSlots(this, inputItems, invSlots)) + InventoryProcessor.instance().checkSlotsAndSizes(this, inputItems, invSlots)) { if (FluidTest.hasEnoughAndExpected(inputFluids, fluids)) { @@ -375,7 +375,7 @@ private boolean commitMilkCurdRecipe(boolean checkOnly) break; } // mark vat for block update - markForBlockUpdate(); + markDirty(); // post event to bus GrowthCraftMilk.MILK_BUS.post(new EventCheeseVatMadeCheeseFluid(this)); } @@ -418,41 +418,45 @@ private void onFinishedProgress() } @Override - protected void updateDevice() + public void updateEntity() { - heatComponent.update(); - if (!isIdle()) + super.updateEntity(); + if (!worldObj.isRemote) { - if (isHeated()) + heatComponent.update(); + if (!isIdle()) { - if (progress < progressMax) + if (isHeated()) { - progress += 1 * getHeatMultiplier(); + if (progress < progressMax) + { + progress += 1 * getHeatMultiplier(); + } + else + { + onFinishedProgress(); + goIdle(); + } } else { - onFinishedProgress(); - goIdle(); + if (progress > 0) + { + progress -= 1; + } + else + { + goIdle(); + } } } else { - if (progress > 0) + if (recheckRecipe) { - progress -= 1; + this.recheckRecipe = false; + if (isHeated()) commitRecipe(); } - else - { - goIdle(); - } - } - } - else - { - if (recheckRecipe) - { - this.recheckRecipe = false; - if (isHeated()) commitRecipe(); } } } @@ -586,8 +590,9 @@ private boolean addItemIngredient(EntityPlayer player, ItemStack stack) } @Override - public boolean tryPlaceItem(EntityPlayer player, ItemStack stack) + public boolean tryPlaceItem(IItemHandler.Action action, EntityPlayer player, ItemStack stack) { + if (IItemHandler.Action.RIGHT != action) return false; if (!isIdle()) return false; if (!ItemTest.isValid(stack)) return false; final Item item = stack.getItem(); @@ -611,8 +616,9 @@ else if (MilkRegistry.instance().cheeseVat().isItemIngredient(stack)) } @Override - public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) + public boolean tryTakeItem(IItemHandler.Action action, EntityPlayer player, ItemStack onHand) { + if (IItemHandler.Action.RIGHT != action) return false; if (!isIdle()) return false; if (onHand == null) { @@ -627,16 +633,16 @@ public boolean tryTakeItem(EntityPlayer player, ItemStack onHand) } @Override - protected void markForFluidUpdate() + protected void markFluidDirty() { - markForBlockUpdate(); markForRecipeCheck(); + markDirty(); } @Override public void writeFluidTankNamesToTag(NBTTagCompound tag) { - final NBTStringTagList tagList = new NBTStringTagList(); + final NBTTagStringList tagList = new NBTTagStringList(); for (FluidTankType type : FluidTankType.VALUES) { tagList.add(type.getUnlocalizedName()); @@ -644,10 +650,9 @@ public void writeFluidTankNamesToTag(NBTTagCompound tag) tag.setTag("tank_names", tagList.getTag()); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_CheeseVat(NBTTagCompound nbt) { - super.readFromNBT(nbt); if (nbt.hasKey("progress_max")) { this.progressMax = nbt.getInteger("progress_max"); @@ -660,17 +665,16 @@ public void readFromNBT(NBTTagCompound nbt) this.vatState = CheeseVatState.getStateSafe(nbt.getString("vat_state")); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_CheeseVat(NBTTagCompound nbt) { - super.writeToNBT(nbt); nbt.setInteger("progress_max", progressMax); nbt.setFloat("progress", progress); heatComponent.writeToNBT(nbt, "heat_component"); nbt.setString("vat_state", vatState.name); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_CheeseVat(ByteBuf stream) throws IOException { this.progressMax = stream.readInt(); @@ -689,7 +693,7 @@ public boolean readFromStream_CheeseVat(ByteBuf stream) throws IOException return false; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_CheeseVat(ByteBuf stream) throws IOException { stream.writeInt(progressMax); diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityHangingCurds.java b/src/java/growthcraft/milk/common/tileentity/TileEntityHangingCurds.java index 8411d60e5..c57bb46ae 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityHangingCurds.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityHangingCurds.java @@ -31,8 +31,8 @@ import growthcraft.api.core.util.PulseStepper; import growthcraft.api.core.util.SpatialRandom; import growthcraft.api.core.util.TickUtils; -import growthcraft.core.common.tileentity.event.EventHandler; -import growthcraft.core.common.tileentity.GrcTileEntityBase; +import growthcraft.core.common.tileentity.event.TileEventHandler; +import growthcraft.core.common.tileentity.GrcTileBase; import growthcraft.milk.common.item.ItemBlockHangingCurds; import growthcraft.milk.common.struct.CheeseCurd; import growthcraft.milk.GrowthCraftMilk; @@ -47,7 +47,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraft.nbt.NBTTagCompound; -public class TileEntityHangingCurds extends GrcTileEntityBase implements INBTItemSerializable +public class TileEntityHangingCurds extends GrcTileBase implements INBTItemSerializable { // SpatialRandom instance private SpatialRandom sprand = new SpatialRandom(); @@ -109,7 +109,7 @@ public void updateEntity() if (cheeseCurd.needClientUpdate) { cheeseCurd.needClientUpdate = false; - markForBlockUpdate(); + markForUpdate(); } cheeseCurd.update(); if (wheyPulsar.update() == PulseStepper.State.PULSE) @@ -126,7 +126,7 @@ public void updateEntity() } // regardless of a pancheon being present, the curd SHOULD drip serverStep++; - markForBlockUpdate(); + markDirtyAndUpdate(); } } else @@ -166,10 +166,9 @@ public void readFromNBTForItem(NBTTagCompound nbt) readWheyPulsarFromNBT(nbt); } - @Override - public void readFromNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_READ) + public void readFromNBT_HangingCurds(NBTTagCompound nbt) { - super.readFromNBT(nbt); readCheeseCurdFromNBT(nbt); readWheyPulsarFromNBT(nbt); } @@ -192,15 +191,14 @@ public void writeToNBTForItem(NBTTagCompound nbt) writeWheyPulsarToNBT(nbt); } - @Override - public void writeToNBT(NBTTagCompound nbt) + @TileEventHandler(event=TileEventHandler.EventType.NBT_WRITE) + public void writeToNBT_HangingCurds(NBTTagCompound nbt) { - super.writeToNBT(nbt); writeCheeseCurdToNBT(nbt); writeWheyPulsarToNBT(nbt); } - @EventHandler(type=EventHandler.EventType.NETWORK_READ) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_READ) public boolean readFromStream_HangingCurds(ByteBuf stream) throws IOException { cheeseCurd.readFromStream(stream); @@ -209,7 +207,7 @@ public boolean readFromStream_HangingCurds(ByteBuf stream) throws IOException return true; } - @EventHandler(type=EventHandler.EventType.NETWORK_WRITE) + @TileEventHandler(event=TileEventHandler.EventType.NETWORK_WRITE) public boolean writeToStream_HangingCurds(ByteBuf stream) throws IOException { cheeseCurd.writeToStream(stream); diff --git a/src/java/growthcraft/milk/common/tileentity/TileEntityPancheon.java b/src/java/growthcraft/milk/common/tileentity/TileEntityPancheon.java index 23c22bfa8..b5b97fe56 100644 --- a/src/java/growthcraft/milk/common/tileentity/TileEntityPancheon.java +++ b/src/java/growthcraft/milk/common/tileentity/TileEntityPancheon.java @@ -24,15 +24,15 @@ package growthcraft.milk.common.tileentity; import growthcraft.api.core.fluids.FluidTest; -import growthcraft.core.common.tileentity.GrcTileEntityDeviceBase; -import growthcraft.core.common.tileentity.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.feature.ITileProgressiveDevice; +import growthcraft.core.common.tileentity.GrcTileDeviceBase; import growthcraft.milk.common.tileentity.device.Pancheon; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; -public class TileEntityPancheon extends GrcTileEntityDeviceBase implements ITileProgressiveDevice, IPancheonTile +public class TileEntityPancheon extends GrcTileDeviceBase implements ITileProgressiveDevice, IPancheonTile { private Pancheon pancheon = new Pancheon(this, 0, 2, 1); @@ -97,9 +97,13 @@ public boolean outputTanksHaveFluid() } @Override - protected void updateDevice() + public void updateEntity() { - pancheon.update(); + super.updateEntity(); + if (!worldObj.isRemote) + { + pancheon.update(); + } } @Override @@ -133,8 +137,9 @@ protected int doFill(ForgeDirection dir, FluidStack stack, boolean doFill) } @Override - protected void markForFluidUpdate() + protected void markFluidDirty() { - markForBlockUpdate(); + super.markFluidDirty(); + markDirtyAndUpdate(); } } diff --git a/src/java/growthcraft/milk/common/tileentity/device/Pancheon.java b/src/java/growthcraft/milk/common/tileentity/device/Pancheon.java index 0926393f6..33d2ac98e 100644 --- a/src/java/growthcraft/milk/common/tileentity/device/Pancheon.java +++ b/src/java/growthcraft/milk/common/tileentity/device/Pancheon.java @@ -99,6 +99,8 @@ private void commitRecipe() final FluidStack bottom = recipe.getBottomOutputFluid(); if (bottom != null) this.bottomSlot.fill(bottom, true); + markDirty(); + markForUpdate(); } } @@ -120,7 +122,7 @@ public void update() } else { - if (resetTime()) markForBlockUpdate(); + if (resetTime()) markDirty(); } } } diff --git a/src/java/growthcraft/milk/init/GrcMilkBlocks.java b/src/java/growthcraft/milk/init/GrcMilkBlocks.java index 39cb1adc6..b46b7e42e 100644 --- a/src/java/growthcraft/milk/init/GrcMilkBlocks.java +++ b/src/java/growthcraft/milk/init/GrcMilkBlocks.java @@ -24,7 +24,7 @@ package growthcraft.milk.init; import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleBlocks; import growthcraft.milk.common.block.BlockButterChurn; import growthcraft.milk.common.block.BlockCheeseBlock; import growthcraft.milk.common.block.BlockCheesePress; @@ -39,7 +39,7 @@ import net.minecraftforge.oredict.OreDictionary; -public class GrcMilkBlocks extends GrcModuleBase +public class GrcMilkBlocks extends GrcModuleBlocks { public BlockDefinition butterChurn; public BlockDefinition cheeseBlock; @@ -52,15 +52,15 @@ public class GrcMilkBlocks extends GrcModuleBase @Override public void preInit() { - this.butterChurn = new BlockDefinition(new BlockButterChurn()); - this.cheeseBlock = new BlockDefinition(new BlockCheeseBlock()); - this.cheesePress = new BlockDefinition(new BlockCheesePress()); - this.cheeseVat = new BlockDefinition(new BlockCheeseVat()); - this.hangingCurds = new BlockDefinition(new BlockHangingCurds()); - this.pancheon = new BlockDefinition(new BlockPancheon()); + this.butterChurn = newDefinition(new BlockButterChurn()); + this.cheeseBlock = newDefinition(new BlockCheeseBlock()); + this.cheesePress = newDefinition(new BlockCheesePress()); + this.cheeseVat = newDefinition(new BlockCheeseVat()); + this.hangingCurds = newDefinition(new BlockHangingCurds()); + this.pancheon = newDefinition(new BlockPancheon()); if (GrowthCraftMilk.getConfig().thistleEnabled) { - this.thistle = new BlockDefinition(new BlockThistle()); + this.thistle = newDefinition(new BlockThistle()); } } diff --git a/src/java/growthcraft/milk/init/GrcMilkFluids.java b/src/java/growthcraft/milk/init/GrcMilkFluids.java index 054a106a7..b0646025f 100644 --- a/src/java/growthcraft/milk/init/GrcMilkFluids.java +++ b/src/java/growthcraft/milk/init/GrcMilkFluids.java @@ -37,6 +37,7 @@ import growthcraft.api.core.effect.EffectList; import growthcraft.api.core.effect.EffectUtils; import growthcraft.api.core.effect.IEffect; +import growthcraft.api.core.fluids.TaggedFluidStacks; import growthcraft.api.core.GrcFluid; import growthcraft.api.core.item.OreItemStacks; import growthcraft.api.core.util.StringUtils; @@ -223,14 +224,28 @@ private void registerOres() if (milk != null) { OreDictionary.registerOre("bottleMilk", milk.foodBottle.asStack()); - OreDictionary.registerOre("bucketMilk", Items.milk_bucket); - // Milk bucket is the vanilla milk bucket, derp + } + // Milk bucket is the vanilla milk bucket, derp + OreDictionary.registerOre("bucketMilk", Items.milk_bucket); + if (skimMilk != null) + { OreDictionary.registerOre("bottleSkimmilk", skimMilk.foodBottle.asStack()); OreDictionary.registerOre("bucketSkimmilk", skimMilk.bucket.asStack()); + } + if (butterMilk != null) + { OreDictionary.registerOre("bottleButtermilk", butterMilk.foodBottle.asStack()); OreDictionary.registerOre("bucketButtermilk", butterMilk.bucket.asStack()); + } + if (whey != null) + { OreDictionary.registerOre("bottleWhey", whey.foodBottle.asStack()); OreDictionary.registerOre("bucketWhey", whey.bucket.asStack()); + // https://github.com/GrowthcraftCE/Growthcraft-1.7/issues/419 + OreDictionary.registerOre("foodStock", whey.foodBottle.asStack()); + } + if (cream != null) + { OreDictionary.registerOre("bottleCream", cream.bottle.asStack()); OreDictionary.registerOre("bucketCream", cream.bucket.asStack()); } @@ -247,8 +262,6 @@ private void registerFermentations() fs[i] = new FluidStack(kumisFluids[i], 1); } - final List milks = getMilkFluids(); - final int fermentTime = GrowthCraftCellar.getConfig().fermentTime; final ICellarBoozeBuilder builder = GrowthCraftCellar.boozeBuilderFactory.create(kumisFluids[0]); builder @@ -257,12 +270,9 @@ private void registerFermentations() .setTipsy(0.10f, 900) .addEffect(milkEffect); - for (Fluid fluid : milks) - { - final FluidStack milkStack = new FluidStack(fluid, 1); - builder.fermentsFrom(milkStack, EnumYeast.BREWERS.asStack(), fermentTime); - builder.fermentsFrom(milkStack, new ItemStack(Items.nether_wart), (int)(fermentTime * 0.66)); - } + final TaggedFluidStacks milkStacks = new TaggedFluidStacks(1, "milk"); + builder.fermentsFrom(milkStacks, EnumYeast.BREWERS.asStack(), fermentTime); + builder.fermentsFrom(milkStacks, new ItemStack(Items.nether_wart), (int)(fermentTime * 0.66)); GrowthCraftCellar.boozeBuilderFactory.create(kumisFluids[1]) .tags(BoozeTag.FERMENTED, BoozeTag.POTENT) diff --git a/src/java/growthcraft/milk/init/GrcMilkItems.java b/src/java/growthcraft/milk/init/GrcMilkItems.java index 043dd0776..2d2118aa8 100644 --- a/src/java/growthcraft/milk/init/GrcMilkItems.java +++ b/src/java/growthcraft/milk/init/GrcMilkItems.java @@ -25,7 +25,7 @@ import growthcraft.api.core.item.EnumDye; import growthcraft.core.common.definition.ItemDefinition; -import growthcraft.core.common.GrcModuleBase; +import growthcraft.core.common.GrcModuleItems; import growthcraft.milk.common.item.EnumButter; import growthcraft.milk.common.item.EnumCheeseType; import growthcraft.milk.common.item.EnumIceCream; @@ -46,7 +46,7 @@ import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe; -public class GrcMilkItems extends GrcModuleBase +public class GrcMilkItems extends GrcModuleItems { public ItemDefinition butter; public ItemDefinition cheese; @@ -60,17 +60,17 @@ public class GrcMilkItems extends GrcModuleBase @Override public void preInit() { - this.butter = new ItemDefinition(new ItemButter()); - this.cheese = new ItemDefinition(new ItemCheese()); - this.cheeseCloth = new ItemDefinition(new ItemCheeseCloth()); - this.iceCream = new ItemDefinition(new ItemIceCream()); - this.yogurt = new ItemDefinition(new ItemYogurt()); + this.butter = newDefinition(new ItemButter()); + this.cheese = newDefinition(new ItemCheese()); + this.cheeseCloth = newDefinition(new ItemCheeseCloth()); + this.iceCream = newDefinition(new ItemIceCream()); + this.yogurt = newDefinition(new ItemYogurt()); if (GrowthCraftMilk.getConfig().thistleSeedEnabled) { - this.seedThistle = new ItemDefinition(new ItemSeedThistle()); + this.seedThistle = newDefinition(new ItemSeedThistle()); } - this.stomach = new ItemDefinition(new ItemStomach()); - this.starterCulture = new ItemDefinition(new ItemStarterCulture()); + this.stomach = newDefinition(new ItemStomach()); + this.starterCulture = newDefinition(new ItemStarterCulture()); } @Override @@ -229,7 +229,7 @@ public void init() OreDictionary.registerOre("foodOffal", stomach.asStack()); OreDictionary.registerOre("materialStarterCulture", starterCulture.asStack()); OreDictionary.registerOre("materialCheeseCloth", cheeseCloth.asStack()); - + if (seedThistle != null) { OreDictionary.registerOre("listAllseed", seedThistle.asStack()); diff --git a/src/java/growthcraft/rice/GrcRiceConfig.java b/src/java/growthcraft/rice/GrcRiceConfig.java index fe58aa842..106574b78 100644 --- a/src/java/growthcraft/rice/GrcRiceConfig.java +++ b/src/java/growthcraft/rice/GrcRiceConfig.java @@ -19,6 +19,9 @@ public class GrcRiceConfig extends ConfigBase public int riceSakeDivineColor = 0xFFFACD; + @ConfigOption(catergory="Villager", name="Enabled", desc="Should we register Village Generation, and Villager Trades?") + public boolean enableVillageGen = true; + @ConfigOption(catergory="Village", name="Generate Village Rice Fields", desc="Should we spawn rice fields in villages?") public boolean generateRiceFieldStructure; diff --git a/src/java/growthcraft/rice/GrowthCraftRice.java b/src/java/growthcraft/rice/GrowthCraftRice.java index 7c993a217..9b1a99e09 100644 --- a/src/java/growthcraft/rice/GrowthCraftRice.java +++ b/src/java/growthcraft/rice/GrowthCraftRice.java @@ -4,22 +4,17 @@ import growthcraft.api.core.log.ILogger; import growthcraft.api.core.module.ModuleContainer; import growthcraft.cellar.GrowthCraftCellar; -import growthcraft.core.common.definition.BlockDefinition; -import growthcraft.core.common.definition.BlockTypeDefinition; -import growthcraft.core.common.definition.ItemDefinition; import growthcraft.core.eventhandler.PlayerInteractEventPaddy; import growthcraft.core.GrowthCraftCore; import growthcraft.core.integration.NEI; import growthcraft.core.util.MapGenHelper; -import growthcraft.rice.common.block.BlockPaddy; -import growthcraft.rice.common.block.BlockRice; import growthcraft.rice.common.CommonProxy; -import growthcraft.rice.common.item.ItemRice; -import growthcraft.rice.common.item.ItemRiceBall; import growthcraft.rice.common.village.ComponentVillageRiceField; import growthcraft.rice.common.village.VillageHandlerRice; import growthcraft.rice.event.BonemealEventRice; +import growthcraft.rice.init.GrcRiceBlocks; import growthcraft.rice.init.GrcRiceFluids; +import growthcraft.rice.init.GrcRiceItems; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -52,17 +47,13 @@ public class GrowthCraftRice @Instance(MOD_ID) public static GrowthCraftRice instance; + public static final GrcRiceBlocks blocks = new GrcRiceBlocks(); + public static final GrcRiceItems items = new GrcRiceItems(); + public static final GrcRiceFluids fluids = new GrcRiceFluids(); - public static BlockTypeDefinition riceBlock; - public static BlockDefinition paddyField; - public static ItemDefinition rice; - public static ItemDefinition riceBall; - - public static GrcRiceFluids fluids = new GrcRiceFluids(); - - private ILogger logger = new GrcLogger(MOD_ID); - private GrcRiceConfig config = new GrcRiceConfig(); - private ModuleContainer modules = new ModuleContainer(); + private final ILogger logger = new GrcLogger(MOD_ID); + private final GrcRiceConfig config = new GrcRiceConfig(); + private final ModuleContainer modules = new ModuleContainer(); public static GrcRiceConfig getConfig() { @@ -74,74 +65,59 @@ public void preload(FMLPreInitializationEvent event) { config.setLogger(logger); config.load(event.getModConfigurationDirectory(), "growthcraft/rice.conf"); - + modules.add(blocks); + modules.add(items); modules.add(fluids); if (config.enableForestryIntegration) modules.add(new growthcraft.rice.integration.ForestryModule()); if (config.enableMFRIntegration) modules.add(new growthcraft.rice.integration.MFRModule()); if (config.enableThaumcraftIntegration) modules.add(new growthcraft.rice.integration.ThaumcraftModule()); - + modules.add(CommonProxy.instance); if (config.debugEnabled) modules.setLogger(logger); - - //==================== - // INIT - //==================== - riceBlock = new BlockTypeDefinition(new BlockRice()); - paddyField = new BlockDefinition(new BlockPaddy()); - - rice = new ItemDefinition(new ItemRice()); - riceBall = new ItemDefinition(new ItemRiceBall()); - + modules.freeze(); modules.preInit(); register(); } private void register() { - //==================== - // REGISTRIES - //==================== - GameRegistry.registerBlock(riceBlock.getBlock(), "grc.riceBlock"); - GameRegistry.registerBlock(paddyField.getBlock(), "grc.paddyField"); - - GameRegistry.registerItem(rice.getItem(), "grc.rice"); - GameRegistry.registerItem(riceBall.getItem(), "grc.riceBall"); - - MinecraftForge.addGrassSeed(rice.asStack(), config.riceSeedDropRarity); + modules.register(); + MinecraftForge.addGrassSeed(items.rice.asStack(), config.riceSeedDropRarity); MapGenHelper.registerVillageStructure(ComponentVillageRiceField.class, "grc.ricefield"); //==================== // ORE DICTIONARY //==================== - OreDictionary.registerOre("cropRice", rice.getItem()); - OreDictionary.registerOre("seedRice", rice.getItem()); + OreDictionary.registerOre("cropRice", items.rice.getItem()); + OreDictionary.registerOre("seedRice", items.rice.getItem()); // For Pam's HarvestCraft // Uses the same OreDict. names as HarvestCraft - OreDictionary.registerOre("listAllseed", rice.getItem()); + OreDictionary.registerOre("listAllseed", items.rice.getItem()); //==================== // CRAFTING //==================== - GameRegistry.addRecipe(new ShapedOreRecipe(riceBall.asStack(1), "###", "###", '#', "cropRice")); + GameRegistry.addRecipe(new ShapedOreRecipe(items.riceBall.asStack(1), "###", "###", '#', "cropRice")); - NEI.hideItem(riceBlock.asStack()); + NEI.hideItem(blocks.riceBlock.asStack()); MinecraftForge.EVENT_BUS.register(this); - - modules.register(); } - @EventHandler - public void load(FMLInitializationEvent event) + private void initVillageHandlers() { - PlayerInteractEventPaddy.paddyBlocks.put(Blocks.farmland, paddyField.getBlock()); - - CommonProxy.instance.initRenders(); - final VillageHandlerRice handler = new VillageHandlerRice(); - VillagerRegistry.instance().registerVillageTradeHandler(GrowthCraftCellar.getConfig().villagerBrewerID, handler); + final int brewerID = GrowthCraftCellar.getConfig().villagerBrewerID; + if (brewerID > 0) + VillagerRegistry.instance().registerVillageTradeHandler(brewerID, handler); VillagerRegistry.instance().registerVillageCreationHandler(handler); + } + @EventHandler + public void load(FMLInitializationEvent event) + { + PlayerInteractEventPaddy.paddyBlocks.put(Blocks.farmland, blocks.paddyField.getBlock()); + if (config.enableVillageGen) initVillageHandlers(); modules.init(); } diff --git a/src/java/growthcraft/rice/client/ClientProxy.java b/src/java/growthcraft/rice/client/ClientProxy.java index 4652b6eda..e6631217f 100644 --- a/src/java/growthcraft/rice/client/ClientProxy.java +++ b/src/java/growthcraft/rice/client/ClientProxy.java @@ -1,3 +1,26 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.rice.client; import growthcraft.rice.client.renderer.RenderRice; @@ -8,8 +31,9 @@ public class ClientProxy extends CommonProxy { @Override - public void initRenders() + public void init() { + super.init(); RenderingRegistry.registerBlockHandler(new RenderRice()); } } diff --git a/src/java/growthcraft/rice/common/CommonProxy.java b/src/java/growthcraft/rice/common/CommonProxy.java index d9de403ae..b7f5dbb32 100644 --- a/src/java/growthcraft/rice/common/CommonProxy.java +++ b/src/java/growthcraft/rice/common/CommonProxy.java @@ -1,11 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015, 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ package growthcraft.rice.common; +import growthcraft.core.common.GrcModuleProxyBase; + import cpw.mods.fml.common.SidedProxy; -public class CommonProxy +public class CommonProxy extends GrcModuleProxyBase { @SidedProxy(clientSide="growthcraft.rice.client.ClientProxy", serverSide="growthcraft.rice.common.CommonProxy") public static CommonProxy instance; - - public void initRenders(){} } diff --git a/src/java/growthcraft/rice/common/block/BlockRice.java b/src/java/growthcraft/rice/common/block/BlockRice.java index 78533f579..6ef71b5e7 100644 --- a/src/java/growthcraft/rice/common/block/BlockRice.java +++ b/src/java/growthcraft/rice/common/block/BlockRice.java @@ -225,7 +225,7 @@ public boolean canBlockStay(World world, int x, int y, int z) @SideOnly(Side.CLIENT) public Item getItem(World world, int x, int y, int z) { - return GrowthCraftRice.rice.getItem(); + return GrowthCraftRice.items.rice.getItem(); } /************ @@ -234,7 +234,7 @@ public Item getItem(World world, int x, int y, int z) @Override public Item getItemDropped(int meta, Random random, int par3) { - return GrowthCraftRice.rice.getItem(); + return GrowthCraftRice.items.rice.getItem(); } @Override @@ -260,7 +260,7 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad { if (world.rand.nextInt(15) <= metadata) { - ret.add(GrowthCraftRice.rice.asStack(1)); + ret.add(GrowthCraftRice.items.rice.asStack(1)); } } } diff --git a/src/java/growthcraft/rice/common/item/ItemRice.java b/src/java/growthcraft/rice/common/item/ItemRice.java index 7d99b26d6..34ac2393a 100644 --- a/src/java/growthcraft/rice/common/item/ItemRice.java +++ b/src/java/growthcraft/rice/common/item/ItemRice.java @@ -38,7 +38,7 @@ else if (player.canPlayerEdit(x, y, z, dir, stack) && player.canPlayerEdit(x, y if (soil != null && RiceBlockCheck.isPaddy(soil) && world.isAirBlock(x, y + 1, z) && world.getBlockMetadata(x, y, z) > 0) { - world.setBlock(x, y + 1, z, GrowthCraftRice.riceBlock.getBlock()); + world.setBlock(x, y + 1, z, GrowthCraftRice.blocks.riceBlock.getBlock()); --stack.stackSize; return true; } diff --git a/src/java/growthcraft/rice/common/village/ComponentVillageRiceField.java b/src/java/growthcraft/rice/common/village/ComponentVillageRiceField.java index 877f658e8..b8eb1a35b 100644 --- a/src/java/growthcraft/rice/common/village/ComponentVillageRiceField.java +++ b/src/java/growthcraft/rice/common/village/ComponentVillageRiceField.java @@ -132,8 +132,8 @@ public boolean addComponentParts(World world, Random random, StructureBoundingBo map.put('-', new BlockEntry(Blocks.log, vert ? 4 : 8)); map.put('f', new BlockEntry(Blocks.fence)); map.put('g', new BlockEntry(Blocks.fence_gate, this.getMetadataWithOffset(Blocks.fence_gate, 0))); - map.put('p', new BlockEntry(GrowthCraftRice.paddyField.getBlock(), GrowthCraftRice.getConfig().paddyFieldMax)); - map.put('r', new BlockEntry(GrowthCraftRice.riceBlock.getBlock(), 6)); + map.put('p', new BlockEntry(GrowthCraftRice.blocks.paddyField.getBlock(), GrowthCraftRice.getConfig().paddyFieldMax)); + map.put('r', new BlockEntry(GrowthCraftRice.blocks.riceBlock.getBlock(), 6)); map.put('s', new BlockEntry(Blocks.oak_stairs, this.getMetadataWithOffset(Blocks.oak_stairs, 3))); map.put('t', new BlockEntry(Blocks.torch)); map.put('x', new BlockEntry(Blocks.log)); diff --git a/src/java/growthcraft/rice/event/BonemealEventRice.java b/src/java/growthcraft/rice/event/BonemealEventRice.java index b9a0efc05..1cbecbc26 100644 --- a/src/java/growthcraft/rice/event/BonemealEventRice.java +++ b/src/java/growthcraft/rice/event/BonemealEventRice.java @@ -26,7 +26,7 @@ private void appleBonemealEffect(World world, Random rand, int x, int y, int z) { for (int k = z - 1; k <= z + 1; ++k) { - final boolean isRiceBlock = (GrowthCraftRice.riceBlock.getBlock() == world.getBlock(i, y, k)) && + final boolean isRiceBlock = (GrowthCraftRice.blocks.riceBlock.getBlock() == world.getBlock(i, y, k)) && (world.getBlockMetadata(i, y, k) != 7); final boolean isPaddyBelow = RiceBlockCheck.isPaddy(world.getBlock(i, y - 1, k)) && (world.getBlockMetadata(i, y - 1, k) != 0); @@ -56,7 +56,7 @@ private void appleBonemealEffect(World world, Random rand, int x, int y, int z) @SubscribeEvent public void onUseBonemeal(BonemealEvent event) { - if (GrowthCraftRice.riceBlock.getBlock() == event.block) + if (GrowthCraftRice.blocks.riceBlock.getBlock() == event.block) { if (!event.world.isRemote) { diff --git a/src/java/growthcraft/rice/init/GrcRiceBlocks.java b/src/java/growthcraft/rice/init/GrcRiceBlocks.java new file mode 100644 index 000000000..5616dfece --- /dev/null +++ b/src/java/growthcraft/rice/init/GrcRiceBlocks.java @@ -0,0 +1,50 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.rice.init; + +import growthcraft.core.common.definition.BlockDefinition; +import growthcraft.core.common.definition.BlockTypeDefinition; +import growthcraft.core.common.GrcModuleBlocks; +import growthcraft.rice.common.block.BlockPaddy; +import growthcraft.rice.common.block.BlockRice; + +public class GrcRiceBlocks extends GrcModuleBlocks +{ + public BlockTypeDefinition riceBlock; + public BlockDefinition paddyField; + + @Override + public void preInit() + { + this.riceBlock = newTypedDefinition(new BlockRice()); + this.paddyField = newDefinition(new BlockPaddy()); + } + + @Override + public void register() + { + riceBlock.register("grc.riceBlock"); + paddyField.register("grc.paddyField"); + } +} diff --git a/src/java/growthcraft/rice/init/GrcRiceFluids.java b/src/java/growthcraft/rice/init/GrcRiceFluids.java index 5b555ada1..bd9e241f0 100644 --- a/src/java/growthcraft/rice/init/GrcRiceFluids.java +++ b/src/java/growthcraft/rice/init/GrcRiceFluids.java @@ -73,7 +73,7 @@ public void preInit() BoozeRegistryHelper.setBoozeFoodStats(riceSakeBooze[0], 1, 0.2f); riceSakeBooze[4].setColor(GrowthCraftRice.getConfig().riceSakeDivineColor); riceSakeFluids[4].getBlock().refreshColor(); - riceSake = new ItemDefinition(new ItemBoozeBottle(riceSakeBooze)); + riceSake = GrowthCraftRice.items.newDefinition(new ItemBoozeBottle(riceSakeBooze)); } private void registerRecipes() diff --git a/src/java/growthcraft/rice/init/GrcRiceItems.java b/src/java/growthcraft/rice/init/GrcRiceItems.java new file mode 100644 index 000000000..6f93c3dba --- /dev/null +++ b/src/java/growthcraft/rice/init/GrcRiceItems.java @@ -0,0 +1,49 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016 IceDragon200 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package growthcraft.rice.init; + +import growthcraft.core.common.definition.ItemDefinition; +import growthcraft.core.common.GrcModuleItems; +import growthcraft.rice.common.item.ItemRice; +import growthcraft.rice.common.item.ItemRiceBall; + +public class GrcRiceItems extends GrcModuleItems +{ + public ItemDefinition rice; + public ItemDefinition riceBall; + + @Override + public void preInit() + { + this.rice = newDefinition(new ItemRice()); + this.riceBall = newDefinition(new ItemRiceBall()); + } + + @Override + public void register() + { + rice.register("grc.rice"); + riceBall.register("grc.riceBall"); + } +} diff --git a/src/java/growthcraft/rice/integration/ForestryModule.java b/src/java/growthcraft/rice/integration/ForestryModule.java index 90637a51a..1332895e6 100644 --- a/src/java/growthcraft/rice/integration/ForestryModule.java +++ b/src/java/growthcraft/rice/integration/ForestryModule.java @@ -45,8 +45,8 @@ protected void integrate() { final int seedamount = getActiveMode().getIntegerSetting("squeezer.liquid.seed"); - final ItemStack riceSeed = GrowthCraftRice.rice.asStack(); - final Block riceBlock = GrowthCraftRice.riceBlock.getBlock(); + final ItemStack riceSeed = GrowthCraftRice.items.rice.asStack(); + final Block riceBlock = GrowthCraftRice.blocks.riceBlock.getBlock(); if (ForestryFluids.SEEDOIL.exists()) recipes().squeezerManager.addRecipe(10, new ItemStack[]{riceSeed}, ForestryFluids.SEEDOIL.asFluidStack(seedamount)); Backpack.FORESTERS.add(riceSeed); addFarmable("farmOrchard", new FarmableBasicGrowthCraft(riceBlock, GrowthCraftRice.getConfig().paddyFieldMax, true, false)); diff --git a/src/java/growthcraft/rice/integration/MFRModule.java b/src/java/growthcraft/rice/integration/MFRModule.java index 5fa15ee0d..f2fa252bc 100644 --- a/src/java/growthcraft/rice/integration/MFRModule.java +++ b/src/java/growthcraft/rice/integration/MFRModule.java @@ -44,6 +44,6 @@ protected void integrate() { registerHarvestable(new RiceFactoryHarvester()); registerPlantable(new RiceFactoryPlanter()); - registerFertilizableCrop(GrowthCraftRice.riceBlock.getBlock(), BlockRice.RiceStage.MATURE); + registerFertilizableCrop(GrowthCraftRice.blocks.riceBlock.getBlock(), BlockRice.RiceStage.MATURE); } } diff --git a/src/java/growthcraft/rice/integration/ThaumcraftModule.java b/src/java/growthcraft/rice/integration/ThaumcraftModule.java index 2629d4c47..1480bdb0f 100644 --- a/src/java/growthcraft/rice/integration/ThaumcraftModule.java +++ b/src/java/growthcraft/rice/integration/ThaumcraftModule.java @@ -46,10 +46,10 @@ public ThaumcraftModule() @Optional.Method(modid="Thaumcraft") protected void integrate() { - FMLInterModComms.sendMessage(modID, "harvestStandardCrop", GrowthCraftRice.riceBlock.asStack(1, 7)); + FMLInterModComms.sendMessage(modID, "harvestStandardCrop", GrowthCraftRice.blocks.riceBlock.asStack(1, 7)); - ThaumcraftApi.registerObjectTag(GrowthCraftRice.rice.asStack(), new AspectList().add(Aspect.CROP, 1)); - ThaumcraftApi.registerObjectTag(GrowthCraftRice.riceBall.asStack(), new AspectList().add(Aspect.ENTROPY, 1).add(Aspect.PLANT, 1).add(Aspect.CRAFT, 1).add(Aspect.HUNGER, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftRice.items.rice.asStack(), new AspectList().add(Aspect.CROP, 1)); + ThaumcraftApi.registerObjectTag(GrowthCraftRice.items.riceBall.asStack(), new AspectList().add(Aspect.ENTROPY, 1).add(Aspect.PLANT, 1).add(Aspect.CRAFT, 1).add(Aspect.HUNGER, 1)); final AspectList[] common = new AspectList[] { diff --git a/src/java/growthcraft/rice/integration/mfr/RiceFactoryHarvester.java b/src/java/growthcraft/rice/integration/mfr/RiceFactoryHarvester.java index 5385e0ab2..f1a90e78c 100644 --- a/src/java/growthcraft/rice/integration/mfr/RiceFactoryHarvester.java +++ b/src/java/growthcraft/rice/integration/mfr/RiceFactoryHarvester.java @@ -36,7 +36,7 @@ public class RiceFactoryHarvester extends AbstractFactoryHarvestable public RiceFactoryHarvester() { super(); - setPlant(GrowthCraftRice.riceBlock.getBlock()); + setPlant(GrowthCraftRice.blocks.riceBlock.getBlock()); } @Override diff --git a/src/java/growthcraft/rice/integration/mfr/RiceFactoryPlanter.java b/src/java/growthcraft/rice/integration/mfr/RiceFactoryPlanter.java index 854650c91..9f16d823e 100644 --- a/src/java/growthcraft/rice/integration/mfr/RiceFactoryPlanter.java +++ b/src/java/growthcraft/rice/integration/mfr/RiceFactoryPlanter.java @@ -35,7 +35,7 @@ public class RiceFactoryPlanter extends AbstractFactoryPlantable { public RiceFactoryPlanter() { - super(GrowthCraftRice.rice.getItem(), GrowthCraftRice.riceBlock.getBlock()); + super(GrowthCraftRice.items.rice.getItem(), GrowthCraftRice.blocks.riceBlock.getBlock()); } @Override diff --git a/src/java/growthcraft/rice/util/RiceBlockCheck.java b/src/java/growthcraft/rice/util/RiceBlockCheck.java index 405df3cea..474441b85 100644 --- a/src/java/growthcraft/rice/util/RiceBlockCheck.java +++ b/src/java/growthcraft/rice/util/RiceBlockCheck.java @@ -40,7 +40,7 @@ private RiceBlockCheck() {} */ public static boolean isPaddy(Block block) { - return GrowthCraftRice.paddyField.equals(block); + return GrowthCraftRice.blocks.paddyField.equals(block); } /** diff --git a/src/resources/assets/grcfishtrap/textures/guis/fishtrap_gui.png b/src/resources/assets/grcfishtrap/textures/guis/fishtrap_gui.png index 720333a97..20dd1ff3a 100644 Binary files a/src/resources/assets/grcfishtrap/textures/guis/fishtrap_gui.png and b/src/resources/assets/grcfishtrap/textures/guis/fishtrap_gui.png differ diff --git a/src/resources/assets/grchops/lang/ru_RU.lang b/src/resources/assets/grchops/lang/ru_RU.lang index ca89b109e..c637a2d34 100644 --- a/src/resources/assets/grchops/lang/ru_RU.lang +++ b/src/resources/assets/grchops/lang/ru_RU.lang @@ -6,43 +6,46 @@ item.grc.hops.name=Обычный хмель item.grc.hopSeeds.name=Семена обычного хмеля # Fluids +fluid.grc.hopAle=Эль fluid.grc.hopAle0=Эль fluid.grc.hopAle1=Эль fluid.grc.hopAle2=Эль fluid.grc.hopAle3=Эль fluid.grc.hopAle4=Эль -fluid.grc.hopAle5=fluid.grc.hopAle5 -fluid.grc.hopAle6=fluid.grc.hopAle6 -fluid.grc.hopAle7=fluid.grc.hopAle7 -fluid.grc.hopAle8=fluid.grc.hopAle8 +fluid.grc.hopAle5=Эль +fluid.grc.hopAle6=Эль +fluid.grc.hopAle7=Эль +fluid.grc.hopAle8=Эль -fluid.grc.lager0=fluid.grc.lager0 -fluid.grc.lager1=fluid.grc.lager1 -fluid.grc.lager2=fluid.grc.lager2 -fluid.grc.lager3=fluid.grc.lager3 -fluid.grc.lager4=fluid.grc.lager4 -fluid.grc.lager5=fluid.grc.lager5 -fluid.grc.lager6=fluid.grc.lager6 +fluid.grc.lager=Светлое пиво +fluid.grc.lager0=Светлое пиво +fluid.grc.lager1=Светлое пиво +fluid.grc.lager2=Светлое пиво +fluid.grc.lager3=Светлое пиво +fluid.grc.lager4=Светлое пиво +fluid.grc.lager5=Светлое пиво +fluid.grc.lager6=Светлое пиво # Fluid Buckets +item.bucket.fluid.grc.hopAle.name=Ведро эля item.bucket.fluid.grc.hopAle0.name=Ведро эля item.bucket.fluid.grc.hopAle1.name=Ведро эля item.bucket.fluid.grc.hopAle2.name=Ведро эля item.bucket.fluid.grc.hopAle3.name=Ведро эля item.bucket.fluid.grc.hopAle4.name=Ведро эля -item.bucket.fluid.grc.hopAle5.name=item.bucket.fluid.grc.hopAle5.name -item.bucket.fluid.grc.hopAle6.name=item.bucket.fluid.grc.hopAle6.name -item.bucket.fluid.grc.hopAle7.name=item.bucket.fluid.grc.hopAle7.name -item.bucket.fluid.grc.hopAle8.name=item.bucket.fluid.grc.hopAle8.name +item.bucket.fluid.grc.hopAle5.name=Ведро эля +item.bucket.fluid.grc.hopAle6.name=Ведро эля +item.bucket.fluid.grc.hopAle7.name=Ведро эля +item.bucket.fluid.grc.hopAle8.name=Ведро эля -item.bucket.fluid.grc.lager.name=item.bucket.fluid.grc.lager.name -item.bucket.fluid.grc.lager0.name=item.bucket.fluid.grc.lager0.name -item.bucket.fluid.grc.lager1.name=item.bucket.fluid.grc.lager1.name -item.bucket.fluid.grc.lager2.name=item.bucket.fluid.grc.lager2.name -item.bucket.fluid.grc.lager3.name=item.bucket.fluid.grc.lager3.name -item.bucket.fluid.grc.lager4.name=item.bucket.fluid.grc.lager4.name -item.bucket.fluid.grc.lager5.name=item.bucket.fluid.grc.lager5.name -item.bucket.fluid.grc.lager6.name=item.bucket.fluid.grc.lager6.name +item.bucket.fluid.grc.lager.name=Ведро светлого пива +item.bucket.fluid.grc.lager0.name=Ведро светлого пива +item.bucket.fluid.grc.lager1.name=Ведро светлого пива +item.bucket.fluid.grc.lager2.name=Ведро светлого пива +item.bucket.fluid.grc.lager3.name=Ведро светлого пива +item.bucket.fluid.grc.lager4.name=Ведро светлого пива +item.bucket.fluid.grc.lager5.name=Ведро светлого пива +item.bucket.fluid.grc.lager6.name=Ведро светлого пива # Fluid Blocks tile.fluid.grc.hopAle.name=Эль @@ -51,19 +54,19 @@ tile.fluid.grc.hopAle1.name=Эль tile.fluid.grc.hopAle2.name=Эль tile.fluid.grc.hopAle3.name=Эль tile.fluid.grc.hopAle4.name=Эль -tile.fluid.grc.hopAle5.name=tile.fluid.grc.hopAle5.name -tile.fluid.grc.hopAle6.name=tile.fluid.grc.hopAle6.name -tile.fluid.grc.hopAle7.name=tile.fluid.grc.hopAle7.name -tile.fluid.grc.hopAle8.name=tile.fluid.grc.hopAle8.name +tile.fluid.grc.hopAle5.name=Эль +tile.fluid.grc.hopAle6.name=Эль +tile.fluid.grc.hopAle7.name=Эль +tile.fluid.grc.hopAle8.name=Эль -tile.fluid.grc.lager.name=tile.fluid.grc.lager.name -tile.fluid.grc.lager0.name=tile.fluid.grc.lager0.name -tile.fluid.grc.lager1.name=tile.fluid.grc.lager1.name -tile.fluid.grc.lager2.name=tile.fluid.grc.lager2.name -tile.fluid.grc.lager3.name=tile.fluid.grc.lager3.name -tile.fluid.grc.lager4.name=tile.fluid.grc.lager4.name -tile.fluid.grc.lager5.name=tile.fluid.grc.lager5.name -tile.fluid.grc.lager6.name=tile.fluid.grc.lager6.name +tile.fluid.grc.lager.name=Светлое пиво +tile.fluid.grc.lager0.name=Светлое пиво +tile.fluid.grc.lager1.name=Светлое пиво +tile.fluid.grc.lager2.name=Светлое пиво +tile.fluid.grc.lager3.name=Светлое пиво +tile.fluid.grc.lager4.name=Светлое пиво +tile.fluid.grc.lager5.name=Светлое пиво +tile.fluid.grc.lager6.name=Светлое пиво # Fluid Tooltips -fluid.grc.hopAle4.modifier=Нехмельной, молодой \ No newline at end of file +fluid.grc.hopAle4.modifier=Нехмельной, молодой diff --git a/src/test/java/growthcraft/core/common/inventory/InventoryProcessorTest.java b/src/test/java/growthcraft/core/common/inventory/InventoryProcessorTest.java index e9af4eaa9..3a01793d2 100644 --- a/src/test/java/growthcraft/core/common/inventory/InventoryProcessorTest.java +++ b/src/test/java/growthcraft/core/common/inventory/InventoryProcessorTest.java @@ -202,7 +202,7 @@ public void test_findNextPresent() assertEquals(0, invProc.findNextPresent(inv)); // clear inventory and ensure that it doesn't find anything - inv.clearInventory(); + inv.clear(); assertEquals(-1, invProc.findNextPresent(inv)); @@ -225,7 +225,7 @@ public void test_findNextPresentFromEnd() assertEquals(0, invProc.findNextPresentFromEnd(inv)); // clear inventory and ensure that it doesn't find anything - inv.clearInventory(); + inv.clear(); assertEquals(-1, invProc.findNextPresentFromEnd(inv)); inv.setInventorySlotContents(2, apple.copy());