mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-13 11:40:29 +00:00
Added speaker as turtle peripheral
This commit is contained in:
parent
3bf15a3798
commit
a3b0e4e993
@ -164,6 +164,7 @@ 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
|
||||||
|
@ -13,6 +13,8 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
|||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.SoundCategory;
|
import net.minecraft.util.SoundCategory;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.util.SoundEvent;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class SpeakerPeripheral implements IPeripheral {
|
public class SpeakerPeripheral implements IPeripheral {
|
||||||
|
|
||||||
@ -20,18 +22,33 @@ public class SpeakerPeripheral implements IPeripheral {
|
|||||||
private long m_clock;
|
private long m_clock;
|
||||||
private long m_lastPlayTime;
|
private long m_lastPlayTime;
|
||||||
|
|
||||||
public SpeakerPeripheral(TileSpeaker speaker)
|
public SpeakerPeripheral()
|
||||||
{
|
{
|
||||||
m_speaker = speaker;
|
|
||||||
m_clock = 0;
|
m_clock = 0;
|
||||||
m_lastPlayTime = 0;
|
m_lastPlayTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateClock()
|
public SpeakerPeripheral(TileSpeaker speaker)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
m_speaker = speaker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateClock()
|
||||||
{
|
{
|
||||||
m_clock++;
|
m_clock++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public World getWorld()
|
||||||
|
{
|
||||||
|
return m_speaker.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos getPos()
|
||||||
|
{
|
||||||
|
return m_speaker.getPos();
|
||||||
|
}
|
||||||
|
|
||||||
/* IPeripheral implementations */
|
/* IPeripheral implementations */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -197,7 +214,7 @@ public class SpeakerPeripheral implements IPeripheral {
|
|||||||
|
|
||||||
if (SoundEvent.REGISTRY.containsKey(resourceName))
|
if (SoundEvent.REGISTRY.containsKey(resourceName))
|
||||||
{
|
{
|
||||||
m_speaker.getWorld().playSound(null, m_speaker.getPos(), new SoundEvent(resourceName), SoundCategory.RECORDS, volume, pitch);
|
getWorld().playSound(null, getPos(), new SoundEvent(resourceName), SoundCategory.RECORDS, volume, pitch);
|
||||||
m_lastPlayTime = m_clock;
|
m_lastPlayTime = m_clock;
|
||||||
return new Object[]{true}; // Success, return true
|
return new Object[]{true}; // Success, return true
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,17 @@
|
|||||||
|
|
||||||
package dan200.computercraft.shared.peripheral.speaker;
|
package dan200.computercraft.shared.peripheral.speaker;
|
||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
|
|
||||||
public class TileSpeaker extends TilePeripheralBase
|
public class TileSpeaker extends TilePeripheralBase
|
||||||
{
|
{
|
||||||
// Statics
|
// Statics
|
||||||
public static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
|
static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
private SpeakerPeripheral m_peripheral;
|
private SpeakerPeripheral m_peripheral; // TODO what happens when multiple computers wrap one peripheral?
|
||||||
|
|
||||||
public TileSpeaker()
|
public TileSpeaker()
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
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;
|
||||||
@ -124,7 +125,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 )
|
||||||
@ -404,8 +405,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
|
||||||
|
@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
* 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 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
|
||||||
|
ResourceLocation m_id;
|
||||||
|
int m_legacyID;
|
||||||
|
Peripheral m_peripheral;
|
||||||
|
|
||||||
|
@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 )
|
||||||
|
{
|
||||||
|
m_peripheral = new TurtleSpeaker.Peripheral( turtle );
|
||||||
|
return m_peripheral; // TODO does this go in constructor?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public TurtleCommandResult useTool(@Nonnull ITurtleAccess turtleAccess, @Nonnull TurtleSide turtleSide, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 turtleAccess, @Nonnull TurtleSide turtleSide)
|
||||||
|
{
|
||||||
|
m_peripheral.updateClock();
|
||||||
|
}
|
||||||
|
}
|
@ -37,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
|
||||||
|
Loading…
Reference in New Issue
Block a user