Integrated party system usage. Enhanced player interactions and team effects.
This commit is contained in:
@@ -37,22 +37,22 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
)
|
||||
public class ComradeHandler {
|
||||
/** Maps each party leader → Party object. Only the leader’s UUID is the key. */
|
||||
private static final Map<UUID, Party> PARTIES = new ConcurrentHashMap<>();
|
||||
public static final Map<UUID, Party> PARTIES = new ConcurrentHashMap<>();
|
||||
|
||||
/** If player X has been invited by leader Y, pendingInvites maps X → Y. */
|
||||
private static final Map<UUID, UUID> PENDING_INVITES = new ConcurrentHashMap<>();
|
||||
|
||||
/** A small helper class to store party data. */
|
||||
private static class Party {
|
||||
public static class Party {
|
||||
final UUID leader;
|
||||
final Set<UUID> members = ConcurrentHashMap.newKeySet();
|
||||
public final Set<UUID> members = ConcurrentHashMap.newKeySet();
|
||||
|
||||
Party(UUID leader) {
|
||||
this.leader = leader;
|
||||
this.members.add(leader);
|
||||
}
|
||||
|
||||
boolean isMember(UUID uuid) {
|
||||
public boolean isMember(UUID uuid) {
|
||||
return members.contains(uuid);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ComradeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<Party> findPartyOf(UUID uuid) {
|
||||
public static Optional<Party> findPartyOf(UUID uuid) {
|
||||
return PARTIES.values().stream()
|
||||
.filter(p -> p.isMember(uuid))
|
||||
.findAny();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.krituximon.stalinium.util.PlacedLogStorage;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -7,7 +8,6 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -22,21 +22,27 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
|
||||
public class StaliniumAxeItem extends AxeItem {
|
||||
public StaliniumAxeItem(Tier tier, Properties properties) {
|
||||
super(tier, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miningEntity) {
|
||||
if (!level.isClientSide && state.is(BlockTags.LOGS)) {
|
||||
cutDownTree(level, pos, (Player)miningEntity, stack);
|
||||
public boolean mineBlock(ItemStack stack,
|
||||
Level level,
|
||||
BlockState state,
|
||||
BlockPos pos,
|
||||
LivingEntity miningEntity) {
|
||||
if (!level.isClientSide() && state.is(BlockTags.LOGS) && miningEntity instanceof Player) {
|
||||
cutDownTree(level, pos, (Player) miningEntity, stack);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return true; // allow the chain to continue
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,19 +50,19 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void cutDownTree(Level level, BlockPos start, Player player, ItemStack stack) {
|
||||
private void cutDownTree(Level level,
|
||||
BlockPos start,
|
||||
Player player,
|
||||
ItemStack stack) {
|
||||
Set<BlockPos> toBreak = new HashSet<>();
|
||||
Deque<BlockPos> queue = new ArrayDeque<>();
|
||||
queue.add(start);
|
||||
PlacedLogStorage storage = PlacedLogStorage.get((ServerLevel) level);
|
||||
|
||||
while (!queue.isEmpty() && toBreak.size() < 256) {
|
||||
BlockPos current = queue.removeFirst();
|
||||
if (toBreak.contains(current)) continue;
|
||||
|
||||
BlockState bs = level.getBlockState(current);
|
||||
if (storage.contains(current) || !bs.is(BlockTags.LOGS)) continue;
|
||||
|
||||
toBreak.add(current);
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
for (int dy = 0; dy <= 1; dy++) {
|
||||
@@ -66,15 +72,29 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Player> allies = level
|
||||
.getEntitiesOfClass(Player.class,
|
||||
player.getBoundingBox().inflate(10.0),
|
||||
p -> p instanceof ServerPlayer);
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
List<Player> allies = new ArrayList<>();
|
||||
if (partyOpt.isPresent()) {
|
||||
ComradeHandler.Party party = partyOpt.get();
|
||||
ServerLevel serverLevel = (ServerLevel) level;
|
||||
for (UUID memberUuid : party.members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverLevel.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null) {
|
||||
if (online.distanceTo(player) <= 10.0) {
|
||||
allies.add(online);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BlockPos logPos : toBreak) {
|
||||
BlockState before = level.getBlockState(logPos);
|
||||
Block sapling = getSaplingForLog(before.getBlock());
|
||||
Block plankBlock = getPlankForLog(before.getBlock());
|
||||
level.destroyBlock(logPos, true, player);
|
||||
|
||||
if (sapling != null) {
|
||||
ItemStack saplingStack = new ItemStack(sapling);
|
||||
for (Player ally : allies) {
|
||||
@@ -92,7 +112,7 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
|
||||
private @Nullable Block getSaplingForLog(Block log) {
|
||||
ResourceLocation id = BuiltInRegistries.BLOCK.getKey(log);
|
||||
if (id == null ) return null;
|
||||
if (id == null) return null;
|
||||
String path = id.getPath();
|
||||
if (!path.endsWith("_log")) return null;
|
||||
String saplingPath = path.substring(0, path.length() - 4) + "_sapling";
|
||||
@@ -132,8 +152,11 @@ public class StaliniumAxeItem extends AxeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_axe.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_axe.tooltip"));
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.krituximon.stalinium.item.ModArmorMaterials;
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
@@ -14,8 +15,8 @@ import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -31,31 +32,53 @@ public class StaliniumBootsItem extends ArmorItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
|
||||
if (level.isClientSide() || !(entity instanceof Player player)) return;
|
||||
ItemStack boots = player.getInventory().getArmor(0);
|
||||
if (boots.getItem() != this) return;
|
||||
public void inventoryTick(ItemStack stack,
|
||||
Level level,
|
||||
Entity entity,
|
||||
int slotId,
|
||||
boolean isSelected) {
|
||||
if (level.isClientSide || !(entity instanceof Player)) return;
|
||||
Player player = (Player) entity;
|
||||
ItemStack feet = player.getItemBySlot(EquipmentSlot.FEET);
|
||||
if (feet.getItem() != this) return;
|
||||
UUID id = player.getUUID();
|
||||
int ticks = sprintTicks.getOrDefault(id, 0);
|
||||
if (player.isSprinting()) {
|
||||
ticks++;
|
||||
if (ticks >= SPRINT_THRESHOLD) {
|
||||
ticks = 0;
|
||||
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 5 * 20, 0, false, true));
|
||||
AABB area = player.getBoundingBox().inflate(RADIUS);
|
||||
List<Player> allies = level.getEntitiesOfClass(
|
||||
Player.class,
|
||||
area,
|
||||
p -> p instanceof ServerPlayer && p != player && player.isAlliedTo(p)
|
||||
);
|
||||
MobEffectInstance buff = new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 5 * 20, 0, false, true);
|
||||
player.addEffect(new MobEffectInstance(
|
||||
MobEffects.MOVEMENT_SPEED, 5 * 20, 0, false, true
|
||||
));
|
||||
List<Player> allies = new ArrayList<>();
|
||||
for (ComradeHandler.Party party : ComradeHandler.PARTIES.values()) {
|
||||
if (party.isMember(player.getUUID())) {
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
for (UUID memberUuid : party.members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverPlayer.level()
|
||||
.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null && online.distanceTo(player) <= RADIUS) {
|
||||
allies.add(online);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply Speed I to each ally
|
||||
for (Player ally : allies) {
|
||||
ally.addEffect(buff);
|
||||
ally.addEffect(new MobEffectInstance(
|
||||
MobEffects.MOVEMENT_SPEED, 5 * 20, 0, false, true
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ticks = 0;
|
||||
}
|
||||
|
||||
sprintTicks.put(id, ticks);
|
||||
}
|
||||
|
||||
@@ -63,14 +86,18 @@ public class StaliniumBootsItem extends ArmorItem {
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
net.minecraft.world.item.Item.TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_boots.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_boots.tooltip"));
|
||||
|
||||
+44
-22
@@ -1,6 +1,7 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.krituximon.stalinium.item.ModArmorMaterials;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -16,10 +17,9 @@ import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaliniumChestplateLeggingsItem extends ArmorItem {
|
||||
private static final Map<Holder<ArmorMaterial>, List<MobEffectInstance>> MATERIAL_TO_EFFECT_MAP =
|
||||
@@ -28,22 +28,30 @@ public class StaliniumChestplateLeggingsItem extends ArmorItem {
|
||||
List.of(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 100, 0, false, false)))
|
||||
.build();
|
||||
|
||||
public StaliniumChestplateLeggingsItem(Holder<ArmorMaterial> material, Type type, Properties properties) {
|
||||
public StaliniumChestplateLeggingsItem(Holder<ArmorMaterial> material,
|
||||
Type type,
|
||||
Properties properties) {
|
||||
super(material, type, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) {
|
||||
if (entity instanceof Player player && !level.isClientSide() && hasChestAndLeggingsOn(player)) {
|
||||
public void inventoryTick(ItemStack stack,
|
||||
Level level,
|
||||
Entity entity,
|
||||
int slotId,
|
||||
boolean isSelected) {
|
||||
if (level.isClientSide || !(entity instanceof Player)) return;
|
||||
Player player = (Player) entity;
|
||||
if (hasChestAndLeggingsOn(player)) {
|
||||
evaluateArmorEffects(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateArmorEffects(Player player) {
|
||||
for (Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
|
||||
for (Map.Entry<Holder<ArmorMaterial>, List<MobEffectInstance>> entry
|
||||
: MATERIAL_TO_EFFECT_MAP.entrySet()) {
|
||||
Holder<ArmorMaterial> mapArmorMaterial = entry.getKey();
|
||||
List<MobEffectInstance> mapEffect = entry.getValue();
|
||||
|
||||
if (hasPlayerCorrectArmorOn(mapArmorMaterial, player)) {
|
||||
addEffectToPlayer(player, mapEffect);
|
||||
}
|
||||
@@ -51,22 +59,26 @@ public class StaliniumChestplateLeggingsItem extends ArmorItem {
|
||||
}
|
||||
|
||||
private void addEffectToPlayer(Player player, List<MobEffectInstance> mapEffect) {
|
||||
AABB box = player.getBoundingBox().inflate(5.0);
|
||||
List<Player> allies = player.level().getEntitiesOfClass(
|
||||
Player.class,
|
||||
box,
|
||||
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
|
||||
);
|
||||
|
||||
for (MobEffectInstance effect : mapEffect) {
|
||||
player.addEffect(new MobEffectInstance(
|
||||
effect.getEffect(),
|
||||
effect.getDuration(),
|
||||
effect.getAmplifier(),
|
||||
effect.isAmbient(),
|
||||
effect.isVisible()));
|
||||
for (Player ally : allies) {
|
||||
ally.addEffect(new MobEffectInstance(
|
||||
effect.isVisible()
|
||||
));
|
||||
for (ComradeHandler.Party party : ComradeHandler.PARTIES.values()) {
|
||||
if (party.isMember(player.getUUID())) {
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
for (UUID memberUuid : party.members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverPlayer.level()
|
||||
.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null) {
|
||||
if (online.distanceTo(player) <= 5.0) {
|
||||
online.addEffect(new MobEffectInstance(
|
||||
effect.getEffect(),
|
||||
effect.getDuration(),
|
||||
effect.getAmplifier(),
|
||||
@@ -76,8 +88,14 @@ public class StaliniumChestplateLeggingsItem extends ArmorItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial, Player player) {
|
||||
private boolean hasPlayerCorrectArmorOn(Holder<ArmorMaterial> mapArmorMaterial,
|
||||
Player player) {
|
||||
ItemStack leggingsStack = player.getInventory().getArmor(1);
|
||||
ItemStack chestplateStack = player.getInventory().getArmor(2);
|
||||
|
||||
@@ -107,19 +125,23 @@ public class StaliniumChestplateLeggingsItem extends ArmorItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
net.minecraft.world.item.Item.TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
boolean shift = Screen.hasShiftDown();
|
||||
EquipmentSlot slot = this.getEquipmentSlot();
|
||||
if (slot == EquipmentSlot.CHEST) {
|
||||
tooltipComponents.add( shift
|
||||
? Component.translatable("item.stalinium_chestplate.tooltip_shift")
|
||||
: Component.translatable("item.stalinium_chestplate.tooltip") );
|
||||
: Component.translatable("item.stalinium_chestplate.tooltip")
|
||||
);
|
||||
} else if (slot == EquipmentSlot.LEGS) {
|
||||
tooltipComponents.add( shift
|
||||
? Component.translatable("item.stalinium_leggings.tooltip_shift")
|
||||
: Component.translatable("item.stalinium_leggings.tooltip") );
|
||||
: Component.translatable("item.stalinium_leggings.tooltip")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,11 +23,6 @@ public class StaliniumHelmetItem extends ArmorItem {
|
||||
public StaliniumHelmetItem(Holder<ArmorMaterial> material, Type slot, Properties props) {
|
||||
super(material, slot, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static subscriber that listens for when *any* player attacks an entity.
|
||||
* If the attacker is wearing our helmet, we give the target Glowing for 10 s.
|
||||
*/
|
||||
@EventBusSubscriber(modid = Stalinium.MODID)
|
||||
public static class HitSubscriber {
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.*;
|
||||
@@ -16,7 +16,10 @@ import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.CropBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaliniumHoeItem extends HoeItem {
|
||||
public StaliniumHoeItem(Tier tier, Item.Properties properties) {
|
||||
@@ -30,23 +33,23 @@ public class StaliniumHoeItem extends HoeItem {
|
||||
BlockState state = level.getBlockState(pos);
|
||||
Player player = ctx.getPlayer();
|
||||
|
||||
// Only run on server side and if it's raining at this position
|
||||
if (!level.isClientSide &&
|
||||
level.isRaining() &&
|
||||
level.isRainingAt(pos) &&
|
||||
state.getBlock() instanceof CropBlock) {
|
||||
// Only run on server side and if it's raining at this position and the block is a CropBlock
|
||||
if (!level.isClientSide()
|
||||
&& level.isRaining()
|
||||
&& level.isRainingAt(pos)
|
||||
&& state.getBlock() instanceof CropBlock) {
|
||||
|
||||
// Get the block's drops
|
||||
// Collect that block’s drops
|
||||
List<ItemStack> drops = Block.getDrops(
|
||||
state,
|
||||
(ServerLevel) level,
|
||||
pos,
|
||||
null, // no block entity
|
||||
ctx.getPlayer(),
|
||||
player,
|
||||
ctx.getItemInHand()
|
||||
);
|
||||
|
||||
// Multiply each drop's count by 2 and spawn them
|
||||
// Double each drop’s count and spawn them
|
||||
for (ItemStack drop : drops) {
|
||||
ItemStack doubled = drop.copy();
|
||||
doubled.setCount(drop.getCount() * 2);
|
||||
@@ -55,24 +58,39 @@ public class StaliniumHoeItem extends HoeItem {
|
||||
|
||||
// Destroy the block
|
||||
level.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
List<Player> comrades = level.getEntitiesOfClass(
|
||||
Player.class,
|
||||
player.getBoundingBox().inflate(8),
|
||||
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
|
||||
);
|
||||
RandomSource rand = level.getRandom();
|
||||
if (rand.nextFloat() < 0.5f) {
|
||||
if (!level.isClientSide() && player != null) {
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
if (partyOpt.isPresent()) {
|
||||
ComradeHandler.Party party = partyOpt.get();
|
||||
List<Player> comrades = new ArrayList<>();
|
||||
ServerLevel serverLevel = (ServerLevel) level;
|
||||
for (UUID memberUuid : party.members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverLevel.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null) {
|
||||
// Check distance (8 blocks)
|
||||
if (online.distanceTo(player) <= 8.0) {
|
||||
comrades.add(online);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 50% chance to send normal block drops to those comrades
|
||||
if (level.getRandom().nextFloat() < 0.5f) {
|
||||
for (ItemStack drop : Block.getDrops(state, (ServerLevel) level, pos, null)) {
|
||||
for (Player buddy : comrades) {
|
||||
buddy.addItem(drop.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.useOn(ctx); // fallback to normal hoe behavior
|
||||
return super.useOn(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,8 +104,11 @@ public class StaliniumHoeItem extends HoeItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_hoe.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_hoe.tooltip"));
|
||||
@@ -95,4 +116,3 @@ public class StaliniumHoeItem extends HoeItem {
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.PickaxeItem;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.DropExperienceBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaliniumPickaxeItem extends PickaxeItem {
|
||||
|
||||
public StaliniumPickaxeItem(Tier tier, Properties properties) {
|
||||
super(tier, properties);
|
||||
}
|
||||
@@ -32,22 +29,36 @@ public class StaliniumPickaxeItem extends PickaxeItem {
|
||||
BlockState state,
|
||||
BlockPos pos,
|
||||
LivingEntity miner) {
|
||||
if (!level.isClientSide && state.getBlock() instanceof DropExperienceBlock && miner instanceof Player player) {
|
||||
if (!level.isClientSide
|
||||
&& state.getBlock() instanceof DropExperienceBlock
|
||||
&& miner instanceof Player player) {
|
||||
mineVein(player, level, pos, state.getBlock());
|
||||
}
|
||||
List<Player> comrades = level.getEntitiesOfClass(
|
||||
Player.class,
|
||||
miner.getBoundingBox().inflate(8),
|
||||
p -> p instanceof ServerPlayer && miner.isAlliedTo(p)
|
||||
);
|
||||
RandomSource rand = level.getRandom();
|
||||
if (rand.nextFloat() < 0.5f) {
|
||||
if (!level.isClientSide && miner instanceof Player) {
|
||||
Player player = (Player) miner;
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
if (partyOpt.isPresent()) {
|
||||
List<Player> comrades = new ArrayList<>();
|
||||
ServerLevel serverLevel = (ServerLevel) level;
|
||||
for (UUID memberUuid : partyOpt.get().members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverLevel.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null && online.distanceTo(player) <= 8.0) {
|
||||
comrades.add(online);
|
||||
}
|
||||
}
|
||||
if (level.getRandom().nextFloat() < 0.5f) {
|
||||
for (ItemStack drop : Block.getDrops(state, (ServerLevel) level, pos, null)) {
|
||||
for (Player buddy : comrades) {
|
||||
buddy.addItem(drop.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.mineBlock(stack, level, state, pos, miner);
|
||||
}
|
||||
|
||||
@@ -69,34 +80,20 @@ public class StaliniumPickaxeItem extends PickaxeItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockPos p : toBreak) {
|
||||
level.destroyBlock(p, true, player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
public boolean hurtEnemy(ItemStack stack,
|
||||
LivingEntity target,
|
||||
LivingEntity attacker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDamageable(ItemStack stack) { return false; }
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_pickaxe.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_pickaxe.tooltip"));
|
||||
}
|
||||
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
|
||||
}
|
||||
public boolean isDamaged(ItemStack stack) { return false; }
|
||||
}
|
||||
@@ -1,25 +1,28 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ShovelItem;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaliniumShovelItem extends ShovelItem {
|
||||
public StaliniumShovelItem(Tier tier, Properties properties) {
|
||||
@@ -27,7 +30,11 @@ public class StaliniumShovelItem extends ShovelItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miningEntity) {
|
||||
public boolean mineBlock(ItemStack stack,
|
||||
Level level,
|
||||
BlockState state,
|
||||
BlockPos pos,
|
||||
LivingEntity miningEntity) {
|
||||
if (level.isClientSide) return true;
|
||||
if (state.is(BlockTags.MINEABLE_WITH_SHOVEL)) {
|
||||
boolean anyBroken = false;
|
||||
@@ -42,37 +49,45 @@ public class StaliniumShovelItem extends ShovelItem {
|
||||
}
|
||||
}
|
||||
if (anyBroken && miningEntity instanceof Player player) {
|
||||
MobEffectInstance selfHaste = new MobEffectInstance(MobEffects.DIG_SPEED, 100, 1, false, true, true);
|
||||
player.addEffect(selfHaste);
|
||||
var box = player.getBoundingBox().inflate(10.0);
|
||||
List<Player> allies = level.getEntitiesOfClass(
|
||||
Player.class,
|
||||
box,
|
||||
other -> other instanceof ServerPlayer && player.isAlliedTo(other)
|
||||
player.addEffect(new MobEffectInstance(
|
||||
net.minecraft.world.effect.MobEffects.DIG_SPEED, 100, 1, false, true, true
|
||||
));
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
if (partyOpt.isPresent()) {
|
||||
List<Player> allies = new ArrayList<>();
|
||||
ServerLevel serverLevel = (ServerLevel) level;
|
||||
for (UUID memberUuid : partyOpt.get().members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverLevel.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null && online.distanceTo(player) <= 10.0) {
|
||||
allies.add(online);
|
||||
}
|
||||
}
|
||||
MobEffectInstance allyHaste = new MobEffectInstance(
|
||||
net.minecraft.world.effect.MobEffects.DIG_SPEED, 100, 0, false, true, true
|
||||
);
|
||||
MobEffectInstance allyHaste = new MobEffectInstance(MobEffects.DIG_SPEED, 100, 0, false, true, true);
|
||||
for (Player ally : allies) {
|
||||
ally.addEffect(allyHaste);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
public boolean hurtEnemy(ItemStack stack,
|
||||
LivingEntity target,
|
||||
LivingEntity attacker) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDamageable(ItemStack stack) { return false; }
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
public boolean isDamaged(ItemStack stack) { return false; }
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext ctx) {
|
||||
@@ -84,8 +99,11 @@ public class StaliniumShovelItem extends ShovelItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
net.minecraft.world.item.Item.TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_shovel.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_shovel.tooltip"));
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
package net.krituximon.stalinium.item.custom;
|
||||
|
||||
import net.krituximon.stalinium.Stalinium;
|
||||
import net.krituximon.stalinium.event.ComradeHandler;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaliniumSwordItem extends SwordItem {
|
||||
private static final double RANGE = 6.0;
|
||||
@@ -35,24 +39,40 @@ public class StaliniumSwordItem extends SwordItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
|
||||
Level world = attacker.getCommandSenderWorld();
|
||||
public boolean hurtEnemy(ItemStack stack,
|
||||
LivingEntity target,
|
||||
LivingEntity attacker) {
|
||||
Level world = attacker.level();
|
||||
if (!world.isClientSide && attacker instanceof Player player) {
|
||||
AABB box = player.getBoundingBox().inflate(5.0);
|
||||
List<Player> allies = world.getEntitiesOfClass(
|
||||
Player.class, box,
|
||||
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
if (partyOpt.isPresent()) {
|
||||
List<Player> allies = new ArrayList<>();
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
for (UUID memberUuid : partyOpt.get().members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverPlayer.level()
|
||||
.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null && online.distanceTo(player) <= 5.0) {
|
||||
allies.add(online);
|
||||
}
|
||||
}
|
||||
MobEffectInstance allyStrength = new MobEffectInstance(
|
||||
MobEffects.DAMAGE_BOOST, 100, 0, false, true
|
||||
);
|
||||
MobEffectInstance allyBuff = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true);
|
||||
for (Player ally : allies) {
|
||||
ally.addEffect(allyBuff);
|
||||
ally.addEffect(allyStrength);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
|
||||
public InteractionResultHolder<ItemStack> use(Level world,
|
||||
Player player,
|
||||
InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
if (player.getCooldowns().isOnCooldown(this)) {
|
||||
return InteractionResultHolder.fail(stack);
|
||||
@@ -64,22 +84,36 @@ public class StaliniumSwordItem extends SwordItem {
|
||||
.getHolderOrThrow(
|
||||
ResourceKey.create(
|
||||
Registries.MOB_EFFECT,
|
||||
ResourceLocation.fromNamespaceAndPath(Stalinium.MODID, "stalinium_charge")
|
||||
ResourceLocation.fromNamespaceAndPath(
|
||||
Stalinium.MODID, "stalinium_charge"
|
||||
)
|
||||
)
|
||||
);
|
||||
player.addEffect(new MobEffectInstance(chargeHolder, DURATION, AMP, false, true));
|
||||
AABB area = player.getBoundingBox().inflate(RANGE);
|
||||
Vec3 look = player.getLookAngle();
|
||||
List<Player> allies = world.getEntitiesOfClass(
|
||||
Player.class, area,
|
||||
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
|
||||
);
|
||||
Optional<ComradeHandler.Party> partyOpt = ComradeHandler.findPartyOf(player.getUUID());
|
||||
if (partyOpt.isPresent()) {
|
||||
List<Player> allies = new ArrayList<>();
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
for (UUID memberUuid : partyOpt.get().members) {
|
||||
if (memberUuid.equals(player.getUUID())) continue;
|
||||
ServerPlayer online = serverPlayer.level()
|
||||
.getServer()
|
||||
.getPlayerList()
|
||||
.getPlayer(memberUuid);
|
||||
if (online != null) {
|
||||
Vec3 toAlly = online.position().subtract(player.position()).normalize();
|
||||
if (toAlly.dot(look) >= COS_HALF_ANG && online.distanceTo(player) <= RANGE) {
|
||||
allies.add(online);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Player ally : allies) {
|
||||
Vec3 toAlly = ally.position().subtract(player.position()).normalize();
|
||||
if (toAlly.dot(look) >= COS_HALF_ANG) {
|
||||
ally.addEffect(new MobEffectInstance(chargeHolder, DURATION, AMP, false, true));
|
||||
}
|
||||
}
|
||||
|
||||
player.getCooldowns().addCooldown(this, COOLDOWN);
|
||||
}
|
||||
player.startUsingItem(hand);
|
||||
@@ -103,8 +137,11 @@ public class StaliniumSwordItem extends SwordItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
if(Screen.hasShiftDown()) {
|
||||
public void appendHoverText(ItemStack stack,
|
||||
TooltipContext context,
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_sword.tooltip_shift"));
|
||||
} else {
|
||||
tooltipComponents.add(Component.translatable("item.stalinium_sword.tooltip"));
|
||||
|
||||
Reference in New Issue
Block a user