mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
implement force_solid for blocks
This commit is contained in:
parent
90ecbf160a
commit
d153dea104
14 changed files with 252 additions and 290 deletions
|
@ -56,7 +56,6 @@ impl BlockBehavior {
|
|||
self
|
||||
}
|
||||
|
||||
// TODO: currently unused
|
||||
pub fn force_solid(mut self, force_solid: bool) -> Self {
|
||||
self.force_solid = Some(force_solid);
|
||||
self
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -106,9 +106,7 @@ where
|
|||
fn find(&self, ecs_lock: Arc<Mutex<World>>) -> Option<Entity> {
|
||||
let mut ecs = ecs_lock.lock();
|
||||
let mut query = ecs.query_filtered::<(Entity, Q), Filter>();
|
||||
let entity = query.iter(&ecs).find(|(_, q)| (self)(q)).map(|(e, _)| e);
|
||||
|
||||
entity
|
||||
query.iter(&ecs).find(|(_, q)| (self)(q)).map(|(e, _)| e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ impl Vec3 {
|
|||
|
||||
pub fn normalize(&self) -> Vec3 {
|
||||
let length = f64::sqrt(self.x * self.x + self.y * self.y + self.z * self.z);
|
||||
if length < 1e-4 {
|
||||
if length < 1e-5 {
|
||||
return Vec3::ZERO;
|
||||
}
|
||||
Vec3 {
|
||||
|
|
|
@ -17,9 +17,9 @@ pub enum Direction {
|
|||
impl Direction {
|
||||
pub const HORIZONTAL: [Direction; 4] = [
|
||||
Direction::North,
|
||||
Direction::East,
|
||||
Direction::South,
|
||||
Direction::West,
|
||||
Direction::East,
|
||||
];
|
||||
pub const VERTICAL: [Direction; 2] = [Direction::Down, Direction::Up];
|
||||
|
||||
|
|
|
@ -1,24 +1,3 @@
|
|||
// default List<VoxelShape> getEntityCollisions(@Nullable Entity entity, AABB
|
||||
// aabb) { if (aabb.getSize() < 1.0E-7) {
|
||||
// return List.of();
|
||||
// } else {
|
||||
// Predicate var3 = entity == null ? EntitySelector.CAN_BE_COLLIDED_WITH
|
||||
// : EntitySelector.NO_SPECTATORS.and(entity::canCollideWith);
|
||||
// List var4 = this.getEntities(entity, aabb.inflate(1.0E-7), var3);
|
||||
// if (var4.isEmpty()) {
|
||||
// return List.of();
|
||||
// } else {
|
||||
// Builder var5 = ImmutableList.builderWithExpectedSize(var4.size());
|
||||
|
||||
// for (Entity var7 : var4) {
|
||||
// var5.add(Shapes.create(var7.getBoundingBox()));
|
||||
// }
|
||||
|
||||
// return var5.build();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
use azalea_core::aabb::AABB;
|
||||
use azalea_entity::{
|
||||
LocalEntity, Physics,
|
||||
|
|
|
@ -256,7 +256,7 @@ impl EntityCollisionContext {
|
|||
}
|
||||
|
||||
pub fn can_stand_on_fluid(&self, above: &FluidState, target: &FluidState) -> bool {
|
||||
self.can_stand_on_fluid_predicate.matches(&target) && !above.is_same_kind(target)
|
||||
self.can_stand_on_fluid_predicate.matches(target) && !above.is_same_kind(target)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
|
|||
let mut z_flow: f64 = 0.;
|
||||
let mut x_flow: f64 = 0.;
|
||||
|
||||
println!("current fluid height: {}", fluid.height());
|
||||
let cur_fluid_height = fluid.height();
|
||||
|
||||
for direction in Direction::HORIZONTAL {
|
||||
let adjacent_block_pos = pos.offset_with_direction(direction);
|
||||
|
@ -196,46 +196,37 @@ pub fn get_fluid_flow(fluid: &FluidState, world: &Instance, pos: BlockPos) -> Ve
|
|||
.unwrap_or_default();
|
||||
let adjacent_fluid_state = FluidState::from(adjacent_block_state);
|
||||
|
||||
if fluid.affects_flow(&adjacent_fluid_state) {
|
||||
let mut adjacent_fluid_height = adjacent_fluid_state.height();
|
||||
let mut adjacent_height_difference: f32 = 0.;
|
||||
if !fluid.affects_flow(&adjacent_fluid_state) {
|
||||
continue;
|
||||
};
|
||||
let mut adjacent_fluid_height = adjacent_fluid_state.height();
|
||||
let mut adjacent_height_difference: f32 = 0.;
|
||||
|
||||
if adjacent_fluid_height == 0. {
|
||||
if !legacy_blocks_motion(adjacent_block_state) {
|
||||
let block_pos_below_adjacent = adjacent_block_pos.down(1);
|
||||
let fluid_below_adjacent = world
|
||||
.get_fluid_state(&block_pos_below_adjacent)
|
||||
.unwrap_or_default();
|
||||
if adjacent_fluid_height == 0. {
|
||||
if !legacy_blocks_motion(adjacent_block_state) {
|
||||
let block_pos_below_adjacent = adjacent_block_pos.down(1);
|
||||
let fluid_below_adjacent = world
|
||||
.get_fluid_state(&block_pos_below_adjacent)
|
||||
.unwrap_or_default();
|
||||
|
||||
if fluid.affects_flow(&fluid_below_adjacent) {
|
||||
adjacent_fluid_height = fluid_below_adjacent.height();
|
||||
if adjacent_fluid_height > 0. {
|
||||
adjacent_height_difference =
|
||||
fluid.height() - (adjacent_fluid_height - 0.8888889);
|
||||
}
|
||||
if fluid.affects_flow(&fluid_below_adjacent) {
|
||||
adjacent_fluid_height = fluid_below_adjacent.height();
|
||||
if adjacent_fluid_height > 0. {
|
||||
adjacent_height_difference =
|
||||
cur_fluid_height - (adjacent_fluid_height - 0.8888889);
|
||||
}
|
||||
}
|
||||
} else if adjacent_fluid_height > 0. {
|
||||
adjacent_height_difference = fluid.height() - adjacent_fluid_height;
|
||||
}
|
||||
} else if adjacent_fluid_height > 0. {
|
||||
adjacent_height_difference = cur_fluid_height - adjacent_fluid_height;
|
||||
}
|
||||
|
||||
println!(
|
||||
"our fluid height: {}, adjacent fluid height: {adjacent_fluid_height}",
|
||||
fluid.height()
|
||||
);
|
||||
println!(
|
||||
"{direction:?} adjacent_height_difference: {adjacent_height_difference}, {adjacent_fluid_state:?}"
|
||||
);
|
||||
|
||||
if adjacent_height_difference != 0. {
|
||||
x_flow += (direction.x() as f32 * adjacent_height_difference) as f64;
|
||||
z_flow += (direction.z() as f32 * adjacent_height_difference) as f64;
|
||||
}
|
||||
if adjacent_height_difference != 0. {
|
||||
x_flow += (direction.x() as f32 * adjacent_height_difference) as f64;
|
||||
z_flow += (direction.z() as f32 * adjacent_height_difference) as f64;
|
||||
}
|
||||
}
|
||||
|
||||
println!("x_flow: {x_flow}, z_flow: {z_flow}");
|
||||
|
||||
let mut flow = Vec3::new(x_flow, 0., z_flow);
|
||||
if fluid.falling {
|
||||
for direction in Direction::HORIZONTAL {
|
||||
|
|
|
@ -163,6 +163,7 @@ fn travel_in_air(
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn travel_in_fluid(
|
||||
world: &Instance,
|
||||
entity: Entity,
|
||||
|
@ -202,8 +203,6 @@ fn travel_in_fluid(
|
|||
// waterMovementSpeed = 0.96F;
|
||||
// }
|
||||
|
||||
println!("travel in fluid");
|
||||
|
||||
move_relative(physics, direction, speed, &acceleration);
|
||||
move_colliding(
|
||||
MoverType::Own,
|
||||
|
@ -225,8 +224,6 @@ fn travel_in_fluid(
|
|||
physics.velocity =
|
||||
get_fluid_falling_adjusted_movement(gravity, moving_down, new_velocity, sprinting);
|
||||
} else {
|
||||
println!("in lava");
|
||||
|
||||
move_relative(physics, direction, 0.02, &acceleration);
|
||||
move_colliding(
|
||||
MoverType::Own,
|
||||
|
@ -269,7 +266,6 @@ fn travel_in_fluid(
|
|||
velocity.up(0.6).down(position.y).up(y),
|
||||
)
|
||||
{
|
||||
println!("horizontal collision, setting y velocity");
|
||||
physics.velocity.y = 0.3;
|
||||
}
|
||||
}
|
||||
|
@ -311,12 +307,9 @@ fn is_free(
|
|||
) -> bool {
|
||||
let bounding_box = bounding_box.move_relative(delta);
|
||||
|
||||
// this.level().noCollision(this, var1) &&
|
||||
// !this.level().containsAnyLiquid(var1);
|
||||
|
||||
no_collision(
|
||||
world,
|
||||
source_entity,
|
||||
Some(source_entity),
|
||||
physics_query,
|
||||
collidable_entity_query,
|
||||
entity_physics,
|
||||
|
@ -327,7 +320,7 @@ fn is_free(
|
|||
|
||||
fn no_collision(
|
||||
world: &Instance,
|
||||
source_entity: Entity,
|
||||
source_entity: Option<Entity>,
|
||||
physics_query: &PhysicsQuery,
|
||||
collidable_entity_query: &CollidableEntityQuery,
|
||||
entity_physics: &mut Physics,
|
||||
|
@ -349,18 +342,16 @@ fn no_collision(
|
|||
if !get_entity_collisions(
|
||||
world,
|
||||
aabb,
|
||||
Some(source_entity),
|
||||
source_entity,
|
||||
physics_query,
|
||||
collidable_entity_query,
|
||||
)
|
||||
.is_empty()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// else if entity is none {
|
||||
// return true;
|
||||
// }
|
||||
else {
|
||||
false
|
||||
} else if source_entity.is_none() {
|
||||
true
|
||||
} else {
|
||||
let collision = border_collision(entity_physics, aabb);
|
||||
if let Some(collision) = collision {
|
||||
// !Shapes.joinIsNotEmpty(collision, Shapes.create(aabb), BooleanOp.AND);
|
||||
|
|
|
@ -296,7 +296,7 @@ impl Connection<ClientboundHandshakePacket, ServerboundHandshakePacket> {
|
|||
|
||||
let _ = socks5_impl::client::connect(&mut stream, address, proxy.auth)
|
||||
.await
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
.map_err(io::Error::other)?;
|
||||
|
||||
Self::new_from_stream(stream.into_inner()).await
|
||||
}
|
||||
|
|
|
@ -13,13 +13,14 @@ def generate(version_id):
|
|||
'1.20.3-pre4', 'shapes')
|
||||
pixlyzer_block_datas = lib.extract.get_pixlyzer_data(
|
||||
'1.20.3-pre4', 'blocks')
|
||||
burger_data = lib.extract.get_burger_data_for_version(version_id)
|
||||
|
||||
block_states_report = lib.extract.get_block_states_report(version_id)
|
||||
registries = lib.extract.get_registries_report(version_id)
|
||||
ordered_blocks = lib.code.blocks.get_ordered_blocks(registries)
|
||||
|
||||
lib.code.blocks.generate_blocks(
|
||||
block_states_report, pixlyzer_block_datas, ordered_blocks)
|
||||
block_states_report, pixlyzer_block_datas, ordered_blocks, burger_data)
|
||||
|
||||
lib.code.shapes.generate_block_shapes(
|
||||
pixlyzer_block_datas, shape_datas['shapes'], shape_datas['aabbs'], block_states_report)
|
||||
|
|
|
@ -12,13 +12,15 @@ BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/generated.rs')
|
|||
# - Block: Has properties and states.
|
||||
|
||||
|
||||
def generate_blocks(blocks_report: dict, pixlyzer_block_datas: dict, ordered_blocks: list[str]):
|
||||
def generate_blocks(blocks_report: dict, pixlyzer_block_datas: dict, ordered_blocks: list[str], burger_data: dict):
|
||||
with open(BLOCKS_RS_DIR, 'r') as f:
|
||||
existing_code = f.read().splitlines()
|
||||
|
||||
new_make_block_states_macro_code = []
|
||||
new_make_block_states_macro_code.append('make_block_states! {')
|
||||
|
||||
burger_block_datas = burger_data[0]['blocks']['block']
|
||||
|
||||
# Find properties
|
||||
properties = {}
|
||||
|
||||
|
@ -77,6 +79,7 @@ def generate_blocks(blocks_report: dict, pixlyzer_block_datas: dict, ordered_blo
|
|||
for block_id in ordered_blocks:
|
||||
block_data_report = blocks_report['minecraft:' + block_id]
|
||||
block_data_pixlyzer = pixlyzer_block_datas.get(f'minecraft:{block_id}', {})
|
||||
block_data_burger = burger_block_datas.get(block_id, {})
|
||||
|
||||
default_property_variants: dict[str, str] = {}
|
||||
for state in block_data_report['states']:
|
||||
|
@ -129,6 +132,14 @@ def generate_blocks(blocks_report: dict, pixlyzer_block_datas: dict, ordered_blo
|
|||
friction = block_data_pixlyzer.get('friction')
|
||||
if friction != None:
|
||||
behavior_constructor += f'.friction({friction})'
|
||||
|
||||
force_solid = None
|
||||
if block_data_burger.get('force_solid_on'):
|
||||
force_solid = 'true'
|
||||
elif block_data_burger.get('force_solid_off'):
|
||||
force_solid = 'false'
|
||||
if force_solid != None:
|
||||
behavior_constructor += f'.force_solid({force_solid})'
|
||||
|
||||
# TODO: use burger to generate the blockbehavior
|
||||
new_make_block_states_macro_code.append(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Extracting data from the Minecraft jars
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from lib.download import get_server_jar, get_burger, get_client_jar, get_pixlyzer, get_yarn_data, get_fabric_api_versions, get_fabric_loader_versions
|
||||
from lib.download import get_mappings_for_version, get_server_jar, get_burger, get_client_jar, get_pixlyzer, get_yarn_data, get_fabric_api_versions, get_fabric_loader_versions
|
||||
from lib.utils import get_dir_location, to_camel_case, upper_first_letter
|
||||
from zipfile import ZipFile
|
||||
import subprocess
|
||||
|
@ -53,19 +53,8 @@ python_command = None
|
|||
|
||||
|
||||
def determine_python_command():
|
||||
global python_command
|
||||
if python_command:
|
||||
return python_command
|
||||
|
||||
def try_python_command(version):
|
||||
return os.system(f'{version} --version') == 0
|
||||
|
||||
for version in (sys.executable, 'python3.9', 'python3.8', 'python3', 'python'):
|
||||
if try_python_command(version):
|
||||
python_command = version
|
||||
return version
|
||||
raise Exception(
|
||||
'Couldn\'t determine python command to use to run burger with!')
|
||||
return 'venv/bin/python'
|
||||
|
||||
|
||||
|
||||
def run_python_command_and_download_deps(command):
|
||||
|
@ -105,10 +94,14 @@ def get_burger_data_for_version(version_id: str):
|
|||
if not os.path.exists(get_dir_location(f'__cache__/burger-{version_id}.json')):
|
||||
get_burger()
|
||||
get_client_jar(version_id)
|
||||
get_mappings_for_version(version_id)
|
||||
|
||||
print('\033[92mRunning Burger...\033[m')
|
||||
run_python_command_and_download_deps(
|
||||
f'cd {get_dir_location("__cache__/Burger")} && {determine_python_command()} munch.py {get_dir_location("__cache__")}/client-{version_id}.jar --output {get_dir_location("__cache__")}/burger-{version_id}.json'
|
||||
f'cd {get_dir_location("__cache__/Burger")} && '\
|
||||
f'{determine_python_command()} munch.py {get_dir_location("__cache__")}/client-{version_id}.jar '\
|
||||
f'--output {get_dir_location("__cache__")}/burger-{version_id}.json '\
|
||||
f'--mappings {get_dir_location("__cache__")}/mappings-{version_id}.txt'
|
||||
)
|
||||
with open(get_dir_location(f'__cache__/burger-{version_id}.json'), 'r') as f:
|
||||
return json.load(f)
|
||||
|
|
|
@ -78,7 +78,6 @@ class Mappings:
|
|||
return self.classes[obfuscated_class_name]
|
||||
|
||||
def get_method(self, obfuscated_class_name, obfuscated_method_name, obfuscated_signature):
|
||||
# print(obfuscated_class_name, self.methods[obfuscated_class_name])
|
||||
return self.methods[obfuscated_class_name][f'{obfuscated_method_name}({obfuscated_signature})']
|
||||
|
||||
def get_field_type(self, obfuscated_class_name, obfuscated_field_name) -> str:
|
||||
|
|
Loading…
Add table
Reference in a new issue