Skip to content

Commit

Permalink
Disable engines
Browse files Browse the repository at this point in the history
Fixes #2678
Fixes #2696
  • Loading branch information
ramidzkh committed Aug 13, 2023
1 parent 30149cc commit 9e57cf2
Show file tree
Hide file tree
Showing 56 changed files with 338 additions and 2,839 deletions.
49 changes: 23 additions & 26 deletions src/main/java/forestry/Forestry.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,7 @@
@Mod("forestry")
public class Forestry {

@SuppressWarnings("NullableProblems")
public static Forestry instance;

public Forestry() {
instance = this;
ForestryAPI.instance = this;
ForestryAPI.forestryConstants = new Constants();
ForestryAPI.errorStateRegistry = new ErrorStateRegistry();
ClimateManager.climateRoot = ClimateRoot.getInstance();
ClimateManager.climateFactory = ClimateFactory.INSTANCE;
Expand All @@ -158,14 +152,13 @@ public Forestry() {
modEventBus.addListener(this::processIMCMessages);
modEventBus.addListener(this::clientSetupRenderers);
modEventBus.addListener(this::gatherData);
EventHandlerCore eventHandlerCore = new EventHandlerCore();
MinecraftForge.EVENT_BUS.register(eventHandlerCore);
MinecraftForge.EVENT_BUS.register(EventHandlerCore.class);
MinecraftForge.EVENT_BUS.register(this);
Proxies.render = DistExecutor.runForDist(() -> ProxyRenderClient::new, () -> ProxyRender::new);
Proxies.common = DistExecutor.runForDist(() -> ProxyClient::new, () -> ProxyCommon::new);
Proxies.render = DistExecutor.safeRunForDist(() -> ProxyRenderClient::new, () -> ProxyRender::new);
Proxies.common = DistExecutor.safeRunForDist(() -> ProxyClient::new, () -> ProxyCommon::new);

ModuleManager.getModuleHandler().runSetup();
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> clientInit(modEventBus, networkHandler));
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> new Client(modEventBus, networkHandler)::run);
modEventBus.addListener(EventPriority.NORMAL, false, FMLCommonSetupEvent.class, evt -> networkHandler.serverPacketHandler());
}

Expand Down Expand Up @@ -243,22 +236,26 @@ private void gatherData(GatherDataEvent event) {
}
}

private void clientInit(IEventBus modEventBus, NetworkHandler networkHandler) {
modEventBus.addListener(EventPriority.NORMAL, false, ColorHandlerEvent.Block.class, x -> {
Minecraft minecraft = Minecraft.getInstance();
ForestrySpriteUploader spriteUploader = new ForestrySpriteUploader(minecraft.textureManager, TextureManagerForestry.LOCATION_FORESTRY_TEXTURE, "gui");
TextureManagerForestry.getInstance().init(spriteUploader);
ResourceManager resourceManager = minecraft.getResourceManager();
if (resourceManager instanceof ReloadableResourceManager reloadableManager) {
reloadableManager.registerReloadListener(ColourProperties.INSTANCE);
reloadableManager.registerReloadListener(GuiElementFactory.INSTANCE);
reloadableManager.registerReloadListener(spriteUploader);
}
//EntriesCategory.registerSearchTree();
ModuleManager.getModuleHandler().runClientInit();
@OnlyIn(Dist.CLIENT)
private record Client(IEventBus modEventBus, NetworkHandler networkHandler) implements Runnable {
@Override
public void run() {
modEventBus.addListener(EventPriority.NORMAL, false, ColorHandlerEvent.Block.class, x -> {
Minecraft minecraft = Minecraft.getInstance();
ForestrySpriteUploader spriteUploader = new ForestrySpriteUploader(minecraft.textureManager, TextureManagerForestry.LOCATION_FORESTRY_TEXTURE, "gui");
TextureManagerForestry.getInstance().init(spriteUploader);
ResourceManager resourceManager = minecraft.getResourceManager();
if (resourceManager instanceof ReloadableResourceManager reloadableManager) {
reloadableManager.registerReloadListener(ColourProperties.INSTANCE);
reloadableManager.registerReloadListener(GuiElementFactory.INSTANCE);
reloadableManager.registerReloadListener(spriteUploader);
}
//EntriesCategory.registerSearchTree();
ModuleManager.getModuleHandler().runClientInit();

});
modEventBus.addListener(EventPriority.NORMAL, false, FMLLoadCompleteEvent.class, fmlLoadCompleteEvent -> networkHandler.clientPacketHandler());
});
modEventBus.addListener(EventPriority.NORMAL, false, FMLLoadCompleteEvent.class, fmlLoadCompleteEvent -> networkHandler.clientPacketHandler());
}
}

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = Constants.MOD_ID)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/forestry/api/circuits/CircuitSocketType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
public enum CircuitSocketType implements ICircuitSocketType {
NONE("none"),
FARM("forestry.farm"),
ELECTRIC_ENGINE("forestry.electric.engine"),
MACHINE("forestry.machine");

private final String uid;
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/forestry/api/core/ForestryAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
*/
public class ForestryAPI {

/**
* The main mod instance for Forestry.
*/
public static Object instance;

/**
* A {@link ITextureManager} needed for some things in the API.
*/
Expand All @@ -55,11 +50,6 @@ public class ForestryAPI {
*/
public static IFarmRegistry farmRegistry;

/**
* Provides information on certain Forestry constants (Villager IDs, Chest gen keys, etc)
*/
public static IForestryConstants forestryConstants;

/**
* Instance of the errorStateRegistry for registering errors.
* Also creates new instances of IErrorLogic.
Expand Down
50 changes: 0 additions & 50 deletions src/main/java/forestry/api/fuels/EngineBronzeFuel.java

This file was deleted.

42 changes: 0 additions & 42 deletions src/main/java/forestry/api/fuels/EngineCopperFuel.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/forestry/api/fuels/FuelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.Map;

import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.item.ItemStack;

public class FuelManager {
Expand All @@ -23,17 +22,5 @@ public class FuelManager {
* Add new substrates for the rainmaker here
*/
public static Map<ItemStack, RainSubstrate> rainSubstrate;
/**
* Add new fuels for EngineBronze (= biogas engine) here
*/
public static Map<Fluid, EngineBronzeFuel> bronzeEngineFuel;
/**
* Add new fuels for EngineCopper (= peat-fired engine) here
*/
public static Map<ItemStack, EngineCopperFuel> copperEngineFuel;
/**
* Add new fuels for Generator here
*/
public static Map<Fluid, GeneratorFuel> generatorFuel;

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import forestry.core.utils.NetworkUtil;
import forestry.energy.EnergyHelper;
import forestry.energy.EnergyManager;
import forestry.energy.EnergyTransferMode;

public abstract class TileAlvearyClimatiser extends TileAlveary implements IActivatable, IAlvearyComponent.Climatiser {

Expand Down Expand Up @@ -57,7 +56,7 @@ protected TileAlvearyClimatiser(BlockAlvearyType alvearyType, BlockPos pos, Bloc
this.definition = definition;

this.energyManager = new EnergyManager(1000, 2000);
this.energyManager.setExternalMode(EnergyTransferMode.RECEIVE);
this.energyManager.setReceiveOnly();
}

/* UPDATING */
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/forestry/arboriculture/blocks/BlockWoodPile.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand All @@ -32,7 +33,9 @@
import forestry.api.arboriculture.TreeManager;
import forestry.arboriculture.features.CharcoalBlocks;
import forestry.core.config.Config;
import org.jetbrains.annotations.Nullable;

// TODO: Fix propagation, aging
public class BlockWoodPile extends Block {

public static final BooleanProperty IS_ACTIVE = BooleanProperty.create("active");
Expand All @@ -45,42 +48,44 @@ public BlockWoodPile() {
.strength(1.5f)
.sound(SoundType.WOOD)
.noOcclusion());
registerDefaultState(getStateDefinition().any().setValue(AGE, 0).setValue(IS_ACTIVE, false));
registerDefaultState(getStateDefinition().any()
.setValue(AGE, 0)
.setValue(IS_ACTIVE, false));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(IS_ACTIVE, AGE);
}

@Nullable
@Override
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState p_220082_4_, boolean p_220082_5_) {
if (!state.getValue(IS_ACTIVE)) {
for (Direction facing : Direction.VALUES) {
BlockState facingState = world.getBlockState(pos.relative(facing));
if (facingState.getBlock() == this && facingState.getValue(IS_ACTIVE)) {
world.setBlockAndUpdate(pos, state.setValue(IS_ACTIVE, true));
break;
}
public BlockState getStateForPlacement(BlockPlaceContext context) {
for (Direction facing : Direction.VALUES) {
BlockState facingState = context.getLevel().getBlockState(context.getClickedPos().relative(facing));

if (facingState.is(this) && facingState.getValue(IS_ACTIVE)) {
return defaultBlockState().setValue(IS_ACTIVE, true);
}
}

// world.getBlockTicks().scheduleTick(pos, this, TICK_RATE + world.random.nextInt(RANDOM_TICK));
return defaultBlockState();
}

@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean p_220069_6_) {
boolean isActive = state.getValue(IS_ACTIVE);
BlockState neighborState = world.getBlockState(fromPos);
if (neighborState.getBlock() == Blocks.FIRE || neighborState.getBlock() == this) {
if (!isActive) {

if (neighborState.getBlock() == Blocks.FIRE || (neighborState.is(this) && neighborState.getValue(IS_ACTIVE))) {
if (!state.getValue(IS_ACTIVE)) {
activatePile(state, world, pos, true);
}
}
}

private void activatePile(BlockState state, Level world, BlockPos pos, boolean scheduleUpdate) {
world.setBlock(pos, state.setValue(IS_ACTIVE, true), 2);
world.setBlock(pos, state.setValue(IS_ACTIVE, true), Block.UPDATE_CLIENTS);

if (scheduleUpdate) {
// world.getBlockTicks().scheduleTick(pos, this, (TICK_RATE + world.random.nextInt(RANDOM_TICK)) / 4);
}
Expand Down Expand Up @@ -111,10 +116,10 @@ public void tick(BlockState state, ServerLevel world, BlockPos pos, Random rand)
}
if (rand.nextFloat() < 0.5F) {
if (state.getValue(AGE) < 7) {
world.setBlock(pos, state.setValue(AGE, state.getValue(AGE) + 1), 2);
world.setBlock(pos, state.setValue(AGE, state.getValue(AGE) + 1), Block.UPDATE_CLIENTS);
} else {
BlockState ashState = CharcoalBlocks.ASH.with(BlockAsh.AMOUNT, Math.min(Math.round(Config.charcoalAmountBase + getCharcoalAmount(world, pos)), 63));
world.setBlock(pos, ashState, 2);
world.setBlock(pos, ashState, Block.UPDATE_CLIENTS);
}
}
// world.getBlockTicks().scheduleTick(pos, this, TICK_RATE + world.random.nextInt(RANDOM_TICK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setRecipe(IRecipeLayoutBuilder builder, ICharcoalPileWall recipe, IF

int amount = 9 + recipe.getCharcoalAmount();

ItemStack coal = new ItemStack(Items.COAL, amount);
ItemStack coal = new ItemStack(Items.CHARCOAL, amount);
builder.addSlot(RecipeIngredientRole.OUTPUT, 85, 17)
.setBackground(slot, -1, -1)
.addItemStack(coal);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/forestry/climatology/ModuleClimatology.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ModuleClimatology extends BlankForestryModule {
private final ProxyClimatology proxy;

public ModuleClimatology() {
proxy = DistExecutor.runForDist(() -> ProxyClimatologyClient::new, () -> ProxyClimatology::new);
proxy = DistExecutor.safeRunForDist(() -> ProxyClimatologyClient::new, () -> ProxyClimatology::new);
}

@Override
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/forestry/core/ModuleFluids.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,7 @@ public void preInit() {
ForgeUtils.registerSubscriber(this);
}

@Override
public void doInit() {
FluidStack ethanol = ForestryFluids.BIO_ETHANOL.getFluid(1);
if (!ethanol.isEmpty()) {
GeneratorFuel ethanolFuel = new GeneratorFuel(ethanol, (int) (32 * Preference.FUEL_MODIFIER), 4);
FuelManager.generatorFuel.put(ethanol.getFluid(), ethanolFuel);
}

FluidStack biomass = ForestryFluids.BIOMASS.getFluid(1);
if (!biomass.isEmpty()) {
GeneratorFuel biomassFuel = new GeneratorFuel(biomass, (int) (8 * Preference.FUEL_MODIFIER), 1);
FuelManager.generatorFuel.put(biomass.getFluid(), biomassFuel);
}
}

@SubscribeEvent
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void handleTextureStitchPre(TextureStitchEvent.Pre event) {
if (event.getAtlas().location() != InventoryMenu.BLOCK_ATLAS) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/forestry/core/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ public class Config {
public static final boolean enableEnergyStat = true;

// Energy
public static final boolean enableRF = true;
public static final boolean enableMJ = true;
public static final boolean enableTesla = true;
public static final EnergyDisplayMode energyDisplayMode = EnergyDisplayMode.RF;

// Charcoal
Expand Down
Loading

0 comments on commit 9e57cf2

Please sign in to comment.