Skip to content

Commit

Permalink
Merge branch '1.18.2/stable' into 1.18.2/4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Cibernet83 committed Mar 4, 2024
2 parents 113a402 + b461041 commit d27aa4b
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static void renderGui(RenderGameOverlayEvent.Pre event)
return;

Player player = Minecraft.getInstance().player;
if (player == null || !PlayerInfoCapability.hasCapability(player))
if (player == null || player.isSpectator() || !PlayerInfoCapability.hasCapability(player))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import net.splatcraft.forge.mixin.MinecraftClientAccessor;
import net.splatcraft.forge.network.SplatcraftPacketHandler;
import net.splatcraft.forge.network.c2s.SwapSlotWithOffhandPacket;
import net.splatcraft.forge.network.c2s.UpdateChargeStatePacket;
import net.splatcraft.forge.util.ClientUtils;
import net.splatcraft.forge.util.CommonUtils;
import net.splatcraft.forge.util.PlayerCharge;
import net.splatcraft.forge.util.PlayerCooldown;
import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -65,14 +67,21 @@ public static boolean isSquidKeyDown() {
}

@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
public static void onClientTick(TickEvent.ClientTickEvent event)
{
Minecraft mc = Minecraft.getInstance();
Player player = mc.player;

if (player == null || player.isSpectator() || !PlayerInfoCapability.hasCapability(player)) {
return;
}

if(!mc.options.keyUse.isDown() && PlayerCharge.hasCharge(player) && PlayerInfoCapability.isSquid(player)) //Resets weapon charge when player is in swim form and not holding down right click. Used to void Charge Storage for Splatlings and Chargers.
{
PlayerCharge.getCharge(player).reset();
SplatcraftPacketHandler.sendToServer(new UpdateChargeStatePacket(false));
}

boolean canHold = canHoldKeys(Minecraft.getInstance());

fireKey.tick(KeyMode.HOLD, canHold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public void readNBT(CompoundTag nbt)
CompoundTag element = (CompoundTag) tag;
ink(NbtUtils.readBlockPos(element.getCompound("Pos")), element.getInt("Color"), InkBlockUtils.InkType.values.get(new ResourceLocation(element.getString("Type"))));
});

INK_MAP.values();
}

public record Entry(int color, InkBlockUtils.InkType type)
Expand Down
146 changes: 80 additions & 66 deletions src/main/java/net/splatcraft/forge/handlers/WorldInkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.event.world.PistonEvent;
import net.minecraftforge.event.world.*;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.splatcraft.forge.Splatcraft;
Expand All @@ -47,6 +45,7 @@

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -96,49 +95,56 @@ public static void onBlockPlace(PlayerInteractEvent.RightClickBlock event)
@SubscribeEvent //Ink Decay
public static void onWorldTick(TickEvent.WorldTickEvent event)
{
if(event.phase == TickEvent.Phase.START && !event.world.players().isEmpty() && event.world instanceof ServerLevel level)
if(event.phase == TickEvent.Phase.START && !event.world.players().isEmpty())
{
List<LevelChunk> chunks = StreamSupport.stream(level.getChunkSource().chunkMap.getChunks().spliterator(), false).map(ChunkHolder::getTickingChunk)
.filter(Objects::nonNull).filter(chunk -> !WorldInkCapability.get(chunk).getInkInChunk().isEmpty()).toList();
int maxChunkCheck = Math.min(level.random.nextInt(MAX_DECAYABLE_CHUNKS), chunks.size());

for(int i = 0; i < maxChunkCheck; i++)
if(event.world instanceof ServerLevel level)
{
LevelChunk chunk = chunks.get(level.random.nextInt(chunks.size()));
WorldInk worldInk = WorldInkCapability.get(chunk);
HashMap<BlockPos, WorldInk.Entry> decayableInk = new HashMap<>(worldInk.getInkInChunk());
List<LevelChunk> chunks = StreamSupport.stream(level.getChunkSource().chunkMap.getChunks().spliterator(), false).map(ChunkHolder::getTickingChunk)
.filter(Objects::nonNull).filter(chunk -> !WorldInkCapability.get(chunk).getInkInChunk().isEmpty()).toList();
int maxChunkCheck = Math.min(level.random.nextInt(MAX_DECAYABLE_CHUNKS), chunks.size());

for (int i = 0; i < maxChunkCheck; i++) {
LevelChunk chunk = chunks.get(level.random.nextInt(chunks.size()));
WorldInk worldInk = WorldInkCapability.get(chunk);
HashMap<BlockPos, WorldInk.Entry> decayableInk = new HashMap<>(worldInk.getInkInChunk());

int blockCount = 0;
while (!decayableInk.isEmpty() && blockCount < MAX_DECAYABLE_PER_CHUNK) {
BlockPos pos = decayableInk.keySet().toArray(new BlockPos[]{})[level.random.nextInt(decayableInk.size())];
BlockPos clearPos = pos.offset(chunk.getPos().x * 16, 0, chunk.getPos().z * 16);

if (!SplatcraftGameRules.getLocalizedRule(level, clearPos, SplatcraftGameRules.INK_DECAY) ||
level.random.nextFloat() >= SplatcraftGameRules.getIntRuleValue(level, SplatcraftGameRules.INK_DECAY_RATE) * 0.001f || //TODO make localized int rules
decayableInk.get(pos).equals(worldInk.getPermanentInk(pos))) {
decayableInk.remove(pos);
continue;
}

int blockCount = 0;
while (!decayableInk.isEmpty() && blockCount < MAX_DECAYABLE_PER_CHUNK)
{
BlockPos pos = decayableInk.keySet().toArray(new BlockPos[]{})[level.random.nextInt(decayableInk.size())];
BlockPos clearPos = pos.offset(chunk.getPos().x * 16, 0, chunk.getPos().z * 16);
int adjacentInk = 0;
for (Direction dir : Direction.values())
if (InkBlockUtils.isInked(level, clearPos.relative(dir)))
adjacentInk++;

if(!SplatcraftGameRules.getLocalizedRule(level, clearPos, SplatcraftGameRules.INK_DECAY) ||
level.random.nextFloat() >= SplatcraftGameRules.getIntRuleValue(level, SplatcraftGameRules.INK_DECAY_RATE) * 0.001f || //TODO make localized int rules
decayableInk.get(pos).equals(worldInk.getPermanentInk(pos)))
{
decayableInk.remove(pos);
continue;
}

int adjacentInk = 0;
for(Direction dir : Direction.values())
if(InkBlockUtils.isInked(level, clearPos.relative(dir)))
adjacentInk++;
if (!(adjacentInk <= 0 || level.random.nextInt(adjacentInk * 2) == 0)) {
decayableInk.remove(pos);
continue;
}

if(!(adjacentInk <= 0 || level.random.nextInt(adjacentInk*2) == 0))
{
InkBlockUtils.clearInk(level, clearPos, false);
decayableInk.remove(pos);
continue;
}

InkBlockUtils.clearInk(level, clearPos, false);
decayableInk.remove(pos);

blockCount++;
blockCount++;
}
}
}
else if(event.world.isClientSide)
{
new ArrayList<>(INK_CACHE.keySet()).forEach(chunkPos ->
{
if(event.world.getChunk(chunkPos.x, chunkPos.z, ChunkStatus.FULL, false) instanceof LevelChunk chunk)
updateClientInkForChunk(event.world, chunk);
});
}
}
}

Expand All @@ -157,52 +163,60 @@ public static void onPistonPush(PistonEvent.Pre event)
InkBlockUtils.clearInk(level, pos, true);
else InkBlockUtils.inkBlock(level, pos, inkToPush.get(pos).color(), 0, inkToPush.get(pos).type());
});
}


@SubscribeEvent
public static void onChunkWatch(ChunkWatchEvent.Watch event)
{
if(event.getWorld().getChunk(event.getPos().x, event.getPos().z, ChunkStatus.FULL, false) instanceof LevelChunk chunk)
{
WorldInk worldInk = WorldInkCapability.get(chunk);
if(!worldInk.getInkInChunk().isEmpty())
SplatcraftPacketHandler.sendToPlayer(new WatchInkPacket(chunk.getPos(), worldInk.getInkInChunk()), event.getPlayer());
}
}

@SubscribeEvent //Send World Ink Data to client
public static void onWatchChunk(ChunkWatchEvent.Watch event)
@SubscribeEvent
public static void onChunkDataLoad(ChunkDataEvent.Load event)
{
if(!event.getWorld().isClientSide)
if(event.getChunk() instanceof LevelChunk chunk)
{
WorldInk worldInk = WorldInkCapability.get(event.getWorld().getChunk(event.getPos().x, event.getPos().z));
SplatcraftPacketHandler.sendToPlayer(new WatchInkPacket(event.getPos(), worldInk.getInkInChunk()), event.getPlayer());
WorldInk worldInk = WorldInkCapability.get(chunk);
if(!worldInk.getInkInChunk().isEmpty())
SplatcraftPacketHandler.sendToDim(new WatchInkPacket(chunk.getPos(), worldInk.getInkInChunk()), chunk.getLevel().dimension());
}
}

private static final HashMap<ChunkPos, HashMap<BlockPos, WorldInk.Entry>> INK_CACHE = new HashMap<>();

//Chunk caps seem to get reset after ChunkWatchEvent, so they need to be cached and updated on ChunkLoadEvent
@SubscribeEvent
public static void onChunkLoad(ChunkEvent.Load event)

@OnlyIn(Dist.CLIENT)
public static void updateClientInkForChunk(Level level, LevelChunk chunk)
{
if(event.getWorld() instanceof Level level && level.isClientSide)
{
ChunkPos chunkPos = event.getChunk().getPos();
WorldInk worldInk = WorldInkCapability.get(level.getChunk(chunkPos.x, chunkPos.z));
WorldInk worldInk = WorldInkCapability.get(chunk);
ChunkPos chunkPos = chunk.getPos();

if(INK_CACHE.containsKey(chunkPos))
if(INK_CACHE.containsKey(chunkPos))
{
INK_CACHE.get(chunkPos).forEach((pos, entry) ->
{
INK_CACHE.get(chunkPos).forEach((pos, entry) ->
{
if (entry == null || entry.type() == null) {
worldInk.clearInk(pos);
} else {
worldInk.ink(pos, entry.color(), entry.type());
}
if (entry == null || entry.type() == null) {
worldInk.clearInk(pos);
} else {
worldInk.ink(pos, entry.color(), entry.type());
}


pos = new BlockPos(pos.getX() + chunkPos.x * 16, pos.getY(), pos.getZ() + chunkPos.z * 16);
BlockState state = level.getBlockState(pos);
level.sendBlockUpdated(pos, state, state, 0);
});
INK_CACHE.remove(chunkPos);
}
pos = new BlockPos(pos.getX() + chunkPos.x * 16, pos.getY(), pos.getZ() + chunkPos.z * 16);
BlockState state = level.getBlockState(pos);
level.sendBlockUpdated(pos, state, state, 0);
});
INK_CACHE.remove(chunkPos);

}
}

public static void updateInk(ChunkPos pos, HashMap<BlockPos, WorldInk.Entry> map)
public static void markInkInChunkForUpdate(ChunkPos pos, HashMap<BlockPos, WorldInk.Entry> map)
{
INK_CACHE.put(pos, map);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/splatcraft/forge/items/FilterItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public FilterItem()
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> tooltip, @NotNull TooltipFlag isAdvanced)
{
super.appendHoverText(stack, level, tooltip, isAdvanced);
if(!stack.getOrCreateTag().getBoolean("HideTooltip"))
tooltip.add(new TranslatableComponent("item.splatcraft.filter.tooltip").withStyle(ChatFormatting.GRAY));
tooltip.add(new TranslatableComponent("item.splatcraft.filter.tooltip").withStyle(ChatFormatting.GRAY));
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/splatcraft/forge/items/InkBandItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public InkBandItem()
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flags)
{
super.appendHoverText(stack, level, tooltip, flags);
if(!stack.getOrCreateTag().getBoolean("HideTooltip"))
tooltip.add(new TranslatableComponent(stack.getDescriptionId() + ".tooltip").withStyle(ChatFormatting.GRAY));
tooltip.add(new TranslatableComponent(stack.getDescriptionId() + ".tooltip").withStyle(ChatFormatting.GRAY));
}
}
22 changes: 16 additions & 6 deletions src/main/java/net/splatcraft/forge/items/InkTankItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -119,16 +120,25 @@ public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, @NotNu
}

@Override
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> tooltip, @NotNull TooltipFlag flag) {
public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List<Component> tooltip, @NotNull TooltipFlag flag)
{
if (ColorUtils.isColorLocked(stack))
tooltip.add(ColorUtils.getFormatedColorName(ColorUtils.getInkColor(stack), true));

super.appendHoverText(stack, level, tooltip, flag);
if (!canRecharge(stack, false)) {
tooltip.add(new TranslatableComponent("item.splatcraft.ink_tank.cant_recharge"));
}

if (flag.isAdvanced() && !stack.getOrCreateTag().getBoolean("HideTooltip")) {
tooltip.add(new TranslatableComponent("item.splatcraft.ink_tank.ink", String.format("%.1f", getInkAmount(stack)), capacity));
if(!stack.getOrCreateTag().getBoolean("HideTooltip"))
{
if (!canRecharge(stack, false)) {
tooltip.add(new TranslatableComponent("item.splatcraft.ink_tank.cant_recharge"));
}

if (flag.isAdvanced()) {
tooltip.add(new TranslatableComponent("item.splatcraft.ink_tank.ink", String.format("%.1f", getInkAmount(stack)), capacity));
}
}


}

private static boolean initModels = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraftforge.registries.RegistryObject;
import net.splatcraft.forge.client.audio.SplatlingChargingTickableSound;
import net.splatcraft.forge.client.handlers.SplatcraftKeyHandler;
import net.splatcraft.forge.data.capabilities.playerinfo.PlayerInfoCapability;
import net.splatcraft.forge.entities.InkProjectileEntity;
import net.splatcraft.forge.handlers.PlayerPosingHandler;
import net.splatcraft.forge.items.InkTankItem;
Expand Down Expand Up @@ -201,16 +202,6 @@ public void releaseUsing(@NotNull ItemStack stack, @NotNull Level level, LivingE

if(charge == null)
return;

/*
if(PlayerInfoCapability.isSquid(player))
{
charge.reset();
SplatcraftPacketHandler.sendToServer(new UpdateChargeStatePacket(false));
}
else */


if (!SplatcraftKeyHandler.isSquidKeyDown() && charge.charge > 0.05f) //checking for squid key press so it doesn't immediately release charge when squidding
{
SplatlingWeaponSettings settings = getSettings(stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public ItemStack execute(BlockSource source, ItemStack stack)
projectileentity.shoot(direction.getStepX(), (float) direction.getStepY() + 0.1F, direction.getStepZ(), this.getPower(), this.getUncertainty());
world.addFreshEntity(projectileentity);
stack.shrink(1);

source.getLevel().playSound(null, source.x(), source.y(), source.z(), SplatcraftSounds.subThrow, SoundSource.PLAYERS, 0.7F, 1);

return stack;
}

Expand All @@ -198,12 +201,6 @@ protected AbstractSubWeaponEntity getProjectile(Level levelIn, Position position
return AbstractSubWeaponEntity.create(((SubWeaponItem) stackIn.getItem()).entityType.get(), levelIn, position.x(), position.y(), position.z(), ColorUtils.getInkColor(stackIn), InkBlockUtils.InkType.NORMAL, stackIn);
}


@Override
protected void playSound(BlockSource source) {
source.getLevel().playSound(null, source.x(), source.y(), source.z(), SplatcraftSounds.subThrow, SoundSource.PLAYERS, 0.7F, 1);
}

protected float getPower() {
return 0.7f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public static WatchInkPacket decode(FriendlyByteBuf buffer)
@Override
public void execute()
{
WorldInkHandler.updateInk(chunkPos, dirty);
WorldInkHandler.markInkInChunkForUpdate(chunkPos, dirty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ advancement grant @s only splatcraft:unlocks/rollers
advancement grant @s only splatcraft:unlocks/chargers
advancement grant @s only splatcraft:unlocks/sloshers
advancement grant @s only splatcraft:unlocks/dualies
advancement grant @s only splatcraft:unlocks/splatlings
advancement grant @s only splatcraft:unlocks/ink_tanks
advancement grant @s only splatcraft:unlocks/sub_weapons

Expand Down

0 comments on commit d27aa4b

Please sign in to comment.