mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 17:03:00 +00:00
Merge pull request #316 from SquidDev-CC/feature/minecraft-1.12.2
Update to 1.12. Bam!
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.apis;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
@@ -21,6 +20,7 @@ import net.minecraft.item.ItemStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
||||
|
||||
@@ -149,7 +149,7 @@ public class TurtleAPI implements ILuaAPI
|
||||
String side = optString( arguments, index, null );
|
||||
if( side == null )
|
||||
{
|
||||
return Optional.absent();
|
||||
return Optional.empty();
|
||||
}
|
||||
else if( side.equalsIgnoreCase( "left" ) )
|
||||
{
|
||||
@@ -435,7 +435,7 @@ public class TurtleAPI implements ILuaAPI
|
||||
int damage = stack.getItemDamage();
|
||||
int count = stack.getCount();
|
||||
|
||||
Map<Object, Object> table = new HashMap<Object, Object>();
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
table.put( "name", name );
|
||||
table.put( "damage", damage );
|
||||
table.put( "count", count );
|
||||
|
||||
@@ -156,7 +156,7 @@ public class TileTurtle extends TileComputerBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDroppedItems( @Nonnull List<ItemStack> drops, boolean creative )
|
||||
public void getDroppedItems( @Nonnull NonNullList<ItemStack> drops, boolean creative )
|
||||
{
|
||||
IComputer computer = getComputer();
|
||||
if( !creative || (computer != null && computer.getLabel() != null) )
|
||||
@@ -258,8 +258,8 @@ public class TileTurtle extends TileComputerBase
|
||||
{
|
||||
Vec3d offset = getRenderOffset( 1.0f );
|
||||
return new AxisAlignedBB(
|
||||
offset.xCoord + 0.125, offset.yCoord + 0.125, offset.zCoord + 0.125,
|
||||
offset.xCoord + 0.875, offset.yCoord + 0.875, offset.zCoord + 0.875
|
||||
offset.x + 0.125, offset.y + 0.125, offset.z + 0.125,
|
||||
offset.x + 0.875, offset.y + 0.875, offset.z + 0.875
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.core;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TurtleAttackCommand extends TurtleToolCommand
|
||||
{
|
||||
public TurtleAttackCommand( InteractDirection direction, Optional<TurtleSide> side )
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.*;
|
||||
public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
private static int s_nextInstanceID = 0;
|
||||
private static Map<Integer, WeakReference<TurtleBrain>> s_allClientBrains = new HashMap<Integer, WeakReference<TurtleBrain>>();
|
||||
private static Map<Integer, WeakReference<TurtleBrain>> s_allClientBrains = new HashMap<>();
|
||||
|
||||
public static int assignInstanceID()
|
||||
{
|
||||
@@ -75,7 +75,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
if( getClientBrain( instanceID ) != brain )
|
||||
{
|
||||
s_allClientBrains.put( instanceID, new WeakReference<TurtleBrain>( brain ) );
|
||||
s_allClientBrains.put( instanceID, new WeakReference<>( brain ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,12 +127,12 @@ public class TurtleBrain implements ITurtleAccess
|
||||
{
|
||||
m_owner = turtle;
|
||||
|
||||
m_commandQueue = new LinkedList<TurtleCommandQueueEntry>();
|
||||
m_commandQueue = new LinkedList<>();
|
||||
m_commandsIssued = 0;
|
||||
|
||||
m_upgrades = new HashMap<TurtleSide, ITurtleUpgrade>();
|
||||
m_peripherals = new HashMap<TurtleSide, IPeripheral>();
|
||||
m_upgradeNBTData = new HashMap<TurtleSide, NBTTagCompound>();
|
||||
m_upgrades = new HashMap<>();
|
||||
m_peripherals = new HashMap<>();
|
||||
m_upgradeNBTData = new HashMap<>();
|
||||
|
||||
m_selectedSlot = 0;
|
||||
m_fuelLevel = 0;
|
||||
@@ -553,9 +553,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
Vec3d offset = getRenderOffset( f );
|
||||
BlockPos pos = m_owner.getPos();
|
||||
return new Vec3d(
|
||||
pos.getX() + 0.5 + offset.xCoord,
|
||||
pos.getY() + 0.5 + offset.yCoord,
|
||||
pos.getZ() + 0.5 + offset.zCoord
|
||||
pos.getX() + 0.5 + offset.x,
|
||||
pos.getY() + 0.5 + offset.y,
|
||||
pos.getZ() + 0.5 + offset.z
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1177,9 +1177,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
Vec3d position = getVisualPosition( 1.0f );
|
||||
if( position != null )
|
||||
{
|
||||
double x = position.xCoord + world.rand.nextGaussian() * 0.1;
|
||||
double y = position.yCoord + 0.5 + world.rand.nextGaussian() * 0.1;
|
||||
double z = position.zCoord + world.rand.nextGaussian() * 0.1;
|
||||
double x = position.x + world.rand.nextGaussian() * 0.1;
|
||||
double y = position.y + 0.5 + world.rand.nextGaussian() * 0.1;
|
||||
double z = position.z + world.rand.nextGaussian() * 0.1;
|
||||
world.spawnParticle(
|
||||
EnumParticleTypes.HEART, x, y, z,
|
||||
world.rand.nextGaussian() * 0.02,
|
||||
|
||||
@@ -15,13 +15,13 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class TurtleCompareCommand implements ITurtleCommand
|
||||
{
|
||||
@@ -77,8 +77,9 @@ public class TurtleCompareCommand implements ITurtleCommand
|
||||
// (try 5 times to try and beat random number generators)
|
||||
for( int i=0; (i<5) && lookAtStack.isEmpty(); ++i )
|
||||
{
|
||||
List<ItemStack> drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 );
|
||||
if( drops != null && drops.size() > 0 )
|
||||
NonNullList<ItemStack> drops = NonNullList.create();
|
||||
lookAtBlock.getDrops( drops, world, newPosition, lookAtState, 0 );
|
||||
if( drops.size() > 0 )
|
||||
{
|
||||
for( ItemStack drop : drops )
|
||||
{
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.core;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TurtleDigCommand extends TurtleToolCommand
|
||||
{
|
||||
public TurtleDigCommand( InteractDirection direction, Optional<TurtleSide> side )
|
||||
|
||||
@@ -53,11 +53,11 @@ public class TurtleInspectCommand implements ITurtleCommand
|
||||
String name = Block.REGISTRY.getNameForObject( block ).toString();
|
||||
int metadata = block.getMetaFromState( state );
|
||||
|
||||
Map<Object, Object> table = new HashMap<Object, Object>();
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
table.put( "name", name );
|
||||
table.put( "metadata", metadata );
|
||||
|
||||
Map<Object, Object> stateTable = new HashMap<Object, Object>();
|
||||
Map<Object, Object> stateTable = new HashMap<>();
|
||||
for( ImmutableMap.Entry<IProperty<?>, ?> entry : state.getActualState( world, newPosition ).getProperties().entrySet() )
|
||||
{
|
||||
String propertyName = entry.getKey().getName();
|
||||
@@ -79,10 +79,10 @@ public class TurtleInspectCommand implements ITurtleCommand
|
||||
|
||||
if( !FAIL_ON_AIR )
|
||||
{
|
||||
Map<Object, Object> table = new HashMap<Object, Object>();
|
||||
Map<Object, Object> table = new HashMap<>();
|
||||
table.put( "name", "minecraft:air" );
|
||||
table.put( "metadata", 0 );
|
||||
table.put( "state", new HashMap<Object, Object>() );
|
||||
table.put( "state", new HashMap<>() );
|
||||
return TurtleCommandResult.success( new Object[]{ table } );
|
||||
}
|
||||
return TurtleCommandResult.failure( "No block to inspect" );
|
||||
|
||||
@@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.ITurtleCommand;
|
||||
import dan200.computercraft.api.turtle.TurtleAnimation;
|
||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import dan200.computercraft.shared.util.IEntityDropConsumer;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -225,22 +224,18 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
// Start claiming entity drops
|
||||
Entity hitEntity = hit.getKey();
|
||||
Vec3d hitPos = hit.getValue();
|
||||
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
|
||||
ComputerCraft.setEntityDropConsumer( hitEntity, ( entity, drop ) ->
|
||||
{
|
||||
@Override
|
||||
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
} );
|
||||
|
||||
// Place on the entity
|
||||
boolean placed = false;
|
||||
EnumActionResult cancelResult = ForgeHooks.onInteractEntityAtAction( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND );
|
||||
EnumActionResult cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND );
|
||||
if( cancelResult == null )
|
||||
{
|
||||
cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, EnumHand.MAIN_HAND );
|
||||
@@ -253,7 +248,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
else
|
||||
{
|
||||
// See EntityPlayer.interactOn
|
||||
cancelResult = ForgeHooks.onInteractEntityAction( turtlePlayer, hitEntity, EnumHand.MAIN_HAND );
|
||||
cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, EnumHand.MAIN_HAND );
|
||||
if( cancelResult == EnumActionResult.SUCCESS )
|
||||
{
|
||||
placed = true;
|
||||
@@ -391,7 +386,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
|
||||
if( !placed && (item instanceof ItemBucket || item instanceof ItemBoat || item instanceof ItemLilyPad || item instanceof ItemGlassBottle) )
|
||||
{
|
||||
EnumActionResult actionResult = ForgeHooks.onItemRightClickAction( turtlePlayer, EnumHand.MAIN_HAND );
|
||||
EnumActionResult actionResult = ForgeHooks.onItemRightClick( turtlePlayer, EnumHand.MAIN_HAND );
|
||||
if( actionResult == EnumActionResult.SUCCESS )
|
||||
{
|
||||
placed = true;
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TurtleSuckCommand implements ITurtleCommand
|
||||
// Suck up the item
|
||||
foundItems = true;
|
||||
EntityItem entityItem = (EntityItem) entity;
|
||||
ItemStack stack = entityItem.getEntityItem().copy();
|
||||
ItemStack stack = entityItem.getItem().copy();
|
||||
ItemStack storeStack;
|
||||
ItemStack leaveStack;
|
||||
if( stack.getCount() > m_quantity )
|
||||
@@ -125,16 +125,16 @@ public class TurtleSuckCommand implements ITurtleCommand
|
||||
}
|
||||
else if( remainder.isEmpty() )
|
||||
{
|
||||
entityItem.setEntityItemStack( leaveStack );
|
||||
entityItem.setItem( leaveStack );
|
||||
}
|
||||
else if( leaveStack.isEmpty() )
|
||||
{
|
||||
entityItem.setEntityItemStack( remainder );
|
||||
entityItem.setItem( remainder );
|
||||
}
|
||||
else
|
||||
{
|
||||
leaveStack.grow( remainder.getCount() );
|
||||
entityItem.setEntityItemStack( leaveStack );
|
||||
entityItem.setItem( leaveStack );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.core;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import dan200.computercraft.api.turtle.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TurtleToolCommand implements ITurtleCommand
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TurtleVisionCamera extends EntityLivingBase
|
||||
{
|
||||
super( world );
|
||||
m_turtle = turtle;
|
||||
m_armor = new ArrayList<ItemStack>();
|
||||
m_armor = new ArrayList<>();
|
||||
applyPos();
|
||||
}
|
||||
|
||||
@@ -60,17 +60,17 @@ public class TurtleVisionCamera extends EntityLivingBase
|
||||
private void applyPos()
|
||||
{
|
||||
Vec3d prevPos = m_turtle.getVisualPosition( 0.0f );
|
||||
this.lastTickPosX = this.prevPosX = prevPos.xCoord;
|
||||
this.lastTickPosY = this.prevPosY = prevPos.yCoord;
|
||||
this.lastTickPosZ = this.prevPosZ = prevPos.zCoord;
|
||||
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.xCoord;
|
||||
this.posY = pos.yCoord;
|
||||
this.posZ = pos.zCoord;
|
||||
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;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ContainerTurtle extends Container
|
||||
private void sendStateToPlayer( IContainerListener icrafting )
|
||||
{
|
||||
int selectedSlot = m_turtle.getSelectedSlot();
|
||||
icrafting.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
|
||||
icrafting.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +112,7 @@ public class ContainerTurtle extends Container
|
||||
{
|
||||
if( m_selectedSlot != selectedSlot )
|
||||
{
|
||||
listener.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
|
||||
listener.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot );
|
||||
}
|
||||
}
|
||||
m_selectedSlot = selectedSlot;
|
||||
|
||||
@@ -20,5 +20,6 @@ public interface ITurtleItem extends IComputerItem, IColouredItem
|
||||
ITurtleUpgrade getUpgrade( ItemStack stack, TurtleSide side );
|
||||
int getFuelLevel( ItemStack stack );
|
||||
ResourceLocation getOverlay( ItemStack stack );
|
||||
@Override
|
||||
int getColour( @Nonnull ItemStack stack );
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@@ -42,8 +41,9 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
|
||||
public abstract ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay );
|
||||
|
||||
@Override
|
||||
public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
|
||||
public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList<ItemStack> list )
|
||||
{
|
||||
if( !isInCreativeTab( tabs ) ) return;
|
||||
NonNullList<ItemStack> all = NonNullList.create();
|
||||
ComputerCraft.addAllUpgradedTurtles( all );
|
||||
for( ItemStack stack : all )
|
||||
|
||||
@@ -6,43 +6,38 @@
|
||||
|
||||
package dan200.computercraft.shared.turtle.recipes;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.items.IComputerItem;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.util.RecipeUtil;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.IRecipeFactory;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleRecipe implements IRecipe
|
||||
public class TurtleRecipe extends ShapedRecipes
|
||||
{
|
||||
private final Item[] m_recipe;
|
||||
private final NonNullList<Ingredient> m_recipe;
|
||||
private final ComputerFamily m_family;
|
||||
|
||||
public TurtleRecipe( Item[] recipe, ComputerFamily family )
|
||||
|
||||
public TurtleRecipe( String group, int width, int height, NonNullList<Ingredient> recipe, ComputerFamily family )
|
||||
{
|
||||
super( group, width, height, recipe, TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null ) );
|
||||
m_recipe = recipe;
|
||||
m_family = family;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize()
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput()
|
||||
{
|
||||
return TurtleItemFactory.create( -1, null, -1, m_family, null, null, 0, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world )
|
||||
{
|
||||
@@ -56,34 +51,28 @@ public class TurtleRecipe implements IRecipe
|
||||
// See if we match the recipe, and extract the input computercraft ID
|
||||
int computerID = -1;
|
||||
String label = null;
|
||||
for( int y=0; y<3; ++y )
|
||||
for( int y = 0; y < 3; ++y )
|
||||
{
|
||||
for( int x=0; x<3; ++x )
|
||||
for( int x = 0; x < 3; ++x )
|
||||
{
|
||||
ItemStack item = inventory.getStackInRowAndColumn(x, y);
|
||||
if( !item.isEmpty() && item.getItem() == m_recipe[ x + y*3 ] )
|
||||
ItemStack item = inventory.getStackInRowAndColumn( x, y );
|
||||
Ingredient target = m_recipe.get( x + y * 3 );
|
||||
|
||||
if( item.getItem() instanceof IComputerItem )
|
||||
{
|
||||
if( item.getItem() instanceof IComputerItem )
|
||||
{
|
||||
IComputerItem itemComputer = (IComputerItem)item.getItem();
|
||||
if( m_family == ComputerFamily.Beginners || itemComputer.getFamily( item ) == m_family )
|
||||
{
|
||||
computerID = itemComputer.getComputerID( item );
|
||||
label = itemComputer.getLabel( item );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
IComputerItem itemComputer = (IComputerItem) item.getItem();
|
||||
if( itemComputer.getFamily( item ) != m_family ) return ItemStack.EMPTY;
|
||||
|
||||
computerID = itemComputer.getComputerID( item );
|
||||
label = itemComputer.getLabel( item );
|
||||
}
|
||||
else
|
||||
else if( !target.apply( item ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Build a turtle with the same ID the computer had
|
||||
// Construct the new stack
|
||||
if( m_family != ComputerFamily.Beginners )
|
||||
@@ -96,16 +85,26 @@ public class TurtleRecipe implements IRecipe
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting )
|
||||
public static class Factory implements IRecipeFactory
|
||||
{
|
||||
NonNullList<ItemStack> results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY );
|
||||
for( int i = 0; i < results.size(); ++i )
|
||||
@Override
|
||||
public IRecipe parse( JsonContext context, JsonObject json )
|
||||
{
|
||||
ItemStack stack = inventoryCrafting.getStackInSlot( i );
|
||||
results.set( i, ForgeHooks.getContainerItem( stack ) );
|
||||
String group = JsonUtils.getString( json, "group", "" );
|
||||
|
||||
String familyName = JsonUtils.getString( json, "family" );
|
||||
ComputerFamily family;
|
||||
try
|
||||
{
|
||||
family = ComputerFamily.valueOf( familyName );
|
||||
}
|
||||
catch( IllegalArgumentException e )
|
||||
{
|
||||
throw new JsonSyntaxException( "Unknown computer family '" + familyName + "'" );
|
||||
}
|
||||
|
||||
CraftingHelper.ShapedPrimer primer = RecipeUtil.getPrimer( context, json );
|
||||
return new TurtleRecipe( group, primer.width, primer.height, primer.input, family );
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.proxy.CCTurtleProxyCommon;
|
||||
import dan200.computercraft.shared.turtle.items.ITurtleItem;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
@@ -21,19 +20,26 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TurtleUpgradeRecipe implements IRecipe
|
||||
public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
|
||||
{
|
||||
public TurtleUpgradeRecipe()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize()
|
||||
public boolean canFit( int x, int y )
|
||||
{
|
||||
return 3;
|
||||
return x >= 3 && y >= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -72,16 +72,6 @@ public class CraftingTablePeripheral
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attach( @Nonnull IComputerAccess computer )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach( @Nonnull IComputerAccess computer )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( IPeripheral other )
|
||||
|
||||
@@ -118,9 +118,4 @@ public class TurtleCraftingTable implements ITurtleUpgrade
|
||||
return Pair.of( modelManager.getModel( m_rightModel ), transform );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
|
||||
}
|
||||
|
||||
// Check the actual crafting
|
||||
return CraftingManager.getInstance().findMatchingRecipe( this, m_turtle.getWorld() );
|
||||
return CraftingManager.findMatchingResult( this, m_turtle.getWorld() );
|
||||
}
|
||||
|
||||
public ArrayList<ItemStack> doCrafting( World world, int maxCount )
|
||||
@@ -88,7 +88,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
|
||||
if( !result.isEmpty() )
|
||||
{
|
||||
// Special case: craft(0) just returns an empty list if crafting was possible
|
||||
ArrayList<ItemStack> results = new ArrayList<ItemStack>();
|
||||
ArrayList<ItemStack> results = new ArrayList<>();
|
||||
if( maxCount == 0 )
|
||||
{
|
||||
return results;
|
||||
@@ -123,7 +123,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting
|
||||
results.add( result );
|
||||
|
||||
// Consume resources from the inventory
|
||||
NonNullList<ItemStack> remainingItems = CraftingManager.getInstance().getRemainingItems( this, world );
|
||||
NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems( this, world );
|
||||
for( int n=0; n<size; ++n )
|
||||
{
|
||||
ItemStack stack = getStackInSlot( n );
|
||||
|
||||
@@ -12,7 +12,6 @@ import dan200.computercraft.api.turtle.*;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||
import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand;
|
||||
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
|
||||
import dan200.computercraft.shared.util.IEntityDropConsumer;
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -28,6 +27,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
@@ -120,11 +120,6 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
|
||||
@@ -185,16 +180,12 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
|
||||
// Start claiming entity drops
|
||||
Entity hitEntity = hit.getKey();
|
||||
ComputerCraft.setEntityDropConsumer( hitEntity, new IEntityDropConsumer()
|
||||
ComputerCraft.setEntityDropConsumer( hitEntity, ( entity, drop ) ->
|
||||
{
|
||||
@Override
|
||||
public void consumeDrop( Entity entity, @Nonnull ItemStack drop )
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
} );
|
||||
|
||||
@@ -315,7 +306,8 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
{
|
||||
IBlockState state = world.getBlockState( pos );
|
||||
Block block = state.getBlock();
|
||||
List<ItemStack> drops = block.getDrops( world, pos, world.getBlockState( pos ), 0 );
|
||||
NonNullList<ItemStack> drops = NonNullList.create();
|
||||
block.getDrops( drops, world, pos, world.getBlockState( pos ), 0 );
|
||||
double chance = ForgeEventFactory.fireBlockHarvesting( drops, world, pos, state, 0, 1, false, player );
|
||||
|
||||
for( int i = drops.size() - 1; i >= 0; i-- )
|
||||
|
||||
Reference in New Issue
Block a user