Add stuff
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
package systems.brn.plasticgun.lib;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.world.World;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import systems.brn.plasticgun.grenades.GrenadeEntity;
|
||||
import systems.brn.plasticgun.grenades.GrenadeItem;
|
||||
import systems.brn.plasticgun.guns.Gun;
|
||||
import systems.brn.plasticgun.shurikens.ShurikenItem;
|
||||
|
||||
import static systems.brn.plasticgun.PlasticGun.*;
|
||||
import static systems.brn.plasticgun.lib.GunComponents.*;
|
||||
@@ -26,12 +32,26 @@ public class EventHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (GrenadeItem grenade : grenades) {
|
||||
if (grenade != null && grenade == stackInHand) {
|
||||
grenade.unpin(world, playerEntity, hand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (ShurikenItem shuriken : shurikens) {
|
||||
if (shuriken != null && shuriken == stackInHand) {
|
||||
shuriken.chuck(world, playerEntity, hand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return TypedActionResult.pass(stack);
|
||||
}
|
||||
|
||||
|
||||
public static void onWorldTick(World world) {
|
||||
public static void onServerWorldTick(ServerWorld world) {
|
||||
// Iterate through all players to detect hand swings or item interactions
|
||||
for (PlayerEntity player : world.getPlayers()) {
|
||||
if (!world.isClient) {
|
||||
@@ -49,6 +69,65 @@ public class EventHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (GrenadeItem grenade : grenades) {
|
||||
if (grenade != null && grenade == itemInHand) {
|
||||
if (player.handSwinging && player.handSwingTicks == -1) {
|
||||
grenade.chuck(world, player, hand);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (ShurikenItem shuriken : shurikens) {
|
||||
if (shuriken != null && shuriken == itemInHand) {
|
||||
if (player.handSwinging && player.handSwingTicks == -1) {
|
||||
shuriken.chuck(world, player, hand);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
for (int i = 1; i < playerInventory.main.size(); i++) {
|
||||
ItemStack stackInSlot = playerInventory.main.get(i);
|
||||
Item itemInSlot = stackInSlot.getItem();
|
||||
for (GrenadeItem grenadeItem : grenades) {
|
||||
if (grenadeItem == itemInSlot) {
|
||||
decrementComponent(GRENADE_TIMER_COMPONENT, stackInSlot);
|
||||
GrenadeItem.updateDamage(stackInSlot, grenadeItem);
|
||||
grenadeItem.checkExplosions(world, player, stackInSlot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void onEntityLoad(Entity entity, ServerWorld world) {
|
||||
if (entity instanceof ItemEntity itemEntity) {
|
||||
ItemStack entityStack = itemEntity.getStack();
|
||||
for (GrenadeItem grenadeItem : grenades) {
|
||||
if (entityStack.getItem() == grenadeItem) {
|
||||
Entity owner = itemEntity.getOwner();
|
||||
int timer = (1 + grenadeItem.explosionTarget) - entityStack.getDamage();
|
||||
if (timer <= grenadeItem.explosionTarget) {
|
||||
if (owner instanceof ServerPlayerEntity player) {
|
||||
GrenadeEntity grenadeEntity = new GrenadeEntity(player, entityStack, timer, 1f, 0, grenadeItem.explosionPower, grenadeItem.repulsionPower, grenadeItem.isIncendiary, grenadeItem.isFragmentation, grenadeItem.flashBangDuration, grenadeItem.stunDuration, grenadeItem.smokeTicks, grenadeItem.smokeRadius, grenadeItem.smokeCount);
|
||||
grenadeEntity.setVelocity(entity.getVelocity());
|
||||
world.spawnEntity(grenadeEntity);
|
||||
world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0f, 2.0f);
|
||||
} else {
|
||||
GrenadeEntity grenadeEntity = new GrenadeEntity(world, entity.getPos(), entityStack, timer, 1f, grenadeItem.explosionPower, grenadeItem.repulsionPower, grenadeItem.isIncendiary, grenadeItem.isFragmentation, grenadeItem.flashBangDuration, grenadeItem.stunDuration, grenadeItem.smokeTicks, grenadeItem.smokeRadius, grenadeItem.smokeCount);
|
||||
grenadeEntity.setVelocity(entity.getVelocity());
|
||||
world.spawnEntity(grenadeEntity);
|
||||
}
|
||||
entity.discard();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ public class GunComponents {
|
||||
public static final ComponentType<Integer> GUN_LOADING_COMPONENT = register("gun_load", builder -> builder.codec(Codec.INT));
|
||||
public static final ComponentType<Integer> GUN_COOLDOWN_COMPONENT = register("gun_cooldown", builder -> builder.codec(Codec.INT));
|
||||
public static final ComponentType<Integer> GUN_RELOAD_COOLDOWN_COMPONENT = register("gun_reload_cooldown", builder -> builder.codec(Codec.INT));
|
||||
public static final ComponentType<Integer> GRENADE_TIMER_COMPONENT = register("grenade_tuner", builder -> builder.codec(Codec.INT));
|
||||
|
||||
private static <T> ComponentType<T> register(String id, UnaryOperator<ComponentType.Builder<T>> builderOperator) {
|
||||
ComponentType<T> componentType = Registry.register(
|
||||
|
66
src/main/java/systems/brn/plasticgun/lib/ItemGroups.java
Normal file
66
src/main/java/systems/brn/plasticgun/lib/ItemGroups.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package systems.brn.plasticgun.lib;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import systems.brn.plasticgun.PlasticGun;
|
||||
import systems.brn.plasticgun.bullets.BulletItem;
|
||||
import systems.brn.plasticgun.grenades.GrenadeItem;
|
||||
import systems.brn.plasticgun.guns.Gun;
|
||||
import systems.brn.plasticgun.shurikens.ShurikenItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static systems.brn.plasticgun.lib.Util.id;
|
||||
|
||||
public class ItemGroups {
|
||||
public static final ItemGroup GUNS_GROUP = PolymerItemGroupUtils.builder()
|
||||
.icon(() -> new ItemStack(PlasticGun.guns.getFirst()))
|
||||
.displayName(Text.translatable("guns.groups.guns"))
|
||||
.entries(((context, entries) -> {
|
||||
for (Gun gun : PlasticGun.guns) {
|
||||
entries.add(gun);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
public static final ItemGroup AMMO_GROUP = PolymerItemGroupUtils.builder()
|
||||
.icon(() -> new ItemStack(PlasticGun.bullets.getFirst()))
|
||||
.displayName(Text.translatable("guns.groups.ammo"))
|
||||
.entries(((context, entries) -> {
|
||||
for (BulletItem bulletItem : PlasticGun.bullets) {
|
||||
entries.add(bulletItem);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
public static final ItemGroup SHURIKEN_GROUP = PolymerItemGroupUtils.builder()
|
||||
.icon(() -> new ItemStack(PlasticGun.shurikens.getFirst()))
|
||||
.displayName(Text.translatable("guns.groups.shurikens"))
|
||||
.entries(((context, entries) -> {
|
||||
for (ShurikenItem shurikenItem : PlasticGun.shurikens) {
|
||||
entries.add(shurikenItem);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
public static final ItemGroup GRENADES_GROUP = PolymerItemGroupUtils.builder()
|
||||
.icon(() -> new ItemStack(PlasticGun.grenades.getFirst()))
|
||||
.displayName(Text.translatable("guns.groups.grenades"))
|
||||
.entries(((context, entries) -> {
|
||||
for (GrenadeItem grenadeItem : PlasticGun.grenades) {
|
||||
entries.add(grenadeItem);
|
||||
}
|
||||
}))
|
||||
.build();
|
||||
|
||||
public static void register() {
|
||||
PolymerItemGroupUtils.registerPolymerItemGroup(id("guns"), GUNS_GROUP);
|
||||
PolymerItemGroupUtils.registerPolymerItemGroup(id("ammo"), AMMO_GROUP);
|
||||
PolymerItemGroupUtils.registerPolymerItemGroup(id("shurikens"), SHURIKEN_GROUP);
|
||||
PolymerItemGroupUtils.registerPolymerItemGroup(id("grenades"), GRENADES_GROUP);
|
||||
}
|
||||
}
|
@@ -1,19 +1,27 @@
|
||||
package systems.brn.plasticgun.lib;
|
||||
|
||||
import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData;
|
||||
import net.minecraft.client.render.model.json.ModelTransformationMode;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.TntEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.data.DataTracker;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.world.explosion.ExplosionBehavior;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -148,5 +156,25 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setProjectileData(List<DataTracker.SerializedEntry<?>> data, boolean initial, float scale, ItemStack itemStack) {
|
||||
if (initial) {
|
||||
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.TELEPORTATION_DURATION, 2));
|
||||
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.Item.ITEM, itemStack));
|
||||
data.add(DataTracker.SerializedEntry.of(DisplayTrackedData.Item.ITEM_DISPLAY, ModelTransformationMode.FIXED.getIndex()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void hitDamage(Vec3d pos, double explosionPower, double repulsionPower, World worldTemp, @Nullable Entity entity, boolean isIncendiary, int radius, @Nullable ExplosionBehavior explosionBehavior) {
|
||||
if (worldTemp instanceof ServerWorld world) {
|
||||
if (explosionPower > 0) {
|
||||
world.createExplosion(entity, Explosion.createDamageSource(world, entity), explosionBehavior, pos.getX(), pos.getY(), pos.getZ(), (float) explosionPower, isIncendiary, ServerWorld.ExplosionSourceType.TNT);
|
||||
}
|
||||
if (repulsionPower > 0) {
|
||||
applyKnockbackToEntities(entity, pos, repulsionPower * 100, radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user