Commit 5c3773a0 authored by Teheno Pengin's avatar Teheno Pengin 💬
Browse files

Aesthetic fix to issue 1

parent c4e2f110
Loading
Loading
Loading
Loading
+1 −1
Changes for build.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -14,6 +14,6 @@ jei_version=4.11.0.206
mod_id=baubleshulkerboxes
mod_id_fancy=BaubleShulkerBoxes
mod_name=Bauble Shulker Boxes
mod_version=1r
mod_version=2r
cf_project=303956
release_type=release
 No newline at end of file
+3
Changes for src/main/java/com/zeitheron/baublesb/BaubleShulkerBoxes.java: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -99,9 +99,12 @@ public class BaubleShulkerBoxes
		{
			IShulkerAnimation isa = event.player.getCapability(ANIMATION_CAPABILITY, null);
			if(isa != null)
			{
				isa.setPlayer(event.player);
				isa.update();
			}
		}
	}
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent e)
+10
Changes for src/main/java/com/zeitheron/baublesb/cap/IShulkerAnimation.java: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
package com.zeitheron.baublesb.cap;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.util.INBTSerializable;

public interface IShulkerAnimation extends ITickable, INBTSerializable<NBTTagCompound>
{
	default void setPlayer(EntityPlayer player)
	{
	}
	
	default EntityPlayer getPlayer()
	{
		return null;
	}
	
	void open();
	
	void close();
+39
Changes for src/main/java/com/zeitheron/baublesb/cap/ShulkerImpl.java: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
package com.zeitheron.baublesb.cap;

import java.lang.ref.WeakReference;

import com.zeitheron.baublesb.NetworkBSB;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.ContainerShulkerBox;
import net.minecraft.nbt.NBTTagCompound;

public class ShulkerImpl implements IShulkerAnimation
@@ -9,25 +16,57 @@ public class ShulkerImpl implements IShulkerAnimation
	public float progress;
	public boolean action;
	
	public WeakReference<EntityPlayer> playerRef;
	
	@Override
	public void update()
	{
		EntityPlayer player = getPlayer();
		if(player instanceof EntityPlayerMP && !player.world.isRemote)
		{
			boolean open = player.openContainer instanceof ContainerShulkerBox;
			
			if(open != action)
			{
				action = open;
				NetworkBSB.INSTANCE.syncAnimation((EntityPlayerMP) player);
			}
		}
		
		if(action && progress < 1F)
			progress = Math.min(1F, progress + actionStep);
		else if(!action && progress > 0F)
			progress = Math.max(0F, progress - actionStep);
	}
	
	@Override
	public void setPlayer(EntityPlayer player)
	{
		playerRef = new WeakReference<>(player);
	}
	
	@Override
	public EntityPlayer getPlayer()
	{
		return playerRef != null ? playerRef.get() : null;
	}
	
	@Override
	public void open()
	{
		action = true;
		EntityPlayer player = getPlayer();
		if(player instanceof EntityPlayerMP)
			NetworkBSB.INSTANCE.syncAnimation((EntityPlayerMP) player);
	}
	
	@Override
	public void close()
	{
		action = false;
		EntityPlayer player = getPlayer();
		if(player instanceof EntityPlayerMP)
			NetworkBSB.INSTANCE.syncAnimation((EntityPlayerMP) player);
	}
	
	@Override