SteamWar/SpigotCore
Archiviert
13
0

Generalize BlockIds
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-02-01 14:50:28 +01:00
Ursprung e97d6a48c3
Commit 6cb89ee938
4 geänderte Dateien mit 34 neuen und 175 gelöschten Zeilen

Datei anzeigen

@ -19,34 +19,59 @@
package de.steamwar.techhider;
import net.minecraft.server.v1_14_R1.*;
import com.comphenix.tinyprotocol.Reflection;
import com.google.common.collect.ImmutableList;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
public class BlockIds14 implements BlockIds {
private static final Class<?> iRegistry = Reflection.getClass("{nms.core}.IRegistry");
private static final Class<?> minecraftKey = Reflection.getClass("{nms.resources}.MinecraftKey");
private static final Class<?> blockStateList = Reflection.getClass("{nms.world.level.block.state}.BlockStateList");
private static final Class<?> fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing");
private static final Class<?> fluid = Reflection.getClass("{nms.world.level.material}.Fluid");
private static final Reflection.MethodInvoker getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData);
@Override
public int materialToId(Material material) {
return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData());
return getCombinedId(getBlockData.invoke(getBlock(material)));
}
private static final Reflection.MethodInvoker getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList);
private static final Reflection.MethodInvoker getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class);
private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid).invoke(Reflection.getField(Reflection.getClass("{nms.world.level.material}.FluidTypes"), fluidTypeFlowing, 1).get(null));
private static final Iterable<?> registryBlockId = (Iterable<?>) Reflection.getField(TechHider.block, Reflection.getClass("{nms.core}.RegistryBlockID"), 0).get(null);
private static final Reflection.MethodInvoker getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid);
@Override
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>();
for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) {
ids.add(Block.getCombinedId(data));
for(Object data : (ImmutableList<?>) getStateList.invoke(getStates.invoke(getBlock(material)))) {
ids.add(getCombinedId(data));
}
if(material == Material.WATER){
Fluid water = FluidTypes.WATER.a(false);
for(IBlockData data : Block.REGISTRY_ID){
if(data.p() == water){
ids.add(Block.getCombinedId(data));
if(material == Material.WATER) {
for(Object data : registryBlockId) {
if(getFluid.invoke(data) == water) {
ids.add(getCombinedId(data));
}
}
}
return ids;
}
private static final Reflection.ConstructorInvoker newMinecraftkey = Reflection.getConstructor(minecraftKey, String.class);
private static final Reflection.MethodInvoker registryBlocksGet = Reflection.getTypedMethod(iRegistry, null, Object.class, minecraftKey);
private static final Object blockRegistry = Reflection.getField(iRegistry, Reflection.getClass("{nms.core}.RegistryBlocks"), 0, TechHider.block).get(null);
private Object getBlock(Material material) {
return registryBlocksGet.invoke(blockRegistry, newMinecraftkey.invoke(material.name().toLowerCase()));
}
private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData);
private int getCombinedId(Object blockData) {
return (int) getCombinedId.invoke(null, blockData);
}
}

Datei anzeigen

@ -1,52 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
public class BlockIds15 implements BlockIds {
@Override
public int materialToId(Material material) {
return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getBlockData());
}
@Override
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>();
for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(material.name().toLowerCase())).getStates().a()) {
ids.add(Block.getCombinedId(data));
}
if(material == Material.WATER){
Fluid water = FluidTypes.WATER.a(false);
for(IBlockData data : Block.REGISTRY_ID){
if(data.getFluid() == water){
ids.add(Block.getCombinedId(data));
}
}
}
return ids;
}
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import net.minecraft.core.IRegistry;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidTypes;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
public class BlockIds18 implements BlockIds {
@Override
public int materialToId(Material material) {
return Block.i(IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).n());
}
@Override
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>();
for(IBlockData data : IRegistry.U.a(new MinecraftKey(material.name().toLowerCase())).m().a()){
ids.add(Block.i(data));
}
if(material == Material.WATER){
Fluid water = FluidTypes.c.h();
for(IBlockData data : Block.o) {
if(data.o() == water) {
ids.add(Block.i(data));
}
}
}
return ids;
}
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.techhider;
import net.minecraft.core.IRegistry;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidTypes;
import org.bukkit.Material;
import java.util.HashSet;
import java.util.Set;
public class BlockIds19 implements BlockIds {
@Override
public int materialToId(Material material) {
return Block.i(IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).m());
}
@Override
public Set<Integer> materialToAllIds(Material material) {
Set<Integer> ids = new HashSet<>();
for(IBlockData data : IRegistry.V.a(new MinecraftKey(material.name().toLowerCase())).k().a()){
ids.add(Block.i(data));
}
if(material == Material.WATER){
Fluid water = FluidTypes.c.h();
for(IBlockData data : Block.o) {
if(data.p() == water) {
ids.add(Block.i(data));
}
}
}
return ids;
}
}