Refactor sendNoSpamMessage to use a packet, fixes a number of issues where no chat messsage was being received at all.
More work towards splitting client and server.
This commit is contained in:
parent
45c1e7412c
commit
27cc9d0730
14 changed files with 123 additions and 116 deletions
|
@ -27,9 +27,11 @@ package techreborn.blockentity.machine.misc;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -51,8 +53,8 @@ public class AlarmBlockEntity extends BlockEntity
|
|||
super(TRBlockEntities.ALARM, pos, state);
|
||||
}
|
||||
|
||||
public void rightClick() {
|
||||
if (world == null || world.isClient) return;
|
||||
public void rightClick(Entity entity) {
|
||||
if (world == null) return;
|
||||
|
||||
if (selectedSound < 3) {
|
||||
selectedSound++;
|
||||
|
@ -60,10 +62,12 @@ public class AlarmBlockEntity extends BlockEntity
|
|||
selectedSound = 1;
|
||||
}
|
||||
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.alarmID, new TranslatableText("techreborn.message.alarm")
|
||||
if (entity instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, MessageIDs.alarmID, new TranslatableText("techreborn.message.alarm")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(" Alarm ")
|
||||
.append(String.valueOf(selectedSound)));
|
||||
}
|
||||
}
|
||||
|
||||
// BlockEntity
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.minecraft.block.entity.BlockEntity;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
@ -123,15 +124,15 @@ public class PlayerDetectorBlock extends BlockMachineBase {
|
|||
}
|
||||
}
|
||||
|
||||
if (worldIn.isClient) {
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.playerDetectorID,
|
||||
new TranslatableText("techreborn.message.detects")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(" ")
|
||||
.append(
|
||||
new LiteralText(StringUtils.toFirstCapital(newType.asString()))
|
||||
.formatted(color)
|
||||
)
|
||||
if (playerIn instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, MessageIDs.playerDetectorID,
|
||||
new TranslatableText("techreborn.message.detects")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(" ")
|
||||
.append(
|
||||
new LiteralText(StringUtils.toFirstCapital(newType.asString()))
|
||||
.formatted(color)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -138,8 +138,8 @@ public class BlockAlarm extends BaseBlockEntityProvider {
|
|||
}
|
||||
}
|
||||
|
||||
if (!worldIn.isClient && playerIn.isSneaking()) {
|
||||
((AlarmBlockEntity) blockEntity).rightClick();
|
||||
if (playerIn.isSneaking()) {
|
||||
((AlarmBlockEntity) blockEntity).rightClick(playerIn);
|
||||
return ActionResult.SUCCESS;
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class BatteryItem extends Item implements RcEnergyItem {
|
|||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
ItemUtils.switchActive(stack, 1, world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.switchActive(stack, 1, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
@ -73,7 +73,7 @@ public class BatteryItem extends Item implements RcEnergyItem {
|
|||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
ItemUtils.checkActive(stack, 1, entity.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, 1, MessageIDs.poweredToolID, entity);
|
||||
if (world.isClient) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
@ -66,20 +67,20 @@ public class FrequencyTransmitterItem extends Item {
|
|||
GlobalPos.CODEC.encodeStart(NbtOps.INSTANCE, globalPos).result()
|
||||
.ifPresent(tag -> stack.getOrCreateNbt().put("pos", tag));
|
||||
|
||||
if (!world.isClient) {
|
||||
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TranslatableText("techreborn.message.setTo")
|
||||
.append(new LiteralText(" X:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getX())).formatted(Formatting.GOLD))
|
||||
.append(new LiteralText(" Y:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getY())).formatted(Formatting.GOLD))
|
||||
.append(new LiteralText(" Z:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getZ())).formatted(Formatting.GOLD))
|
||||
.append(" ")
|
||||
.append(new TranslatableText("techreborn.message.in").formatted(Formatting.GRAY))
|
||||
.append(" ")
|
||||
.append(new LiteralText(getDimName(globalPos.getDimension()).toString()).formatted(Formatting.GOLD)));
|
||||
if (context.getPlayer() instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, MessageIDs.freqTransmitterID, new TranslatableText("techreborn.message.setTo")
|
||||
.append(new LiteralText(" X:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getX())).formatted(Formatting.GOLD))
|
||||
.append(new LiteralText(" Y:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getY())).formatted(Formatting.GOLD))
|
||||
.append(new LiteralText(" Z:").formatted(Formatting.GRAY))
|
||||
.append(new LiteralText(String.valueOf(pos.getZ())).formatted(Formatting.GOLD))
|
||||
.append(" ")
|
||||
.append(new TranslatableText("techreborn.message.in").formatted(Formatting.GRAY))
|
||||
.append(" ")
|
||||
.append(new LiteralText(getDimName(globalPos.getDimension()).toString()).formatted(Formatting.GOLD)));
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -96,16 +97,16 @@ public class FrequencyTransmitterItem extends Item {
|
|||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
stack.setNbt(null);
|
||||
if (!world.isClient) {
|
||||
|
||||
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID,
|
||||
new TranslatableText("techreborn.message.coordsHaveBeen")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(" ")
|
||||
.append(
|
||||
new TranslatableText("techreborn.message.cleared")
|
||||
.formatted(Formatting.GOLD)
|
||||
)
|
||||
if (player instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, MessageIDs.freqTransmitterID,
|
||||
new TranslatableText("techreborn.message.coordsHaveBeen")
|
||||
.formatted(Formatting.GRAY)
|
||||
.append(" ")
|
||||
.append(
|
||||
new TranslatableText("techreborn.message.cleared")
|
||||
.formatted(Formatting.GOLD)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class AdvancedJackhammerItem extends JackhammerItem implements MultiBlock
|
|||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.switchActive(stack, cost, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
@ -98,7 +98,7 @@ public class AdvancedJackhammerItem extends JackhammerItem implements MultiBlock
|
|||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
ItemUtils.checkActive(stack, cost, entity.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, cost, MessageIDs.poweredToolID, entity);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
|
|
@ -108,7 +108,7 @@ public class IndustrialChainsawItem extends ChainsawItem {
|
|||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.switchActive(stack, cost, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
@ -116,7 +116,7 @@ public class IndustrialChainsawItem extends ChainsawItem {
|
|||
|
||||
@Override
|
||||
public void usageTick(World world, LivingEntity entity, ItemStack stack, int i) {
|
||||
ItemUtils.checkActive(stack, cost, entity.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, cost, MessageIDs.poweredToolID, entity);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
|
|
@ -103,7 +103,7 @@ public class IndustrialDrillItem extends DrillItem {
|
|||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.switchActive(stack, cost, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
@ -111,7 +111,7 @@ public class IndustrialDrillItem extends DrillItem {
|
|||
|
||||
@Override
|
||||
public void usageTick(World world, LivingEntity entity, ItemStack stack, int i) {
|
||||
ItemUtils.checkActive(stack, cost, entity.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, cost, MessageIDs.poweredToolID, entity);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
|
@ -64,22 +65,22 @@ public class IndustrialJackhammerItem extends JackhammerItem implements MultiBlo
|
|||
}
|
||||
|
||||
// Cycle Inactive, Active 3*3 and Active 5*5
|
||||
private void switchAOE(ItemStack stack, int cost, boolean isClient, int messageId) {
|
||||
ItemUtils.checkActive(stack, cost, isClient, messageId);
|
||||
private void switchAOE(ItemStack stack, int cost, int messageId, Entity entity) {
|
||||
ItemUtils.checkActive(stack, cost, messageId, entity);
|
||||
if (!ItemUtils.isActive(stack)) {
|
||||
ItemUtils.switchActive(stack, cost, isClient, messageId);
|
||||
ItemUtils.switchActive(stack, cost, messageId, entity);
|
||||
stack.getOrCreateNbt().putBoolean("AOE5", false);
|
||||
if (isClient) {
|
||||
ChatUtils.sendNoSpamMessages(messageId, new TranslatableText("techreborn.message.setTo").formatted(Formatting.GRAY).append(" ").append(new LiteralText("3*3").formatted(Formatting.GOLD)));
|
||||
if (entity instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, messageId, new TranslatableText("techreborn.message.setTo").formatted(Formatting.GRAY).append(" ").append(new LiteralText("3*3").formatted(Formatting.GOLD)));
|
||||
}
|
||||
} else {
|
||||
if (isAOE5(stack)) {
|
||||
ItemUtils.switchActive(stack, cost, isClient, messageId);
|
||||
ItemUtils.switchActive(stack, cost, messageId, entity);
|
||||
stack.getOrCreateNbt().putBoolean("AOE5", false);
|
||||
} else {
|
||||
stack.getOrCreateNbt().putBoolean("AOE5", true);
|
||||
if (isClient) {
|
||||
ChatUtils.sendNoSpamMessages(messageId, new TranslatableText("techreborn.message.setTo").formatted(Formatting.GRAY).append(" ").append(new LiteralText("5*5").formatted(Formatting.GOLD)));
|
||||
if (entity instanceof ServerPlayerEntity serverPlayerEntity) {
|
||||
ChatUtils.sendNoSpamMessage(serverPlayerEntity, messageId, new TranslatableText("techreborn.message.setTo").formatted(Formatting.GRAY).append(" ").append(new LiteralText("5*5").formatted(Formatting.GOLD)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +135,7 @@ public class IndustrialJackhammerItem extends JackhammerItem implements MultiBlo
|
|||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
switchAOE(stack, cost, world.isClient, MessageIDs.poweredToolID);
|
||||
switchAOE(stack, cost, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
@ -142,7 +143,7 @@ public class IndustrialJackhammerItem extends JackhammerItem implements MultiBlo
|
|||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
|
||||
ItemUtils.checkActive(stack, cost, entity.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, cost, MessageIDs.poweredToolID, entity);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
|
|
@ -81,14 +81,14 @@ public class NanosaberItem extends SwordItem implements RcEnergyItem, ItemStackM
|
|||
// Item
|
||||
@Override
|
||||
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
|
||||
ItemUtils.checkActive(stack, cost, entityIn.world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.checkActive(stack, cost, MessageIDs.poweredToolID, entityIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
final ItemStack stack = player.getStackInHand(hand);
|
||||
if (player.isSneaking()) {
|
||||
ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID);
|
||||
ItemUtils.switchActive(stack, cost, MessageIDs.poweredToolID, player);
|
||||
return new TypedActionResult<>(ActionResult.SUCCESS, stack);
|
||||
}
|
||||
return new TypedActionResult<>(ActionResult.PASS, stack);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue