Skip to content

Commit

Permalink
Rotate X / Z buttons. Implements #114
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Nov 10, 2018
1 parent 3c4be46 commit 506c988
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 24 deletions.
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nonnull;

import mod.chiselsandbits.api.EventBlockBitModification;
import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.chiseledblock.data.BitLocation;
import mod.chiselsandbits.chiseledblock.data.IntegerBox;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
Expand Down Expand Up @@ -38,7 +39,9 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
Expand Down Expand Up @@ -481,18 +484,42 @@ public void scroll(
final int dwheel )
{
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = dwheel;
p.axis = Axis.Y;
p.rotation = dwheel > 0 ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
NetworkRouter.instance.sendToServer( p );
}

@Override
public void rotate(
final ItemStack stack,
final int rotationDirection )
final Axis axis,
final Rotation rotation )
{
EnumFacing side = ModUtil.getSide( stack );

side = rotationDirection > 0 ? side.rotateY() : side.rotateYCCW();
if ( axis == Axis.Y )
{
switch ( rotation )
{
case CLOCKWISE_180:
side = side.rotateY();
case CLOCKWISE_90:
side = side.rotateY();
break;
case COUNTERCLOCKWISE_90:
side = side.rotateYCCW();
break;
default:
case NONE:
break;
}
}
else
{
IBitAccess ba = ChiselsAndBits.getApi().createBitItem( stack );
ba.rotate( axis, rotation );
stack.setTagCompound( ba.getBitsAsItem( side, ChiselsAndBits.getApi().getItemType( stack ), false ).getTagCompound() );
}

ModUtil.setSide( stack, side );
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mod/chiselsandbits/client/gui/ButtonAction.java
Expand Up @@ -5,6 +5,9 @@ public enum ButtonAction
UNDO,
REDO,

ROLL_X,
ROLL_Z,

REPLACE_TOGGLE,

WHITE,
Expand Down
Expand Up @@ -205,6 +205,12 @@ public void drawScreen(
btns.add( new MenuButton( "mod.chiselsandbits.other.undo", ButtonAction.UNDO, text_distnace, -20, ClientSide.undoIcon, EnumFacing.EAST ) );
btns.add( new MenuButton( "mod.chiselsandbits.other.redo", ButtonAction.REDO, text_distnace, 4, ClientSide.redoIcon, EnumFacing.EAST ) );

if ( tool == ChiselToolType.CHISELED_BLOCK || tool == ChiselToolType.NEGATIVEPATTERN || tool == ChiselToolType.POSITIVEPATTERN )
{
btns.add( new MenuButton( "mod.chiselsandbits.other.roll_x", ButtonAction.ROLL_X, -text_distnace - 18, -20, ClientSide.roll_x, EnumFacing.WEST ) );
btns.add( new MenuButton( "mod.chiselsandbits.other.roll_z", ButtonAction.ROLL_Z, -text_distnace - 18, 4, ClientSide.roll_z, EnumFacing.WEST ) );
}

if ( tool == ChiselToolType.TAPEMEASURE )
{
final int colorSize = EnumDyeColor.values().length / 4 * 24 - 4;
Expand Down Expand Up @@ -415,7 +421,11 @@ else if ( -0.2 <= x && x <= 0.2 )
{
final String text = DeprecationHelper.translateToLocal( btn.name );

if ( btn.textSide == EnumFacing.EAST )
if ( btn.textSide == EnumFacing.WEST )
{
fontRendererObj.drawStringWithShadow( text, (int) ( middle_x + btn.x1 - 8 ) - fontRendererObj.getStringWidth( text ), (int) ( middle_y + btn.y1 + 6 ), 0xffffffff );
}
else if ( btn.textSide == EnumFacing.EAST )
{
fontRendererObj.drawStringWithShadow( text, (int) ( middle_x + btn.x2 + 8 ), (int) ( middle_y + btn.y1 + 6 ), 0xffffffff );
}
Expand Down
37 changes: 32 additions & 5 deletions src/main/java/mod/chiselsandbits/core/ClientSide.java
Expand Up @@ -107,6 +107,7 @@
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -401,6 +402,9 @@ public Map<IBlockState, ModelResourceLocation> putStateModelLocations(
public static TextureAtlasSprite swapIcon;
public static TextureAtlasSprite placeIcon;

public static TextureAtlasSprite roll_x;
public static TextureAtlasSprite roll_z;

@SubscribeEvent
void registerIconTextures(
final TextureStitchEvent.Pre ev )
Expand All @@ -411,6 +415,8 @@ void registerIconTextures(
undoIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/undo" ) );
redoIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/redo" ) );
trashIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/trash" ) );
roll_x = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/roll_x" ) );
roll_z = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/roll_z" ) );

for ( final ChiselMode mode : ChiselMode.values() )
{
Expand Down Expand Up @@ -521,6 +527,20 @@ public void onRenderGUI(
ClientSide.instance.playRadialMenu();
switch ( ChiselsAndBitsMenu.instance.doAction )
{
case ROLL_X:
PacketRotateVoxelBlob pri = new PacketRotateVoxelBlob();
pri.axis = Axis.X;
pri.rotation = Rotation.CLOCKWISE_90;
NetworkRouter.instance.sendToServer( pri );
break;

case ROLL_Z:
PacketRotateVoxelBlob pri2 = new PacketRotateVoxelBlob();
pri2.axis = Axis.Z;
pri2.rotation = Rotation.CLOCKWISE_90;
NetworkRouter.instance.sendToServer( pri2 );
break;

case REPLACE_TOGGLE:
ChiselsAndBits.getConfig().replaceingBits = !ChiselsAndBits.getConfig().replaceingBits;
ReflectionWrapper.instance.clearHighlightedStack();
Expand Down Expand Up @@ -671,7 +691,7 @@ public void onRenderGUI(
final ItemStack stack = mc.thePlayer.inventory.mainInventory.get( slot );
if ( stack != null && stack.getItem() instanceof ItemChisel )
{
final ChiselToolType toolType = getToolTypeForItemm( stack );
final ChiselToolType toolType = getToolTypeForItem( stack );
IToolMode mode = toolType.getMode( stack );

if ( !ChiselsAndBits.getConfig().perChiselMode && tool == ChiselToolType.CHISEL )
Expand Down Expand Up @@ -752,10 +772,10 @@ public ChiselToolType getHeldToolType(
}

final ItemStack is = player.getHeldItem( enumHand );
return getToolTypeForItemm( is );
return getToolTypeForItem( is );
}

private ChiselToolType getToolTypeForItemm(
private ChiselToolType getToolTypeForItem(
final ItemStack is )
{
if ( is != null && is.getItem() instanceof ItemChisel )
Expand All @@ -768,6 +788,11 @@ private ChiselToolType getToolTypeForItemm(
return ChiselToolType.BIT;
}

if ( is != null && is.getItem() instanceof ItemBlockChiseled )
{
return ChiselToolType.CHISELED_BLOCK;
}

if ( is != null && is.getItem() == ChiselsAndBits.getItems().itemTapeMeasure )
{
return ChiselToolType.TAPEMEASURE;
Expand Down Expand Up @@ -852,7 +877,8 @@ public void interaction(
{
rotateTimer = Stopwatch.createStarted();
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = 1;
p.axis = Axis.Y;
p.rotation = Rotation.COUNTERCLOCKWISE_90;
NetworkRouter.instance.sendToServer( p );
}
}
Expand All @@ -863,7 +889,8 @@ public void interaction(
{
rotateTimer = Stopwatch.createStarted();
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = -1;
p.axis = Axis.Y;
p.rotation = Rotation.CLOCKWISE_90;
NetworkRouter.instance.sendToServer( p );
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mod/chiselsandbits/helpers/ChiselToolType.java
Expand Up @@ -17,9 +17,11 @@ public enum ChiselToolType
CHISEL( true, true ),
BIT( true, false ),

CHISELED_BLOCK( true, false ),

POSITIVEPATTERN( true, true ),
TAPEMEASURE( true, true ),
NEGATIVEPATTERN( false, false ),
NEGATIVEPATTERN( true, false ),
MIRRORPATTERN( false, false );

final private boolean hasMenu;
Expand Down
@@ -1,12 +1,14 @@
package mod.chiselsandbits.interfaces;

import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.Rotation;

public interface IVoxelBlobItem
{

void rotate(
ItemStack is,
int rotationDirection );

final ItemStack is,
final Axis axis,
final Rotation rotation );
}
42 changes: 35 additions & 7 deletions src/main/java/mod/chiselsandbits/items/ItemNegativePrint.java
Expand Up @@ -5,6 +5,7 @@

import javax.annotation.Nonnull;

import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.api.VoxelStats;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.NBTBlobConverter;
Expand Down Expand Up @@ -38,6 +39,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -151,7 +153,8 @@ public EnumActionResult onItemUse(
final ItemStack stack = player.getHeldItem( hand );
final IBlockState blkstate = world.getBlockState( pos );

if ( ItemChiseledBit.checkRequiredSpace( player, blkstate ) ) {
if ( ItemChiseledBit.checkRequiredSpace( player, blkstate ) )
{
return EnumActionResult.FAIL;
}

Expand Down Expand Up @@ -307,7 +310,7 @@ protected void applyPrint(
BitInventoryFeeder feeder = new BitInventoryFeeder( who, world );
for ( final EntityItem ei : spawnlist )
{
feeder.addItem(ei);
feeder.addItem( ei );
}
}

Expand All @@ -318,23 +321,48 @@ public void scroll(
final int dwheel )
{
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = dwheel;
p.axis = Axis.Y;
p.rotation = dwheel > 0 ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
NetworkRouter.instance.sendToServer( p );
}

@Override
public void rotate(
final ItemStack stack,
final int rotationDirection )
final Axis axis,
final Rotation rotation )
{
EnumFacing side = ModUtil.getSide( stack );

if ( side.getAxis() == Axis.Y )
if ( axis == Axis.Y )
{
if ( side.getAxis() == Axis.Y )
{
side = EnumFacing.NORTH;
}

switch ( rotation )
{
case CLOCKWISE_180:
side = side.rotateY();
case CLOCKWISE_90:
side = side.rotateY();
break;
case COUNTERCLOCKWISE_90:
side = side.rotateYCCW();
break;
default:
case NONE:
break;
}
}
else
{
side = EnumFacing.NORTH;
IBitAccess ba = ChiselsAndBits.getApi().createBitItem( stack );
ba.rotate( axis, rotation );
stack.setTagCompound( ba.getBitsAsItem( side, ChiselsAndBits.getApi().getItemType( stack ), false ).getTagCompound() );
}

side = rotationDirection > 0 ? side.rotateY() : side.rotateYCCW();
ModUtil.setSide( stack, side );
}

Expand Down
Expand Up @@ -5,11 +5,14 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.Rotation;

public class PacketRotateVoxelBlob extends ModPacket
{

public int rotationDirection;
public Axis axis;
public Rotation rotation;

@Override
public void server(
Expand All @@ -18,22 +21,24 @@ public void server(
final ItemStack is = player.getHeldItemMainhand();
if ( is != null && is.getItem() instanceof IVoxelBlobItem )
{
( (IVoxelBlobItem) is.getItem() ).rotate( is, rotationDirection );
( (IVoxelBlobItem) is.getItem() ).rotate( is, axis, rotation );
}
}

@Override
public void getPayload(
final PacketBuffer buffer )
{
buffer.writeInt( rotationDirection );
buffer.writeEnumValue( axis );
buffer.writeEnumValue( rotation );
}

@Override
public void readPayload(
final PacketBuffer buffer )
{
rotationDirection = buffer.readInt();
axis = buffer.readEnumValue( Axis.class );
rotation = buffer.readEnumValue( Rotation.class );
}

}
3 changes: 3 additions & 0 deletions src/main/resources/assets/chiselsandbits/lang/en_us.lang
Expand Up @@ -82,6 +82,9 @@ mod.chiselsandbits.other.pickbit=Pick Bit
mod.chiselsandbits.other.offgrid=Place Off Grid
mod.chiselsandbits.other.add_to_clipboard=Pick Block to Clipboard

mod.chiselsandbits.other.roll_x=Rotate X Clockwise
mod.chiselsandbits.other.roll_z=Rotate Z Clockwise

mod.chiselsandbits.help.shiftdetails=<Hold Shift For Details>
mod.chiselsandbits.help.empty=Empty
mod.chiselsandbits.help.filled=Filled
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 506c988

Please sign in to comment.