Demon Crucible implementation
Readded the Demon Crucible to test the World's Will Chunk saving/loading.
This commit is contained in:
parent
bacd3d27f2
commit
5e8437fe58
19 changed files with 993 additions and 487 deletions
|
@ -2,6 +2,7 @@ package wayoftime.bloodmagic.util.handler.event;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
@ -9,17 +10,28 @@ import net.minecraft.entity.MobEntity;
|
|||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.world.ChunkDataEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.common.item.BloodMagicItems;
|
||||
import wayoftime.bloodmagic.demonaura.PosXY;
|
||||
import wayoftime.bloodmagic.demonaura.WillChunk;
|
||||
import wayoftime.bloodmagic.demonaura.WorldDemonWillHandler;
|
||||
import wayoftime.bloodmagic.potion.BloodMagicPotions;
|
||||
import wayoftime.bloodmagic.will.DemonWillHolder;
|
||||
import wayoftime.bloodmagic.will.EnumDemonWillType;
|
||||
import wayoftime.bloodmagic.will.IDemonWill;
|
||||
import wayoftime.bloodmagic.will.IDemonWillWeapon;
|
||||
|
@ -28,7 +40,7 @@ import wayoftime.bloodmagic.will.PlayerDemonWillHandler;
|
|||
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class WillHandler
|
||||
{
|
||||
private static final HashMap<Integer, Integer> SERVER_TICKS = new HashMap<>();
|
||||
private static final HashMap<ResourceLocation, Integer> SERVER_TICKS = new HashMap<>();
|
||||
|
||||
// Adds Will to player
|
||||
@SubscribeEvent
|
||||
|
@ -112,4 +124,84 @@ public class WillHandler
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerWorldTick(TickEvent.WorldTickEvent event)
|
||||
{
|
||||
if (event.world.isRemote)
|
||||
return;
|
||||
|
||||
ResourceLocation rl = WorldDemonWillHandler.getDimensionResourceLocation(event.world);
|
||||
// int dim = event.world.provider.getDimension();
|
||||
if (event.phase == TickEvent.Phase.END)
|
||||
{
|
||||
if (!SERVER_TICKS.containsKey(rl))
|
||||
SERVER_TICKS.put(rl, 0);
|
||||
|
||||
int ticks = (SERVER_TICKS.get(rl));
|
||||
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
CopyOnWriteArrayList<PosXY> dirtyChunks = WorldDemonWillHandler.dirtyChunks.get(rl);
|
||||
if ((dirtyChunks != null) && (dirtyChunks.size() > 0))
|
||||
{
|
||||
for (PosXY pos : dirtyChunks)
|
||||
event.world.markChunkDirty(new BlockPos(pos.x * 16, 5, pos.y * 16), null);
|
||||
|
||||
dirtyChunks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
SERVER_TICKS.put(rl, ticks + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void chunkSave(ChunkDataEvent.Save event)
|
||||
{
|
||||
if (!(event.getWorld() instanceof World))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ResourceLocation rl = WorldDemonWillHandler.getDimensionResourceLocation((World) event.getWorld());
|
||||
// int dim = event.getWorld().provider.getDimension();
|
||||
|
||||
ChunkPos loc = event.getChunk().getPos();
|
||||
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
event.getData().put("BloodMagic", nbt);
|
||||
|
||||
WillChunk ac = WorldDemonWillHandler.getWillChunk(rl, loc.x, loc.z);
|
||||
if (ac != null)
|
||||
{
|
||||
nbt.putShort("base", ac.getBase());
|
||||
ac.getCurrentWill().writeToNBT(nbt, "current");
|
||||
// if (event.getChunk() instanceof Chunk && !((Chunk) event.getChunk()).setLoaded(loaded);)
|
||||
if (!event.getWorld().getChunkProvider().isChunkLoaded(event.getChunk().getPos()))
|
||||
WorldDemonWillHandler.removeWillChunk(rl, loc.x, loc.z);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void chunkLoad(ChunkDataEvent.Load event)
|
||||
{
|
||||
if (!(event.getWorld() instanceof World))
|
||||
{
|
||||
return;
|
||||
}
|
||||
ResourceLocation rl = WorldDemonWillHandler.getDimensionResourceLocation((World) event.getWorld());
|
||||
// int dim = event.getWorld().provider.getDimension();
|
||||
if (event.getData().getCompound("BloodMagic").contains("base"))
|
||||
{
|
||||
CompoundNBT nbt = event.getData().getCompound("BloodMagic");
|
||||
short base = nbt.getShort("base");
|
||||
DemonWillHolder current = new DemonWillHolder();
|
||||
current.readFromNBT(nbt, "current");
|
||||
WorldDemonWillHandler.addWillChunk(rl, event.getChunk(), base, current);
|
||||
} else
|
||||
{
|
||||
WorldDemonWillHandler.generateWill(event.getChunk(), (World) event.getWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue