Skip to content
Merged
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
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.5
yarn_mappings = 1.21.5+build.1
loader_version = 0.16.14
fabric_version = 0.119.2+1.21.4
fabric_version = 0.123.2+1.21.5

plasmid_version = 0.6.3+1.21.4
plasmid_version = 0.6.4+1.21.5
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);
}
}
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
13 changes: 7 additions & 6 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,7 +156,7 @@ public final void baseTick() {
entry.tick(this.entry);
}

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

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 @@ -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