Commit b57f0ced authored by mrAppleXZ's avatar mrAppleXZ 💾

SIF Storage refactoring

parent d74d27bf
Subproject commit cbb542ea76be1dbede4b8b899158e0992f8b7190
Subproject commit 214dcd1d5cee6193cb8f1da11253717ef1641093
......@@ -23,7 +23,6 @@ import ru.pearx.purmag.common.items.papyrus.PapyrusRegistry;
import ru.pearx.purmag.common.loot_tables.LootTablesRegistry;
import ru.pearx.purmag.common.magibench.MagibenchRegistry;
import ru.pearx.purmag.common.networking.NetworkManager;
import ru.pearx.purmag.common.sif.SifStorageServer;
import ru.pearx.purmag.common.sip.SipEffectsRegistry;
import ru.pearx.purmag.common.sip.SipTypeRegistry;
import ru.pearx.purmag.common.structure.PMStructureProcessorRegistry;
......@@ -53,7 +52,6 @@ public class PurMag
//don't move this to PurMagClient
public Random random = new Random();
public SifStorageServer sif_storage = new SifStorageServer();
private SipTypeRegistry sip_registry = new SipTypeRegistry();
private SipEffectsRegistry sip_effects = new SipEffectsRegistry();
private IfRegistry if_registry = new IfRegistry();
......
......@@ -4,7 +4,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.purmag.client.gui.microscope.MicroscopeDataBuilder;
import ru.pearx.purmag.client.sif.SifStorageClient;
import ru.pearx.purmag.common.Utils;
/**
......@@ -17,8 +16,6 @@ public enum PurMagClient
public static ResourceLocation BUTTON_TEXTURE = Utils.gRL("textures/gui/button.png");
public SifStorageClient sif_storage = new SifStorageClient();
private MicroscopeDataBuilder microscopeDataBuilder = new MicroscopeDataBuilder();
public MicroscopeDataBuilder getMicroscopeDataBuilder()
......
......@@ -6,7 +6,7 @@ import org.lwjgl.util.Point;
import ru.pearx.carbide.Colors;
import ru.pearx.carbide.mc.client.gui.DrawingTools;
import ru.pearx.carbide.mc.client.gui.drawables.item.MultiItemDrawable;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
import ru.pearx.purmag.common.infofield.steps.IRSIngredient;
/*
......
......@@ -10,4 +10,9 @@ import ru.pearx.purmag.common.sif.SifStorage;
@SideOnly(Side.CLIENT)
public class SifStorageClient extends SifStorage
{
@Override
public void markDirty()
{
}
}
......@@ -11,6 +11,7 @@ import ru.pearx.carbide.mc.client.ModelSupplied;
import ru.pearx.carbide.mc.client.PXLFastTESR;
import ru.pearx.carbide.mc.common.blocks.controllers.HorizontalFacingController;
import ru.pearx.carbide.mc.client.models.PXLModelRenderer;
import ru.pearx.carbide.mc.common.misc.CoordUtils;
import ru.pearx.purmag.common.Utils;
import ru.pearx.purmag.common.blocks.BlockRegistry;
import ru.pearx.purmag.common.tiles.TileCodeStorage;
......@@ -33,7 +34,7 @@ public class TESRCodeStorage extends PXLFastTESR<TileCodeStorage>
GlStateManager.pushMatrix();
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(CarbideMC.getHorizontalRotation(st.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.rotate(CoordUtils.getHorizontalDegrees(st.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
long rnd = MathHelper.getPositionRandom(te.getPos());
......
......@@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import ru.pearx.carbide.mc.CarbideMC;
import ru.pearx.carbide.mc.client.PXLFastTESR;
import ru.pearx.carbide.mc.common.blocks.controllers.HorizontalFacingController;
import ru.pearx.carbide.mc.common.misc.CoordUtils;
import ru.pearx.purmag.PurMag;
import ru.pearx.purmag.common.magibench.MagibenchRegistry;
import ru.pearx.purmag.common.tiles.TileMagibench;
......@@ -28,7 +29,7 @@ public class TESRMagibench extends PXLFastTESR<TileMagibench>
float scale = Math.min(1f / t.getWidth(), 1f / t.getHeight());
GlStateManager.pushMatrix();
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(CarbideMC.getHorizontalRotation(te.getWorld().getBlockState(te.getPos()).getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.rotate(CoordUtils.getHorizontalDegrees(te.getWorld().getBlockState(te.getPos()).getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
GlStateManager.translate(0.16f, 1.09f, 0.16f);
for (int yy = 0; yy < t.getHeight(); yy++)
......
......@@ -11,6 +11,7 @@ import net.minecraft.item.ItemStack;
import ru.pearx.carbide.mc.CarbideMC;
import ru.pearx.carbide.mc.client.PXLFastTESR;
import ru.pearx.carbide.mc.common.blocks.controllers.HorizontalFacingController;
import ru.pearx.carbide.mc.common.misc.CoordUtils;
import ru.pearx.purmag.common.blocks.BlockRegistry;
import ru.pearx.purmag.common.tiles.TileMicroscope;
......@@ -31,7 +32,7 @@ public class TESRMicroscope extends PXLFastTESR<TileMicroscope>
{
GlStateManager.pushMatrix();
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(CarbideMC.getHorizontalRotation(state.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.rotate(CoordUtils.getHorizontalDegrees(state.getValue(HorizontalFacingController.FACING_H)), 0, 1, 0);
GlStateManager.rotate(180, 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
......
......@@ -18,6 +18,7 @@ import ru.pearx.carbide.mc.CarbideMC;
import ru.pearx.carbide.mc.client.ModelSupplied;
import ru.pearx.carbide.mc.client.TESRMultiblock;
import ru.pearx.carbide.mc.client.models.PXLModelRenderer;
import ru.pearx.carbide.mc.common.misc.CoordUtils;
import ru.pearx.purmag.common.Utils;
import ru.pearx.purmag.common.tiles.TileStoneCrusher;
......@@ -38,7 +39,7 @@ public class TESRStoneCrusher extends TESRMultiblock<TileStoneCrusher>
{
GlStateManager.pushMatrix();
GlStateManager.translate(0.5f, 0, 0.5f);
GlStateManager.rotate(CarbideMC.getHorizontalRotation(te.getRotation()), 0, 1, 0);
GlStateManager.rotate(CoordUtils.getHorizontalDegrees(te.getRotation()), 0, 1, 0);
GlStateManager.translate(-0.5f, 0, -0.5f);
//main part
......
package ru.pearx.purmag.common;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager;
import ru.pearx.carbide.mc.common.CapabilityStorageSimple;
import ru.pearx.purmag.common.aura.AuraContainer;
import ru.pearx.purmag.common.aura.IAuraContainer;
import ru.pearx.purmag.common.infofield.playerdata.IIfEntryStore;
import ru.pearx.purmag.common.infofield.playerdata.IfEntryStore;
import ru.pearx.purmag.common.sif.ISifStorage;
import ru.pearx.purmag.common.sif.SifStorage;
import ru.pearx.purmag.common.sip.store.ISipStore;
import ru.pearx.purmag.common.sip.store.SipStore;
import javax.annotation.Nullable;
/**
* Created by mrAppleXZ on 22.04.17 17:05.
*/
......@@ -27,58 +26,19 @@ public class CapabilityRegistry
public static final Capability<ISipStore> SIP_STORE_CAP = null;
@CapabilityInject(IAuraContainer.class)
public static final Capability<IAuraContainer> AURA_CONTAINER_CAP = null;
@CapabilityInject(ISifStorage.class)
public static final Capability<ISifStorage> SIF_STORAGE = null;
public static final ResourceLocation ENTRY_STORE_NAME = Utils.gRL("if_entry_store");
public static final ResourceLocation SIP_STORE_NAME = Utils.gRL("sip_store");
public static final ResourceLocation AURA_CONTAINER_NAME = Utils.gRL("aura_container");
public static final ResourceLocation SIF_STORAGE_NAME = Utils.gRL("sif_storage");
public static void register()
{
CapabilityManager.INSTANCE.register(IIfEntryStore.class, new Capability.IStorage<IIfEntryStore>()
{
@Override
public NBTBase writeNBT(Capability<IIfEntryStore> capability, IIfEntryStore instance, EnumFacing side)
{
return instance.serializeNBT();
}
@Override
public void readNBT(Capability<IIfEntryStore> capability, IIfEntryStore instance, EnumFacing side, NBTBase nbt)
{
instance.deserializeNBT((NBTTagCompound) nbt);
}
}, IfEntryStore.class);
CapabilityManager.INSTANCE.register(ISipStore.class, new Capability.IStorage<ISipStore>()
{
@Nullable
@Override
public NBTBase writeNBT(Capability<ISipStore> capability, ISipStore instance, EnumFacing side)
{
return instance.serializeNBT();
}
@Override
public void readNBT(Capability<ISipStore> capability, ISipStore instance, EnumFacing side, NBTBase nbt)
{
instance.deserializeNBT((NBTTagCompound) nbt);
}
}, SipStore.class);
CapabilityManager.INSTANCE.register(IAuraContainer.class, new Capability.IStorage<IAuraContainer>()
{
@Nullable
@Override
public NBTBase writeNBT(Capability<IAuraContainer> capability, IAuraContainer instance, EnumFacing side)
{
return instance.serializeNBT();
}
@Override
public void readNBT(Capability<IAuraContainer> capability, IAuraContainer instance, EnumFacing side, NBTBase nbt)
{
instance.deserializeNBT((NBTTagCompound) nbt);
}
}, AuraContainer.class);
CapabilityManager.INSTANCE.register(IIfEntryStore.class, new CapabilityStorageSimple<>(NBTTagCompound.class), IfEntryStore.class);
CapabilityManager.INSTANCE.register(ISipStore.class, new CapabilityStorageSimple<>(NBTTagCompound.class), SipStore.class);
CapabilityManager.INSTANCE.register(IAuraContainer.class, new CapabilityStorageSimple<>(NBTTagCompound.class), AuraContainer.class);
CapabilityManager.INSTANCE.register(ISifStorage.class, new CapabilityStorageSimple<>(NBTTagCompound.class), SifStorage.class);
}
}
......@@ -17,7 +17,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
import ru.pearx.carbide.mc.common.blocks.controllers.HorizontalFacingController;
import ru.pearx.purmag.common.blocks.base.BlockBase;
import ru.pearx.purmag.common.tiles.TileAbstractSingleItem;
......
......@@ -20,7 +20,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
import ru.pearx.carbide.mc.common.blocks.controllers.HorizontalFacingController;
import ru.pearx.carbide.mc.common.blocks.properties.PropertyInt;
import ru.pearx.purmag.PurMag;
......
......@@ -7,7 +7,7 @@ import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.items.ItemStackHandler;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
import ru.pearx.carbide.mc.common.inventory.PXLContainer;
import ru.pearx.purmag.PurMag;
import ru.pearx.purmag.common.magibench.MagibenchRegistry;
......
......@@ -13,6 +13,7 @@ import ru.pearx.purmag.common.networking.packets.code_storage.SPacketLock;
import ru.pearx.purmag.common.networking.packets.code_storage.SPacketUnlock;
import ru.pearx.purmag.common.networking.packets.microscope.CPacketCheckMicroscopeResearchResponse;
import ru.pearx.purmag.common.networking.packets.microscope.SPacketCheckMicroscopeResearch;
import ru.pearx.purmag.common.sif.net.CPacketSyncSif;
/**
* Created by mrAppleXZ on 23.04.17 11:23.
......@@ -29,7 +30,6 @@ public class NetworkManager
INSTANCE.registerMessage(CPacketSyncEntryStore.Handler.class, CPacketSyncEntryStore.class, id++, Side.CLIENT);
INSTANCE.registerMessage(CPacketDisplayMessage.Handler.class, CPacketDisplayMessage.class, id++, Side.CLIENT);
INSTANCE.registerMessage(CPacketSyncSif.Handler.class, CPacketSyncSif.class, id++, Side.CLIENT);
INSTANCE.registerMessage(CPacketDesyncSif.Handler.class, CPacketDesyncSif.class, id++, Side.CLIENT);
INSTANCE.registerMessage(SPacketUseSipAmulet.Handler.class, SPacketUseSipAmulet.class, id++, Side.SERVER);
INSTANCE.registerMessage(CPacketSpawnSipParticle.Handler.class, CPacketSpawnSipParticle.class, id++, Side.CLIENT);
INSTANCE.registerMessage(SPacketDoneTranslation.Handler.class, SPacketDoneTranslation.class, id++, Side.SERVER);
......
package ru.pearx.purmag.common.networking.packets;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.carbide.mc.common.GlobalChunkPos;
import ru.pearx.purmag.client.PurMagClient;
/**
* Created by mrAppleXZ on 27.06.17 16:20.
*/
public class CPacketDesyncSif implements IMessage
{
public GlobalChunkPos pos;
public CPacketDesyncSif()
{
}
public CPacketDesyncSif(GlobalChunkPos pos)
{
this.pos = pos;
}
@Override
public void fromBytes(ByteBuf buf)
{
pos = GlobalChunkPos.readBytes(buf);
}
@Override
public void toBytes(ByteBuf buf)
{
pos.writeBytes(buf);
}
public static class Handler implements IMessageHandler<CPacketDesyncSif, IMessage>
{
public Handler()
{
}
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(CPacketDesyncSif message, MessageContext ctx)
{
Minecraft.getMinecraft().addScheduledTask(() -> PurMagClient.INSTANCE.sif_storage.remove(message.pos));
return null;
}
}
}
......@@ -15,6 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import ru.pearx.carbide.RandomUtils;
import ru.pearx.carbide.mc.CarbideMC;
import ru.pearx.carbide.mc.client.particle.ParticleEngine;
import ru.pearx.carbide.mc.common.misc.CoordUtils;
import ru.pearx.carbide.mc.common.networking.ByteBufTools;
import ru.pearx.carbide.mc.common.structure.blockarray.BlockArray;
import ru.pearx.carbide.mc.common.structure.multiblock.Multiblock;
......@@ -71,8 +72,8 @@ public class CPacketSpawnMultiblockParticles implements IMessage
{
Minecraft.getMinecraft().world.playSound(message.pos, SoundRegistry.MULTIBLOCK_FORM, SoundCategory.BLOCKS, 1, 1, false);
BlockArray struct = Multiblock.REGISTRY.getValue(message.multiblockId).getStructure();
BlockPos f = CarbideMC.transformPos(new BlockPos(struct.getMinX(), struct.getMinY(), struct.getMinZ()), null, message.rot).add(message.pos);
BlockPos t = CarbideMC.transformPos(new BlockPos(struct.getMaxX(), struct.getMaxY(), struct.getMaxZ()), null, message.rot).add(message.pos);
BlockPos f = CoordUtils.transformPos(new BlockPos(struct.getMinX(), struct.getMinY(), struct.getMinZ()), null, message.rot).add(message.pos);
BlockPos t = CoordUtils.transformPos(new BlockPos(struct.getMaxX(), struct.getMaxY(), struct.getMaxZ()), null, message.rot).add(message.pos);
int minX = Math.min(f.getX(), t.getX());
int maxX = Math.max(f.getX(), t.getX());
int minY = Math.min(f.getY(), t.getY());
......
......@@ -9,7 +9,7 @@ import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.IShapedRecipe;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
/*
* Created by mrAppleXZ on 30.10.17 18:11.
......
......@@ -8,7 +8,7 @@ import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.CraftingHelper;
import ru.pearx.carbide.mc.common.ItemStackUtils;
import ru.pearx.carbide.mc.common.misc.ItemStackUtils;
import javax.annotation.Nonnull;
......
package ru.pearx.purmag.common.sif;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.INBTSerializable;
/*
* Created by mrAppleXZ on 27.05.18 11:51.
*/
public interface ISifStorage extends INBTSerializable<NBTTagCompound>
{
float getPower();
void setPower(float value);
void markDirty();
}
package ru.pearx.purmag.common.sif;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import ru.pearx.carbide.mc.common.GlobalChunkPos;
import ru.pearx.purmag.PurMag;
import ru.pearx.purmag.client.sif.SifStorageClient;
import ru.pearx.purmag.common.CapabilityRegistry;
import ru.pearx.purmag.common.networking.NetworkManager;
import ru.pearx.purmag.common.networking.packets.CPacketDesyncSif;
import ru.pearx.purmag.common.networking.packets.CPacketSyncSif;
import ru.pearx.purmag.common.sif.net.CPacketSyncSif;
/**
* Created by mrAppleXZ on 27.06.17 16:37.
......@@ -18,42 +18,9 @@ import ru.pearx.purmag.common.networking.packets.CPacketSyncSif;
public class SifEvents
{
@SubscribeEvent
public static void onChunkDataLoad(ChunkDataEvent.Load e)
public static void onAttach(AttachCapabilitiesEvent<Chunk> e)
{
try
{
PurMag.INSTANCE.sif_storage.set(GlobalChunkPos.fromChunk(e.getChunk()), e.getData().getFloat("sif_power"));
}
catch (Exception ex)
{
PurMag.INSTANCE.log.error("Can't load the SIF chunk data!", ex);
}
}
@SubscribeEvent
public static void onChunkDataSave(ChunkDataEvent.Save e)
{
try
{
e.getData().setFloat("sif_power", PurMag.INSTANCE.sif_storage.get(GlobalChunkPos.fromChunk(e.getChunk())));
}
catch (Exception ex)
{
PurMag.INSTANCE.log.error("Can't save the SIF chunk data!", ex);
}
}
@SubscribeEvent
public static void onChunkUnload(ChunkEvent.Unload e)
{
try
{
PurMag.INSTANCE.sif_storage.remove(GlobalChunkPos.fromChunk(e.getChunk()));
}
catch (Exception ex)
{
PurMag.INSTANCE.log.error("Can't remove the SIP chunk data on chunk unload!", ex);
}
e.addCapability(CapabilityRegistry.SIF_STORAGE_NAME, new SifStorageProvider(e.getObject().getWorld().isRemote ? new SifStorageClient() : new SifStorageServer(e.getObject())));
}
@SubscribeEvent
......@@ -61,26 +28,14 @@ public class SifEvents
{
try
{
GlobalChunkPos pos = new GlobalChunkPos(e.getChunk().x, e.getChunk().z, e.getPlayer().dimension);
NetworkManager.sendTo(new CPacketSyncSif(pos, PurMag.INSTANCE.sif_storage.get(pos)), e.getPlayer());
Chunk ch = e.getChunkInstance();
if(ch == null)
ch = e.getPlayer().world.getChunkFromChunkCoords(e.getChunk().x, e.getChunk().z);
NetworkManager.sendTo(new CPacketSyncSif(ch.x, ch.z, ch.getCapability(CapabilityRegistry.SIF_STORAGE, null).getPower()), e.getPlayer());
}
catch (Exception ex)
{
PurMag.INSTANCE.log.error("Can't sync the SIF chunk data with player!", ex);
}
}
@SubscribeEvent
public static void onChunkUnWatch(ChunkWatchEvent.UnWatch e)
{
try
{
GlobalChunkPos pos = new GlobalChunkPos(e.getChunk().x, e.getChunk().z, e.getPlayer().dimension);
NetworkManager.sendTo(new CPacketDesyncSif(pos), e.getPlayer());
}
catch (Exception ex)
{
PurMag.INSTANCE.log.error("Can't desync the SIF chunk data with player!", ex);
}
}
}
package ru.pearx.purmag.common.sif;
import ru.pearx.carbide.mc.common.GlobalChunkPos;
import net.minecraft.nbt.NBTTagCompound;
import java.util.HashMap;
import java.util.Map;
/**
* Created by mrAppleXZ on 27.06.17 15:29.
/*
* Created by mrAppleXZ on 27.05.18 12:21.
*/
public class SifStorage
public abstract class SifStorage implements ISifStorage
{
protected Map<GlobalChunkPos, Float> loaded = new HashMap<>();
private float power;
@Override
public NBTTagCompound serializeNBT()
{
NBTTagCompound tag = new NBTTagCompound();
tag.setFloat("power", getPower());
return tag;
}
public float get(GlobalChunkPos pos)
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
return loaded.get(pos);
setPower(nbt.getFloat("power"));
}
public void set(GlobalChunkPos pos, float value)
@Override
public float getPower()
{
loaded.put(pos, value);
return power;
}
public void remove(GlobalChunkPos pos)
@Override
public void setPower(float value)
{
loaded.remove(pos);
power = value;
markDirty();
}
}
package ru.pearx.purmag.common.sif;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import ru.pearx.purmag.common.CapabilityRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/*
* Created by mrAppleXZ on 27.05.18 12:02.
*/
public class SifStorageProvider implements ICapabilitySerializable<NBTTagCompound>
{
private ISifStorage storage;
public SifStorageProvider(ISifStorage storage)
{
this.storage = storage;
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{
return capability == CapabilityRegistry.SIF_STORAGE;
}
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{
if(capability == CapabilityRegistry.SIF_STORAGE)
return CapabilityRegistry.SIF_STORAGE.cast(storage);
return null;
}
@Override
public NBTTagCompound serializeNBT()
{
return storage.serializeNBT();
}
@Override
public void deserializeNBT(NBTTagCompound nbt)
{
storage.deserializeNBT(nbt);
}
}
......@@ -2,12 +2,13 @@ package ru.pearx.purmag.common.sif;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.DimensionManager;
import ru.pearx.carbide.mc.common.GlobalChunkPos;
import ru.pearx.purmag.PurMag;
import ru.pearx.purmag.common.networking.NetworkManager;
import ru.pearx.purmag.common.networking.packets.CPacketDesyncSif;
import ru.pearx.purmag.common.networking.packets.CPacketSyncSif;
import ru.pearx.purmag.common.sif.net.CPacketSyncSif;
import java.util.Random;
......@@ -16,51 +17,43 @@ import java.util.Random;
*/
public class SifStorageServer extends SifStorage
{
@Override
public void set(GlobalChunkPos pos, float value)
private Chunk chunk;
private boolean isSet;
public SifStorageServer(Chunk chunk)
{
if (loaded.containsKey(pos))
if (loaded.get(pos).equals(value))
return;
loaded.put(pos, value);
WorldServer wrld = DimensionManager.getWorld(pos.getDimension());
wrld.getChunkFromChunkCoords(pos.getX(), pos.getZ()).markDirty();
PlayerChunkMapEntry map = wrld.getPlayerChunkMap().getEntry(pos.getX(), pos.getZ());
if (map != null)
{
for (EntityPlayerMP p : map.players)
{
NetworkManager.sendTo(new CPacketSyncSif(pos, value), p);
}
}
this.chunk = chunk;
}
@Override
public void remove(GlobalChunkPos pos)
public void setPower(float value)
{
if (!loaded.containsKey(pos))
return;
loaded.remove(pos);
PlayerChunkMapEntry map = DimensionManager.getWorld(pos.getDimension()).getPlayerChunkMap().getEntry(pos.getX(), pos.getZ());
if (map != null)
isSet = true;
super.setPower(value);
World w = chunk.getWorld();
if(w instanceof WorldServer)
{
for (EntityPlayerMP p : map.players)
PlayerChunkMapEntry map = ((WorldServer) w).getPlayerChunkMap().getEntry(chunk.x, chunk.z);
if (map != null)
{
NetworkManager.sendTo(new CPacketDesyncSif(pos), p);
for (EntityPlayerMP p : map.players)
{
NetworkManager.sendTo(new CPacketSyncSif(chunk.x, chunk.z, value), p);
}
}
}
}
@Override
public float get(GlobalChunkPos pos)
public float getPower()
{
if (!loaded.containsKey(pos))
if(!isSet)
{
long worldSeed = DimensionManager.getWorld(pos.getDimension()).getSeed();
long worldSeed = chunk.getWorld().getSeed();
Random rand = new Random(worldSeed);
long xSeed = rand.nextLong() >> 2 + 1L;
long zSeed = rand.nextLong() >> 2 + 1L;
rand.setSeed((xSeed * pos.getX() + zSeed * pos.getZ()) ^ worldSeed);
rand.setSeed((xSeed * chunk.x + zSeed * chunk.z) ^ worldSeed);
int main;
float f = rand.nextFloat();
......@@ -77,8 +70,14 @@ public class SifStorageServer extends SifStorage
main = 0;
}
set(pos, main + f);
setPower(main + f);
}
return loaded.get(pos);
return super.getPower();
}
@Override
public void markDirty()
{