Corporea Retainer.

This commit is contained in:
Vasco Lavos committed 2015-09-28 15:30:09 +01:00
1 parent 556dec52a6
commit ea747bc640
12 files changed
+314 -44

No files matched your search

@@ -0,0 +1,25 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 28, 2015, 11:25:48 AM (GMT)]
*/
package vazkii.botania.api.corporea;
/**
* A TileEntity that implements this be called by other TileEntities
* to allow for it to do any request at any time. This is used by the
* Corporea Retainer for example.
*/
public interface ICorporeaRequestor {
/*
* Executes the passed in request.
*/
public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark);
}
@@ -1,4 +1,4 @@
@API(owner = "Botania", apiVersion = "63", provides = "BotaniaAPI")
@API(owner = "Botania", apiVersion = "64", provides = "BotaniaAPI")
package vazkii.botania.api;
import cpw.mods.fml.common.API;
@@ -24,6 +24,7 @@ import vazkii.botania.common.block.corporea.BlockCorporeaCrystalCube;
import vazkii.botania.common.block.corporea.BlockCorporeaFunnel;
import vazkii.botania.common.block.corporea.BlockCorporeaIndex;
import vazkii.botania.common.block.corporea.BlockCorporeaInterceptor;
import vazkii.botania.common.block.corporea.BlockCorporeaRetainer;
import vazkii.botania.common.block.decor.BlockBlaze;
import vazkii.botania.common.block.decor.BlockBuriedPetals;
import vazkii.botania.common.block.decor.BlockCustomBrick;
@@ -146,6 +147,7 @@ import vazkii.botania.common.block.tile.corporea.TileCorporeaCrystalCube;
import vazkii.botania.common.block.tile.corporea.TileCorporeaFunnel;
import vazkii.botania.common.block.tile.corporea.TileCorporeaIndex;
import vazkii.botania.common.block.tile.corporea.TileCorporeaInterceptor;
import vazkii.botania.common.block.tile.corporea.TileCorporeaRetainer;
import vazkii.botania.common.block.tile.mana.TileBellows;
import vazkii.botania.common.block.tile.mana.TileDistributor;
import vazkii.botania.common.block.tile.mana.TileManaDetector;
@@ -254,6 +256,7 @@ public final class ModBlocks {
public static Block cellBlock;
public static Block redStringInterceptor;
public static Block gaiaHead;
public static Block corporeaRetainer;
public static void init() {
flower = new BlockModFlower();
@@ -340,6 +343,7 @@ public final class ModBlocks {
cellBlock = new BlockCell();
redStringInterceptor = new BlockRedStringInterceptor();
gaiaHead = new BlockGaiaHead();
corporeaRetainer = new BlockCorporeaRetainer();
ModFluffBlocks.init();
@@ -439,6 +443,7 @@ public final class ModBlocks {
registerTile(TileCell.class, LibBlockNames.CELL_BLOCK);
registerTile(TileRedStringInterceptor.class, LibBlockNames.RED_STRING_INTERCEPTOR);
registerTile(TileGaiaHead.class, LibBlockNames.GAIA_HEAD);
registerTile(TileCorporeaRetainer.class, LibBlockNames.CORPOREA_RETAINER);
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class);
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class);
@@ -0,0 +1,69 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 28, 2015, 11:53:13 AM (GMT)]
*/
package vazkii.botania.common.block.corporea;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import vazkii.botania.common.achievement.ICraftAchievement;
import vazkii.botania.common.achievement.ModAchievements;
import vazkii.botania.common.block.BlockModContainer;
import vazkii.botania.common.block.tile.corporea.TileCorporeaRetainer;
import vazkii.botania.common.lib.LibBlockNames;
public class BlockCorporeaRetainer extends BlockModContainer implements ICraftAchievement {
public BlockCorporeaRetainer() {
super(Material.iron);
setHardness(5.5F);
setStepSound(soundTypeMetal);
setBlockName(LibBlockNames.CORPOREA_RETAINER);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
boolean power = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
int meta = world.getBlockMetadata(x, y, z);
boolean powered = (meta & 8) != 0;
if(power && !powered) {
((TileCorporeaRetainer) world.getTileEntity(x, y, z)).fulfilRequest();
world.setBlockMetadataWithNotify(x, y, z, meta | 8, 4);
} else if(!power && powered)
world.setBlockMetadataWithNotify(x, y, z, meta & -9, 4);
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int s) {
return ((TileCorporeaRetainer) world.getTileEntity(x, y, z)).hasPendingRequest() ? 15 : 0;
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileCorporeaRetainer();
}
@Override
public Achievement getAchievementOnCraft(ItemStack stack, EntityPlayer player, IInventory matrix) {
return ModAchievements.corporeaCraft;
}
}
@@ -16,11 +16,13 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.api.corporea.CorporeaHelper;
import vazkii.botania.api.corporea.ICorporeaInterceptor;
import vazkii.botania.api.corporea.ICorporeaRequestor;
import vazkii.botania.api.corporea.ICorporeaSpark;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.common.lib.LibBlockNames;
public class TileCorporeaCrystalCube extends TileCorporeaBase {
public class TileCorporeaCrystalCube extends TileCorporeaBase implements ICorporeaRequestor {
private static final String TAG_REQUEST_TARGET = "requestTarget";
private static final String TAG_ITEM_COUNT = "itemCount";
@@ -65,21 +67,8 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase {
ICorporeaSpark spark = getSpark();
if(spark != null && spark.getMaster() != null && requestTarget != null) {
List<ItemStack> stacks = CorporeaHelper.requestItem(requestTarget, fullStack ? requestTarget.getMaxStackSize() : 1, spark, true, true);
spark.onItemsRequested(stacks);
boolean did = false;
for(ItemStack reqStack : stacks)
if(requestTarget != null) {
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, reqStack);
worldObj.spawnEntityInWorld(item);
itemCount -= reqStack.stackSize;
did = true;
}
if(did) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
onUpdateCount();
}
int count = fullStack ? requestTarget.getMaxStackSize() : 1;
doCorporeaRequest(requestTarget, count, spark);
}
}
@@ -146,4 +135,26 @@ public class TileCorporeaCrystalCube extends TileCorporeaBase {
return LibBlockNames.CORPOREA_CRYSTAL_CUBE;
}
@Override
public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark) {
if(!(request instanceof ItemStack))
return;
List<ItemStack> stacks = CorporeaHelper.requestItem((ItemStack) request, count, spark, true, true);
spark.onItemsRequested(stacks);
boolean did = false;
for(ItemStack reqStack : stacks)
if(requestTarget != null) {
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, reqStack);
worldObj.spawnEntityInWorld(item);
itemCount -= reqStack.stackSize;
did = true;
}
if(did) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
onUpdateCount();
}
}
}
@@ -20,37 +20,25 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import vazkii.botania.api.corporea.CorporeaHelper;
import vazkii.botania.api.corporea.ICorporeaInterceptor;
import vazkii.botania.api.corporea.ICorporeaRequestor;
import vazkii.botania.api.corporea.ICorporeaSpark;
import vazkii.botania.common.core.helper.InventoryHelper;
import vazkii.botania.common.lib.LibBlockNames;
import vazkii.botania.common.lib.LibMisc;
public class TileCorporeaFunnel extends TileCorporeaBase {
public class TileCorporeaFunnel extends TileCorporeaBase implements ICorporeaRequestor {
public void doRequest() {
ICorporeaSpark spark = getSpark();
if(spark != null && spark.getMaster() != null) {
IInventory inv = InventoryHelper.getInventory(worldObj, xCoord, yCoord - 1, zCoord);
if(inv == null)
inv = InventoryHelper.getInventory(worldObj, xCoord, yCoord - 2, zCoord);
List<ItemStack> filter = getFilter();
if(!filter.isEmpty()) {
ItemStack stack = filter.get(worldObj.rand.nextInt(filter.size()));
if(stack != null) {
List<ItemStack> stacks = CorporeaHelper.requestItem(stack, spark, true, true);
spark.onItemsRequested(stacks);
for(ItemStack reqStack : stacks)
if(stack != null) {
if(inv != null && reqStack.stackSize == InventoryHelper.testInventoryInsertion(inv, reqStack, ForgeDirection.UP))
InventoryHelper.insertItemIntoInventory(inv, reqStack);
else {
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, reqStack);
worldObj.spawnEntityInWorld(item);
}
}
}
System.out.println("self");
if(stack != null)
doCorporeaRequest(stack, stack.stackSize, spark);
}
}
}
@@ -98,4 +86,27 @@ public class TileCorporeaFunnel extends TileCorporeaBase {
return LibBlockNames.CORPOREA_FUNNEL;
}
@Override
public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark) {
System.out.println(request + " " + count);
if(!(request instanceof ItemStack))
return;
IInventory inv = InventoryHelper.getInventory(worldObj, xCoord, yCoord - 1, zCoord);
if(inv == null)
inv = InventoryHelper.getInventory(worldObj, xCoord, yCoord - 2, zCoord);
List<ItemStack> stacks = CorporeaHelper.requestItem((ItemStack) request, count, spark, true, true);
spark.onItemsRequested(stacks);
for(ItemStack reqStack : stacks)
if(request != null) {
if(inv != null && reqStack.stackSize == InventoryHelper.testInventoryInsertion(inv, reqStack, ForgeDirection.UP))
InventoryHelper.insertItemIntoInventory(inv, reqStack);
else {
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, reqStack);
worldObj.spawnEntityInWorld(item);
}
}
}
}
@@ -24,6 +24,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChatStyle;
@@ -34,6 +35,8 @@ import org.apache.commons.lang3.text.WordUtils;
import vazkii.botania.api.corporea.CorporeaHelper;
import vazkii.botania.api.corporea.ICorporeaAutoCompleteController;
import vazkii.botania.api.corporea.ICorporeaInterceptor;
import vazkii.botania.api.corporea.ICorporeaRequestor;
import vazkii.botania.api.corporea.ICorporeaSpark;
import vazkii.botania.common.achievement.ModAchievements;
import vazkii.botania.common.core.helper.MathHelper;
@@ -43,7 +46,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileCorporeaIndex extends TileCorporeaBase {
public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequestor {
public static final double RADIUS = 2.5;
@@ -199,6 +202,20 @@ public class TileCorporeaIndex extends TileCorporeaBase {
public String getInventoryName() {
return LibBlockNames.CORPOREA_INDEX;
}
@Override
public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark) {
if(!(request instanceof String))
return;
List<ItemStack> stacks = CorporeaHelper.requestItem((String) request, count, spark, true);
spark.onItemsRequested(stacks);
for(ItemStack stack : stacks)
if(stack != null) {
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack);
worldObj.spawnEntityInWorld(item);
}
}
public static boolean isInRangeOfIndex(EntityPlayer player, TileCorporeaIndex index) {
return MathHelper.pointDistanceSpace(index.xCoord + 0.5, index.yCoord + 0.5, index.zCoord + 0.5, player.posX, player.posY + (player.worldObj.isRemote ? 0 : 1.6), player.posZ) < RADIUS;
@@ -258,13 +275,7 @@ public class TileCorporeaIndex extends TileCorporeaBase {
name = stack.getDisplayName().toLowerCase().trim();
}
List<ItemStack> stacks = CorporeaHelper.requestItem(name, count, spark, true);
spark.onItemsRequested(stacks);
for(ItemStack stack : stacks)
if(stack != null) {
EntityItem item = new EntityItem(index.worldObj, index.xCoord + 0.5, index.yCoord + 1.5, index.zCoord + 0.5, stack);
index.worldObj.spawnEntityInWorld(item);
}
index.doCorporeaRequest(name, count, spark);
event.player.addChatMessage(new ChatComponentTranslation("botaniamisc.requestMsg", count, WordUtils.capitalizeFully(name), CorporeaHelper.lastRequestMatches, CorporeaHelper.lastRequestExtractions).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.LIGHT_PURPLE)));
if(CorporeaHelper.lastRequestExtractions >= 50000)
@@ -16,6 +16,7 @@ import java.util.List;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import vazkii.botania.api.corporea.CorporeaHelper;
@@ -58,6 +59,14 @@ public class TileCorporeaInterceptor extends TileCorporeaBase implements ICorpor
if(missing > 0 && getBlockMetadata() == 0) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 | 2);
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, getBlockType(), 2);
TileEntity requestor = (TileEntity) source.getInventory();
for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) {
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord, zCoord + dir.offsetZ);
if(tile != null && tile instanceof TileCorporeaRetainer)
((TileCorporeaRetainer) tile).setPendingRequest(requestor.xCoord, requestor.yCoord, requestor.zCoord, request, count);
}
return;
}
}
@@ -0,0 +1,126 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Sep 28, 2015, 11:55:56 AM (GMT)]
*/
package vazkii.botania.common.block.tile.corporea;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.api.corporea.CorporeaHelper;
import vazkii.botania.api.corporea.ICorporeaRequestor;
import vazkii.botania.api.corporea.ICorporeaSpark;
import vazkii.botania.common.block.tile.TileMod;
import vazkii.botania.common.lib.LibBlockNames;
public class TileCorporeaRetainer extends TileMod {
private static final String TAG_PENDING_REQUEST = "pendingRequest";
private static final String TAG_REQUEST_X = "requestX";
private static final String TAG_REQUEST_Y = "requestY";
private static final String TAG_REQUEST_Z = "requestZ";
private static final String TAG_REQUEST_TYPE = "requestType";
private static final String TAG_REQUEST_CONTENTS = "requestContents";
private static final String TAG_REQUEST_STACK = "requestStack";
private static final String TAG_REQUEST_COUNT = "requestCount";
private static final int REQUEST_NULL = 0;
private static final int REQUEST_ITEMSTACK = 1;
private static final int REQUEST_STRING = 2;
boolean pendingRequest = false;
int requestX, requestY, requestZ;
Object request;
int requestCount;
public void setPendingRequest(int x, int y, int z, Object request, int requestCount) {
if(pendingRequest)
return;
requestX = x;
requestY = y;
requestZ = z;
this.request = request;
this.requestCount = requestCount;
pendingRequest = true;
worldObj.func_147453_f(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
}
public boolean hasPendingRequest() {
return pendingRequest;
}
public void fulfilRequest() {
if(!hasPendingRequest())
return;
ICorporeaSpark spark = CorporeaHelper.getSparkForBlock(worldObj, requestX, requestY, requestZ);
if(spark != null) {
IInventory inv = spark.getInventory();
if(inv != null && inv instanceof ICorporeaRequestor) {
ICorporeaRequestor requestor = (ICorporeaRequestor) inv;
requestor.doCorporeaRequest(request, requestCount, spark);
pendingRequest = false;
worldObj.func_147453_f(xCoord, yCoord, zCoord, worldObj.getBlock(xCoord, yCoord, zCoord));
}
}
}
@Override
public void writeCustomNBT(NBTTagCompound cmp) {
super.writeCustomNBT(cmp);
cmp.setBoolean(TAG_PENDING_REQUEST, pendingRequest);
cmp.setInteger(TAG_REQUEST_X, requestX);
cmp.setInteger(TAG_REQUEST_Y, requestY);
cmp.setInteger(TAG_REQUEST_Z, requestZ);
int reqType = REQUEST_NULL;
if(request != null)
reqType = request instanceof String ? REQUEST_STRING : REQUEST_ITEMSTACK;
cmp.setInteger(TAG_REQUEST_TYPE, reqType);
switch (reqType) {
case REQUEST_STRING:
cmp.setString(TAG_REQUEST_CONTENTS, (String) request);
break;
case REQUEST_ITEMSTACK:
NBTTagCompound cmp1 = new NBTTagCompound();
((ItemStack) request).writeToNBT(cmp1);
cmp.setTag(TAG_REQUEST_STACK, cmp1);
break;
default: break;
}
cmp.setInteger(TAG_REQUEST_COUNT, requestCount);
}
@Override
public void readCustomNBT(NBTTagCompound cmp) {
super.readCustomNBT(cmp);
pendingRequest = cmp.getBoolean(TAG_PENDING_REQUEST);
requestX = cmp.getInteger(TAG_REQUEST_X);
requestY = cmp.getInteger(TAG_REQUEST_Y);
requestZ = cmp.getInteger(TAG_REQUEST_Z);
int reqType = cmp.getInteger(TAG_REQUEST_TYPE);
switch (reqType) {
case REQUEST_STRING:
request = cmp.getString(TAG_REQUEST_CONTENTS);
break;
case REQUEST_ITEMSTACK:
NBTTagCompound cmp1 = cmp.getCompoundTag(TAG_REQUEST_STACK);
request = ItemStack.loadItemStackFromNBT(cmp1);
break;
default: break;
}
requestCount = cmp.getInteger(TAG_REQUEST_COUNT);
}
}
@@ -270,6 +270,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
addBlock(ModBlocks.corporeaIndex);
addBlock(ModBlocks.corporeaFunnel);
addBlock(ModBlocks.corporeaInterceptor);
addBlock(ModBlocks.corporeaRetainer);
addBlock(ModBlocks.corporeaCrystalCube);
addBlock(ModBlocks.lightRelay);
addBlock(ModBlocks.lightLauncher);
@@ -100,7 +100,8 @@ public final class LibBlockNames {
public static final String PAVEMENT = "pavement";
public static final String CELL_BLOCK = "cellBlock";
public static final String GAIA_HEAD = "gaiaHeadBlock";
public static final String CORPOREA_RETAINER = "corporeaRetainer";
public static final String SUBTILE_PUREDAISY = "puredaisy";
public static final String SUBTILE_MANASTAR = "manastar";