Added dispay stand and leaf blower and potion ring integration for it

This commit is contained in:
Ellpeck 2016-06-06 21:27:09 +02:00
parent 5972b516e9
commit 5895a8de1c
15 changed files with 420 additions and 26 deletions

View file

@ -0,0 +1,21 @@
/*
* This file ("IDisplayStandItem.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.api.misc;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public interface IDisplayStandItem{
boolean update(ItemStack stack, TileEntity tile, int elapsedTicks);
int getUsePerTick(ItemStack stack, TileEntity tile, int elapsedTicks);
}

View file

@ -0,0 +1,89 @@
/*
* This file ("BlockDisplayStand.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.TileEntityDisplayStand;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockDisplayStand extends BlockContainerBase{
public BlockDisplayStand(String name){
super(Material.ROCK, name);
this.setHarvestLevel("pickaxe", 0);
this.setHardness(1.5F);
this.setResistance(10.0F);
this.setSoundType(SoundType.STONE);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta){
return new TileEntityDisplayStand();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing par6, float par7, float par8, float par9){
if(!world.isRemote){
TileEntityDisplayStand stand = (TileEntityDisplayStand)world.getTileEntity(pos);
if(stand != null){
ItemStack display = stand.getStackInSlot(0);
if(heldItem != null){
if(display == null){
ItemStack toPut = heldItem.copy();
toPut.stackSize = 1;
stand.setInventorySlotContents(0, toPut);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
return true;
}
}
else{
if(display != null){
player.inventory.setInventorySlotContents(player.inventory.currentItem, display.copy());
stand.setInventorySlotContents(0, null);
return true;
}
}
}
return false;
}
else{
return true;
}
}
@SuppressWarnings("deprecation")
@Override
public boolean isOpaqueCube(IBlockState state){
return false;
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
this.dropInventory(worldIn, pos);
super.breakBlock(worldIn, pos, state);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE;
}
}

View file

@ -116,10 +116,12 @@ public class InitBlocks{
public static Block blockPillarQuartzSlab;
public static Block blockBookletStand;
public static Block blockDisplayStand;
public static void init(){
ModUtil.LOGGER.info("Initializing Blocks...");
blockDisplayStand = new BlockDisplayStand("blockDisplayStand");
blockPlayerInterface = new BlockPlayerInterface("blockPlayerInterface");
blockBookletStand = new BlockBookletStand("blockBookletStand");
blockItemViewer = new BlockItemViewer("blockItemViewer");

View file

@ -0,0 +1,52 @@
/*
* This file ("RenderDisplayStand.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.render;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class RenderDisplayStand extends TileEntitySpecialRenderer{
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float par5, int par6){
if(!(tile instanceof TileEntityDisplayStand)){
return;
}
ItemStack stack = ((TileEntityDisplayStand)tile).getStackInSlot(0);
if(stack != null){
GlStateManager.pushMatrix();
GlStateManager.translate((float)x+0.5F, (float)y+1F, (float)z+0.5F);
double boop = Minecraft.getSystemTime()/800D;
GlStateManager.translate(0D, Math.sin(boop%(2*Math.PI))*0.065, 0D);
GlStateManager.rotate((float)(((boop*40D)%360)), 0, 1, 0);
float scale = stack.getItem() instanceof ItemBlock ? 0.85F : 0.65F;
GlStateManager.scale(scale, scale, scale);
try{
AssetUtil.renderItemInWorld(stack);
}
catch(Exception e){
ModUtil.LOGGER.error("Something went wrong trying to render an item in a display stand! The item is "+stack.getItem().getRegistryName()+"!", e);
}
GlStateManager.popMatrix();
}
}
}

View file

@ -73,6 +73,7 @@ public class CreativeTab extends CreativeTabs{
this.add(InitBlocks.blockPhantomBooster);
this.add(InitBlocks.blockCoffeeMachine);
this.add(InitBlocks.blockXPSolidifier);
this.add(InitBlocks.blockDisplayStand);
this.add(InitBlocks.blockMiner);
this.add(InitBlocks.blockGreenhouseGlass);

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
@ -22,6 +23,7 @@ import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
@ -33,7 +35,7 @@ import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Collections;
public class ItemLeafBlower extends ItemBase{
public class ItemLeafBlower extends ItemBase implements IDisplayStandItem{
private final boolean isAdvanced;
@ -70,16 +72,22 @@ public class ItemLeafBlower extends ItemBase{
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int time){
if(!player.worldObj.isRemote){
this.doUpdate(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), time, stack);
}
private boolean doUpdate(World world, int x, int y, int z, int time, ItemStack stack){
if(!world.isRemote){
if(time <= this.getMaxItemUseDuration(stack) && (this.isAdvanced || time%3 == 0)){
//Breaks the Blocks
this.breakStuff(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
boolean broke = this.breakStuff(world, x, y, z);
//Plays a Minecart sounds (It really sounds like a Leaf Blower!)
if(!ConfigBoolValues.LESS_SOUND.isEnabled()){
player.worldObj.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_MINECART_RIDING, SoundCategory.PLAYERS, 0.3F, 0.001F);
world.playSound(null, x, y, z, SoundEvents.ENTITY_MINECART_RIDING, SoundCategory.PLAYERS, 0.3F, 0.001F);
}
return broke;
}
}
return false;
}
/**
@ -90,7 +98,7 @@ public class ItemLeafBlower extends ItemBase{
* @param y The Y Position of the Player
* @param z The Z Position of the Player
*/
public void breakStuff(World world, int x, int y, int z){
public boolean breakStuff(World world, int x, int y, int z){
ArrayList<BlockPos> breakPositions = new ArrayList<BlockPos>();
int rangeSides = 5;
@ -130,6 +138,18 @@ public class ItemLeafBlower extends ItemBase{
//Drops the Items into the World
world.spawnEntityInWorld(new EntityItem(world, theCoord.getX()+0.5, theCoord.getY()+0.5, theCoord.getZ()+0.5, theDrop));
}
return true;
}
return false;
}
@Override
public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){
return this.doUpdate(tile.getWorld(), tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), elapsedTicks, stack);
}
@Override
public int getUsePerTick(ItemStack stack, TileEntity tile, int elapsedTicks){
return 60;
}
}

View file

@ -10,27 +10,33 @@
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.ThePotionRings;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.Collections;
import java.util.List;
public class ItemPotionRing extends ItemBase implements IColorProvidingItem{
public class ItemPotionRing extends ItemBase implements IColorProvidingItem, IDisplayStandItem{
public static final ThePotionRings[] allRings = ThePotionRings.values();
@ -62,25 +68,12 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem{
if(!world.isRemote && stack.getItemDamage() < allRings.length){
if(player instanceof EntityPlayer){
EntityPlayer thePlayer = (EntityPlayer)player;
ItemStack equippedStack = ((EntityPlayer)player).getHeldItemMainhand();
ThePotionRings effect = ThePotionRings.values()[stack.getItemDamage()];
Potion potion = Potion.getPotionById(effect.effectID);
if(!effect.needsWaitBeforeActivating || !thePlayer.isPotionActive(potion)){
if(!((ItemPotionRing)stack.getItem()).isAdvanced){
if(equippedStack != null && stack == equippedStack){
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.normalAmplifier, true, false));
}
}
else{
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.advancedAmplifier, true, false));
}
}
ItemStack equippedStack = thePlayer.getHeldItemMainhand();
this.effectEntity(thePlayer, stack, equippedStack != null && stack == equippedStack);
}
}
}
@Override
public String getItemStackDisplayName(ItemStack stack){
String standardName = StringUtil.localize(this.getUnlocalizedName()+".name");
@ -122,4 +115,64 @@ public class ItemPotionRing extends ItemBase implements IColorProvidingItem{
}
};
}
@Override
public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){
boolean advanced = ((ItemPotionRing)stack.getItem()).isAdvanced;
int range = advanced ? 96 : 16;
List<EntityLivingBase> entities = tile.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(tile.getPos().getX()-range, tile.getPos().getY()-range, tile.getPos().getZ()-range, tile.getPos().getX()+range, tile.getPos().getY()+range, tile.getPos().getZ()+range));
if(entities != null && !entities.isEmpty()){
if(advanced){
//Give all entities the effect
for(EntityLivingBase entity : entities){
this.effectEntity(entity, stack, true);
}
return true;
}
else{
Potion potion = Potion.getPotionById(ThePotionRings.values()[stack.getItemDamage()].effectID);
for(EntityLivingBase entity : entities){
if(entity.isPotionActive(potion)){
//Sometimes make the effect switch to someone else
if(Util.RANDOM.nextInt(100) <= 0){
break;
}
else{
//Continue giving the entity that already has the potion effect the effect
//Otherwise, it will randomly switch around to other entities
this.effectEntity(entity, stack, true);
return true;
}
}
}
//Give the effect to someone new if no one had it or it randomly switched
Collections.shuffle(entities);
this.effectEntity(entities.get(0), stack, true);
return true;
}
}
return false;
}
@Override
public int getUsePerTick(ItemStack stack, TileEntity tile, int elapsedTicks){
return 325;
}
private void effectEntity(EntityLivingBase thePlayer, ItemStack stack, boolean canUseBasic){
ThePotionRings effect = ThePotionRings.values()[stack.getItemDamage()];
Potion potion = Potion.getPotionById(effect.effectID);
PotionEffect activeEffect = thePlayer.getActivePotionEffect(potion);
if(!effect.needsWaitBeforeActivating || (activeEffect == null || activeEffect.getDuration() <= 1)){
if(!((ItemPotionRing)stack.getItem()).isAdvanced){
if(canUseBasic){
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.normalAmplifier, true, false));
}
}
else{
thePlayer.addPotionEffect(new PotionEffect(potion, effect.activeTime, effect.advancedAmplifier, true, false));
}
}
}
}

View file

@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderCompost;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
@ -25,6 +26,7 @@ import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityDisplayStand;
import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud;
import de.ellpeck.actuallyadditions.mod.util.FluidStateMapper;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
@ -162,6 +164,7 @@ public class ClientProxy implements IProxy{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAtomicReconstructor.class, new RenderReconstructorLens());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySmileyCloud.class, new RenderSmileyCloud());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayStand.class, new RenderDisplayStand());
//VillagerRegistry.instance().registerVillagerSkin(ConfigIntValues.JAM_VILLAGER_ID.getValue(), new ResourceLocation(ModUtil.MOD_ID, "textures/entity/villager/jamVillager.png"));

View file

@ -91,6 +91,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
GameRegistry.registerTileEntity(TileEntityLaserRelayItemWhitelist.class, ModUtil.MOD_ID+":tileEntityLaserRelayItemWhitelist");
GameRegistry.registerTileEntity(TileEntityItemViewer.class, ModUtil.MOD_ID+":tileItemViewer");
GameRegistry.registerTileEntity(TileEntityBookletStand.class, ModUtil.MOD_ID+":tileEntityBookletStand");
GameRegistry.registerTileEntity(TileEntityDisplayStand.class, ModUtil.MOD_ID+":tileEntityDisplayStand");
}
@Override

View file

@ -0,0 +1,140 @@
/*
* This file ("TileEntityDisplayStand.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.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay, IEnergyReceiver{
private EnergyStorage storage = new EnergyStorage(300000);
private int oldEnergy;
public TileEntityDisplayStand(){
super(1, "displayStand");
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
if(this.slots[0] != null && !this.isRedstonePowered){
IDisplayStandItem item = this.convertToDisplayStandItem(this.slots[0].getItem());
if(item != null){
int energy = item.getUsePerTick(this.slots[0], this, this.ticksElapsed);
if(this.storage.getEnergyStored() >= energy){
if(item.update(this.slots[0], this, this.ticksElapsed)){
this.storage.extractEnergy(energy, false);
}
}
}
}
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
this.oldEnergy = this.storage.getEnergyStored();
}
}
}
@Override
public boolean shouldSyncSlots(){
return true;
}
@Override
public void markDirty(){
super.markDirty();
this.sendUpdate();
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){
return this.isItemValidForSlot(index, stack);
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.writeSyncableNBT(compound, isForSync);
this.storage.writeToNBT(compound);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.readSyncableNBT(compound, isForSync);
this.storage.readFromNBT(compound);
}
private IDisplayStandItem convertToDisplayStandItem(Item item){
if(item instanceof IDisplayStandItem){
return (IDisplayStandItem)item;
}
else if(item instanceof ItemBlock){
Block block = Block.getBlockFromItem(item);
if(block instanceof IDisplayStandItem){
return (IDisplayStandItem)block;
}
}
return null;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
return true;
}
@Override
public int getEnergy(){
return this.storage.getEnergyStored();
}
@Override
public int getMaxEnergy(){
return this.storage.getMaxEnergyStored();
}
@Override
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
return from != EnumFacing.UP ? this.storage.receiveEnergy(maxReceive, simulate) : 0;
}
@Override
public int getEnergyStored(EnumFacing from){
return from != EnumFacing.UP ? this.storage.getEnergyStored() : 0;
}
@Override
public int getMaxEnergyStored(EnumFacing from){
return from != EnumFacing.UP ? this.storage.getMaxEnergyStored() : 0;
}
@Override
public boolean canConnectEnergy(EnumFacing from){
return from != EnumFacing.UP;
}
@Override
public int getInventoryStackLimit(){
return 1;
}
}

View file

@ -127,11 +127,6 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return false;
}
@Override
public int getField(int id){
return 0;

View file

@ -0,0 +1,16 @@
{
"forge_marker": 1,
"defaults": {
"model": "minecraft:half_slab",
"textures": {
"bottom": "actuallyadditions:blocks/blockDisplayStand",
"top": "#bottom",
"side": "actuallyadditions:blocks/blockDisplayStandSide"
},
"transform": "forge:default-block"
},
"variants": {
"normal": [{}],
"inventory": [{}]
}
}

View file

@ -209,6 +209,7 @@ tile.actuallyadditions.blockLaserRelayItemWhitelist.name=Advanced Item Laser Rel
tile.actuallyadditions.blockItemViewer.name=Item Interface
tile.actuallyadditions.blockImpureIron.name=Impure Iron
tile.actuallyadditions.blockBookletStand.name=Wall-Mount Manual
tile.actuallyadditions.blockDisplayStand.name=Display Stand
#ESD
tile.actuallyadditions.blockInputter.name=ESD

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B