From 527264d4e531251b6e8c28a93f8bb8fdf20223ae Mon Sep 17 00:00:00 2001 From: Giant_Salted_Fish Date: Mon, 6 Mar 2023 16:21:56 +0800 Subject: [PATCH] For a dev release version --- build.gradle | 7 +- .../assets/mcwb/lang/en_us.lang | 7 + .../assets/mcwb/lang/zh_cn.lang | 9 +- run/mcwb/Octagon Weapons/pack.json | 5 +- .../com/mcwb/client/gun/GunPartRenderer.java | 6 +- .../java/com/mcwb/client/gun/GunRenderer.java | 5 +- .../mcwb/client/gun/OpticSightRenderer.java | 6 +- .../mcwb/client/player/OpLoadAmmoClient.java | 112 +++++++++++++++ .../mcwb/client/player/OpLoadMagClient.java | 101 ++++++++++++++ .../mcwb/client/player/OpModifyClient.java | 3 +- .../client/player/OpUnloadAmmoClient.java | 64 +++++++++ .../mcwb/client/player/OpUnloadMagClient.java | 58 ++++++++ src/main/java/com/mcwb/common/MCWB.java | 2 +- .../java/com/mcwb/common/gun/GunType.java | 37 +++++ .../java/com/mcwb/common/gun/MagType.java | 58 +++++++- .../mcwb/common/item/ModifiableItemType.java | 10 +- .../com/mcwb/common/load/BuildableLoader.java | 2 +- .../com/mcwb/common/network/PacketCode.java | 56 ++++---- .../mcwb/common/network/PacketCodeAssist.java | 82 +++++++++++ .../mcwb/common/network/PacketHandler.java | 2 +- .../com/mcwb/common/network/PacketModify.java | 2 +- .../com/mcwb/common/operation/Operation.java | 22 +-- .../common/operation/TogglableOperation.java | 3 +- .../java/com/mcwb/common/pack/FolderPack.java | 2 +- .../java/com/mcwb/common/pack/JarPack.java | 9 +- .../java/com/mcwb/common/pack/LocalPack.java | 11 ++ .../com/mcwb/common/player/OpLoadAmmo.java | 7 +- .../com/mcwb/common/player/OpLoadMag.java | 10 +- .../com/mcwb/common/player/OpUnloadAmmo.java | 9 +- .../com/mcwb/common/player/OpUnloadMag.java | 9 +- src/main/java/com/mcwb/devtool/Dev.java | 132 +++++++++--------- 31 files changed, 689 insertions(+), 159 deletions(-) create mode 100644 src/main/java/com/mcwb/client/player/OpLoadAmmoClient.java create mode 100644 src/main/java/com/mcwb/client/player/OpLoadMagClient.java create mode 100644 src/main/java/com/mcwb/client/player/OpUnloadAmmoClient.java create mode 100644 src/main/java/com/mcwb/client/player/OpUnloadMagClient.java create mode 100644 src/main/java/com/mcwb/common/network/PacketCodeAssist.java diff --git a/build.gradle b/build.gradle index 94388d1..32c9cf4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +// See https://gitlab.com/gofancy/fancygradle plugins { id 'eclipse' id 'maven-publish' @@ -5,9 +6,9 @@ plugins { id 'wtf.gofancy.fancygradle' version '1.1.+' } -version = '1.0' -group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'modid' +version = '0.2.0-alpha' +group = 'com.mcwb' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = '[MC-1.12.2] FMUM 2.0 v' + version + ' - 2023-3-6' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. diff --git a/run/mcwb/Octagon Weapons/assets/mcwb/lang/en_us.lang b/run/mcwb/Octagon Weapons/assets/mcwb/lang/en_us.lang index e971bdf..067cc1f 100644 --- a/run/mcwb/Octagon Weapons/assets/mcwb/lang/en_us.lang +++ b/run/mcwb/Octagon Weapons/assets/mcwb/lang/en_us.lang @@ -64,6 +64,13 @@ item.cic_is9_rear_sight-tritium_green.name=CIC IS-9 Rear Sight - Tritium Green item.cic_is9_rear_sight-tritium_red.name=CIC IS-9 Rear Sight - Tritium Red item.cic_is9_rear_sight-tritium_white.name=CIC IS-9 Rear Sight - Tritium White +# Optic sight +item.kobra_ekp8mpp.name=Kobra EKP-8M-PP +item.eotech_exps30.name=Eotech EXPS3-0 + +# Grip +item.td_grip.name=TD Grip + # Muzzle item.556mm_thread_protector.name=5.56mm Thread Protector diff --git a/run/mcwb/Octagon Weapons/assets/mcwb/lang/zh_cn.lang b/run/mcwb/Octagon Weapons/assets/mcwb/lang/zh_cn.lang index 11bbf2c..9da0358 100644 --- a/run/mcwb/Octagon Weapons/assets/mcwb/lang/zh_cn.lang +++ b/run/mcwb/Octagon Weapons/assets/mcwb/lang/zh_cn.lang @@ -21,7 +21,7 @@ item.hk416_165_barrel.name=H&K416 16.5英寸枪管 item.hk416_20_barrel.name=H&K416 20英寸枪管 item.hk416_barrel_extension.name=H&K416 枪管节套 item.hk416_barrel_nut.name=H&K416 枪管螺母 -item.hk416_bolt.name=H&K416 枪击组件 +item.hk416_bolt.name=H&K416 枪机组件 item.hk416_buffer_tube.name=H&K416 缓冲管 item.hk416_charge_handle.name=H&K416 拉机柄 item.hk416_dust_cover.name=H&K416 防尘盖 @@ -64,6 +64,13 @@ item.cic_is9_rear_sight-tritium_green.name=CIC IS-9 照门 - 绿氚光 item.cic_is9_rear_sight-tritium_red.name=CIC IS-9 照门 - 红氚光 item.cic_is9_rear_sight-tritium_white.name=CIC IS-9 照门 - 白氚光 +# 光瞄 +item.kobra_ekp8mpp.name=Kobra EKP-8M-PP 反射式红点瞄具 +item.eotech_exps30.name=Eotech EXPS3-0 全息瞄具 + +# 握把 +item.td_grip.name=TD 握把 + # 膛口装置 item.556mm_thread_protector.name=5.56mm 螺纹保护帽 diff --git a/run/mcwb/Octagon Weapons/pack.json b/run/mcwb/Octagon Weapons/pack.json index 3ad3a89..90fcc5a 100644 --- a/run/mcwb/Octagon Weapons/pack.json +++ b/run/mcwb/Octagon Weapons/pack.json @@ -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" ] } diff --git a/src/main/java/com/mcwb/client/gun/GunPartRenderer.java b/src/main/java/com/mcwb/client/gun/GunPartRenderer.java index 9809020..0e4baed 100644 --- a/src/main/java/com/mcwb/client/gun/GunPartRenderer.java +++ b/src/main/java/com/mcwb/client/gun/GunPartRenderer.java @@ -3,6 +3,7 @@ import com.mcwb.client.item.ModifiableItemRenderer; import com.mcwb.client.render.IAnimator; import com.mcwb.client.render.IRenderer; +import com.mcwb.common.MCWB; import com.mcwb.common.gun.IGunPart; import com.mcwb.common.load.BuildableLoader; import com.mcwb.util.ArmTracker; @@ -17,7 +18,10 @@ public class GunPartRenderer< T extends IGunPart< ? > > extends ModifiableItemRenderer< T > implements IGunPartRenderer< T > { public static final BuildableLoader< IRenderer > - LOADER = new BuildableLoader<>( "gun_part", GunPartRenderer.class ); + LOADER = new BuildableLoader<>( + "gun_part", + json -> MCWB.GSON.fromJson( json, GunPartRenderer.class ) + ); @Override public void setupLeftArmToRender( ArmTracker leftArm, IAnimator animator ) diff --git a/src/main/java/com/mcwb/client/gun/GunRenderer.java b/src/main/java/com/mcwb/client/gun/GunRenderer.java index c895adb..a70f2e8 100644 --- a/src/main/java/com/mcwb/client/gun/GunRenderer.java +++ b/src/main/java/com/mcwb/client/gun/GunRenderer.java @@ -9,6 +9,7 @@ import com.mcwb.client.player.PlayerPatchClient; import com.mcwb.client.render.IAnimator; import com.mcwb.client.render.IRenderer; +import com.mcwb.common.MCWB; import com.mcwb.common.gun.IGun; import com.mcwb.common.load.BuildableLoader; import com.mcwb.common.load.IContentProvider; @@ -30,8 +31,8 @@ @SideOnly( Side.CLIENT ) public class GunRenderer< T extends IGun< ? > > extends GunPartRenderer< T > { - public static final BuildableLoader< IRenderer > - LOADER = new BuildableLoader<>( "gun", GunRenderer.class ); + public static final BuildableLoader< IRenderer > LOADER = + new BuildableLoader<>( "gun", json -> MCWB.GSON.fromJson( json, GunRenderer.class ) ); protected static final Vec3f HOLD_POS = new Vec3f( -14F / 160F, -72F / 160F, 87.5F / 160F ); protected static final Vec3f HOLD_ROT = new Vec3f( 0F, 0F, -5F ); diff --git a/src/main/java/com/mcwb/client/gun/OpticSightRenderer.java b/src/main/java/com/mcwb/client/gun/OpticSightRenderer.java index 443655c..24b84ec 100644 --- a/src/main/java/com/mcwb/client/gun/OpticSightRenderer.java +++ b/src/main/java/com/mcwb/client/gun/OpticSightRenderer.java @@ -10,6 +10,7 @@ import com.mcwb.client.module.IDeferredRenderer; import com.mcwb.client.render.IAnimator; import com.mcwb.client.render.IRenderer; +import com.mcwb.common.MCWB; import com.mcwb.common.gun.IGunPart; import com.mcwb.common.load.BuildableLoader; import com.mcwb.common.load.IContentProvider; @@ -25,7 +26,10 @@ public class OpticSightRenderer< T extends IGunPart< ? > > extends GunPartRenderer< T > { public static final BuildableLoader< IRenderer > - LOADER = new BuildableLoader<>( "optic_sight", OpticSightRenderer.class ); + LOADER = new BuildableLoader<>( + "optic_sight", + json -> MCWB.GSON.fromJson( json, OpticSightRenderer.class ) + ); @SerializedName( value = "lenMeshPath", alternate = "lenMesh" ) protected String lenMeshPath = ""; diff --git a/src/main/java/com/mcwb/client/player/OpLoadAmmoClient.java b/src/main/java/com/mcwb/client/player/OpLoadAmmoClient.java new file mode 100644 index 0000000..2152cf7 --- /dev/null +++ b/src/main/java/com/mcwb/client/player/OpLoadAmmoClient.java @@ -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; + } +} diff --git a/src/main/java/com/mcwb/client/player/OpLoadMagClient.java b/src/main/java/com/mcwb/client/player/OpLoadMagClient.java new file mode 100644 index 0000000..f241c2e --- /dev/null +++ b/src/main/java/com/mcwb/client/player/OpLoadMagClient.java @@ -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; + } +} diff --git a/src/main/java/com/mcwb/client/player/OpModifyClient.java b/src/main/java/com/mcwb/client/player/OpModifyClient.java index 7aec8f1..74be33f 100644 --- a/src/main/java/com/mcwb/client/player/OpModifyClient.java +++ b/src/main/java/com/mcwb/client/player/OpModifyClient.java @@ -96,7 +96,7 @@ public OpModifyClient() { return this.renderDelegate != null ? ( T ) this.renderDelegate : original; } - public OpModifyClient reset() + public IOperation reset() { this.player = MCWBClient.MC.player; this.stack = this.player.inventory.getCurrentItem(); @@ -381,7 +381,6 @@ public IOperation launch( IOperation oldOp ) return super.launch( oldOp ); } - @Override public IOperation toggle() { diff --git a/src/main/java/com/mcwb/client/player/OpUnloadAmmoClient.java b/src/main/java/com/mcwb/client/player/OpUnloadAmmoClient.java new file mode 100644 index 0000000..c1481ce --- /dev/null +++ b/src/main/java/com/mcwb/client/player/OpUnloadAmmoClient.java @@ -0,0 +1,64 @@ +package com.mcwb.client.player; + +import com.mcwb.client.MCWBClient; +import com.mcwb.common.IAutowirePacketHandler; +import com.mcwb.common.gun.IMag; +import com.mcwb.common.item.IItem; +import com.mcwb.common.network.PacketCode; +import com.mcwb.common.network.PacketCode.Code; +import com.mcwb.common.operation.IOperation; +import com.mcwb.common.operation.Operation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly( Side.CLIENT ) +public class OpUnloadAmmoClient extends Operation< IMag< ? > > implements IAutowirePacketHandler +{ + public OpUnloadAmmoClient() { super( null, null, null ); } + + public IOperation reset( IMag< ? > mag ) + { + this.player = MCWBClient.MC.player; + this.contexted = mag; + this.controller = mag.popAmmoController(); + return this; + } + + @Override + public IOperation launch( IOperation oldOp ) + { + if( this.contexted.isEmpty() ) return NONE; + + this.clearProgress(); + this.sendToServer( new PacketCode( Code.UNLOAD_AMMO ) ); + return this; + } + + @Override + public IOperation terminate() + { + this.sendToServer( new PacketCode( Code.TERMINATE_OP ) ); + return NONE; + } + + @Override + public IOperation onInHandStackChange( IItem newItem ) + { + if( ( ( IMag< ? > ) newItem ).isEmpty() ) + return this.terminate(); + + this.contexted = ( IMag< ? > ) newItem; + return this; + } + + @Override + protected IOperation onComplete() + { + this.clearProgress(); + return this.launch( this ); + } + + @Override + protected void doHandleEffect() { this.contexted.popAmmo(); } +} diff --git a/src/main/java/com/mcwb/client/player/OpUnloadMagClient.java b/src/main/java/com/mcwb/client/player/OpUnloadMagClient.java new file mode 100644 index 0000000..77208d9 --- /dev/null +++ b/src/main/java/com/mcwb/client/player/OpUnloadMagClient.java @@ -0,0 +1,58 @@ +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.item.IItem; +import com.mcwb.common.network.PacketCode; +import com.mcwb.common.network.PacketCode.Code; +import com.mcwb.common.operation.IOperation; +import com.mcwb.common.operation.Operation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly( Side.CLIENT ) +public class OpUnloadMagClient extends Operation< IGun< ? > > implements IAutowirePacketHandler +{ + public OpUnloadMagClient() { super( null, null, null ); } + + public IOperation reset( IGun< ? > gun ) + { + this.player = MCWBClient.MC.player; + this.contexted = gun; + this.controller = gun.unloadMagController(); + return this; + } + + @Override + public IOperation launch( IOperation oldOp ) + { + if( !this.contexted.hasMag() ) return NONE; + +// this.mag = this.contexted.mag(); + this.clearProgress(); + this.sendToServer( new PacketCode( Code.UNLOAD_MAG ) ); + return this; + } + + @Override + public IOperation terminate() + { + this.sendToServer( new 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() { } //this.contexted.unloadMag(); } +} diff --git a/src/main/java/com/mcwb/common/MCWB.java b/src/main/java/com/mcwb/common/MCWB.java index ae3adc9..abd0b67 100644 --- a/src/main/java/com/mcwb/common/MCWB.java +++ b/src/main/java/com/mcwb/common/MCWB.java @@ -246,7 +246,7 @@ public void load() { // Check content pack folder // TODO: if load packs from mods dir then allow the player to disable content pack folder - final File packDir = new File( this.gameDir, ID ); + final File packDir = new File( this.gameDir, "fmum" ); // ID ); if( !packDir.exists() ) { packDir.mkdirs(); diff --git a/src/main/java/com/mcwb/common/gun/GunType.java b/src/main/java/com/mcwb/common/gun/GunType.java index ae515b1..7f33548 100644 --- a/src/main/java/com/mcwb/common/gun/GunType.java +++ b/src/main/java/com/mcwb/common/gun/GunType.java @@ -3,13 +3,18 @@ import java.util.function.BiConsumer; import com.mcwb.client.gun.IGunPartRenderer; +import com.mcwb.client.input.IKeyBind; import com.mcwb.client.input.InputHandler; +import com.mcwb.client.input.Key; +import com.mcwb.client.player.OpLoadMagClient; +import com.mcwb.client.player.OpUnloadMagClient; import com.mcwb.client.player.PlayerPatchClient; import com.mcwb.client.render.IAnimator; import com.mcwb.common.load.BuildableLoader; import com.mcwb.common.meta.IMeta; import com.mcwb.common.module.IModular; import com.mcwb.common.module.IModuleEventSubscriber; +import com.mcwb.common.operation.IOperation; import com.mcwb.common.operation.IOperationController; import com.mcwb.common.operation.OperationController; import com.mcwb.util.ArmTracker; @@ -26,6 +31,9 @@ public abstract class GunType< C extends IGun< ? >, R extends IGunPartRenderer< public static final BuildableLoader< IMeta > LOADER = new BuildableLoader<>( "gun", GunJson.class ); + protected static final OpLoadMagClient OP_LOAD_MAG = new OpLoadMagClient(); + protected static final OpUnloadMagClient OP_UNLOAD_MAG = new OpUnloadMagClient(); + protected static final OperationController LOAD_MAG_CONTROLLER = new OperationController( 1F / 40F, @@ -81,6 +89,23 @@ public IOperationController unloadMagController() { return GunType.this.unloadMagController; } + @Override + @SideOnly( Side.CLIENT ) + public void onKeyPress( IKeyBind key ) + { + switch( key.name() ) + { + case Key.LOAD_UNLOAD_MAG: + case Key.CO_LOAD_UNLOAD_MAG: + final IOperation op = this.hasMag() + ? OP_UNLOAD_MAG.reset( this ) : OP_LOAD_MAG.reset( this ); + PlayerPatchClient.instance.tryLaunch( op ); + break; + + default: super.onKeyPress( key ); + } + } + @Override @SideOnly( Side.CLIENT ) public boolean updateViewBobbing( boolean original ) { return false; } @@ -110,6 +135,18 @@ protected static class GunWrapper< { protected GunWrapper( T primary, ItemStack stack ) { super( primary, stack ); } + @Override + public boolean hasMag() { return this.primary.hasMag(); } + + @Override + public boolean isAllowed( IMag< ? > mag ) { return this.primary.isAllowed( mag ); } + + @Override + public void loadMag( IMag< ? > mag ) { this.primary.loadMag( mag ); } + + @Override + public IMag< ? > unloadMag() { return this.primary.unloadMag(); } + @Override public IOperationController loadMagController() { return this.primary.loadMagController(); } diff --git a/src/main/java/com/mcwb/common/gun/MagType.java b/src/main/java/com/mcwb/common/gun/MagType.java index c176678..738ab2d 100644 --- a/src/main/java/com/mcwb/common/gun/MagType.java +++ b/src/main/java/com/mcwb/common/gun/MagType.java @@ -8,8 +8,17 @@ import com.google.gson.annotations.SerializedName; import com.mcwb.client.gun.IGunPartRenderer; +import com.mcwb.client.input.IKeyBind; +import com.mcwb.client.input.Key; +import com.mcwb.client.player.OpLoadAmmoClient; +import com.mcwb.client.player.OpUnloadAmmoClient; +import com.mcwb.client.player.PlayerPatchClient; +import com.mcwb.common.ammo.IAmmoType; +import com.mcwb.common.item.IItemTypeHost; +import com.mcwb.common.load.BuildableLoader; import com.mcwb.common.meta.IMeta; import com.mcwb.common.module.IModular; +import com.mcwb.common.operation.IOperation; import com.mcwb.common.operation.IOperationController; import com.mcwb.common.operation.OperationController; @@ -17,10 +26,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.capabilities.ICapabilityProvider; - -import com.mcwb.common.ammo.IAmmoType; -import com.mcwb.common.item.IItemTypeHost; -import com.mcwb.common.load.BuildableLoader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public abstract class MagType< C extends IMag< ? >, R extends IGunPartRenderer< ? super C > > extends GunPartType< C, R > @@ -28,6 +35,9 @@ public abstract class MagType< C extends IMag< ? >, R extends IGunPartRenderer< public static final BuildableLoader< IMeta > LOADER = new BuildableLoader<>( "mag", MagJson.class ); + protected static final OpLoadAmmoClient OP_LOAD_AMMO = new OpLoadAmmoClient(); + protected static final OpUnloadAmmoClient OP_UNLOAD_AMMO = new OpUnloadAmmoClient(); + protected static final OperationController PUSH_AMMO_CONTROLLER = new OperationController( 1F / 10F, @@ -102,6 +112,40 @@ public IAmmoType popAmmo() @Override public IOperationController popAmmoController() { return MagType.this.popAmmoController; } + @Override + @SideOnly( Side.CLIENT ) + public void onKeyPress( IKeyBind key ) + { + switch( key.name() ) + { + case Key.PULL_TRIGGER: + PlayerPatchClient.instance.tryLaunch( OP_LOAD_AMMO.reset( this ) ); + break; + + case Key.AIM_HOLD: + case Key.AIM_TOGGLE: + PlayerPatchClient.instance.tryLaunch( OP_UNLOAD_AMMO.reset( this ) ); + break; + + default: super.onKeyPress( key ); + } + } + + @Override + @SideOnly( Side.CLIENT ) + public void onKeyRelease( IKeyBind key ) + { + switch( key.name() ) + { + case Key.PULL_TRIGGER: + case Key.AIM_HOLD: + case Key.AIM_TOGGLE: + final IOperation op = PlayerPatchClient.instance.executing(); + if( op instanceof OpLoadAmmoClient || op instanceof OpUnloadAmmoClient ) + PlayerPatchClient.instance.ternimateExecuting(); + } + } + @Override public void deserializeNBT( NBTTagCompound nbt ) { @@ -151,6 +195,9 @@ protected static class MagWrapper< @Override public boolean isFull() { return this.primary.isFull(); } + @Override + public boolean isEmpty() { return this.primary.isEmpty(); } + @Override public int ammoCount() { return this.primary.ammoCount(); } @@ -163,6 +210,9 @@ protected static class MagWrapper< @Override public IAmmoType popAmmo() { return this.primary.popAmmo(); } + @Override + public IAmmoType peek() { return this.primary.peek(); } + @Override public IAmmoType getAmmo( int idx ) { return this.primary.getAmmo( idx ); } diff --git a/src/main/java/com/mcwb/common/item/ModifiableItemType.java b/src/main/java/com/mcwb/common/item/ModifiableItemType.java index 8e77388..c2bebdc 100644 --- a/src/main/java/com/mcwb/common/item/ModifiableItemType.java +++ b/src/main/java/com/mcwb/common/item/ModifiableItemType.java @@ -448,11 +448,6 @@ protected ModifiableItemWrapper( T primary, ItemStack stack ) this.stack = stack; } - @Override - public IUseContext onTakeOut( IItem oldItem, EntityPlayer player, EnumHand hand ) { - return this.primary.onTakeOut( oldItem, player, hand ); - } - @Override public ItemStack toStack() { return this.stack; } @@ -461,6 +456,11 @@ public void tickInHand( EntityPlayer player, EnumHand hand ) { this.primary.tickInHand( player, hand ); } + @Override + public IUseContext onTakeOut( IItem oldItem, EntityPlayer player, EnumHand hand ) { + return this.primary.onTakeOut( oldItem, player, hand ); + } + @Override public IUseContext onInHandStackChanged( IItem oldItem, diff --git a/src/main/java/com/mcwb/common/load/BuildableLoader.java b/src/main/java/com/mcwb/common/load/BuildableLoader.java index c429e61..6f77f7d 100644 --- a/src/main/java/com/mcwb/common/load/BuildableLoader.java +++ b/src/main/java/com/mcwb/common/load/BuildableLoader.java @@ -22,7 +22,7 @@ public BuildableLoader( String entry, Class< ? extends IBuildable< ? extends T > } public BuildableLoader( - String entry, + String entry, Function< JsonObject, ? extends IBuildable< ? extends T > > parser ) { this.entry = entry; diff --git a/src/main/java/com/mcwb/common/network/PacketCode.java b/src/main/java/com/mcwb/common/network/PacketCode.java index 52a87f7..75cb52a 100644 --- a/src/main/java/com/mcwb/common/network/PacketCode.java +++ b/src/main/java/com/mcwb/common/network/PacketCode.java @@ -1,9 +1,16 @@ package com.mcwb.common.network; +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.player.OpUnloadAmmo; +import com.mcwb.common.player.OpUnloadMag; import com.mcwb.common.player.PlayerPatch; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public final class PacketCode implements IPacket @@ -19,30 +26,31 @@ protected void handle( EntityPlayerMP player ) // TODO: notify other players to stop animation } }, -// UNLOAD_AMMO() -// { -// @Override -// protected void handle( EntityPlayerMP player ) -// { -// final ItemStack stack = player.inventory.getCurrentItem(); -// final IItem item = IItemTypeHost.getType( stack ).getContexted( stack ); -// if( !( item instanceof IMag ) ) return; -// -// PlayerPatch.get( player ).tryLaunch( new OpUnloadAmmo( player, ( IMag ) item ) ); -// } -// }, -// UNLOAD_MAG() -// { -// @Override -// protected void handle( EntityPlayerMP player ) -// { -// final ItemStack stack = player.inventory.getCurrentItem(); -// final IItem item = IItemTypeHost.getType( stack ).getContexted( stack ); -// if( !( item instanceof IGun ) ) return; -// -// PlayerPatch.get( player ).tryLaunch( new OpUnloadMag( player, ( IGun ) item ) ); -// } -// }, + UNLOAD_AMMO() + { + @Override + protected void handle( EntityPlayerMP player ) + { + final ItemStack stack = player.inventory.getCurrentItem(); + final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); + if( !( item instanceof IMag< ? > ) ) return; + + PlayerPatch.get( player ).tryLaunch( new OpUnloadAmmo( player, ( IMag< ? > ) item ) ); + } + }, + UNLOAD_MAG() + { + @Override + protected void handle( EntityPlayerMP player ) + { + final ItemStack stack = player.inventory.getCurrentItem(); + final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); + if( !( item instanceof IGun< ? > ) ) return; + + final IGun< ? > gun = ( IGun< ? > ) item; + PlayerPatch.get( player ).tryLaunch( new OpUnloadMag( player, gun ) ); + } + }, SWAP_HAND() { diff --git a/src/main/java/com/mcwb/common/network/PacketCodeAssist.java b/src/main/java/com/mcwb/common/network/PacketCodeAssist.java new file mode 100644 index 0000000..8ed23f0 --- /dev/null +++ b/src/main/java/com/mcwb/common/network/PacketCodeAssist.java @@ -0,0 +1,82 @@ +package com.mcwb.common.network; + +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.player.OpLoadAmmo; +import com.mcwb.common.player.OpLoadMag; +import com.mcwb.common.player.PlayerPatch; + +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; + +public final class PacketCodeAssist implements IPacket +{ + public static enum Code + { + LOAD_AMMO + { + // TODO: check assist maybe? + @Override + protected void handle( PacketCodeAssist packet, EntityPlayerMP player ) + { + final ItemStack stack = player.inventory.getCurrentItem(); + final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); + if( !( item instanceof IMag< ? > ) ) return; + + final IMag< ? > mag = ( IMag< ? > ) item; + PlayerPatch.get( player ).tryLaunch( new OpLoadAmmo( player, mag, packet.assist ) ); + } + }, + LOAD_MAG + { + @Override + protected void handle( PacketCodeAssist packet, EntityPlayerMP player ) + { + final ItemStack stack = player.inventory.getCurrentItem(); + final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); + if( !( item instanceof IGun< ? > ) ) return; + + final IGun< ? > gun = ( IGun< ? > ) item; + PlayerPatch.get( player ).tryLaunch( new OpLoadMag( player, gun, packet.assist ) ); + } + }; + + protected abstract void handle( PacketCodeAssist packet, EntityPlayerMP player ); + } + + protected Code code; + protected int assist; + + public PacketCodeAssist() { } + + public PacketCodeAssist( Code code, int assist ) + { + this.code = code; + this.assist = assist; + } + + @Override + public void toBytes( ByteBuf buf ) + { + buf.writeByte( this.code.ordinal() ); + buf.writeInt( this.assist ); + } + + @Override + public void fromBytes( ByteBuf buf ) + { + this.code = Code.values()[ buf.readByte() ]; + this.assist = buf.readInt(); + } + + @Override + public void handleServerSide( MessageContext ctx ) + { + final EntityPlayerMP player = ctx.getServerHandler().player; + player.getServerWorld().addScheduledTask( () -> this.code.handle( this, player ) ); + } +} diff --git a/src/main/java/com/mcwb/common/network/PacketHandler.java b/src/main/java/com/mcwb/common/network/PacketHandler.java index aa6d3e0..3ab3b73 100644 --- a/src/main/java/com/mcwb/common/network/PacketHandler.java +++ b/src/main/java/com/mcwb/common/network/PacketHandler.java @@ -27,7 +27,7 @@ public final class PacketHandler extends SimpleNetworkWrapper public void regisPackets() { this.regis( PacketCode.class, Side.SERVER ); -// this.regis( PacketCodeAssist.class, Side.SERVER ); + this.regis( PacketCodeAssist.class, Side.SERVER ); this.regis( PacketModify.class, Side.SERVER ); // this.regis( PacketGunShoot.class, Side.SERVER ); diff --git a/src/main/java/com/mcwb/common/network/PacketModify.java b/src/main/java/com/mcwb/common/network/PacketModify.java index 21c3150..996b48d 100644 --- a/src/main/java/com/mcwb/common/network/PacketModify.java +++ b/src/main/java/com/mcwb/common/network/PacketModify.java @@ -17,7 +17,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class PacketModify implements IPacket +public final class PacketModify implements IPacket { public static enum Code { diff --git a/src/main/java/com/mcwb/common/operation/Operation.java b/src/main/java/com/mcwb/common/operation/Operation.java index 0068a08..450abbf 100644 --- a/src/main/java/com/mcwb/common/operation/Operation.java +++ b/src/main/java/com/mcwb/common/operation/Operation.java @@ -34,22 +34,6 @@ public float getProgress( float smoother ) { return this.prevProgress + ( this.progress - this.prevProgress ) * smoother; } - @Override - public IOperation launch( IOperation oldOp ) - { - this.clearProgress(); // TODO: if this is necessary? - this.ieffect = 0; - this.isound = 0; - return this; - } - - @Override - public IOperation terminate() - { - this.clearProgress(); // TODO: if this is necessary? - return NONE; - } - @Override public IOperation tick() { @@ -63,7 +47,7 @@ public IOperation tick() this.ieffect < effectCount && this.controller.getEffectTime( this.ieffect ) <= this.progress; ++this.ieffect - ) this.dohandleEffect(); + ) this.doHandleEffect(); // Handle sounds for( @@ -86,6 +70,8 @@ protected void clearProgress() { this.prevProgress = 0F; this.progress = 0F; + this.ieffect = 0; + this.isound = 0; } protected IOperation onComplete() { return NONE; } @@ -93,5 +79,5 @@ protected void clearProgress() /** * Handle effect specified by {@link #ieffect} */ - protected void dohandleEffect() { } + protected void doHandleEffect() { } } diff --git a/src/main/java/com/mcwb/common/operation/TogglableOperation.java b/src/main/java/com/mcwb/common/operation/TogglableOperation.java index f41774a..accdb05 100644 --- a/src/main/java/com/mcwb/common/operation/TogglableOperation.java +++ b/src/main/java/com/mcwb/common/operation/TogglableOperation.java @@ -26,7 +26,8 @@ public IOperation launch( IOperation oldOp ) { // Use forward controller for launch this.controller = this.forwardController; - return super.launch( oldOp ); + this.clearProgress(); + return this; } @Override diff --git a/src/main/java/com/mcwb/common/pack/FolderPack.java b/src/main/java/com/mcwb/common/pack/FolderPack.java index 91b536c..bfacbe4 100644 --- a/src/main/java/com/mcwb/common/pack/FolderPack.java +++ b/src/main/java/com/mcwb/common/pack/FolderPack.java @@ -32,7 +32,7 @@ public void load() for( final File dir : this.source.listFiles() ) { final String dirName = dir.getName(); - if( dir.isDirectory() && !dirName.contentEquals( "assets" ) ) + if( dir.isDirectory() && !this.ignoreEntires.contains( dirName ) ) this.tryLoadFrom( dir, this.getFallbackType( dirName ), () -> dirName ); } } diff --git a/src/main/java/com/mcwb/common/pack/JarPack.java b/src/main/java/com/mcwb/common/pack/JarPack.java index da51532..f86d7d5 100644 --- a/src/main/java/com/mcwb/common/pack/JarPack.java +++ b/src/main/java/com/mcwb/common/pack/JarPack.java @@ -36,7 +36,10 @@ public void load() // Skip stuffs not in folder or in "assets/" folder final String eName = e.getName(); final int i = eName.indexOf( '/' ); - if( i < 0 || eName.startsWith( "assets/" ) ) continue; + if( i < 0 ) continue; + + final String entry = eName.substring( 0, i ); + if( this.ignoreEntires.contains( entry ) ) continue; final Supplier< String > sourceTrace = () -> this.sourceName() + "/" + eName; try @@ -45,8 +48,8 @@ public void load() { this.loadJsonType( new InputStreamReader( zipIn ), - this.getFallbackType( eName.substring( i ) ), - eName.substring( eName.lastIndexOf( '/' ), eName.length() - 5 ), + this.getFallbackType( entry ), + eName.substring( eName.lastIndexOf( '/' ) + 1, eName.length() - 5 ), sourceTrace ); } diff --git a/src/main/java/com/mcwb/common/pack/LocalPack.java b/src/main/java/com/mcwb/common/pack/LocalPack.java index 67119b2..283c255 100644 --- a/src/main/java/com/mcwb/common/pack/LocalPack.java +++ b/src/main/java/com/mcwb/common/pack/LocalPack.java @@ -3,10 +3,12 @@ import java.io.File; import java.io.Reader; import java.util.HashMap; +import java.util.HashSet; import java.util.function.Supplier; import javax.annotation.Nullable; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mcwb.common.IAutowireLogger; @@ -51,10 +53,13 @@ public abstract class LocalPack extends Meta implements IContentProvider, IAutow */ protected String author = "mcwb.author_missing"; + protected final HashSet< String > ignoreEntires = new HashSet<>(); + protected LocalPack( File source ) { this.name = source.getName(); this.source = source; + this.ignoreEntires.add( "assets" ); } @Override @@ -82,6 +87,12 @@ protected void setupInfoWith( Reader in ) this.name = obj.get( "name" ).getAsString(); if( obj.has( "author" ) ) this.author = obj.get( "author" ).getAsString(); + if( obj.has( "ignoreEntries" ) ) + { + final JsonArray arr = obj.get( "ignoreEntries" ).getAsJsonArray(); + for( int i = arr.size(); i-- > 0; ) + this.ignoreEntires.add( arr.get( i ).getAsString() ); + } // TODO: handle version check } diff --git a/src/main/java/com/mcwb/common/player/OpLoadAmmo.java b/src/main/java/com/mcwb/common/player/OpLoadAmmo.java index 611b075..b030798 100644 --- a/src/main/java/com/mcwb/common/player/OpLoadAmmo.java +++ b/src/main/java/com/mcwb/common/player/OpLoadAmmo.java @@ -38,7 +38,7 @@ public IOperation launch( IOperation oldOp ) final boolean isAmmo = type instanceof IAmmoType; if( !isAmmo || !this.contexted.isAllowed( ( IAmmoType ) type ) ) break; - return super.launch( oldOp ); + return this; } return NONE; } @@ -53,8 +53,7 @@ public IOperation onOtherTryLaunch( IOperation op ) @Override public IOperation onInHandStackChange( IItem newItem ) { - if( ( ( IMag< ? > ) newItem ).isFull() ) - return this.terminate(); + if( ( ( IMag< ? > ) newItem ).isFull() ) return NONE; this.contexted = ( IMag< ? > ) newItem; return this; @@ -64,7 +63,7 @@ public IOperation onInHandStackChange( IItem newItem ) protected IOperation onComplete() { return this.next.launch( this ); } @Override - protected void dohandleEffect() + protected void doHandleEffect() { final InventoryPlayer inv = this.player.inventory; final ItemStack stack = inv.getStackInSlot( this.invSlot ); diff --git a/src/main/java/com/mcwb/common/player/OpLoadMag.java b/src/main/java/com/mcwb/common/player/OpLoadMag.java index d3d4e00..af05460 100644 --- a/src/main/java/com/mcwb/common/player/OpLoadMag.java +++ b/src/main/java/com/mcwb/common/player/OpLoadMag.java @@ -32,10 +32,10 @@ public IOperation launch( IOperation oldOp ) final ItemStack stack = this.player.inventory.getStackInSlot( this.invSlot ); final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); - final boolean isMag = item instanceof IMag; + final boolean isMag = item instanceof IMag< ? >; if( !isMag || !this.contexted.isAllowed( ( IMag< ? > ) item ) ) break; - return super.launch( oldOp ); + return this; } return NONE; } @@ -44,16 +44,16 @@ public IOperation launch( IOperation oldOp ) public IOperation onInHandStackChange( IItem newItem ) { this.contexted = ( IGun< ? > ) newItem; - return this.contexted.hasMag() ? this.terminate() : this; + return this.contexted.hasMag() ? NONE : this; } @Override - protected void dohandleEffect() + protected void doHandleEffect() { final InventoryPlayer inv = this.player.inventory; final ItemStack stack = inv.getStackInSlot( this.invSlot ); final IItem item = IItemTypeHost.getTypeOrDefault( stack ).getContexted( stack ); - final boolean isMag = item instanceof IMag; + final boolean isMag = item instanceof IMag< ? >; if( !isMag ) return; final IMag< ? > mag = ( IMag< ? > ) item; diff --git a/src/main/java/com/mcwb/common/player/OpUnloadAmmo.java b/src/main/java/com/mcwb/common/player/OpUnloadAmmo.java index 249389a..0eed291 100644 --- a/src/main/java/com/mcwb/common/player/OpUnloadAmmo.java +++ b/src/main/java/com/mcwb/common/player/OpUnloadAmmo.java @@ -18,9 +18,7 @@ public OpUnloadAmmo( EntityPlayer player, IMag< ? > mag ) { } @Override - public IOperation launch( IOperation oldOp ) { - return this.contexted.isEmpty() ? NONE : super.launch( oldOp ); - } + public IOperation launch( IOperation oldOp ) { return this.contexted.isEmpty() ? NONE : this; } @Override public IOperation onOtherTryLaunch( IOperation op ) @@ -32,8 +30,7 @@ public IOperation onOtherTryLaunch( IOperation op ) @Override public IOperation onInHandStackChange( IItem newItem ) { - if( ( ( IMag< ? > ) newItem ).isEmpty() ) - return this.terminate(); + if( ( ( IMag< ? > ) newItem ).isEmpty() ) return NONE; this.contexted = ( IMag< ? > ) newItem; return this; @@ -43,7 +40,7 @@ public IOperation onInHandStackChange( IItem newItem ) protected IOperation onComplete() { return this.next.launch( this ); } @Override - protected void dohandleEffect() + protected void doHandleEffect() { final IAmmoType ammo = this.contexted.popAmmo(); final ItemStack stack = new ItemStack( ammo.item() ); diff --git a/src/main/java/com/mcwb/common/player/OpUnloadMag.java b/src/main/java/com/mcwb/common/player/OpUnloadMag.java index f696fd6..3520125 100644 --- a/src/main/java/com/mcwb/common/player/OpUnloadMag.java +++ b/src/main/java/com/mcwb/common/player/OpUnloadMag.java @@ -15,22 +15,19 @@ public OpUnloadMag( EntityPlayer player, IGun< ? > gun ) { } @Override - public IOperation launch( IOperation oldOp ) { - return this.contexted.hasMag() ? super.launch( oldOp ) : NONE; - } + public IOperation launch( IOperation oldOp ) { return this.contexted.hasMag() ? this : NONE; } @Override public IOperation onInHandStackChange( IItem newItem ) { - if( !( ( IGun< ? > ) newItem ).hasMag() ) - return this.terminate(); + if( !( ( IGun< ? > ) newItem ).hasMag() ) return NONE; this.contexted = ( IGun< ? > ) newItem; return this; } @Override - protected void dohandleEffect() + protected void doHandleEffect() { final IMag< ? > mag = this.contexted.unloadMag(); this.player.addItemStackToInventory( mag.toStack() ); diff --git a/src/main/java/com/mcwb/devtool/Dev.java b/src/main/java/com/mcwb/devtool/Dev.java index 0ae8177..c06b053 100644 --- a/src/main/java/com/mcwb/devtool/Dev.java +++ b/src/main/java/com/mcwb/devtool/Dev.java @@ -71,72 +71,72 @@ public void accept( Boolean useDefaultTexture ) static { - final String group = "test"; - final Collection< IKeyBind > updateGroup = InputHandler.GLOBAL_KEYS; - new KeyBind( "test_up", group, Keyboard.KEY_UP, updateGroup ) { - @Override - protected void onFire() { Dev.tu = true; } - }; - new KeyBind( "test_down", group, Keyboard.KEY_DOWN, updateGroup ) { - @Override - protected void onFire() { Dev.td = true; } - }; - new KeyBind( "test_left", group, Keyboard.KEY_LEFT, updateGroup ) { - @Override - protected void onFire() { Dev.tl = true; } - }; - new KeyBind( "test_right", group, Keyboard.KEY_RIGHT, updateGroup ) { - @Override - protected void onFire() { Dev.tr = true; } - }; - new KeyBind( "test_enter", group, Keyboard.KEY_NUMPAD5, updateGroup ) { - @Override - protected void onFire() { Dev.te = true; } - }; - new KeyBind( "test_quit", group, Keyboard.KEY_NUMPAD2, updateGroup ) { - @Override - protected void onFire() { Dev.tq = true; } - }; - new KeyBind( "test_flag", group, Keyboard.KEY_F10, updateGroup ) { - @Override - protected void onFire() - { - Dev.flag = !Dev.flag; - // FIXME: add check for vector and matrix pool -// final Vec3f rot = cur().getRot(); -// -// Mat4f mat = new Mat4f(); -// mat.setIdentity(); -// mat.eulerRotateYXZ( rot ); -// mat.translate( 0F, 0F, 3F ); -// MCWBClient.MOD.sendPlayerMsg( mat.toString() + "^ Mat4f" ); -// -// rot.scale( Util.TO_RADIANS ); -// Matrix4f mat0 = new Matrix4f(); -// Matrix4f mat1 = new Matrix4f(); -// Matrix4f mat2 = new Matrix4f(); -// Matrix4f mat3 = new Matrix4f(); -// mat0.rotY( rot.y ); -// mat1.rotX( rot.x ); -// mat2.rotZ( rot.z ); -// mat3.setIdentity(); -// mat3.setTranslation( new Vector3f( 0F, 0F, 3F ) ); -// -// mat0.mul( mat1 ); -// mat0.mul( mat2 ); -// mat0.mul( mat3 ); -// MCWBClient.MOD.sendPlayerMsg( mat0.toString() + "^ Matrix4f" ); - } - }; - - MinecraftForge.EVENT_BUS.register( new Object() { - @SubscribeEvent - public void onGuiOpen( GuiOpenEvent evt ) - { - InputHandler.updateMappers(); - MinecraftForge.EVENT_BUS.unregister( this ); - } - } ); +// final String group = "test"; +// final Collection< IKeyBind > updateGroup = InputHandler.GLOBAL_KEYS; +// new KeyBind( "test_up", group, Keyboard.KEY_UP, updateGroup ) { +// @Override +// protected void onFire() { Dev.tu = true; } +// }; +// new KeyBind( "test_down", group, Keyboard.KEY_DOWN, updateGroup ) { +// @Override +// protected void onFire() { Dev.td = true; } +// }; +// new KeyBind( "test_left", group, Keyboard.KEY_LEFT, updateGroup ) { +// @Override +// protected void onFire() { Dev.tl = true; } +// }; +// new KeyBind( "test_right", group, Keyboard.KEY_RIGHT, updateGroup ) { +// @Override +// protected void onFire() { Dev.tr = true; } +// }; +// new KeyBind( "test_enter", group, Keyboard.KEY_NUMPAD5, updateGroup ) { +// @Override +// protected void onFire() { Dev.te = true; } +// }; +// new KeyBind( "test_quit", group, Keyboard.KEY_NUMPAD2, updateGroup ) { +// @Override +// protected void onFire() { Dev.tq = true; } +// }; +// new KeyBind( "test_flag", group, Keyboard.KEY_F10, updateGroup ) { +// @Override +// protected void onFire() +// { +// Dev.flag = !Dev.flag; +// // FIXME: add check for vector and matrix pool +//// final Vec3f rot = cur().getRot(); +//// +//// Mat4f mat = new Mat4f(); +//// mat.setIdentity(); +//// mat.eulerRotateYXZ( rot ); +//// mat.translate( 0F, 0F, 3F ); +//// MCWBClient.MOD.sendPlayerMsg( mat.toString() + "^ Mat4f" ); +//// +//// rot.scale( Util.TO_RADIANS ); +//// Matrix4f mat0 = new Matrix4f(); +//// Matrix4f mat1 = new Matrix4f(); +//// Matrix4f mat2 = new Matrix4f(); +//// Matrix4f mat3 = new Matrix4f(); +//// mat0.rotY( rot.y ); +//// mat1.rotX( rot.x ); +//// mat2.rotZ( rot.z ); +//// mat3.setIdentity(); +//// mat3.setTranslation( new Vector3f( 0F, 0F, 3F ) ); +//// +//// mat0.mul( mat1 ); +//// mat0.mul( mat2 ); +//// mat0.mul( mat3 ); +//// MCWBClient.MOD.sendPlayerMsg( mat0.toString() + "^ Matrix4f" ); +// } +// }; +// +// MinecraftForge.EVENT_BUS.register( new Object() { +// @SubscribeEvent +// public void onGuiOpen( GuiOpenEvent evt ) +// { +// InputHandler.updateMappers(); +// MinecraftForge.EVENT_BUS.unregister( this ); +// } +// } ); } public static void tick()