mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 14:59:22 +01:00
parent
548050b6e9
commit
3392441e38
11 changed files with 105 additions and 23 deletions
|
@ -1,5 +1,7 @@
|
|||
package de.ellpeck.naturesaura.blocks;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityChunkLoader;
|
||||
|
@ -8,17 +10,22 @@ import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
|
||||
|
@ -56,6 +63,8 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
|
|||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
if (!ModConfig.instance.chunkLoader.get())
|
||||
return;
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
if (tile instanceof TileEntityChunkLoader) {
|
||||
int range = ((TileEntityChunkLoader) tile).range();
|
||||
|
@ -78,6 +87,16 @@ public class BlockChunkLoader extends BlockContainerImpl implements IVisualizabl
|
|||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return ModConfig.instance.chunkLoader.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, @Nullable IBlockReader worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
|
||||
super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateCustomBlockState(BlockStateGenerator generator) {
|
||||
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.ellpeck.naturesaura.blocks;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.TileEntityRFConverter;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -9,4 +11,9 @@ public class BlockRFConverter extends BlockContainerImpl {
|
|||
public BlockRFConverter() {
|
||||
super("rf_converter", TileEntityRFConverter::new, Properties.create(Material.ROCK).sound(SoundType.STONE).hardnessAndResistance(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return ModConfig.instance.rfConverter.get() ? super.getTranslationKey() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public final class Multiblocks {
|
|||
'L', ModBlocks.ANCIENT_LOG,
|
||||
'0', ModBlocks.AUTO_CRAFTER,
|
||||
' ', Matcher.wildcard());
|
||||
public static final IMultiblock RF_CONVERTER = ModConfig.instance.rfConverter.get() ? NaturesAuraAPI.instance().createMultiblock(
|
||||
public static final IMultiblock RF_CONVERTER = NaturesAuraAPI.instance().createMultiblock(
|
||||
new ResourceLocation(NaturesAura.MOD_ID, "rf_converter"),
|
||||
new String[][]{
|
||||
{" ", " ", " ", " R ", " ", " ", " "},
|
||||
|
@ -110,5 +110,5 @@ public final class Multiblocks {
|
|||
{" ", " ", " ", " R ", " ", " ", " "}},
|
||||
'R', Blocks.REDSTONE_BLOCK,
|
||||
'0', ModBlocks.RF_CONVERTER,
|
||||
' ', Matcher.wildcard()) : null;
|
||||
' ', Matcher.wildcard());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.ITickableTileEntity;
|
||||
|
@ -16,17 +17,12 @@ import java.util.stream.Collectors;
|
|||
public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTileEntity {
|
||||
|
||||
private final List<ChunkPos> forcedChunks = new ArrayList<>();
|
||||
private boolean firstTick = true;
|
||||
|
||||
public TileEntityChunkLoader() {
|
||||
super(ModTileEntities.CHUNK_LOADER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
super.validate();
|
||||
this.loadChunks(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
super.remove();
|
||||
|
@ -47,7 +43,7 @@ public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
|
|||
}
|
||||
|
||||
private void loadChunks(boolean unload) {
|
||||
if (this.world.isRemote)
|
||||
if (this.world.isRemote || !ModConfig.instance.chunkLoader.get())
|
||||
return;
|
||||
ServerWorld world = (ServerWorld) this.world;
|
||||
|
||||
|
@ -82,7 +78,14 @@ public class TileEntityChunkLoader extends TileEntityImpl implements ITickableTi
|
|||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!this.world.isRemote) {
|
||||
if (!this.world.isRemote && ModConfig.instance.chunkLoader.get()) {
|
||||
// defer loading chunks on load to here since, otherwise, deadlocks happen oof
|
||||
// since forced chunks are saved to disk by the game, this is only necessary for when the chunk loader config changes
|
||||
if (this.firstTick) {
|
||||
this.loadChunks(false);
|
||||
this.firstTick = false;
|
||||
}
|
||||
|
||||
if (this.world.getGameTime() % 20 != 0)
|
||||
return;
|
||||
int toUse = MathHelper.ceil(this.range() / 2F);
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TileEntityRFConverter extends TileEntityImpl implements ITickableTi
|
|||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!this.world.isRemote) {
|
||||
if (!this.world.isRemote && ModConfig.instance.rfConverter.get()) {
|
||||
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) {
|
||||
this.sendToClients();
|
||||
this.lastEnergy = this.storage.getEnergyStored();
|
||||
|
|
|
@ -388,7 +388,7 @@ public class ClientEvents {
|
|||
} else if (tile instanceof TileEntityRFConverter) {
|
||||
EnergyStorage storage = ((TileEntityRFConverter) tile).storage;
|
||||
this.drawContainerInfo(stack, storage.getEnergyStored(), storage.getMaxEnergyStored(), 0xcc4916,
|
||||
mc, res, 35, I18n.format("tile.naturesaura.rf_converter.name"),
|
||||
mc, res, 35, I18n.format("block.naturesaura.rf_converter"),
|
||||
storage.getEnergyStored() + " / " + storage.getMaxEnergyStored() + " RF");
|
||||
} else if (tile instanceof TileEntityGratedChute) {
|
||||
TileEntityGratedChute chute = (TileEntityGratedChute) tile;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package de.ellpeck.naturesaura.recipes;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.ellpeck.naturesaura.ModConfig;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import net.minecraft.util.JSONUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
|
||||
public class EnabledCondition implements ICondition {
|
||||
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled");
|
||||
private ForgeConfigSpec.ConfigValue<Boolean> config;
|
||||
private final String name;
|
||||
|
||||
public EnabledCondition(String name) {
|
||||
this.name = name;
|
||||
try {
|
||||
this.config = (ForgeConfigSpec.ConfigValue<Boolean>) ModConfig.class.getField(name).get(ModConfig.instance);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
NaturesAura.LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getID() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test() {
|
||||
return this.config != null && this.config.get();
|
||||
}
|
||||
|
||||
public static class Serializer implements IConditionSerializer<EnabledCondition> {
|
||||
@Override
|
||||
public void write(JsonObject json, EnabledCondition value) {
|
||||
json.addProperty("config", value.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnabledCondition read(JsonObject json) {
|
||||
return new EnabledCondition(JSONUtils.getString(json, "config"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getID() {
|
||||
return EnabledCondition.NAME;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import de.ellpeck.naturesaura.items.*;
|
|||
import de.ellpeck.naturesaura.items.tools.*;
|
||||
import de.ellpeck.naturesaura.potion.ModPotions;
|
||||
import de.ellpeck.naturesaura.potion.PotionBreathless;
|
||||
import de.ellpeck.naturesaura.recipes.EnabledCondition;
|
||||
import de.ellpeck.naturesaura.recipes.ModRecipes;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -51,6 +52,7 @@ import net.minecraft.world.World;
|
|||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.structure.Structure;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.extensions.IForgeContainerType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
@ -147,14 +149,10 @@ public final class ModRegistry {
|
|||
new BlockAuraTimer(),
|
||||
new BlockSlimeSplitGenerator(),
|
||||
new BlockSpring(),
|
||||
new BlockWeatherChanger()
|
||||
new BlockWeatherChanger(),
|
||||
new BlockRFConverter(),
|
||||
new BlockChunkLoader()
|
||||
);
|
||||
|
||||
if (ModConfig.instance.rfConverter.get())
|
||||
event.getRegistry().register(new BlockRFConverter());
|
||||
if (ModConfig.instance.chunkLoader.get())
|
||||
event.getRegistry().register(new BlockChunkLoader());
|
||||
|
||||
Helper.populateObjectHolders(ModBlocks.class, event.getRegistry());
|
||||
}
|
||||
|
||||
|
@ -330,6 +328,7 @@ public final class ModRegistry {
|
|||
@SubscribeEvent
|
||||
public static void registerRecipes(RegistryEvent.Register<IRecipeSerializer<?>> event) {
|
||||
ModRecipes.register(event.getRegistry());
|
||||
CraftingHelper.register(new EnabledCondition.Serializer());
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
"block.naturesaura.gold_brick": "Golden Stone Bricks",
|
||||
"block.naturesaura.gold_nether_brick": "Golden Nether Bricks",
|
||||
"block.naturesaura.rf_converter": "Energetic Aura Forge",
|
||||
"block.naturesaura.rf_converter.disabled": "Energetic Aura Forge §4(Disabled)",
|
||||
"block.naturesaura.moss_generator": "Swamp Homi",
|
||||
"block.naturesaura.time_changer": "Shifting Sundial",
|
||||
"block.naturesaura.generator_limit_remover": "Creational Catalyst",
|
||||
|
@ -50,6 +51,7 @@
|
|||
"block.naturesaura.powder_placer": "Powder Manipulator",
|
||||
"block.naturesaura.firework_generator": "Firecracker Gaze",
|
||||
"block.naturesaura.chunk_loader": "World Eye",
|
||||
"block.naturesaura.chunk_loader.disabled": "World Eye §4(Disabled)",
|
||||
"block.naturesaura.dimension_rail_overworld": "Rail of the Overworld",
|
||||
"block.naturesaura.dimension_rail_end": "Rail of the End",
|
||||
"block.naturesaura.dimension_rail_nether": "Rail of the Nether",
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
},
|
||||
"conditions": [
|
||||
{
|
||||
"type": "forge:item_exists",
|
||||
"item": "naturesaura:chunk_loader"
|
||||
"type": "naturesaura:enabled",
|
||||
"config": "chunkLoader"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -27,8 +27,8 @@
|
|||
},
|
||||
"conditions": [
|
||||
{
|
||||
"type": "forge:item_exists",
|
||||
"item": "naturesaura:rf_converter"
|
||||
"type": "naturesaura:enabled",
|
||||
"config": "rfConverter"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue