mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-20 14:16:26 -04:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4eba39562a |
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.util.ByIdMap;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.item.component.FireworkExplosion;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
@Mixin(FireworkExplosion.Shape.class)
|
||||
public abstract class FireworkExplosionShapeMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
private static FireworkExplosion.Shape[] $VALUES;
|
||||
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
private static IntFunction<FireworkExplosion.Shape> BY_ID;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
public static StreamCodec<ByteBuf, FireworkExplosion.Shape> STREAM_CODEC;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
@Mutable
|
||||
public static Codec<FireworkExplosion.Shape> CODEC;
|
||||
|
||||
@Invoker("<init>")
|
||||
private static FireworkExplosion.Shape cobblemon$createFireworkExplosionShape(String enumName, int internalId, int id, String name) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "<clinit>",
|
||||
at = @At("TAIL")
|
||||
)
|
||||
private static void cobblemon$addFireworkExplosionShape(CallbackInfo ci) {
|
||||
ArrayList<FireworkExplosion.Shape> types = new ArrayList<>(List.of($VALUES));
|
||||
|
||||
types.add(cobblemon$createFireworkExplosionShape("POKEBALL", $VALUES.length, 5, "pokeball"));
|
||||
|
||||
$VALUES = types.toArray(FireworkExplosion.Shape[]::new);
|
||||
|
||||
BY_ID = ByIdMap.continuous(FireworkExplosion.Shape::getId, FireworkExplosion.Shape.values(), ByIdMap.OutOfBoundsStrategy.ZERO);
|
||||
STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, FireworkExplosion.Shape::getId);
|
||||
CODEC = StringRepresentable.fromValues(FireworkExplosion.Shape::values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.minecraft.client.particle.FireworkParticles;
|
||||
import net.minecraft.world.item.component.FireworkExplosion;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(FireworkParticles.Starter.class)
|
||||
public abstract class FireworkParticlesMixin {
|
||||
|
||||
@Shadow
|
||||
protected abstract void createParticleShape(double speed, double[][] coords, IntList colors, IntList fadeColors, boolean trail, boolean twinkle, boolean isCreeper);
|
||||
|
||||
@Inject(
|
||||
method = "tick()V",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/particle/Particle;setColor(FFF)V",
|
||||
shift = At.Shift.BEFORE,
|
||||
by = 2
|
||||
)
|
||||
)
|
||||
private void cobblemon$createPokeballParticleShape(
|
||||
CallbackInfo ci,
|
||||
@Local FireworkExplosion fireworkExplosion2,
|
||||
@Local(ordinal = 0) int bl3,
|
||||
@Local(ordinal = 0) int bl4,
|
||||
@Local(ordinal = 0) IntList intList,
|
||||
@Local(ordinal = 0) IntList intList2
|
||||
) {
|
||||
if (fireworkExplosion2.shape().getSerializedName().equals("pokeball")) {
|
||||
final double[][] POKEBALL_PARTICLE_COORDS = new double[][]{
|
||||
{0, 0.5},
|
||||
{0.05, 0.497494},
|
||||
{0.1, 0.489898},
|
||||
{0.15, 0.47697},
|
||||
{0.2, 0.458258},
|
||||
{0.25, 0.433013},
|
||||
{0.3, 0.4},
|
||||
{0.35, 0.357071},
|
||||
{0.4, 0.3},
|
||||
{0.45, 0.217945},
|
||||
{0.4975, 0.049937},
|
||||
{0.086606, 0.049994},
|
||||
{0.05, 0.086603},
|
||||
{0, 0.1},
|
||||
{0.05, 0.049994},
|
||||
|
||||
{0.05, -0.049994},
|
||||
{0, -0.1},
|
||||
{0.05, -0.086603},
|
||||
{0.086606, -0.049994},
|
||||
{0.0, -0.049937},
|
||||
{0.4975, -0.049937},
|
||||
{0.45, -0.217945},
|
||||
{0.4, -0.3},
|
||||
{0.35, -0.357071},
|
||||
{0.3, -0.4},
|
||||
{0.25, -0.433013},
|
||||
{0.2, -0.458258},
|
||||
{0.15, -0.47697},
|
||||
{0.1, -0.489898},
|
||||
{0.05, -0.497494},
|
||||
{0, -0.5},
|
||||
};
|
||||
|
||||
boolean b3 = bl3 == 1;
|
||||
boolean b4 = bl4 == 1;
|
||||
|
||||
this.createParticleShape(0.5, POKEBALL_PARTICLE_COORDS, intList, intList2, b3, b4, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.cobblemon.mod.common.CobblemonItems;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.FireworkExplosion;
|
||||
import net.minecraft.world.item.crafting.FireworkStarRecipe;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import org.spongepowered.asm.mixin.*;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(FireworkStarRecipe.class)
|
||||
public class FireworkStarRecipeMixin {
|
||||
|
||||
@Mutable
|
||||
@Shadow
|
||||
@Final
|
||||
private static Map<Item, FireworkExplosion.Shape> SHAPE_BY_ITEM;
|
||||
|
||||
@Mutable
|
||||
@Shadow
|
||||
@Final
|
||||
private static Ingredient SHAPE_INGREDIENT;
|
||||
|
||||
@Inject(method = "<clinit>", at = @At("TAIL"))
|
||||
private static void cobblemon$addCustomShape(CallbackInfo ci) {
|
||||
ItemStack[] existing = SHAPE_INGREDIENT.getItems();
|
||||
ItemStack[] extended = new ItemStack[existing.length + 1];
|
||||
System.arraycopy(existing, 0, extended, 0, existing.length);
|
||||
|
||||
extended[existing.length] = new ItemStack(CobblemonItems.POKE_BALL);
|
||||
|
||||
SHAPE_INGREDIENT = Ingredient.of(Arrays.stream(extended)
|
||||
.map(ItemStack::getItem)
|
||||
.toArray(ItemLike[]::new));
|
||||
SHAPE_BY_ITEM.put(CobblemonItems.POKE_BALL, FireworkExplosion.Shape.byId(5));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
"BuiltinModelItemRendererMixin",
|
||||
"ClientPacketListenerMixin",
|
||||
"EntityRenderDispatcherMixin",
|
||||
"FireworkParticlesMixin",
|
||||
"ItemPropertiesMixin",
|
||||
"MusicManagerMixin",
|
||||
"ParticleManagerMixin",
|
||||
@@ -60,6 +61,8 @@
|
||||
"EntityStorageMixin",
|
||||
"EntityVillagerMixin",
|
||||
"ExplosionMixin",
|
||||
"FireworkExplosionShapeMixin",
|
||||
"FireworkStarRecipeMixin",
|
||||
"ItemStackComponentizationFixMixin",
|
||||
"LecternBlockMixin",
|
||||
"LightningBoltMixin",
|
||||
|
||||
Reference in New Issue
Block a user