mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-06-22 16:34:10 +00:00
Merge pull request #237 from Restioson/feature/speaker
[Peripheral] Speaker
This commit is contained in:
commit
cd85a03429
@ -40,6 +40,7 @@ import dan200.computercraft.shared.peripheral.modem.WirelessNetwork;
|
|||||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||||
|
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||||
import dan200.computercraft.shared.proxy.ICCTurtleProxy;
|
import dan200.computercraft.shared.proxy.ICCTurtleProxy;
|
||||||
import dan200.computercraft.shared.proxy.IComputerCraftProxy;
|
import dan200.computercraft.shared.proxy.IComputerCraftProxy;
|
||||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||||
@ -134,6 +135,8 @@ public class ComputerCraft
|
|||||||
public static int floppySpaceLimit = 125 * 1000;
|
public static int floppySpaceLimit = 125 * 1000;
|
||||||
public static int maximumFilesOpen = 128;
|
public static int maximumFilesOpen = 128;
|
||||||
|
|
||||||
|
public static int maxNotesPerTick = 8;
|
||||||
|
|
||||||
// Blocks and Items
|
// Blocks and Items
|
||||||
public static class Blocks
|
public static class Blocks
|
||||||
{
|
{
|
||||||
@ -166,12 +169,14 @@ public class ComputerCraft
|
|||||||
public static TurtleAxe diamondAxe;
|
public static TurtleAxe diamondAxe;
|
||||||
public static TurtleHoe diamondHoe;
|
public static TurtleHoe diamondHoe;
|
||||||
public static TurtleModem advancedModem;
|
public static TurtleModem advancedModem;
|
||||||
|
public static TurtleSpeaker turtleSpeaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class PocketUpgrades
|
public static class PocketUpgrades
|
||||||
{
|
{
|
||||||
public static PocketModem wirelessModem;
|
public static PocketModem wirelessModem;
|
||||||
public static PocketModem advancedModem;
|
public static PocketModem advancedModem;
|
||||||
|
public static PocketSpeaker pocketSpeaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Config {
|
public static class Config {
|
||||||
@ -198,6 +203,8 @@ public class ComputerCraft
|
|||||||
public static Property computerSpaceLimit;
|
public static Property computerSpaceLimit;
|
||||||
public static Property floppySpaceLimit;
|
public static Property floppySpaceLimit;
|
||||||
public static Property maximumFilesOpen;
|
public static Property maximumFilesOpen;
|
||||||
|
public static Property maxNotesPerTick;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registries
|
// Registries
|
||||||
@ -298,6 +305,9 @@ public class ComputerCraft
|
|||||||
Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush );
|
Config.turtlesCanPush = Config.config.get( Configuration.CATEGORY_GENERAL, "turtlesCanPush", turtlesCanPush );
|
||||||
Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
|
Config.turtlesCanPush.setComment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" );
|
||||||
|
|
||||||
|
Config.maxNotesPerTick = Config.config.get( Configuration.CATEGORY_GENERAL, "maxNotesPerTick", maxNotesPerTick );
|
||||||
|
Config.maxNotesPerTick.setComment( "Maximum amount of notes a speaker can play at once" );
|
||||||
|
|
||||||
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
for (Property property : Config.config.getCategory( Configuration.CATEGORY_GENERAL ).getOrderedValues())
|
||||||
{
|
{
|
||||||
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
|
property.setLanguageKey( "gui.computercraft:config." + CaseFormat.LOWER_CAMEL.to( CaseFormat.LOWER_UNDERSCORE, property.getName() ) );
|
||||||
@ -337,6 +347,8 @@ public class ComputerCraft
|
|||||||
turtlesObeyBlockProtection = Config.turtlesObeyBlockProtection.getBoolean();
|
turtlesObeyBlockProtection = Config.turtlesObeyBlockProtection.getBoolean();
|
||||||
turtlesCanPush = Config.turtlesCanPush.getBoolean();
|
turtlesCanPush = Config.turtlesCanPush.getBoolean();
|
||||||
|
|
||||||
|
maxNotesPerTick = Math.max(1, Config.maxNotesPerTick.getInt());
|
||||||
|
|
||||||
Config.config.save();
|
Config.config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +728,7 @@ public class ComputerCraft
|
|||||||
public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades() {
|
public static Iterable<IPocketUpgrade> getVanillaPocketUpgrades() {
|
||||||
List<IPocketUpgrade> upgrades = new ArrayList<IPocketUpgrade>();
|
List<IPocketUpgrade> upgrades = new ArrayList<IPocketUpgrade>();
|
||||||
for(IPocketUpgrade upgrade : pocketUpgrades.values()) {
|
for(IPocketUpgrade upgrade : pocketUpgrades.values()) {
|
||||||
if(upgrade instanceof PocketModem) {
|
if(upgrade instanceof PocketModem || upgrade instanceof PocketSpeaker) {
|
||||||
upgrades.add( upgrade );
|
upgrades.add( upgrade );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,6 +155,8 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon
|
|||||||
loadModel( event, "advanced_turtle_modem_on_left" );
|
loadModel( event, "advanced_turtle_modem_on_left" );
|
||||||
loadModel( event, "advanced_turtle_modem_off_right" );
|
loadModel( event, "advanced_turtle_modem_off_right" );
|
||||||
loadModel( event, "advanced_turtle_modem_on_right" );
|
loadModel( event, "advanced_turtle_modem_on_right" );
|
||||||
|
loadModel( event, "turtle_speaker_upgrade_left" );
|
||||||
|
loadModel( event, "turtle_speaker_upgrade_right" );
|
||||||
loadSmartModel( event, "turtle_dynamic", m_turtleSmartItemModel );
|
loadSmartModel( event, "turtle_dynamic", m_turtleSmartItemModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
|||||||
registerItemModel( ComputerCraft.Blocks.cable, 1, "wired_modem" );
|
registerItemModel( ComputerCraft.Blocks.cable, 1, "wired_modem" );
|
||||||
registerItemModel( ComputerCraft.Blocks.commandComputer, "command_computer" );
|
registerItemModel( ComputerCraft.Blocks.commandComputer, "command_computer" );
|
||||||
registerItemModel( ComputerCraft.Blocks.advancedModem, "advanced_modem" );
|
registerItemModel( ComputerCraft.Blocks.advancedModem, "advanced_modem" );
|
||||||
|
registerItemModel( ComputerCraft.Blocks.peripheral, 5, "speaker" );
|
||||||
|
|
||||||
registerItemModel( ComputerCraft.Items.disk, "disk" );
|
registerItemModel( ComputerCraft.Items.disk, "disk" );
|
||||||
registerItemModel( ComputerCraft.Items.diskExpanded, "disk_expanded" );
|
registerItemModel( ComputerCraft.Items.diskExpanded, "disk_expanded" );
|
||||||
|
@ -20,7 +20,8 @@ public enum PeripheralType implements IStringSerializable
|
|||||||
WiredModem( "wired_modem" ),
|
WiredModem( "wired_modem" ),
|
||||||
Cable( "cable" ),
|
Cable( "cable" ),
|
||||||
WiredModemWithCable( "wired_modem_with_cable" ),
|
WiredModemWithCable( "wired_modem_with_cable" ),
|
||||||
AdvancedModem( "advanced_modem" );
|
AdvancedModem( "advanced_modem" ),
|
||||||
|
Speaker( "speaker" );
|
||||||
|
|
||||||
private String m_name;
|
private String m_name;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
|
|||||||
import dan200.computercraft.shared.peripheral.modem.TileWirelessModem;
|
import dan200.computercraft.shared.peripheral.modem.TileWirelessModem;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||||
|
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
|
||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
import dan200.computercraft.shared.util.DirectionUtil;
|
||||||
import net.minecraft.block.properties.PropertyDirection;
|
import net.minecraft.block.properties.PropertyDirection;
|
||||||
import net.minecraft.block.properties.PropertyEnum;
|
import net.minecraft.block.properties.PropertyEnum;
|
||||||
@ -105,6 +106,10 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
{
|
{
|
||||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
|
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
|
||||||
}
|
}
|
||||||
|
else if (meta == 13)
|
||||||
|
{
|
||||||
|
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker);
|
||||||
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +169,11 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
meta = 12;
|
meta = 12;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
meta = 13;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
@ -323,6 +333,11 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
state = state.withProperty( Properties.FACING, dir );
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Monitor:
|
case Monitor:
|
||||||
case AdvancedMonitor:
|
case AdvancedMonitor:
|
||||||
{
|
{
|
||||||
@ -489,6 +504,10 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
{
|
{
|
||||||
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
|
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.AdvancedMonitor );
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
return getDefaultState().withProperty( Properties.VARIANT, BlockPeripheralVariant.Speaker );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,6 +546,10 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
{
|
{
|
||||||
return new TilePrinter();
|
return new TilePrinter();
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
return new TileSpeaker();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,6 +566,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
|||||||
|
|
||||||
switch( getPeripheralType( state ) )
|
switch( getPeripheralType( state ) )
|
||||||
{
|
{
|
||||||
|
case Speaker:
|
||||||
case DiskDrive:
|
case DiskDrive:
|
||||||
case Printer:
|
case Printer:
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,8 @@ public enum BlockPeripheralVariant implements IStringSerializable
|
|||||||
AdvancedMonitorDownLUD( "advanced_monitor_down_lud", PeripheralType.AdvancedMonitor ),
|
AdvancedMonitorDownLUD( "advanced_monitor_down_lud", PeripheralType.AdvancedMonitor ),
|
||||||
AdvancedMonitorDownRU( "advanced_monitor_down_ru", PeripheralType.AdvancedMonitor ),
|
AdvancedMonitorDownRU( "advanced_monitor_down_ru", PeripheralType.AdvancedMonitor ),
|
||||||
AdvancedMonitorDownLRU( "advanced_monitor_down_lru", PeripheralType.AdvancedMonitor ),
|
AdvancedMonitorDownLRU( "advanced_monitor_down_lru", PeripheralType.AdvancedMonitor ),
|
||||||
AdvancedMonitorDownLU( "advanced_monitor_down_lu", PeripheralType.AdvancedMonitor );
|
AdvancedMonitorDownLU( "advanced_monitor_down_lu", PeripheralType.AdvancedMonitor ),
|
||||||
|
Speaker( "speaker", PeripheralType.Speaker );
|
||||||
|
|
||||||
private String m_name;
|
private String m_name;
|
||||||
private PeripheralType m_peripheralType;
|
private PeripheralType m_peripheralType;
|
||||||
|
@ -56,6 +56,12 @@ public class ItemPeripheral extends ItemPeripheralBase
|
|||||||
stack = new ItemStack( this, quantity, 4 );
|
stack = new ItemStack( this, quantity, 4 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
stack = new ItemStack(this, quantity, 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
// Ignore types we can't handle
|
// Ignore types we can't handle
|
||||||
@ -77,6 +83,7 @@ public class ItemPeripheral extends ItemPeripheralBase
|
|||||||
list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) );
|
list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) );
|
||||||
list.add( PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 1 ) );
|
list.add( PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 1 ) );
|
||||||
list.add( PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ) );
|
list.add( PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ) );
|
||||||
|
list.add( PeripheralItemFactory.create( PeripheralType.Speaker, null, 1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,6 +112,10 @@ public class ItemPeripheral extends ItemPeripheralBase
|
|||||||
{
|
{
|
||||||
return PeripheralType.AdvancedMonitor;
|
return PeripheralType.AdvancedMonitor;
|
||||||
}
|
}
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
return PeripheralType.Speaker;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,10 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera
|
|||||||
{
|
{
|
||||||
return "tile.computercraft:advanced_modem";
|
return "tile.computercraft:advanced_modem";
|
||||||
}
|
}
|
||||||
|
case Speaker:
|
||||||
|
{
|
||||||
|
return "tile.computercraft:speaker";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public class PeripheralItemFactory
|
|||||||
ItemAdvancedModem advancedModem = ((ItemAdvancedModem)Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem ));
|
ItemAdvancedModem advancedModem = ((ItemAdvancedModem)Item.getItemFromBlock( ComputerCraft.Blocks.advancedModem ));
|
||||||
switch( type )
|
switch( type )
|
||||||
{
|
{
|
||||||
|
case Speaker:
|
||||||
case DiskDrive:
|
case DiskDrive:
|
||||||
case Printer:
|
case Printer:
|
||||||
case Monitor:
|
case Monitor:
|
||||||
|
@ -0,0 +1,264 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.peripheral.speaker;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
|
import dan200.computercraft.api.lua.ILuaTask;
|
||||||
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.SoundCategory;
|
||||||
|
import net.minecraft.util.SoundEvent;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class SpeakerPeripheral implements IPeripheral {
|
||||||
|
|
||||||
|
private TileSpeaker m_speaker;
|
||||||
|
private long m_clock;
|
||||||
|
private long m_lastPlayTime;
|
||||||
|
private int m_notesThisTick;
|
||||||
|
|
||||||
|
public SpeakerPeripheral()
|
||||||
|
{
|
||||||
|
m_clock = 0;
|
||||||
|
m_lastPlayTime = 0;
|
||||||
|
m_notesThisTick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpeakerPeripheral(TileSpeaker speaker)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
m_speaker = speaker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void update() {
|
||||||
|
m_clock++;
|
||||||
|
m_notesThisTick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld()
|
||||||
|
{
|
||||||
|
return m_speaker.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos()
|
||||||
|
{
|
||||||
|
return m_speaker.getPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IPeripheral implementations */
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(IPeripheral other)
|
||||||
|
{
|
||||||
|
if (other != null && other instanceof SpeakerPeripheral)
|
||||||
|
{
|
||||||
|
SpeakerPeripheral otherSpeaker = (SpeakerPeripheral) other;
|
||||||
|
return otherSpeaker.m_speaker == m_speaker;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void attach(@Nonnull IComputerAccess computerAccess)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detach(@Nonnull IComputerAccess computerAccess)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return "speaker";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String[] getMethodNames()
|
||||||
|
{
|
||||||
|
return new String[] {
|
||||||
|
"playSound", // Plays sound at resourceLocator
|
||||||
|
"playNote" // Plays note
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] callMethod(@Nonnull IComputerAccess computerAccess, @Nonnull ILuaContext context, int methodIndex, @Nonnull Object[] args) throws LuaException
|
||||||
|
{
|
||||||
|
switch (methodIndex)
|
||||||
|
{
|
||||||
|
// playsound
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
return playSound(args, context, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// playnote
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
return playNote(args, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
throw new LuaException("Method index out of range!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private synchronized Object[] playNote(Object[] arguments, ILuaContext context) throws LuaException
|
||||||
|
{
|
||||||
|
double volume = 1f;
|
||||||
|
double pitch = 1f;
|
||||||
|
|
||||||
|
// Check if arguments are correct
|
||||||
|
if (arguments.length == 0) // Too few args
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(arguments[0] instanceof String)) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SoundEvent.REGISTRY.containsKey(new ResourceLocation("block.note." + arguments[0])))
|
||||||
|
{
|
||||||
|
throw new LuaException("Invalid instrument, \"" + arguments[0] + "\"!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.length > 1)
|
||||||
|
{
|
||||||
|
if (!(arguments[1] instanceof Double) && arguments[1] != null) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
volume = arguments[1] != null ? ((Double) arguments[1]).floatValue() : 1f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.length > 2)
|
||||||
|
{
|
||||||
|
if (!(arguments[1] instanceof Double) && arguments[2] != null) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
pitch = arguments[2] != null ? ((Double) arguments[2]).floatValue() : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the resource location for note block notes changes, this method call will need to be updated
|
||||||
|
Object[] returnValue = playSound(new Object[] {"block.note." + arguments[0], volume, Math.pow(2d, (pitch - 12) / 12d)}, context, true);
|
||||||
|
|
||||||
|
if (returnValue[0] instanceof Boolean && (Boolean) returnValue[0])
|
||||||
|
{
|
||||||
|
m_notesThisTick++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private synchronized Object[] playSound(Object[] arguments, ILuaContext context, boolean isNote) throws LuaException
|
||||||
|
{
|
||||||
|
|
||||||
|
float volume = 1f;
|
||||||
|
float pitch = 1f;
|
||||||
|
|
||||||
|
// Check if arguments are correct
|
||||||
|
if (arguments.length == 0) // Too few args
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(arguments[0] instanceof String)) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.length > 1)
|
||||||
|
{
|
||||||
|
if (!(arguments[1] instanceof Double) && arguments[1] != null) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
|
||||||
|
volume = arguments[1] != null ? ((Double) arguments[1]).floatValue() : 1f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.length > 2)
|
||||||
|
{
|
||||||
|
if (!(arguments[2] instanceof Double) && arguments[2] != null) // Arg wrong type
|
||||||
|
{
|
||||||
|
throw new LuaException("Expected string, number (optional), number (optional)");
|
||||||
|
}
|
||||||
|
pitch = arguments[2] != null ? ((Double) arguments[2]).floatValue() : 1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ResourceLocation resourceName = new ResourceLocation((String) arguments[0]);
|
||||||
|
|
||||||
|
if (m_clock - m_lastPlayTime >= TileSpeaker.MIN_TICKS_BETWEEN_SOUNDS || ((m_clock - m_lastPlayTime == 0) && (m_notesThisTick < ComputerCraft.maxNotesPerTick) && isNote))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (SoundEvent.REGISTRY.containsKey(resourceName))
|
||||||
|
{
|
||||||
|
|
||||||
|
final World world = getWorld();
|
||||||
|
final BlockPos pos = getPos();
|
||||||
|
final ResourceLocation resource = resourceName;
|
||||||
|
final float vol = volume;
|
||||||
|
final float soundPitch = pitch;
|
||||||
|
|
||||||
|
context.issueMainThreadTask(new ILuaTask() {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public Object[] execute() throws LuaException {
|
||||||
|
world.playSound(null, pos, new SoundEvent(resource), SoundCategory.RECORDS, vol, soundPitch);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
m_lastPlayTime = m_clock;
|
||||||
|
return new Object[]{true}; // Success, return true
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Object[]{false}; // Failed - sound not existent, return false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Object[]{false}; // Failed - rate limited, return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.peripheral.speaker;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
public class TileSpeaker extends TilePeripheralBase
|
||||||
|
{
|
||||||
|
// Statics
|
||||||
|
static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
|
||||||
|
|
||||||
|
// Members
|
||||||
|
private SpeakerPeripheral m_peripheral;
|
||||||
|
|
||||||
|
public TileSpeaker()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
m_peripheral = new SpeakerPeripheral(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void update() {
|
||||||
|
m_peripheral.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPeripheralTile implementation
|
||||||
|
|
||||||
|
public IPeripheral getPeripheral(EnumFacing side)
|
||||||
|
{
|
||||||
|
return m_peripheral;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.pocket.peripherals;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.pocket.IPocketAccess;
|
||||||
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
|
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||||
|
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class PocketSpeaker implements IPocketUpgrade
|
||||||
|
{
|
||||||
|
public PocketSpeaker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getUpgradeID()
|
||||||
|
{
|
||||||
|
return new ResourceLocation( "computercraft", "speaker" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getUnlocalisedAdjective()
|
||||||
|
{
|
||||||
|
return "upgrade.computercraft:speaker.adjective";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemStack getCraftingItem()
|
||||||
|
{
|
||||||
|
return PeripheralItemFactory.create(PeripheralType.Speaker, null, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IPeripheral createPeripheral( @Nonnull IPocketAccess access )
|
||||||
|
{
|
||||||
|
return new PocketSpeakerPeripheral();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update( @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||||
|
{
|
||||||
|
if ( peripheral instanceof PocketSpeakerPeripheral )
|
||||||
|
{
|
||||||
|
Entity entity = access.getEntity();
|
||||||
|
|
||||||
|
PocketSpeakerPeripheral speaker = (PocketSpeakerPeripheral) peripheral;
|
||||||
|
|
||||||
|
if ( entity instanceof EntityLivingBase)
|
||||||
|
{
|
||||||
|
EntityLivingBase player = (EntityLivingBase) entity;
|
||||||
|
speaker.setLocation( entity.getEntityWorld(), player.posX, player.posY + player.getEyeHeight(), player.posZ );
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ( entity != null )
|
||||||
|
{
|
||||||
|
speaker.setLocation( entity.getEntityWorld(), entity.posX, entity.posY, entity.posZ );
|
||||||
|
}
|
||||||
|
speaker.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onRightClick(@Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.pocket.peripherals;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class PocketSpeakerPeripheral extends SpeakerPeripheral
|
||||||
|
{
|
||||||
|
private World m_world;
|
||||||
|
private BlockPos m_position;
|
||||||
|
|
||||||
|
PocketSpeakerPeripheral()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
m_world = null;
|
||||||
|
m_position = new BlockPos( 0.0, 0.0, 0.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLocation(World world, double x, double y, double z)
|
||||||
|
{
|
||||||
|
m_position = new BlockPos( x, y, z );
|
||||||
|
|
||||||
|
if( m_world != world )
|
||||||
|
{
|
||||||
|
m_world = world;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld()
|
||||||
|
{
|
||||||
|
return m_world;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockPos getPos()
|
||||||
|
{
|
||||||
|
if( m_world != null )
|
||||||
|
{
|
||||||
|
return m_position;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( IPeripheral other )
|
||||||
|
{
|
||||||
|
// Sufficient because of use case: checking peripherals on individual pocket computers -- there will not be +1
|
||||||
|
return other instanceof PocketSpeakerPeripheral;
|
||||||
|
}
|
||||||
|
}
|
@ -8,8 +8,10 @@ package dan200.computercraft.shared.proxy;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
|
import dan200.computercraft.core.computer.Computer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
|
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
|
||||||
|
import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral;
|
||||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtleAdvanced;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtleAdvanced;
|
||||||
@ -126,7 +128,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
|||||||
|
|
||||||
public static boolean isUpgradeVanilla( ITurtleUpgrade upgrade )
|
public static boolean isUpgradeVanilla( ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
return upgrade instanceof TurtleTool || upgrade instanceof TurtleModem || upgrade instanceof TurtleCraftingTable;
|
return upgrade instanceof TurtleTool || upgrade instanceof TurtleModem || upgrade instanceof TurtleCraftingTable || upgrade instanceof TurtleSpeaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUpgradeSuitableForFamily( ComputerFamily family, ITurtleUpgrade upgrade )
|
public static boolean isUpgradeSuitableForFamily( ComputerFamily family, ITurtleUpgrade upgrade )
|
||||||
@ -156,6 +158,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
|||||||
addUpgradedTurtle( family, ComputerCraft.Upgrades.craftingTable, list );
|
addUpgradedTurtle( family, ComputerCraft.Upgrades.craftingTable, list );
|
||||||
addUpgradedTurtle( family, ComputerCraft.Upgrades.wirelessModem, list );
|
addUpgradedTurtle( family, ComputerCraft.Upgrades.wirelessModem, list );
|
||||||
addUpgradedTurtle( family, ComputerCraft.Upgrades.advancedModem, list );
|
addUpgradedTurtle( family, ComputerCraft.Upgrades.advancedModem, list );
|
||||||
|
addUpgradedTurtle( family, ComputerCraft.Upgrades.turtleSpeaker, list );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addUpgradedTurtle( ComputerFamily family, ITurtleUpgrade upgrade, List<ItemStack> list )
|
private void addUpgradedTurtle( ComputerFamily family, ITurtleUpgrade upgrade, List<ItemStack> list )
|
||||||
@ -384,8 +387,12 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
|||||||
ComputerCraft.Upgrades.diamondHoe = new TurtleHoe( new ResourceLocation( "minecraft", "diamond_hoe" ), 7, "upgrade.minecraft:diamond_hoe.adjective", Items.DIAMOND_HOE );
|
ComputerCraft.Upgrades.diamondHoe = new TurtleHoe( new ResourceLocation( "minecraft", "diamond_hoe" ), 7, "upgrade.minecraft:diamond_hoe.adjective", Items.DIAMOND_HOE );
|
||||||
registerTurtleUpgradeInternal( ComputerCraft.Upgrades.diamondHoe );
|
registerTurtleUpgradeInternal( ComputerCraft.Upgrades.diamondHoe );
|
||||||
|
|
||||||
ComputerCraft.Upgrades.advancedModem = new TurtleModem( true, new ResourceLocation( "computercraft", "advanced_modem" ), -1 );
|
ComputerCraft.Upgrades.advancedModem = new TurtleModem( true, new ResourceLocation( "computercraft", "advanced_modem" ), -1 );
|
||||||
registerTurtleUpgradeInternal( ComputerCraft.Upgrades.advancedModem );
|
registerTurtleUpgradeInternal( ComputerCraft.Upgrades.advancedModem );
|
||||||
|
|
||||||
|
ComputerCraft.Upgrades.turtleSpeaker = new TurtleSpeaker( new ResourceLocation( "computercraft", "speaker" ), 8 );
|
||||||
|
registerTurtleUpgradeInternal( ComputerCraft.Upgrades.turtleSpeaker );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,10 +44,12 @@ import dan200.computercraft.shared.peripheral.modem.TileWirelessModem;
|
|||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
|
||||||
|
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
|
||||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
|
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||||
|
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||||
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
|
import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||||
@ -306,6 +308,15 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
'Y', Items.REDSTONE
|
'Y', Items.REDSTONE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Speaker
|
||||||
|
ItemStack speaker = PeripheralItemFactory.create( PeripheralType.Speaker, null, 1);
|
||||||
|
GameRegistry.addRecipe( speaker,
|
||||||
|
"XXX", "XYX", "XZX",
|
||||||
|
'X', Blocks.STONE,
|
||||||
|
'Y', Blocks.NOTEBLOCK,
|
||||||
|
'Z', Items.REDSTONE
|
||||||
|
);
|
||||||
|
|
||||||
// Wireless Modem
|
// Wireless Modem
|
||||||
ItemStack wirelessModem = PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 );
|
ItemStack wirelessModem = PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 );
|
||||||
GameRegistry.addRecipe( wirelessModem,
|
GameRegistry.addRecipe( wirelessModem,
|
||||||
@ -441,6 +452,9 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
ComputerCraft.PocketUpgrades.advancedModem = new PocketModem( true );
|
ComputerCraft.PocketUpgrades.advancedModem = new PocketModem( true );
|
||||||
ComputerCraftAPI.registerPocketUpgrade( ComputerCraft.PocketUpgrades.advancedModem );
|
ComputerCraftAPI.registerPocketUpgrade( ComputerCraft.PocketUpgrades.advancedModem );
|
||||||
|
|
||||||
|
ComputerCraft.PocketUpgrades.pocketSpeaker = new PocketSpeaker();
|
||||||
|
ComputerCraftAPI.registerPocketUpgrade( ComputerCraft.PocketUpgrades.pocketSpeaker );
|
||||||
|
|
||||||
// Wireless Pocket Computer
|
// Wireless Pocket Computer
|
||||||
GameRegistry.addRecipe( new PocketComputerUpgradeRecipe() );
|
GameRegistry.addRecipe( new PocketComputerUpgradeRecipe() );
|
||||||
|
|
||||||
@ -547,6 +561,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
registerTileEntity( TileCable.class, "wiredmodem" );
|
registerTileEntity( TileCable.class, "wiredmodem" );
|
||||||
registerTileEntity( TileCommandComputer.class, "command_computer" );
|
registerTileEntity( TileCommandComputer.class, "command_computer" );
|
||||||
registerTileEntity( TileAdvancedModem.class, "advanced_modem" );
|
registerTileEntity( TileAdvancedModem.class, "advanced_modem" );
|
||||||
|
registerTileEntity( TileSpeaker.class, "speaker" );
|
||||||
|
|
||||||
// Register peripheral providers
|
// Register peripheral providers
|
||||||
ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() );
|
ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() );
|
||||||
|
@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package dan200.computercraft.shared.turtle.upgrades;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.turtle.*;
|
||||||
|
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||||
|
import dan200.computercraft.shared.peripheral.common.PeripheralItemFactory;
|
||||||
|
import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.vecmath.Matrix4f;
|
||||||
|
|
||||||
|
public class TurtleSpeaker implements ITurtleUpgrade
|
||||||
|
{
|
||||||
|
private static class Peripheral extends SpeakerPeripheral
|
||||||
|
{
|
||||||
|
// Members
|
||||||
|
ITurtleAccess m_turtle;
|
||||||
|
|
||||||
|
public Peripheral(ITurtleAccess turtle)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
m_turtle = turtle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
super.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getWorld()
|
||||||
|
{
|
||||||
|
return m_turtle.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockPos getPos()
|
||||||
|
{
|
||||||
|
return m_turtle.getPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(IPeripheral other)
|
||||||
|
{
|
||||||
|
if (other instanceof Peripheral)
|
||||||
|
{
|
||||||
|
Peripheral otherPeripheral = (Peripheral) other;
|
||||||
|
return otherPeripheral.m_turtle == m_turtle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Members
|
||||||
|
private ResourceLocation m_id;
|
||||||
|
private int m_legacyID;
|
||||||
|
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
private ModelResourceLocation m_leftModel;
|
||||||
|
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
private ModelResourceLocation m_rightModel;
|
||||||
|
|
||||||
|
public TurtleSpeaker(ResourceLocation id, int legacyId)
|
||||||
|
{
|
||||||
|
m_id = id;
|
||||||
|
m_legacyID = legacyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getUpgradeID()
|
||||||
|
{
|
||||||
|
return m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLegacyUpgradeID()
|
||||||
|
{
|
||||||
|
return m_legacyID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getUnlocalisedAdjective()
|
||||||
|
{
|
||||||
|
return "upgrade.computercraft:speaker.adjective";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public TurtleUpgradeType getType()
|
||||||
|
{
|
||||||
|
return TurtleUpgradeType.Peripheral;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getCraftingItem()
|
||||||
|
{
|
||||||
|
return PeripheralItemFactory.create( PeripheralType.Speaker, null, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||||
|
{
|
||||||
|
return new TurtleSpeaker.Peripheral(turtle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public TurtleCommandResult useTool(@Nonnull ITurtleAccess turtleAccess, @Nonnull TurtleSide turtleSide, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction)
|
||||||
|
{
|
||||||
|
return TurtleCommandResult.failure();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
private void loadModelLocations()
|
||||||
|
{
|
||||||
|
if( m_leftModel == null )
|
||||||
|
{
|
||||||
|
m_leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
|
||||||
|
m_rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
@SideOnly( Side.CLIENT )
|
||||||
|
public Pair<IBakedModel, Matrix4f> getModel(ITurtleAccess turtle, @Nonnull TurtleSide side ) {
|
||||||
|
|
||||||
|
loadModelLocations();
|
||||||
|
ModelManager modelManager = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager();
|
||||||
|
|
||||||
|
if (side == TurtleSide.Left)
|
||||||
|
{
|
||||||
|
return Pair.of(modelManager.getModel( m_leftModel ), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Pair.of(modelManager.getModel( m_rightModel ), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(@Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide)
|
||||||
|
{
|
||||||
|
IPeripheral turtlePeripheral = turtle.getPeripheral(turtleSide);
|
||||||
|
|
||||||
|
if (turtlePeripheral instanceof Peripheral)
|
||||||
|
{
|
||||||
|
Peripheral peripheral = (Peripheral) turtlePeripheral;
|
||||||
|
peripheral.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,6 +13,11 @@
|
|||||||
"facing=west,variant=disk_drive_invalid": { "model": "computercraft:disk_drive_invalid", "y": 270 },
|
"facing=west,variant=disk_drive_invalid": { "model": "computercraft:disk_drive_invalid", "y": 270 },
|
||||||
"facing=east,variant=disk_drive_invalid": { "model": "computercraft:disk_drive_invalid", "y": 90 },
|
"facing=east,variant=disk_drive_invalid": { "model": "computercraft:disk_drive_invalid", "y": 90 },
|
||||||
|
|
||||||
|
"facing=north,variant=speaker": { "model": "computercraft:speaker" },
|
||||||
|
"facing=south,variant=speaker": { "model": "computercraft:speaker", "y": 180 },
|
||||||
|
"facing=west,variant=speaker": { "model": "computercraft:speaker", "y": 270 },
|
||||||
|
"facing=east,variant=speaker": { "model": "computercraft:speaker", "y": 90 },
|
||||||
|
|
||||||
"facing=north,variant=printer_empty": { "model": "computercraft:printer_empty" },
|
"facing=north,variant=printer_empty": { "model": "computercraft:printer_empty" },
|
||||||
"facing=south,variant=printer_empty": { "model": "computercraft:printer_empty", "y": 180 },
|
"facing=south,variant=printer_empty": { "model": "computercraft:printer_empty", "y": 180 },
|
||||||
"facing=west,variant=printer_empty": { "model": "computercraft:printer_empty", "y": 270 },
|
"facing=west,variant=printer_empty": { "model": "computercraft:printer_empty", "y": 270 },
|
||||||
|
@ -9,6 +9,7 @@ tile.computercraft:wired_modem.name=Wired Modem
|
|||||||
tile.computercraft:cable.name=Networking Cable
|
tile.computercraft:cable.name=Networking Cable
|
||||||
tile.computercraft:command_computer.name=Command Computer
|
tile.computercraft:command_computer.name=Command Computer
|
||||||
tile.computercraft:advanced_modem.name=Ender Modem
|
tile.computercraft:advanced_modem.name=Ender Modem
|
||||||
|
tile.computercraft:speaker.name=Speaker
|
||||||
|
|
||||||
tile.computercraft:turtle.name=Turtle
|
tile.computercraft:turtle.name=Turtle
|
||||||
tile.computercraft:turtle.upgraded.name=%s Turtle
|
tile.computercraft:turtle.upgraded.name=%s Turtle
|
||||||
@ -36,6 +37,7 @@ upgrade.minecraft:diamond_hoe.adjective=Farming
|
|||||||
upgrade.computercraft:wireless_modem.adjective=Wireless
|
upgrade.computercraft:wireless_modem.adjective=Wireless
|
||||||
upgrade.minecraft:crafting_table.adjective=Crafty
|
upgrade.minecraft:crafting_table.adjective=Crafty
|
||||||
upgrade.computercraft:advanced_modem.adjective=Ender
|
upgrade.computercraft:advanced_modem.adjective=Ender
|
||||||
|
upgrade.computercraft:speaker.adjective=Noisy
|
||||||
|
|
||||||
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
|
gui.computercraft:wired_modem.peripheral_connected=Peripheral "%s" connected to network
|
||||||
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
|
gui.computercraft:wired_modem.peripheral_disconnected=Peripheral "%s" disconnected from network
|
||||||
@ -58,3 +60,4 @@ gui.computercraft:config.advanced_turtle_fuel_limit=Advanced Turtle fuel limit
|
|||||||
gui.computercraft:config.turtles_obey_block_protection=Turtles obey block protection
|
gui.computercraft:config.turtles_obey_block_protection=Turtles obey block protection
|
||||||
gui.computercraft:config.turtles_can_push=Turtles can push entities
|
gui.computercraft:config.turtles_can_push=Turtles can push entities
|
||||||
gui.computercraft:config.maximum_files_open=Maximum files open per computer
|
gui.computercraft:config.maximum_files_open=Maximum files open per computer
|
||||||
|
gui.computercraft:config.max_notes_per_tick=Maximum notes that a computer can play at once
|
||||||
|
@ -30,6 +30,7 @@ New Features in ComputerCraft 1.80:
|
|||||||
* Turtles now use tinting
|
* Turtles now use tinting
|
||||||
* shell.resolveProgram now picks up on *.lua files
|
* shell.resolveProgram now picks up on *.lua files
|
||||||
* Fixed a handful of bugs in ComputerCraft
|
* Fixed a handful of bugs in ComputerCraft
|
||||||
|
* Added speaker block, turtle upgrade, pocket upgrade, and peripheral api
|
||||||
|
|
||||||
New Features in ComputerCraft 1.79:
|
New Features in ComputerCraft 1.79:
|
||||||
|
|
||||||
|
@ -30,5 +30,6 @@ New Features in ComputerCraft 1.80:
|
|||||||
* Turtles now use tinting
|
* Turtles now use tinting
|
||||||
* shell.resolveProgram now picks up on *.lua files
|
* shell.resolveProgram now picks up on *.lua files
|
||||||
* Fixed a handful of bugs in ComputerCraft
|
* Fixed a handful of bugs in ComputerCraft
|
||||||
|
* Added speaker block, turtle upgrade, pocket upgrade, and peripheral api
|
||||||
|
|
||||||
Type "help changelog" to see the full version history.
|
Type "help changelog" to see the full version history.
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"parent": "block/orientable",
|
||||||
|
"textures": {
|
||||||
|
"front": "computercraft:blocks/speaker_front",
|
||||||
|
"side": "computercraft:blocks/speaker_side",
|
||||||
|
"top": "computercraft:blocks/speaker_top"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "computercraft:block/turtle_upgrade_base_left",
|
||||||
|
"textures": {
|
||||||
|
"texture": "computercraft:blocks/turtle_speaker_face"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "computercraft:block/turtle_upgrade_base_right",
|
||||||
|
"textures": {
|
||||||
|
"texture": "computercraft:blocks/turtle_speaker_face"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"parent": "computercraft:block/speaker"
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 493 B |
Binary file not shown.
After Width: | Height: | Size: 327 B |
Binary file not shown.
After Width: | Height: | Size: 290 B |
Binary file not shown.
After Width: | Height: | Size: 452 B |
Loading…
x
Reference in New Issue
Block a user