mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-15 22:17:39 +00:00
Compare commits
12 Commits
v1.80pr1.7
...
v1.80pr1.8
Author | SHA1 | Date | |
---|---|---|---|
![]() |
efa57521c7 | ||
![]() |
4700f8831b | ||
![]() |
9428bee316 | ||
![]() |
89c7183a1d | ||
![]() |
d2a9e7e458 | ||
![]() |
1774f1a079 | ||
![]() |
de1307913b | ||
![]() |
093132533d | ||
![]() |
0685be6bfa | ||
![]() |
f40733e9a6 | ||
![]() |
a3d1cff298 | ||
![]() |
b8957cab5c |
16
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
16
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report some misbehaviour in the mod
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
## Before reporting
|
||||
- Search for the bug both here and [on the ComputerCraft issues page](https://github.com/dan200/ComputerCraft/issues?utf8=%E2%9C%93&q=is%3Aissue+)
|
||||
- If possible, try to reproduce on vanilla ComputerCraft. If it still occurs, [report on the ComputerCraft repo](https://github.com/dan200/ComputerCraft/issues/new) instead.
|
||||
-->
|
||||
|
||||
## Useful information to include:
|
||||
- Minecraft version
|
||||
- CC: Tweaked version
|
||||
- Detailed reproduction steps!** Sometimes I can spot a bug pretty easily, but often it's much more obscure. Anything you can give which will help reproduce it means it'll get fixed quicker.
|
15
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
15
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea or improvement
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
## Before reporting
|
||||
- Search for the suggestion both here and [on the ComputerCraft issues page](https://github.com/dan200/ComputerCraft/issues?utf8=%E2%9C%93&q=is%3Aissue+). It's possible someone's suggested it before!
|
||||
- Unless something is specific to CC:Tweaked, try to [suggest them on the ComputerCraft repo](https://github.com/dan200/ComputerCraft/issues/new). There's a lot more people watching it, so it allows the wider community to contribute.
|
||||
-->
|
||||
|
||||
## Useful information to include:
|
||||
- Explanation of how the feature/change chould work.
|
||||
- Some rationale/use case for a feature. I'd like to keep CC:T as minimal
|
9
.github/pull_request_template.md
vendored
Normal file
9
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<!--
|
||||
Unless this feature is specific to CC:Tweaked, try to [target the original ComputerCraft repo](https://github.com/dan200/ComputerCraft/) instead. There's a lot more people watching it, so it allows the wider community to contribute.
|
||||
-->
|
||||
|
||||
## Useful information to include:
|
||||
- Brief explanation of the changes you've made.
|
||||
- Rationale of why this change has been made/reasoning behind it.
|
||||
|
||||
The more information you can provide, the easier it is to review something now _and_ to see why a change was made, when the code needs updating in the future.
|
13
build.gradle
13
build.gradle
@@ -23,12 +23,12 @@ apply plugin: 'org.ajoberstar.grgit'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'maven'
|
||||
|
||||
version = "1.80pr1.7"
|
||||
version = "1.80pr1.8"
|
||||
group = "org.squiddev"
|
||||
archivesBaseName = "cc-tweaked"
|
||||
|
||||
minecraft {
|
||||
version = "1.12.2-14.23.2.2634"
|
||||
version = "1.12.2-14.23.4.2749"
|
||||
runDir = "run"
|
||||
replace '${version}', project.version
|
||||
|
||||
@@ -37,7 +37,7 @@ minecraft {
|
||||
// stable_# stables are built at the discretion of the MCP team.
|
||||
// Use non-default mappings at your own risk. they may not allways work.
|
||||
// simply re-run your setup task after changing the mappings to update your workspace.
|
||||
mappings = "snapshot_20180324"
|
||||
mappings = "snapshot_20180724"
|
||||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ repositories {
|
||||
name = "squiddev"
|
||||
url = "https://dl.bintray.com/squiddev/maven"
|
||||
}
|
||||
|
||||
ivy { artifactPattern "https://asie.pl/files/mods/Charset/LibOnly/[module]-[revision](-[classifier]).[ext]" }
|
||||
}
|
||||
|
||||
configurations {
|
||||
@@ -60,8 +62,11 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
deobfProvided "mezz.jei:jei_1.12.2:4.8.5.159:api"
|
||||
deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
||||
|
||||
runtime "mezz.jei:jei_1.12.2:4.8.5.159"
|
||||
shade 'org.squiddev:Cobalt:0.3.1'
|
||||
|
||||
shade 'org.squiddev:Cobalt:0.3.2'
|
||||
|
||||
testCompile 'junit:junit:4.11'
|
||||
|
||||
|
@@ -98,7 +98,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@@ -1125,18 +1125,18 @@ public class ComputerCraft
|
||||
turtleProxy.addAllUpgradedTurtles( list );
|
||||
}
|
||||
|
||||
public static void setDropConsumer( Entity entity, Consumer<ItemStack> consumer )
|
||||
public static void setDropConsumer( Entity entity, Function<ItemStack, ItemStack> consumer )
|
||||
{
|
||||
turtleProxy.setDropConsumer( entity, consumer );
|
||||
}
|
||||
|
||||
public static void setDropConsumer( World world, BlockPos pos, Consumer<ItemStack> consumer )
|
||||
public static void setDropConsumer( World world, BlockPos pos, Function<ItemStack, ItemStack> consumer )
|
||||
{
|
||||
turtleProxy.setDropConsumer( world, pos, consumer );
|
||||
}
|
||||
|
||||
public static void clearDropConsumer( )
|
||||
public static List<ItemStack> clearDropConsumer( )
|
||||
{
|
||||
turtleProxy.clearDropConsumer();
|
||||
return turtleProxy.clearDropConsumer();
|
||||
}
|
||||
}
|
||||
|
@@ -65,6 +65,10 @@ public class PrintoutRenderer
|
||||
|
||||
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
||||
{
|
||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.enableTexture2D();
|
||||
|
||||
FixedWidthFontRenderer fontRenderer = (FixedWidthFontRenderer) ComputerCraft.getFixedWidthFontRenderer();
|
||||
|
||||
for( int line = 0; line < LINES_PER_PAGE && line < text.length; ++line )
|
||||
@@ -76,6 +80,9 @@ public class PrintoutRenderer
|
||||
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
|
||||
{
|
||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.enableTexture2D();
|
||||
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture( BG );
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
|
@@ -71,7 +71,7 @@ public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable
|
||||
buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
||||
buffer.noColor();
|
||||
|
||||
ForgeHooksClient.setRenderLayer( block.getBlockLayer() );
|
||||
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
||||
|
||||
// See BlockRendererDispatcher#renderBlockDamage
|
||||
TextureAtlasSprite breakingTexture = mc.getTextureMapBlocks().getAtlasSprite( "minecraft:blocks/destroy_stage_" + destroyStage );
|
||||
|
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static dan200.computercraft.shared.command.framework.ChatHelpers.*;
|
||||
|
||||
@@ -147,26 +148,15 @@ public final class CommandComputerCraft extends CommandDelegate
|
||||
@Override
|
||||
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
|
||||
{
|
||||
Set<ServerComputer> computers = Sets.newHashSet();
|
||||
if( arguments.size() > 0 )
|
||||
{
|
||||
for( String arg : arguments )
|
||||
withComputers( arguments, computers -> {
|
||||
int shutdown = 0;
|
||||
for( ServerComputer computer : computers )
|
||||
{
|
||||
computers.addAll( ComputerSelector.getComputers( arg ) );
|
||||
if( computer.isOn() ) shutdown++;
|
||||
computer.unload();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
computers.addAll( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
}
|
||||
|
||||
int shutdown = 0;
|
||||
for( ServerComputer computer : computers )
|
||||
{
|
||||
if( computer.isOn() ) shutdown++;
|
||||
computer.unload();
|
||||
}
|
||||
context.getSender().sendMessage( text( "Shutdown " + shutdown + " / " + computers.size() + " computers" ) );
|
||||
context.getSender().sendMessage( text( "Shutdown " + shutdown + " / " + computers.size() + " computers" ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -188,26 +178,15 @@ public final class CommandComputerCraft extends CommandDelegate
|
||||
@Override
|
||||
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
|
||||
{
|
||||
Set<ServerComputer> computers = Sets.newHashSet();
|
||||
if( arguments.size() > 0 )
|
||||
{
|
||||
for( String arg : arguments )
|
||||
withComputers( arguments, computers -> {
|
||||
int on = 0;
|
||||
for( ServerComputer computer : computers )
|
||||
{
|
||||
computers.addAll( ComputerSelector.getComputers( arg ) );
|
||||
if( !computer.isOn() ) on++;
|
||||
computer.turnOn();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
computers.addAll( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
}
|
||||
|
||||
int on = 0;
|
||||
for( ServerComputer computer : computers )
|
||||
{
|
||||
if( !computer.isOn() ) on++;
|
||||
computer.turnOn();
|
||||
}
|
||||
context.getSender().sendMessage( text( "Turned on " + on + " / " + computers.size() + " computers" ) );
|
||||
context.getSender().sendMessage( text( "Turned on " + on + " / " + computers.size() + " computers" ) );
|
||||
} );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -489,8 +468,6 @@ public final class CommandComputerCraft extends CommandDelegate
|
||||
if( server.getID() > maxId ) maxId = server.getID();
|
||||
}
|
||||
|
||||
ICommandSender sender = context.getSender();
|
||||
|
||||
timings.sort( Comparator.<ComputerTracker, Long>comparing( x -> x.get( field ) ).reversed() );
|
||||
|
||||
boolean defaultLayout = field == TrackingField.TASKS || field == TrackingField.TOTAL_TIME
|
||||
@@ -526,4 +503,30 @@ public final class CommandComputerCraft extends CommandDelegate
|
||||
|
||||
table.displayTo( context.getSender() );
|
||||
}
|
||||
|
||||
private static void withComputers( List<String> selectors, Consumer<Collection<ServerComputer>> action ) throws CommandException
|
||||
{
|
||||
Set<ServerComputer> computers = Sets.newHashSet();
|
||||
List<String> failed = new ArrayList<>();
|
||||
if( selectors.isEmpty() )
|
||||
{
|
||||
computers.addAll( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( String selector : selectors )
|
||||
{
|
||||
List<ServerComputer> selected = ComputerSelector.getComputers( selector );
|
||||
computers.addAll( selected );
|
||||
if( selected.isEmpty() ) failed.add( selector );
|
||||
}
|
||||
}
|
||||
|
||||
action.accept( computers );
|
||||
|
||||
if( !failed.isEmpty() )
|
||||
{
|
||||
throw new CommandException( "Could not find computers matching " + String.join( ", ", failed ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,30 +12,22 @@ import java.util.function.Predicate;
|
||||
|
||||
public final class ComputerSelector
|
||||
{
|
||||
private static List<ServerComputer> getComputers( Predicate<ServerComputer> predicate, String selector ) throws CommandException
|
||||
private static List<ServerComputer> getComputers( Predicate<ServerComputer> predicate ) throws CommandException
|
||||
{
|
||||
// We copy it to prevent concurrent modifications.
|
||||
List<ServerComputer> computers = Lists.newArrayList( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
List<ServerComputer> candidates = Lists.newArrayList();
|
||||
for( ServerComputer searchComputer : computers )
|
||||
{
|
||||
if( predicate.test( searchComputer ) ) candidates.add( searchComputer );
|
||||
}
|
||||
|
||||
if( candidates.isEmpty() )
|
||||
{
|
||||
throw new CommandException( "No computer matching " + selector );
|
||||
}
|
||||
else
|
||||
{
|
||||
return candidates;
|
||||
}
|
||||
ArrayList<ServerComputer> computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
computers.removeIf( predicate.negate() );
|
||||
return computers;
|
||||
}
|
||||
|
||||
public static ServerComputer getComputer( String selector ) throws CommandException
|
||||
{
|
||||
List<ServerComputer> computers = getComputers( selector );
|
||||
if( computers.size() == 1 )
|
||||
if( computers.size() == 0 )
|
||||
{
|
||||
throw new CommandException( "No computer matching " + selector );
|
||||
}
|
||||
else if( computers.size() == 1 )
|
||||
{
|
||||
return computers.get( 0 );
|
||||
}
|
||||
@@ -71,17 +63,17 @@ public final class ComputerSelector
|
||||
throw new CommandException( "'" + selector + "' is not a valid number" );
|
||||
}
|
||||
|
||||
return getComputers( x -> x.getID() == id, selector );
|
||||
return getComputers( x -> x.getID() == id );
|
||||
}
|
||||
else if( selector.length() > 0 && selector.charAt( 0 ) == '@' )
|
||||
{
|
||||
String label = selector.substring( 1 );
|
||||
return getComputers( x -> Objects.equals( label, x.getLabel() ), selector );
|
||||
return getComputers( x -> Objects.equals( label, x.getLabel() ) );
|
||||
}
|
||||
else if( selector.length() > 0 && selector.charAt( 0 ) == '~' )
|
||||
{
|
||||
String familyName = selector.substring( 1 );
|
||||
return getComputers( x -> x.getFamily().name().equalsIgnoreCase( familyName ), selector );
|
||||
return getComputers( x -> x.getFamily().name().equalsIgnoreCase( familyName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,14 +88,7 @@ public final class ComputerSelector
|
||||
}
|
||||
|
||||
ServerComputer computer = ComputerCraft.serverComputerRegistry.get( instance );
|
||||
if( computer == null )
|
||||
{
|
||||
throw new CommandException( "No such computer for instance id " + instance );
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.singletonList( computer );
|
||||
}
|
||||
return computer == null ? Collections.emptyList() : Collections.singletonList( computer );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ public class BlockCommandComputer extends BlockComputerBase
|
||||
super( Material.IRON );
|
||||
setBlockUnbreakable();
|
||||
setResistance( 6000000.0F );
|
||||
setUnlocalizedName( "computercraft:command_computer" );
|
||||
setTranslationKey( "computercraft:command_computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
||||
@@ -62,7 +62,7 @@ public class BlockCommandComputer extends BlockComputerBase
|
||||
@Deprecated
|
||||
public IBlockState getStateFromMeta( int meta )
|
||||
{
|
||||
EnumFacing dir = EnumFacing.getFront( meta & 0x7 );
|
||||
EnumFacing dir = EnumFacing.byIndex( meta & 0x7 );
|
||||
if( dir.getAxis() == EnumFacing.Axis.Y )
|
||||
{
|
||||
dir = EnumFacing.NORTH;
|
||||
|
@@ -44,7 +44,7 @@ public class BlockComputer extends BlockComputerBase
|
||||
{
|
||||
super( Material.ROCK );
|
||||
setHardness( 2.0f );
|
||||
setUnlocalizedName( "computercraft:computer" );
|
||||
setTranslationKey( "computercraft:computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
||||
@@ -65,7 +65,7 @@ public class BlockComputer extends BlockComputerBase
|
||||
@Deprecated
|
||||
public IBlockState getStateFromMeta( int meta )
|
||||
{
|
||||
EnumFacing dir = EnumFacing.getFront( meta & 0x7 );
|
||||
EnumFacing dir = EnumFacing.byIndex( meta & 0x7 );
|
||||
if( dir.getAxis() == EnumFacing.Axis.Y )
|
||||
{
|
||||
dir = EnumFacing.NORTH;
|
||||
|
@@ -24,7 +24,7 @@ public class ItemCommandComputer extends ItemComputer
|
||||
super( block );
|
||||
setMaxStackSize( 64 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:command_computer" );
|
||||
setTranslationKey( "computercraft:command_computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,7 @@ public class ItemComputer extends ItemComputerBase
|
||||
super( block );
|
||||
setMaxStackSize( 64 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:computer" );
|
||||
setTranslationKey( "computercraft:computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ItemComputer extends ItemComputerBase
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName( @Nonnull ItemStack stack )
|
||||
public String getTranslationKey( @Nonnull ItemStack stack )
|
||||
{
|
||||
switch( getFamily( stack ) )
|
||||
{
|
||||
|
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.integration.charset;
|
||||
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import pl.asie.charset.api.wires.IBundledEmitter;
|
||||
import pl.asie.charset.api.wires.IBundledReceiver;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER;
|
||||
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_RECEIVER;
|
||||
|
||||
final class BundledCapabilityProvider implements ICapabilityProvider
|
||||
{
|
||||
private final TileGeneric tile;
|
||||
private IBundledReceiver receiver;
|
||||
private IBundledEmitter[] emitters;
|
||||
|
||||
BundledCapabilityProvider( TileGeneric tile )
|
||||
{
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable EnumFacing side )
|
||||
{
|
||||
return capability == CAPABILITY_EMITTER || capability == CAPABILITY_RECEIVER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing side )
|
||||
{
|
||||
if( capability == CAPABILITY_RECEIVER )
|
||||
{
|
||||
IBundledReceiver receiver = this.receiver;
|
||||
if( receiver == null ) receiver = this.receiver = tile::onNeighbourChange;
|
||||
|
||||
return CAPABILITY_RECEIVER.cast( receiver );
|
||||
}
|
||||
else if( capability == CAPABILITY_EMITTER )
|
||||
{
|
||||
IBundledEmitter[] emitters = this.emitters;
|
||||
if( emitters == null ) emitters = this.emitters = new IBundledEmitter[7];
|
||||
|
||||
int index = side == null ? 6 : side.getIndex();
|
||||
IBundledEmitter emitter = emitters[index];
|
||||
if( emitter == null )
|
||||
{
|
||||
if( side == null )
|
||||
{
|
||||
emitter = emitters[index] = () -> {
|
||||
int flags = 0;
|
||||
for( EnumFacing facing : EnumFacing.VALUES ) flags |= tile.getBundledRedstoneOutput( facing );
|
||||
return toBytes( flags );
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
emitter = emitters[index] = () -> toBytes( tile.getBundledRedstoneOutput( side ) );
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
return CAPABILITY_EMITTER.cast( emitter );
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] toBytes( int flag )
|
||||
{
|
||||
byte[] channels = new byte[16];
|
||||
for( int i = 0; i < 16; i++ ) channels[i] = (flag & (1 << i)) == 0 ? (byte) 0 : 15;
|
||||
return channels;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.integration.charset;
|
||||
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER;
|
||||
|
||||
public class BundledRedstoneProvider implements IBundledRedstoneProvider
|
||||
{
|
||||
@Override
|
||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
||||
{
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1;
|
||||
|
||||
byte[] signal = tile.getCapability( CAPABILITY_EMITTER, side ).getBundledSignal();
|
||||
if( signal == null ) return -1;
|
||||
|
||||
int flag = 0;
|
||||
for( int i = 0; i < signal.length; i++ ) flag |= signal[i] > 0 ? (1 << i) : 0;
|
||||
return flag;
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.integration.charset;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import pl.asie.charset.api.wires.IBundledEmitter;
|
||||
import pl.asie.charset.api.wires.IBundledReceiver;
|
||||
|
||||
public final class IntegrationCharset
|
||||
{
|
||||
private static final ResourceLocation CAPABILITY_KEY = new ResourceLocation( ComputerCraft.MOD_ID, "charset" );
|
||||
|
||||
@CapabilityInject( IBundledEmitter.class )
|
||||
public static final Capability<IBundledEmitter> CAPABILITY_EMITTER = null;
|
||||
|
||||
@CapabilityInject( IBundledReceiver.class )
|
||||
public static final Capability<IBundledReceiver> CAPABILITY_RECEIVER = null;
|
||||
|
||||
private IntegrationCharset()
|
||||
{
|
||||
}
|
||||
|
||||
public static void register()
|
||||
{
|
||||
if( CAPABILITY_EMITTER == null || CAPABILITY_RECEIVER == null ) return;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register( new IntegrationCharset() );
|
||||
ComputerCraftAPI.registerBundledRedstoneProvider( new BundledRedstoneProvider() );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void attachGenericCapabilities( AttachCapabilitiesEvent<TileEntity> event)
|
||||
{
|
||||
TileEntity tile = event.getObject();
|
||||
if(tile instanceof TileGeneric)
|
||||
{
|
||||
event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) );
|
||||
}
|
||||
}
|
||||
}
|
@@ -33,7 +33,7 @@ public class ItemDiskLegacy extends Item
|
||||
{
|
||||
setMaxStackSize( 1 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:disk" );
|
||||
setTranslationKey( "computercraft:disk" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ public class ItemPrintout extends Item
|
||||
{
|
||||
setMaxStackSize( 1 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:page" );
|
||||
setTranslationKey( "computercraft:page" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ItemPrintout extends Item
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName( @Nonnull ItemStack stack )
|
||||
public String getTranslationKey( @Nonnull ItemStack stack )
|
||||
{
|
||||
Type type = getType( stack );
|
||||
switch( type )
|
||||
|
@@ -34,7 +34,7 @@ public class ItemTreasureDisk extends Item
|
||||
{
|
||||
setMaxStackSize( 1 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:treasure_disk" );
|
||||
setTranslationKey( "computercraft:treasure_disk" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -55,7 +55,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
public BlockCable()
|
||||
{
|
||||
setHardness( 1.5f );
|
||||
setUnlocalizedName( "computercraft:cable" );
|
||||
setTranslationKey( "computercraft:cable" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.MODEM, BlockCableModemVariant.None )
|
||||
@@ -94,12 +94,12 @@ public class BlockCable extends BlockPeripheralBase
|
||||
if( meta < 6 )
|
||||
{
|
||||
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.NONE );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta ) ) );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta ) ) );
|
||||
}
|
||||
else if( meta < 12 )
|
||||
{
|
||||
state = state.withProperty( Properties.CABLE, BlockCableCableVariant.ANY );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.getFront( meta - 6 ) ) );
|
||||
state = state.withProperty( Properties.MODEM, BlockCableModemVariant.fromFacing( EnumFacing.byIndex( meta - 6 ) ) );
|
||||
}
|
||||
else if( meta == 13 )
|
||||
{
|
||||
@@ -296,7 +296,7 @@ public class BlockCable extends BlockPeripheralBase
|
||||
}
|
||||
}
|
||||
|
||||
return result == null ? null : new RayTraceResult( result.hitVec.addVector( pos.getX(), pos.getY(), pos.getZ() ), result.sideHit, pos );
|
||||
return result == null ? null : new RayTraceResult( result.hitVec.add( pos.getX(), pos.getY(), pos.getZ() ), result.sideHit, pos );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -44,7 +44,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
public BlockPeripheral()
|
||||
{
|
||||
setHardness( 2.0f );
|
||||
setUnlocalizedName( "computercraft:peripheral" );
|
||||
setTranslationKey( "computercraft:peripheral" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
||||
@@ -55,7 +55,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
@Override
|
||||
@Nonnull
|
||||
@SideOnly( Side.CLIENT)
|
||||
public BlockRenderLayer getBlockLayer()
|
||||
public BlockRenderLayer getRenderLayer()
|
||||
{
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
if( meta >= 2 && meta <= 5 )
|
||||
{
|
||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.DiskDriveEmpty );
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.getFront( meta ) );
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.byIndex( meta ) );
|
||||
}
|
||||
else if( meta <= 9 )
|
||||
{
|
||||
@@ -93,7 +93,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
else
|
||||
{
|
||||
state = state.withProperty( Properties.VARIANT, BlockPeripheralVariant.WirelessModemOff );
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.getFront( meta - 4 ) );
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.byIndex( meta - 4 ) );
|
||||
}
|
||||
}
|
||||
else if( meta == 10 )
|
||||
@@ -651,7 +651,7 @@ public class BlockPeripheral extends BlockPeripheralBase
|
||||
public boolean causesSuffocation(IBlockState state)
|
||||
{
|
||||
// This normally uses the default state
|
||||
return blockMaterial.blocksMovement() && state.isOpaqueCube();
|
||||
return material.blocksMovement() && state.isOpaqueCube();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,7 +34,7 @@ public class BlockWiredModemFull extends BlockPeripheralBase
|
||||
public BlockWiredModemFull()
|
||||
{
|
||||
setHardness( 1.5f );
|
||||
setUnlocalizedName( "computercraft:wired_modem_full" );
|
||||
setTranslationKey( "computercraft:wired_modem_full" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( blockState.getBaseState()
|
||||
.withProperty( Properties.MODEM_ON, false )
|
||||
|
@@ -21,7 +21,7 @@ public class ItemAdvancedModem extends ItemPeripheralBase
|
||||
public ItemAdvancedModem( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:advanced_modem" );
|
||||
setTranslationKey( "computercraft:advanced_modem" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -28,7 +28,7 @@ public class ItemCable extends ItemPeripheralBase
|
||||
public ItemCable( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:cable" );
|
||||
setTranslationKey( "computercraft:cable" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ public class ItemPeripheral extends ItemPeripheralBase
|
||||
public ItemPeripheral( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:peripheral" );
|
||||
setTranslationKey( "computercraft:peripheral" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -59,7 +59,7 @@ public abstract class ItemPeripheralBase extends ItemBlock implements IPeriphera
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName( @Nonnull ItemStack stack )
|
||||
public String getTranslationKey( @Nonnull ItemStack stack )
|
||||
{
|
||||
PeripheralType type = getPeripheralType( stack );
|
||||
switch( type )
|
||||
|
@@ -143,7 +143,7 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
super.readFromNBT(nbttagcompound);
|
||||
if( nbttagcompound.hasKey( "dir" ) )
|
||||
{
|
||||
m_dir = EnumFacing.getFront( nbttagcompound.getInteger( "dir" ) );
|
||||
m_dir = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) );
|
||||
}
|
||||
if( nbttagcompound.hasKey( "anim" ) )
|
||||
{
|
||||
@@ -174,7 +174,7 @@ public abstract class TilePeripheralBase extends TileGeneric
|
||||
public void readDescription( @Nonnull NBTTagCompound nbttagcompound )
|
||||
{
|
||||
super.readDescription( nbttagcompound );
|
||||
m_dir = EnumFacing.getFront( nbttagcompound.getInteger( "dir" ) );
|
||||
m_dir = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) );
|
||||
m_anim = nbttagcompound.getInteger( "anim" );
|
||||
if( nbttagcompound.hasKey( "label" ) )
|
||||
{
|
||||
|
@@ -605,8 +605,8 @@ public class TileDiskDrive extends TilePeripheralBase
|
||||
if( !destroyed )
|
||||
{
|
||||
EnumFacing dir = getDirection();
|
||||
xOff = dir.getFrontOffsetX();
|
||||
zOff = dir.getFrontOffsetZ();
|
||||
xOff = dir.getXOffset();
|
||||
zOff = dir.getZOffset();
|
||||
}
|
||||
|
||||
BlockPos pos = getPos();
|
||||
|
@@ -33,7 +33,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase
|
||||
public BlockAdvancedModem()
|
||||
{
|
||||
setHardness( 2.0f );
|
||||
setUnlocalizedName( "computercraft:advanced_modem" );
|
||||
setTranslationKey( "computercraft:advanced_modem" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
||||
@@ -54,7 +54,7 @@ public class BlockAdvancedModem extends BlockPeripheralBase
|
||||
public IBlockState getStateFromMeta( int meta )
|
||||
{
|
||||
IBlockState state = getDefaultState();
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.getFront( meta ) );
|
||||
state = state.withProperty( Properties.FACING, EnumFacing.byIndex( meta ) );
|
||||
state = state.withProperty( Properties.ON, false );
|
||||
return state;
|
||||
}
|
||||
|
@@ -344,7 +344,7 @@ public class TileMonitor extends TilePeripheralBase
|
||||
|
||||
public EnumFacing getFront()
|
||||
{
|
||||
return m_dir <= 5 ? EnumFacing.getFront( m_dir ) : (m_dir <= 11 ? EnumFacing.DOWN : EnumFacing.UP);
|
||||
return m_dir <= 5 ? EnumFacing.byIndex( m_dir ) : (m_dir <= 11 ? EnumFacing.DOWN : EnumFacing.UP);
|
||||
}
|
||||
|
||||
public EnumFacing getRight()
|
||||
|
@@ -43,7 +43,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
{
|
||||
setMaxStackSize( 1 );
|
||||
setHasSubtypes( true );
|
||||
setUnlocalizedName( "computercraft:pocket_computer" );
|
||||
setTranslationKey( "computercraft:pocket_computer" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName( @Nonnull ItemStack stack )
|
||||
public String getTranslationKey( @Nonnull ItemStack stack )
|
||||
{
|
||||
switch( getFamily( stack ) )
|
||||
{
|
||||
@@ -209,7 +209,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
|
||||
@Override
|
||||
public String getItemStackDisplayName( @Nonnull ItemStack stack )
|
||||
{
|
||||
String baseString = getUnlocalizedName( stack );
|
||||
String baseString = getTranslationKey( stack );
|
||||
IPocketUpgrade upgrade = getUpgrade( stack );
|
||||
if( upgrade != null )
|
||||
{
|
||||
|
@@ -48,17 +48,19 @@ import net.minecraftforge.registries.IForgeRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
{
|
||||
private Map<Integer, ITurtleUpgrade> m_legacyTurtleUpgrades;
|
||||
private Map<String, ITurtleUpgrade> m_turtleUpgrades;
|
||||
|
||||
private Consumer<ItemStack> dropConsumer;
|
||||
private Function<ItemStack, ItemStack> dropConsumer;
|
||||
private List<ItemStack> remainingDrops;
|
||||
private WeakReference<World> dropWorld;
|
||||
private BlockPos dropPos;
|
||||
private AxisAlignedBB dropBounds;
|
||||
@@ -200,9 +202,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDropConsumer( Entity entity, Consumer<ItemStack> consumer )
|
||||
public void setDropConsumer( Entity entity, Function<ItemStack, ItemStack> consumer )
|
||||
{
|
||||
dropConsumer = consumer;
|
||||
remainingDrops = new ArrayList<>();
|
||||
dropEntity = new WeakReference<>( entity );
|
||||
dropWorld = new WeakReference<>( entity.world );
|
||||
dropPos = null;
|
||||
@@ -212,9 +215,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDropConsumer( World world, BlockPos pos, Consumer<ItemStack> consumer )
|
||||
public void setDropConsumer( World world, BlockPos pos, Function<ItemStack, ItemStack> consumer )
|
||||
{
|
||||
dropConsumer = consumer;
|
||||
remainingDrops = new ArrayList<>();
|
||||
dropEntity = null;
|
||||
dropWorld = new WeakReference<>( world );
|
||||
dropPos = pos;
|
||||
@@ -222,7 +226,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearDropConsumer()
|
||||
public List<ItemStack> clearDropConsumer()
|
||||
{
|
||||
if( dropEntity != null )
|
||||
{
|
||||
@@ -232,17 +236,22 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
entity.captureDrops = false;
|
||||
if( entity.capturedDrops != null )
|
||||
{
|
||||
for( EntityItem entityItem : entity.capturedDrops ) dropConsumer.accept( entityItem.getItem() );
|
||||
for( EntityItem entityItem : entity.capturedDrops ) handleDrops( entityItem.getItem() );
|
||||
entity.capturedDrops.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> remainingStacks = remainingDrops;
|
||||
|
||||
dropConsumer = null;
|
||||
remainingDrops = null;
|
||||
dropEntity = null;
|
||||
dropWorld = null;
|
||||
dropPos = null;
|
||||
dropBounds = null;
|
||||
|
||||
return remainingStacks;
|
||||
}
|
||||
|
||||
private void registerTurtleUpgradeInternal( ITurtleUpgrade upgrade )
|
||||
@@ -413,10 +422,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
// We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower.
|
||||
for( RegistryEvent.MissingMappings.Mapping<Item> mapping : mappings.getAllMappings() )
|
||||
{
|
||||
String domain = mapping.key.getResourceDomain();
|
||||
String domain = mapping.key.getNamespace();
|
||||
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
|
||||
|
||||
String key = mapping.key.getResourcePath();
|
||||
String key = mapping.key.getPath();
|
||||
if( key.equalsIgnoreCase( "CC-Turtle" ) )
|
||||
{
|
||||
mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.turtle ) );
|
||||
@@ -438,10 +447,10 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
// We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower.
|
||||
for( RegistryEvent.MissingMappings.Mapping<Block> mapping : mappings.getAllMappings() )
|
||||
{
|
||||
String domain = mapping.key.getResourceDomain();
|
||||
String domain = mapping.key.getNamespace();
|
||||
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
|
||||
|
||||
String key = mapping.key.getResourcePath();
|
||||
String key = mapping.key.getPath();
|
||||
if( key.equalsIgnoreCase( "CC-Turtle" ) )
|
||||
{
|
||||
mapping.remap( ComputerCraft.Blocks.turtle );
|
||||
@@ -471,6 +480,12 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
MinecraftForge.EVENT_BUS.register( handlers );
|
||||
}
|
||||
|
||||
private void handleDrops(ItemStack stack)
|
||||
{
|
||||
ItemStack remaining = dropConsumer.apply(stack);
|
||||
if (!remaining.isEmpty()) remainingDrops.add(remaining);
|
||||
}
|
||||
|
||||
private class ForgeHandlers
|
||||
{
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
@@ -480,7 +495,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
if( dropEntity != null && event.getEntity() == dropEntity.get() )
|
||||
{
|
||||
List<EntityItem> drops = event.getDrops();
|
||||
for( EntityItem entityItem : drops ) dropConsumer.accept( entityItem.getItem() );
|
||||
for( EntityItem entityItem : drops ) handleDrops( entityItem.getItem() );
|
||||
drops.clear();
|
||||
}
|
||||
}
|
||||
@@ -494,7 +509,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
{
|
||||
for( ItemStack item : event.getDrops() )
|
||||
{
|
||||
if( event.getWorld().rand.nextFloat() < event.getDropChance() ) dropConsumer.accept( item );
|
||||
if( event.getWorld().rand.nextFloat() < event.getDropChance() ) handleDrops( item );
|
||||
}
|
||||
event.getDrops().clear();
|
||||
}
|
||||
@@ -507,7 +522,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
||||
if( dropWorld != null && dropWorld.get() == event.getWorld() && event.getEntity() instanceof EntityItem
|
||||
&& dropBounds.contains( event.getEntity().getPositionVector() ) )
|
||||
{
|
||||
dropConsumer.accept( ((EntityItem) event.getEntity()).getItem() );
|
||||
handleDrops( ((EntityItem) event.getEntity()).getItem() );
|
||||
event.setCanceled( true );
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import dan200.computercraft.shared.computer.core.*;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
import dan200.computercraft.shared.integration.charset.IntegrationCharset;
|
||||
import dan200.computercraft.shared.media.common.DefaultMediaProvider;
|
||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
||||
@@ -76,6 +77,7 @@ import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||
@@ -83,6 +85,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import pl.asie.charset.ModCharset;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
@@ -117,6 +120,8 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
{
|
||||
registerTileEntities();
|
||||
registerForgeHandlers();
|
||||
|
||||
if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -414,10 +419,10 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
// We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower.
|
||||
for( RegistryEvent.MissingMappings.Mapping<Item> mapping : mappings.getAllMappings() )
|
||||
{
|
||||
String domain = mapping.key.getResourceDomain();
|
||||
String domain = mapping.key.getNamespace();
|
||||
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
|
||||
|
||||
String key = mapping.key.getResourcePath();
|
||||
String key = mapping.key.getPath();
|
||||
if( key.equalsIgnoreCase( "CC-Computer" ) )
|
||||
{
|
||||
mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.computer ) );
|
||||
@@ -451,10 +456,10 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
||||
// We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower.
|
||||
for( RegistryEvent.MissingMappings.Mapping<Block> mapping : mappings.getAllMappings() )
|
||||
{
|
||||
String domain = mapping.key.getResourceDomain();
|
||||
String domain = mapping.key.getNamespace();
|
||||
if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue;
|
||||
|
||||
String key = mapping.key.getResourcePath();
|
||||
String key = mapping.key.getPath();
|
||||
if( key.equalsIgnoreCase( "CC-Computer" ) )
|
||||
{
|
||||
mapping.remap( ComputerCraft.Blocks.computer );
|
||||
|
@@ -14,7 +14,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface ICCTurtleProxy
|
||||
{
|
||||
@@ -27,7 +29,7 @@ public interface ICCTurtleProxy
|
||||
ITurtleUpgrade getTurtleUpgrade( @Nonnull ItemStack item );
|
||||
void addAllUpgradedTurtles( NonNullList<ItemStack> list );
|
||||
|
||||
void setDropConsumer( Entity entity, Consumer<ItemStack> consumer );
|
||||
void setDropConsumer( World world, BlockPos pos, Consumer<ItemStack> consumer );
|
||||
void clearDropConsumer();
|
||||
void setDropConsumer( Entity entity, Function<ItemStack, ItemStack> consumer );
|
||||
void setDropConsumer( World world, BlockPos pos, Function<ItemStack, ItemStack> consumer );
|
||||
List<ItemStack> clearDropConsumer();
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ public class BlockTurtle extends BlockComputerBase
|
||||
{
|
||||
super( Material.IRON );
|
||||
setHardness( 2.5f );
|
||||
setUnlocalizedName( "computercraft:turtle" );
|
||||
setTranslationKey( "computercraft:turtle" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
setDefaultState( this.blockState.getBaseState()
|
||||
.withProperty( Properties.FACING, EnumFacing.NORTH )
|
||||
|
@@ -226,7 +226,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
public void readFromNBT( NBTTagCompound nbttagcompound )
|
||||
{
|
||||
// Read state
|
||||
m_direction = EnumFacing.getFront( nbttagcompound.getInteger( "dir" ) );
|
||||
m_direction = EnumFacing.byIndex( nbttagcompound.getInteger( "dir" ) );
|
||||
m_selectedSlot = nbttagcompound.getInteger( "selectedSlot" );
|
||||
if( nbttagcompound.hasKey( "fuelLevel" ) )
|
||||
{
|
||||
@@ -370,8 +370,8 @@ public class TurtleBrain implements ITurtleAccess
|
||||
// Write overlay
|
||||
if( m_overlay != null )
|
||||
{
|
||||
nbttagcompound.setString( "overlay_mod", m_overlay.getResourceDomain() );
|
||||
nbttagcompound.setString( "overlay_path", m_overlay.getResourcePath() );
|
||||
nbttagcompound.setString( "overlay_mod", m_overlay.getNamespace() );
|
||||
nbttagcompound.setString( "overlay_path", m_overlay.getPath() );
|
||||
}
|
||||
|
||||
// Write NBT
|
||||
@@ -429,8 +429,8 @@ public class TurtleBrain implements ITurtleAccess
|
||||
// Overlay
|
||||
if( m_overlay != null )
|
||||
{
|
||||
nbttagcompound.setString( "overlay_mod", m_overlay.getResourceDomain() );
|
||||
nbttagcompound.setString( "overlay_path", m_overlay.getResourcePath() );
|
||||
nbttagcompound.setString( "overlay_mod", m_overlay.getNamespace() );
|
||||
nbttagcompound.setString( "overlay_path", m_overlay.getPath() );
|
||||
}
|
||||
|
||||
// Animation
|
||||
@@ -505,7 +505,7 @@ public class TurtleBrain implements ITurtleAccess
|
||||
m_lastAnimationProgress = 0;
|
||||
}
|
||||
|
||||
m_direction = EnumFacing.getFront( nbttagcompound.getInteger( "direction" ) );
|
||||
m_direction = EnumFacing.byIndex( nbttagcompound.getInteger( "direction" ) );
|
||||
m_fuelLevel = nbttagcompound.getInteger( "fuelLevel" );
|
||||
}
|
||||
|
||||
@@ -998,9 +998,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
double distance = -1.0 + getAnimationFraction( f );
|
||||
return new Vec3d(
|
||||
distance * dir.getFrontOffsetX(),
|
||||
distance * dir.getFrontOffsetY(),
|
||||
distance * dir.getFrontOffsetZ()
|
||||
distance * dir.getXOffset(),
|
||||
distance * dir.getYOffset(),
|
||||
distance * dir.getZOffset()
|
||||
);
|
||||
}
|
||||
default:
|
||||
@@ -1184,31 +1184,31 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
float pushFrac = 1.0f - ((float)(m_animationProgress + 1) / (float)ANIM_DURATION);
|
||||
float push = Math.max( pushFrac + 0.0125f, 0.0f );
|
||||
if (moveDir.getFrontOffsetX() < 0)
|
||||
if (moveDir.getXOffset() < 0)
|
||||
{
|
||||
minX += moveDir.getFrontOffsetX() * push;
|
||||
minX += moveDir.getXOffset() * push;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxX -= moveDir.getFrontOffsetX() * push;
|
||||
maxX -= moveDir.getXOffset() * push;
|
||||
}
|
||||
|
||||
if (moveDir.getFrontOffsetY() < 0)
|
||||
if (moveDir.getYOffset() < 0)
|
||||
{
|
||||
minY += moveDir.getFrontOffsetY() * push;
|
||||
minY += moveDir.getYOffset() * push;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxY -= moveDir.getFrontOffsetY() * push;
|
||||
maxY -= moveDir.getYOffset() * push;
|
||||
}
|
||||
|
||||
if (moveDir.getFrontOffsetZ() < 0)
|
||||
if (moveDir.getZOffset() < 0)
|
||||
{
|
||||
minZ += moveDir.getFrontOffsetZ() * push;
|
||||
minZ += moveDir.getZOffset() * push;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxZ -= moveDir.getFrontOffsetZ() * push;
|
||||
maxZ -= moveDir.getZOffset() * push;
|
||||
}
|
||||
|
||||
AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ );
|
||||
@@ -1216,9 +1216,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
double pushStep = 1.0f / ANIM_DURATION;
|
||||
double pushStepX = moveDir.getFrontOffsetX() * pushStep;
|
||||
double pushStepY = moveDir.getFrontOffsetY() * pushStep;
|
||||
double pushStepZ = moveDir.getFrontOffsetZ() * pushStep;
|
||||
double pushStepX = moveDir.getXOffset() * pushStep;
|
||||
double pushStepY = moveDir.getYOffset() * pushStep;
|
||||
double pushStepZ = moveDir.getZOffset() * pushStep;
|
||||
for (Entity entity : list)
|
||||
{
|
||||
entity.move( MoverType.PISTON, pushStepX, pushStepY, pushStepZ );
|
||||
|
@@ -126,7 +126,7 @@ public class TurtleCompareCommand implements ITurtleCommand
|
||||
{
|
||||
return TurtleCommandResult.success();
|
||||
}
|
||||
else if( selectedStack.getUnlocalizedName().equals( lookAtStack.getUnlocalizedName() ) )
|
||||
else if( selectedStack.getTranslationKey().equals( lookAtStack.getTranslationKey() ) )
|
||||
{
|
||||
return TurtleCommandResult.success();
|
||||
}
|
||||
|
@@ -87,9 +87,9 @@ public class TurtleMoveCommand implements ITurtleCommand
|
||||
if( entityBB != null )
|
||||
{
|
||||
AxisAlignedBB pushedBB = entityBB.offset(
|
||||
direction.getFrontOffsetX(),
|
||||
direction.getFrontOffsetY(),
|
||||
direction.getFrontOffsetZ()
|
||||
direction.getXOffset(),
|
||||
direction.getYOffset(),
|
||||
direction.getZOffset()
|
||||
);
|
||||
if( !oldWorld.getCollisionBoxes( null, pushedBB ).isEmpty() )
|
||||
{
|
||||
|
@@ -30,7 +30,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
@@ -38,6 +37,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public class TurtlePlaceCommand implements ITurtleCommand
|
||||
{
|
||||
@@ -194,9 +194,9 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
// Stop intersection with the turtle itself
|
||||
if( turtle.getPosition().equals( position ) )
|
||||
{
|
||||
turtlePlayer.posX += 0.48 * direction.getFrontOffsetX();
|
||||
turtlePlayer.posY += 0.48 * direction.getFrontOffsetY();
|
||||
turtlePlayer.posZ += 0.48 * direction.getFrontOffsetZ();
|
||||
turtlePlayer.posX += 0.48 * direction.getXOffset();
|
||||
turtlePlayer.posY += 0.48 * direction.getYOffset();
|
||||
turtlePlayer.posZ += 0.48 * direction.getZOffset();
|
||||
}
|
||||
|
||||
if( direction.getAxis() != EnumFacing.Axis.Y )
|
||||
@@ -241,14 +241,10 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
// Start claiming entity drops
|
||||
Entity hitEntity = hit.getKey();
|
||||
Vec3d hitPos = hit.getValue();
|
||||
ComputerCraft.setDropConsumer( hitEntity, ( drop ) ->
|
||||
{
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
WorldUtil.dropItemStack( remainder, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
} );
|
||||
ComputerCraft.setDropConsumer(
|
||||
hitEntity,
|
||||
drop -> InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() )
|
||||
);
|
||||
|
||||
// Place on the entity
|
||||
boolean placed = false;
|
||||
@@ -285,7 +281,11 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
}
|
||||
|
||||
// Stop claiming drops
|
||||
ComputerCraft.clearDropConsumer();
|
||||
List<ItemStack> remainingDrops = ComputerCraft.clearDropConsumer();
|
||||
for( ItemStack remaining : remainingDrops )
|
||||
{
|
||||
WorldUtil.dropItemStack( remaining, world, position, turtle.getDirection().getOpposite() );
|
||||
}
|
||||
|
||||
// Put everything we collected into the turtles inventory, then return
|
||||
ItemStack remainder = turtlePlayer.unloadInventory( turtle );
|
||||
@@ -367,9 +367,9 @@ public class TurtlePlaceCommand implements ITurtleCommand
|
||||
orientPlayer( turtle, turtlePlayer, playerPosition, playerDir );
|
||||
|
||||
// Calculate where the turtle would hit the block
|
||||
float hitX = 0.5f + side.getFrontOffsetX() * 0.5f;
|
||||
float hitY = 0.5f + side.getFrontOffsetY() * 0.5f;
|
||||
float hitZ = 0.5f + side.getFrontOffsetZ() * 0.5f;
|
||||
float hitX = 0.5f + side.getXOffset() * 0.5f;
|
||||
float hitY = 0.5f + side.getYOffset() * 0.5f;
|
||||
float hitZ = 0.5f + side.getZOffset() * 0.5f;
|
||||
if( Math.abs( hitY - 0.5f ) < 0.01f )
|
||||
{
|
||||
hitY = 0.45f;
|
||||
|
@@ -15,7 +15,7 @@ public class ItemTurtleAdvanced extends ItemTurtleNormal
|
||||
public ItemTurtleAdvanced( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:advanced_turtle" );
|
||||
setTranslationKey( "computercraft:advanced_turtle" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -114,7 +114,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName( @Nonnull ItemStack stack )
|
||||
public String getTranslationKey( @Nonnull ItemStack stack )
|
||||
{
|
||||
ComputerFamily family = getFamily( stack );
|
||||
switch( family )
|
||||
@@ -139,7 +139,7 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle
|
||||
@Override
|
||||
public String getItemStackDisplayName( @Nonnull ItemStack stack )
|
||||
{
|
||||
String baseString = getUnlocalizedName( stack );
|
||||
String baseString = getTranslationKey( stack );
|
||||
ITurtleUpgrade left = getUpgrade( stack, TurtleSide.Left );
|
||||
ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right );
|
||||
if( left != null && right != null )
|
||||
|
@@ -23,7 +23,7 @@ public class ItemTurtleLegacy extends ItemTurtleBase
|
||||
public ItemTurtleLegacy( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:turtle" );
|
||||
setTranslationKey( "computercraft:turtle" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,7 @@ public class ItemTurtleNormal extends ItemTurtleBase
|
||||
public ItemTurtleNormal( Block block )
|
||||
{
|
||||
super( block );
|
||||
setUnlocalizedName( "computercraft:turtle" );
|
||||
setTranslationKey( "computercraft:turtle" );
|
||||
setCreativeTab( ComputerCraft.mainCreativeTab );
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ public class ItemTurtleNormal extends ItemTurtleBase
|
||||
}
|
||||
if( overlay != null )
|
||||
{
|
||||
nbt.setString( "overlay_mod", overlay.getResourceDomain() );
|
||||
nbt.setString( "overlay_path", overlay.getResourcePath() );
|
||||
nbt.setString( "overlay_mod", overlay.getNamespace() );
|
||||
nbt.setString( "overlay_path", overlay.getPath() );
|
||||
}
|
||||
stack.setTagCompound( nbt );
|
||||
|
||||
|
@@ -42,9 +42,8 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.vecmath.Matrix4f;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TurtleTool implements ITurtleUpgrade
|
||||
{
|
||||
@@ -103,7 +102,7 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
public Pair<IBakedModel, Matrix4f> getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
|
||||
{
|
||||
float xOffset = (side == TurtleSide.Left) ? -0.40625f : 0.40625f;
|
||||
@@ -154,7 +153,7 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
{
|
||||
return 3.0f;
|
||||
}
|
||||
|
||||
|
||||
private TurtleCommandResult attack( final ITurtleAccess turtle, EnumFacing direction, TurtleSide side )
|
||||
{
|
||||
// Create a fake player, and orient it appropriately
|
||||
@@ -185,10 +184,9 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
{
|
||||
return TurtleCommandResult.failure( attackEvent.getFailureMessage() );
|
||||
}
|
||||
|
||||
|
||||
// Start claiming entity drops
|
||||
List<ItemStack> extra = new ArrayList<>( );
|
||||
ComputerCraft.setDropConsumer( hitEntity, turtleDropConsumer( turtle, extra ) );
|
||||
ComputerCraft.setDropConsumer( hitEntity, turtleDropConsumer( turtle ) );
|
||||
|
||||
// Attack the entity
|
||||
boolean attacked = false;
|
||||
@@ -220,7 +218,7 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
}
|
||||
|
||||
// Stop claiming drops
|
||||
stopConsuming( turtle, extra );
|
||||
stopConsuming( turtle );
|
||||
|
||||
// Put everything we collected into the turtles inventory, then return
|
||||
if( attacked )
|
||||
@@ -232,7 +230,7 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
|
||||
return TurtleCommandResult.failure( "Nothing to attack here" );
|
||||
}
|
||||
|
||||
|
||||
private TurtleCommandResult dig( ITurtleAccess turtle, EnumFacing direction, TurtleSide side )
|
||||
{
|
||||
// Get ready to dig
|
||||
@@ -277,8 +275,7 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
}
|
||||
|
||||
// Consume the items the block drops
|
||||
List<ItemStack> extra = new ArrayList<>( );
|
||||
ComputerCraft.setDropConsumer( world, blockPosition, turtleDropConsumer( turtle, extra ) );
|
||||
ComputerCraft.setDropConsumer( world, blockPosition, turtleDropConsumer( turtle ) );
|
||||
|
||||
TileEntity tile = world.getTileEntity( blockPosition );
|
||||
|
||||
@@ -291,13 +288,13 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
// Destroy the block
|
||||
boolean canHarvest = state.getBlock().canHarvestBlock( world, blockPosition, turtlePlayer );
|
||||
boolean canBreak = state.getBlock().removedByPlayer( state, world, blockPosition, turtlePlayer, canHarvest );
|
||||
if( canBreak ) state.getBlock().onBlockDestroyedByPlayer( world, blockPosition, state );
|
||||
if( canBreak ) state.getBlock().onPlayerDestroy( world, blockPosition, state );
|
||||
if( canHarvest )
|
||||
{
|
||||
state.getBlock().harvestBlock( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getHeldItemMainhand() );
|
||||
}
|
||||
|
||||
stopConsuming( turtle, extra );
|
||||
stopConsuming( turtle );
|
||||
|
||||
// Remember the previous block
|
||||
if( turtle instanceof TurtleBrain )
|
||||
@@ -312,18 +309,14 @@ public class TurtleTool implements ITurtleUpgrade
|
||||
return TurtleCommandResult.failure( "Nothing to dig here" );
|
||||
}
|
||||
|
||||
private Consumer<ItemStack> turtleDropConsumer( ITurtleAccess turtle, List<ItemStack> extra )
|
||||
private Function<ItemStack, ItemStack> turtleDropConsumer( ITurtleAccess turtle )
|
||||
{
|
||||
return ( drop ) ->
|
||||
{
|
||||
ItemStack remainder = InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
if( !remainder.isEmpty() ) extra.add( remainder );
|
||||
};
|
||||
return drop -> InventoryUtil.storeItems( drop, turtle.getItemHandler(), turtle.getSelectedSlot() );
|
||||
}
|
||||
|
||||
private void stopConsuming( ITurtleAccess turtle, List<ItemStack> extra )
|
||||
private void stopConsuming( ITurtleAccess turtle )
|
||||
{
|
||||
ComputerCraft.clearDropConsumer();
|
||||
List<ItemStack> extra = ComputerCraft.clearDropConsumer();
|
||||
for( ItemStack remainder : extra )
|
||||
{
|
||||
WorldUtil.dropItemStack( remainder, turtle.getWorld(), turtle.getPosition(), turtle.getDirection().getOpposite() );
|
||||
|
@@ -24,7 +24,7 @@ public class CreativeTabMain extends CreativeTabs
|
||||
@Nonnull
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ItemStack getTabIconItem()
|
||||
public ItemStack createIcon()
|
||||
{
|
||||
return new ItemStack( ComputerCraft.Blocks.computer );
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class CreativeTabMain extends CreativeTabs
|
||||
@Nonnull
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getTranslatedTabLabel()
|
||||
public String getTranslationKey()
|
||||
{
|
||||
return getTabLabel();
|
||||
}
|
||||
|
@@ -21,14 +21,14 @@ public class CreativeTabTreasure extends CreativeTabs
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getTabIconItem()
|
||||
public ItemStack createIcon()
|
||||
{
|
||||
return new ItemStack( ComputerCraft.Items.treasureDisk );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getTranslatedTabLabel()
|
||||
public String getTranslationKey()
|
||||
{
|
||||
return getTabLabel();
|
||||
}
|
||||
|
@@ -73,13 +73,13 @@ public class InventoryUtil
|
||||
|
||||
// Look for entity with inventory
|
||||
Vec3d vecStart = new Vec3d(
|
||||
pos.getX() + 0.5 + 0.6 * side.getFrontOffsetX(),
|
||||
pos.getY() + 0.5 + 0.6 * side.getFrontOffsetY(),
|
||||
pos.getZ() + 0.5 + 0.6 * side.getFrontOffsetZ()
|
||||
pos.getX() + 0.5 + 0.6 * side.getXOffset(),
|
||||
pos.getY() + 0.5 + 0.6 * side.getYOffset(),
|
||||
pos.getZ() + 0.5 + 0.6 * side.getZOffset()
|
||||
);
|
||||
EnumFacing dir = side.getOpposite();
|
||||
Vec3d vecDir = new Vec3d(
|
||||
dir.getFrontOffsetX(), dir.getFrontOffsetY(), dir.getFrontOffsetZ()
|
||||
dir.getXOffset(), dir.getYOffset(), dir.getZOffset()
|
||||
);
|
||||
Pair<Entity, Vec3d> hit = WorldUtil.rayTraceEntities( world, vecStart, vecDir, 1.1 );
|
||||
if( hit != null )
|
||||
|
@@ -43,14 +43,14 @@ public class WorldUtil
|
||||
|
||||
public static Pair<Entity, Vec3d> rayTraceEntities( World world, Vec3d vecStart, Vec3d vecDir, double distance )
|
||||
{
|
||||
Vec3d vecEnd = vecStart.addVector( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance );
|
||||
Vec3d vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance );
|
||||
|
||||
// Raycast for blocks
|
||||
RayTraceResult result = world.rayTraceBlocks( vecStart.addVector(0.0,0.0,0.0), vecEnd.addVector(0.0,0.0,0.0) );
|
||||
RayTraceResult result = world.rayTraceBlocks( vecStart, vecEnd );
|
||||
if( result != null && result.typeOfHit == RayTraceResult.Type.BLOCK )
|
||||
{
|
||||
distance = vecStart.distanceTo( result.hitVec );
|
||||
vecEnd = vecStart.addVector( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance );
|
||||
vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance );
|
||||
}
|
||||
|
||||
// Check for entities
|
||||
@@ -114,7 +114,7 @@ public class WorldUtil
|
||||
}
|
||||
if( closest != null && closestDist <= distance )
|
||||
{
|
||||
Vec3d closestPos = vecStart.addVector( vecDir.x * closestDist, vecDir.y * closestDist, vecDir.z * closestDist );
|
||||
Vec3d closestPos = vecStart.add( vecDir.x * closestDist, vecDir.y * closestDist, vecDir.z * closestDist );
|
||||
return Pair.of( closest, closestPos );
|
||||
}
|
||||
return null;
|
||||
@@ -128,7 +128,7 @@ public class WorldUtil
|
||||
public static Vec3d getRayEnd( EntityPlayer player) {
|
||||
double reach = player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue();
|
||||
Vec3d look = player.getLookVec();
|
||||
return getRayStart( player ).addVector( look.x * reach, look.y * reach, look.z * reach );
|
||||
return getRayStart( player ).add( look.x * reach, look.y * reach, look.z * reach );
|
||||
}
|
||||
|
||||
public static boolean isVecInsideInclusive(AxisAlignedBB bb , Vec3d vec) {
|
||||
@@ -147,9 +147,9 @@ public class WorldUtil
|
||||
double zDir;
|
||||
if( direction != null )
|
||||
{
|
||||
xDir = direction.getFrontOffsetX();
|
||||
yDir = direction.getFrontOffsetY();
|
||||
zDir = direction.getFrontOffsetZ();
|
||||
xDir = direction.getXOffset();
|
||||
yDir = direction.getYOffset();
|
||||
zDir = direction.getZOffset();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -18,9 +18,6 @@ if _VERSION == "Lua 5.1" then
|
||||
if env ~= nil and type( env) ~= "table" then
|
||||
error( "bad argument #4 (expected table, got " .. type( env ) .. ")", 2 )
|
||||
end
|
||||
if mode ~= nil and mode ~= "t" then
|
||||
error( "Binary chunk loading prohibited", 2 )
|
||||
end
|
||||
local ok, p1, p2 = pcall( function()
|
||||
if type(x) == "string" then
|
||||
local result, err = nativeloadstring( x, name )
|
||||
|
@@ -421,8 +421,10 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible )
|
||||
function window.reposition( nNewX, nNewY, nNewWidth, nNewHeight )
|
||||
if type( nNewX ) ~= "number" then error( "bad argument #1 (expected number, got " .. type( nNewX ) .. ")", 2 ) end
|
||||
if type( nNewY ) ~= "number" then error( "bad argument #2 (expected number, got " .. type( nNewY ) .. ")", 2 ) end
|
||||
if nNewWidth ~= nil and type( nNewWidth ) ~= "number" then error( "bad argument #3 (expected number, got " .. type( nNewWidth ) .. ")", 2 ) end
|
||||
if nNewHeight ~= nil and type( nNewHeight ) ~= "number" then error( "bad argument #4 (expected number, got " .. type( nNewHeight ) .. ")", 2 ) end
|
||||
if nNewWidth ~= nil or nNewWidth ~= nil then
|
||||
if type( nNewWidth ) ~= "number" then error( "bad argument #3 (expected number, got " .. type( nNewWidth ) .. ")", 2 ) end
|
||||
if type( nNewHeight ) ~= "number" then error( "bad argument #4 (expected number, got " .. type( nNewHeight ) .. ")", 2 ) end
|
||||
end
|
||||
|
||||
nX = nNewX
|
||||
nY = nNewY
|
||||
|
@@ -13,18 +13,14 @@ if sTopic == "index" then
|
||||
return
|
||||
end
|
||||
|
||||
local w,h = term.getSize()
|
||||
local sFile = help.lookup( sTopic )
|
||||
local file = ((sFile ~= nil) and io.open( sFile )) or nil
|
||||
local nLinesPrinted = 0
|
||||
if file then
|
||||
local sLine = file:read()
|
||||
local nLines = 0
|
||||
while sLine do
|
||||
nLines = nLines + textutils.pagedPrint( sLine, (h-3) - nLines )
|
||||
sLine = file:read()
|
||||
end
|
||||
local sContents = file:read("*a")
|
||||
file:close()
|
||||
|
||||
local _, nHeight = term.getSize()
|
||||
textutils.pagedPrint( sContents, nHeight - 3 )
|
||||
else
|
||||
print( "No help available" )
|
||||
end
|
||||
|
@@ -113,7 +113,7 @@ elseif sCommand == "run" then
|
||||
printError( err )
|
||||
return
|
||||
end
|
||||
local success, msg = pcall(func, table.unpack(tArgs, 3))
|
||||
local success, msg = pcall(func, select(3, ...))
|
||||
if not success then
|
||||
printError( msg )
|
||||
end
|
||||
|
@@ -89,18 +89,17 @@ end
|
||||
|
||||
print( "Press any key to stop the groove" )
|
||||
|
||||
local bEnd = false
|
||||
parallel.waitForAll(
|
||||
parallel.waitForAny(
|
||||
function()
|
||||
while not bEnd do
|
||||
local event, key = os.pullEvent("key")
|
||||
if key ~= keys.escape then
|
||||
bEnd = true
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
function()
|
||||
while not bEnd do
|
||||
while true do
|
||||
local fnMove = tMoves[math.random(1,#tMoves)]
|
||||
fnMove()
|
||||
end
|
||||
|
Reference in New Issue
Block a user