Skip to content

Commit

Permalink
Add IMC for registering flowers (#2027)
Browse files Browse the repository at this point in the history
  • Loading branch information
temp1011 authored and Nedelosk committed Apr 27, 2018
1 parent 0ff0aa8 commit f12c6d2
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/main/java/forestry/apiculture/ModuleApiculture.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.minecraft.init.Items;
import net.minecraft.init.PotionTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -157,9 +159,9 @@ public class ModuleApiculture extends BlankForestryModule {
public static int ticksPerBeeWorkCycle = 550;

public static boolean hivesDamageOnPeaceful = false;

public static boolean doSelfPollination = true;

public static int maxFlowersSpawnedPerHive = 20;
@Nullable
public static VillagerRegistry.VillagerProfession villagerApiarist;
Expand Down Expand Up @@ -282,7 +284,7 @@ public void doInit() {
ticksPerBeeWorkCycle = config.getIntLocalized("beekeeping", "ticks.work", 550, 250, 850);

hivesDamageOnPeaceful = config.getBooleanLocalized("beekeeping", "hivedamage.peaceful", false);

doSelfPollination = config.getBooleanLocalized("beekeeping", "self.pollination", false);

config.save();
Expand Down Expand Up @@ -988,11 +990,52 @@ public boolean processIMCMessage(IMCMessage message) {
HiveConfig.addBlacklistedDim(dim);
}
return true;
} else if (message.key.equals("add-plantable-flower")) {
return addPlantableFlower(message);
} else if (message.key.equals("add-acceptable-flower")) {
return addAcceptableFlower(message);
}

return false;
}

private boolean addPlantableFlower(IMCMessage message) {
try {
NBTTagCompound tagCompound = message.getNBTValue();
IBlockState flowerState = NBTUtil.readBlockState(tagCompound);
double weight = tagCompound.getDouble("weight");
List<String> flowerTypes = new ArrayList<>();
for (String key : tagCompound.getKeySet()) {
if (key.contains("flowertype")) {
flowerTypes.add(tagCompound.getString("flowertype"));
}
}
FlowerManager.flowerRegistry.registerPlantableFlower(flowerState, weight, flowerTypes.toArray(new String[flowerTypes.size()]));
return true;
} catch (Exception e) {
IMCUtil.logInvalidIMCMessage(message);
return false;
}
}

private boolean addAcceptableFlower(IMCMessage message) {
try {
NBTTagCompound tagCompound = message.getNBTValue();
IBlockState flowerState = NBTUtil.readBlockState(tagCompound);
List<String> flowerTypes = new ArrayList<>();
for (String key : tagCompound.getKeySet()) {
if (key.contains("flowertype")) {
flowerTypes.add(tagCompound.getString("flowertype"));
}
}
FlowerManager.flowerRegistry.registerAcceptableFlower(flowerState, flowerTypes.toArray(new String[flowerTypes.size()]));
return true;
} catch (Exception e) {
IMCUtil.logInvalidIMCMessage(message);
return false;
}
}

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureHook(TextureStitchEvent.Pre event) {
Expand Down

0 comments on commit f12c6d2

Please sign in to comment.