mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-15 01:24:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
202d19df93 | ||
|
|
333334190a | ||
|
|
7c00ea2965 | ||
|
|
79cf866a96 | ||
|
|
504ec8acfc | ||
|
|
44a926f897 |
No files matched your search
+1
-1
@@ -8,4 +8,4 @@ ic2_version=2.6.76-ex110
|
||||
|
||||
version_major=5
|
||||
version_minor=2
|
||||
version_patch=16
|
||||
version_patch=17
|
||||
@@ -139,7 +139,7 @@ public abstract class EntityMinecartBeeHousingBase extends EntityMinecartContain
|
||||
|
||||
@Override
|
||||
public boolean isRaining() {
|
||||
return worldObj.canBlockSeeSky(getPosition().up());
|
||||
return worldObj.isRainingAt(getPosition().up());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockFurnace;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousingInventory;
|
||||
|
||||
@@ -52,10 +52,6 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
|
||||
/* PROPERTYS */
|
||||
public static final PropertyTree TREE = new PropertyTree("tree");
|
||||
|
||||
public static TileSapling getSaplingTile(IBlockAccess world, BlockPos pos) {
|
||||
return TileUtil.getTile(world, pos, TileSapling.class);
|
||||
}
|
||||
|
||||
public BlockSapling() {
|
||||
super(Material.PLANTS);
|
||||
@@ -105,7 +101,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
TileSapling sapling = getSaplingTile(world, pos);
|
||||
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if(sapling != null && sapling.getTree() != null){
|
||||
state = state.withProperty(TREE, sapling.getTree().getGenome().getPrimary());
|
||||
}else{
|
||||
@@ -135,7 +131,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
|
||||
/* PLANTING */
|
||||
public static boolean canBlockStay(IBlockAccess world, BlockPos pos) {
|
||||
TileSapling tile = getSaplingTile(world, pos);
|
||||
TileSapling tile = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -165,7 +161,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
||||
TileSapling sapling = getSaplingTile(world, pos);
|
||||
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (sapling == null || sapling.getTree() == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -188,7 +184,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
return;
|
||||
}
|
||||
|
||||
TileSapling sapling = getSaplingTile(world, pos);
|
||||
TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (sapling != null && sapling.getTree() != null) {
|
||||
ItemStack saplingStack = TreeManager.treeRoot.getMemberStack(sapling.getTree(), EnumGermlingType.SAPLING);
|
||||
ItemStackUtil.dropItemStackAsEntity(saplingStack, world, pos);
|
||||
@@ -202,7 +198,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
if (world.rand.nextFloat() >= 0.45F) {
|
||||
return false;
|
||||
}
|
||||
TileSapling saplingTile = getSaplingTile(world, pos);
|
||||
TileSapling saplingTile = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (saplingTile != null) {
|
||||
return saplingTile.canAcceptBoneMeal(rand);
|
||||
}
|
||||
@@ -216,7 +212,7 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat
|
||||
|
||||
@Override
|
||||
public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
|
||||
TileSapling saplingTile = getSaplingTile(world, pos);
|
||||
TileSapling saplingTile = TileUtil.getTile(world, pos, TileSapling.class);
|
||||
if (saplingTile != null) {
|
||||
saplingTile.tryGrow(rand, true);
|
||||
}
|
||||
|
||||
Executable → Regular
+16
-27
@@ -10,33 +10,27 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.ErrorStateRegistry;
|
||||
import forestry.core.loot.LootTableLoader;
|
||||
import forestry.core.models.ModelBlockCached;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerRequest;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.plugins.PluginManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.loot.LootPool;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.event.LootTableLoadEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.ErrorStateRegistry;
|
||||
import forestry.core.loot.LootTableLoader;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.plugins.PluginManager;
|
||||
|
||||
public class EventHandlerCore {
|
||||
|
||||
public EventHandlerCore() {
|
||||
@@ -57,22 +51,17 @@ public class EventHandlerCore {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handlePlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
EntityPlayer player = event.player;
|
||||
if (player != null) {
|
||||
Collection<ISpeciesRoot> speciesRoots = AlleleManager.alleleRegistry.getSpeciesRoot().values();
|
||||
for (ISpeciesRoot speciesRoot : speciesRoots) {
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.getEntityWorld(), player.getGameProfile());
|
||||
breedingTracker.synchToPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleWorldLoad(WorldEvent.Load event) {
|
||||
World world = event.getWorld();
|
||||
|
||||
for (ISaveEventHandler handler : PluginManager.saveEventHandlers) {
|
||||
handler.onWorldLoad(event.getWorld());
|
||||
handler.onWorldLoad(world);
|
||||
}
|
||||
|
||||
if (world.isRemote) {
|
||||
IForestryPacketServer packet = new PacketGenomeTrackerRequest();
|
||||
world.sendPacketToServer(packet.getPacket());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.apiculture.genetics.BeeRoot;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.mutations.EnumMutateChance;
|
||||
import forestry.core.gui.buttons.GuiBetterButton;
|
||||
|
||||
@@ -98,13 +98,19 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!base.hasTagCompound() || !comparison.hasTagCompound()) {
|
||||
NBTTagCompound baseTagCompound = base.getTagCompound();
|
||||
NBTTagCompound comparisonTagCompound = comparison.getTagCompound();
|
||||
if (baseTagCompound == null || comparisonTagCompound == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String baseUID = base.getTagCompound().getString(KEY_UID);
|
||||
String comparisonUID = comparison.getTagCompound().getString(KEY_UID);
|
||||
return baseUID != null && comparisonUID != null && baseUID.equals(comparisonUID);
|
||||
if (!baseTagCompound.hasKey(KEY_UID) || !comparisonTagCompound.hasKey(KEY_UID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int baseUID = baseTagCompound.getInteger(KEY_UID);
|
||||
int comparisonUID = comparisonTagCompound.getInteger(KEY_UID);
|
||||
return baseUID == comparisonUID;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
@@ -33,6 +33,9 @@ public enum PacketIdServer implements IPacketId {
|
||||
// Apiculture
|
||||
BEE_LOGIC_ACTIVE_ENTITY_REQUEST,
|
||||
|
||||
// Genetics
|
||||
GENOME_TRACKER_REQUEST,
|
||||
|
||||
// Mail
|
||||
LETTER_INFO_REQUEST,
|
||||
TRADING_ADDRESS_REQUEST,
|
||||
|
||||
@@ -16,6 +16,7 @@ import forestry.core.network.packets.PacketChipsetClick;
|
||||
import forestry.core.network.packets.PacketErrorUpdate;
|
||||
import forestry.core.network.packets.PacketErrorUpdateEntity;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerRequest;
|
||||
import forestry.core.network.packets.PacketGenomeTrackerSync;
|
||||
import forestry.core.network.packets.PacketGuiEnergy;
|
||||
import forestry.core.network.packets.PacketGuiLayoutSelect;
|
||||
@@ -53,5 +54,6 @@ public class PacketRegistryCore extends PacketRegistry {
|
||||
registerServerPacket(new PacketSolderingIronClick());
|
||||
registerServerPacket(new PacketCamouflageSelectServer());
|
||||
registerServerPacket(new PacketUpdateClimateControl());
|
||||
registerServerPacket(new PacketGenomeTrackerRequest());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAlleleRegistry;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class PacketGenomeTrackerRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.GENOME_TRACKER_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
IAlleleRegistry alleleRegistry = AlleleManager.alleleRegistry;
|
||||
Collection<ISpeciesRoot> speciesRoots = alleleRegistry.getSpeciesRoot().values();
|
||||
for (ISpeciesRoot speciesRoot : speciesRoots) {
|
||||
IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.getEntityWorld(), player.getGameProfile());
|
||||
breedingTracker.synchToPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.proxy;
|
||||
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
|
||||
public class ProxyNetworkClient extends ProxyNetwork {
|
||||
|
||||
@Override
|
||||
public void sendToServer(IForestryPacketServer packet) {
|
||||
NetHandlerPlayClient netHandler = Proxies.common.getClientInstance().getConnection();
|
||||
if (netHandler != null) {
|
||||
netHandler.sendPacket(packet.getPacket());
|
||||
}
|
||||
Preconditions.checkNotNull(netHandler, "Tried to send packet before netHandler (client world) exists.");
|
||||
netHandler.sendPacket(packet.getPacket());
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,18 @@ package forestry.core.tiles;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockFlowerPot;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkCache;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
@@ -48,12 +51,26 @@ public abstract class TileUtil {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tile of the specified class, returns null if it is the wrong type or does not exist.
|
||||
* Avoids creating new tile entities when using a ChunkCache (off the main thread).
|
||||
* see {@link BlockFlowerPot#getActualState(IBlockState, IBlockAccess, BlockPos)}
|
||||
*/
|
||||
@Nullable
|
||||
public static <T extends TileEntity> T getTile(@Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull Class<T> tileClass) {
|
||||
if(pos == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
|
||||
TileEntity tileEntity;
|
||||
|
||||
if (world instanceof ChunkCache) {
|
||||
ChunkCache chunkCache = (ChunkCache) world;
|
||||
tileEntity = chunkCache.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
} else {
|
||||
tileEntity = world.getTileEntity(pos);
|
||||
}
|
||||
|
||||
if (tileClass.isInstance(tileEntity)) {
|
||||
return tileClass.cast(tileEntity);
|
||||
} else {
|
||||
|
||||
@@ -18,6 +18,7 @@ import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -62,7 +63,7 @@ public class CamouflageUtil {
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
|
||||
if(tile instanceof ICamouflagedTile){
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
@@ -86,7 +87,7 @@ public class CamouflageUtil {
|
||||
if(pos == null || world == null){
|
||||
return null;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
TileEntity tile = TileUtil.getTile(world, pos, TileEntity.class);
|
||||
if(tile instanceof ICamouflagedTile){
|
||||
ICamouflagedTile block = (ICamouflagedTile) tile;
|
||||
String type = block.getCamouflageType();
|
||||
|
||||
@@ -13,6 +13,7 @@ package forestry.core.utils;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -37,7 +38,7 @@ public abstract class EntityUtil {
|
||||
living.setLocationAndAngles(x, y, z, MathHelper.wrapDegrees(world.rand.nextFloat() * 360.0f), 0.0f);
|
||||
living.rotationYawHead = living.rotationYaw;
|
||||
living.renderYawOffset = living.rotationYaw;
|
||||
living.onInitialSpawn(null, null);
|
||||
living.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(x, y, z)), null);
|
||||
world.spawnEntityInWorld(living);
|
||||
living.playLivingSound();
|
||||
return living;
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -275,7 +276,7 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
if (getGreenhouseType() == BlockGreenhouseType.SPRINKLER) {
|
||||
return state.withProperty(Properties.StaticProperty, true);
|
||||
} else {
|
||||
TileEntity tile = worldIn.getTileEntity(pos);
|
||||
TileEntity tile = TileUtil.getTile(worldIn, pos, TileEntity.class);
|
||||
if(tile instanceof IActivatable){
|
||||
state = state.withProperty(STATE, ((IActivatable) tile).isActive() ? State.ON : State.OFF);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import forestry.api.core.IModelBaker;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.models.ModelBlockDefault;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouse;
|
||||
import forestry.greenhouse.blocks.BlockGreenhouseType;
|
||||
@@ -28,6 +29,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -73,7 +75,7 @@ public class ModelGreenhouse extends ModelBlockDefault<BlockGreenhouse, ModelGre
|
||||
|
||||
if (camouflageStack != null) {
|
||||
ICamouflageHandler camouflageHandler = CamouflageUtil.getCamouflageHandler(world, pos);
|
||||
ICamouflagedTile camouflageTile = (ICamouflagedTile) world.getTileEntity(pos);
|
||||
ICamouflagedTile camouflageTile = (ICamouflagedTile) TileUtil.getTile(world, pos, TileEntity.class);
|
||||
ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandlerFromItem(camouflageStack);
|
||||
if(itemHandler != null){
|
||||
Pair<IBlockState, IBakedModel> model = itemHandler.getModel(camouflageStack, camouflageHandler, camouflageTile);
|
||||
|
||||
@@ -10,39 +10,32 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoRequest;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
|
||||
public class EventHandlerMailAlert {
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != Phase.END) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Minecraft.getMinecraft().theWorld != null && GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
if (event.phase == Phase.END &&
|
||||
Minecraft.getMinecraft().theWorld != null &&
|
||||
GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
GuiMailboxInfo.instance.render();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handlePlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
EntityPlayer player = event.player;
|
||||
if (player != null) {
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.worldObj, address);
|
||||
if (pobox != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
public void handleWorldLoad(WorldEvent.Load event) {
|
||||
World world = event.getWorld();
|
||||
if (world.isRemote) {
|
||||
PacketPOBoxInfoRequest packet = new PacketPOBoxInfoRequest();
|
||||
world.sendPacketToServer(packet.getPacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import forestry.core.network.PacketRegistry;
|
||||
import forestry.mail.network.packets.PacketLetterInfoRequest;
|
||||
import forestry.mail.network.packets.PacketLetterInfoResponse;
|
||||
import forestry.mail.network.packets.PacketLetterTextSet;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoRequest;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketTraderAddressRequest;
|
||||
import forestry.mail.network.packets.PacketTraderAddressResponse;
|
||||
@@ -24,6 +25,7 @@ public class PacketRegistryMail extends PacketRegistry {
|
||||
registerServerPacket(new PacketLetterInfoRequest());
|
||||
registerServerPacket(new PacketTraderAddressRequest());
|
||||
registerServerPacket(new PacketLetterTextSet());
|
||||
registerServerPacket(new PacketPOBoxInfoRequest());
|
||||
|
||||
registerClientPacket(new PacketLetterInfoResponse());
|
||||
registerClientPacket(new PacketTraderAddressResponse());
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.POBox;
|
||||
import forestry.mail.PostRegistry;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
public class PacketPOBoxInfoRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.worldObj, address);
|
||||
PacketPOBoxInfoUpdate packet = new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo());
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.POBOX_INFO_REQUEST;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ import forestry.storage.items.ItemBackpack;
|
||||
|
||||
public class ResupplyHandler implements IResupplyHandler {
|
||||
|
||||
private static List<ItemStack> backpacks(InventoryPlayer playerInventory) {
|
||||
private static List<ItemStack> getBackpacks(InventoryPlayer playerInventory) {
|
||||
List<ItemStack> backpacks = new ArrayList<>();
|
||||
for (ItemStack itemStack : playerInventory.mainInventory) {
|
||||
if (itemStack != null && itemStack.stackSize > 0 && itemStack.getItem() instanceof ItemBackpack) {
|
||||
@@ -41,48 +41,26 @@ public class ResupplyHandler implements IResupplyHandler {
|
||||
|
||||
@Override
|
||||
public void resupply(EntityPlayer player) {
|
||||
|
||||
// Do not attempt resupplying if this backpack is already opened.
|
||||
if (!(player.openContainer instanceof ContainerPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack backpack : backpacks(player.inventory)) {
|
||||
for (ItemStack backpack : getBackpacks(player.inventory)) {
|
||||
if (ItemBackpack.getMode(backpack) == BackpackMode.RESUPPLY) {
|
||||
// Load their inventory
|
||||
ItemBackpack backpackItem = (ItemBackpack) backpack.getItem();
|
||||
ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack);
|
||||
|
||||
// Only handle those in resupply mode
|
||||
if (ItemBackpack.getMode(backpack) != BackpackMode.RESUPPLY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Delay before resupplying
|
||||
if (backpack.getItemDamage() < 40) {
|
||||
backpack.setItemDamage(backpack.getItemDamage() + 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load their inventory
|
||||
ItemBackpack backpackItem = (ItemBackpack) backpack.getItem();
|
||||
ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack);
|
||||
|
||||
Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
if (event.isCanceled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Cycle through their contents
|
||||
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
|
||||
|
||||
ItemStack itemStack = backpackInventory.getStackInSlot(i);
|
||||
if (itemStack == null || itemStack.stackSize <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Try to add it to the player's inventory and note any change
|
||||
boolean change = topOffPlayerInventory(player, itemStack);
|
||||
|
||||
if (change) {
|
||||
backpackInventory.setInventorySlotContents(i, itemStack);
|
||||
Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory);
|
||||
if (!MinecraftForge.EVENT_BUS.post(event)) {
|
||||
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
|
||||
ItemStack itemStack = backpackInventory.getStackInSlot(i);
|
||||
if (topOffPlayerInventory(player, itemStack)) {
|
||||
backpackInventory.setInventorySlotContents(i, itemStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,29 +70,22 @@ public class ResupplyHandler implements IResupplyHandler {
|
||||
* This tops off existing stacks in the player's inventory.
|
||||
*/
|
||||
private static boolean topOffPlayerInventory(EntityPlayer player, ItemStack itemstack) {
|
||||
if (itemstack == null || itemstack.stackSize < 1) {
|
||||
return false;
|
||||
}
|
||||
InventoryPlayer playerInventory = player.inventory;
|
||||
ItemStack[] mainInventory = playerInventory.mainInventory;
|
||||
|
||||
// Add to player inventory first, if there is an incomplete stack in
|
||||
// there.
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack inventoryStack = player.inventory.getStackInSlot(i);
|
||||
// We only add to existing stacks.
|
||||
if (inventoryStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Already full
|
||||
if (inventoryStack.stackSize >= inventoryStack.getMaxStackSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inventoryStack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(inventoryStack, itemstack)) {
|
||||
for (ItemStack inventoryStack : mainInventory) {
|
||||
if (playerInventory.canMergeStacks(inventoryStack, itemstack)) {
|
||||
inventoryStack.stackSize++;
|
||||
inventoryStack.animationsToGo = 5;
|
||||
itemstack.stackSize--;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,3 +6,6 @@ public net.minecraft.client.renderer.texture.TextureMap field_94254_c # basePath
|
||||
public net.minecraft.client.renderer.texture.TextureMap field_110574_e # mapRegisteredSprites
|
||||
|
||||
public net.minecraft.client.renderer.texture.TextureMap func_110569_e()V # initMissingImage
|
||||
|
||||
#InventoryPlayer
|
||||
public net.minecraft.entity.player.InventoryPlayer func_184436_a(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z # canMergeStacks
|
||||
Reference in new issue
Block a user