Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.10.5"
id "fabric-loom" version "1.11.3"
id "maven-publish"
}

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod_version = 1.0.0
org.gradle.jvmargs = -Xmx1G

# Versions
minecraft_version = 1.21.4
yarn_mappings = 1.21.4+build.8
minecraft_version = 1.21.7
yarn_mappings = 1.21.7+build.4
loader_version = 0.16.14
fabric_version = 0.119.2+1.21.4
fabric_version = 0.128.2+1.21.7

plasmid_version = 0.6.3+1.21.4
plasmid_version = 0.6.5+1.21.7
24 changes: 24 additions & 0 deletions src/main/java/io/github/haykam821/microbattle/PoolHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.haykam821.microbattle;

import java.util.List;
import java.util.function.Predicate;

import net.minecraft.util.collection.Pool;
import net.minecraft.util.collection.Weighted;

public final class PoolHelper {
private PoolHelper() {
return;
}

public static <T> Pool<T> filter(Pool<T> pool, Predicate<T> predicate) {
List<Weighted<T>> entries = pool.getEntries()
.stream()
.filter(entry -> {
return predicate.test(entry.value());
})
.toList();

return Pool.of(entries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void tick() {

public void tickOutOfBounds() {
this.outOfBoundsTicks += 1;
this.player.damage(this.player.getServerWorld(), this.player.getDamageSources().outOfWorld(), this.outOfBoundsTicks / 80);
this.player.damage(this.player.getWorld(), this.player.getDamageSources().outOfWorld(), this.outOfBoundsTicks / 80);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void placeFlower(ServerWorld world, BlockPos pos) {
@Override
public EventResult onKilledPlayer(PlayerEntry entry, DamageSource source) {
if (entry.getPlayer().isOnGround()) {
this.placeFlower(entry.getPlayer().getServerWorld(), entry.getPlayer().getBlockPos());
this.placeFlower(entry.getPlayer().getWorld(), entry.getPlayer().getBlockPos());
}
return EventResult.PASS;
}
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/io/github/haykam821/microbattle/game/kit/FoxKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Optional;

import io.github.haykam821.microbattle.PoolHelper;
import io.github.haykam821.microbattle.game.PlayerEntry;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
Expand All @@ -14,12 +15,11 @@
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.DyeColor;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.collection.Weighted;
import net.minecraft.util.collection.Pool;
import xyz.nucleoid.plasmid.api.game.common.OldCombat;

public class FoxKit extends Kit {
private static final DataPool<DigEntry> DIG_ITEMS = DataPool.<DigEntry>builder()
private static final Pool<DigEntry> DIG_ITEMS = Pool.<DigEntry>builder()
.add(new DigEntry(durabilityStack(Items.IRON_SWORD, 4), true), 500)
.add(new DigEntry(durabilityStack(Items.IRON_PICKAXE, 32), true), 500)
.add(new DigEntry(durabilityStack(Items.IRON_AXE, 4), true), 500)
Expand Down Expand Up @@ -104,15 +104,9 @@ private void dig() {
}

private ItemStack getDigStack() {
DataPool.Builder<DigEntry> builder = DataPool.builder();
Pool<DigEntry> pool = PoolHelper.filter(DIG_ITEMS, entry -> !entry.isRestricted(this.player));

for (Weighted.Present<DigEntry> entry : DIG_ITEMS.getEntries()) {
if (!entry.data().isRestricted(this.player)) {
builder.add(entry.data(), entry.getWeight().getValue());
}
}

Optional<DigEntry> optional = builder.build().getDataOrEmpty(entry.getPlayer().getRandom());
Optional<DigEntry> optional = pool.getOrEmpty(entry.getPlayer().getRandom());
return optional.isPresent() ? optional.get().stack().copy() : null;
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/github/haykam821/microbattle/game/kit/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.haykam821.microbattle.game.phase.MicroBattleActivePhase;
import net.minecraft.block.BlockState;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected Text getName() {

private Text getHoverableName() {
return this.getName().copy().styled(style -> {
return style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, this.getTooltip("")));
return style.withHoverEvent(new HoverEvent.ShowText(this.getTooltip("")));
});
}

Expand Down Expand Up @@ -155,8 +156,8 @@ public final void baseTick() {
entry.tick(this.entry);
}

if (this.isDamagedByWater() && this.player.isWet()) {
this.player.damage(this.player.getServerWorld(), this.player.getDamageSources().drown(), 1.0F);
if (this.isDamagedByWater() && this.player.isTouchingWaterOrRain()) {
this.player.damage(this.player.getWorld(), this.player.getDamageSources().drown(), 1.0F);
}

this.tick();
Expand Down Expand Up @@ -224,15 +225,15 @@ public final void applyInventory() {
}

List<ItemStack> armorStacks = this.getArmorStacks();
int index = 3;
int slot = EquipmentSlot.HEAD.getOffsetEntitySlotId(36);
for (ItemStack stack : armorStacks) {
player.getInventory().armor.set(index, stack);
index -= 1;
player.getInventory().setStack(slot, stack);
slot -= 1;
}

List<ItemStack> stacks = new ArrayList<>();
this.appendInitialStacks(stacks);
int slot = 0;
slot = 0;
for (ItemStack stack : stacks) {
player.getInventory().setStack(slot, this.phase.isOldCombat() ? OldCombat.applyTo(stack) : stack);
slot += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void updateExperienceBarForWoolCoat() {
public ActionResult onUseBlock(Hand hand, BlockHitResult hitResult) {
if (hitResult.getSide() != Direction.DOWN) {
BlockPos pos = hitResult.getBlockPos();
World world = this.player.getEntityWorld();
World world = this.player.getWorld();
BlockState state = world.getBlockState(pos);

boolean grassBlock = state.isOf(Blocks.GRASS_BLOCK);
Expand Down Expand Up @@ -86,7 +86,7 @@ public EventResult onDealDamage(PlayerEntry target, DamageSource source, float a
this.grassEaten = 0;
this.updateExperienceBarForWoolCoat();

World world = this.player.getEntityWorld();
World world = this.player.getWorld();
BlockPos pos = target.getPlayer().getBlockPos();

world.setBlockState(pos, WOOL_COAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void tick() {
}

private void tickTrail() {
ServerWorld world = this.player.getServerWorld();
ServerWorld world = this.player.getWorld();

BlockPos.Mutable pos = new BlockPos.Mutable(0, Math.floor(this.player.getY()), 0);
for (int corner = 0; corner < 4; corner++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import eu.pb4.sgui.api.gui.SlotGuiInterface;
import io.github.haykam821.microbattle.game.kit.KitType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.TooltipDisplayComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Unit;
import xyz.nucleoid.plasmid.api.shop.ShopEntry;

public class KitSelectionUi {
Expand All @@ -23,7 +23,14 @@ private static void addKit(SlotGuiInterface builder, KitSelectionManager kitSele
Text name = kitType.getName().copy().formatted(Formatting.GREEN);

ItemStack icon = kitType.getIcon();
icon.set(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);

icon.apply(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplayComponent.DEFAULT, display -> {
return display
.with(DataComponentTypes.ATTRIBUTE_MODIFIERS, true)
.with(DataComponentTypes.BEES, true)
.with(DataComponentTypes.BLOCK_STATE, true)
.with(DataComponentTypes.POTION_CONTENTS, true);
});

if (icon.contains(DataComponentTypes.POTION_CONTENTS)) {
icon.set(DataComponentTypes.CUSTOM_NAME, name.copy().styled(GuiHelpers.STYLE_CLEARER));
Expand All @@ -50,7 +57,6 @@ public void onClose() {
gui.setTitle(TITLE);

ItemStack icon = new ItemStack(Items.ENDER_CHEST);
icon.set(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);

gui.addSlot(ShopEntry
.ofIcon(icon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.VineBlock;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.collection.Pool;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;

public class BuildingFixture extends Fixture {
private static final DataPool<BlockState> STATES = DataPool.<BlockState>builder()
private static final Pool<BlockState> STATES = Pool.<BlockState>builder()
.add(Blocks.STONE_BRICKS.getDefaultState(), 20)
.add(Blocks.COBBLESTONE.getDefaultState(), 5)
.add(Blocks.BRICKS.getDefaultState(), 5)
Expand Down Expand Up @@ -94,7 +94,7 @@ public static BuildingFixture randomize(Random random) {

double vineDensity = getVineDensity(random);

BlockState state = STATES.getDataOrEmpty(random).orElseThrow(IllegalStateException::new);
BlockState state = STATES.getOrEmpty(random).orElseThrow(IllegalStateException::new);
return new BuildingFixture(size, random.nextInt(4) + 6, size, vineDensity, state);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.github.haykam821.microbattle.game.map.fixture;

import net.minecraft.block.Blocks;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.collection.Pool;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.gen.stateprovider.BlockStateProvider;

public final class Fixtures {
private static final DataPool<FixtureCreator> PRIMARY_FIXTURES = DataPool.<FixtureCreator>builder()
private static final Pool<FixtureCreator> PRIMARY_FIXTURES = Pool.<FixtureCreator>builder()
.add(Fixtures::building, 5)
.add(Fixtures::tower, 1)
.build();

private static final DataPool<FixtureCreator> DECORATION_FIXTURES = DataPool.<FixtureCreator>builder()
private static final Pool<FixtureCreator> DECORATION_FIXTURES = Pool.<FixtureCreator>builder()
.add(Fixtures::grassPatch, 1)
.build();

Expand All @@ -24,7 +24,7 @@ protected static Fixture tower(Random random) {
}

protected static Fixture primary(Random random) {
return PRIMARY_FIXTURES.getDataOrEmpty(random).orElseThrow().get(random);
return PRIMARY_FIXTURES.getOrEmpty(random).orElseThrow().get(random);
}

protected static Fixture grassPatch(Random random) {
Expand All @@ -33,7 +33,7 @@ protected static Fixture grassPatch(Random random) {
}

protected static Fixture decoration(Random random) {
return DECORATION_FIXTURES.getDataOrEmpty(random).orElseThrow().get(random);
return DECORATION_FIXTURES.getOrEmpty(random).orElseThrow().get(random);
}

@FunctionalInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.state.property.Properties;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.collection.Pool;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import xyz.nucleoid.plasmid.api.util.WoodType;

public class TowerFixture extends Fixture {
private static final DataPool<Variant> STATES = DataPool.<Variant>builder()
private static final Pool<Variant> STATES = Pool.<Variant>builder()
.add(new Variant(WoodType.OAK, Blocks.SPRUCE_SLAB.getDefaultState()), 20)
.add(new Variant(WoodType.DARK_OAK, Blocks.COBBLED_DEEPSLATE_SLAB.getDefaultState()), 10)
.add(new Variant(WoodType.ACACIA, Blocks.SMOOTH_STONE_SLAB.getDefaultState()), 5)
Expand Down Expand Up @@ -81,7 +81,7 @@ private static int randomizeSize(Random random) {
}

public static TowerFixture randomize(Random random) {
Variant variant = STATES.getDataOrEmpty(random).orElseThrow(IllegalStateException::new);
Variant variant = STATES.getOrEmpty(random).orElseThrow(IllegalStateException::new);
int depth = TowerFixture.randomizeSize(random);

int width = TowerFixture.randomizeSize(random);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private EventResult onBreakBlock(ServerPlayerEntity player, ServerWorld world, B
if (kitResult != EventResult.PASS) return kitResult;

// Prevent breaking non-beacons
BlockState state = player.getEntityWorld().getBlockState(pos);
BlockState state = player.getWorld().getBlockState(pos);
if (!state.isIn(Main.RESPAWN_BEACONS)) return EventResult.ALLOW;

// Send message
Expand All @@ -376,7 +376,7 @@ private EventResult onBreakBlock(ServerPlayerEntity player, ServerWorld world, B
}

// Remove beacon
player.getEntityWorld().setBlockState(pos, state.getFluidState().getBlockState());
player.getWorld().setBlockState(pos, state.getFluidState().getBlockState());
return EventResult.DENY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class LivingEntityMixin {
@Redirect(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getDeathSound()Lnet/minecraft/sound/SoundEvent;"))
private SoundEvent modifyDeathSound(LivingEntity entity) {
SoundEvent defaultSound = this.getDeathSound();
if (entity.getEntityWorld().isClient()) return defaultSound;
if (entity.getWorld().isClient()) return defaultSound;

try (EventInvokers invokers = Stimuli.select().forEntity(entity)) {
return invokers.get(PlayDeathSoundListener.EVENT).playDeathSound(entity, defaultSound);
Expand All @@ -34,7 +34,7 @@ private SoundEvent modifyDeathSound(LivingEntity entity) {
@Redirect(method = "playHurtSound", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getHurtSound(Lnet/minecraft/entity/damage/DamageSource;)Lnet/minecraft/sound/SoundEvent;"))
private SoundEvent modifyHurtSound(LivingEntity entity, DamageSource source) {
SoundEvent defaultSound = this.getHurtSound(source);
if (entity.getEntityWorld().isClient()) return defaultSound;
if (entity.getWorld().isClient()) return defaultSound;

try (EventInvokers invokers = Stimuli.select().forEntity(entity)) {
return invokers.get(PlayHurtSoundListener.EVENT).playHurtSound(entity, source, defaultSound);
Expand Down