2025-11-24 22:52:51 +03:00

83 lines
2.3 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world.entity.vehicle;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.ValueInput;
import net.minecraft.world.level.storage.ValueOutput;
public class MinecartSpawner
extends AbstractMinecart {
private final BaseSpawner spawner = new BaseSpawner(){
@Override
public void broadcastEvent(Level level, BlockPos pos, int id) {
level.broadcastEntityEvent(MinecartSpawner.this, (byte)id);
}
};
private final Runnable ticker;
public MinecartSpawner(EntityType<? extends MinecartSpawner> type, Level level) {
super(type, level);
this.ticker = this.createTicker(level);
}
@Override
protected Item getDropItem() {
return Items.MINECART;
}
@Override
public ItemStack getPickResult() {
return new ItemStack(Items.MINECART);
}
private Runnable createTicker(Level level) {
return level instanceof ServerLevel ? () -> this.spawner.serverTick((ServerLevel)level, this.blockPosition()) : () -> this.spawner.clientTick(level, this.blockPosition());
}
@Override
public BlockState getDefaultDisplayBlockState() {
return Blocks.SPAWNER.defaultBlockState();
}
@Override
protected void readAdditionalSaveData(ValueInput input) {
super.readAdditionalSaveData(input);
this.spawner.load(this.level(), this.blockPosition(), input);
}
@Override
protected void addAdditionalSaveData(ValueOutput output) {
super.addAdditionalSaveData(output);
this.spawner.save(output);
}
@Override
public void handleEntityEvent(byte id) {
this.spawner.onEventTriggered(this.level(), id);
}
@Override
public void tick() {
super.tick();
this.ticker.run();
}
public BaseSpawner getSpawner() {
return this.spawner;
}
}