2017-05-10 14:46:18 +00:00
|
|
|
/*
|
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2021-01-06 17:13:40 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
2017-05-10 14:46:18 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
package dan200.computercraft.shared.turtle.upgrades;
|
|
|
|
|
2020-01-22 11:14:30 +00:00
|
|
|
import dan200.computercraft.api.client.TransformedModel;
|
2017-05-10 14:46:18 +00:00
|
|
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
2020-01-28 22:23:43 +00:00
|
|
|
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
|
2018-12-17 21:33:49 +00:00
|
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
|
|
import dan200.computercraft.api.turtle.TurtleSide;
|
|
|
|
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
2020-06-27 09:23:45 +00:00
|
|
|
import dan200.computercraft.shared.Registry;
|
2021-06-18 21:23:04 +00:00
|
|
|
import dan200.computercraft.shared.peripheral.speaker.UpgradeSpeakerPeripheral;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
2017-05-10 14:46:18 +00:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-01-12 15:42:50 +00:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2017-05-10 14:46:18 +00:00
|
|
|
import net.minecraft.world.World;
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-12-17 21:33:49 +00:00
|
|
|
|
2017-05-10 14:46:18 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2018-12-26 09:01:03 +00:00
|
|
|
public class TurtleSpeaker extends AbstractTurtleUpgrade
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
|
|
|
|
private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
|
|
|
|
|
2021-06-18 21:23:04 +00:00
|
|
|
private static class Peripheral extends UpgradeSpeakerPeripheral
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2018-12-26 09:01:03 +00:00
|
|
|
ITurtleAccess turtle;
|
2017-05-10 14:46:18 +00:00
|
|
|
|
2018-12-26 09:01:03 +00:00
|
|
|
Peripheral( ITurtleAccess turtle )
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2018-12-26 09:01:03 +00:00
|
|
|
this.turtle = turtle;
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World getWorld()
|
|
|
|
{
|
2018-12-26 09:01:03 +00:00
|
|
|
return turtle.getWorld();
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-01-20 16:16:02 +00:00
|
|
|
public Vec3d getPosition()
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2019-01-12 15:42:50 +00:00
|
|
|
BlockPos pos = turtle.getPosition();
|
|
|
|
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-17 21:33:49 +00:00
|
|
|
public boolean equals( IPeripheral other )
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2019-01-12 15:42:50 +00:00
|
|
|
return this == other || (other instanceof Peripheral && turtle == ((Peripheral) other).turtle);
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
public TurtleSpeaker( ResourceLocation id )
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2020-06-27 09:23:45 +00:00
|
|
|
super( id, TurtleUpgradeType.PERIPHERAL, Registry.ModBlocks.SPEAKER );
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IPeripheral createPeripheral( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
|
|
|
{
|
2018-12-17 21:33:49 +00:00
|
|
|
return new TurtleSpeaker.Peripheral( turtle );
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.
Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:
- Flatten everything. For instance, there are now three instances of
BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
more BlockPeripheral (thank heavens) - there's separate block classes
for each peripheral type.
- Remove pretty much all legacy code. As we're breaking world
compatibility anyway, we can remove all the code to load worlds from
1.4 days.
- The command system is largely rewriten to take advantage of 1.13's
new system. It's very fancy!
- WidgetTerminal now uses Minecraft's "GUI listener" system.
- BREAKING CHANGE: All the codes in keys.lua are different, due to the
move to LWJGL 3. Hopefully this won't have too much of an impact.
I don't want to map to the old key codes on the Java side, as there
always ends up being small but slight inconsistencies. IMO it's
better to make a clean break - people should be using keys rather
than hard coding the constants anyway.
- commands.list now allows fetching sub-commands. The ROM has already
been updated to allow fancy usage such as commands.time.set("noon").
- Turtles, modems and cables can be waterlogged.
2019-04-02 12:27:27 +00:00
|
|
|
@OnlyIn( Dist.CLIENT )
|
2020-01-22 11:14:30 +00:00
|
|
|
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
|
2017-05-19 18:25:08 +00:00
|
|
|
{
|
2021-01-15 16:35:49 +00:00
|
|
|
return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel );
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-19 18:25:08 +00:00
|
|
|
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide )
|
2017-05-10 14:46:18 +00:00
|
|
|
{
|
2017-05-19 18:25:08 +00:00
|
|
|
IPeripheral turtlePeripheral = turtle.getPeripheral( turtleSide );
|
2021-01-15 16:35:49 +00:00
|
|
|
if( turtlePeripheral instanceof Peripheral ) ((Peripheral) turtlePeripheral).update();
|
2017-05-10 14:46:18 +00:00
|
|
|
}
|
|
|
|
}
|