Skip to content

Commit

Permalink
Port to upstream changes (maybe)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed May 17, 2024
1 parent 4e898b8 commit 57285f9
Show file tree
Hide file tree
Showing 28 changed files with 1,095 additions and 1,131 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

base {
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8"

group = project.maven_group ?: rootProject.maven_group
Expand All @@ -23,8 +23,8 @@ repositories {
}

dependencies {
compileOnly "com.viaversion:viaversion-common:4.10.1"
compileOnly "com.viaversion:viabackwards-common:4.10.1"
compileOnly "com.viaversion:viaversion-common:5.0.0-SNAPSHOT"
compileOnly "com.viaversion:viabackwards-common:5.0.0-SNAPSHOT"
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:33.2.0-jre"
compileOnly "io.netty:netty-handler:4.1.109.Final"
Expand All @@ -41,7 +41,6 @@ sourceSets {

java {
withSourcesJar()
withJavadocJar()
}

jar {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ org.gradle.configureondemand=true

maven_group=net.raphimc
maven_name=ViaAprilFools
maven_version=2.0.13-SNAPSHOT
maven_version=3.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

public class ViaAprilFoolsConfig extends Config implements net.raphimc.viaaprilfools.platform.ViaAprilFoolsConfig {

public ViaAprilFoolsConfig(final File configFile) {
super(configFile);
public ViaAprilFoolsConfig(final File configFile, final Logger logger) {
super(configFile, logger);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
*/
package net.raphimc.viaaprilfools.api.data;

import com.viaversion.viabackwards.api.data.BackwardsMappings;
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.nbt.tag.CompoundTag;
import net.raphimc.viaaprilfools.ViaAprilFools;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.logging.Logger;

public class AprilFoolsMappings extends BackwardsMappings {
public class AprilFoolsMappingData extends BackwardsMappingData {

public AprilFoolsMappings(String unmappedVersion, String mappedVersion, @Nullable Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass) {
public AprilFoolsMappingData(String unmappedVersion, String mappedVersion, @Nullable Class<? extends Protocol<?, ?, ?, ?>> vvProtocolClass) {
super(unmappedVersion, mappedVersion, vvProtocolClass);
}

@Override
protected @Nullable CompoundTag readMappingsFile(String name) {
return VAFMappingDataLoader.INSTANCE.loadNBTFromDir(name);
return AprilFoolsMappingDataLoader.INSTANCE.loadNBTFromDir(name);
}

@Override
protected @Nullable CompoundTag readUnmappedIdentifiersFile(String name) {
return VAFMappingDataLoader.INSTANCE.loadNBT(name, true);
return AprilFoolsMappingDataLoader.INSTANCE.loadNBT(name, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import java.io.File;
import java.util.logging.Logger;

public class VAFMappingDataLoader extends BackwardsMappingDataLoader {
public class AprilFoolsMappingDataLoader extends BackwardsMappingDataLoader {

public static final VAFMappingDataLoader INSTANCE = new VAFMappingDataLoader();
public static final AprilFoolsMappingDataLoader INSTANCE = new AprilFoolsMappingDataLoader();

public VAFMappingDataLoader() {
super(VAFMappingDataLoader.class, "assets/viaaprilfools/data/");
public AprilFoolsMappingDataLoader() {
super(AprilFoolsMappingDataLoader.class, "assets/viaaprilfools/data/");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
/*
* This file is part of ViaAprilFools - https://github.com/RaphiMC/ViaAprilFools
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaaprilfools.api.minecraft.entity;

import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.util.EntityTypeUtil;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Locale;

public enum EntityTypes20w14infinite implements EntityType {

ENTITY(null, null),

AREA_EFFECT_CLOUD(ENTITY),
END_CRYSTAL(ENTITY),
EVOKER_FANGS(ENTITY),
EXPERIENCE_ORB(ENTITY),
EYE_OF_ENDER(ENTITY),
FALLING_BLOCK(ENTITY),
ITEM(ENTITY),
TNT(ENTITY),
LIGHTNING_BOLT(ENTITY),

// Hanging entities
HANGING_ENTITY(ENTITY, null),
LEASH_KNOT(HANGING_ENTITY),
PAINTING(HANGING_ENTITY),
ITEM_FRAME(HANGING_ENTITY),

// Projectiles
PROJECTILE(ENTITY, null), // Not actually its own abstract type, but useful for categorizing
SNOWBALL(PROJECTILE),
ENDER_PEARL(PROJECTILE),
EGG(PROJECTILE),
POTION(PROJECTILE),
EXPERIENCE_BOTTLE(PROJECTILE),
FIREWORK_ROCKET(PROJECTILE),
LLAMA_SPIT(PROJECTILE),
SHULKER_BULLET(PROJECTILE),
FISHING_BOBBER(PROJECTILE),
WITHER_SKULL(PROJECTILE),
DRAGON_FIREBALL(PROJECTILE), // Doesn't actually inherit fireball

ABSTRACT_ARROW(PROJECTILE, null),
ARROW(ABSTRACT_ARROW),
SPECTRAL_ARROW(ABSTRACT_ARROW),
TRIDENT(ABSTRACT_ARROW),

ABSTRACT_FIREBALL(ENTITY, null),
FIREBALL(ABSTRACT_FIREBALL),
SMALL_FIREBALL(ABSTRACT_FIREBALL),

// Vehicles
VEHICLE(ENTITY, null),
BOAT(VEHICLE),

ABSTRACT_MINECART(VEHICLE, null),
MINECART(ABSTRACT_MINECART),
FURNACE_MINECART(ABSTRACT_MINECART),
COMMAND_BLOCK_MINECART(ABSTRACT_MINECART),
TNT_MINECART(ABSTRACT_MINECART),
SPAWNER_MINECART(ABSTRACT_MINECART),

ABSTRACT_MINECART_CONTAINER(ABSTRACT_MINECART, null),
CHEST_MINECART(ABSTRACT_MINECART_CONTAINER),
HOPPER_MINECART(ABSTRACT_MINECART_CONTAINER),

// Living entities as a larger subclass
LIVING_ENTITY(ENTITY, null),
ARMOR_STAND(LIVING_ENTITY),
PLAYER(LIVING_ENTITY),

// Mobs as a larger subclass
MOB(LIVING_ENTITY, null),
ENDER_DRAGON(MOB),

SLIME(MOB),
MAGMA_CUBE(SLIME),

// Ambient mobs
AMBIENT_CREATURE(MOB, null),
BAT(AMBIENT_CREATURE),

// Flying mobs
FLYING_MOB(MOB, null),
GHAST(FLYING_MOB),
PHANTOM(FLYING_MOB),

// Pathfinder mobs and its subclasses
PATHFINDER_MOB(MOB, null),

ABSTRACT_GOLEM(PATHFINDER_MOB, null),
SNOW_GOLEM(ABSTRACT_GOLEM),
IRON_GOLEM(ABSTRACT_GOLEM),
SHULKER(ABSTRACT_GOLEM),

// Water mobs
WATER_ANIMAL(PATHFINDER_MOB, null),
DOLPHIN(WATER_ANIMAL),
SQUID(WATER_ANIMAL),

ABSTRACT_FISH(WATER_ANIMAL, null),
PUFFERFISH(ABSTRACT_FISH),

ABSTRACT_SCHOOLING_FISH(ABSTRACT_FISH, null),
COD(ABSTRACT_SCHOOLING_FISH),
SALMON(ABSTRACT_SCHOOLING_FISH),
TROPICAL_FISH(ABSTRACT_SCHOOLING_FISH),

// Ageable mobs and (tamable) animals
ABSTRACT_AGEABLE(PATHFINDER_MOB, null),
ABSTRACT_VILLAGER(ABSTRACT_AGEABLE, null),
VILLAGER(ABSTRACT_VILLAGER),
WANDERING_TRADER(ABSTRACT_VILLAGER),

ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
CHICKEN(ABSTRACT_ANIMAL),
PANDA(ABSTRACT_ANIMAL),
PIG(ABSTRACT_ANIMAL),
POLAR_BEAR(ABSTRACT_ANIMAL),
RABBIT(ABSTRACT_ANIMAL),
SHEEP(ABSTRACT_ANIMAL),
BEE(ABSTRACT_ANIMAL),
TURTLE(ABSTRACT_ANIMAL),
FOX(ABSTRACT_ANIMAL),
HOGLIN(ABSTRACT_ANIMAL),
STRIDER(ABSTRACT_ANIMAL),

COW(ABSTRACT_ANIMAL),
MOOSHROOM(COW),

TAMABLE_ANIMAL(ABSTRACT_ANIMAL, null),
CAT(TAMABLE_ANIMAL),
OCELOT(TAMABLE_ANIMAL),
WOLF(TAMABLE_ANIMAL),
PARROT(TAMABLE_ANIMAL),

ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
HORSE(ABSTRACT_HORSE),
SKELETON_HORSE(ABSTRACT_HORSE),
ZOMBIE_HORSE(ABSTRACT_HORSE),

ABSTRACT_CHESTED_HORSE(ABSTRACT_HORSE, null),
DONKEY(ABSTRACT_CHESTED_HORSE),
MULE(ABSTRACT_CHESTED_HORSE),
LLAMA(ABSTRACT_CHESTED_HORSE),
TRADER_LLAMA(LLAMA),

// Monsters
ABSTRACT_MONSTER(PATHFINDER_MOB, null),
BLAZE(ABSTRACT_MONSTER),
CREEPER(ABSTRACT_MONSTER),
ENDERMITE(ABSTRACT_MONSTER),
ENDERMAN(ABSTRACT_MONSTER),
GIANT(ABSTRACT_MONSTER),
SILVERFISH(ABSTRACT_MONSTER),
VEX(ABSTRACT_MONSTER),
WITHER(ABSTRACT_MONSTER),
PIGLIN(ABSTRACT_MONSTER),

ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
SKELETON(ABSTRACT_SKELETON),
STRAY(ABSTRACT_SKELETON),
WITHER_SKELETON(ABSTRACT_SKELETON),

ZOMBIE(ABSTRACT_MONSTER),
DROWNED(ZOMBIE),
HUSK(ZOMBIE),
ZOMBIFIED_PIGLIN(ZOMBIE),
ZOMBIE_VILLAGER(ZOMBIE),

GUARDIAN(ABSTRACT_MONSTER),
ELDER_GUARDIAN(GUARDIAN),

SPIDER(ABSTRACT_MONSTER),
CAVE_SPIDER(SPIDER),

// Raiders
ABSTRACT_RAIDER(ABSTRACT_MONSTER, null),
WITCH(ABSTRACT_RAIDER),
RAVAGER(ABSTRACT_RAIDER),

ABSTRACT_ILLAGER(ABSTRACT_RAIDER, null),
SPELLCASTER_ILLAGER(ABSTRACT_ILLAGER, null),
VINDICATOR(ABSTRACT_ILLAGER),
PILLAGER(ABSTRACT_ILLAGER),
EVOKER(SPELLCASTER_ILLAGER),
ILLUSIONER(SPELLCASTER_ILLAGER);

private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
private final EntityType parent;
private final String identifier;
private int id = -1;

EntityTypes20w14infinite(final EntityType parent) {
this.parent = parent;
this.identifier = Key.namespaced(name().toLowerCase(Locale.ROOT));
}

EntityTypes20w14infinite(final EntityType parent, @Nullable final String identifier) {
this.parent = parent;
this.identifier = identifier;
}

@Override
public int getId() {
if (id == -1) {
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
}
return id;
}

@Override
public String identifier() {
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
return identifier;
}

@Override
public @Nullable EntityType getParent() {
return parent;
}

@Override
public boolean isAbstractType() {
return identifier == null;
}

public static EntityType getTypeFromId(final int typeId) {
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
}

public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
import net.raphimc.viaaprilfools.ViaAprilFools;
import net.raphimc.viaaprilfools.ViaAprilFoolsConfig;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.viaaprilfools.protocols.protocol1_14to3D_Shareware.Protocol1_14to3D_Shareware;
import net.raphimc.viaaprilfools.protocols.protocol1_16_2toCombatTest8c.Protocol1_16_2toCombatTest8c;
import net.raphimc.viaaprilfools.protocols.protocol1_16to20w14infinite.Protocol1_16to20w14infinite;
import net.raphimc.viaaprilfools.protocols.protocol3D_Sharewareto1_14.Protocol3D_Sharewareto1_14;
import net.raphimc.viaaprilfools.protocol.s3d_sharewaretov1_14.Protocol1_14to3D_Shareware;
import net.raphimc.viaaprilfools.protocol.scombattest8ctov1_16_2.Protocol1_16_2toCombatTest8c;
import net.raphimc.viaaprilfools.protocol.s20w14infinitetov1_16.Protocol20w14infiniteTo1_16;
import net.raphimc.viaaprilfools.protocol.v1_14tos3d_shareware.Protocol3D_Sharewareto1_14;

import java.io.File;
import java.util.logging.Logger;

public interface ViaAprilFoolsPlatform {

default void init(final File configFile) {
final ViaAprilFoolsConfig config = new ViaAprilFoolsConfig(configFile);
final ViaAprilFoolsConfig config = new ViaAprilFoolsConfig(configFile, getLogger());
config.reload();
ViaAprilFools.init(this, config);
Via.getManager().getConfigurationProvider().register(config);
Expand All @@ -43,7 +43,7 @@ default void init(final File configFile) {
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
protocolManager.registerProtocol(new Protocol1_14to3D_Shareware(), ProtocolVersion.v1_14, AprilFoolsProtocolVersion.s3d_shareware);
protocolManager.registerProtocol(new Protocol3D_Sharewareto1_14(), AprilFoolsProtocolVersion.s3d_shareware, ProtocolVersion.v1_14);
protocolManager.registerProtocol(new Protocol1_16to20w14infinite(), ProtocolVersion.v1_16, AprilFoolsProtocolVersion.s20w14infinite);
protocolManager.registerProtocol(new Protocol20w14infiniteTo1_16(), ProtocolVersion.v1_16, AprilFoolsProtocolVersion.s20w14infinite);
protocolManager.registerProtocol(new Protocol1_16_2toCombatTest8c(), ProtocolVersion.v1_16_2, AprilFoolsProtocolVersion.sCombatTest8c);
}

Expand Down
Loading

0 comments on commit 57285f9

Please sign in to comment.