-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from sharing_1.10 to 1.12 and continue project.
This is a fresh commit rather then a merge because it is clearer to see how the changes are reflected against the modern code base. Blueprints are survival usable at this point, though you still have to use a command to dump them out, they aren't super efficient either. I know there are missing localization and art, and a lot of testing needs to get done.
- Loading branch information
1 parent
68ce8ae
commit 64fa3fa
Showing
92 changed files
with
5,655 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/mod/chiselsandbits/blueprints/BlueprintContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package mod.chiselsandbits.blueprints; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.Container; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
public class BlueprintContainer extends Container | ||
{ | ||
final EntityPlayer thePlayer; | ||
protected int bluePrintSlot; | ||
|
||
public BlueprintContainer( | ||
final EntityPlayer player, | ||
final World world, | ||
final int x, | ||
final int y, | ||
final int z ) | ||
{ | ||
thePlayer = player; | ||
bluePrintSlot = player.inventory.currentItem; | ||
} | ||
|
||
@Override | ||
public boolean canInteractWith( | ||
final EntityPlayer playerIn ) | ||
{ | ||
return playerIn == thePlayer && hasBlueprintInHand( thePlayer ); | ||
} | ||
|
||
private boolean hasBlueprintInHand( | ||
final EntityPlayer player ) | ||
{ | ||
final ItemStack inHand = player.getHeldItem( EnumHand.MAIN_HAND ); | ||
|
||
if ( inHand != null && inHand.getItem() instanceof ItemBlueprint ) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@SideOnly( Side.CLIENT ) | ||
public static Object getGuiClass() | ||
{ | ||
return BlueprintGui.class; | ||
} | ||
|
||
} |
243 changes: 243 additions & 0 deletions
243
src/main/java/mod/chiselsandbits/blueprints/BlueprintData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
package mod.chiselsandbits.blueprints; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.net.URLDecoder; | ||
import java.net.URLEncoder; | ||
|
||
import javax.imageio.ImageIO; | ||
|
||
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled; | ||
import mod.chiselsandbits.chiseledblock.data.IVoxelAccess; | ||
import mod.chiselsandbits.core.ChiselsAndBits; | ||
import mod.chiselsandbits.core.ClientSide; | ||
import mod.chiselsandbits.core.Log; | ||
import mod.chiselsandbits.share.ShareWorldData; | ||
import mod.chiselsandbits.voxelspace.IVoxelProvider; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class BlueprintData implements Runnable, IVoxelProvider | ||
{ | ||
public static enum EnumLoadState | ||
{ | ||
LOADING, | ||
LOADED, | ||
FAILED; | ||
|
||
public boolean readyOrWaiting() | ||
{ | ||
return this != FAILED; | ||
} | ||
}; | ||
|
||
private long lastNeeded = getCurrentTime(); | ||
private EnumLoadState state = EnumLoadState.LOADING; | ||
private URL url = null; | ||
|
||
private ShareWorldData data; | ||
|
||
public BlueprintData( | ||
final String url ) | ||
{ | ||
try | ||
{ | ||
if ( url != null ) | ||
{ | ||
this.url = new URL( url ); | ||
final Thread t = new Thread( this ); | ||
t.setName( "Blueprint-" + url ); | ||
t.start(); | ||
} | ||
} | ||
catch ( final MalformedURLException e ) | ||
{ | ||
state = EnumLoadState.FAILED; | ||
Log.logError( "Blueprint URL is invalid.", e ); | ||
} | ||
} | ||
|
||
private long getCurrentTime() | ||
{ | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
synchronized public void updateTime() | ||
{ | ||
lastNeeded = getCurrentTime(); | ||
} | ||
|
||
synchronized public boolean isExpired() | ||
{ | ||
return getCurrentTime() - lastNeeded > ChiselsAndBits.getConfig().blueprintExpireTime; | ||
} | ||
|
||
synchronized public EnumLoadState getState() | ||
{ | ||
updateTime(); | ||
return state; | ||
} | ||
|
||
public void setLocalSource( | ||
final String string ) throws MalformedURLException, UnsupportedEncodingException | ||
{ | ||
url = new URL( "file", ClientSide.instance.getLocalName(), 0, "/" + URLEncoder.encode( string, "UTF-8" ) ); | ||
} | ||
|
||
public void setURLSource( | ||
final URL url2 ) | ||
{ | ||
url = url2; | ||
} | ||
|
||
public void loadData( | ||
InputStream is ) throws IOException | ||
{ | ||
is = new BufferedInputStream( is ); | ||
EnumLoadState result = EnumLoadState.FAILED; | ||
|
||
try | ||
{ | ||
final byte[] peek = new byte[4]; | ||
is.mark( peek.length ); | ||
is.read( peek ); | ||
is.reset(); | ||
|
||
// load png? or is it text? | ||
if ( peek[0] == 0x89 && peek[1] == 0x50 && peek[2] == 0x4E && peek[3] == 0x47 ) | ||
{ | ||
data = new ShareWorldData( ImageIO.read( is ) ); | ||
} | ||
else | ||
{ | ||
final StringBuilder builder = new StringBuilder(); | ||
final byte[] buffer = new byte[2048]; | ||
int read = 0; | ||
|
||
do | ||
{ | ||
read = is.read( buffer ); | ||
|
||
// C&B data should be visible as ascii if utf8 or various | ||
// iso | ||
// formats, probably the best approach to prevent utf-8 from | ||
// being confused from other charsets | ||
if ( read > 0 ) | ||
{ | ||
builder.append( new String( buffer, 0, read, "ASCII" ) ); | ||
} | ||
} | ||
while ( read > 0 ); | ||
|
||
data = new ShareWorldData( builder.toString() ); | ||
} | ||
|
||
result = EnumLoadState.LOADED; | ||
} | ||
finally | ||
{ | ||
state = result; | ||
} | ||
} | ||
|
||
public void loadData( | ||
final byte[] bs ) throws IOException | ||
{ | ||
EnumLoadState result = EnumLoadState.FAILED; | ||
try | ||
{ | ||
data = new ShareWorldData( bs ); | ||
result = EnumLoadState.LOADED; | ||
} | ||
finally | ||
{ | ||
state = result; | ||
} | ||
} | ||
|
||
@Override | ||
public void run() | ||
{ | ||
EnumLoadState result = EnumLoadState.FAILED; | ||
try | ||
{ | ||
if ( url.getProtocol().equals( "file" ) ) | ||
{ | ||
if ( url.getHost().equals( ClientSide.instance.getLocalName() ) ) | ||
{ | ||
loadData( new FileInputStream( new File( URLDecoder.decode( url.getFile().substring( 1 ), "UTF-8" ) ) ) ); | ||
result = EnumLoadState.LOADED; | ||
return; | ||
} | ||
|
||
return; | ||
} | ||
|
||
final URLConnection src = url.openConnection(); | ||
loadData( src.getInputStream() ); | ||
result = EnumLoadState.LOADED; | ||
} | ||
catch ( final IOException e ) | ||
{ | ||
Log.logError( "Unload to download Blueprint.", e ); | ||
} | ||
finally | ||
{ | ||
state = result; | ||
} | ||
} | ||
|
||
public byte[] getStuctureData() throws IOException | ||
{ | ||
return data.getStuctureData(); | ||
} | ||
|
||
public int getXSize() | ||
{ | ||
return data.getXSize(); | ||
} | ||
|
||
public int getYSize() | ||
{ | ||
return data.getYSize(); | ||
} | ||
|
||
public int getZSize() | ||
{ | ||
return data.getZSize(); | ||
} | ||
|
||
public String getURL() | ||
{ | ||
return url == null ? "" : url.toString(); | ||
} | ||
|
||
@Override | ||
public IVoxelAccess get( | ||
final int x, | ||
final int y, | ||
final int z ) | ||
{ | ||
return data.getBlob( x, y, z ); | ||
} | ||
|
||
public IBlockState getStateAt( | ||
final BlockPos p ) | ||
{ | ||
return data.getStateAt( p ); | ||
} | ||
|
||
public TileEntityBlockChiseled getTileAt( | ||
final BlockPos p ) | ||
{ | ||
return data.getTileAt( p ); | ||
} | ||
|
||
} |
Oops, something went wrong.