mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-14 12:07:10 +00:00
Initial update to 1.12
- Convert most recipes to JSON - Add JSON factories for impostor and turtle recipes. - Several mappings changes - Migrate to Forge's new registry system
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -240,7 +240,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
|
||||
// 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 +253,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 +391,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -42,8 +42,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
|
||||
|
||||
@@ -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 )
|
||||
@@ -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 );
|
||||
|
||||
@@ -28,6 +28,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;
|
||||
@@ -315,7 +316,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