Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.19' into 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
ljfa-ag committed Jul 12, 2023
2 parents 4fb07d0 + a311dc1 commit 88acea9
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ public MusicResult acceptMusic(MusicInstrument instr, int amount, Vec3 from, @Nu
/**
* Returns the amount of music stored from the given instrument.
*/
public int getMusicAmount(MusicInstrument instr)
{
public int getMusicAmount(MusicInstrument instr) {
return music.getInt(instr);
}

/**
* Sets the amount of music for the given instrument. This method does not check if the amount exceeds the maximum.
*/
public void setMusicAmount(MusicInstrument instr, int amount)
{
public void setMusicAmount(MusicInstrument instr, int amount) {
Objects.requireNonNull(instr);
int oldVal = music.getInt(instr);
if(amount != oldVal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.PacketDistributor;
import pokefenn.totemic.Totemic;
import pokefenn.totemic.advancements.ModCriteriaTriggers;
import pokefenn.totemic.api.TotemicAPI;
Expand Down Expand Up @@ -62,7 +63,7 @@ public boolean canAcceptMusic(MusicInstrument instr) {
public MusicResult acceptMusic(MusicInstrument instr, int amount, Vec3 from, @Nullable Entity entity) {
var result = musicHandler.acceptMusic(instr, amount, from, entity);
if(result.isSuccess()) {
NetworkHandler.channel.send(NetworkHandler.nearTile(tile, 16),
NetworkHandler.channel.send(PacketDistributor.TRACKING_CHUNK.with(() -> tile.getLevel().getChunkAt(tile.getBlockPos())),
new ClientboundPacketStartupMusic(tile.getBlockPos(), instr, musicHandler.getMusicAmount(instr)));
tile.setChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ public void load(CompoundTag tag) {

@Override
public CompoundTag getUpdateTag() {
var tag = new CompoundTag();
saveAdditional(tag);
return tag;
return saveWithoutMetadata();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public void load(CompoundTag tag) {

@Override
public CompoundTag getUpdateTag() {
var tag = new CompoundTag();
saveAdditional(tag);
return tag;
return saveWithoutMetadata();
}

@Override
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/pokefenn/totemic/network/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@

import java.util.Optional;

import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PacketDistributor.PacketTarget;
import net.minecraftforge.network.PacketDistributor.TargetPoint;
import net.minecraftforge.network.simple.SimpleChannel;
import pokefenn.totemic.api.TotemicAPI;

Expand All @@ -24,12 +18,4 @@ public static void init() {
channel.registerMessage(0, ServerboundPacketMouseWheel.class, ServerboundPacketMouseWheel::encode, ServerboundPacketMouseWheel::decode, ServerboundPacketMouseWheel::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER));
channel.registerMessage(1, ClientboundPacketStartupMusic.class, ClientboundPacketStartupMusic::encode, ClientboundPacketStartupMusic::decode, ClientboundPacketStartupMusic::handle, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
}

public static PacketTarget nearPosition(Level level, BlockPos pos, double radius) {
return PacketDistributor.NEAR.with(TargetPoint.p(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, radius, level.dimension()));
}

public static PacketTarget nearTile(BlockEntity tile, double radius) {
return nearPosition(tile.getLevel(), tile.getBlockPos(), radius);
}
}

0 comments on commit 88acea9

Please sign in to comment.