mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-06-23 13:43:22 +00:00
![SquidDev](/assets/img/avatar_default.png)
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.
216 lines
5.7 KiB
Java
216 lines
5.7 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
*/
|
|
|
|
package dan200.computercraft.shared.turtle.core;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
import dan200.computercraft.ComputerCraft;
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
import dan200.computercraft.shared.util.InventoryUtil;
|
|
import dan200.computercraft.shared.util.WorldUtil;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.IMerchant;
|
|
import net.minecraft.entity.passive.AbstractHorse;
|
|
import net.minecraft.inventory.IInventory;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.tileentity.TileEntitySign;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraft.util.EnumHand;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraft.world.IInteractionObject;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.WorldServer;
|
|
import net.minecraftforge.common.util.FakePlayer;
|
|
|
|
import javax.annotation.Nonnull;
|
|
import javax.annotation.Nullable;
|
|
import java.util.UUID;
|
|
|
|
public final class TurtlePlayer extends FakePlayer
|
|
{
|
|
public static final GameProfile DEFAULT_PROFILE = new GameProfile(
|
|
UUID.fromString( "0d0c4ca0-4ff1-11e4-916c-0800200c9a66" ),
|
|
"[ComputerCraft]"
|
|
);
|
|
|
|
public static final EntityType<TurtlePlayer> TYPE = EntityType.Builder.create( TurtlePlayer.class, TurtlePlayer::new )
|
|
.disableSerialization()
|
|
.disableSummoning()
|
|
.build( ComputerCraft.MOD_ID + ":turtle_player" );
|
|
|
|
private TurtlePlayer( World world )
|
|
{
|
|
super( (WorldServer) world, DEFAULT_PROFILE );
|
|
}
|
|
|
|
private TurtlePlayer( ITurtleAccess turtle )
|
|
{
|
|
super( (WorldServer) turtle.getWorld(), getProfile( turtle.getOwningPlayer() ) );
|
|
setState( turtle );
|
|
}
|
|
|
|
private static GameProfile getProfile( @Nullable GameProfile profile )
|
|
{
|
|
return profile != null && profile.isComplete() ? profile : DEFAULT_PROFILE;
|
|
}
|
|
|
|
private void setState( ITurtleAccess turtle )
|
|
{
|
|
BlockPos position = turtle.getPosition();
|
|
posX = position.getX() + 0.5;
|
|
posY = position.getY() + 0.5;
|
|
posZ = position.getZ() + 0.5;
|
|
|
|
rotationYaw = turtle.getDirection().getHorizontalAngle();
|
|
rotationPitch = 0.0f;
|
|
|
|
inventory.clear();
|
|
}
|
|
|
|
public static TurtlePlayer get( ITurtleAccess access )
|
|
{
|
|
if( !(access instanceof TurtleBrain) ) return new TurtlePlayer( access );
|
|
|
|
TurtleBrain brain = (TurtleBrain) access;
|
|
TurtlePlayer player = brain.m_cachedPlayer;
|
|
if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() )
|
|
|| player.getEntityWorld() != access.getWorld() )
|
|
{
|
|
player = brain.m_cachedPlayer = new TurtlePlayer( brain );
|
|
}
|
|
else
|
|
{
|
|
player.setState( access );
|
|
}
|
|
|
|
return player;
|
|
}
|
|
|
|
public void loadInventory( @Nonnull ItemStack currentStack )
|
|
{
|
|
// Load up the fake inventory
|
|
inventory.currentItem = 0;
|
|
inventory.setInventorySlotContents( 0, currentStack );
|
|
}
|
|
|
|
public ItemStack unloadInventory( ITurtleAccess turtle )
|
|
{
|
|
// Get the item we placed with
|
|
ItemStack results = inventory.getStackInSlot( 0 );
|
|
inventory.setInventorySlotContents( 0, ItemStack.EMPTY );
|
|
|
|
// Store (or drop) anything else we found
|
|
BlockPos dropPosition = turtle.getPosition();
|
|
EnumFacing dropDirection = turtle.getDirection().getOpposite();
|
|
for( int i = 0; i < inventory.getSizeInventory(); i++ )
|
|
{
|
|
ItemStack stack = inventory.getStackInSlot( i );
|
|
if( !stack.isEmpty() )
|
|
{
|
|
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
|
if( !remainder.isEmpty() )
|
|
{
|
|
WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection );
|
|
}
|
|
inventory.setInventorySlotContents( i, ItemStack.EMPTY );
|
|
}
|
|
}
|
|
inventory.markDirty();
|
|
return results;
|
|
}
|
|
|
|
@Override
|
|
public Vec3d getPositionVector()
|
|
{
|
|
return new Vec3d( posX, posY, posZ );
|
|
}
|
|
|
|
@Override
|
|
public float getEyeHeight()
|
|
{
|
|
return 0.0f;
|
|
}
|
|
|
|
@Override
|
|
public float getDefaultEyeHeight()
|
|
{
|
|
return 0.0f;
|
|
}
|
|
|
|
@Override
|
|
public void sendEnterCombat()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void sendEndCombat()
|
|
{
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public SleepResult trySleep( @Nonnull BlockPos bedLocation )
|
|
{
|
|
return SleepResult.OTHER_PROBLEM;
|
|
}
|
|
|
|
// TODO: Flesh this out. Or just stub out the connection, like plethora?
|
|
|
|
@Override
|
|
public void openSignEditor( TileEntitySign signTile )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void displayGui( IInteractionObject guiOwner )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void displayGUIChest( IInventory chestInventory )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void displayVillagerTradeGui( IMerchant villager )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void openHorseInventory( AbstractHorse horse, IInventory inventoryIn )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void openBook( ItemStack stack, @Nonnull EnumHand hand )
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public void updateHeldItem()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
protected void onItemUseFinish()
|
|
{
|
|
}
|
|
|
|
/*
|
|
@Override
|
|
public void mountEntityAndWakeUp()
|
|
{
|
|
}
|
|
*/
|
|
|
|
@Override
|
|
public void dismountEntity( @Nonnull Entity entity )
|
|
{
|
|
}
|
|
}
|