mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
chonki boi, part 1
This commit is contained in:
parent
8b02621c5d
commit
de2e6aa23a
10 changed files with 223 additions and 46 deletions
|
@ -47,6 +47,8 @@ public final class ModConfig {
|
||||||
public boolean removeDragonBreathContainerItem = true;
|
public boolean removeDragonBreathContainerItem = true;
|
||||||
@Comment("If the RF converter block should be enabled")
|
@Comment("If the RF converter block should be enabled")
|
||||||
public boolean rfConverter = true;
|
public boolean rfConverter = true;
|
||||||
|
@Comment("If the chunk loader block should be enabled")
|
||||||
|
public boolean chunkLoader = true;
|
||||||
|
|
||||||
@Comment("If the Aura Imbalance effect of grass and trees dying in the area if the Aura levels are too low should occur")
|
@Comment("If the Aura Imbalance effect of grass and trees dying in the area if the Aura levels are too low should occur")
|
||||||
public boolean grassDieEffect = true;
|
public boolean grassDieEffect = true;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||||
|
import net.minecraftforge.fml.common.Mod.Instance;
|
||||||
import net.minecraftforge.fml.common.SidedProxy;
|
import net.minecraftforge.fml.common.SidedProxy;
|
||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
@ -48,6 +49,9 @@ public final class NaturesAura {
|
||||||
|
|
||||||
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
|
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
|
||||||
|
|
||||||
|
@Instance(value = MOD_ID)
|
||||||
|
public static NaturesAura instance;
|
||||||
|
|
||||||
@SidedProxy(modId = MOD_ID, clientSide = PROXY_LOCATION + "ClientProxy", serverSide = PROXY_LOCATION + "ServerProxy")
|
@SidedProxy(modId = MOD_ID, clientSide = PROXY_LOCATION + "ClientProxy", serverSide = PROXY_LOCATION + "ServerProxy")
|
||||||
public static IProxy proxy;
|
public static IProxy proxy;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
||||||
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityChunkLoader;
|
||||||
|
import net.minecraft.block.SoundType;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||||
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable {
|
||||||
|
|
||||||
|
public BlockChunkLoader() {
|
||||||
|
super(Material.ROCK, "chunk_loader", TileEntityChunkLoader.class, "chunk_loader");
|
||||||
|
this.setSoundType(SoundType.STONE);
|
||||||
|
this.setHardness(3F);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInit(FMLInitializationEvent event) {
|
||||||
|
super.onInit(event);
|
||||||
|
ForgeChunkManager.setForcedChunkLoadingCallback(NaturesAura.instance, new ChunkLoadingCallback());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
if (tile instanceof TileEntityChunkLoader) {
|
||||||
|
int range = ((TileEntityChunkLoader) tile).range();
|
||||||
|
if (range > 0) {
|
||||||
|
return new AxisAlignedBB(
|
||||||
|
(pos.getX() - range) >> 4 << 4,
|
||||||
|
0,
|
||||||
|
(pos.getZ() - range) >> 4 << 4,
|
||||||
|
((pos.getX() + range) >> 4 << 4) + 16,
|
||||||
|
world.getHeight(),
|
||||||
|
((pos.getZ() + range) >> 4 << 4) + 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public int getVisualizationColor(World world, BlockPos pos) {
|
||||||
|
return 0xc159f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChunkLoadingCallback implements ForgeChunkManager.LoadingCallback {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ticketsLoaded(List<Ticket> tickets, World world) {
|
||||||
|
for (Ticket ticket : tickets) {
|
||||||
|
NBTTagCompound data = ticket.getModData();
|
||||||
|
BlockPos pos = BlockPos.fromLong(data.getLong("pos"));
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
if (!(tile instanceof TileEntityChunkLoader))
|
||||||
|
continue;
|
||||||
|
TileEntityChunkLoader loader = (TileEntityChunkLoader) tile;
|
||||||
|
loader.updateTicket(ticket);
|
||||||
|
loader.loadChunks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -132,23 +132,27 @@ public class BlockContainerImpl extends BlockContainer implements IModItem, ICre
|
||||||
if (tile instanceof TileEntityImpl) {
|
if (tile instanceof TileEntityImpl) {
|
||||||
TileEntityImpl impl = (TileEntityImpl) tile;
|
TileEntityImpl impl = (TileEntityImpl) tile;
|
||||||
int newPower = world.getRedstonePowerFromNeighbors(pos);
|
int newPower = world.getRedstonePowerFromNeighbors(pos);
|
||||||
if (impl.redstonePower != newPower) {
|
if (impl.redstonePower != newPower)
|
||||||
boolean pulse = impl.redstonePower <= 0 && newPower > 0;
|
|
||||||
impl.redstonePower = newPower;
|
|
||||||
impl.onRedstonePowerChange();
|
|
||||||
if (pulse)
|
|
||||||
world.scheduleUpdate(pos, this, this.tickRate(world));
|
world.scheduleUpdate(pos, this, this.tickRate(world));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int tickRate(World worldIn) {
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
||||||
if (!worldIn.isRemote) {
|
if (!worldIn.isRemote) {
|
||||||
TileEntity tile = worldIn.getTileEntity(pos);
|
TileEntity tile = worldIn.getTileEntity(pos);
|
||||||
if (tile instanceof TileEntityImpl)
|
if (tile instanceof TileEntityImpl) {
|
||||||
((TileEntityImpl) tile).onRedstonePulse();
|
TileEntityImpl impl = (TileEntityImpl) tile;
|
||||||
|
int newPower = worldIn.getRedstonePowerFromNeighbors(pos);
|
||||||
|
if (impl.redstonePower != newPower)
|
||||||
|
((TileEntityImpl) tile).onRedstonePowerChange(newPower);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -53,4 +53,5 @@ public final class ModBlocks {
|
||||||
public static final Block POWDER_PLACER = new BlockPowderPlacer();
|
public static final Block POWDER_PLACER = new BlockPowderPlacer();
|
||||||
public static final Block FIREWORK_GENERATOR = new BlockFireworkGenerator();
|
public static final Block FIREWORK_GENERATOR = new BlockFireworkGenerator();
|
||||||
public static final Block PROJECTILE_GENERATOR = new BlockProjectileGenerator();
|
public static final Block PROJECTILE_GENERATOR = new BlockProjectileGenerator();
|
||||||
|
public static final Block CHUNK_LOADER = ModConfig.enabledFeatures.chunkLoader ? new BlockChunkLoader() : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
package de.ellpeck.naturesaura.blocks.tiles;
|
||||||
|
|
||||||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||||||
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.ITickable;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||||
|
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class TileEntityChunkLoader extends TileEntityImpl implements ITickable {
|
||||||
|
|
||||||
|
private Ticket ticket;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
super.validate();
|
||||||
|
if (!this.world.isRemote && this.ticket == null) {
|
||||||
|
Ticket ticket = ForgeChunkManager.requestTicket(NaturesAura.instance, this.world, Type.NORMAL);
|
||||||
|
this.updateTicket(ticket);
|
||||||
|
ticket.getModData().setLong("pos", this.pos.toLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate() {
|
||||||
|
super.invalidate();
|
||||||
|
if (!this.world.isRemote)
|
||||||
|
this.updateTicket(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRedstonePowerChange(int newPower) {
|
||||||
|
super.onRedstonePowerChange(newPower);
|
||||||
|
if (!this.world.isRemote) {
|
||||||
|
this.loadChunks();
|
||||||
|
this.sendToClients();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int range() {
|
||||||
|
return this.redstonePower * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTicket(Ticket ticket) {
|
||||||
|
if (this.ticket != null)
|
||||||
|
ForgeChunkManager.releaseTicket(this.ticket);
|
||||||
|
this.ticket = ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadChunks() {
|
||||||
|
if (this.ticket == null)
|
||||||
|
return;
|
||||||
|
Set<ChunkPos> before = new HashSet<>(this.ticket.getChunkList());
|
||||||
|
int range = this.range();
|
||||||
|
if (range > 0) {
|
||||||
|
for (int x = (this.pos.getX() - range) >> 4; x <= (this.pos.getX() + range) >> 4; x++) {
|
||||||
|
for (int z = (this.pos.getZ() - range) >> 4; z <= (this.pos.getZ() + range) >> 4; z++) {
|
||||||
|
ChunkPos pos = new ChunkPos(x, z);
|
||||||
|
if (!before.contains(pos))
|
||||||
|
ForgeChunkManager.forceChunk(this.ticket, pos);
|
||||||
|
else
|
||||||
|
before.remove(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (ChunkPos pos : before)
|
||||||
|
ForgeChunkManager.unforceChunk(this.ticket, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (!this.world.isRemote) {
|
||||||
|
if (this.world.getTotalWorldTime() % 20 != 0)
|
||||||
|
return;
|
||||||
|
int toUse = MathHelper.ceil(this.range() / 2F);
|
||||||
|
if (toUse > 0) {
|
||||||
|
BlockPos spot = IAuraChunk.getHighestSpot(this.world, this.pos, 35, this.pos);
|
||||||
|
IAuraChunk.getAuraChunk(this.world, spot).drainAura(spot, toUse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -58,12 +58,8 @@ public class TileEntityImpl extends TileEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onRedstonePowerChange() {
|
public void onRedstonePowerChange(int newPower) {
|
||||||
|
this.redstonePower = newPower;
|
||||||
}
|
|
||||||
|
|
||||||
public void onRedstonePulse() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,7 +7,8 @@ public class TileEntityPickupStopper extends TileEntityImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRedstonePowerChange() {
|
public void onRedstonePowerChange(int newPower) {
|
||||||
|
super.onRedstonePowerChange(newPower);
|
||||||
if (!this.world.isRemote)
|
if (!this.world.isRemote)
|
||||||
this.sendToClients();
|
this.sendToClients();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ import java.util.List;
|
||||||
public class TileEntityPowderPlacer extends TileEntityImpl {
|
public class TileEntityPowderPlacer extends TileEntityImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRedstonePulse() {
|
public void onRedstonePowerChange(int newPower) {
|
||||||
|
if (this.redstonePower <= 0 && newPower > 0) {
|
||||||
List<EntityEffectInhibitor> powders = this.world.getEntitiesWithinAABB(EntityEffectInhibitor.class,
|
List<EntityEffectInhibitor> powders = this.world.getEntitiesWithinAABB(EntityEffectInhibitor.class,
|
||||||
new AxisAlignedBB(this.pos, this.pos.add(1, 2, 1)), EntitySelectors.IS_ALIVE);
|
new AxisAlignedBB(this.pos, this.pos.add(1, 2, 1)), EntitySelectors.IS_ALIVE);
|
||||||
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
|
for (EnumFacing facing : EnumFacing.HORIZONTALS) {
|
||||||
|
@ -51,4 +52,6 @@ public class TileEntityPowderPlacer extends TileEntityImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
super.onRedstonePowerChange(newPower);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ public class TileEntitySpawnLamp extends TileEntityImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRedstonePowerChange() {
|
public void onRedstonePowerChange(int newPower) {
|
||||||
|
super.onRedstonePowerChange(newPower);
|
||||||
if (!this.world.isRemote)
|
if (!this.world.isRemote)
|
||||||
this.sendToClients();
|
this.sendToClients();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue