mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
some api and config for the pickaxe conversion and flower generator
This commit is contained in:
parent
d2531e1d8a
commit
27217f5854
7 changed files with 92 additions and 11 deletions
|
@ -5,6 +5,9 @@ import de.ellpeck.naturesaura.api.NACapabilities;
|
|||
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityImpl;
|
||||
import de.ellpeck.naturesaura.compat.Compat;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
|
@ -16,6 +19,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -180,4 +184,34 @@ public final class Helper {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static IBlockState getStateFromString(String raw) {
|
||||
String[] split = raw.split("\\[");
|
||||
Block block = Block.REGISTRY.getObject(new ResourceLocation(split[0]));
|
||||
if (block != null) {
|
||||
IBlockState state = block.getDefaultState();
|
||||
if (split.length > 1) {
|
||||
for (String part : split[1].replace("]", "").split(",")) {
|
||||
String[] keyValue = part.split("=");
|
||||
for (IProperty<?> prop : state.getProperties().keySet()) {
|
||||
IBlockState changed = findProperty(state, prop, keyValue[0], keyValue[1]);
|
||||
if (changed != null) {
|
||||
state = changed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
private static <T extends Comparable<T>> IBlockState findProperty(IBlockState state, IProperty<T> prop, String key, String newValue) {
|
||||
if (key.equals(prop.getName()))
|
||||
for (T value : prop.getAllowedValues())
|
||||
if (prop.getName(value).equals(newValue))
|
||||
return state.withProperty(prop, value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura;
|
||||
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import net.minecraftforge.common.config.Config;
|
||||
import net.minecraftforge.common.config.Config.Comment;
|
||||
import net.minecraftforge.common.config.Config.RangeDouble;
|
||||
|
@ -15,6 +16,11 @@ public final class ModConfig {
|
|||
@Comment("If using Dragon's Breath in a Brewing Stand should not cause a glass bottle to appear")
|
||||
public boolean removeDragonBreathContainerItem = true;
|
||||
|
||||
@Comment("Additional conversion recipes for the Botanist's Pickaxe right click function. Each entry needs to be formatted as modid:input_block[prop1=value1,...]->modid:output_block[prop1=value1,...] where block state properties are optional")
|
||||
public String[] additionalBotanistPickaxeConversions = new String[0];
|
||||
|
||||
@Comment("Additional blocks that the Herbivorous Absorber can consume to generate Aura. Each entry needs to be formatted as modid:block[prop1=value1,...] where block state properties are optional")
|
||||
public String[] additionalHerbivorousAbsorberFlowers = new String[0];
|
||||
}
|
||||
|
||||
public static class Client {
|
||||
|
@ -26,4 +32,24 @@ public final class ModConfig {
|
|||
@Comment("If particle spawning should respect the particle setting in Minecraft's video settings screen")
|
||||
public boolean respectVanillaParticleSettings = true;
|
||||
}
|
||||
|
||||
public static void initOrReload() {
|
||||
try {
|
||||
for (String s : general.additionalBotanistPickaxeConversions) {
|
||||
String[] split = s.split("->");
|
||||
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
|
||||
Helper.getStateFromString(split[0]),
|
||||
Helper.getStateFromString(split[1]));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NaturesAura.LOGGER.warn("Error parsing additionalBotanistPickaxeConversions", e);
|
||||
}
|
||||
|
||||
try {
|
||||
for (String s : general.additionalHerbivorousAbsorberFlowers)
|
||||
NaturesAuraAPI.FLOWER_GENERATOR_BLOCKS.add(Helper.getStateFromString(s));
|
||||
} catch (Exception e) {
|
||||
NaturesAura.LOGGER.warn("Error parsing additionalHerbivorousAbsorberFlowers", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public final class NaturesAura {
|
|||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
ModConfig.initOrReload();
|
||||
ModRecipes.init();
|
||||
ModRegistry.init(event);
|
||||
OreDict.init();
|
||||
|
|
|
@ -5,13 +5,17 @@ import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
|||
import de.ellpeck.naturesaura.api.internal.StubHooks;
|
||||
import de.ellpeck.naturesaura.api.recipes.AltarRecipe;
|
||||
import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe;
|
||||
import net.minecraft.block.BlockFlower;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
@ -35,6 +39,18 @@ public final class NaturesAuraAPI {
|
|||
* added to this list.
|
||||
*/
|
||||
public static final Map<ResourceLocation, TreeRitualRecipe> TREE_RITUAL_RECIPES = new HashMap<>();
|
||||
/**
|
||||
* The list of all types of flowers that the flower generator can use for
|
||||
* consumption. By default, all {@link BlockFlower} instances and all blocks
|
||||
* specified in the config file are added
|
||||
*/
|
||||
public static final List<IBlockState> FLOWER_GENERATOR_BLOCKS = new ArrayList<>();
|
||||
/**
|
||||
* A map of all of the block states that the Botanist's Pickaxe can convert
|
||||
* into their mossy variations. Contains mossy brick and mossy cobblestone
|
||||
* by default, along with all blocks specified in the config file
|
||||
*/
|
||||
public static final Map<IBlockState, IBlockState> BOTANIST_PICKAXE_CONVERSIONS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* This method returns the active {@link IInternalHooks} instance which can
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.AuraType;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
|
@ -25,12 +26,10 @@ import java.util.Map;
|
|||
|
||||
public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickable {
|
||||
|
||||
private static final List<IBlockState> FLOWERS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
for (Block block : ForgeRegistries.BLOCKS) {
|
||||
if (block instanceof BlockFlower) {
|
||||
FLOWERS.addAll(block.getBlockState().getValidStates());
|
||||
NaturesAuraAPI.FLOWER_GENERATOR_BLOCKS.addAll(block.getBlockState().getValidStates());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +45,7 @@ public class TileEntityFlowerGenerator extends TileEntityImpl implements ITickab
|
|||
for (int z = -range; z <= range; z++) {
|
||||
BlockPos offset = this.pos.add(x, 0, z);
|
||||
IBlockState state = this.world.getBlockState(offset);
|
||||
if (FLOWERS.contains(state)) {
|
||||
if (NaturesAuraAPI.FLOWER_GENERATOR_BLOCKS.contains(state)) {
|
||||
possible.add(offset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura.events;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NACapabilities;
|
||||
import de.ellpeck.naturesaura.api.aura.AuraType;
|
||||
|
@ -58,6 +59,7 @@ public class CommonEvents {
|
|||
public void onConfigChanged(OnConfigChangedEvent event) {
|
||||
if (NaturesAura.MOD_ID.equals(event.getModID())) {
|
||||
ConfigManager.sync(NaturesAura.MOD_ID, Config.Type.INSTANCE);
|
||||
ModConfig.initOrReload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package de.ellpeck.naturesaura.items.tools;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import de.ellpeck.naturesaura.Helper;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import de.ellpeck.naturesaura.reg.IModItem;
|
||||
import de.ellpeck.naturesaura.reg.IModelProvider;
|
||||
|
@ -26,14 +26,17 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
|||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvider {
|
||||
|
||||
private static final Map<IBlockState, IBlockState> BOTANIST_CONVERSION = ImmutableMap.<IBlockState, IBlockState>builder()
|
||||
.put(Blocks.COBBLESTONE.getDefaultState(), Blocks.MOSSY_COBBLESTONE.getDefaultState())
|
||||
.put(Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.DEFAULT),
|
||||
Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY)).build();
|
||||
static {
|
||||
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
|
||||
Blocks.COBBLESTONE.getDefaultState(),
|
||||
Blocks.MOSSY_COBBLESTONE.getDefaultState());
|
||||
NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.put(
|
||||
Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.DEFAULT),
|
||||
Blocks.STONEBRICK.getDefaultState().withProperty(BlockStoneBrick.VARIANT, BlockStoneBrick.EnumType.MOSSY));
|
||||
}
|
||||
|
||||
private final String baseName;
|
||||
|
||||
|
@ -72,7 +75,7 @@ public class ItemPickaxeNA extends ItemPickaxe implements IModItem, IModelProvid
|
|||
if (this == ModItems.INFUSED_PICKAXE) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
IBlockState state = worldIn.getBlockState(pos);
|
||||
IBlockState result = BOTANIST_CONVERSION.get(state);
|
||||
IBlockState result = NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.get(state);
|
||||
if (result != null) {
|
||||
if (!worldIn.isRemote)
|
||||
worldIn.setBlockState(pos, result);
|
||||
|
|
Loading…
Reference in a new issue