-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e32004
commit 527264d
Showing
31 changed files
with
689 additions
and
159 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"name": "oc.pack", | ||
"author": "oc.author", | ||
"version": "0.1.0-alpha", | ||
"coreVersion": "0.1.0-alpha" | ||
"version": "0.2.0-alpha", | ||
"coreVersion": "0.2.0-alpha", | ||
"ignoreEntries": [ "com" ] | ||
} |
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
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
112 changes: 112 additions & 0 deletions
112
src/main/java/com/mcwb/client/player/OpLoadAmmoClient.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,112 @@ | ||
package com.mcwb.client.player; | ||
|
||
import com.mcwb.client.MCWBClient; | ||
import com.mcwb.client.input.InputHandler; | ||
import com.mcwb.common.IAutowirePacketHandler; | ||
import com.mcwb.common.ammo.IAmmoType; | ||
import com.mcwb.common.gun.IMag; | ||
import com.mcwb.common.item.IItem; | ||
import com.mcwb.common.item.IItemType; | ||
import com.mcwb.common.item.IItemTypeHost; | ||
import com.mcwb.common.network.PacketCode; | ||
import com.mcwb.common.network.PacketCodeAssist; | ||
import com.mcwb.common.network.PacketCodeAssist.Code; | ||
import com.mcwb.common.operation.IOperation; | ||
import com.mcwb.common.operation.Operation; | ||
|
||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
@SideOnly( Side.CLIENT ) | ||
public class OpLoadAmmoClient extends Operation< IMag< ? > > implements IAutowirePacketHandler | ||
{ | ||
protected int invSlot; | ||
|
||
public OpLoadAmmoClient() { super( null, null, null ); } | ||
|
||
public IOperation reset( IMag< ? > mag ) | ||
{ | ||
this.player = MCWBClient.MC.player; | ||
this.contexted = mag; | ||
this.controller = mag.pushAmmoController(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public IOperation launch( IOperation oldOp ) | ||
{ | ||
switch( 0 ) | ||
{ | ||
default: | ||
if( this.contexted.isFull() ) break; | ||
|
||
this.invSlot = this.getValidAmmoSlot( InputHandler.CO.down ? 1 : 0 ); | ||
if( this.invSlot == -1 ) break; | ||
|
||
this.clearProgress(); | ||
this.sendToServer( new PacketCodeAssist( Code.LOAD_AMMO, this.invSlot ) ); | ||
return this; | ||
} | ||
|
||
return NONE; | ||
} | ||
|
||
@Override | ||
public IOperation terminate() | ||
{ | ||
this.sendToServer( new PacketCode( PacketCode.Code.TERMINATE_OP ) ); | ||
return NONE; | ||
} | ||
|
||
@Override | ||
public IOperation onInHandStackChange( IItem newItem ) | ||
{ | ||
if( ( ( IMag< ? > ) newItem ).isFull() ) | ||
return this.terminate(); | ||
|
||
this.contexted = ( IMag< ? > ) newItem; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected IOperation onComplete() | ||
{ | ||
this.clearProgress(); | ||
return this.launch( this ); | ||
} | ||
|
||
@Override | ||
protected void doHandleEffect() | ||
{ | ||
final ItemStack stack = this.player.inventory.getStackInSlot( this.invSlot ); | ||
final IItemType type = IItemTypeHost.getTypeOrDefault( stack ); | ||
if( !( type instanceof IAmmoType ) ) return; | ||
|
||
final IAmmoType ammo = ( IAmmoType ) type; | ||
if( !this.contexted.isAllowed( ammo ) ) return; | ||
|
||
this.contexted.pushAmmo( ammo ); | ||
// if( !this.player.capabilities.isCreativeMode ) | ||
stack.shrink( 1 ); | ||
} | ||
|
||
protected int getValidAmmoSlot( int offset ) | ||
{ | ||
final InventoryPlayer inv = this.player.inventory; | ||
|
||
int invSlot = -1; | ||
for( int i = 0, size = inv.getSizeInventory(); offset >= 0 && i < size; ++i ) | ||
{ | ||
final ItemStack stack = inv.getStackInSlot( i ); | ||
final IItemType type = IItemTypeHost.getTypeOrDefault( stack ); | ||
if( type instanceof IAmmoType && this.contexted.isAllowed( ( IAmmoType ) type ) ) | ||
{ | ||
invSlot = i; | ||
--offset; | ||
} | ||
} | ||
return invSlot; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
src/main/java/com/mcwb/client/player/OpLoadMagClient.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,101 @@ | ||
package com.mcwb.client.player; | ||
|
||
import com.mcwb.client.MCWBClient; | ||
import com.mcwb.common.IAutowirePacketHandler; | ||
import com.mcwb.common.gun.IGun; | ||
import com.mcwb.common.gun.IMag; | ||
import com.mcwb.common.item.IItem; | ||
import com.mcwb.common.item.IItemTypeHost; | ||
import com.mcwb.common.network.PacketCode; | ||
import com.mcwb.common.network.PacketCodeAssist; | ||
import com.mcwb.common.network.PacketCodeAssist.Code; | ||
import com.mcwb.common.operation.IOperation; | ||
import com.mcwb.common.operation.Operation; | ||
|
||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
@SideOnly( Side.CLIENT ) | ||
public class OpLoadMagClient extends Operation< IGun< ? > > implements IAutowirePacketHandler | ||
{ | ||
protected int invSlot; | ||
|
||
protected IMag< ? > mag; | ||
|
||
public OpLoadMagClient() { super( null, null, null ); } | ||
|
||
public IOperation reset( IGun< ? > gun ) | ||
{ | ||
this.player = MCWBClient.MC.player; | ||
this.contexted = gun; | ||
this.controller = gun.loadMagController(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public IOperation launch( IOperation oldOp ) | ||
{ | ||
switch( 0 ) | ||
{ | ||
default: | ||
if( this.contexted.hasMag() ) break; | ||
|
||
this.invSlot = this.getValidMagSlot(); | ||
if( this.invSlot == -1 ) break; | ||
|
||
final ItemStack stack = this.player.inventory.getStackInSlot( this.invSlot ); | ||
this.mag = ( IMag< ? > ) IItemTypeHost.getTypeA( stack ).getContexted( stack ); | ||
|
||
this.clearProgress(); | ||
this.sendToServer( new PacketCodeAssist( Code.LOAD_MAG, this.invSlot ) ); | ||
return this; | ||
} | ||
|
||
return NONE; | ||
} | ||
|
||
@Override | ||
public IOperation terminate() | ||
{ | ||
this.sendToServer( new PacketCode( PacketCode.Code.TERMINATE_OP ) ); | ||
return NONE; | ||
} | ||
|
||
@Override | ||
public IOperation onInHandStackChange( IItem newItem ) | ||
{ | ||
if( ( ( IGun< ? > ) newItem ).hasMag() ) | ||
return this.terminate(); | ||
|
||
this.contexted = ( IGun< ? > ) newItem; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected void doHandleEffect() | ||
{ | ||
// Calling install will change the state of the mag itself, hence copy before use | ||
// final ItemStack stack = this.player.inventory.getStackInSlot( this.invSlot ).copy(); | ||
// final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); | ||
// if( !( item instanceof IMag< ? > ) ) return; | ||
// | ||
// final IMag< ? > mag = ( IMag< ? > ) item; | ||
// if( this.contexted.isAllowed( mag ) ) | ||
// this.contexted.loadMag( mag ); | ||
} | ||
|
||
protected int getValidMagSlot() | ||
{ | ||
final InventoryPlayer inv = this.player.inventory; | ||
for( int i = 0, size = inv.getSizeInventory(); i < size; ++i ) | ||
{ | ||
final ItemStack stack = inv.getStackInSlot( i ); | ||
final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); | ||
if( item instanceof IMag< ? > && this.contexted.isAllowed( ( IMag< ? > ) item ) ) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
} |
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
Oops, something went wrong.