Compare commits

..

13 Commits

Author SHA1 Message Date
ce0f8643e7 Update to 1.21.8 2025-07-20 23:18:21 +02:00
977050276c Update to 1.21.5 2025-04-16 22:14:08 +02:00
6fc5738e38 Update 2024-12-23 08:49:36 +01:00
8afe0c0063 Update to 1.21.4 2024-12-05 14:46:33 +01:00
b7fc022f90 Try some stuff 2024-11-01 23:38:18 +01:00
78633a1338 Try some stuff 2024-11-01 23:35:39 +01:00
2395fa83ff Add loot tables 2024-09-17 08:56:31 +02:00
3487a054cc Fix recipe 2024-08-20 09:44:13 +02:00
2e4a221528 Fix recipe 2024-08-20 09:44:01 +02:00
8205348228 Fix recipe 2024-08-19 22:48:12 +02:00
0366fe425a Fix recipe 2024-08-18 11:49:20 +02:00
8a53f20f77 Fix bug 2024-08-02 20:05:56 +02:00
ed1bfb65d4 Fix bug 2024-08-02 20:02:46 +02:00
251 changed files with 1356 additions and 741 deletions

View File

@@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '1.7-SNAPSHOT' id 'fabric-loom' version '1.11-SNAPSHOT'
id 'maven-publish' id 'maven-publish'
} }
@@ -35,6 +35,7 @@ dependencies {
modImplementation include("eu.pb4:polymer-virtual-entity:${project.polymer_version}") modImplementation include("eu.pb4:polymer-virtual-entity:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-blocks:${project.polymer_version}") modImplementation include("eu.pb4:polymer-blocks:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-resource-pack:${project.polymer_version}") modImplementation include("eu.pb4:polymer-resource-pack:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-resource-pack-extras:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-autohost:${project.polymer_version}") modImplementation include("eu.pb4:polymer-autohost:${project.polymer_version}")
modImplementation "eu.pb4.polyport:trinkets:${project.trinkets_version}" modImplementation "eu.pb4.polyport:trinkets:${project.trinkets_version}"
@@ -54,8 +55,8 @@ processResources {
filesMatching("fabric.mod.json") { filesMatching("fabric.mod.json") {
expand "version": project.version, expand "version": project.version,
"minecraft_version": project.minecraft_version, "minecraft_version": project.minecraft_version,
"loader_version": project.loader_version, "trinkets_version": project.trinkets_version,
"trinkets_version": project.trinkets_version "loader_version": project.loader_version
} }
} }
@@ -94,24 +95,6 @@ jar {
} }
} }
// configure the maven publication
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
loom { loom {
accessWidenerPath = file("src/main/resources/plasticgun.accesswidener") accessWidenerPath = file("src/main/resources/plasticgun.accesswidener")
} }

View File

@@ -2,17 +2,17 @@
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.21 minecraft_version=1.21.8
yarn_mappings=1.21+build.9 yarn_mappings=1.21.8+build.1
loader_version=0.16.0 loader_version=0.16.14
# Mod Properties # Mod Properties
mod_version=1.9 mod_version=2.0.3
maven_group=systems.brn maven_group=systems.brn
archives_base_name=plasticgun archives_base_name=plasticgun
# Dependencies # Dependencies
# check this on https://modmuss50.me/fabric.html # check this on https://modmuss50.me/fabric.html
fabric_version=0.100.7+1.21 fabric_version=0.129.0+1.21.8
polymer_version=0.9.4+1.21 trinkets_version=3.11.0-beta.1+polymerport.2
server_translations_api_version=2.3.1+1.21-pre2 polymer_version=0.13.7+1.21.8
trinkets_version=3.10.0+polymerport.2 server_translations_api_version=2.5.1+1.21.5

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@@ -3,7 +3,6 @@ package systems.brn.plasticgun;
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback;
@@ -15,11 +14,13 @@ import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.loot.LootTables;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import systems.brn.plasticgun.bullets.BulletEntity; import systems.brn.plasticgun.bullets.BulletEntity;
@@ -34,8 +35,6 @@ import systems.brn.plasticgun.lib.CraftingItem;
import systems.brn.plasticgun.lib.EventHandler; import systems.brn.plasticgun.lib.EventHandler;
import systems.brn.plasticgun.lib.ItemGroups; import systems.brn.plasticgun.lib.ItemGroups;
import systems.brn.plasticgun.packets.ModDetect; import systems.brn.plasticgun.packets.ModDetect;
import systems.brn.plasticgun.packets.Reload;
import systems.brn.plasticgun.packets.Shoot;
import systems.brn.plasticgun.shurikens.ShurikenEntity; import systems.brn.plasticgun.shurikens.ShurikenEntity;
import systems.brn.plasticgun.shurikens.ShurikenItem; import systems.brn.plasticgun.shurikens.ShurikenItem;
import systems.brn.plasticgun.testing.DamageTester; import systems.brn.plasticgun.testing.DamageTester;
@@ -59,20 +58,36 @@ public class PlasticGun implements ModInitializer {
public static final ArrayList<CraftingItem> craftingItems = new ArrayList<>(); public static final ArrayList<CraftingItem> craftingItems = new ArrayList<>();
public static final ArrayList<WeaponArmor> weaponArmors = new ArrayList<>();
public static Map<Item, Gun> itemGunMap; public static Map<Item, Gun> itemGunMap;
public static Map<Item, BulletItem> itemBulletItemMap; public static Map<Item, BulletItem> itemBulletItemMap;
public static Map<Item, GrenadeItem> itemGrenadeItemMap; public static Map<Item, GrenadeItem> itemGrenadeItemMap;
public static Map<Item, ShurikenItem> itemShurikenItemMap; public static Map<Item, ShurikenItem> itemShurikenItemMap;
public static EntityType<BulletEntity> BULLET_ENTITY_TYPE; public static final EntityType<BulletEntity> BULLET_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("bullet"),
EntityType.Builder.<BulletEntity>create(BulletEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("bullet")))
);
public static EntityType<GrenadeEntity> GRENADE_ENTITY_TYPE; public static final EntityType<GrenadeEntity> GRENADE_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("grenade"),
EntityType.Builder.<GrenadeEntity>create(GrenadeEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("grenade")))
);
public static final ArrayList<WeaponArmor> weaponArmors = new ArrayList<>(); public static final EntityType<ShurikenEntity> SHURIKEN_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("shuriken"),
EntityType.Builder.<ShurikenEntity>create(ShurikenEntity::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("shuriken")))
);
public static EntityType<ShurikenEntity> SHURIKEN_ENTITY_TYPE; public static final EntityType<DamageTester> DAMAGE_TESTER_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
public static EntityType<DamageTester> DAMAGE_TESTER_ENTITY_TYPE; id("damagetester"),
EntityType.Builder.create(DamageTester::new, SpawnGroup.MISC).build(RegistryKey.of(RegistryKeys.ENTITY_TYPE, id("damagetester")))
);
public static final Logger logger = LoggerFactory.getLogger(MOD_ID); public static final Logger logger = LoggerFactory.getLogger(MOD_ID);
@@ -80,8 +95,8 @@ public class PlasticGun implements ModInitializer {
public static final ArrayList<Item> clickEventItems = new ArrayList<>(); public static final ArrayList<Item> clickEventItems = new ArrayList<>();
public static final RegistryEntry.Reference<StatusEffect> flashbangEffect = Registry.registerReference(Registries.STATUS_EFFECT, id("flashbang"), new FlashbangEffect()); public static final RegistryEntry.Reference<StatusEffect> flashbangEffect = Registry.registerReference(Registries.STATUS_EFFECT, id("flashbang"), new FlashbangEffect());
public static final RegistryEntry.Reference<StatusEffect> stunEffect = Registry.registerReference(Registries.STATUS_EFFECT, id("stun"), new StunEffect()); public static final RegistryEntry.Reference<StatusEffect> stunEffect = Registry.registerReference(Registries.STATUS_EFFECT, id("stun"), new StunEffect());
@Override @Override
public void onInitialize() { public void onInitialize() {
@@ -107,17 +122,17 @@ public class PlasticGun implements ModInitializer {
bullets.add(new BulletItem("force_container", 99, 0, 888, false, 0, 1)); bullets.add(new BulletItem("force_container", 99, 0, 888, false, 0, 1));
// Guns // Guns
guns.add(new Gun("forcegun", 0, 4, 5, 10, 10, 888, 5, 0, 2, 0f, 0f, 5f, 10f, 0, 0)); // 0 guns.add(new Gun("forcegun", 0, 4, 5, 10, 10, 888, 5, 0, 10, 0f, 0f, 0f, 1f, 0, 0)); // 0
guns.add(new Gun("p2022", 0.2, 12, 5, 10, 41, 9, 10, 0, 0, 1f, 4, 0.1f, 0.25f, -1, 1)); // 1.8 guns.add(new Gun("p2022", 0.2, 12, 5, 10, 41, 9, 10, 0, 0, 0f, 0.7f, 0.1f, 0.25f, -0.2, 0.2)); // 1.8
guns.add(new Gun("colt_1903", 0.3, 10, 5, 8, 38, 32, 10, 0, 0, 1, 3, 0.1f, 0.3f, -1, 1)); // 3 guns.add(new Gun("colt_1903", 0.3, 10, 5, 8, 38, 32, 10, 0, 0, 0, 0.5f, 0.1f, 0.3f, -0.2, 0.2)); // 3
guns.add(new Gun("ak_47", 0.2, 4, 5, 30, 45, 762, 0, 0, 0, 1f, 2, 0.2f, 0.4f, -1, 1)); // 9 guns.add(new Gun("ak_47", 0.2, 4, 5, 30, 45, 762, 0, 0, 0, 0.1f, 0.3f, 0.2f, 0.3f, -0.2, 0.2)); // 9
guns.add(new Gun("colt_45", 0.4, 9, 5, 7, 48, 45, 10, 0, 0, 1.5f, 2, 0.15f, 0.4f, -1, 1)); // 3.6 guns.add(new Gun("colt_45", 0.4, 9, 5, 7, 48, 45, 10, 0, 0, 0, 0.5f, 0.15f, 0.4f, -0.2, 0.2)); // 3.6
guns.add(new Gun("snub_nosed_revolver", 0.4, 7, 3, 5, 36, 38, 20, 0, 0, 1f, 2, 0.2f, 0.45f, -1, 1)); // 2.8 guns.add(new Gun("snub_nosed_revolver", 0.4, 7, 3, 5, 36, 38, 20, 0, 0, 0f, 0.4f, 0.2f, 0.45f, -0.2, 0.2)); // 2.8
guns.add(new Gun("colt_peacemaker", 0.6, 8, 5, 6, 43, 45, 10, 0, 0, 0.9f, 2, 0.2f, 0.5f, -1, 1)); // 4.8 guns.add(new Gun("colt_peacemaker", 0.6, 8, 5, 6, 43, 45, 10, 0, 0, 0, 1, 0.2f, 0.5f, -0.2, 0.2)); // 4.8
guns.add(new Gun("tokarev_tt_33", 0.7, 10, 5, 8, 45, 762, 10, 0, 0, 1.5f, 2.5f, 0.25f, 0.5f, -1, 1)); // 7 guns.add(new Gun("tokarev_tt_33", 0.7, 10, 5, 8, 45, 762, 10, 0, 0, 0, 2f, 0.25f, 0.5f, -0.2, 0.2)); // 7
guns.add(new Gun("357_revolver", 1, 8, 5, 6, 45, 357, 20, 0, 0, 2, 4, 0.2f, 0.5f, -1, 1)); // 8 guns.add(new Gun("357_revolver", 1, 8, 5, 6, 45, 357, 20, 0, 0, 2, 3, 0.2f, 0.5f, -0.2, 0.2)); // 8
guns.add(new Gun("awp", 1, 4, 20, 1, 75, 762, 40, 0, 0, 2f, 8, 0.3f, 0.6f, -1, 1)); // 4 guns.add(new Gun("awp", 1, 4, 20, 1, 75, 762, 40, 0, 0, 4f, 6f, 0.3f, 0.6f, -2, 2)); // 4
guns.add(new Gun("rpg9", 2, 4, 20, 1, 10, 999, 20, 20, 0, 3f, 0.5f, 1, 2, -1, 1)); // 8 guns.add(new Gun("rpg9", 2, 4, 20, 1, 10, 999, 20, 10, 0, 2f, 4f, 1, 2, -1, 1)); // 8
grenades.add(new GrenadeItem("grenade_m18", 1, 0.1f, 0.2f, 50, false, false, 0, 0, 100, 15, 30)); // 0.02 grenades.add(new GrenadeItem("grenade_m18", 1, 0.1f, 0.2f, 50, false, false, 0, 0, 100, 15, 30)); // 0.02
@@ -169,6 +184,129 @@ public class PlasticGun implements ModInitializer {
craftingItems.add(new CraftingItem("titanium_alloy")); craftingItems.add(new CraftingItem("titanium_alloy"));
craftingItems.add(new CraftingItem("trigger_mechanism")); craftingItems.add(new CraftingItem("trigger_mechanism"));
for (Item craftingItem : craftingItems) {
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, craftingItem, 2);
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, craftingItem, 6);
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, craftingItem, 6);
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, craftingItem, 5);
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, craftingItem, 2);
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_ARMORER_GIFT_GAMEPLAY, craftingItem, 1);
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, craftingItem, 2);
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, craftingItem, 10);
addItemToLootTable(LootTables.VILLAGE_ARMORER_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, craftingItem, 4);
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, craftingItem, 4);
}
int i = 0;
for (Item shuriken : shurikens) {
float weightCoeff = (float) i / shurikens.size();
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, shuriken, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, shuriken, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, shuriken, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, shuriken, getAfterWeight(weightCoeff, 5));
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, shuriken, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, shuriken, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, shuriken, getAfterWeight(weightCoeff, 10));
addItemToLootTable(LootTables.VILLAGE_ARMORER_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, shuriken, getAfterWeight(weightCoeff, 4));
i++;
}
for (Item weaponArmor : weaponArmors) {
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, weaponArmor, 4);
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, weaponArmor, 12);
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, weaponArmor, 12);
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, weaponArmor, 10);
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, weaponArmor, 8);
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, weaponArmor, 2);
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, weaponArmor, 4);
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, weaponArmor, 4);
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, weaponArmor, 2);
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_ARMORER_GIFT_GAMEPLAY, weaponArmor, 10);
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, weaponArmor, 2);
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, weaponArmor, 10);
addItemToLootTable(LootTables.VILLAGE_ARMORER_CHEST, weaponArmor, 20);
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, weaponArmor, 4);
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, weaponArmor, 4);
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, weaponArmor, 4);
}
i = 0;
for (Item gun : guns) {
float weightCoeff = (float) i / guns.size();
weightCoeff *= 5;
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, gun, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, gun, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, gun, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, gun, getAfterWeight(weightCoeff, 5));
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, gun, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, gun, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, gun, getAfterWeight(weightCoeff, 10));
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, gun, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, gun, getAfterWeight(weightCoeff, 4));
i++;
}
i = 0;
for (Item grenade : grenades) {
float weightCoeff = (float) i / grenades.size();
weightCoeff *= 6;
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, grenade, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, grenade, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, grenade, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, grenade, getAfterWeight(weightCoeff, 5));
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, grenade, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, grenade, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, grenade, getAfterWeight(weightCoeff, 10));
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, grenade, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, grenade, getAfterWeight(weightCoeff, 4));
i++;
}
i = 0;
for (Item bullet : bullets) {
float weightCoeff = (float) i / bullets.size();
weightCoeff *= 8;
addItemToLootTable(LootTables.ABANDONED_MINESHAFT_CHEST, bullet, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.ANCIENT_CITY_CHEST, bullet, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.ANCIENT_CITY_ICE_BOX_CHEST, bullet, getAfterWeight(weightCoeff, 6));
addItemToLootTable(LootTables.END_CITY_TREASURE_CHEST, bullet, getAfterWeight(weightCoeff, 5));
addItemToLootTable(LootTables.BASTION_BRIDGE_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_HOGLIN_STABLE_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_OTHER_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BASTION_TREASURE_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.BURIED_TREASURE_CHEST, bullet, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.HERO_OF_THE_VILLAGE_WEAPONSMITH_GIFT_GAMEPLAY, bullet, getAfterWeight(weightCoeff, 2));
addItemToLootTable(LootTables.VILLAGE_WEAPONSMITH_CHEST, bullet, getAfterWeight(weightCoeff, 10));
addItemToLootTable(LootTables.DESERT_PYRAMID_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.WOODLAND_MANSION_CHEST, bullet, getAfterWeight(weightCoeff, 4));
addItemToLootTable(LootTables.TRIAL_CHAMBERS_REWARD_CHEST, bullet, getAfterWeight(weightCoeff, 4));
i++;
}
itemGunMap = generateItemMap(guns); itemGunMap = generateItemMap(guns);
itemBulletItemMap = generateItemMap(bullets); itemBulletItemMap = generateItemMap(bullets);
itemGrenadeItemMap = generateItemMap(grenades); itemGrenadeItemMap = generateItemMap(grenades);
@@ -178,34 +316,13 @@ public class PlasticGun implements ModInitializer {
registerIntoClickEvents(grenades); registerIntoClickEvents(grenades);
registerIntoClickEvents(shurikens); registerIntoClickEvents(shurikens);
GRENADE_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("grenade"),
EntityType.Builder.<GrenadeEntity>create(GrenadeEntity::new, SpawnGroup.MISC).build()
);
PolymerEntityUtils.registerType(GRENADE_ENTITY_TYPE); PolymerEntityUtils.registerType(GRENADE_ENTITY_TYPE);
BULLET_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("bullet"),
EntityType.Builder.<BulletEntity>create(BulletEntity::new, SpawnGroup.MISC).build()
);
PolymerEntityUtils.registerType(BULLET_ENTITY_TYPE); PolymerEntityUtils.registerType(BULLET_ENTITY_TYPE);
SHURIKEN_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("shuriken"),
EntityType.Builder.<ShurikenEntity>create(ShurikenEntity::new, SpawnGroup.MISC).build()
);
PolymerEntityUtils.registerType(SHURIKEN_ENTITY_TYPE); PolymerEntityUtils.registerType(SHURIKEN_ENTITY_TYPE);
DAMAGE_TESTER_ENTITY_TYPE = Registry.register(
Registries.ENTITY_TYPE,
id("damagetester"),
EntityType.Builder.create(DamageTester::new, SpawnGroup.MISC).build()
);
FabricDefaultAttributeRegistry.register(DAMAGE_TESTER_ENTITY_TYPE, DamageTester.createDamageTesterAttributes());
PolymerEntityUtils.registerType(DAMAGE_TESTER_ENTITY_TYPE); PolymerEntityUtils.registerType(DAMAGE_TESTER_ENTITY_TYPE);
FabricDefaultAttributeRegistry.register(DAMAGE_TESTER_ENTITY_TYPE, DamageTester.createDamageTesterAttributes());
// Detect item use // Detect item use
@@ -222,16 +339,12 @@ public class PlasticGun implements ModInitializer {
ItemGroups.register(); ItemGroups.register();
PayloadTypeRegistry.playC2S().register(ModDetect.PACKET_ID, ModDetect.PACKET_CODEC); PayloadTypeRegistry.playC2S().register(ModDetect.PACKET_ID, ModDetect.PACKET_CODEC);
PayloadTypeRegistry.playC2S().register(Reload.PACKET_ID, Reload.PACKET_CODEC);
PayloadTypeRegistry.playC2S().register(Shoot.PACKET_ID, Shoot.PACKET_CODEC);
// Register the global receiver // Register the global receiver
ServerPlayNetworking.registerGlobalReceiver(ModDetect.PACKET_ID, EventHandler::onClientConfirm); ServerPlayNetworking.registerGlobalReceiver(ModDetect.PACKET_ID, EventHandler::onClientConfirm);
ServerPlayNetworking.registerGlobalReceiver(Reload.PACKET_ID, EventHandler::onClientReload);
ServerPlayNetworking.registerGlobalReceiver(Shoot.PACKET_ID, EventHandler::onClientShoot);
PolymerResourcePackUtils.addModAssets(MOD_ID); PolymerResourcePackUtils.addModAssets(MOD_ID);
PolymerResourcePackUtils.markAsRequired(); PolymerResourcePackUtils.markAsRequired();
logger.info("Guns are loaded"); logger.info("Guns are loaded");
} }
} }

View File

@@ -19,6 +19,7 @@ import net.minecraft.world.World;
import systems.brn.plasticgun.grenades.GrenadeExplosionBehavior; import systems.brn.plasticgun.grenades.GrenadeExplosionBehavior;
import systems.brn.plasticgun.guns.Gun; import systems.brn.plasticgun.guns.Gun;
import systems.brn.plasticgun.lib.WeaponDamageType; import systems.brn.plasticgun.lib.WeaponDamageType;
import xyz.nucleoid.packettweaker.PacketContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
@@ -35,7 +36,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
private final float scale; private final float scale;
public BulletEntity(LivingEntity livingEntity, ItemStack stack, Hand hand, Gun gun, float scale, double damage, float speed, double explosionPower, double repulsionPower, boolean isIncendiary) { public BulletEntity(LivingEntity livingEntity, ItemStack stack, Hand hand, Gun gun, float scale, double damage, float speed, double explosionPower, double repulsionPower, boolean isIncendiary) {
super(BULLET_ENTITY_TYPE, livingEntity.getPos().x, livingEntity.getPos().y + 1.75d, livingEntity.getPos().z, livingEntity.getEntityWorld(), stack, livingEntity.getStackInHand(hand)); super(BULLET_ENTITY_TYPE, livingEntity.getPos().x, livingEntity.getPos().y + 1.75d, livingEntity.getPos().z, livingEntity.getWorld(), stack, livingEntity.getStackInHand(hand));
this.setOwner(livingEntity); this.setOwner(livingEntity);
this.setVelocity(livingEntity, livingEntity.getPitch(), livingEntity.getYaw(), 0.0F, speed, 0); this.setVelocity(livingEntity, livingEntity.getPitch(), livingEntity.getYaw(), 0.0F, speed, 0);
this.pickupType = PickupPermission.DISALLOWED; this.pickupType = PickupPermission.DISALLOWED;
@@ -87,7 +88,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
} }
@Override @Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) { public EntityType<?> getPolymerEntityType(PacketContext packetContext) {
return EntityType.ITEM_DISPLAY; return EntityType.ITEM_DISPLAY;
} }
@@ -96,7 +97,7 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
this.setPosition(blockHitResult.getPos()); this.setPosition(blockHitResult.getPos());
if (blockHitResult.getType() == HitResult.Type.BLOCK) { if (blockHitResult.getType() == HitResult.Type.BLOCK) {
BlockState block = this.getWorld().getBlockState(blockHitResult.getBlockPos()); BlockState block = this.getWorld().getBlockState(blockHitResult.getBlockPos());
blockHitParticles(this.getPos(), block, this.getWorld(), this.getDamage() * this.getVelocity().length()); blockHitParticles(this.getPos(), block, this.getWorld(), this.damage * this.getVelocity().length());
SoundEvent soundEvent = block.getSoundGroup().getHitSound(); SoundEvent soundEvent = block.getSoundGroup().getHitSound();
setSilent(false); setSilent(false);
playSound(soundEvent, 4.0F, 1.0F); playSound(soundEvent, 4.0F, 1.0F);
@@ -117,8 +118,8 @@ public class BulletEntity extends PersistentProjectileEntity implements PolymerE
setSilent(true); setSilent(true);
if (entityHitResult.getEntity() instanceof LivingEntity livingEntity) { if (entityHitResult.getEntity() instanceof LivingEntity livingEntity) {
this.setDamage(getFinalDamage(livingEntity, WeaponDamageType.BULLET, this.getDamage())); this.setDamage(getFinalDamage(livingEntity, WeaponDamageType.BULLET, this.damage));
entityHitParticles(livingEntity, this.getDamage() * this.getVelocity().length()); entityHitParticles(livingEntity, this.damage * this.getVelocity().length());
} }
super.onEntityHit(entityHitResult); super.onEntityHit(entityHitResult);

View File

@@ -5,6 +5,8 @@ import net.minecraft.component.type.LoreComponent;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import systems.brn.plasticgun.lib.SimpleItem; import systems.brn.plasticgun.lib.SimpleItem;
@@ -23,13 +25,13 @@ public class BulletItem extends SimpleItem {
new Settings() new Settings()
.maxCount(maxCount) .maxCount(maxCount)
.component(DataComponentTypes.LORE, new LoreComponent(List.of( .component(DataComponentTypes.LORE, new LoreComponent(List.of(
Text.translatable("gun.description.caliber", caliber),
Text.translatable("gun.description.speed", damageCoefficient), Text.translatable("gun.description.speed", damageCoefficient),
Text.translatable("gun.description.explosion_coefficient", explosionPowerCoefficient), Text.translatable("gun.description.explosion_coefficient", explosionPowerCoefficient),
Text.translatable("gun.description.repulsion_efficient", repulsionPowerCoefficient), Text.translatable("gun.description.repulsion_efficient", repulsionPowerCoefficient),
Text.translatable("gun.description.repulsion_efficient", repulsionPowerCoefficient),
Text.translatable(isIncendiary ? "gun.description.incendiary_yes" : "gun.description.incendiary_no") Text.translatable(isIncendiary ? "gun.description.incendiary_yes" : "gun.description.incendiary_no")
)) )))
) .registryKey(RegistryKey.of(RegistryKeys.ITEM, id(path)))
, ,
id(path), id(path),
Items.STICK); Items.STICK);

View File

@@ -1,38 +1,17 @@
package systems.brn.plasticgun.companion; package systems.brn.plasticgun.companion;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.render.RenderTickCounter; import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.ColorHelper; import net.minecraft.util.math.ColorHelper;
import systems.brn.plasticgun.packets.ModDetect; import systems.brn.plasticgun.packets.ModDetect;
import systems.brn.plasticgun.packets.Reload;
import systems.brn.plasticgun.packets.Shoot;
import java.util.UUID; import java.util.UUID;
import static systems.brn.plasticgun.PlasticGun.flashbangEffect; import static systems.brn.plasticgun.PlasticGun.flashbangEffect;
import static systems.brn.plasticgun.lib.Util.shouldSendClickEvents;
public class ClientEvents { public class ClientEvents {
public static void tick(MinecraftClient minecraftClient) {
if (minecraftClient.options.useKey.isPressed() && minecraftClient.player != null) {
if (shouldSendClickEvents(minecraftClient.player)) {
UUID reloadUUID = UUID.randomUUID();
ClientPlayNetworking.send(new Reload(reloadUUID));
}
}
if (minecraftClient.options.attackKey.isPressed() && minecraftClient.player != null) {
if (shouldSendClickEvents(minecraftClient.player)) {
UUID shootUUID = UUID.randomUUID();
ClientPlayNetworking.send(new Shoot(shootUUID));
}
}
}
public static void join(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) { public static void join(ClientPlayNetworkHandler clientPlayNetworkHandler, PacketSender packetSender, MinecraftClient minecraftClient) {
UUID joinUUID = UUID.randomUUID(); UUID joinUUID = UUID.randomUUID();
packetSender.sendPacket(new ModDetect(joinUUID)); packetSender.sendPacket(new ModDetect(joinUUID));
@@ -43,7 +22,7 @@ public class ClientEvents {
if (MinecraftClient.getInstance().player.hasStatusEffect(flashbangEffect)) { if (MinecraftClient.getInstance().player.hasStatusEffect(flashbangEffect)) {
int width = drawContext.getScaledWindowWidth(); int width = drawContext.getScaledWindowWidth();
int height = drawContext.getScaledWindowHeight(); int height = drawContext.getScaledWindowHeight();
drawContext.fill(0, 0, width, height, ColorHelper.Argb.fromFloats(1, 1, 1, 1)); drawContext.fill(0, 0, width, height, ColorHelper.fromFloats(1, 1, 1, 1));
} }
} }
} }

View File

@@ -1,14 +1,12 @@
package systems.brn.plasticgun.companion; package systems.brn.plasticgun.companion;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
public class PlasticGunClient implements ClientModInitializer { public class PlasticGunClient implements ClientModInitializer {
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(ClientEvents::tick);
ClientPlayConnectionEvents.JOIN.register(ClientEvents::join); ClientPlayConnectionEvents.JOIN.register(ClientEvents::join);
HudRenderCallback.EVENT.register(ClientEvents::HUDDraw); HudRenderCallback.EVENT.register(ClientEvents::HUDDraw);
} }

View File

@@ -1,11 +1,14 @@
package systems.brn.plasticgun.defence; package systems.brn.plasticgun.defence;
import dev.emi.trinkets.api.Trinket;
import dev.emi.trinkets.api.TrinketsApi; import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.component.DataComponentTypes; import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent; import net.minecraft.component.type.LoreComponent;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import systems.brn.plasticgun.lib.TrinketPolymerItem; import systems.brn.plasticgun.lib.TrinketPolymerItem;
import systems.brn.plasticgun.lib.WeaponDamageType; import systems.brn.plasticgun.lib.WeaponDamageType;
@@ -15,7 +18,7 @@ import java.util.List;
import static systems.brn.plasticgun.lib.Util.id; import static systems.brn.plasticgun.lib.Util.id;
public class WeaponArmor extends TrinketPolymerItem { public class WeaponArmor extends TrinketPolymerItem implements Trinket {
public final HashMap<WeaponDamageType, Double> resistances = new HashMap<>(); public final HashMap<WeaponDamageType, Double> resistances = new HashMap<>();
public WeaponArmor(String name, int durability, double grenadeDamageCoefficient, double fragmentationDamageCoefficient, double bulletDamageCoefficient, double shurikenDamageCoefficient) { public WeaponArmor(String name, int durability, double grenadeDamageCoefficient, double fragmentationDamageCoefficient, double bulletDamageCoefficient, double shurikenDamageCoefficient) {
@@ -25,7 +28,7 @@ public class WeaponArmor extends TrinketPolymerItem {
Text.translatable("gun.description.armor.grenade", (int) ((1 - grenadeDamageCoefficient) * 100)), Text.translatable("gun.description.armor.grenade", (int) ((1 - grenadeDamageCoefficient) * 100)),
Text.translatable("gun.description.armor.fragmentation_grenade", (int) ((1 - fragmentationDamageCoefficient) * 100)), Text.translatable("gun.description.armor.fragmentation_grenade", (int) ((1 - fragmentationDamageCoefficient) * 100)),
Text.translatable("gun.description.armor.shuriken", (int) ((1 - shurikenDamageCoefficient) * 100)) Text.translatable("gun.description.armor.shuriken", (int) ((1 - shurikenDamageCoefficient) * 100))
))) ))).registryKey(RegistryKey.of(RegistryKeys.ITEM, id(name)))
, name) , name)
; ;
Registry.register(Registries.ITEM, id(name), this); Registry.register(Registries.ITEM, id(name), this);

View File

@@ -5,10 +5,12 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld;
import systems.brn.plasticgun.PlasticGun; import systems.brn.plasticgun.PlasticGun;
import xyz.nucleoid.packettweaker.PacketContext;
import static systems.brn.plasticgun.PlasticGun.flashbangEffect; import static systems.brn.plasticgun.PlasticGun.flashbangEffect;
import static systems.brn.plasticgun.PlasticGun.stunEffect;
public class FlashbangEffect extends StatusEffect implements PolymerStatusEffect { public class FlashbangEffect extends StatusEffect implements PolymerStatusEffect {
public FlashbangEffect() { public FlashbangEffect() {
@@ -26,14 +28,13 @@ public class FlashbangEffect extends StatusEffect implements PolymerStatusEffect
// Called when the effect is applied. // Called when the effect is applied.
@Override @Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
return super.applyUpdateEffect(entity, amplifier); return super.applyUpdateEffect(world, entity, amplifier);
} }
@Override @Override
public StatusEffect getPolymerReplacement(ServerPlayerEntity player){ public StatusEffect getPolymerReplacement(StatusEffect potion, PacketContext packetContext) {
if (PlasticGun.clientsWithMod.contains(player)){ if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){
return flashbangEffect.value(); return stunEffect.value();
} }
return StatusEffects.BLINDNESS.value(); return StatusEffects.BLINDNESS.value();
} }

View File

@@ -6,10 +6,10 @@ import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory; import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld;
import systems.brn.plasticgun.PlasticGun; import systems.brn.plasticgun.PlasticGun;
import xyz.nucleoid.packettweaker.PacketContext;
import static systems.brn.plasticgun.PlasticGun.flashbangEffect;
import static systems.brn.plasticgun.PlasticGun.stunEffect; import static systems.brn.plasticgun.PlasticGun.stunEffect;
public class StunEffect extends StatusEffect implements PolymerStatusEffect { public class StunEffect extends StatusEffect implements PolymerStatusEffect {
@@ -35,16 +35,16 @@ public class StunEffect extends StatusEffect implements PolymerStatusEffect {
// Called when the effect is applied. // Called when the effect is applied.
@Override @Override
public boolean applyUpdateEffect(LivingEntity entity, int amplifier) { public boolean applyUpdateEffect(ServerWorld world, LivingEntity entity, int amplifier) {
applied = true; applied = true;
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, stunDuration, 255, true, false)); entity.addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, stunDuration, 255, true, false));
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, stunDuration, 255, true, false)); entity.addStatusEffect(new StatusEffectInstance(StatusEffects.JUMP_BOOST, stunDuration, 255, true, false));
return super.applyUpdateEffect(entity, amplifier); return super.applyUpdateEffect(world, entity, amplifier);
} }
@Override @Override
public StatusEffect getPolymerReplacement(ServerPlayerEntity player) { public StatusEffect getPolymerReplacement(StatusEffect potion, PacketContext packetContext) {
if (PlasticGun.clientsWithMod.contains(player)){ if (PlasticGun.clientsWithMod.contains(packetContext.getPlayer())){
return stunEffect.value(); return stunEffect.value();
} }
return null; return null;

View File

@@ -63,8 +63,8 @@ public class FragmentationExplosionBehavior extends ExplosionBehavior {
} }
@Override @Override
public float calculateDamage(Explosion explosion, Entity entity) { public float calculateDamage(Explosion explosion, Entity entity, float amount) {
float original = super.calculateDamage(explosion, entity); float original = super.calculateDamage(explosion, entity, amount);
if (entity instanceof LivingEntity livingEntity) { if (entity instanceof LivingEntity livingEntity) {
original = (float) getFinalDamage(livingEntity, WeaponDamageType.FRAGMENTATION_GRENADE, original); original = (float) getFinalDamage(livingEntity, WeaponDamageType.FRAGMENTATION_GRENADE, original);
if (original > 0) { if (original > 0) {

View File

@@ -6,7 +6,6 @@ import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType; import net.minecraft.entity.MovementType;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
@@ -14,7 +13,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import systems.brn.plasticgun.effects.FlashbangEffect;
import systems.brn.plasticgun.throwables.ThrowableProjectile; import systems.brn.plasticgun.throwables.ThrowableProjectile;
import java.util.List; import java.util.List;

View File

@@ -13,8 +13,8 @@ public class GrenadeExplosionBehavior extends ExplosionBehavior {
@Override @Override
public float calculateDamage(Explosion explosion, Entity entity) { public float calculateDamage(Explosion explosion, Entity entity, float amount) {
float original = super.calculateDamage(explosion, entity); float original = super.calculateDamage(explosion, entity, amount);
if (entity instanceof LivingEntity livingEntity) { if (entity instanceof LivingEntity livingEntity) {
original = (float) getFinalDamage(livingEntity, WeaponDamageType.GRENADE, original); original = (float) getFinalDamage(livingEntity, WeaponDamageType.GRENADE, original);
if (original > 0) { if (original > 0) {

View File

@@ -8,6 +8,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@@ -57,6 +59,7 @@ public class GrenadeItem extends SimpleItem implements PolymerItem {
Text.translatable("gun.description.effect_radius", effectRadius), Text.translatable("gun.description.effect_radius", effectRadius),
Text.translatable("gun.description.particle_count", smokeCount) Text.translatable("gun.description.particle_count", smokeCount)
))) )))
.registryKey(RegistryKey.of(RegistryKeys.ITEM, id(path)))
.maxDamage(explosionTarget + 1) .maxDamage(explosionTarget + 1)
, id(path), Items.STICK , id(path), Items.STICK
); );
@@ -114,14 +117,14 @@ public class GrenadeItem extends SimpleItem implements PolymerItem {
public void turnIntoEntity(ServerPlayerEntity player, @Nullable ItemStack stack, int speed, int timer) { public void turnIntoEntity(ServerPlayerEntity player, @Nullable ItemStack stack, int speed, int timer) {
GrenadeEntity grenadeEntity = new GrenadeEntity(player, stack, timer, 0.5f, speed, explosionPower, repulsionPower, isIncendiary, isFragmentation, flashBangDuration, stunDuration, smokeTicks, 8, smokeCount); GrenadeEntity grenadeEntity = new GrenadeEntity(player, stack, timer, 0.5f, speed, explosionPower, repulsionPower, isIncendiary, isFragmentation, flashBangDuration, stunDuration, smokeTicks, 8, smokeCount);
player.getServerWorld().spawnEntity(grenadeEntity); player.getWorld().spawnEntity(grenadeEntity);
player.getServerWorld().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0f, 2.0f); player.getWorld().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0f, 2.0f);
} }
public void turnIntoEntity(Entity entity, @Nullable ItemStack stack, int speed, int timer) { public void turnIntoEntity(Entity entity, @Nullable ItemStack stack, int speed, int timer) {
GrenadeEntity grenadeEntity = new GrenadeEntity(entity.getEntityWorld(), entity.getPos(), stack, timer, 1f, explosionPower, repulsionPower, isIncendiary, isFragmentation, flashBangDuration, stunDuration, smokeTicks, 8, smokeCount); GrenadeEntity grenadeEntity = new GrenadeEntity(entity.getWorld(), entity.getPos(), stack, timer, 1f, explosionPower, repulsionPower, isIncendiary, isFragmentation, flashBangDuration, stunDuration, smokeTicks, 8, smokeCount);
entity.getEntityWorld().spawnEntity(grenadeEntity); entity.getWorld().spawnEntity(grenadeEntity);
entity.getEntityWorld().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0f, 2.0f); entity.getWorld().playSound(null, entity.getX(), entity.getY(), entity.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0f, 2.0f);
} }
public void checkExplosions(ServerWorld world, PlayerEntity playerEntity, ItemStack stackInSlot) { public void checkExplosions(ServerWorld world, PlayerEntity playerEntity, ItemStack stackInSlot) {

View File

@@ -3,7 +3,6 @@ package systems.brn.plasticgun.guns;
import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.item.PolymerItem;
import net.minecraft.component.DataComponentTypes; import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent; import net.minecraft.component.type.LoreComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@@ -11,6 +10,8 @@ import net.minecraft.item.*;
import net.minecraft.network.packet.s2c.play.PositionFlag; import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@@ -29,8 +30,8 @@ import systems.brn.plasticgun.lib.SimpleItem;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static systems.brn.plasticgun.PlasticGun.bullets; import static java.lang.Math.*;
import static systems.brn.plasticgun.PlasticGun.itemBulletItemMap; import static systems.brn.plasticgun.PlasticGun.*;
import static systems.brn.plasticgun.lib.GunComponents.*; import static systems.brn.plasticgun.lib.GunComponents.*;
import static systems.brn.plasticgun.lib.Util.*; import static systems.brn.plasticgun.lib.Util.*;
@@ -74,15 +75,25 @@ public class Gun extends SimpleItem implements PolymerItem {
Text.translatable("gun.description.explosion_power", explosionPowerGun), Text.translatable("gun.description.explosion_power", explosionPowerGun),
Text.translatable("gun.description.repulsion_power", repulsionPowerGun) Text.translatable("gun.description.repulsion_power", repulsionPowerGun)
))) )))
.registryKey(RegistryKey.of(RegistryKeys.ITEM, id(path)))
.maxDamage(clipSize + 1) .maxDamage(clipSize + 1)
, id(path), Items.WOODEN_SWORD , id(path), Items.WOODEN_SWORD
); );
this.verticalRecoilMin = verticalRecoilMin; this.verticalRecoilMin = verticalRecoilMin / 100f;
this.verticalRecoilMax = verticalRecoilMax; this.verticalRecoilMax = verticalRecoilMax / 100f;
this.velocityRecoilMin = velocityRecoilMin; this.velocityRecoilMin = velocityRecoilMin;
this.velocityRecoilMax = velocityRecoilMax; this.velocityRecoilMax = velocityRecoilMax;
this.horizontalRecoilMin = horizontalRecoilMin; this.horizontalRecoilMin = horizontalRecoilMin / 100f;
this.horizontalRecoilMax = horizontalRecoilMax; this.horizontalRecoilMax = horizontalRecoilMax / 100f;
if (verticalRecoilMin > verticalRecoilMax) {
logger.error("verticalRecoilMin > verticalRecoilMax for {}", path);
}
if (horizontalRecoilMin > horizontalRecoilMax) {
logger.error("horizontalRecoilMin > horizontalRecoilMax for {}", path);
}
if (velocityRecoilMin > velocityRecoilMax) {
logger.error("velocityRecoilMin > velocityRecoilMax for {}", path);
}
Registry.register(Registries.ITEM, id(path), this); Registry.register(Registries.ITEM, id(path), this);
this.damage = damage; this.damage = damage;
this.reloadCount = reloadCount; this.reloadCount = reloadCount;
@@ -243,27 +254,30 @@ public class Gun extends SimpleItem implements PolymerItem {
stack.set(DataComponentTypes.LORE, newLore); stack.set(DataComponentTypes.LORE, newLore);
} }
public void doRecoil(LivingEntity entity) { public int doRecoil(LivingEntity entity) {
if (entity.getEntityWorld() instanceof ServerWorld serverWorld) { if (entity.getWorld() instanceof ServerWorld serverWorld) {
Random rng = entity.getWorld().getRandom(); Random rng = entity.getWorld().getRandom();
// Get the entity's current position and yaw // Get the entity's current position and yaw
Vec3d pos = entity.getPos(); Vec3d pos = entity.getPos();
float yaw = entity.getYaw(); float yaw = entity.getYaw();
float newPitch = entity.getPitch(); float newPitch = entity.getPitch();
Vec3d currentLook = entity.getRotationVector().multiply(-1); Vec3d currentLook = entity.getRotationVector().multiply(-1);
newPitch -= verticalRecoilMin + rng.nextFloat() * (verticalRecoilMax - verticalRecoilMin); float yawChange = verticalRecoilMin + rng.nextFloat() * (verticalRecoilMax - verticalRecoilMin);
yaw -= (float) (horizontalRecoilMin + rng.nextFloat() * (horizontalRecoilMax - horizontalRecoilMin)); float pitchChange = (float) (horizontalRecoilMin + rng.nextFloat() * (horizontalRecoilMax - horizontalRecoilMin));
newPitch -= yawChange;
yaw -= pitchChange;
entity.teleport(serverWorld, pos.x, pos.y, pos.z, PositionFlag.ROT, yaw, newPitch); entity.teleport(serverWorld, pos.x, pos.y, pos.z, PositionFlag.ROT, yaw, newPitch, true);
double velocityRecoil = rng.nextDouble() * (velocityRecoilMax - velocityRecoilMin); double velocityRecoil = rng.nextDouble() * (velocityRecoilMax - velocityRecoilMin);
if (velocityRecoil > 0) { if (velocityRecoil > 0) {
entity.setVelocity(currentLook.multiply(velocityRecoil)); entity.setVelocity(currentLook.multiply(velocityRecoil));
} }
return (int) ((abs(yawChange) + abs(pitchChange) + abs(velocityRecoil) + max(abs(yawChange), max(abs(pitchChange), abs(velocityRecoil)))) / 4f) * 40;
} }
return 0;
} }
public void shoot(ServerWorld world, LivingEntity user, Hand hand) { public int shoot(ServerWorld world, LivingEntity user, Hand hand) {
int stunLen = 0;
if (!world.isClient()) { if (!world.isClient()) {
ItemStack stack = user.getStackInHand(hand); ItemStack stack = user.getStackInHand(hand);
int currentReload = stack.getOrDefault(GUN_LOADING_COMPONENT, 1); int currentReload = stack.getOrDefault(GUN_LOADING_COMPONENT, 1);
@@ -281,7 +295,7 @@ public class Gun extends SimpleItem implements PolymerItem {
world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE.value(), SoundCategory.PLAYERS, 0.1f, 1.2f); world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE.value(), SoundCategory.PLAYERS, 0.1f, 1.2f);
chamber.decrement(1); chamber.decrement(1);
stack.set(GUN_COOLDOWN_COMPONENT, cooldownTarget); stack.set(GUN_COOLDOWN_COMPONENT, cooldownTarget);
doRecoil(user); stunLen = doRecoil(user);
if (chamber.isEmpty()) { if (chamber.isEmpty()) {
stack.remove(GUN_AMMO_COMPONENT); stack.remove(GUN_AMMO_COMPONENT);
} else { } else {
@@ -292,6 +306,7 @@ public class Gun extends SimpleItem implements PolymerItem {
} }
updateDamage(stack); updateDamage(stack);
} }
return stunLen;
} }
private @NotNull BulletEntity getBulletEntity(LivingEntity entity, Hand hand, BulletItem bullet, ItemStack chamber) { private @NotNull BulletEntity getBulletEntity(LivingEntity entity, Hand hand, BulletItem bullet, ItemStack chamber) {

View File

@@ -12,16 +12,11 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.RangedAttackMob; import net.minecraft.entity.ai.RangedAttackMob;
import net.minecraft.entity.ai.goal.Goal; import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.BowItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import static systems.brn.plasticgun.PlasticGun.guns;
import static systems.brn.plasticgun.PlasticGun.itemGunMap; import static systems.brn.plasticgun.PlasticGun.itemGunMap;
import static systems.brn.plasticgun.lib.GunComponents.*; import static systems.brn.plasticgun.lib.GunComponents.*;
@@ -152,7 +147,7 @@ public class WeaponShootGoal<T extends HostileEntity & RangedAttackMob> extends
if (itemGunMap.containsKey(gunStack.getItem())) { if (itemGunMap.containsKey(gunStack.getItem())) {
Gun gun = itemGunMap.get(gunStack.getItem()); Gun gun = itemGunMap.get(gunStack.getItem());
// Handle item usage // Handle item usage
gun.reload(this.actor.getEntityWorld(), this.actor, gunHand, this.actor.getRandom(), this.actor.getWorld().getLocalDifficulty(this.actor.getBlockPos())); gun.reload(this.actor.getWorld(), this.actor, gunHand, this.actor.getRandom(), this.actor.getWorld().getLocalDifficulty(this.actor.getBlockPos()));
if (!canSeeTarget && this.targetSeeingTicker < -60) { if (!canSeeTarget && this.targetSeeingTicker < -60) {
this.actor.clearActiveItem(); this.actor.clearActiveItem();
} else if (canSeeTarget) { } else if (canSeeTarget) {
@@ -161,8 +156,8 @@ public class WeaponShootGoal<T extends HostileEntity & RangedAttackMob> extends
int currentCooldown = gunStack.getOrDefault(GUN_COOLDOWN_COMPONENT, 1); int currentCooldown = gunStack.getOrDefault(GUN_COOLDOWN_COMPONENT, 1);
ItemStack chamber = gunStack.getOrDefault(GUN_AMMO_COMPONENT, ItemStack.EMPTY).copy(); ItemStack chamber = gunStack.getOrDefault(GUN_AMMO_COMPONENT, ItemStack.EMPTY).copy();
if (!chamber.isEmpty() && currentReload == 1 && currentCooldown == 0 && lockedTicks >= 10) { if (!chamber.isEmpty() && currentReload == 1 && currentCooldown == 0 && lockedTicks >= 10) {
if (this.actor.getEntityWorld() instanceof ServerWorld serverWorld) { if (this.actor.getWorld() instanceof ServerWorld serverWorld) {
gun.shoot(serverWorld, this.actor, gunHand); this.targetSeeingTicker -= gun.shoot(serverWorld, this.actor, gunHand);
} }
} }
} }

View File

@@ -3,13 +3,15 @@ package systems.brn.plasticgun.lib;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import static systems.brn.plasticgun.lib.Util.id; import static systems.brn.plasticgun.lib.Util.id;
public class CraftingItem extends SimpleItem{ public class CraftingItem extends SimpleItem{
public CraftingItem(String name) { public CraftingItem(String name) {
super(new Settings(), id(name), Items.STICK); super(new Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id(name))), id(name), Items.STICK);
Registry.register(Registries.ITEM, id(name), this); Registry.register(Registries.ITEM, id(name), this);
} }
} }

View File

@@ -15,16 +15,12 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import systems.brn.plasticgun.grenades.GrenadeEntity; import systems.brn.plasticgun.grenades.GrenadeEntity;
import systems.brn.plasticgun.grenades.GrenadeItem; import systems.brn.plasticgun.grenades.GrenadeItem;
import systems.brn.plasticgun.guns.Gun;
import systems.brn.plasticgun.packets.ModDetect; import systems.brn.plasticgun.packets.ModDetect;
import systems.brn.plasticgun.packets.Reload;
import systems.brn.plasticgun.packets.Shoot;
import systems.brn.plasticgun.shurikens.ShurikenItem;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -32,18 +28,17 @@ import static systems.brn.plasticgun.PlasticGun.*;
import static systems.brn.plasticgun.lib.GunComponents.*; import static systems.brn.plasticgun.lib.GunComponents.*;
public class EventHandler { public class EventHandler {
public static TypedActionResult<ItemStack> onItemUse(PlayerEntity playerEntity, World world, Hand hand) { public static ActionResult onItemUse(PlayerEntity playerEntity, World world, Hand hand) {
ItemStack stack = playerEntity.getStackInHand(hand);
if (playerEntity instanceof ServerPlayerEntity serverPlayerEntity) { if (playerEntity instanceof ServerPlayerEntity serverPlayerEntity) {
if (!world.isClient && !clientsWithMod.contains(serverPlayerEntity)) { if (!world.isClient) {
rightClickWithItem(serverPlayerEntity, hand); rightClickWithItem(serverPlayerEntity, hand);
} }
} }
return TypedActionResult.pass(stack); return ActionResult.PASS;
} }
public static void rightClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) { public static void rightClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) {
if (serverPlayerEntity.getEntityWorld() instanceof ServerWorld world) { if (serverPlayerEntity.getWorld() instanceof ServerWorld world) {
Item stackInHand = serverPlayerEntity.getStackInHand(hand).getItem(); Item stackInHand = serverPlayerEntity.getStackInHand(hand).getItem();
if (itemGunMap.containsKey(stackInHand)) { if (itemGunMap.containsKey(stackInHand)) {
itemGunMap.get(stackInHand).reload(world, serverPlayerEntity, hand); itemGunMap.get(stackInHand).reload(world, serverPlayerEntity, hand);
@@ -59,7 +54,7 @@ public class EventHandler {
} }
public static void leftClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) { public static void leftClickWithItem(ServerPlayerEntity serverPlayerEntity, Hand hand) {
if (serverPlayerEntity.getEntityWorld() instanceof ServerWorld world) { if (serverPlayerEntity.getWorld() instanceof ServerWorld world) {
ItemStack stackInHand = serverPlayerEntity.getStackInHand(hand); ItemStack stackInHand = serverPlayerEntity.getStackInHand(hand);
Item itemInHand = stackInHand.getItem(); Item itemInHand = stackInHand.getItem();
if (itemGrenadeItemMap.containsKey(itemInHand)) { if (itemGrenadeItemMap.containsKey(itemInHand)) {
@@ -73,7 +68,7 @@ public class EventHandler {
} }
public static void tickItemUpdate(ServerPlayerEntity serverPlayerEntity) { public static void tickItemUpdate(ServerPlayerEntity serverPlayerEntity) {
if (serverPlayerEntity.getEntityWorld() instanceof ServerWorld world) { if (serverPlayerEntity.getWorld() instanceof ServerWorld world) {
Hand hand = serverPlayerEntity.getActiveHand(); Hand hand = serverPlayerEntity.getActiveHand();
ItemStack stackInHand = serverPlayerEntity.getStackInHand(hand); ItemStack stackInHand = serverPlayerEntity.getStackInHand(hand);
Item itemInHand = stackInHand.getItem(); Item itemInHand = stackInHand.getItem();
@@ -83,8 +78,8 @@ public class EventHandler {
} }
PlayerInventory playerInventory = serverPlayerEntity.getInventory(); PlayerInventory playerInventory = serverPlayerEntity.getInventory();
for (int i = 1; i < playerInventory.main.size(); i++) { for (int i = 1; i < playerInventory.getMainStacks().size(); i++) {
ItemStack stackInSlot = playerInventory.main.get(i); ItemStack stackInSlot = playerInventory.getMainStacks().get(i);
Item itemInSlot = stackInSlot.getItem(); Item itemInSlot = stackInSlot.getItem();
if (itemGrenadeItemMap.containsKey(itemInSlot)) { if (itemGrenadeItemMap.containsKey(itemInSlot)) {
decrementComponent(GRENADE_TIMER_COMPONENT, stackInSlot); decrementComponent(GRENADE_TIMER_COMPONENT, stackInSlot);
@@ -100,12 +95,11 @@ public class EventHandler {
public static void mobTickUpdate(ServerWorld world) { public static void mobTickUpdate(ServerWorld world) {
Predicate<Entity> allEntities = entity -> true; Predicate<Entity> allEntities = entity -> true;
for (SkeletonEntity skeletonEntity : world.getEntitiesByType(EntityType.SKELETON, allEntities)) { for (SkeletonEntity skeletonEntity : world.getEntitiesByType(EntityType.SKELETON, allEntities)) {
for (ItemStack itemStack : skeletonEntity.getEquippedItems()) { ItemStack itemStack = skeletonEntity.getActiveItem();
if (itemGunMap.containsKey(itemStack.getItem())) { if (itemGunMap.containsKey(itemStack.getItem())) {
decrementComponent(GUN_COOLDOWN_COMPONENT, itemStack); decrementComponent(GUN_COOLDOWN_COMPONENT, itemStack);
decrementComponent(GUN_RELOAD_COOLDOWN_COMPONENT, itemStack); decrementComponent(GUN_RELOAD_COOLDOWN_COMPONENT, itemStack);
} }
}
} }
} }
@@ -114,10 +108,8 @@ public class EventHandler {
if (!world.isClient) { if (!world.isClient) {
for (ServerPlayerEntity player : world.getPlayers()) { for (ServerPlayerEntity player : world.getPlayers()) {
Hand hand = player.getActiveHand(); Hand hand = player.getActiveHand();
if (!clientsWithMod.contains(player)) { if (player.handSwinging && player.handSwingTicks == -1) {
if (player.handSwinging && player.handSwingTicks == -1) { leftClickWithItem(player, hand);
leftClickWithItem(player, hand);
}
} }
tickItemUpdate(player); tickItemUpdate(player);
} }
@@ -163,16 +155,4 @@ public class EventHandler {
} }
} }
public static void onClientReload(Reload reload, ServerPlayNetworking.Context context) {
ServerPlayerEntity player = context.player();
Hand hand = player.getActiveHand();
rightClickWithItem(player, hand);
}
public static void onClientShoot(Shoot shoot, ServerPlayNetworking.Context context) {
ServerPlayerEntity player = context.player();
Hand hand = player.getActiveHand();
leftClickWithItem(player, hand);
}
} }

View File

@@ -3,7 +3,6 @@ package systems.brn.plasticgun.lib;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import eu.pb4.polymer.core.api.other.PolymerComponent; import eu.pb4.polymer.core.api.other.PolymerComponent;
import net.minecraft.component.ComponentType; import net.minecraft.component.ComponentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;

View File

@@ -2,35 +2,29 @@ package systems.brn.plasticgun.lib;
import eu.pb4.polymer.core.api.item.PolymerItem; import eu.pb4.polymer.core.api.item.PolymerItem;
import eu.pb4.polymer.core.api.item.SimplePolymerItem; import eu.pb4.polymer.core.api.item.SimplePolymerItem;
import eu.pb4.polymer.resourcepack.api.PolymerModelData; import eu.pb4.polymer.resourcepack.extras.api.ResourcePackExtras;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable; import xyz.nucleoid.packettweaker.PacketContext;
import systems.brn.plasticgun.PlasticGun;
public abstract class SimpleItem extends SimplePolymerItem implements PolymerItem { public abstract class SimpleItem extends SimplePolymerItem implements PolymerItem {
private final PolymerModelData polymerModel; private final Identifier polymerModel;
protected final Identifier identifier; protected final Identifier identifier;
public SimpleItem(Settings settings, Identifier identifier, Item replacement) { public SimpleItem(Settings settings, Identifier identifier, Item replacement) {
super(settings, replacement); super(settings, replacement);
this.identifier = identifier; this.identifier = identifier;
this.polymerModel = PolymerResourcePackUtils.requestModel(replacement, identifier.withPath("item/" + identifier.getPath())); this.polymerModel = identifier;
} }
@Override @Override
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) { public Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
if (PlasticGun.clientsWithMod.contains(player)) { return this.polymerModel;
return this;
}
return this.polymerModel.item();
} }
@Override @Override
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) { public Item getPolymerItem(ItemStack itemStack, PacketContext player) {
return this.polymerModel.value(); return Items.STICK;
} }
} }

View File

@@ -1,36 +1,30 @@
package systems.brn.plasticgun.lib; package systems.brn.plasticgun.lib;
import dev.emi.trinkets.TrinketSlot;
import dev.emi.trinkets.api.*; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundEvents;
import net.minecraft.sound.SoundEvent; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import java.util.Map;
import java.util.Optional;
import static systems.brn.plasticgun.lib.Util.id; import static systems.brn.plasticgun.lib.Util.id;
public class TrinketPolymerItem extends SimpleItem implements Trinket { public class TrinketPolymerItem extends SimpleItem {
public TrinketPolymerItem(Item.Settings settings, String name) { public TrinketPolymerItem(Item.Settings settings, String name) {
super(settings, id(name), Items.STICK); super(settings.equippable(EquipmentSlot.CHEST), id(name), Items.STICK);
TrinketsApi.registerTrinket(this, this);
} }
@Override @Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { public ActionResult use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand); ItemStack stack = user.getStackInHand(hand);
if (equipItem(user, stack)) { if (equipItem(user, stack)) {
return TypedActionResult.success(stack, world.isClient()); return ActionResult.SUCCESS;
} }
return super.use(world, user, hand); return super.use(world, user, hand);
} }
@@ -40,31 +34,8 @@ public class TrinketPolymerItem extends SimpleItem implements Trinket {
} }
public static boolean equipItem(LivingEntity user, ItemStack stack) { public static boolean equipItem(LivingEntity user, ItemStack stack) {
Optional<TrinketComponent> optional = TrinketsApi.getTrinketComponent(user); user.equipStack(EquipmentSlot.CHEST, stack);
if (optional.isPresent()) { user.playSound(SoundEvents.ITEM_ARMOR_EQUIP_CHAIN.value());
TrinketComponent comp = optional.get();
for (Map<String, TrinketInventory> group : comp.getInventory().values()) {
for (TrinketInventory inv : group.values()) {
for (int i = 0; i < inv.size(); i++) {
if (inv.getStack(i).isEmpty()) {
SlotReference ref = new SlotReference(inv, i);
if (TrinketSlot.canInsert(stack, ref, user)) {
ItemStack newStack = stack.copy();
inv.setStack(i, newStack);
Trinket trinket = TrinketsApi.getTrinket(stack.getItem());
RegistryEntry<SoundEvent> soundEvent = trinket.getEquipSound(stack, ref, user);
if (!stack.isEmpty() && soundEvent != null) {
user.emitGameEvent(GameEvent.EQUIP);
user.playSound(soundEvent.value(), 1.0F, 1.0F);
}
stack.setCount(0);
return true;
}
}
}
}
}
}
return false; return false;
} }
} }

View File

@@ -1,19 +1,12 @@
package systems.brn.plasticgun.lib; package systems.brn.plasticgun.lib;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData; import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData;
import net.fabricmc.loader.impl.lib.sat4j.core.Vec; import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.particle.BlockDustParticle;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@@ -21,17 +14,15 @@ import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@@ -44,14 +35,10 @@ import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior; import net.minecraft.world.explosion.ExplosionBehavior;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f; import org.joml.Vector3f;
import systems.brn.plasticgun.PlasticGun;
import systems.brn.plasticgun.defence.WeaponArmor; import systems.brn.plasticgun.defence.WeaponArmor;
import java.util.*; import java.util.*;
import java.util.function.Function;
import static net.minecraft.entity.projectile.AbstractWindChargeEntity.EXPLOSION_BEHAVIOR;
import static net.minecraft.world.explosion.Explosion.getExposure;
import static systems.brn.plasticgun.PlasticGun.*; import static systems.brn.plasticgun.PlasticGun.*;
public class Util { public class Util {
@@ -64,7 +51,7 @@ public class Util {
if (bulletItem == null || bulletItem.isEmpty()) { if (bulletItem == null || bulletItem.isEmpty()) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
for (ItemStack itemStack : player.getInventory().main) { for (ItemStack itemStack : player.getInventory().getMainStacks()) {
for (Item item : bulletItem) { for (Item item : bulletItem) {
if (item == itemStack.getItem()) { if (item == itemStack.getItem()) {
return itemStack; return itemStack;
@@ -80,8 +67,8 @@ public class Util {
if (inventory instanceof PlayerInventory playerInventory) { if (inventory instanceof PlayerInventory playerInventory) {
// Iterate through the slots in the player's inventory // Iterate through the slots in the player's inventory
for (int i = 0; i < playerInventory.main.size(); i++) { for (int i = 0; i < playerInventory.getMainStacks().size(); i++) {
ItemStack slotStack = playerInventory.main.get(i); ItemStack slotStack = playerInventory.getMainStacks().get(i);
maxInsert = canInsertToStack(slotStack, itemStack, maxInsert); maxInsert = canInsertToStack(slotStack, itemStack, maxInsert);
} }
} else { } else {
@@ -148,7 +135,7 @@ public class Util {
int minZ = MathHelper.floor(pos.z - radius - 1.0); int minZ = MathHelper.floor(pos.z - radius - 1.0);
int maxZ = MathHelper.floor(pos.z + radius + 1.0); int maxZ = MathHelper.floor(pos.z + radius + 1.0);
Box box = new Box(minX, minY, minZ, maxX, maxY, maxZ); Box box = new Box(minX, minY, minZ, maxX, maxY, maxZ);
return entity.getEntityWorld().getOtherEntities(entity, box); return entity.getWorld().getOtherEntities(entity, box);
} }
public static void setProjectileData(List<DataTracker.SerializedEntry<?>> data, boolean initial, float scale, ItemStack itemStack) { public static void setProjectileData(List<DataTracker.SerializedEntry<?>> data, boolean initial, float scale, ItemStack itemStack) {
@@ -157,7 +144,6 @@ public class Util {
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.SCALE, new Vector3f(scale))); data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.SCALE, new Vector3f(scale)));
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.BILLBOARD, (byte) DisplayEntity.BillboardMode.CENTER.ordinal())); data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.BILLBOARD, (byte) DisplayEntity.BillboardMode.CENTER.ordinal()));
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.Item.ITEM, itemStack)); data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.Item.ITEM, itemStack));
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.Item.ITEM_DISPLAY, ModelTransformationMode.FIXED.getIndex()));
} }
} }
@@ -173,36 +159,26 @@ public class Util {
} }
public static double getFinalDamage(LivingEntity livingEntity, WeaponDamageType damageType, double damage) { public static double getFinalDamage(LivingEntity livingEntity, WeaponDamageType damageType, double damage) {
Optional<TrinketComponent> trinketComponentTemp = TrinketsApi.getTrinketComponent(livingEntity); for (WeaponArmor weaponArmor : weaponArmors) {
if (trinketComponentTemp.isPresent()) { if (weaponArmor.resistances.containsKey(damageType)) {
TrinketComponent trinketComponent = trinketComponentTemp.get();
for (WeaponArmor weaponArmor : weaponArmors) {
if (weaponArmor.resistances.containsKey(damageType)) {
List<Pair<SlotReference, ItemStack>> vestsComponents = trinketComponent.getEquipped(weaponArmor); ItemStack chestStack = livingEntity.getEquippedStack(EquipmentSlot.CHEST);
if (!vestsComponents.isEmpty()) { int currentDamage = chestStack.getDamage();
Pair<SlotReference, ItemStack> vestComponent = vestsComponents.getFirst(); int maxDamage = chestStack.getMaxDamage();
TrinketInventory trinketInventory = vestComponent.getLeft().inventory(); double reducedDamage = 0;
int currentDamage = vestComponent.getRight().getDamage(); if (currentDamage < maxDamage) {
int maxDamage = vestComponent.getRight().getMaxDamage(); double coefficient = weaponArmor.resistances.get(damageType);
double reducedDamage = 0; reducedDamage = (1 - coefficient) * damage;
if (currentDamage < maxDamage) { damage *= coefficient;
double coefficient = weaponArmor.resistances.get(damageType);
reducedDamage = (1 - coefficient) * damage;
damage *= coefficient;
}
int nextDamage = currentDamage + (int) reducedDamage;
int inventoryIndex = vestComponent.getLeft().index();
ItemStack vestStack = trinketInventory.getStack(inventoryIndex);
if (nextDamage >= maxDamage) {
vestStack.setCount(0);
} else {
vestStack.setDamage(nextDamage);
}
trinketInventory.setStack(inventoryIndex, vestStack);
}
} }
int nextDamage = currentDamage + (int) reducedDamage;
if (nextDamage >= maxDamage) {
chestStack.setCount(0);
} else {
chestStack.setDamage(nextDamage);
}
livingEntity.equipStack(EquipmentSlot.CHEST, chestStack);
} }
} }
return damage; return damage;
@@ -236,7 +212,6 @@ public class Util {
case EASY -> 1; case EASY -> 1;
case NORMAL -> 2; case NORMAL -> 2;
case HARD -> 3; case HARD -> 3;
default -> 1;
}; };
// Determine the chance to equip a gun // Determine the chance to equip a gun
@@ -286,7 +261,13 @@ public class Util {
} }
public static void entityHitParticles(LivingEntity livingEntity, double damage) { public static void entityHitParticles(LivingEntity livingEntity, double damage) {
if (livingEntity.getEntityWorld() instanceof ServerWorld world) { if (livingEntity.getWorld() instanceof ServerWorld world) {
if (livingEntity instanceof ServerPlayerEntity) {
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) livingEntity;
if (serverPlayerEntity.isCreative()) {
return;
}
}
Vec3d pos = livingEntity.getPos(); Vec3d pos = livingEntity.getPos();
int particleCount = (int) damage * 4; // Number of particles int particleCount = (int) damage * 4; // Number of particles
double radius = livingEntity.getWidth() / 2 + 0.5; // Radius of the circle double radius = livingEntity.getWidth() / 2 + 0.5; // Radius of the circle
@@ -313,4 +294,16 @@ public class Util {
} }
} }
} }
}
public static void addItemToLootTable(RegistryKey<LootTable> tableId, Item item, Integer weight) {
LootTableEvents.MODIFY.register((key, tableBuilder, source, wrapperLookup) -> {
if (source.isBuiltin() && tableId.equals(key)) {
tableBuilder.modifyPools(poolBuilder -> poolBuilder.with(ItemEntry.builder(item).weight(weight)));
}
});
}
public static int getAfterWeight(float coeff, int weight) {
return (int) Math.ceil(coeff * weight);
}
}

View File

@@ -2,29 +2,22 @@ package systems.brn.plasticgun.mixins;
import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.ai.goal.BowAttackGoal; import net.minecraft.entity.ai.goal.BowAttackGoal;
import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.ai.goal.MeleeAttackGoal; import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.mob.AbstractSkeletonEntity; import net.minecraft.entity.mob.AbstractSkeletonEntity;
import net.minecraft.entity.projectile.ProjectileUtil; import net.minecraft.entity.projectile.ProjectileUtil;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.item.RangedWeaponItem; import net.minecraft.item.RangedWeaponItem;
import net.minecraft.util.Hand;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.Difficulty; import net.minecraft.world.Difficulty;
import net.minecraft.world.LocalDifficulty; import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import systems.brn.plasticgun.PlasticGun;
import systems.brn.plasticgun.guns.Gun;
import systems.brn.plasticgun.guns.WeaponShootGoal; import systems.brn.plasticgun.guns.WeaponShootGoal;
import static systems.brn.plasticgun.PlasticGun.guns; import static systems.brn.plasticgun.PlasticGun.guns;

View File

@@ -5,12 +5,10 @@ import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.ZombieEntity; import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.Difficulty;
import net.minecraft.world.LocalDifficulty; import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -18,7 +16,6 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import systems.brn.plasticgun.PlasticGun;
import systems.brn.plasticgun.grenades.GrenadeItem; import systems.brn.plasticgun.grenades.GrenadeItem;
import java.util.Arrays; import java.util.Arrays;
@@ -55,7 +52,9 @@ public abstract class ZombieGrenadeMixin extends MobEntity {
} else if (i < 14) { } else if (i < 14) {
int grenadeIndex = selectWeaponIndex(random, localDifficulty, grenades.size()); int grenadeIndex = selectWeaponIndex(random, localDifficulty, grenades.size());
stackToEquip = new ItemStack(grenades.get(grenadeIndex)); stackToEquip = new ItemStack(grenades.get(grenadeIndex));
Arrays.fill(this.handDropChances, 0F); for (EquipmentSlot slot : EquipmentSlot.values()) {
this.setEquipmentDropChance(slot, 0f);
}
} else { } else {
stackToEquip = new ItemStack(Items.IRON_SHOVEL); stackToEquip = new ItemStack(Items.IRON_SHOVEL);
} }

View File

@@ -1,11 +1,9 @@
package systems.brn.plasticgun.packets; package systems.brn.plasticgun.packets;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload; import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import net.minecraft.util.Uuids; import net.minecraft.util.Uuids;
import java.util.UUID; import java.util.UUID;

View File

@@ -1,19 +0,0 @@
package systems.brn.plasticgun.packets;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Uuids;
import java.util.UUID;
public record Reload(UUID slapped) implements CustomPayload {
public static final Id<Reload> PACKET_ID = new Id<>(CustomPayload.id("reload").id());
public static final PacketCodec<RegistryByteBuf, Reload> PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Reload::new, Reload::slapped).cast();
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

View File

@@ -1,19 +0,0 @@
package systems.brn.plasticgun.packets;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Uuids;
import java.util.UUID;
public record Shoot(UUID slapped) implements CustomPayload {
public static final Id<Shoot> PACKET_ID = new Id<>(CustomPayload.id("shoot").id());
public static final PacketCodec<RegistryByteBuf, Shoot> PACKET_CODEC = Uuids.PACKET_CODEC.xmap(Shoot::new, Shoot::slapped).cast();
@Override
public Id<? extends CustomPayload> getId() {
return PACKET_ID;
}
}

View File

@@ -33,7 +33,7 @@ public class ShurikenEntity extends ThrowableProjectile implements PolymerEntity
if (blockHitResult.getType() == HitResult.Type.BLOCK) { if (blockHitResult.getType() == HitResult.Type.BLOCK) {
BlockState block = this.getWorld().getBlockState(blockHitResult.getBlockPos()); BlockState block = this.getWorld().getBlockState(blockHitResult.getBlockPos());
blockHitParticles(this.getPos(), block, this.getWorld(), this.getDamage() * this.getVelocity().length()); blockHitParticles(this.getPos(), block, this.getWorld(), this.damage * this.getVelocity().length());
SoundEvent soundEvent = block.getSoundGroup().getHitSound(); SoundEvent soundEvent = block.getSoundGroup().getHitSound();
setSilent(false); setSilent(false);
playSound(soundEvent, 4.0F, 1.0F); playSound(soundEvent, 4.0F, 1.0F);
@@ -54,8 +54,8 @@ public class ShurikenEntity extends ThrowableProjectile implements PolymerEntity
@Override @Override
protected void onEntityHit(EntityHitResult entityHitResult) { protected void onEntityHit(EntityHitResult entityHitResult) {
if (entityHitResult.getEntity() instanceof LivingEntity livingEntity) { if (entityHitResult.getEntity() instanceof LivingEntity livingEntity) {
this.setDamage(getFinalDamage(livingEntity, WeaponDamageType.SHURIKEN, this.getDamage())); this.setDamage(getFinalDamage(livingEntity, WeaponDamageType.SHURIKEN, this.damage));
entityHitParticles(livingEntity, this.getDamage()); entityHitParticles(livingEntity, this.damage);
} }
super.onEntityHit(entityHitResult); super.onEntityHit(entityHitResult);

View File

@@ -8,13 +8,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.world.World;
import systems.brn.plasticgun.lib.SimpleItem; import systems.brn.plasticgun.lib.SimpleItem;
import java.util.List; import java.util.List;
@@ -36,6 +37,7 @@ public class ShurikenItem extends SimpleItem implements PolymerItem {
Text.translatable("gun.description.speed", speed), Text.translatable("gun.description.speed", speed),
Text.translatable("gun.description.damage_with_coefficient_max_speed", speed, speed * damage) Text.translatable("gun.description.damage_with_coefficient_max_speed", speed, speed * damage)
))) )))
.registryKey(RegistryKey.of(RegistryKeys.ITEM, id(path)))
, id(path), Items.WOODEN_PICKAXE , id(path), Items.WOODEN_PICKAXE
); );
Registry.register(Registries.ITEM, id(path), this); Registry.register(Registries.ITEM, id(path), this);

View File

@@ -10,11 +10,12 @@ import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.entity.PolymerEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;
import java.util.Collections; import java.util.Collections;
@@ -25,10 +26,10 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
} }
@Override @Override
public boolean damage(DamageSource source, float amount) { public boolean damage(ServerWorld world, DamageSource source, float amount) {
Entity attacker = source.getAttacker(); Entity attacker = source.getAttacker();
if (attacker instanceof PlayerEntity player) { if (attacker instanceof PlayerEntity player) {
player.sendMessage(Text.literal("You damaged by " + amount)); player.sendMessage(Text.literal("You damaged by " + amount), false);
if (player.isSneaking()) { if (player.isSneaking()) {
this.remove(RemovalReason.KILLED); this.remove(RemovalReason.KILLED);
} }
@@ -39,18 +40,8 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
public static DefaultAttributeContainer.Builder createDamageTesterAttributes() { public static DefaultAttributeContainer.Builder createDamageTesterAttributes() {
return LivingEntity.createLivingAttributes() return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 1.0) .add(EntityAttributes.MAX_HEALTH, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 0.0); .add(EntityAttributes.ATTACK_DAMAGE, 0.0);
}
@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
return EntityType.ZOMBIE;
}
@Override
public Iterable<ItemStack> getArmorItems() {
return Collections.emptyList();
} }
@Override @Override
@@ -67,4 +58,9 @@ public class DamageTester extends LivingEntity implements PolymerEntity {
public Arm getMainArm() { public Arm getMainArm() {
return Arm.RIGHT; return Arm.RIGHT;
} }
@Override
public EntityType<?> getPolymerEntityType(PacketContext context) {
return EntityType.ZOMBIE;
}
} }

View File

@@ -9,6 +9,7 @@ import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import xyz.nucleoid.packettweaker.PacketContext;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
@@ -17,31 +18,43 @@ import static systems.brn.plasticgun.lib.Util.setProjectileData;
public class ThrowableProjectile extends PersistentProjectileEntity implements PolymerEntity { public class ThrowableProjectile extends PersistentProjectileEntity implements PolymerEntity {
private ItemStack itemStack = Items.ARROW.getDefaultStack(); private ItemStack itemStack = Items.ARROW.getDefaultStack();
public final EntityType<? extends PersistentProjectileEntity> entityType;
private final float scale; private final float scale;
public double prevX;
public double prevY;
public double prevZ;
public ThrowableProjectile(EntityType<? extends ThrowableProjectile> entityType, World world, Vec3d pos, ItemStack itemStack, float scale, double damage, PickupPermission pickupPermission, byte penetration) { public ThrowableProjectile(EntityType<? extends ThrowableProjectile> entityType, World world, Vec3d pos, ItemStack itemStack, float scale, double damage, PickupPermission pickupPermission, byte penetration) {
super(entityType, pos.getX(), pos.getY() + 1.5d, pos.getZ(), world, itemStack, null); super(entityType, pos.getX(), pos.getY() + 1.5d, pos.getZ(), world, itemStack, null);
this.pickupType = pickupPermission; this.pickupType = pickupPermission;
this.setDamage(damage); this.setDamage(damage);
this.setSilent(true); this.setSilent(true);
this.scale = scale; this.scale = scale;
this.entityType = entityType;
this.setCustomPierceLevel(penetration); this.setCustomPierceLevel(penetration);
this.setItemStack(itemStack.copy()); this.setItemStack(itemStack.copy());
} }
public ThrowableProjectile(EntityType<? extends PersistentProjectileEntity> entityType, ServerPlayerEntity player, ItemStack itemStack, float scale, float speed, double damage, PickupPermission pickupPermission, byte penetration) { public ThrowableProjectile(EntityType<? extends PersistentProjectileEntity> entityType, ServerPlayerEntity player, ItemStack itemStack, float scale, float speed, double damage, PickupPermission pickupPermission, byte penetration) {
super(entityType, player.getPos().x, player.getPos().y + 1.5d, player.getPos().z, player.getServerWorld(), itemStack, itemStack); super(entityType, player.getPos().x, player.getPos().y + 1.5d, player.getPos().z, player.getWorld(), itemStack, itemStack);
this.setOwner(player); this.setOwner(player);
this.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, speed, 0); this.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, speed, 0);
this.pickupType = pickupPermission; this.pickupType = pickupPermission;
this.setDamage(damage); this.setDamage(damage);
this.setSilent(true); this.setSilent(true);
this.scale = scale; this.scale = scale;
this.entityType = entityType;
this.setCustomPierceLevel(penetration); this.setCustomPierceLevel(penetration);
this.setItemStack(itemStack); this.setItemStack(itemStack);
} }
@Override
public EntityType<?> getPolymerEntityType(PacketContext context) {
return EntityType.ITEM_DISPLAY;
}
@Override @Override
public void modifyRawTrackedData(List<DataTracker.SerializedEntry<?>> data, ServerPlayerEntity player, boolean initial) { public void modifyRawTrackedData(List<DataTracker.SerializedEntry<?>> data, ServerPlayerEntity player, boolean initial) {
setProjectileData(data, initial, scale, this.itemStack); setProjectileData(data, initial, scale, this.itemStack);
@@ -70,10 +83,5 @@ public class ThrowableProjectile extends PersistentProjectileEntity implements P
return this.itemStack(); return this.itemStack();
} }
@Override
public EntityType<?> getPolymerEntityType(ServerPlayerEntity player) {
return EntityType.ITEM_DISPLAY;
}
} }

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/32_acp"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/32_acp_high_velocity"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/357_magnum"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/357_revolver"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/357_standard"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/38_special"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/38_special_p"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/45_acp"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/45_acp_hollow_point"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/762_tokarev"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/762_tokarev_ap"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/9mm_jhp"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/9mm_parabellum"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/advanced_circuit"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/ak_47"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/alloy_wheel"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/awp"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/ceramic_mixture"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/ceramic_plate"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/colt_1903"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/colt_45"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/colt_peacemaker"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/composite_frame"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/composite_resin"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/copper_wiring"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/diamond_shuriken"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/enhanced_gunpowder"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/explosive_powder"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/flak_vest"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/force_container"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/forcegun"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/golden_shuriken"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/graphene_sheet"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_an_m14"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_f1"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_k417"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_m18"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_m34"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_m67"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_m7a3"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_m84"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_mk3a2"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_no_69"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_rgd_5"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_rgo"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/grenade_thermite"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/hardened_steel"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/hyperalloy"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/iron_shuriken"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/kevlar_sheet"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/kevlar_vest"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/magnetic_coil"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/microchip"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/nano_tubes"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/netherite_shuriken"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/p2022"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/plasma_core"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/power_cell"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/precision_gear"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/reinforced_fiber"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/rpg9"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/rpg_shell"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/rpg_shell_incendiary"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/silicon_mixture"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/silicon_wafer"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/snub_nosed_revolver"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/stone_shuriken"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "plasticgun:item/titanium_alloy"
}
}

Some files were not shown because too many files have changed in this diff Show More