mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-12 00:08:01 +00:00
finish up cabinet logic
This commit is contained in:
1 parent
e7e5292526
commit
f366dcdfc6
2 files changed
+50
-11
No files matched your search
@@ -4,7 +4,10 @@ import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -13,6 +16,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import magicbees.main.CommonProxy;
|
||||
import magicbees.main.utils.TabMagicBees;
|
||||
import magicbees.tileentity.TileEntityPhialingCabinet;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.IEssentiaContainerItem;
|
||||
|
||||
public class BlockPhialingCabinet extends BlockContainer {
|
||||
|
||||
@@ -36,9 +41,35 @@ public class BlockPhialingCabinet extends BlockContainer {
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7,
|
||||
float par8, float par9) {
|
||||
boolean activate = false;
|
||||
if (world.isRemote) {
|
||||
return false;
|
||||
} else {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof TileEntityPhialingCabinet) {
|
||||
ItemStack tItemStack = player.getHeldItem();
|
||||
if (tItemStack != null) {
|
||||
Item tItem = tItemStack.getItem();
|
||||
if (tItem instanceof IEssentiaContainerItem
|
||||
&& ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()) != null
|
||||
&& ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem()).size() > 0) {
|
||||
Aspect tLocked = ((IEssentiaContainerItem) tItem).getAspects(player.getHeldItem())
|
||||
.getAspects()[0];
|
||||
((TileEntityPhialingCabinet) tile).setAspect(tLocked);
|
||||
|
||||
return activate;
|
||||
// TODO: improve text
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("Producing " + tLocked.getLocalizedDescription()));
|
||||
}
|
||||
} else {
|
||||
((TileEntityPhialingCabinet) tile).setAspect(null);
|
||||
|
||||
// TODO: improve text
|
||||
player.addChatMessage(new ChatComponentTranslation("Cleared production specifier"));
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,10 +2,11 @@ package magicbees.tileentity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import magicbees.main.utils.ChunkCoords;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
@@ -29,6 +30,10 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont
|
||||
|
||||
private int increment = 0;
|
||||
|
||||
public void setAspect(Aspect sAspect) {
|
||||
aspect = sAspect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
// If there's no stored aspect we shouldn't even check for the above block.
|
||||
@@ -53,7 +58,9 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont
|
||||
increment = 0;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
MinecraftServer.getServer().addChatMessage(new ChatComponentText(ignored.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
increment++;
|
||||
@@ -76,14 +83,15 @@ public class TileEntityPhialingCabinet extends TileEntity implements IAspectCont
|
||||
|
||||
@Override
|
||||
public int addToContainer(Aspect tag, int am) {
|
||||
if (am != 0) {
|
||||
int amount = this.essentia.visSize();
|
||||
if (amount < this.maxAmount && tag == this.aspect || amount == 0) {
|
||||
this.aspect = tag;
|
||||
int added = Math.min(am, this.maxAmount - amount);
|
||||
am -= added;
|
||||
}
|
||||
int toAdd = Math.min(maxAmount - essentia.visSize(), am);
|
||||
|
||||
if (aspect.equals(tag) && toAdd > 0) {
|
||||
essentia.add(aspect, toAdd);
|
||||
markDirty();
|
||||
return am - toAdd;
|
||||
}
|
||||
|
||||
markDirty();
|
||||
return am;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user