Skip to content

Commit

Permalink
Fix Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Jun 15, 2024
1 parent 5b9a9ef commit 496e044
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static List<Fire> getFires() {
* @return registered {@link Fire} or {@link #DEFAULT_FIRE}.
*/
public static Fire getFire(@Nullable String modId, @Nullable String fireId) {
return isValidModId(modId) && isValidFireId(fireId) ? getFire(new ResourceLocation(modId, fireId)) : DEFAULT_FIRE;
return isValidModId(modId) && isValidFireId(fireId) ? getFire(fireType(modId, fireId)) : DEFAULT_FIRE;
}

/**
Expand Down Expand Up @@ -367,7 +367,7 @@ public static boolean isValidType(@Nullable ResourceLocation fireType) {
* @return whether a fire is registered with the given values.
*/
public static boolean isRegisteredType(@Nullable String modId, @Nullable String fireId) {
return isValidModId(modId) && isValidFireId(fireId) && isRegisteredType(new ResourceLocation(modId, fireId));
return isValidModId(modId) && isValidFireId(fireId) && isRegisteredType(fireType(modId, fireId));
}

/**
Expand Down Expand Up @@ -428,7 +428,7 @@ public static boolean isRegisteredModId(@Nullable String id) {
* @return the closest well-formed Fire Type.
*/
public static ResourceLocation sanitize(@Nullable String modId, @Nullable String fireId) {
return isValidModId(modId) && isValidModId(fireId) ? sanitize(new ResourceLocation(modId, fireId)) : DEFAULT_FIRE_TYPE;
return isValidModId(modId) && isValidModId(fireId) ? sanitize(fireType(modId, fireId)) : DEFAULT_FIRE_TYPE;
}

/**
Expand Down Expand Up @@ -576,7 +576,7 @@ public static boolean damageOnFire(Entity entity, ResourceLocation fireType) {
*/
private static boolean harmOrHeal(Entity entity, DamageSource damageSource, float damage, boolean invertHealAndHarm) {
Predicate<Entity> behavior = FireManager.getProperty(((FireTyped) entity).getFireType(), Fire::getBehavior);
if (behavior.test(entity) && damage != 0) {
if (behavior.test(entity) && Float.compare(damage, 0) != 0) {
if (damage > 0) {
if (entity instanceof LivingEntity livingEntity) {
if (livingEntity.isInvertedHealAndHarm() && invertHealAndHarm) {
Expand Down Expand Up @@ -618,4 +618,8 @@ public static void writeTag(CompoundTag tag, @Nullable ResourceLocation fireType
public static ResourceLocation readTag(CompoundTag tag) {
return ensure(ResourceLocation.tryParse(tag.getString(FIRE_TYPE_TAG)));
}

private static ResourceLocation fireType(@Nullable String modId, @Nullable String fireId) {
return new ResourceLocation(Objects.requireNonNull(modId), Objects.requireNonNull(fireId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public CustomCampfireBlock(ResourceLocation fireType, boolean spawnParticles, Pr
this.fireType = fireType;
}

protected BlockEntityType<? extends CustomCampfireBlockEntity> getBlockEntityType() {
protected BlockEntityType<CustomCampfireBlockEntity> getBlockEntityType() {
return FireManager.CUSTOM_CAMPFIRE_ENTITY_TYPE.get();
}

protected BlockEntityTicker<? super CampfireBlockEntity> particleTick() {
protected BlockEntityTicker<CampfireBlockEntity> particleTick() {
return CustomCampfireBlockEntity::particleTick;
}

protected BlockEntityTicker<? super CampfireBlockEntity> cookTick() {
protected BlockEntityTicker<CampfireBlockEntity> cookTick() {
return CustomCampfireBlockEntity::cookTick;
}

protected BlockEntityTicker<? super CampfireBlockEntity> cooldownTick() {
protected BlockEntityTicker<CampfireBlockEntity> cooldownTick() {
return CustomCampfireBlockEntity::cooldownTick;
}

Expand All @@ -79,7 +79,7 @@ public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState sta
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, @NotNull BlockState state, @NotNull BlockEntityType<T> blockEntityType) {
BlockEntityType<? extends CustomCampfireBlockEntity> customBlockEntityType = getBlockEntityType();
BlockEntityType<CustomCampfireBlockEntity> customBlockEntityType = getBlockEntityType();
if (level.isClientSide) {
return state.getValue(LIT) ? createTickerHelper(blockEntityType, customBlockEntityType, particleTick()) : null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void tick(@NotNull BlockState state, @NotNull ServerLevel level, @NotNull
int age = state.getValue(AGE);
if (
!state.canSurvive(level, pos) ||
FireManager.getProperty(getFireType(), Fire::canRainDouse) && !level.getBlockState(pos.below()).is(level.dimensionType().infiniburn()) && level.isRaining() && level.isRainingAt(pos) && rand.nextFloat() < 0.2 + (float) age * 0.03
FireManager.getProperty(getFireType(), Fire::canRainDouse) && !level.getBlockState(pos.below()).is(level.dimensionType().infiniburn()) && level.isRaining() && level.isRainingAt(pos) && rand.nextFloat() < 0.2 + age * 0.03
) {
level.removeBlock(pos, false);
} else if (age < MAX_AGE && rand.nextInt(2) == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public DynamicBlockEntityType(BlockEntitySupplier<? extends T> supplier) {

@Override
public boolean isValid(BlockState state) {
return FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(campfire -> campfire instanceof CustomCampfireBlock).toList().contains(state.getBlock());
return FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(CustomCampfireBlock.class::isInstance).toList().contains(state.getBlock());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public final class ClientModLoader implements ClientModInitializer {
public void onInitializeClient() {
FireClientManager.registerFires(FireManager.getFires());
BlockEntityRenderers.register(FireManager.CUSTOM_CAMPFIRE_ENTITY_TYPE.get(), CampfireRenderer::new);
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(campfire -> campfire instanceof CustomCampfireBlock).forEach(campfire -> BlockRenderLayerMap.INSTANCE.putBlock(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(source -> source instanceof CustomFireBlock).forEach(source -> BlockRenderLayerMap.INSTANCE.putBlock(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomTorchBlock).forEach(torch -> BlockRenderLayerMap.INSTANCE.putBlock(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomWallTorchBlock).forEach(torch -> BlockRenderLayerMap.INSTANCE.putBlock(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(CustomCampfireBlock.class::isInstance).forEach(campfire -> BlockRenderLayerMap.INSTANCE.putBlock(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(CustomFireBlock.class::isInstance).forEach(source -> BlockRenderLayerMap.INSTANCE.putBlock(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(CustomTorchBlock.class::isInstance).forEach(torch -> BlockRenderLayerMap.INSTANCE.putBlock(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(CustomWallTorchBlock.class::isInstance).forEach(torch -> BlockRenderLayerMap.INSTANCE.putBlock(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.FLAME_PARTICLE).forEach(flame -> ParticleFactoryRegistry.getInstance().register((SimpleParticleType) flame, FlameParticle.Provider::new));
ClientPlayNetworking.registerGlobalReceiver(RegisterFirePacket.ID, FabricFirePacketHandler::handleRegister);
ClientPlayNetworking.registerGlobalReceiver(UnregisterFirePacket.ID, FabricFirePacketHandler::handleUnregister);
Expand Down
3 changes: 0 additions & 3 deletions forge/src/main/java/it/crystalnest/soul_fire_d/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@ public final class ModLoader {
public ModLoader() {
CommonModLoader.init();
LootRegistry.register(FMLJavaModLoadingContext.get().getModEventBus());
// MinecraftForge.EVENT_BUS.addListener((RenderBlockScreenEffectEvent event) -> {
// FireManager.getSourceBlock(((FireTyped) event.getPlayer()).getFireType()).defaultBlockState();
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ private FMLClientSetupEventHandler() {}
@SuppressWarnings("deprecation")
public static void handle(FMLClientSetupEvent event) {
FireClientManager.registerFires(FireManager.getFires());
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(campfire -> campfire instanceof CustomCampfireBlock).forEach(campfire -> ItemBlockRenderTypes.setRenderLayer(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(source -> source instanceof CustomFireBlock).forEach(source -> ItemBlockRenderTypes.setRenderLayer(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomTorchBlock).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomWallTorchBlock).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(CustomCampfireBlock.class::isInstance).forEach(campfire -> ItemBlockRenderTypes.setRenderLayer(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(CustomFireBlock.class::isInstance).forEach(source -> ItemBlockRenderTypes.setRenderLayer(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(CustomTorchBlock.class::isInstance).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(CustomWallTorchBlock.class::isInstance).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ private FMLClientSetupEventHandler() {}
@SuppressWarnings("deprecation")
public static void handle(FMLClientSetupEvent event) {
FireClientManager.registerFires(FireManager.getFires());
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(campfire -> campfire instanceof CustomCampfireBlock).forEach(campfire -> ItemBlockRenderTypes.setRenderLayer(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(source -> source instanceof CustomFireBlock).forEach(source -> ItemBlockRenderTypes.setRenderLayer(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomTorchBlock).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(torch -> torch instanceof CustomWallTorchBlock).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.CAMPFIRE_BLOCK).stream().filter(CustomCampfireBlock.class::isInstance).forEach(campfire -> ItemBlockRenderTypes.setRenderLayer(campfire, RenderType.cutout()));
FireManager.getComponentList(FireComponent.SOURCE_BLOCK).stream().filter(CustomFireBlock.class::isInstance).forEach(source -> ItemBlockRenderTypes.setRenderLayer(source, RenderType.cutout()));
FireManager.getComponentList(FireComponent.TORCH_BLOCK).stream().filter(CustomTorchBlock.class::isInstance).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
FireManager.getComponentList(FireComponent.WALL_TORCH_BLOCK).stream().filter(CustomWallTorchBlock.class::isInstance).forEach(torch -> ItemBlockRenderTypes.setRenderLayer(torch, RenderType.cutout()));
}

@SubscribeEvent
Expand Down

0 comments on commit 496e044

Please sign in to comment.