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