1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-12 03:13:00 +00:00

Move several methods out of the proxy

Some methods act the same on both sides, and so can be in utility
classes. Others are only needed on one side, and so do not really need
to be part of the proxy.

 - Remove TurtleVisionCamera. It would be possible to add this back in
   the future, but for now it is unused and so should be removed.
 - Move frame info (cursor blink, current render frame) into a
   FrameInfo class.
 - Move record methods (name, playing a record) into a RecordUtil class.
This commit is contained in:
SquidDev
2018-12-27 11:58:08 +00:00
parent 2c87e66db8
commit 26ba61097b
16 changed files with 147 additions and 463 deletions

View File

@@ -6,8 +6,8 @@
package dan200.computercraft.shared.media.items;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.util.RecordUtil;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
@@ -34,7 +34,7 @@ public class RecordMedia implements IMedia
@Override
public String getAudioTitle( @Nonnull ItemStack stack )
{
return ComputerCraft.getRecordInfo( stack );
return RecordUtil.getRecordInfo( stack );
}
@Override

View File

@@ -16,6 +16,7 @@ import dan200.computercraft.shared.peripheral.PeripheralType;
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
import dan200.computercraft.shared.util.InventoryUtil;
import dan200.computercraft.shared.util.RecordUtil;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@@ -655,17 +656,17 @@ public class TileDiskDrive extends TilePeripheralBase
SoundEvent record = (contents != null) ? contents.getAudio( m_diskStack ) : null;
if( record != null )
{
ComputerCraft.playRecord( record, contents.getAudioTitle( m_diskStack ), getWorld(), getPos() );
RecordUtil.playRecord( record, contents.getAudioTitle( m_diskStack ), getWorld(), getPos() );
}
else
{
ComputerCraft.playRecord( null, null, getWorld(), getPos() );
RecordUtil.playRecord( null, null, getWorld(), getPos() );
}
}
private void stopRecord()
{
ComputerCraft.playRecord( null, null, getWorld(), getPos() );
RecordUtil.playRecord( null, null, getWorld(), getPos() );
}
@Override

View File

@@ -64,7 +64,6 @@ import net.minecraft.command.CommandHandler;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.item.Item;
@@ -75,7 +74,10 @@ import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
@@ -95,16 +97,9 @@ import net.minecraftforge.registries.IForgeRegistry;
import pl.asie.charset.ModCharset;
import javax.annotation.Nonnull;
import java.io.File;
public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
{
public ComputerCraftProxyCommon()
{
}
// IComputerCraftProxy implementation
@Override
public void preInit()
{
@@ -112,14 +107,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
// Creative tab
ComputerCraft.mainCreativeTab = new CreativeTabMain( CreativeTabs.getNextID() );
// Recipe types
// RecipeSorter.register( "computercraft:impostor", ImpostorRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" );
// RecipeSorter.register( "computercraft:impostor_shapeless", ImpostorShapelessRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
// RecipeSorter.register( "computercraft:disk", DiskRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
// RecipeSorter.register( "computercraft:colour", ColourableRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
// RecipeSorter.register( "computercraft:printout", PrintoutRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
// RecipeSorter.register( "computercraft:pocket_computer_upgrade", PocketComputerUpgradeRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" );
}
@Override
@@ -139,73 +126,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
handler.registerCommand( new CommandComputerCraft() );
}
@Override
public abstract boolean isClient();
@Override
public abstract boolean getGlobalCursorBlink();
@Override
public abstract long getRenderFrame();
@Override
public abstract Object getFixedWidthFontRenderer();
@Override
public String getRecordInfo( @Nonnull ItemStack recordStack )
{
Item item = recordStack.getItem();
if( item instanceof ItemRecord )
{
ItemRecord record = (ItemRecord) item;
return StringUtil.translateToLocal( record.displayName );
}
return null;
}
@Override
public void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
{
ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.PlayRecord;
if( record != null )
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ(), SoundEvent.REGISTRY.getIDForObject( record ) };
packet.m_dataString = new String[] { recordInfo };
}
else
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ() };
}
NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint( world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64 );
ComputerCraft.sendToAllAround( packet, point );
}
@Override
public abstract Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );
@Override
public abstract Object getComputerGUI( TileComputer computer );
@Override
public abstract Object getPrinterGUI( InventoryPlayer inventory, TilePrinter printer );
@Override
public abstract Object getTurtleGUI( InventoryPlayer inventory, TileTurtle turtle );
@Override
public abstract Object getPrintoutGUI( EntityPlayer player, EnumHand hand );
@Override
public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand );
@Override
public abstract Object getComputerGUI( IComputer computer, int width, int height, ComputerFamily family );
@Override
public abstract File getWorldDir( World world );
@Override
public void handlePacket( final ComputerCraftPacket packet, final EntityPlayer player )
{

View File

@@ -15,14 +15,10 @@ import dan200.computercraft.shared.peripheral.printer.TilePrinter;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.io.File;
public interface IComputerCraftProxy
@@ -33,18 +29,6 @@ public interface IComputerCraftProxy
void initServer( MinecraftServer server );
boolean isClient();
boolean getGlobalCursorBlink();
long getRenderFrame();
Object getFixedWidthFontRenderer();
String getRecordInfo( @Nonnull ItemStack item );
void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos );
Object getDiskDriveGUI( InventoryPlayer inventory, TileDiskDrive drive );
Object getComputerGUI( TileComputer computer );

View File

@@ -1,116 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.turtle.entity;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import java.util.ArrayList;
public class TurtleVisionCamera extends EntityLivingBase
{
private ITurtleAccess m_turtle;
private ArrayList<ItemStack> m_armor;
public TurtleVisionCamera( World world, ITurtleAccess turtle )
{
super( world );
m_turtle = turtle;
m_armor = new ArrayList<>();
applyPos();
}
public ITurtleAccess getTurtle()
{
return m_turtle;
}
@Override
public float getEyeHeight()
{
return 0.0f;
}
@Nonnull
@Override
public EnumHandSide getPrimaryHand()
{
return EnumHandSide.RIGHT;
}
@Override
public void onUpdate()
{
m_turtle = ((TurtleBrain) m_turtle).getFutureSelf();
applyPos();
}
private void applyPos()
{
Vec3d prevPos = m_turtle.getVisualPosition( 0.0f );
this.lastTickPosX = this.prevPosX = prevPos.x;
this.lastTickPosY = this.prevPosY = prevPos.y;
this.lastTickPosZ = this.prevPosZ = prevPos.z;
this.prevRotationPitch = 0.0f;
this.prevRotationYaw = m_turtle.getVisualYaw( 0.0f );
this.prevCameraPitch = 0.0f;
Vec3d pos = m_turtle.getVisualPosition( 1.0f );
this.posX = pos.x;
this.posY = pos.y;
this.posZ = pos.z;
this.rotationPitch = 0.0f;
this.rotationYaw = m_turtle.getVisualYaw( 1.0f );
this.cameraPitch = 0.0f;
float yawDifference = this.rotationYaw - this.prevRotationYaw;
if( yawDifference > 180.0f )
{
this.prevRotationYaw += 360.0f;
}
else if( yawDifference < -180.0f )
{
this.prevRotationYaw -= 360.0f;
}
}
// EntityLivingBase overrides:
@Nonnull
@Override
public ItemStack getHeldItem( EnumHand hand )
{
return ItemStack.EMPTY;
}
@Override
public void setItemStackToSlot( @Nonnull EntityEquipmentSlot slot, @Nonnull ItemStack stack )
{
}
@Nonnull
@Override
public ItemStack getItemStackFromSlot( @Nonnull EntityEquipmentSlot slot )
{
return ItemStack.EMPTY;
}
@Nonnull
@Override
public Iterable<ItemStack> getArmorInventoryList()
{
return m_armor;
}
}

View File

@@ -0,0 +1,49 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.shared.util;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.network.ComputerCraftPacket;
import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import javax.annotation.Nonnull;
public class RecordUtil
{
public static void playRecord( SoundEvent record, String recordInfo, World world, BlockPos pos )
{
ComputerCraftPacket packet = new ComputerCraftPacket();
packet.m_packetType = ComputerCraftPacket.PlayRecord;
if( record != null )
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ(), SoundEvent.REGISTRY.getIDForObject( record ) };
packet.m_dataString = new String[] { recordInfo };
}
else
{
packet.m_dataInt = new int[] { pos.getX(), pos.getY(), pos.getZ() };
}
NetworkRegistry.TargetPoint point = new NetworkRegistry.TargetPoint( world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64 );
ComputerCraft.sendToAllAround( packet, point );
}
public static String getRecordInfo( @Nonnull ItemStack recordStack )
{
Item item = recordStack.getItem();
if( !(item instanceof ItemRecord) ) return null;
ItemRecord record = (ItemRecord) item;
return StringUtil.translateToLocal( record.displayName );
}
}