Added Player Interface

This commit is contained in:
Ellpeck 2016-06-05 04:05:37 +02:00
parent f576d58204
commit d66b53af9a
8 changed files with 288 additions and 0 deletions

View file

@ -0,0 +1,59 @@
/*
* This file ("BlockPlayerInterface.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBookletStand;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockPlayerInterface extends BlockContainerBase{
public BlockPlayerInterface(String name){
super(Material.ROCK, name);
this.setHarvestLevel("pickaxe", 0);
this.setHardness(4.5F);
this.setResistance(10.0F);
this.setSoundType(SoundType.STONE);
}
@Override
public TileEntity createNewTileEntity(World world, int par2){
return new TileEntityPlayerInterface();
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC;
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack){
TileEntity tile = world.getTileEntity(pos);
if(tile != null && tile instanceof TileEntityPlayerInterface){
TileEntityPlayerInterface face = (TileEntityPlayerInterface)tile;
if(face.connectedPlayer == null){
face.connectedPlayer = player.getUniqueID();
face.markDirty();
}
}
super.onBlockPlacedBy(world, pos, state, player, stack);
}
}

View file

@ -57,6 +57,7 @@ public class InitBlocks{
public static Block blockPhantomLiquiface;
public static Block blockPhantomEnergyface;
public static Block blockPhantomRedstoneface;
public static Block blockPlayerInterface;
public static Block blockFluidPlacer;
public static Block blockFluidCollector;
@ -119,6 +120,7 @@ public class InitBlocks{
public static void init(){
ModUtil.LOGGER.info("Initializing Blocks...");
blockPlayerInterface = new BlockPlayerInterface("blockPlayerInterface");
blockBookletStand = new BlockBookletStand("blockBookletStand");
blockItemViewer = new BlockItemViewer("blockItemViewer");
blockFireworkBox = new BlockFireworkBox("blockFireworkBox");

View file

@ -67,6 +67,7 @@ public class CreativeTab extends CreativeTabs{
this.add(InitBlocks.blockPhantomRedstoneface);
this.add(InitBlocks.blockPhantomPlacer);
this.add(InitBlocks.blockPhantomBreaker);
this.add(InitBlocks.blockPlayerInterface);
this.add(InitBlocks.blockInputter);
this.add(InitBlocks.blockInputterAdvanced);
this.add(InitBlocks.blockPhantomBooster);

View file

@ -67,6 +67,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
GameRegistry.registerTileEntity(TileEntityPhantomItemface.class, ModUtil.MOD_ID+":tileEntityPhantomItemface");
GameRegistry.registerTileEntity(TileEntityPhantomLiquiface.class, ModUtil.MOD_ID+":tileEntityPhantomLiquiface");
GameRegistry.registerTileEntity(TileEntityPhantomEnergyface.class, ModUtil.MOD_ID+":tileEntityPhantomEnergyface");
GameRegistry.registerTileEntity(TileEntityPlayerInterface.class, ModUtil.MOD_ID+":tileEntityPlayerInterface");
GameRegistry.registerTileEntity(TileEntityPhantomPlacer.class, ModUtil.MOD_ID+":tileEntityPhantomPlacer");
GameRegistry.registerTileEntity(TileEntityPhantomBreaker.class, ModUtil.MOD_ID+":tileEntityPhantomBreaker");
GameRegistry.registerTileEntity(TileEntityFluidCollector.class, ModUtil.MOD_ID+":tileEntityFluidCollector");

View file

@ -0,0 +1,210 @@
/*
* This file ("TileEntityPlayerInterface.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import java.util.UUID;
public class TileEntityPlayerInterface extends TileEntityInventoryBase implements IEnergyReceiver{
public static final int DEFAULT_RANGE = 32;
private EnergyStorage storage = new EnergyStorage(30000);
private int range;
public UUID connectedPlayer;
public TileEntityPlayerInterface(){
super(0, "playerInterface");
}
private EntityPlayer getPlayer(){
if(this.connectedPlayer != null){
EntityPlayer player = this.worldObj.getPlayerEntityByUUID(this.connectedPlayer);
if(player != null){
if(player.getDistance(this.pos.getX(), this.pos.getY(), this.pos.getZ()) <= this.range){
return player;
}
}
}
return null;
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
boolean changed = false;
this.range = TileEntityPhantomface.upgradeRange(DEFAULT_RANGE, this.worldObj, this.pos);
EntityPlayer player = this.getPlayer();
if(player != null){
for(int i = 0; i < player.inventory.getSizeInventory(); i++){
if(this.storage.getEnergyStored() > 0){
ItemStack slot = player.inventory.getStackInSlot(i);
if(slot != null && slot.getItem() instanceof IEnergyContainerItem){
int received = ((IEnergyContainerItem)slot.getItem()).receiveEnergy(slot, this.storage.getEnergyStored(), false);
this.storage.extractEnergy(received, false);
changed = true;
}
}
else{
break;
}
}
}
if(changed){
this.markDirty();
this.sendUpdate();
}
}
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
this.storage.writeToNBT(compound);
if(this.connectedPlayer != null){
compound.setUniqueId("Player", this.connectedPlayer);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
this.storage.readFromNBT(compound);
if(compound.hasKey("PlayerLeast")){
this.connectedPlayer = compound.getUniqueId("Player");
}
}
@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
return this.storage.receiveEnergy(maxReceive, simulate);
}
@Override
public int getEnergyStored(EnumFacing from){
return this.storage.getEnergyStored();
}
@Override
public int getMaxEnergyStored(EnumFacing from){
return this.storage.getMaxEnergyStored();
}
@Override
public boolean canConnectEnergy(EnumFacing from){
return true;
}
@Override
public int[] getSlotsForFace(EnumFacing side){
if(this.getPlayer() != null){
int[] theInt = new int[this.getSizeInventory()];
for(int i = 0; i < theInt.length; i++){
theInt[i] = i;
}
return theInt;
}
return new int[0];
}
@Override
public int getInventoryStackLimit(){
EntityPlayer player = this.getPlayer();
return player != null ? player.inventory.getInventoryStackLimit() : 0;
}
@Override
public void clear(){
EntityPlayer player = this.getPlayer();
if(player != null){
player.inventory.clear();
}
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
EntityPlayer player = this.getPlayer();
if(player != null){
player.inventory.setInventorySlotContents(i, stack);
}
}
@Override
public int getSizeInventory(){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.getSizeInventory();
}
else{
return 0;
}
}
@Override
public ItemStack getStackInSlot(int i){
EntityPlayer player = this.getPlayer();
if(player != null){
return player.inventory.getStackInSlot(i);
}
else{
return null;
}
}
@Override
public ItemStack decrStackSize(int i, int j){
EntityPlayer player = this.getPlayer();
if(player != null){
ItemStack stack = player.inventory.decrStackSize(i, j);
if(stack != null){
return stack;
}
}
return null;
}
@Override
public ItemStack removeStackFromSlot(int index){
EntityPlayer player = this.getPlayer();
if(player != null){
ItemStack stack = player.inventory.removeStackFromSlot(index);
if(stack != null){
return stack;
}
}
return null;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
EntityPlayer player = this.getPlayer();
return player != null && player.inventory.isItemValidForSlot(i, stack);
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return true;
}
}

View file

@ -0,0 +1,14 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:cube_all",
"textures": {
"all": "actuallyadditions:blocks/blockPlayerInterface"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}]
}
}

View file

@ -141,6 +141,7 @@ tile.actuallyadditions.blockColoredLampPink.name=Pink Lamp
tile.actuallyadditions.blockColoredLampCyan.name=Cyan Lamp
tile.actuallyadditions.blockColoredLampPurple.name=Purple Lamp
tile.actuallyadditions.blockPhantomface.name=Phantomface
tile.actuallyadditions.blockPlayerInterface.name=Player Interface
tile.actuallyadditions.blockPhantomEnergyface.name=Phantom Energyface
tile.actuallyadditions.blockPhantomRedstoneface.name=Phantom Redstoneface
tile.actuallyadditions.blockPhantomLiquiface.name=Phantom Liquiface

Binary file not shown.

After

Width:  |  Height:  |  Size: 885 B